/* Balletrax admin — design tokens first, components second.
   Light and dark are both first-class; dark follows the OS unless the user
   overrides it, and the override is remembered per browser. */

:root {
  color-scheme: light dark;

  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* Type scale (1.200 minor third) */
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;

  /* Spacing scale */
  --s1: 0.25rem; --s2: 0.5rem;  --s3: 0.75rem; --s4: 1rem;
  --s5: 1.5rem; --s6: 2rem;     --s7: 3rem;    --s8: 4rem;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --sidebar-w: 248px;
  --measure: 62ch;

  /* Light palette — sampled from the app's player screen.
     Contrast verified: body text 17.4:1, secondary 7.4:1, muted 4.8:1,
     button label on brand 5.3:1, brand on brand-soft 4.6:1, control borders
     3.0:1. Every pair meets WCAG 2.1 AA. */
  --bg: #fdfafb;
  --surface: #ffffff;
  --surface-2: #fdf7fa;
  --surface-inset: #f7edf2;
  /* Decorative dividers. Deliberately lighter than --border-strong: WCAG's
     3:1 applies to what identifies a control, not to table rules. */
  --border: #efe1e8;
  /* Form-control boundaries, which DO need 3:1 to be identifiable. */
  --border-strong: #a68d9e;
  --text: #1f181c;
  --text-2: #645157;
  --text-3: #7e6773;

  --brand: #c2326f;
  --brand-2: #c54983;
  --brand-ink: #ffffff;
  --brand-soft: #fbeaf2;

  --ok: #0f7a4a;      --ok-soft: #e6f5ee;
  --warn: #8a5800;    --warn-soft: #fdf3e0;
  --danger: #b3261e;  --danger-soft: #fdeceb;  --danger-ink: #ffffff;

  --shadow-sm: 0 1px 2px rgba(48, 16, 32, 0.06);
  --shadow: 0 2px 8px rgba(48, 16, 32, 0.09);
  --shadow-lg: 0 12px 32px rgba(48, 16, 32, 0.16);

  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120d10;
    --surface: #1b1318;
    --surface-2: #21181e;
    --surface-inset: #2a1e25;
    --border: #342530;
    --border-strong: #755c6a;
    --text: #f8f1f4;
    --text-2: #c2aeb7;
    --text-3: #9b8590;

    --brand: #ec7aa8;
    --brand-2: #f59cc0;
    --brand-ink: #1a0e14;
    --brand-soft: #3a212c;

    --ok: #4ade80;      --ok-soft: #10261b;
    --warn: #fbbf24;    --warn-soft: #2a2011;
    --danger: #f87171;  --danger-soft: #2d1616;  --danger-ink: #2d1616;  --danger-ink: #2d1616;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --bg: #120d10;
  --surface: #1b1318;
  --surface-2: #21181e;
  --surface-inset: #2a1e25;
  --border: #342530;
  --border-strong: #755c6a;
  --text: #f8f1f4;
  --text-2: #c2aeb7;
  --text-3: #9b8590;

  --brand: #ec7aa8;
  --brand-2: #f59cc0;
  --brand-ink: #1a0e14;
  --brand-soft: #3a212c;

  --ok: #4ade80;    --ok-soft: #10261b;
  --warn: #fbbf24;  --warn-soft: #2a2011;
  --danger: #f87171;  --danger-soft: #2d1616;  --danger-ink: #2d1616;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.6);
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.015em; font-weight: 650; }
p { margin: 0 0 var(--s3); }
a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

/* box-shadow is not painted in forced-colors mode, which would leave keyboard
   users with no focus indicator at all. Restore a real outline there. */
@media (forced-colors: active) {
  :focus-visible { outline: 3px solid Highlight; outline-offset: 2px; }
}

/* Respect a user who asks for less motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.skip-link {
  position: absolute; left: var(--s3); top: -4rem; z-index: 100;
  padding: var(--s2) var(--s4); background: var(--brand); color: var(--brand-ink);
  border-radius: var(--radius); font-weight: 600; transition: top .15s ease;
}
.skip-link:focus { top: var(--s3); }

/* ---------------------------------------------------------------- layout */

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* The mobile nav backdrop. `display: none` has to be a BASE rule, not a
   mobile-only one: as a grid child it would otherwise occupy the first column
   at desktop widths and push the sidebar and main content out of place. */
.scrim { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 40; }

.sidebar {
  display: flex; flex-direction: column; gap: var(--s5);
  padding: var(--s5) var(--s4);
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: var(--s3); text-decoration: none; color: inherit; }
.brand-mark {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  border-radius: var(--radius); font-weight: 800; font-size: var(--text-sm);
  color: var(--brand-ink);
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.brand-name { font-weight: 680; letter-spacing: -0.02em; }
.brand-sub { display: block; font-size: var(--text-xs); color: var(--text-3); font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-3); font-weight: 650; padding: var(--s3) var(--s3) var(--s1);
}
.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-radius: var(--radius);
  color: var(--text-2); text-decoration: none; font-weight: 550;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--surface-inset); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.nav-item .count { margin-left: auto; font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-icon { width: 18px; height: 18px; flex: none; stroke-width: 1.8; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--s3); }
.who { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: var(--radius-pill);
  display: grid; place-items: center; font-size: var(--text-xs); font-weight: 700;
  background: var(--surface-inset); color: var(--text-2);
}
.who-name { font-size: var(--text-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { font-size: var(--text-xs); color: var(--text-3); }

.main { min-width: 0; display: flex; flex-direction: column; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4);
  padding: var(--s6) var(--s6) var(--s5);
  flex-wrap: wrap;
}
.page-title { font-size: var(--text-2xl); }
.page-sub { color: var(--text-2); font-size: var(--text-sm); margin: var(--s1) 0 0; }
.content { padding: 0 var(--s6) var(--s7); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 0.5rem 0.9rem; border-radius: var(--radius);
  font: inherit; font-weight: 600; font-size: var(--text-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  min-height: 38px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-inset); }
.btn-danger { background: var(--danger); color: var(--danger-ink); }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { padding: 0.3rem 0.6rem; min-height: 30px; font-size: var(--text-xs); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card-pad { padding: var(--s5); }

.stats { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat { padding: var(--s4) var(--s5); }
.stat-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); font-weight: 650; }
.stat-value { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; margin-top: var(--s1); }
.stat-note { font-size: var(--text-sm); color: var(--text-2); }

/* ---------------------------------------------------------------- tables */

.toolbar { display: flex; gap: var(--s3); align-items: center; margin-bottom: var(--s4); flex-wrap: wrap; }
.search { flex: 1 1 260px; max-width: 420px; position: relative; display: flex; }
.search input {
  width: 100%; padding: 0.5rem 0.8rem 0.5rem 2.1rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-sm);
  min-height: 38px;
}
.search svg { position: absolute; left: 0.65rem; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); }
.result-count { color: var(--text-3); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th {
  text-align: left; font-weight: 650; font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-3);
  padding: var(--s3); border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
tbody td { padding: var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.cell-title { font-weight: 600; color: var(--text); }
.cell-meta { color: var(--text-3); font-size: var(--text-xs); }
.cell-num { font-variant-numeric: tabular-nums; text-align: right; }
.row-actions { display: flex; gap: var(--s2); justify-content: flex-end; }

.thumb {
  width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: var(--text-xs); flex: none;
}
.media-cell { display: flex; align-items: center; gap: var(--s3); min-width: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 0.3em;
  padding: 0.15rem 0.5rem; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 650; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-muted { background: var(--surface-inset); color: var(--text-3); }

/* A native <audio controls> per row is far too wide for a dense table — it
   pushed Edit/Delete off the end, and narrowing it collapsed the play button
   away entirely. One shared player behind a compact per-row toggle keeps the
   row readable and guarantees only one preview plays at a time. */
.play {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 0.3rem 0.65rem; min-height: 30px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--text); font: inherit;
  font-size: var(--text-xs); font-weight: 600; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.play:hover { background: var(--surface-inset); }
.play svg { width: 13px; height: 13px; fill: currentColor; flex: none; }
/* `.play svg` sets no display, but some engines still need this explicitly for
   SVG children — without it both the play and pause glyphs render at once. */
.play svg[hidden] { display: none; }
/* The label is for screen readers only: the icon carries the meaning, and the
   text was wide enough to push the Delete action off the end of the row. */
.play > span { position: absolute; width: 1px; height: 1px; overflow: hidden;
               clip: rect(0 0 0 0); white-space: nowrap; }
.play { position: relative; padding: 0.3rem 0.55rem; }
.play[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.play[data-loading="true"] { opacity: .6; }
.cell-album { max-width: 18ch; }
audio { height: 32px; max-width: 100%; }

/* ---------------------------------------------------------------- forms */

.form-grid { display: grid; gap: var(--s5); max-width: var(--measure); }
.field { display: flex; flex-direction: column; gap: var(--s2); }
.field > label { font-weight: 600; font-size: var(--text-sm); }
.field-input, .field-select {
  padding: 0.55rem 0.7rem; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--text-base); min-height: 40px; width: 100%;
}
.field-select { appearance: none; background-image:
  linear-gradient(45deg, transparent 50%, currentColor 50%),
  linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 2.2rem; }
.field-help { font-size: var(--text-xs); color: var(--text-3); }
.field-error { font-size: var(--text-sm); color: var(--danger); font-weight: 550; }
.field-input[aria-invalid="true"], .field-select[aria-invalid="true"] { border-color: var(--danger); }

.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg);
  padding: var(--s5); text-align: center; background: var(--surface-2);
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.is-over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input[type="file"] { display: block; margin: var(--s3) auto 0; max-width: 100%; }
.dropzone-hint { color: var(--text-2); font-size: var(--text-sm); }
.dropzone-file { margin-top: var(--s3); font-size: var(--text-sm); font-weight: 600; color: var(--brand); word-break: break-all; }

.form-actions { display: flex; gap: var(--s3); align-items: center; margin-top: var(--s5); flex-wrap: wrap; }

/* ---------------------------------------------------------------- misc */

.messages { display: flex; flex-direction: column; gap: var(--s2); padding: 0 var(--s6); margin-bottom: var(--s4); }
.message {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4); border-radius: var(--radius); font-size: var(--text-sm);
  border: 1px solid transparent;
}
.message-success { background: var(--ok-soft); color: var(--ok); border-color: currentColor; }
.message-error { background: var(--danger-soft); color: var(--danger); border-color: currentColor; }
.message-info { background: var(--brand-soft); color: var(--brand); border-color: currentColor; }

.empty { text-align: center; padding: var(--s8) var(--s5); color: var(--text-2); }
.empty-title { font-size: var(--text-lg); font-weight: 650; color: var(--text); margin-bottom: var(--s2); }

.pagination { display: flex; gap: var(--s2); align-items: center; justify-content: center; margin-top: var(--s5); }
.pagination .current { font-size: var(--text-sm); color: var(--text-2); font-variant-numeric: tabular-nums; }

.mono { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-3); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- auth */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s5); }
.auth-card { width: 100%; max-width: 400px; padding: var(--s6); }
.auth-head { text-align: center; margin-bottom: var(--s5); }
.auth-head .brand-mark { width: 44px; height: 44px; margin: 0 auto var(--s4); font-size: var(--text-base); }

/* ---------------------------------------------------------------- responsive */

.menu-toggle { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(84vw, var(--sidebar-w));
    transform: translateX(-100%); transition: transform .2s ease; z-index: 50;
    box-shadow: var(--shadow-lg);
  }
  .shell.nav-open .sidebar { transform: none; visibility: visible; }
  /* transform alone does not remove an element from the tab order or the
     accessibility tree: a keyboard user would tab into an invisible menu.
     `visibility` does, and it still transitions alongside the transform. */
  .sidebar { visibility: hidden; transition: transform .2s ease, visibility .2s; }
  .menu-toggle { display: inline-flex; }
  .page-head, .content, .messages { padding-left: var(--s4); padding-right: var(--s4); }
  .page-head { padding-top: var(--s4); }
  .shell.nav-open .scrim { display: block; }
}

@media (max-width: 560px) {
  .stat-value { font-size: var(--text-2xl); }
  .row-actions { flex-direction: column; align-items: stretch; }
}

@media print {
  .sidebar, .toolbar, .row-actions, .pagination { display: none; }
  .shell { grid-template-columns: 1fr; }
}

/* Visible to screen readers only — used for table captions and action-column
   headers, which need a name but would be visual noise. */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Filter dropdown, sitting beside the search box in the same form. */
.filter { display: flex; flex: 0 1 220px; }
.filter .field-select { min-height: 38px; font-size: var(--text-sm); padding-top: 0; padding-bottom: 0; }

/* The no-JS submit button. admin.js hides it and auto-submits on change, so
   it only ever shows where scripting is unavailable. */
[data-submit-fallback][hidden] { display: none; }

/* The announcement body. `field-input` gives it the border and colours; it
   only needs a sensible height and the ability to grow. */
textarea.field-input { min-height: 7.5rem; resize: vertical; line-height: 1.5; }
input.field-input[type="datetime-local"] { max-width: 16rem; }
