/* Manaki CMS — dark, premium festival-console theme.
   Chart DATA uses the validated categorical palette (charts.js); UI CHROME
   uses its own ink + a warm gold accent, so a status/brand colour never
   impersonates a data series. */

:root {
  --plane: #0d0d0d;          /* page background */
  --surface: #16161a;        /* panels */
  --surface-2: #1c1c21;      /* raised / hover */
  --surface-1: #1a1a19;      /* chart surface (matches validated palette) */
  --line: #2a2a30;           /* hairline borders */
  --line-2: #35353d;
  --ink: #f5f4ef;            /* primary text */
  --ink-2: #b9b8b0;          /* secondary text */
  --ink-3: #85847d;          /* muted */
  --gold: #e0a83c;           /* chrome accent (film / awards) */
  --gold-soft: rgba(224, 168, 60, 0.14);
  --gold-line: rgba(224, 168, 60, 0.38);
  --good: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Theme-dependent chrome fragments (dark defaults). */
  --sidebar-bg: linear-gradient(180deg, #151519, #101013);
  --brand-mark-bg: radial-gradient(circle at 30% 25%, #2a2a2f, #111 70%);
  --topbar-bg: rgba(13, 13, 13, 0.75);
  --btn-hover-bg: #26262c;
  --tooltip-bg: #0a0a0c;
  --login-bg: radial-gradient(1200px 600px at 50% -10%, #1a1a1f, #0a0a0c 70%);
  --track: #202027;          /* hbar track (charts) */
  --ok-ink: #a7e6a7;
  --error-ink: #f0a8a8;
  --warn-ink: #f0cf8e;
}

/* ── Light theme ──────────────────────────────────────────────────────────
   Same warm, premium console, inverted. Gold accent darkens so it stays
   legible on light surfaces. Chart DATA colours (charts.js CAT palette) are
   mid-tones and read on both themes; chrome fragments swap via the vars above. */
:root[data-theme="light"] {
  --plane: #f3f1ea;
  --surface: #ffffff;
  --surface-2: #efece3;
  --surface-1: #faf8f2;
  --line: #e4dfd2;
  --line-2: #d3cdbd;
  --ink: #1e1c16;
  --ink-2: #57534a;
  --ink-3: #8a877c;
  --gold: #9a6f16;
  --gold-soft: rgba(224, 168, 60, 0.18);
  --gold-line: rgba(154, 111, 22, 0.42);
  --good: #0a8a0a;
  --warn: #b7791f;
  --crit: #c0392b;
  --shadow: 0 10px 30px rgba(60, 50, 20, 0.12);

  --sidebar-bg: linear-gradient(180deg, #fbf9f4, #f1eee6);
  --brand-mark-bg: radial-gradient(circle at 30% 25%, #fff, #f0ece1 70%);
  --topbar-bg: rgba(255, 255, 255, 0.82);
  --btn-hover-bg: #e7e3d8;
  --tooltip-bg: #ffffff;
  --login-bg: radial-gradient(1200px 600px at 50% -10%, #ffffff, #ece8dd 70%);
  --track: #e7e3d8;
  --ok-ink: #1c7a1c;
  --error-ink: #b23636;
  --warn-ink: #8a6510;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }

/* ── Layout ───────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 20px;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  background: var(--brand-mark-bg);
  border: 1px solid var(--gold-line);
  display: grid; place-items: center;
  color: var(--gold); font-weight: 800; font-size: 1.05rem;
  box-shadow: inset 0 0 12px rgba(224,168,60,0.12);
}
.brand-name { font-weight: 700; font-size: 1.02rem; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.72rem; color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; }

.nav-group-label {
  font-size: 0.67rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--ink-3); padding: 16px 10px 7px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--ink-2); font-size: 0.92rem; font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--gold-soft); color: var(--gold); }
.nav-link.active svg { color: var(--gold); }
.nav-link svg { width: 19px; height: 19px; color: var(--ink-3); flex-shrink: 0; }
.nav-link .count {
  margin-left: auto; font-size: 0.72rem; color: var(--ink-3);
  background: var(--surface); padding: 1px 7px; border-radius: 20px; border: 1px solid var(--line);
}
.nav-spacer { flex: 1; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 62px; flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 16px;
  padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 1.12rem; }
.topbar .sub { color: var(--ink-3); font-size: 0.85rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.chip {
  font-size: 0.78rem; color: var(--ink-2); background: var(--surface);
  border: 1px solid var(--line); padding: 5px 11px; border-radius: 20px;
}

.content { padding: 26px; max-width: 1320px; width: 100%; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface-2);
  color: var(--ink); font-size: 0.88rem; font-weight: 550; cursor: pointer;
  font-family: var(--sans); transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--btn-hover-bg); border-color: var(--line-2); }
.btn-primary {
  background: linear-gradient(180deg, #edb84e, #d89a2c);
  color: #1c1400; border: none; font-weight: 650;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { color: #f0a0a0; border-color: rgba(208,59,59,0.4); background: rgba(208,59,59,0.1); }
.btn-danger:hover { background: rgba(208,59,59,0.2); }
.btn-sm { padding: 6px 11px; font-size: 0.82rem; }
.btn-ghost { background: transparent; border-color: var(--line); }

/* ── Flash messages ───────────────────────────────────────────────────── */
.flashes { margin-bottom: 18px; display: flex; flex-direction: column; gap: 9px; }
.flash {
  padding: 11px 15px; border-radius: var(--radius-sm); font-size: 0.88rem;
  border: 1px solid var(--line-2); background: var(--surface);
}
.flash.ok { border-color: rgba(12,163,12,0.4); background: rgba(12,163,12,0.1); color: var(--ok-ink); }
.flash.error { border-color: rgba(208,59,59,0.45); background: rgba(208,59,59,0.12); color: var(--error-ink); }
.flash.warn { border-color: var(--gold-line); background: var(--gold-soft); color: var(--warn-ink); }

/* ── Cards / panels ───────────────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.panel-head { display: flex; align-items: center; margin-bottom: 16px; gap: 12px; }
.panel-head h3 { font-size: 1rem; }
.panel-head .panel-sub { color: var(--ink-3); font-size: 0.82rem; }
.panel-head .spacer { flex: 1; }

.page-head { display: flex; align-items: flex-end; margin-bottom: 22px; gap: 16px; }
.page-head .spacer { flex: 1; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); font-size: 0.9rem; }

/* ── Stat tiles ───────────────────────────────────────────────────────── */
.stat-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 17px 18px;
  position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--gold); opacity: 0.0; transition: opacity 0.2s;
}
.stat:hover::after { opacity: 0.7; }
.stat .label { color: var(--ink-3); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value { font-size: 1.85rem; font-weight: 680; margin-top: 6px; letter-spacing: -0.02em; }
.stat .sub { color: var(--ink-3); font-size: 0.8rem; margin-top: 3px; }
.stat .sub b { color: var(--ink-2); font-weight: 600; }

/* ── Grid helpers ─────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.span-2 { grid-column: span 2; }
@media (max-width: 1080px) { .grid-2, .grid-3, .span-2 { grid-template-columns: 1fr; grid-column: auto; } }

/* ── Tables ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th {
  text-align: left; padding: 12px 16px; color: var(--ink-3);
  font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background 0.1s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 7px; justify-content: flex-end; }
.muted { color: var(--ink-3); }
.title-cell { font-weight: 600; }

/* ── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 0.74rem;
  border: 1px solid var(--line-2); color: var(--ink-2); background: var(--surface-2);
  white-space: nowrap; font-weight: 550;
}
.badge.gold { color: var(--gold); border-color: var(--gold-line); background: var(--gold-soft); }
.badge.on { color: var(--ok-ink); border-color: rgba(12,163,12,0.4); background: rgba(12,163,12,0.1); }
.badge.crit { color: var(--error-ink); border-color: rgba(208,59,59,0.4); background: rgba(208,59,59,0.1); }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-grid { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 820px) { .form-grid { grid-template-columns: 1fr; } }
.field label { display: block; font-size: 0.82rem; color: var(--ink-2); margin-bottom: 6px; font-weight: 550; }
.field .hint { font-size: 0.76rem; color: var(--ink-3); margin-top: 5px; }
input[type=text], input[type=email], input[type=password], input[type=url],
input[type=number], input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; background: var(--surface-1);
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  color: var(--ink); font-family: var(--sans); font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--gold-line); box-shadow: 0 0 0 3px var(--gold-soft);
}
textarea { resize: vertical; min-height: 84px; }
select[multiple] { min-height: 150px; }
.loc-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.loc-pair .tag { font-size: 0.7rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; display: block; }
.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--gold); }
.form-actions { display: flex; gap: 10px; margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.form-actions .spacer { flex: 1; }

/* ── Charts ───────────────────────────────────────────────────────────── */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px 18px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 0.8rem; color: var(--ink-2); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.chart-empty { color: var(--ink-3); font-size: 0.85rem; padding: 40px 0; text-align: center; }

.viz-tooltip {
  position: fixed; pointer-events: none; z-index: 100;
  background: var(--tooltip-bg); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 11px; font-size: 0.8rem; color: var(--ink);
  box-shadow: var(--shadow); opacity: 0; transition: opacity 0.08s; max-width: 260px;
}
.viz-tooltip .t-label { color: var(--ink-3); font-size: 0.74rem; }
.viz-tooltip .t-value { font-weight: 650; font-variant-numeric: tabular-nums; }

.axis text { fill: var(--ink-3); font-size: 11px; }
.axis line, .axis path { stroke: var(--line); }
.gridline { stroke: var(--line); stroke-dasharray: 2 4; }

/* ── Range filter ─────────────────────────────────────────────────────── */
.range-filter { display: inline-flex; border: 1px solid var(--line-2); border-radius: 20px; overflow: hidden; background: var(--surface); }
.range-filter a { padding: 6px 14px; font-size: 0.82rem; color: var(--ink-2); border-right: 1px solid var(--line); }
.range-filter a:last-child { border-right: none; }
.range-filter a.active { background: var(--gold-soft); color: var(--gold); font-weight: 600; }

/* ── Login ────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--login-bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 34px; box-shadow: var(--shadow); }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card h2 { text-align: center; margin-bottom: 4px; }
.login-card .lede { text-align: center; color: var(--ink-3); font-size: 0.86rem; margin-bottom: 24px; }
.login-card .field { margin-bottom: 15px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.login-hint { text-align: center; color: var(--ink-3); font-size: 0.78rem; margin-top: 18px; }

/* ── Misc ─────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-3); }
.empty-state h3 { color: var(--ink-2); margin-bottom: 8px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.hamburger { display: none; }
@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .hamburger { display: inline-flex; }
}

/* ── Theme toggle ─────────────────────────────────────────────────────────
   One button that swaps a page-wide `data-theme` attribute; the sun/moon
   glyphs show per current theme (sun = "switch to light", moon = "switch to
   dark"). Chrome colours cross-fade so the switch doesn't flash. */
html, body { transition: background-color 0.2s ease, color 0.2s ease; }
.sidebar, .topbar, .panel, .stat, .btn, .chip, .badge, table.data th,
.table-wrap, input, select, textarea, .range-filter, .flash {
  transition: background 0.2s ease, background-color 0.2s ease,
              border-color 0.2s ease, color 0.2s ease;
}
.theme-toggle {
  width: 38px; height: 38px; padding: 0; justify-content: center; flex-shrink: 0;
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: inline-flex; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: inline-flex; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
.login-theme-toggle { position: fixed; top: 18px; right: 18px; z-index: 10; }
