/* ==========================================================================
   PCTV Design System — PCTV-MUSE-WEB-002
   Palette (§4): bg #0B1218, secondary bg #14242D, accent #2DD4BF,
   primary text #F4F7F8, secondary text #A3B5BF.
   Type: Manrope (Google Fonts, progressive enhancement) with system fallback.
   Contrast (WCAG 2.2 AA, normal text >= 4.5:1):
     #F4F7F8 on #0B1218 = 15.9:1 | #A3B5BF on #0B1218 = 7.3:1
     #2DD4BF on #0B1218 = 8.4:1  | #06231F on #2DD4BF = 8.0:1
   All component states (default / hover / focus / disabled / error /
   loading / empty) are defined here; pages use only these classes.
   ========================================================================== */

:root {
  /* Colour tokens */
  --bg: #0B1218;
  --bg-2: #14242D;
  --surface: #111B24;
  --surface-2: #1A2B36;
  --text: #F4F7F8;
  --muted: #A3B5BF;
  --accent: #2DD4BF;
  --accent-ink: #06231F;
  --line: #22303A;
  --line-strong: #31424E;
  --warning: #F2A65A;
  --danger: #F26D6D;
  --danger-bg: #3A1B1E;
  --ok: #2DD4BF;
  --info: #7CC7E8;
  --focus: #2DD4BF;
  /* Type scale (Manrope, 1rem = 16px) */
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs-xs: 0.8125rem;
  --fs-sm: 0.9375rem;
  --fs-base: 1.05rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.6rem;
  --fs-2xl: 2.1rem;
  --fs-3xl: 2.8rem;
  /* Spacing + radii */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
  --maxw: 1120px;
  --maxw-wide: 1360px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-base); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--space-3); font-weight: 800; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--space-4); }
.lede { font-size: var(--fs-lg); color: var(--muted); max-width: 62ch; }
.small { font-size: var(--fs-sm); color: var(--muted); }
.muted { color: var(--muted); }
a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: #5FE3D2; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* Skip link (WCAG 2.2 AA: bypass blocks) */
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 10px 16px; font-weight: 700; z-index: 200; border-radius: 0 0 var(--radius-sm) 0; }
.skip-link:focus { left: 8px; top: 8px; }

/* --- Layout --- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.wrap-wide { max-width: var(--maxw-wide); margin: 0 auto; padding: 0 20px; }
main { padding: var(--space-6) 0 var(--space-7); }
section.block { margin-bottom: var(--space-7); }
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stack > * + * { margin-top: var(--space-3); }

/* --- Header / navigation --- */
header.site { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 100; }
header.site .bar { max-width: var(--maxw-wide); margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.logo { font-size: 1.5rem; font-weight: 800; letter-spacing: .01em; color: var(--text); text-decoration: none; }
.logo span { color: var(--accent); }
.logo .tag { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; margin-left: 8px; letter-spacing: .04em; }
nav.main { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
nav.main a { color: var(--text); text-decoration: none; padding: 8px 10px; border-radius: var(--radius-sm); font-weight: 600; font-size: var(--fs-sm); }
nav.main a:hover { background: var(--surface-2); }
nav.main a[aria-current="page"] { color: var(--accent); background: var(--bg-2); }
.nav-toggle { display: none; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; font: inherit; font-weight: 700; cursor: pointer; }
footer.site { border-top: 1px solid var(--line); padding: var(--space-6) 0; color: var(--muted); font-size: var(--fs-sm); }
footer.site .cols { display: flex; gap: var(--space-6); flex-wrap: wrap; justify-content: space-between; }
footer.site a { color: var(--muted); }
footer.site .disclaimer { max-width: 72ch; }

/* --- Buttons --- */
.btn, .btn-primary, .cta { display: inline-block; background: var(--accent); color: var(--accent-ink); border: 1px solid transparent; border-radius: var(--radius-sm); padding: 12px 20px; font: inherit; font-weight: 800; text-decoration: none; cursor: pointer; line-height: 1.3; }
.btn:hover, .btn-primary:hover, .cta:hover { background: #5FE3D2; color: var(--accent-ink); }
.btn.ghost, .cta.ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.ghost:hover, .cta.ghost:hover { background: var(--bg-2); }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--bg-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #F58A8A; }
.btn.small { padding: 8px 12px; font-size: var(--fs-sm); }
.btn[disabled], .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }

/* --- Cards --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); }
.card h3 { margin-top: 0; }
.card.accent { border-color: var(--accent); }
.card .meta { color: var(--muted); font-size: var(--fs-sm); }
.badge { display: inline-block; font-size: var(--fs-xs); font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted); }
.badge.accent { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.badge.warn { color: #2A1D05; background: var(--warning); border-color: var(--warning); }
.badge.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.badge.planned { color: var(--info); border-color: var(--info); }
.badge.staging { color: var(--warning); border-color: var(--warning); }

/* --- Forms --- */
form .field { margin-bottom: var(--space-4); }
label { display: block; font-weight: 700; margin-bottom: 6px; }
label .req { color: var(--danger); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; background: var(--bg-2); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 11px 12px; font: inherit; font-size: var(--fs-base);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.help { font-size: var(--fs-sm); color: var(--muted); margin-top: 4px; }
.field-error { font-size: var(--fs-sm); color: var(--danger); margin-top: 4px; font-weight: 600; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); margin: 0 0 var(--space-4); }
legend { font-weight: 800; padding: 0 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { width: auto; margin-top: 4px; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); background: var(--surface); }
caption { text-align: left; font-weight: 800; padding: var(--space-3) var(--space-4); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg-2); font-weight: 800; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Status / notifications / empty / loading / error --- */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: var(--fs-sm); }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warning); }
.status.bad { color: var(--danger); } .status.info { color: var(--info); } .status.muted { color: var(--muted); }
.notice { border: 1px solid var(--line-strong); border-left: 4px solid var(--accent); background: var(--surface); border-radius: var(--radius-sm); padding: var(--space-4); margin-bottom: var(--space-4); }
.notice.warn { border-left-color: var(--warning); }
.notice.error { border-left-color: var(--danger); background: var(--danger-bg); }
.notice h3, .notice h4 { margin-top: 0; }
.empty { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: var(--space-6); text-align: center; color: var(--muted); }
.empty h3 { color: var(--text); }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { color: var(--muted); }
.skeleton { background: var(--surface-2); border-radius: var(--radius-sm); min-height: 18px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .6; } 50% { opacity: 1; } }

/* --- Dialogues --- */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); padding: var(--space-5); max-width: 560px; width: calc(100vw - 40px); }
dialog::backdrop { background: rgba(4, 8, 11, .75); }
dialog h2 { margin-top: 0; }

/* --- KPIs / charts --- */
.kpis { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); }
.kpi .value { font-size: var(--fs-2xl); font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .label { color: var(--muted); font-size: var(--fs-sm); font-weight: 700; }
.kpi .delta { font-size: var(--fs-sm); font-weight: 700; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); }
.bar-row { display: grid; grid-template-columns: 140px 1fr 56px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: var(--fs-sm); }
.bar-track { background: var(--bg-2); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; }
.bar-fill.warn { background: var(--warning); }
.bar-fill.bad { background: var(--danger); }

/* --- Portal / Ops shells --- */
.shell { display: grid; grid-template-columns: 240px 1fr; gap: 0; align-items: start; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--line); padding: var(--space-4); position: sticky; top: 65px; min-height: calc(100vh - 65px); }
.sidebar nav a { display: block; color: var(--text); text-decoration: none; padding: 9px 10px; border-radius: var(--radius-sm); font-weight: 600; font-size: var(--fs-sm); }
.sidebar nav a:hover { background: var(--surface-2); }
.sidebar nav a[aria-current="page"] { background: var(--surface-2); color: var(--accent); }
.sidebar .group { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 800; margin: var(--space-4) 0 6px; }
.sidebar .who { font-size: var(--fs-sm); color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: var(--space-3); margin-bottom: var(--space-3); }
.content { padding: var(--space-5) var(--space-6) var(--space-7); min-width: 0; }
.content h1 { font-size: var(--fs-2xl); }
.toolbar { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; margin-bottom: var(--space-4); }
.toolbar input[type="search"] { max-width: 320px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: var(--space-4); }
.tabs a { color: var(--muted); text-decoration: none; padding: 10px 12px; font-weight: 700; font-size: var(--fs-sm); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.code { font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; font-size: var(--fs-sm); background: var(--bg-2); padding: 2px 6px; border-radius: 4px; }
pre.code-block { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); overflow-x: auto; font-size: var(--fs-sm); }
details.faq { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); margin-bottom: var(--space-3); }
details.faq summary { font-weight: 800; cursor: pointer; }
.steps { counter-reset: step; list-style: none; padding: 0; }
.steps li { counter-increment: step; padding-left: 44px; position: relative; margin-bottom: var(--space-4); }
.steps li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; display: flex; align-items: center; justify-content: center; }
.qr-placeholder { width: 200px; height: 200px; border: 2px dashed var(--line-strong); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: var(--space-4); background: #fff; color: #0B1218; font-weight: 700; }

/* --- Responsive --- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; min-height: 0; border-right: none; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar nav a { padding: 8px; }
  h1 { font-size: var(--fs-2xl); }
  .content { padding: var(--space-4); }
}
@media (max-width: 720px) {
  .nav-toggle { display: inline-block; }
  nav.main { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  nav.main.open { display: flex; }
  nav.main a { padding: 10px 4px; }
  .bar-row { grid-template-columns: 96px 1fr 48px; }
  .btn-row .btn, .btn-row .cta { width: 100%; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .spinner, .skeleton { animation: none; }
}
