/* ──────────────────────────────────────────────────────────────
   Stevek apps: shared components. Needs tokens.css loaded first.
   Plain HTML + CSS. Class names are a contract with the apps that
   use them (see the design doc, "Markup contract"): add, don't rename.
   ────────────────────────────────────────────────────────────── */

/* ── Base ─────────────────────────────────────────────────── */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-text); text-underline-offset: 0.18em; }

:focus-visible {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--focus-offset);
}

svg { flex: none; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-8) var(--page-pad) var(--space-12);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ── Mark and lockup ──────────────────────────────────────── */
.mark { display: block; width: 32px; height: 32px; }
.mark__fill { fill: var(--mark-fill); stroke: var(--mark-fill); }
.mark__detail { fill: var(--mark-detail); stroke: var(--mark-detail); }
.mark--lg { width: 56px; height: 56px; }

.lockup {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-min);
  color: var(--text);
  text-decoration: none;
  font-size: 1.0625rem;
  line-height: 1;
  letter-spacing: -0.01em;
}
.lockup__name { font-weight: var(--weight-bold); }
.lockup__product { font-weight: var(--weight-regular); color: var(--text-muted); }

/* ── Header ───────────────────────────────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: var(--page-max);
  min-height: var(--header-h);
  margin: 0 auto;
  padding: 0 var(--page-pad);
}

.user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.user__avatar {
  display: grid;
  place-items: center;
  width: var(--avatar);
  height: var(--avatar);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
}
.user__name { font-weight: var(--weight-medium); }
.user__role {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-left: var(--space-1);
}
@media (max-width: 599px) {
  .user__name, .user__role { display: none; }
}

/* ── Buttons ──────────────────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--text-on-accent);
  font: inherit;
  font-weight: var(--weight-strong);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.button:hover { background: var(--accent-hover); }
.button svg { width: 20px; height: 20px; }

.button--quiet {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
  font-weight: var(--weight-medium);
  padding: 0 var(--space-4);
}
.button--quiet:hover { background: var(--surface-sunken); border-color: var(--border-strong); }

/* "Sign in with Stevek Login": the one sign-in button everywhere */
.signin-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: 0 var(--space-6);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--signin-bg);
  color: var(--signin-text);
  --mark-fill: var(--signin-mark-fill);
  --mark-detail: var(--signin-mark-detail);
  font: inherit;
  font-size: var(--text-lg);
  font-weight: var(--weight-strong);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.signin-button:hover { background: var(--signin-bg-hover); }
.signin-button:active { transform: translateY(1px); }
.signin-button .mark { width: 28px; height: 28px; }

/* ── Page heading ─────────────────────────────────────────── */
.hello { margin: 0 0 var(--space-8); }
.hello__title {
  margin: 0;
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  font-weight: var(--weight-bold);
  letter-spacing: -0.015em;
}
.hello__lead { margin: var(--space-2) 0 0; color: var(--text-muted); }

.backlink {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  margin: calc(-1 * var(--space-4)) 0 var(--space-2);
  color: var(--accent-text);
  font-weight: var(--weight-medium);
  text-decoration: none;
}
.backlink:hover { text-decoration: underline; }
.backlink svg { width: 20px; height: 20px; }

/* ── Sections ─────────────────────────────────────────────── */
.section + .section { margin-top: var(--space-12); }
.section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1) var(--space-4);
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.section__title {
  margin: 0;
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  font-weight: var(--weight-bold);
  letter-spacing: -0.01em;
}
.section__note { margin: 0; color: var(--text-muted); font-size: var(--text-sm); }

/* ── Tile grid ────────────────────────────────────────────── */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tile-min), 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.tiles--rows {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--tile-row-min)), 1fr));
  gap: var(--space-3);
}
@media (max-width: 599px) {
  .tiles { gap: var(--space-3); }
}

/* ── Tile ─────────────────────────────────────────────────── */
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  height: 100%;
  min-height: var(--tile-min-h);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-tile);
  color: var(--text);
  text-decoration: none;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease),
    transform var(--dur) var(--ease);
}
.tile:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-tile-hover);
  transform: translateY(-2px);
}
.tile:active { transform: translateY(0); }
.tile:focus-visible { outline-offset: 2px; }

/* Icon square. Neutral (warm grey, ink glyph) unless an ancestor
   carries data-app, which sets --app / --app-ink from tokens.css. */
.tile__icon {
  display: grid;
  place-items: center;
  width: var(--tile-icon);
  height: var(--tile-icon);
  margin-bottom: auto;            /* pins the text to the bottom of the tile */
  border-radius: var(--radius-md);
  background: var(--app, var(--surface-sunken));
  color: var(--app-ink, var(--text));
}
.tile__icon svg { width: var(--tile-glyph); height: var(--tile-glyph); }

/* App colours: one line per family app (tokens in tokens.css) */
[data-app="movies"]   { --app: var(--app-movies);   --app-ink: var(--app-movies-ink); }
[data-app="photos"]   { --app: var(--app-photos);   --app-ink: var(--app-photos-ink); }
[data-app="home"]     { --app: var(--app-home);     --app-ink: var(--app-home-ink); }
[data-app="requests"] { --app: var(--app-requests); --app-ink: var(--app-requests-ink); }
[data-app="status"]   { --app: var(--app-status);   --app-ink: var(--app-status-ink); }
[data-app="internet"] { --app: var(--app-internet); --app-ink: var(--app-internet-ink); }

.tile__name {
  margin-top: var(--space-4);
  font-size: var(--text-lg);
  line-height: var(--leading-tight);
  font-weight: var(--weight-strong);
  letter-spacing: -0.01em;
}
.tile__sub {
  font-size: var(--text-sm);
  line-height: 1.35;
  color: var(--text-muted);
}

/* Small "Home or Tailscale" marker: where a link works */
.tile__marker {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: var(--space-2);
  padding: 2px 8px 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.5;
  white-space: nowrap;
}
.tile__marker svg { width: 13px; height: 13px; }

/* Live state on a tile (Status tile, or an app that is down) */
.tile__state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  line-height: 1.35;
}
.tile__state svg { width: 16px; height: 16px; }
.tile__state--ok { color: var(--ok); }
.tile__state--down { color: var(--down); }
.tile__state--warn { color: var(--warn); }

.tile__badge {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px 3px 7px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-strong);
  line-height: 1.4;
}
.tile__badge svg { width: 13px; height: 13px; }
.tile__badge--down { background: var(--down-soft); color: var(--down); }

/* Compact row tile, for admin quick links */
.tile--row {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "icon name" "icon sub" "icon marker";
  align-items: center;
  align-content: center;
  column-gap: var(--space-4);
  row-gap: 0;
  min-height: 84px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
}
.tile--row:hover { transform: none; }
.tile--row .tile__icon {
  grid-area: icon;
  align-self: start;
  width: 40px;
  height: 40px;
  margin: 0;
  border-radius: calc(var(--radius-md) - 2px);
}
.tile--row .tile__icon svg { width: 22px; height: 22px; }
.tile--row .tile__name { grid-area: name; margin: 0; font-size: var(--text-md); }
.tile--row .tile__sub { grid-area: sub; }
.tile--row .tile__marker { grid-area: marker; justify-self: start; margin-top: var(--space-1); }

/* ── Status view ──────────────────────────────────────────── */
.status-summary {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  margin: 0 0 var(--space-6);
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--ok-soft);
}
.status-summary--down { background: var(--down-soft); }
.status-summary__icon { width: 32px; height: 32px; margin-top: 2px; color: var(--ok); }
.status-summary--down .status-summary__icon { color: var(--down); }
.status-summary__title {
  margin: 0;
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  font-weight: var(--weight-bold);
}
.status-summary__text { margin: var(--space-1) 0 0; }

.status-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.status-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 72px;
  padding: var(--space-3) var(--space-5);
}
.status-row + .status-row { border-top: 1px solid var(--border); }
.status-row .tile__icon { width: 40px; height: 40px; margin: 0; border-radius: calc(var(--radius-md) - 2px); }
.status-row .tile__icon svg { width: 22px; height: 22px; }
.status-row__name { flex: 1; min-width: 0; font-weight: var(--weight-strong); font-size: var(--text-lg); }
.status-row__state { text-align: right; }
.status-row__time { display: block; font-size: var(--text-sm); color: var(--text-muted); }

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: var(--weight-strong);
}
.state svg { width: 18px; height: 18px; }
.state--ok { color: var(--ok); }
.state--down { color: var(--down); }
.state--warn { color: var(--warn); }

.status-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-6);
  margin-top: var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--page-pad) var(--space-10);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
