/* ==========================================================================
   Studio design system
   Tokens first (color, type, space, radius, elevation), then components.
   Every color has one job; status colors never double as decoration.
   ========================================================================== */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  /* neutrals, warm */
  --n-0: #ffffff;
  --n-25: #fbfaf8;
  --n-50: #f5f3ef;
  --n-100: #ebe8e2;
  --n-200: #ddd9d1;
  --n-400: #a19b90;
  --n-500: #6b655a;  /* 4.7:1 on the darkest light surface (WCAG AA) */
  --n-600: #5c574e;
  --n-900: #1b1a17;

  /* roles */
  --bg: var(--n-50);
  --surface: var(--n-0);
  --surface-2: var(--n-25);
  --surface-sunken: var(--n-100);
  --border: var(--n-200);
  --border-strong: var(--n-400);
  --text: var(--n-900);
  --text-2: var(--n-600);
  --text-3: var(--n-500);

  /* brand: action and focus only */
  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --accent-ink: #3730a3;
  --focus: #6366f1;

  /* status */
  --info: #3730a3;      --info-soft: #eef0ff;
  --warn: #8a4b00;      --warn-soft: #fff1d6;
  --ok: #0b6b3a;        --ok-soft: #e1f4e8;
  --danger: #b4231a;    --danger-soft: #fde9e7;
  --muted-soft: var(--n-100);

  /* type: 1.25 scale */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --fs-xs: .75rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.875rem;

  /* space: 4 px grid */
  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem;
  --s-5: 1.25rem; --s-6: 1.5rem; --s-8: 2rem; --s-10: 2.5rem; --s-12: 3rem;

  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px; --r-full: 999px;

  --shadow-sm: 0 1px 2px rgb(27 26 23 / .06);
  --shadow-md: 0 1px 2px rgb(27 26 23 / .05), 0 4px 12px rgb(27 26 23 / .06);
  --shadow-lg: 0 2px 4px rgb(27 26 23 / .05), 0 12px 32px rgb(27 26 23 / .10);

  --ease: cubic-bezier(.2, .7, .2, 1);
  --header-h: 60px;
  --content: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1b1a18;
    --surface-2: #201f1c;
    --surface-sunken: #262420;
    --border: #312e2a;
    --border-strong: #4a463f;
    --text: #efece6;
    --text-2: #b3ada2;
    --text-3: #9a9488;  /* 5.1:1 on the darkest dark surface */
    --accent: #8b93ff;
    --accent-hover: #a5abff;
    --accent-soft: #23244a;
    --accent-text: #121110;
    --accent-ink: #b9beff;
    --focus: #a5abff;
    --info: #b9beff;      --info-soft: #23244a;
    --warn: #ffcf7a;      --warn-soft: #3a2c10;
    --ok: #74e0a5;        --ok-soft: #15301f;
    --danger: #ff9d92;    --danger-soft: #3b1714;
    --muted-soft: #2a2824;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-md: 0 1px 2px rgb(0 0 0 / .4), 0 4px 12px rgb(0 0 0 / .35);
    --shadow-lg: 0 2px 4px rgb(0 0 0 / .4), 0 12px 32px rgb(0 0 0 / .5);
  }
}

/* --------------------------------------------------------------- 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: 400 var(--fs-md)/1.55 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.015em; line-height: 1.2; }
h1 { font-size: var(--fs-2xl); font-weight: 700; }
h2 { font-size: var(--fs-lg); font-weight: 650; }
h3 { font-size: var(--fs-md); font-weight: 650; }
p { margin: 0; }
a { color: var(--accent-ink); text-underline-offset: 3px; }
code { font-family: var(--mono); font-size: .9em; }
img, svg, video { display: block; max-width: 100%; }
.icon { flex: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------- header */
.header {
  position: sticky; top: 0; z-index: 20; height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--content); height: 100%; margin: 0 auto; padding: 0 var(--s-5);
  display: flex; align-items: center; gap: var(--s-4);
}
.brand { display: flex; align-items: center; gap: var(--s-2); color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.02em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
  color: #fff; box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 12px; height: 12px; margin-left: 2px; }
.brand-sep { width: 1px; height: 22px; background: var(--border); }
.tenant {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3);
  border-radius: var(--r-full); background: var(--surface-sunken); color: var(--text);
  font-size: var(--fs-sm); font-weight: 600;
}
.tenant .icon { color: var(--text-3); }
.header-nav { margin-left: auto; display: flex; align-items: center; gap: var(--s-1); }
.nav-link {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); font-weight: 550;
}
.nav-link:hover { background: var(--surface-sunken); color: var(--text); }
.nav-link[aria-current="page"] { color: var(--text); background: var(--surface-sunken); }

/* menu without script: <details> */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; border-radius: var(--r-full); }
.menu > summary::-webkit-details-marker { display: none; }
.avatar {
  width: 34px; height: 34px; border-radius: var(--r-full); display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: var(--fs-sm);
  border: 1px solid var(--border); text-transform: uppercase;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + var(--s-2)); width: 260px; padding: var(--s-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
}
.menu-head { padding: var(--s-2) var(--s-3) var(--s-3); border-bottom: 1px solid var(--border); margin-bottom: var(--s-2); }
.menu-head strong { display: block; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.menu-head span { font-size: var(--fs-xs); color: var(--text-3); }
.menu-item {
  min-height: 40px;
  display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: var(--s-2) var(--s-3);
  border: 0; border-radius: var(--r-md); background: none; color: var(--text); font: inherit;
  font-size: var(--fs-sm); text-decoration: none; cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--surface-sunken); }
.menu-item .icon { color: var(--text-3); }
.menu-item[aria-current="true"] { font-weight: 650; }
.menu-item[aria-current="true"] .icon { color: var(--accent-ink); }
.menu form { margin: 0; }
.menu-label { padding: var(--s-3) var(--s-3) var(--s-1); font-size: var(--fs-xs); color: var(--text-3); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
.menu-divider { height: 1px; background: var(--border); margin: var(--s-2) 0; }

/* ------------------------------------------------------------- layout */
.page { max-width: var(--content); margin: 0 auto; padding: var(--s-8) var(--s-5) var(--s-12); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap; }
.page-head p { color: var(--text-2); margin-top: var(--s-1); }
.eyebrow { font-size: var(--fs-xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin-bottom: var(--s-2); }
.stack { display: grid; gap: var(--s-5); }

/* ------------------------------------------------------------- auth pages */
.auth { min-height: calc(100vh - var(--header-h)); display: grid; place-items: center; padding: var(--s-8) var(--s-4); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { padding: var(--s-8); box-shadow: var(--shadow-lg); }
.auth-icon {
  width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); margin-bottom: var(--s-5);
}
.auth-card h1 { font-size: var(--fs-xl); margin-bottom: var(--s-2); }
.auth-card .lead { color: var(--text-2); margin-bottom: var(--s-6); }
.auth-card .alert { margin-bottom: var(--s-5); }
.auth-foot { text-align: center; color: var(--text-3); font-size: var(--fs-xs); margin-top: var(--s-5); padding: 0 var(--s-4); text-wrap: balance; }
.auth-foot .icon { display: inline-block; vertical-align: -2px; margin-right: 4px; }

/* ------------------------------------------------------------- card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s-6); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-5); }
.card-head > .icon { color: var(--text-3); margin-top: 2px; }
.card-head p { color: var(--text-2); font-size: var(--fs-sm); margin-top: 2px; }

/* ------------------------------------------------------------- forms */
.form { display: grid; gap: var(--s-4); }
.field { display: grid; gap: var(--s-2); }
.field label { font-size: var(--fs-sm); font-weight: 600; }
.field .help { font-size: var(--fs-xs); color: var(--text-3); }
input[type=email], input[type=password], input[type=text], input[inputmode], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); padding: .7rem .85rem;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 22%, transparent); }
::placeholder { color: var(--text-3); opacity: .55; }
input.code-input { font: 600 1.6rem/1 var(--mono); letter-spacing: .4em; text-align: center; padding: .9rem; }

/* ------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 42px; padding: 0 var(--s-5); border-radius: var(--r-md); border: 1px solid transparent;
  font: 600 var(--fs-sm)/1 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-sunken); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-sunken); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 var(--s-3); }

/* ------------------------------------------------------------- alerts */
.alert { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); border-radius: var(--r-md); font-size: var(--fs-sm); }
.alert .icon { margin-top: 2px; }
.alert ul { margin: 0; padding-left: var(--s-4); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.page > .alert { margin-bottom: var(--s-5); }

/* ------------------------------------------------------------- status */
.status {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px;
  border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 650; line-height: 1.4;
  background: var(--muted-soft); color: var(--text-2); width: fit-content;
}
.status-ready { background: var(--info-soft); color: var(--info); }
.status-scheduled, .status-publishing { background: var(--warn-soft); color: var(--warn); }
.status-published { background: var(--ok-soft); color: var(--ok); }
.status-failed, .status-missed { background: var(--danger-soft); color: var(--danger); }
.status-lg { font-size: var(--fs-sm); padding: 5px 12px 5px 9px; }

/* ------------------------------------------------------------- filters */
.tabs {
  display: flex; gap: var(--s-1); padding: var(--s-1); margin-bottom: var(--s-6); width: fit-content; max-width: 100%;
  background: var(--surface-sunken); border-radius: var(--r-lg); overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-4);
  border-radius: var(--r-md); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab .count { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.tab[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.tab[aria-current="page"] .count { color: var(--accent-ink); }

/* ------------------------------------------------------------- video grid */
.grid { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-5); grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile {
  display: flex; flex-direction: column; height: 100%; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden;
  box-shadow: var(--shadow-sm); transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease);
}
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.tile-media { position: relative; aspect-ratio: 9 / 16; background: var(--surface-sunken); }
.tile-media img { width: 100%; height: 100%; object-fit: cover; }
.tile-media .status { position: absolute; top: var(--s-2); left: var(--s-2); box-shadow: var(--shadow-md); }
.tile-empty { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: var(--s-2); color: var(--text-3); font-size: var(--fs-xs); }
.tile-body { padding: var(--s-3) var(--s-4) var(--s-4); display: grid; gap: var(--s-1); }
.tile-title {
  font-size: var(--fs-sm); font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tile-meta { display: flex; align-items: center; gap: 5px; font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: var(--s-12) var(--s-4); color: var(--text-2); }
.empty .icon { margin: 0 auto var(--s-3); color: var(--text-3); }

/* ------------------------------------------------------------- detail */
.back { display: inline-flex; align-items: center; gap: var(--s-1); margin-bottom: var(--s-5); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); font-weight: 550; }
.back:hover { color: var(--text); }
.detail { display: grid; gap: var(--s-8); grid-template-columns: minmax(0, 380px) minmax(0, 1fr); align-items: start; }
.player { position: sticky; top: calc(var(--header-h) + var(--s-6)); }
.player video, .player-empty { width: 100%; aspect-ratio: 9 / 16; border-radius: var(--r-xl); background: #000; box-shadow: var(--shadow-lg); }
.player-empty { display: grid; place-items: center; align-content: center; gap: var(--s-2); background: var(--surface-sunken); color: var(--text-3); box-shadow: none; border: 1px dashed var(--border-strong); font-size: var(--fs-sm); }
.detail-head { display: grid; gap: var(--s-3); margin-bottom: var(--s-2); }
.detail-head h1 { font-size: var(--fs-xl); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-3) var(--s-6); margin: 0; font-size: var(--fs-sm); }
.facts dt { color: var(--text-3); display: flex; align-items: center; gap: var(--s-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.facts a { display: inline-flex; align-items: center; gap: 4px; }

.files { list-style: none; margin: 0; padding: 0; display: grid; }
.file { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) 0; border-top: 1px solid var(--border); }
.file:first-child { border-top: 0; padding-top: 0; }
.file:last-child { padding-bottom: 0; }
.file-icon { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--surface-sunken); color: var(--text-2); }
.file-info { flex: 1; min-width: 0; }
.file-info strong { display: block; font-size: var(--fs-sm); }
.file-info span { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }

textarea.caption { resize: vertical; min-height: 240px; font-size: var(--fs-sm); line-height: 1.6; background: var(--surface-2); }
.notes { margin-top: var(--s-4); font-size: var(--fs-sm); }
.notes summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
.notes pre { white-space: pre-wrap; font: inherit; color: var(--text-2); margin: var(--s-3) 0 0; padding: var(--s-4); background: var(--surface-2); border-radius: var(--r-md); border: 1px solid var(--border); }
.hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--s-2); }

/* ------------------------------------------------------------- account */
.settings { display: grid; gap: var(--s-5); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

/* ------------------------------------------------------------- second factor */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 var(--s-5); display: grid; gap: var(--s-3); font-size: var(--fs-sm); color: var(--text-2); }
.steps li { counter-increment: step; display: grid; grid-template-columns: 26px 1fr; gap: var(--s-3); align-items: start; }
.steps li::before {
  content: counter(step); width: 26px; height: 26px; border-radius: var(--r-full); display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: var(--fs-xs);
}
.qr { display: grid; place-items: center; padding: var(--s-4); margin-bottom: var(--s-4); background: #fff; border-radius: var(--r-lg); border: 1px solid var(--border); }
.qr svg { width: 200px; height: auto; }
.secret { display: block; word-break: break-all; font-size: var(--fs-sm); padding: var(--s-3); background: var(--surface-sunken); border-radius: var(--r-md); margin-top: var(--s-2); }
.disclosure { font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--s-5); }
.disclosure summary { cursor: pointer; font-weight: 600; }
.disclosure p { margin-top: var(--s-2); }
.codes { list-style: none; padding: 0; margin: 0 0 var(--s-6); display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2); }
.codes code { display: block; text-align: center; padding: var(--s-3); border-radius: var(--r-md); background: var(--surface-sunken); font-size: var(--fs-sm); font-weight: 600; letter-spacing: .03em; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .detail { grid-template-columns: 1fr; gap: var(--s-6); }
  .player { position: static; max-width: 400px; width: 100%; margin: 0 auto; }
}
@media (max-width: 640px) {
  /* touch targets of 40 px or more (WCAG 2.5.8 asks 24, platform guides 44-48) */
  .btn, .btn-sm { min-height: 44px; }
  .tab { min-height: 40px; }
  .nav-link { min-height: 40px; min-width: 40px; justify-content: center; }
  .avatar { width: 40px; height: 40px; }
  :root { --fs-2xl: 1.6rem; --header-h: 56px; }
  .header-inner { padding: 0 var(--s-4); gap: var(--s-3); }
  /* with a tenant pill the brand mark alone is enough; on login pages the name stays */
  .header-inner:has(.tenant) .brand-name, .brand-sep, .nav-text { display: none; }
  .tabs { flex-wrap: wrap; width: 100%; }
  .page { padding: var(--s-6) var(--s-4) var(--s-10); }
  .grid { gap: var(--s-3); grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-body { padding: var(--s-3); }
  .card { padding: var(--s-5); }
  .auth-card .card { padding: var(--s-6); }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: var(--s-3); }
  .settings { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
