/* SIDE A — server GUI. Consumes semantic tokens from /static/brand/tokens.css.
   Dark is the default theme; [data-sa-theme="light"] supplies the light map. */

* { box-sizing: border-box; }
html { color-scheme: dark; }
/* html keeps height:100% so percentage heights resolve; body must NOT be
   height-capped: the border-box padding that clears the fixed player
   footer has to grow the document, or content inside the padding band
   sits behind the player with no way to scroll it into view. */
html { height: 100%; }
html, body { margin: 0; }
body {
  background: var(--sa-background);
  color: var(--sa-text);
  font: 400 16px/1.5 var(--sa-font-sans);
  min-height: 100vh;
}
.muted { color: var(--sa-text-secondary); }
.small { font-size: 14px; }
.hidden { display: none !important; }
.inline-form { display: inline; }

/* Mono for durations, queue numbers, technical values. */
.mono, .time, .eyebrow {
  font-family: var(--sa-font-mono);
  font-weight: 400;
}

.sa-icon { width: 20px; height: 20px; flex: none; }

/* The inlined icon sprite uses the hidden attribute; UA styles don't
   apply it to SVG elements, so hide it explicitly. */
svg[hidden] { display: none; }

/* Visible keyboard focus everywhere. */
:focus-visible {
  outline: 2px solid var(--sa-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: 8px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 600;
  font-size: 15px;
  transition: background-color var(--sa-motion-ms-transition) ease,
              border-color var(--sa-motion-ms-transition) ease;
}
.btn-primary { background: var(--sa-accent); color: var(--sa-on-accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: var(--sa-surface);
  color: var(--sa-text);
  border: 1px solid var(--sa-border-control);
}
.btn-secondary:hover { border-color: var(--sa-text); }
.btn-ghost { border: 1px solid transparent; color: var(--sa-text-secondary); }
.btn-ghost:hover { color: var(--sa-text); border-color: var(--sa-border-control); }
.danger:not(:focus):not(:hover) { color: var(--sa-error); }
.danger:hover { color: var(--sa-error); border-color: var(--sa-error); }

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--sa-text);
  border-radius: 999px;
}
.icon-btn:hover { background: var(--sa-surface); }
.btn-play {
  width: 56px;
  height: 56px;
  background: var(--sa-accent);
  color: var(--sa-on-accent);
}
.btn-play:hover { background: var(--sa-accent); filter: brightness(1.08); }
.btn-play .sa-icon { width: 24px; height: 24px; }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 8px;
  color: var(--sa-text-secondary);
  font-size: 14px;
}
.link-btn:hover { color: var(--sa-text); }

/* --- inputs ------------------------------------------------------------ */

input, select {
  font: inherit;
  color: var(--sa-text);
  background: var(--sa-surface);
  border: 1px solid var(--sa-border-control);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
}
input::placeholder { color: var(--sa-text-secondary); }

label { font-size: 14px; color: var(--sa-text-secondary); }

/* --- login -------------------------------------------------------------- */

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  width: min(92vw, 380px);
  background: var(--sa-surface);
  border: 1px solid var(--sa-border-decorative);
  border-radius: var(--sa-radius-panel);
  padding: 40px 36px 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-word { font-weight: 700; letter-spacing: 0.14em; font-size: 18px; }
.login-mark { border-radius: 8px; }
.login-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.login-sub { margin: 0 0 20px; }
.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--sa-error);
  background: var(--sa-background);
  border: 1px solid var(--sa-border-decorative);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 16px;
  font-size: 14px;
}
.login-form { display: flex; flex-direction: column; gap: 8px; }
.login-form label { margin-top: 8px; }
.login-form .btn { margin-top: 20px; justify-content: center; }
.login-foot { margin: 20px 0 0; font-size: 13px; }

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

.player-page {
  --player-height: 128px;
  padding-bottom: var(--player-height);
}
.shell {
  display: flex;
  min-height: calc(100dvh - var(--player-height, 0px));
}
.sidebar {
  width: 224px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 16px;
  border-right: 1px solid var(--sa-border-decorative);
}
.brand-wordmark { display: block; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--sa-text-secondary);
  font-weight: 500;
  font-size: 15px;
  text-decoration: none;
  text-align: left;
}
.nav-item:hover { color: var(--sa-text); background: var(--sa-surface); }
.nav-item.active {
  color: var(--sa-accent-text);
  background: var(--sa-surface);
}
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--sa-border-decorative);
  padding-top: 16px;
}
.account-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  color: var(--sa-text-secondary);
  font-size: 14px;
}
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 48px;
  max-width: 860px;
}

.eyebrow {
  display: block;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sa-text-secondary);
  margin-bottom: 8px;
}
.page-title { font-size: 36px; font-weight: 700; line-height: 1.15; margin: 0 0 8px; }
.section-title {
  font-size: 16px;
  font-weight: 700;
  margin: 24px 0 12px;
}
.status-line { min-height: 22px; margin: 0 0 16px; font-size: 14px; }

/* --- search -------------------------------------------------------------- */

.search-form { display: flex; gap: 8px; margin-bottom: 16px; }
.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--sa-surface);
  border: 1px solid var(--sa-border-control);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--sa-text-secondary);
}
.search-box:focus-within { border-color: var(--sa-text); }
.search-box input {
  flex: 1;
  border: 0;
  background: none;
  padding: 10px 0;
  min-height: 44px;
}
.search-box input:focus { outline: none; }
.search-box:focus-within input { outline: none; }
.search-box:has(input:focus-visible) { outline: 2px solid var(--sa-focus); outline-offset: 3px; }

/* --- track rows ----------------------------------------------------------- */

.track-list { list-style: none; margin: 0; padding: 0; }
.track-row {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--sa-border-decorative);
}
.track-row:hover { background: color-mix(in srgb, var(--sa-surface) 55%, transparent); }
.track-row.active .track-title { color: var(--sa-accent-text); }
.row-num {
  width: 24px;
  text-align: right;
  color: var(--sa-text-secondary);
  font-size: 12px;
  flex: none;
}
.row-thumb, .row-thumb-empty {
  width: 48px;
  height: 48px;
  border-radius: var(--sa-radius-artwork);
  object-fit: cover;
  background: var(--sa-surface);
  flex: none;
}
.row-thumb-empty {
  display: grid;
  place-items: center;
  color: var(--sa-text-secondary);
}
.row-meta { flex: 1; min-width: 0; }
.track-title {
  display: block;
  font-weight: 600;
  font-size: 16px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-artist {
  display: block;
  color: var(--sa-text-secondary);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-duration {
  color: var(--sa-text-secondary);
  font-size: 12px;
  flex: none;
}

/* state chips: icon + words, never color alone */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  font-size: 12px;
  color: var(--sa-text-secondary);
}
.chip.running, .chip.queued { color: var(--sa-accent-text); }
.chip.failed { color: var(--sa-error); }
.chip.ready { color: var(--sa-success); }
.chip .sa-icon { width: 14px; height: 14px; }

.row-actions { display: flex; gap: 2px; flex: none; }
.row-actions .icon-btn { width: 40px; height: 40px; }
.row-actions .sa-icon { width: 18px; height: 18px; }
a.icon-btn { color: var(--sa-text-secondary); }
a.icon-btn:hover { color: var(--sa-text); }

/* empty / loading states */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 16px;
  text-align: center;
  color: var(--sa-text-secondary);
}
.empty-state img { width: 96px; height: 96px; opacity: 0.5; border-radius: var(--sa-radius-artwork); }
.empty-state strong { color: var(--sa-text); font-weight: 600; }

/* --- playlists ------------------------------------------------------------- */

.generate-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}
.playlist-hero {
  display: flex;
  gap: 24px;
  align-items: flex-end;
  margin: 16px 0 24px;
  flex-wrap: wrap;
}
.playlist-cover { border-radius: var(--sa-radius-artwork); }
.playlist-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.playlist-row .track-title { font-weight: 600; }

/* --- player bar -------------------------------------------------------------- */

.player {
  position: fixed;
  z-index: 10;
  left: 0; right: 0; bottom: 0;
  height: var(--player-height);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 44%) minmax(0, 1fr);
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--sa-surface);
  border-top: 1px solid var(--sa-border-decorative);
}
.player-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.player-art {
  width: 56px;
  height: 56px;
  border-radius: var(--sa-radius-artwork);
  background: var(--sa-background) url("/static/brand/grooves.svg") center/cover no-repeat;
  opacity: 0.85;
  flex: none;
}
.player-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.player-meta .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  min-width: 0;
}
.player-controls { display: flex; align-items: center; gap: 8px; }
.player-seek {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 560px;
}
.time { color: var(--sa-text-secondary); font-size: 12px; min-width: 40px; }
.time:last-child { text-align: right; }
#seek {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 44px;
  margin: 0;
  min-height: 44px; /* touch target; visual track is thinner */
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  border: 0;
  padding: 0;
  --fill: 0%;
}
#seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background:
    linear-gradient(var(--sa-progress-fill), var(--sa-progress-fill)) 0/var(--fill) 100% no-repeat,
    var(--sa-progress-track);
}
#seek::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--sa-progress-track);
}
#seek::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--sa-progress-fill);
}
#seek::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--sa-progress-fill);
  margin-top: -4px;
}
#seek::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 999px;
  background: var(--sa-progress-fill);
}
.player-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.player-options { display: flex; align-items: center; gap: 12px; }
.player-options .link-btn { white-space: nowrap; }
.state-line { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; min-height: 14px; }
.state-line:empty { display: none; }
.player-side .state-line { max-width: 100%; text-align: right; overflow-wrap: anywhere; }
.state-line.error { color: var(--sa-error); }

/* toggle switch */
.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 44px; height: 44px; margin: 0; cursor: pointer; }
.toggle-track {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--sa-background);
  border: 1px solid var(--sa-border-control);
  position: relative;
  flex: none;
  transition: background-color var(--sa-motion-ms-transition) ease;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 999px;
  background: var(--sa-text-secondary);
  transition: transform var(--sa-motion-ms-transition) ease;
}
.toggle input:checked + .toggle-track { background: var(--sa-accent); border-color: var(--sa-accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); background: var(--sa-on-accent); }
.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--sa-focus);
  outline-offset: 3px;
}
.toggle-label { font-size: 14px; color: var(--sa-text-secondary); }

/* --- tables (admin) ------------------------------------------------------- */

.panel {
  background: var(--sa-surface);
  border: 1px solid var(--sa-border-decorative);
  border-radius: var(--sa-radius-panel);
  padding: 24px;
  margin-bottom: 24px;
}
.row-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.row-form input, .row-form select { flex: 1; min-width: 140px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  color: var(--sa-text-secondary);
  font-weight: 500;
  font-size: 12px;
  font-family: var(--sa-font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px;
  border-bottom: 1px solid var(--sa-border-control);
}
.table td { padding: 10px 8px; border-bottom: 1px solid var(--sa-border-decorative); }
.table select { min-height: 36px; padding: 4px 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--sa-radius-pill);
  padding: 3px 10px;
  font-size: 12px;
  font-family: var(--sa-font-mono);
}
.badge.enabled { color: var(--sa-success); border: 1px solid var(--sa-border-control); }
.badge.disabled { color: var(--sa-error); border: 1px solid var(--sa-border-control); }

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

@media (max-width: 960px) {
  .content { padding: 24px 20px 40px; }
  .player { grid-template-columns: minmax(0, 1fr) minmax(280px, 1.3fr); gap: 16px; padding-inline: 16px; }
  .player-side { display: none; }
}
@media (max-width: 720px) {
  .player-page { --player-height: 172px; }
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--sa-border-decorative);
    overflow-x: auto;
  }
  .sidebar-brand { margin-right: auto; }
  .brand-wordmark { width: 92px; height: auto; }
  .sidebar-nav { flex-direction: row; }
  .nav-item { width: auto; padding: 0 10px; }
  .nav-item span { display: none; } /* icons only at phone width; aria-labels carry names */
  .sidebar-foot { margin: 0; border: 0; padding: 0; flex-direction: row; }
  .account-chip { display: none; }
  .page-title { font-size: 28px; }
  .playlist-hero { align-items: flex-start; flex-direction: column; }
  .player { grid-template-columns: minmax(0, 1fr); grid-template-rows: 44px 1fr; gap: 4px; padding: 10px 16px; }
  .player-center { width: 100%; }
  .player .btn-play { width: 48px; height: 48px; }
  .player-art { width: 44px; height: 44px; }
}

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

.activity-track { min-width: 220px; max-width: 320px; overflow-wrap: anywhere; }

.content.admin-content { max-width: 1560px; }
.activity-table { min-width: 1120px; }
.activity-table td { vertical-align: top; }
.activity-table th { white-space: nowrap; }
.activity-table td:nth-child(3) { min-width: 160px; }
.activity-table td:nth-child(7) { max-width: 200px; overflow-wrap: anywhere; }
.activity-table td:last-child { white-space: nowrap; }
