/*
 * card_web control panel stylesheet.
 *
 * Hand-authored design-system CSS committed as a static asset (no Node on prod,
 * per PRD). It provides the layout + component classes the panel templates use.
 * Dark theme ONLY (no light mode). Aesthetic: dense ops dashboard, Linear /
 * Grafana-adjacent restraint - one blue accent, one radius system, mono tabular
 * numbers for every metric, no gradients / glows / decorative dots.
 *
 * ---------------------------------------------------------------------------
 * COMPONENT CLASS REFERENCE (wave-2 page authors: use these, don't reinvent)
 * ---------------------------------------------------------------------------
 *   .page-head        h1 + optional .toolbar on one row (page title bar)
 *   .stat-grid        responsive auto-fit grid of stat cards
 *   .stat-card        label + large mono value; optional sparkline slot + link.
 *                     Variants: <a class="stat-card"> makes the whole tile a link
 *   .stat-card .stat-label / .stat-value / .stat-sub   inner text rows
 *   .stat-delta.up / .stat-delta.down   small +/- trend chip (accent/danger)
 *   .chart            responsive SVG (viewBox scales to 100% width) - from charts.py
 *   .spark            tiny inline sparkline (stat-card slot) - from charts.py
 *   .tabs             horizontal link tabs for sibling pages (a.active = current)
 *   .empty-state      friendly centered "nothing here yet" block
 *   .filter-input     client-side list filter; pair with data-filter-target="#id"
 *                     (panel.js hides non-matching rows of the target table)
 *   .num              right-aligned tabular-mono cell for table numerics
 *   .quick-actions    row of one-click action links (.quick-action items)
 *   .service-row      one service status line (name + .badge)
 * Existing shared classes kept stable: .card-panel .table-wrap .toolbar
 *   .inline-form .badge.status-* button.secondary button.danger .tier-group
 *   .count-pill .flashes .movie-list .num
 * ---------------------------------------------------------------------------
 */
:root {
  --bg: #0f1115;
  --panel: #161a20;
  --panel-2: #1c212a;
  --border: #272d38;
  --text: #e4e6eb;
  --muted: #9aa0aa;
  --accent: #5b8def;
  --accent-soft: rgba(91, 141, 239, 0.14);
  --danger: #e5534b;
  --ok: #3fb950;
  --warn: #d29922;
  --radius: 10px;      /* panels / cards */
  --radius-sm: 6px;    /* controls / inputs / buttons */
  --sidebar-w: 220px;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", "Roboto Mono",
               Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto,
        "Noto Sans CJK TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
h1, h2, h3 { font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* --- App shell: sidebar + content ------------------------------------- */
.layout { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  padding: 0.25rem 0.5rem 0.75rem;
}
.sidebar .brand:hover { text-decoration: none; }

/* Expandable nav groups: <details class="nav-group"><summary>label</summary> */
.nav-group { border: none; }
.nav-group > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.5rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  user-select: none;
}
.nav-group > summary:hover { color: var(--text); background: var(--panel-2); }
.nav-group > summary::-webkit-details-marker { display: none; }
/* Chevron drawn in CSS (no icon lib); rotates when the group is open. */
.nav-group > summary::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
  margin-left: 0.5rem;
  opacity: 0.7;
}
.nav-group[open] > summary::after { transform: rotate(45deg); }
.nav-links { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.15rem 0; }
.nav-link {
  display: block;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  border-left: 2px solid transparent;
}
.nav-link:hover { background: var(--panel-2); text-decoration: none; }
.nav-link.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--text);
}
/* User chip + logout pinned to the bottom of the sidebar. */
.sidebar .user-box {
  margin-top: auto;
  padding: 0.75rem 0.5rem 0.25rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.content { flex: 1 1 auto; padding: 1.5rem 1.75rem 3rem; min-width: 0; }
.content-inner { max-width: 1180px; margin-inline: auto; }

/* Mobile: the whole sidebar becomes a top strip (simplest correct collapse). */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto;
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content { padding: 1rem; }
}

/* --- Forms + buttons -------------------------------------------------- */
input, textarea, select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.6rem;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
textarea { width: 100%; min-height: 6rem; resize: vertical; }
label { display: inline-block; color: var(--muted); }
button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 500;
}
button:hover { filter: brightness(1.08); }
button.secondary { background: var(--panel-2); border-color: var(--border); color: var(--text); }
button.danger { background: var(--danger); border-color: var(--danger); }
button:disabled { cursor: not-allowed; filter: grayscale(0.4); opacity: 0.6; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 1rem 0;
}
.inline-form { display: inline; margin: 0; }
.card-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
}

/* --- Page head: title + optional toolbar on one row ------------------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.page-head h1 { margin: 0; }
.page-head .toolbar { margin: 0; }

/* --- Horizontal link tabs for sibling pages --------------------------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin: 0 0 1.25rem;
}
.tabs a {
  padding: 0.45rem 0.8rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* --- Stat cards ------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  margin: 1rem 0;
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  color: var(--text);
  min-width: 0;
}
a.stat-card { transition: border-color 0.15s ease, background 0.15s ease; }
a.stat-card:hover {
  text-decoration: none;
  border-color: var(--accent);
  background: var(--panel-2);
}
.stat-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.stat-sub { color: var(--muted); font-size: 0.8rem; }
.stat-delta {
  display: inline-block;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.stat-delta.up { color: var(--ok); border-color: var(--ok); }
.stat-delta.down { color: var(--danger); border-color: var(--danger); }
.stat-spark { margin-top: auto; height: 32px; }
.stat-spark .spark { display: block; width: 100%; height: 100%; }

/* --- Quick actions row ------------------------------------------------ */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0 1.5rem;
}
.quick-action {
  padding: 0.5rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}
.quick-action:hover {
  text-decoration: none;
  border-color: var(--accent);
  background: var(--panel-2);
}

/* --- Service status rows ---------------------------------------------- */
a.services-panel { display: block; color: var(--text); }
a.services-panel:hover { text-decoration: none; border-color: var(--accent); }
.service-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.service-row:last-child { border-bottom: none; }
.service-row .svc-name { font-family: var(--font-mono); font-size: 0.9rem; }

/* --- Empty state ------------------------------------------------------ */
.empty-state {
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  margin: 1rem 0;
}

/* --- Charts (from card_web.charts) ------------------------------------ */
.chart { display: block; width: 100%; height: auto; max-width: 100%; }

/* --- Client-side filter input ----------------------------------------- */
.filter-input { width: 100%; margin-bottom: 0.75rem; }

/* --- Tables ----------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
  margin: 0;
  background: var(--panel);
}
/* Bare tables not inside a .table-wrap still get their own frame. */
:not(.table-wrap) > table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 1rem 0;
}
th, td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--panel-2); }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--panel-2);
}
/* Sticky header within a scrollable .table-wrap. */
.table-wrap thead th { position: sticky; top: 0; z-index: 1; }
.select-cell { width: 4rem; text-align: center; }
.movies-cell { min-width: 12rem; max-width: 20rem; }
.movie-list {
  display: grid;
  gap: 0.35rem;
  list-style: none;
  padding: 0;
  margin: 0;
}
.movie-list li {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  overflow-wrap: anywhere;
}

/* --- Status badges ---------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
}
.badge.status-draft { color: var(--muted); }
.badge.status-pending { color: var(--warn); border-color: var(--warn); }
.badge.status-approved { color: var(--accent); border-color: var(--accent); }
.badge.status-live, .badge.status-ok { color: var(--ok); border-color: var(--ok); }
.badge.status-failed { color: var(--danger); border-color: var(--danger); }

/* --- Collapsible tier groups (player lookup Owned Stacks) ------------- */
#stack-filter { width: 100%; margin-bottom: 0.75rem; }
.tier-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  margin: 0.6rem 0;
}
.tier-group > summary {
  cursor: pointer;
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
}
.tier-group > summary::-webkit-details-marker { display: none; }
.tier-group > .table-wrap { border: none; }
.tier-group > .table-wrap table { margin: 0; border: none; border-radius: 0; }
.tier-dot {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}
.count-pill {
  display: inline-block;
  min-width: 2rem;
  padding: 0.1rem 0.5rem;
  text-align: center;
  border-radius: 999px;
  font-weight: 600;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid var(--border);
}

/* --- Flashes + images ------------------------------------------------- */
.flashes {
  list-style: none;
  padding: 0.75rem 1rem;
  margin: 0 0 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
}
.flashes li + li { margin-top: 0.4rem; }
.error { color: var(--danger); }
.deny-reason { color: #ff9b93; }
img.thumb, td img, .card-form-preview img { max-width: 200px; height: auto; border-radius: var(--radius-sm); }

/* --- Login page ------------------------------------------------------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
}
.login-card .brand {
  display: block;
  font-weight: 700;
  font-size: 1.2rem;
  margin-bottom: 1.25rem;
}
.login-card label { display: block; margin-bottom: 0.9rem; color: var(--muted); }
.login-card input { width: 100%; margin-top: 0.3rem; }
.login-card button { width: 100%; margin-top: 0.35rem; }

/* Respect reduced-motion: drop the transitions used above. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
