/* MusicPlay — global design system (ADR-003: no client build step).
 * Dark-first, auto-light via prefers-color-scheme. Replaces Pico: owns the
 * reset, typography, base element styles, the app shell (sidebar on desktop /
 * topbar on mobile), and the shared components used across every page. The
 * dashboard layers chart-specific styles on top via /static/dashboard.css. */

/* ---------- Tokens ---------- */
:root {
  --d-bg: #0b0e16;
  --d-surface: #141a27;
  --d-surface-2: #1b2333;
  --d-elev: #212c41;
  --d-border: rgba(255, 255, 255, 0.08);
  --d-border-strong: rgba(255, 255, 255, 0.16);
  --d-text: #eef1f7;
  --d-muted: #9aa4b8;
  --d-faint: #7f8da0;
  --d-accent: #8b7bff;
  --d-accent-2: #38bdf8;
  --d-met: #34d399;
  --d-partial: #fbbf24;
  --d-danger: #fb7185;
  --d-unheard: #64748b;
  --d-grad: linear-gradient(135deg, #8b7bff 0%, #38bdf8 100%);
  --d-grad-soft: linear-gradient(135deg, rgba(139, 123, 255, 0.18), rgba(56, 189, 248, 0.12));
  --d-radius: 14px;
  --d-radius-sm: 9px;
  --d-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 28px rgba(0, 0, 0, 0.38);
  --d-sidebar-w: 232px;
  --d-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    --d-bg: #eef1f8;
    --d-surface: #ffffff;
    --d-surface-2: #f5f8fc;
    --d-elev: #ffffff;
    --d-border: rgba(15, 23, 42, 0.1);
    --d-border-strong: rgba(15, 23, 42, 0.18);
    --d-text: #0f172a;
    --d-muted: #56627a;
    --d-faint: #636e81;
    --d-unheard: #94a3b8;
    --d-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.08);
  }
}

/* ---------- Reset & base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--d-font);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  color: var(--d-text);
  background: var(--d-bg);
  font-feature-settings: "cv11", "ss01";
}
h1,
h2,
h3,
h4 {
  margin: 0 0 0.4rem;
  line-height: 1.2;
  font-weight: 650;
}
h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 1rem;
}
p {
  margin: 0 0 0.75rem;
}
a {
  color: var(--d-accent-2);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
small {
  font-size: 0.82rem;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  background: var(--d-surface-2);
  border: 1px solid var(--d-border);
  border-radius: 6px;
  padding: 0.05rem 0.35rem;
}
hr {
  border: none;
  border-top: 1px solid var(--d-border);
  margin: 1rem 0;
}
time {
  font-variant-numeric: tabular-nums;
}

/* ---------- Forms ---------- */
label {
  display: block;
  margin-bottom: 0.75rem;
  font-weight: 550;
  font-size: 0.9rem;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--d-text);
  background: var(--d-surface-2);
  border: 1px solid var(--d-border-strong);
  border-radius: var(--d-radius-sm);
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--d-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--d-accent) 30%, transparent);
}
textarea {
  resize: vertical;
  min-height: 6rem;
}
label > input[type="checkbox"] {
  width: auto;
  margin: 0 0.45rem 0 0;
  accent-color: var(--d-accent);
  vertical-align: middle;
}
::placeholder {
  color: var(--d-faint);
}
.error {
  display: block;
  color: var(--d-danger);
  font-size: 0.85rem;
  margin: -0.4rem 0 0.6rem;
}

/* ---------- Buttons ---------- */
button,
a[role="button"],
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1;
  color: #0b0e16;
  background: var(--d-grad);
  border: 1px solid transparent;
  border-radius: var(--d-radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition:
    filter 0.15s,
    transform 0.05s;
}
button:hover,
a[role="button"]:hover,
.btn:hover {
  filter: brightness(1.08);
  text-decoration: none;
}
button:active,
.btn:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}
/* Secondary / ghost buttons (and HTMX action buttons in tables). */
.btn-ghost,
a.secondary,
a[role="button"].secondary,
table button {
  color: var(--d-text);
  background: var(--d-surface-2);
  border-color: var(--d-border-strong);
}
.btn-ghost:hover,
table button:hover {
  border-color: var(--d-accent);
  filter: none;
}
/* Spotify-branded action (open/share the playlist). */
.btn-spotify {
  color: #ffffff;
  background: #1db954;
  border-color: #1db954;
}
.btn-spotify:hover {
  filter: brightness(1.08);
  color: #ffffff;
}
.btn-spotify svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: currentColor;
}

/* ---------- App shell ---------- */
/* Hidden toggle state holder. `display:none` keeps it out of the tab order and
 * the a11y tree; `<label for>` still toggles it, so the CSS-only menu works. */
.nav-toggle {
  display: none;
}
/* Screen-reader-only utility + the mobile "close menu" affordance. */
.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;
}
.sidebar-close {
  display: none;
}
.app {
  display: grid;
  grid-template-columns: var(--d-sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 0.75rem;
  background: var(--d-surface);
  border-right: 1px solid var(--d-border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem 0.9rem;
  font-weight: 750;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.brand .mark {
  display: inline-grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 8px;
  background: var(--d-grad);
  color: #0b0e16;
  font-size: 0.95rem;
}
.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--d-radius-sm);
  color: var(--d-muted);
  font-weight: 550;
  font-size: 0.92rem;
}
.nav a:hover {
  background: var(--d-surface-2);
  color: var(--d-text);
  text-decoration: none;
}
.nav a.active {
  background: var(--d-grad-soft);
  color: var(--d-text);
  box-shadow: inset 2px 0 0 var(--d-accent);
}
.nav a .ico {
  font-size: 1rem;
  width: 1.2rem;
  text-align: center;
}
.sidebar-foot {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--d-border);
}
.sidebar-foot form {
  margin: 0;
}
.sidebar-foot button {
  width: 100%;
  justify-content: center;
  color: var(--d-muted);
  background: transparent;
  border-color: var(--d-border-strong);
}
.sidebar-foot button:hover {
  color: var(--d-text);
  filter: none;
}
.main-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: none;
}
.content {
  width: 100%;
  min-width: 0;
  padding: 1.5rem clamp(1rem, 2vw, 2rem) 3rem;
  max-width: 1240px;
}

/* Mobile: collapse the sidebar behind a topbar hamburger (CSS-only). */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.9rem;
    background: var(--d-surface);
    border-bottom: 1px solid var(--d-border);
  }
  .topbar .brand {
    padding: 0;
    font-size: 1rem;
  }
  .hamburger {
    display: inline-grid;
    place-items: center;
    width: 2.2rem;
    height: 2.2rem;
    padding: 0;
    color: var(--d-text);
    background: var(--d-surface-2);
    border: 1px solid var(--d-border-strong);
    border-radius: var(--d-radius-sm);
    font-size: 1.1rem;
    cursor: pointer;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: min(80vw, var(--d-sidebar-w));
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--d-shadow);
  }
  .nav-toggle:checked ~ .app .sidebar {
    transform: translateX(0);
  }
  /* Dimmed backdrop when the menu is open. */
  .nav-toggle:checked ~ .scrim {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.5);
  }
  .content {
    padding: 1rem 1rem 2.5rem;
  }
}
@media (min-width: 861px) {
  .scrim,
  .hamburger {
    display: none;
  }
}

/* ---------- Page head ---------- */
.page-head,
.page-header {
  margin-bottom: 1.25rem;
}
.page-head h1,
.page-header h1 {
  margin-bottom: 0.2rem;
}
.page-head .sub,
.page-header p {
  margin: 0;
  color: var(--d-muted);
  font-size: 0.95rem;
}

/* ---------- Cards / sections ---------- */
.card,
.content > section {
  background: var(--d-surface);
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius);
  box-shadow: var(--d-shadow);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.card > h2:first-child,
.content > section > h2:first-child {
  margin-top: 0;
}
hgroup {
  margin-bottom: 1rem;
}
hgroup h1 {
  margin-bottom: 0.15rem;
}
hgroup p {
  margin: 0;
  color: var(--d-muted);
}
dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  margin: 0.5rem 0;
}
dt {
  color: var(--d-muted);
  font-size: 0.85rem;
}
dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

/* Admin home shortcut grid. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.grid > article {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--d-surface);
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius);
  box-shadow: var(--d-shadow);
  padding: 1.1rem 1.2rem;
}
.grid > article p {
  flex: 1;
  color: var(--d-muted);
  margin: 0;
}
.grid > article > header {
  font-weight: 650;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--d-radius-sm);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th,
td {
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--d-border);
  vertical-align: middle;
}
th {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--d-muted);
  font-weight: 600;
}
tbody tr:hover {
  background: var(--d-surface-2);
}
table button {
  padding: 0.32rem 0.6rem;
  font-size: 0.82rem;
  white-space: nowrap;
}
td a {
  white-space: nowrap;
}

/* ---------- Badges & banners ---------- */
.badge {
  display: inline-block;
  padding: 0.13rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.5;
  background: color-mix(in srgb, var(--d-unheard) 22%, transparent);
  color: var(--d-text);
}
.badge.ok,
.badge-compliant {
  background: color-mix(in srgb, var(--d-met) 18%, transparent);
  color: var(--d-met);
}
.badge.pending,
.badge-not-yet {
  background: color-mix(in srgb, var(--d-partial) 18%, transparent);
  color: var(--d-partial);
}
.badge.miss,
.badge.error {
  background: color-mix(in srgb, var(--d-danger) 18%, transparent);
  color: var(--d-danger);
}
.badge.inactive,
.badge-untracked,
.badge.muted {
  background: color-mix(in srgb, var(--d-unheard) 22%, transparent);
  color: var(--d-muted);
}
.badge.voltas {
  background: color-mix(in srgb, var(--d-accent) 20%, transparent);
  color: var(--d-accent);
}

/* ---------- Weekly scoreboard (the board, `/`) ---------- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}
.kpi-strip .kpi {
  background: var(--d-surface);
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius);
  box-shadow: var(--d-shadow);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.kpi-strip .kpi-num {
  font-size: 1.5rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-strip .kpi-label {
  font-size: 0.8rem;
  color: var(--d-muted);
}
.scoreboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.score-row {
  display: grid;
  grid-template-columns: auto 1fr minmax(7rem, 1.3fr) auto auto;
  align-items: center;
  gap: 0.5rem 0.9rem;
  background: var(--d-surface);
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius);
  padding: 0.6rem 0.9rem;
}
.score-row.is-compliant {
  border-color: color-mix(in srgb, var(--d-met) 35%, var(--d-border));
}
.score-row.band-inactive {
  opacity: 0.62;
}
.score-row .rank {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--d-faint);
  min-width: 1.4rem;
  text-align: right;
}
.score-row .who {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.score-row .who-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.score-row .who-band {
  font-size: 0.78rem;
  color: var(--d-muted);
}
.score-row .prog {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.score-row .bar {
  height: 7px;
  border-radius: 999px;
  background: var(--d-surface-2);
  overflow: hidden;
}
.score-row .bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--d-grad);
}
.score-row .frac {
  font-size: 0.76rem;
  color: var(--d-muted);
  font-variant-numeric: tabular-nums;
}
.score-row .pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: flex-end;
}
.score-row .score-link {
  font-size: 1.15rem;
  color: var(--d-muted);
  text-decoration: none;
  padding: 0 0.2rem;
}
.score-row .score-link:hover {
  color: var(--d-accent-2);
}
.board-foot {
  margin-top: 1rem;
  color: var(--d-muted);
}
@media (max-width: 640px) {
  .kpi-strip {
    grid-template-columns: 1fr 1fr;
  }
  .score-row {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "rank who link"
      "rank prog prog"
      "rank pills pills";
    row-gap: 0.45rem;
  }
  .score-row .rank {
    grid-area: rank;
    align-self: start;
  }
  .score-row .who {
    grid-area: who;
  }
  .score-row .prog {
    grid-area: prog;
  }
  .score-row .pills {
    grid-area: pills;
    justify-content: flex-start;
  }
  .score-row .score-link {
    grid-area: link;
    align-self: start;
  }
}
.banner {
  border-left: 3px solid var(--d-accent);
  background: var(--d-surface-2);
  padding: 0.7rem 0.9rem;
  border-radius: var(--d-radius-sm);
  margin-bottom: 1rem;
}
.banner-warning {
  border-left-color: var(--d-partial);
  background: color-mix(in srgb, var(--d-partial) 12%, var(--d-surface));
}

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--d-border-strong);
  border-radius: var(--d-radius);
  background: var(--d-surface);
  box-shadow: none;
}
.empty-state h2 {
  margin-bottom: 0.3rem;
}
.empty-state p {
  color: var(--d-muted);
  margin-bottom: 1rem;
}
.empty-state a[role="button"] + a[role="button"] {
  margin-left: 0.5rem;
}

/* ---------- Auth (login) ---------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--d-surface);
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius);
  box-shadow: var(--d-shadow);
  padding: 1.75rem;
}
.auth-card .brand {
  justify-content: center;
  padding: 0 0 1rem;
}
.auth-card button {
  width: 100%;
  justify-content: center;
  margin-top: 0.25rem;
}
.auth-alt {
  margin: 1rem 0 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--d-muted);
}

/* ---------- Board: bands & member cards ---------- */
section.band {
  margin-bottom: 1.25rem;
}
section.band > h2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--d-border);
  margin-bottom: 0.85rem;
}
section.band[data-band-active="0"] {
  opacity: 0.62;
}
article.member {
  margin: 0 0 0.75rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius-sm);
  background: var(--d-surface-2);
}
article.member > header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
article.member h3 {
  margin: 0;
}
article.member .username {
  margin: 0;
  color: var(--d-faint);
  font-size: 0.85rem;
}
article.member .status {
  margin: 0.25rem 0;
}
article.member .status strong {
  color: var(--d-accent-2);
}
article.member .tracking-meta,
article.member .history-empty {
  font-size: 0.84rem;
  color: var(--d-muted);
  margin: 0.25rem 0 0;
}
article.member .card-actions {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
}
details.history {
  margin-top: 0.5rem;
}
details.history summary {
  cursor: pointer;
  color: var(--d-muted);
  font-size: 0.88rem;
}
details.history ul {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
}
details.history li {
  margin: 0.2rem 0;
  font-size: 0.88rem;
}

/* A collapsible form panel (e.g. "+ Novo participante"). */
details.form-panel {
  background: var(--d-surface);
  border: 1px solid var(--d-border);
  border-radius: var(--d-radius);
  box-shadow: var(--d-shadow);
  padding: 0.4rem 1.2rem;
  margin-bottom: 1.25rem;
}
details.form-panel[open] {
  padding-bottom: 1.2rem;
}
details.form-panel > summary {
  cursor: pointer;
  font-weight: 650;
  padding: 0.7rem 0;
  list-style: none;
}
details.form-panel > summary::-webkit-details-marker {
  display: none;
}
details.form-panel > summary::before {
  content: "＋ ";
  color: var(--d-accent);
}
details.form-panel[open] > summary::before {
  content: "－ ";
}
/* Sub-sections inside the "Avançado" panel: light separators + compact headings. */
details.form-panel > section + section {
  border-top: 1px solid var(--d-border);
  padding-top: 1rem;
  margin-top: 1rem;
}
details.form-panel > section > h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}

.muted {
  color: var(--d-muted);
}
.nowrap {
  white-space: nowrap;
}
/* Playlist change-history log. */
.changelog {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.changelog-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.85rem;
  padding: 0.6rem 0.3rem;
  border-bottom: 1px solid var(--d-border);
}
.changelog-item:last-child {
  border-bottom: none;
}
.changelog-when {
  color: var(--d-faint);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  min-width: 9.5rem;
}
.changelog-badge {
  font-weight: 650;
  font-size: 0.85rem;
}
.changelog-added .changelog-badge {
  color: var(--d-met);
}
.changelog-removed .changelog-badge {
  color: var(--d-danger);
}
/* The mobile "close menu" affordance lives inside the sidebar; shown only when
 * the sidebar overlays the content (≤860px). */
@media (max-width: 860px) {
  .sidebar-close {
    display: inline-grid;
    place-items: center;
    align-self: flex-end;
    width: 2rem;
    height: 2rem;
    margin: -0.25rem -0.25rem 0.5rem auto;
    border-radius: var(--d-radius-sm);
    color: var(--d-muted);
    background: var(--d-surface-2);
    border: 1px solid var(--d-border);
    font-size: 1rem;
    cursor: pointer;
  }
}
.share-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.share-row .muted {
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
