/* VireTV Admin - Material Design 3 (dark, brand blue). Tokens first, then components. */
:root {
  color-scheme: dark;
  --primary: #5ab4ee; --on-primary: #04223d; --primary-container: #1a4a78; --on-primary-container: #cfe6ff;
  --secondary-container: #24405f; --on-secondary-container: #d3e4fa;
  --surface: #0b1626; --surface-1: #101f35; --surface-2: #142741; --surface-3: #192f4d; --surface-4: #1e3758;
  --on-surface: #e6edf9; --on-surface-variant: #a9b8d0; --outline: #3d5a82; --outline-variant: #2a4263;
  --error: #ffb4ab; --on-error: #4b0d09; --error-container: #7a1a14;
  --success: #86e3a4; --warning: #ffd479;
  --r-s: 8px; --r-m: 12px; --r-l: 16px; --r-xl: 28px;
  --e1: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px 1px rgba(0, 0, 0, .18);
  --e2: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 6px 2px rgba(0, 0, 0, .2);
  --e3: 0 4px 8px 3px rgba(0, 0, 0, .28), 0 1px 3px rgba(0, 0, 0, .4);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--surface); color: var(--on-surface); font: 14px/1.5 Roboto, "Segoe UI", system-ui, -apple-system, sans-serif; letter-spacing: .01em; }
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; font-weight: 500; }
.icon { width: 24px; height: 24px; fill: currentColor; flex: none; }

/* ---- sign in ---- */
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 85% -10%, rgba(0, 200, 255, .14), transparent 60%), var(--surface); }
.login-card { width: min(420px, 100%); background: var(--surface-2); border-radius: var(--r-xl); padding: 32px 28px; box-shadow: var(--e3); }
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-card p.sub { color: var(--on-surface-variant); margin: 0 0 22px; }

/* ---- app frame ---- */
.appbar { position: sticky; top: 0; z-index: 20; height: 64px; display: flex; align-items: center; gap: 16px; padding: 0 20px 0 16px; background: var(--surface-2); box-shadow: var(--e1); }
.appbar .brand { font-size: 20px; font-weight: 500; }
.appbar .brand span { color: var(--primary); }
.appbar .grow { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r-s); border: 1px solid var(--outline); background: transparent; color: var(--on-surface-variant); font: inherit; font-size: 13px; white-space: nowrap; }
.chip.tonal { background: var(--secondary-container); border-color: transparent; color: var(--on-secondary-container); }
.chip.ok { background: rgba(134, 227, 164, .14); border-color: transparent; color: var(--success); }
.chip.warn { background: rgba(255, 212, 121, .14); border-color: transparent; color: var(--warning); }
.chip.bad { background: rgba(255, 180, 171, .14); border-color: transparent; color: var(--error); }
button.chip { cursor: pointer; }
button.chip:hover { background: var(--surface-3); }
button.chip.selected { background: var(--secondary-container); border-color: transparent; color: var(--on-secondary-container); }
.layout { display: grid; grid-template-columns: 88px 1fr; min-height: calc(100vh - 64px); }
.rail { position: sticky; top: 64px; align-self: start; height: calc(100vh - 64px); display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px 0; background: var(--surface-1); }
.rail a { width: 72px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--on-surface-variant); text-decoration: none; font-size: 12px; border-radius: var(--r-m); padding: 2px 0 6px; }
.rail a .pill { width: 56px; height: 32px; border-radius: 16px; display: grid; place-items: center; transition: background .15s; }
.rail a:hover .pill { background: var(--surface-3); }
.rail a.active { color: var(--on-surface); }
.rail a.active .pill { background: var(--secondary-container); color: var(--on-secondary-container); }
.rail a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.content { min-width: 0; padding: 24px; max-width: 1240px; width: 100%; margin: 0 auto; }
.page-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title h1 { font-size: 28px; font-weight: 400; }
.page-title .grow { flex: 1; }

/* ---- surfaces ---- */
.card { background: var(--surface-2); border-radius: var(--r-l); padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--e1); }
.card.outlined { background: transparent; box-shadow: none; border: 1px solid var(--outline-variant); }
.card h2 { font-size: 16px; margin-bottom: 14px; color: var(--on-surface); }
.card .sub { color: var(--on-surface-variant); }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.stat { background: var(--surface-2); border-radius: var(--r-l); padding: 16px 18px; box-shadow: var(--e1); }
.stat .label { color: var(--on-surface-variant); font-size: 13px; }
.stat .value { font-size: 32px; line-height: 1.2; font-weight: 400; margin-top: 2px; }
.stat .foot { color: var(--on-surface-variant); font-size: 12px; margin-top: 4px; }
.stat.accent { background: var(--primary-container); color: var(--on-primary-container); }
.stat.accent .label, .stat.accent .foot { color: var(--on-primary-container); opacity: .85; }
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r-m); background: rgba(255, 212, 121, .12); color: var(--warning); margin-bottom: 16px; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 22px; border: 0; border-radius: 20px; font: inherit; font-weight: 500; letter-spacing: .02em; cursor: pointer; background: var(--primary); color: var(--on-primary); transition: filter .15s, box-shadow .15s; }
.btn:hover { filter: brightness(1.1); box-shadow: var(--e1); }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.btn.tonal { background: var(--secondary-container); color: var(--on-secondary-container); }
.btn.outlined { background: transparent; color: var(--primary); border: 1px solid var(--outline); }
.btn.text { background: transparent; color: var(--primary); padding: 0 12px; }
.btn.danger { background: transparent; color: var(--error); border: 1px solid var(--error); }
.btn.danger.filled { background: var(--error); color: var(--on-error); border-color: transparent; }
.btn.small { height: 32px; padding: 0 14px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; filter: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; color: var(--on-surface-variant); display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--on-surface); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- fields ---- */
.field { display: block; position: relative; margin: 6px 0 14px; }
.field > span { position: absolute; left: 12px; top: -8px; padding: 0 4px; background: var(--surface-2); color: var(--on-surface-variant); font-size: 12px; }
.field input, .field select, .field textarea { width: 100%; height: 48px; padding: 0 14px; background: transparent; color: var(--on-surface); border: 1px solid var(--outline); border-radius: var(--r-s); font: inherit; }
.field textarea { height: auto; min-height: 84px; padding: 12px 14px; resize: vertical; }
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--on-surface-variant) 50%), linear-gradient(135deg, var(--on-surface-variant) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; }
.field select option { background: var(--surface-2); }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--on-surface-variant); }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border: 2px solid var(--primary); padding: 0 13px; }
.field textarea:focus { padding: 11px 13px; }
.field:focus-within > span { color: var(--primary); }
.card .field > span { background: var(--surface-2); }
.field.search { flex: 1; min-width: 220px; margin: 0; }
.dialog .field > span { background: var(--surface-3); }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 180px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; }
.checks label { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--outline); border-radius: var(--r-s); cursor: pointer; font-size: 13px; }
.checks input { accent-color: var(--primary); width: 16px; height: 16px; }
.error-text { color: var(--error); min-height: 1.3em; margin: 4px 0 0; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; border-radius: var(--r-m); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--on-surface-variant); padding: 12px 14px; border-bottom: 1px solid var(--outline-variant); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--outline-variant); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-3); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 6px; padding-top: 12px; color: var(--on-surface-variant); }
.empty { text-align: center; padding: 36px 12px; color: var(--on-surface-variant); }

/* ---- lists, bars ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--outline-variant); min-height: 52px; }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--on-surface-variant); font-size: 12px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bars .bar { flex: 1; min-width: 6px; max-width: 56px; background: var(--primary-container); border-radius: 6px 6px 2px 2px; position: relative; }
.bars .bar.now { background: var(--primary); }
.bars .bar span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--on-surface-variant); }
.bar-labels { display: flex; gap: 6px; margin-top: 6px; color: var(--on-surface-variant); font-size: 11px; }
.bar-labels span { flex: 1; text-align: center; min-width: 6px; overflow: hidden; }
.dist { display: grid; gap: 10px; }
.dist .row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 12px; }
.dist .track { height: 10px; border-radius: 5px; background: var(--surface-4); overflow: hidden; }
.dist .fill { height: 100%; background: var(--primary); border-radius: 5px; }

/* ---- dialog + snackbar ---- */
dialog.dialog { border: 0; padding: 0; border-radius: var(--r-xl); background: var(--surface-3); color: var(--on-surface); width: min(440px, calc(100vw - 32px)); box-shadow: var(--e3); }
dialog.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog form { padding: 24px 24px 18px; }
.dialog h2 { font-size: 22px; font-weight: 400; margin-bottom: 12px; }
.dialog p { color: var(--on-surface-variant); margin: 0 0 16px; }
.dialog .actions { justify-content: flex-end; margin-top: 8px; }
#snack { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 90px); background: #e6edf9; color: #10203a; padding: 12px 20px; border-radius: var(--r-s); box-shadow: var(--e3); transition: transform .25s; z-index: 50; max-width: calc(100vw - 32px); }
#snack.show { transform: translate(-50%, 0); }
#snack.error { background: var(--error); color: var(--on-error); }

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; z-index: 30; bottom: 0; top: auto; left: 0; right: 0; height: 68px; flex-direction: row; justify-content: space-around; padding: 6px 4px; box-shadow: 0 -2px 8px rgba(0, 0, 0, .4); }
  .rail a { width: auto; min-width: 0; flex: 1; }
  .rail a .pill { width: min(56px, 100%); }
  .content { padding: 16px 14px 92px; }
  .appbar .chip.tonal { display: none; }
  .dist .row { grid-template-columns: 90px 1fr 32px; }
}
