/* ==========================================================================
   Z3connect · DWTC Venue Intelligence — design system (light first)
   Fonts are embedded in css/fonts.css (SIL Open Font License) so the demo works offline.
   ========================================================================== */

:root,
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f7f8fa;
  --bg3: #f1f3f6;
  --panel: #ffffff;
  --panel2: #f7f8fa;
  --panel3: #eef1f5;
  --line: #e7eaf0;
  --line2: #d9dee6;
  --text: #0f172a;
  --text2: #334155;
  --muted: #5b6577;
  --faint: #8b94a5;
  --ink: #0f172a;
  --gold: #b8862b;
  --gold2: #a97a20;
  --gold-soft: #fbf3e2;
  --teal: #0e8a7c;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #c2780a;
  --green: #15925a;
  --violet: #7c3aed;
  --pink: #db2777;
  --orange: #ea580c;
  --c1: #2563eb; --c2: #0e9f8f; --c3: #c8932f; --c4: #db2777; --c5: #7c3aed; --c6: #ea580c;
  --ok-bg: #e9f8f0;
  --warn-bg: #fdf4e3;
  --bad-bg: #fdecec;
  --info-bg: #eaf1fe;
  --violet-bg: #f2ecfe;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .05);
  --shadow: 0 2px 6px rgba(16, 24, 40, .05), 0 12px 32px rgba(16, 24, 40, .08);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, .16);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --font: "InterVar", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, "NotoArabic", sans-serif;
  --display: "Jakarta", "InterVar", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --arabic: "NotoArabic", "Geeza Pro", "InterVar", sans-serif;
  --mono: "JBMono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar: 264px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1120; --bg2: #0f172a; --bg3: #131c31; --panel: #111a2e; --panel2: #152036; --panel3: #1b2740;
  --line: #233049; --line2: #2e3d5a; --text: #e9eef7; --text2: #c9d3e3; --muted: #9aa8bf; --faint: #6f7e98; --ink: #f8fafc;
  --gold: #e0ad4f; --gold2: #f0c56b; --gold-soft: rgba(224, 173, 79, .14); --teal: #2fc2b0; --blue: #60a5fa; --red: #f87171;
  --amber: #fbbf24; --green: #4ade80; --violet: #a78bfa; --pink: #f472b6; --orange: #fb923c;
  --c1: #60a5fa; --c2: #2dd4bf; --c3: #e0ad4f; --c4: #f472b6; --c5: #a78bfa; --c6: #fb923c;
  --ok-bg: rgba(74, 222, 128, .12); --warn-bg: rgba(251, 191, 36, .12); --bad-bg: rgba(248, 113, 113, .12); --info-bg: rgba(96, 165, 250, .12); --violet-bg: rgba(167, 139, 250, .14);
  --shadow-xs: none; --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow: 0 12px 34px rgba(0, 0, 0, .35); --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14.5px/1.55 var(--font); letter-spacing: -0.006em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01", "ss03";
}
h1, h2, h3, h4 { margin: 0; font-family: var(--display); line-height: 1.2; letter-spacing: -0.02em; color: var(--text); font-weight: 700; }
p { margin: 0 0 .6em; }
a { color: var(--teal); text-underline-offset: 3px; }
small { color: var(--muted); }
b, strong { font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: .9em; }
[dir="rtl"], [lang="ar"] { font-family: var(--arabic); letter-spacing: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
svg { flex: none; }
::selection { background: rgba(184, 134, 43, .22); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); height: 100vh; height: 100dvh; transition: grid-template-columns .25s ease; }
.sidebar { background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.brand { display: flex; gap: 12px; align-items: center; padding: 20px 16px 16px 20px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: linear-gradient(140deg, #0f172a 0%, #1e293b 100%); color: #f1c66a; font: 800 14px/1 var(--display); letter-spacing: -.04em;
  box-shadow: 0 6px 16px rgba(15, 23, 42, .25), inset 0 0 0 1px rgba(241, 198, 106, .35);
}
.brand-text { min-width: 0; flex: 1; }
.brand-text b { display: block; font: 700 15px/1.2 var(--display); letter-spacing: -.02em; white-space: nowrap; }
.brand-text small { font-size: 11.5px; white-space: nowrap; }
.rail-btn { width: 30px; height: 30px; border-color: transparent; background: transparent; }
.rail-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; transition: transform .25s; }
.nav { flex: 1; overflow: auto; padding: 6px 12px 12px; }
.nav-group { font: 600 10.5px/1 var(--font); text-transform: uppercase; letter-spacing: .09em; color: var(--faint); padding: 18px 10px 8px; white-space: nowrap; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; margin: 1px 0; color: var(--text2); text-decoration: none;
  border-radius: 10px; font-weight: 500; font-size: 14px; position: relative; white-space: nowrap; transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; opacity: .78; }
.nav a:hover { background: var(--panel3); color: var(--text); }
.nav a.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--line); }
.nav a.active::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold); }
.nav a.active svg { opacity: 1; color: var(--gold); }
.nav .code { margin-left: auto; font: 600 10.5px/1 var(--mono); padding: 4px 6px; border-radius: 6px; background: var(--gold-soft); color: var(--gold2); }
.side-foot { padding: 14px 18px 18px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.side-foot .note { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* collapsed rail */
.app.rail { --sidebar: 76px; }
.app.rail .brand { padding: 18px 12px 12px; flex-direction: column; gap: 8px; }
.app.rail .brand-text, .app.rail .nav-l, .app.rail .nav .code, .app.rail .side-foot, .app.rail .nav-group { display: none; }
.app.rail .rail-btn svg { transform: rotate(180deg); }
.app.rail .nav { padding: 6px 12px; }
.app.rail .nav a { justify-content: center; padding: 11px 0; }
.app.rail .nav a.active::before { left: -12px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar { position: relative; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: saturate(1.4) blur(14px); border-bottom: 1px solid var(--line); }
.tb-row { display: flex; align-items: center; gap: 14px; padding: 14px 28px 10px; }
.tb-title { min-width: 0; flex: 1; }
.crumb { display: flex; align-items: center; gap: 8px; min-width: 0; }
.crumb span { font-size: 13px; color: var(--faint); font-weight: 500; white-space: nowrap; }
.crumb i { color: var(--line2); font-style: normal; }
.crumb h1 { font: 700 18px/1.2 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tb-actions { display: flex; align-items: center; gap: 8px; }
.ctx-bar { display: flex; align-items: center; gap: 12px; padding: 0 28px 12px; flex-wrap: wrap; }
.ctx-field { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 500; }
.ctx-field select { width: auto; max-width: 340px; padding: 7px 30px 7px 11px; font-weight: 500; font-size: 13px; }
.ctx-live { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); }
.ctx-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--ok-bg); }
.menu-btn { display: none; }
.view { flex: 1; overflow: auto; padding: 26px 28px 40px; min-height: 0; scroll-behavior: smooth; }
.view:focus { outline: none; }
.view > * { max-width: 1680px; margin-left: auto; margin-right: auto; }

.clock { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-xs); }
.clk-btn { width: 30px; height: 30px; border-radius: 9px; font-size: 11px; background: var(--ink); color: var(--bg); border-color: transparent; }
.clk-btn:hover { background: var(--ink); opacity: .88; }
.clock.playing .clk-btn { background: var(--gold); color: #fff; }
.clk-read { display: grid; line-height: 1.1; min-width: 84px; }
.clk-read b { font: 600 14px/1.15 var(--mono); letter-spacing: -.02em; }
.clk-read small { font-size: 11px; }
.clock input[type=range] { width: 150px; }
.clock select { width: auto; padding: 5px 26px 5px 9px; font-size: 12.5px; border-color: transparent; background-color: var(--panel2); }

.bottom-nav { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none;
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel); color: var(--text);
  font-weight: 600; font-size: 13.5px; line-height: 1.2; white-space: nowrap; box-shadow: var(--shadow-xs);
  transition: transform .08s, background .15s, border-color .15s, box-shadow .15s, opacity .15s;
}
a.btn { color: var(--text); }
.btn svg { width: 15px; height: 15px; fill: currentColor; }
.btn:hover { border-color: var(--faint); background: var(--panel2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-dark, a.btn-dark { background: var(--ink); color: var(--bg); border-color: transparent; }
.btn-dark:hover { background: var(--ink); opacity: .9; }
.btn-primary { background: var(--teal); color: #fff; border-color: transparent; }
.btn-primary:hover { background: var(--teal); opacity: .92; }
.btn-gold, a.btn-gold { background: linear-gradient(180deg, #d4a142, #b8862b); color: #fff; border-color: transparent; box-shadow: 0 1px 2px rgba(120, 80, 10, .25), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn-gold:hover { background: linear-gradient(180deg, #d9a84b, #b0802a); border-color: transparent; }
.btn-danger { background: var(--red); color: #fff; border-color: transparent; }
.btn-danger:hover { background: var(--red); opacity: .92; }
.btn-ghost, a.btn-ghost { background: transparent; box-shadow: none; }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 9px; }
.btn-xs { padding: 4px 9px; font-size: 11.5px; border-radius: 7px; box-shadow: none; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text2); font-size: 15px;
}
.icon-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--panel2); color: var(--text); }
.icon-btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ---------- Cards & layout ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; min-width: 0; box-shadow: var(--shadow-xs); }
.card-tight { padding: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { font-size: 16px; }
.card-head .sub { font-size: 12.5px; color: var(--muted); }
.card h4 { font: 600 11px/1.3 var(--font); margin: 16px 0 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.g2, .g3, .g4, .g5 { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.split { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
.split-l { display: grid; gap: 18px; grid-template-columns: 310px minmax(0, 1fr); align-items: start; }
.split-3 { display: grid; gap: 18px; grid-template-columns: 300px minmax(0, 1fr) 340px; align-items: start; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hr { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.mt0 { margin-top: 0 !important; }
.hidden { display: none !important; }

/* ---------- Page intro ---------- */
.page-intro { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; align-items: end; margin-bottom: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.page-intro .eyebrow { display: flex; align-items: center; gap: 8px; font: 600 11.5px/1 var(--font); letter-spacing: .1em; color: var(--gold2); text-transform: uppercase; }
.page-intro h2 { font-size: clamp(23px, 2.2vw, 29px); margin-top: 8px; letter-spacing: -.028em; }
.page-intro p { color: var(--muted); max-width: 860px; margin: 8px 0 0; font-size: 14.5px; line-height: 1.6; }
.page-intro > .row { justify-content: flex-end; }

/* ---------- Chips & badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel2); color: var(--muted); white-space: nowrap; line-height: 1.5;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.no-dot::before { display: none; }
.chip-verified { color: var(--green); background: var(--ok-bg); border-color: transparent; }
.chip-sample { color: var(--amber); background: var(--warn-bg); border-color: transparent; }
.chip-synthetic { color: var(--violet); background: var(--violet-bg); border-color: transparent; }
.chip-bad { color: var(--red); background: var(--bad-bg); border-color: transparent; }
.chip-info { color: var(--blue); background: var(--info-bg); border-color: transparent; }
.chip-gold { color: var(--gold2); background: var(--gold-soft); border-color: transparent; }
.tag { font: 600 10.5px/1 var(--mono); padding: 4px 7px; border-radius: 6px; background: var(--gold-soft); color: var(--gold2); letter-spacing: .02em; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--c, var(--muted)); flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; min-width: 0; box-shadow: var(--shadow-xs); }
.kpi .k-l { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; gap: 6px; }
.kpi .k-v { font: 700 27px/1.15 var(--display); letter-spacing: -.03em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .k-s { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.45; }
.kpi.accent { background: linear-gradient(160deg, var(--gold-soft), var(--panel) 70%); border-color: color-mix(in srgb, var(--gold) 30%, var(--line)); }
.delta-up { color: var(--green); }
.delta-down { color: var(--red); }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; }
.field > span, .field > label { font-size: 12.5px; color: var(--text2); font-weight: 500; }
input[type=text], input[type=email], input[type=number], input[type=search], input[type=time], select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel); color: var(--text);
  transition: border-color .15s, box-shadow .15s; min-width: 0; font-size: 14px; box-shadow: var(--shadow-xs);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 15%, transparent); }
select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b94a5' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
textarea { resize: vertical; min-height: 70px; }
input[type=range] { accent-color: var(--gold); width: 100%; cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--ink); width: 16px; height: 16px; cursor: pointer; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; cursor: pointer; line-height: 1.45; }
.check input { margin-top: 2px; flex: none; }
.range-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.range-row output { font: 600 12px var(--mono); color: var(--text); min-width: 44px; text-align: right; padding: 3px 6px; border-radius: 6px; background: var(--panel2); }

.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--bg3); border: 1px solid var(--line); gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12.5px; transition: background .15s, color .15s; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .1), 0 0 0 1px var(--line); }
.seg button:hover:not(.on) { color: var(--text); }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; color: var(--text2); user-select: none; font-weight: 500; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 999px; background: var(--line2); position: relative; cursor: pointer; transition: background .2s; margin: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch input:checked { background: var(--ink); }
.switch input:checked::after { transform: translateX(14px); }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); padding: 11px 12px; border-bottom: 1px solid var(--line); background: var(--panel2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.t td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--panel2); }
.t tr.sel td { background: var(--gold-soft); }
.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t tr.click { cursor: pointer; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { border: 0; background: transparent; padding: 11px 14px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; transition: color .15s; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--ink); }

/* ---------- Callouts ---------- */
.callout { border: 1px solid var(--line); background: var(--panel2); padding: 12px 14px; border-radius: 12px; font-size: 13.5px; color: var(--text2); line-height: 1.55; position: relative; padding-left: 16px; }
.callout::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--teal); }
.callout.gold { background: var(--gold-soft); border-color: transparent; }
.callout.gold::before { background: var(--gold); }
.callout.warn { background: var(--warn-bg); border-color: transparent; }
.callout.warn::before { background: var(--amber); }
.callout.bad { background: var(--bad-bg); border-color: transparent; }
.callout.bad::before { background: var(--red); }
.callout.ok { background: var(--ok-bg); border-color: transparent; }
.callout.ok::before { background: var(--green); }
.callout b { color: var(--text); }

/* ---------- Toast & modal ---------- */
#toast-host { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 15px; border-radius: 14px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 13.5px; opacity: 0; transform: translateY(8px); transition: all .25s; }
.toast b { color: inherit; }
.toast.in { opacity: 1; transform: none; }
.toast-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: #60a5fa; flex: none; }
.toast-ok .toast-dot { background: #4ade80; }
.toast-warn .toast-dot { background: #fbbf24; }
.toast-bad .toast-dot { background: #f87171; }
.modal-wrap { position: fixed; inset: 0; background: rgba(15, 23, 42, .38); backdrop-filter: blur(4px); display: grid; place-items: center; z-index: 150; opacity: 0; transition: opacity .2s; padding: 16px; }
.modal-wrap.in { opacity: 1; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); transform: translateY(12px) scale(.98); transition: transform .22s; }
.modal-wrap.in .modal { transform: none; }
.modal-wide { width: min(880px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); gap: 12px; }
.modal-head h3 { font-size: 17px; }
.modal-head .icon-btn { width: 32px; height: 32px; font-size: 13px; }
.modal-body { padding: 18px 22px; overflow: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; background: var(--panel2); border-radius: 0 0 20px 20px; }
.modal-foot:empty { display: none; }

/* ---------- Guided tour ---------- */
.tour-spot { position: fixed; z-index: 120; border-radius: 16px; box-shadow: 0 0 0 9999px rgba(15, 23, 42, .5), 0 0 0 3px var(--gold); pointer-events: none; transition: all .35s ease; }
.tour-card { position: fixed; z-index: 121; width: min(390px, calc(100vw - 24px)); background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 18px; transition: top .35s, left .35s; border: 1px solid var(--line); }
.tour-card .t-step { font: 600 11px var(--mono); color: var(--gold2); letter-spacing: .08em; }
.tour-card h3 { font-size: 17px; margin: 8px 0 6px; }
.tour-card p { color: var(--muted); font-size: 14px; }
.tour-card .t-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 8px; }
.tour-dots { display: flex; gap: 4px; }
.tour-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line2); }
.tour-dots i.on { background: var(--gold); width: 16px; border-radius: 3px; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--faint); font-size: 10.5px; font-family: var(--font); }
.chart .ln { fill: none; stroke: var(--c1); stroke-width: 2.2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.chart .ln.dash { stroke-dasharray: 5 4; }
.chart .ln.c2 { stroke: var(--c2); } .chart .ln.c3 { stroke: var(--c3); } .chart .ln.c4 { stroke: var(--c4); } .chart .ln.c5 { stroke: var(--c5); } .chart .ln.c6 { stroke: var(--c6); }
.chart .ln.actual { stroke: var(--c3); stroke-width: 2.6; }
.chart .area { fill: var(--c1); opacity: .09; }
.chart .area.c2 { fill: var(--c2); } .chart .area.c3 { fill: var(--c3); }
.chart .band { fill: var(--c1); opacity: .12; }
.chart .now { stroke: var(--ink); stroke-width: 1.2; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; opacity: .55; }
.chart .now-l { fill: var(--text); font-weight: 700; }
.chart .thresh { stroke: var(--red); stroke-dasharray: 4 4; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .thresh-l { fill: var(--red); }
.chart .bar { fill: var(--c1); }
.chart .bar.c2 { fill: var(--c2); } .chart .bar.c3 { fill: var(--c3); } .chart .bar.c4 { fill: var(--c4); } .chart .bar.c5 { fill: var(--c5); } .chart .bar.c6 { fill: var(--c6); }
.chart .bar.over { fill: var(--red); }
.chart .bar.dim { opacity: .35; }
.donut .donut-bg { fill: none; stroke: var(--bg3); }
.donut .seg { fill: none; stroke: var(--c1); stroke-linecap: butt; }
.donut .seg.c2 { stroke: var(--c2); } .donut .seg.c3 { stroke: var(--c3); } .donut .seg.c4 { stroke: var(--c4); } .donut .seg.c5 { stroke: var(--c5); } .donut .seg.c6 { stroke: var(--c6); }
.donut .seg.ok { stroke: var(--green); } .donut .seg.warn { stroke: var(--amber); } .donut .seg.bad { stroke: var(--red); } .donut .seg.none { stroke: var(--line2); }
.donut-c { fill: var(--text); font: 700 19px var(--display); }
.donut-s { fill: var(--muted); font-size: 10px; }
.spark { width: 100%; height: 32px; display: block; }
.spark polyline { fill: none; stroke: var(--c2); stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark.bad polyline { stroke: var(--red); }
.spark.warn polyline { stroke: var(--amber); }
.spark .now { stroke: var(--ink); stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; opacity: .5; }
.spark .thresh { stroke: var(--red); stroke-dasharray: 3 3; opacity: .6; vector-effect: non-scaling-stroke; }
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 170px) 1fr auto; gap: 12px; align-items: center; font-size: 13px; }
.hbar-l { color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-t { height: 8px; background: var(--bg3); border-radius: 999px; overflow: hidden; }
.hbar-f { display: block; height: 100%; background: var(--c1); border-radius: 999px; transition: width .5s; }
.hbar-f.c2 { background: var(--c2); } .hbar-f.c3 { background: var(--c3); } .hbar-f.c4 { background: var(--c4); } .hbar-f.c5 { background: var(--c5); } .hbar-f.c6 { background: var(--c6); }
.hbar-f.ok { background: var(--green); } .hbar-f.warn { background: var(--amber); } .hbar-f.bad { background: var(--red); }
.hbar-v { font: 600 12px var(--mono); white-space: nowrap; color: var(--text); }
.heatgrid { display: grid; gap: 3px; font-size: 11px; }
.hg-col { color: var(--faint); text-align: center; padding-bottom: 4px; font-weight: 500; }
.hg-row { color: var(--text2); white-space: nowrap; padding-right: 8px; align-self: center; font-weight: 500; }
.hg-cell { height: 26px; border-radius: 6px; background: color-mix(in srgb, #c8932f calc(var(--v) * 100%), var(--bg3)); display: grid; place-items: center; font: 600 10px var(--mono); color: color-mix(in srgb, var(--text) 80%, transparent); }

.mock-code { width: 124px; height: 124px; border-radius: 10px; display: block; box-shadow: 0 0 0 1px var(--line); }

/* ---------- Responsive ---------- */
@media (max-width: 1440px) {
  .split { grid-template-columns: minmax(0, 1fr) 350px; }
}
@media (max-width: 1280px) {
  .app:not(.rail-open) { --sidebar: 76px; }
  .app:not(.rail-open) .brand { padding: 18px 12px 12px; flex-direction: column; gap: 8px; }
  .app:not(.rail-open) .brand-text, .app:not(.rail-open) .nav-l, .app:not(.rail-open) .nav .code, .app:not(.rail-open) .side-foot, .app:not(.rail-open) .nav-group { display: none; }
  .app:not(.rail-open) .nav { padding: 6px 12px; }
  .app:not(.rail-open) .nav a { justify-content: center; padding: 11px 0; }
  .app .rail-btn { display: none; }
  .split-3 { grid-template-columns: 280px minmax(0, 1fr); }
  .split-3 > :last-child { grid-column: 1 / -1; }
  .g5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .split, .split-l { grid-template-columns: minmax(0, 1fr); }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 288px; z-index: 100; transform: translateX(-102%); transition: transform .28s ease; box-shadow: var(--shadow-lg); }
  .app .sidebar .brand { flex-direction: row; padding: 20px 16px 16px 20px; }
  .app .sidebar .brand-text, .app .sidebar .nav-l, .app .sidebar .nav .code, .app .sidebar .side-foot, .app .sidebar .nav-group { display: revert; }
  .app .sidebar .nav a { justify-content: flex-start; padding: 10px 10px; }
  .app .sidebar .nav .code { display: inline-block; }
  .app.menu-open .sidebar { transform: none; }
  .app.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 90; backdrop-filter: blur(2px); }
  .menu-btn { display: inline-grid; }
  .split-3 { grid-template-columns: minmax(0, 1fr); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-intro { grid-template-columns: minmax(0, 1fr); }
  .page-intro > .row { justify-content: flex-start; }
  .ctx-live { display: none; }
}
@media (max-width: 760px) {
  .tb-row { padding: 12px 16px 8px; }
  .ctx-bar { padding: 0 16px 10px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ctx-bar::-webkit-scrollbar { display: none; }
  .ctx-field span { display: none; }
  .ctx-field select { max-width: 220px; }
  .clock input[type=range] { width: 110px; }
  .tb-sub { display: none; }
  #btn-tour span { display: none; }
  #btn-tour { padding: 8px 10px; }
  .view { padding: 18px 16px calc(92px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 60;
    background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(16px) saturate(1.4); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 6px;
  }
  .bottom-nav a, .bottom-nav button { display: grid; justify-items: center; gap: 3px; padding: 6px 0; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 10.5px; font-weight: 600; background: none; border: 0; cursor: pointer; }
  .bottom-nav svg { width: 21px; height: 21px; }
  .bottom-nav a.active { color: var(--text); background: var(--panel3); }
  .bottom-nav a.active svg { color: var(--gold); }
  #toast-host { bottom: calc(90px + env(safe-area-inset-bottom)); right: 12px; left: 12px; max-width: none; }
}
@media (max-width: 640px) {
  .g2, .g3, .g4, .g5 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px 14px; }
  .kpi .k-v { font-size: 21px; }
  .card { padding: 16px; border-radius: 16px; }
  .hbar { grid-template-columns: 90px 1fr auto; }
  .page-intro h2 { font-size: 23px; }
  .page-intro p { font-size: 14px; }
}

@media print {
  .sidebar, .topbar, .s3-hud, .no-print, #toast-host, .bottom-nav { display: none !important; }
  .app { display: block; height: auto; }
  .view { overflow: visible; padding: 0; }
  body { background: #fff; color: #111; }
  .card, .kpi { break-inside: avoid; box-shadow: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
.brand-text small { display: block; overflow: hidden; text-overflow: ellipsis; }
:root[data-theme="dark"] .switch input:checked { background: var(--gold); }
:root[data-theme="dark"] input[type=checkbox], :root[data-theme="dark"] input[type=radio] { accent-color: var(--gold); }

/* ---------- DWTC brand lockup ---------- */
.brand { align-items: center; padding: 22px 14px 14px 20px; }
.brand-logo { flex: 1; min-width: 0; display: block; line-height: 0; border-radius: 6px; }
.brand-logo img { display: block; height: auto; }
.logo-full { width: 100%; max-width: 192px; }
.logo-mark { display: none !important; width: 40px; height: 40px; }
.logo-w { display: none !important; }
:root[data-theme="dark"] .logo-b { display: none !important; }
:root[data-theme="dark"] .logo-w:not(.logo-mark) { display: block !important; }
.brand-product { display: flex; align-items: center; gap: 10px; margin: 2px 16px 8px 20px; padding: 9px 11px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-xs); }
.brand-product b { display: block; font: 700 13.5px/1.2 var(--display); letter-spacing: -.01em; white-space: nowrap; }
.brand-product small { display: block; font-size: 11.5px; white-space: nowrap; }
.bp-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(140deg, #d4a142, #b8862b); color: #fff; flex: none; }
.bp-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linejoin: round; }
.tb-mark { display: none; width: 34px; height: 34px; flex: none; }
.tb-mark img { width: 34px; height: 34px; display: block; }
.app.rail .logo-full, .app.rail .brand-product { display: none !important; }
.app.rail .logo-mark.logo-b { display: block !important; }
:root[data-theme="dark"] .app.rail .logo-mark.logo-b { display: none !important; }
:root[data-theme="dark"] .app.rail .logo-mark.logo-w { display: block !important; }
.app.rail .brand-logo { flex: none; }
.print-head { display: none; }
@media (max-width: 1280px) {
  .app:not(.rail-open) .logo-full, .app:not(.rail-open) .brand-product { display: none !important; }
  .app:not(.rail-open) .logo-mark.logo-b { display: block !important; }
  :root[data-theme="dark"] .app:not(.rail-open) .logo-mark.logo-b { display: none !important; }
  :root[data-theme="dark"] .app:not(.rail-open) .logo-mark.logo-w { display: block !important; }
  .app:not(.rail-open) .brand-logo { flex: none; }
}
@media (max-width: 900px) {
  .app .sidebar .logo-full.logo-b { display: block !important; }
  .app .sidebar .brand-product { display: flex !important; }
  .app .sidebar .logo-mark { display: none !important; }
  .app .sidebar .brand-logo { flex: 1; }
  :root[data-theme="dark"] .app .sidebar .logo-full.logo-b { display: none !important; }
  :root[data-theme="dark"] .app .sidebar .logo-full.logo-w { display: block !important; }
  .tb-mark { display: block; }
  .tb-mark .logo-b { display: block !important; }
  :root[data-theme="dark"] .tb-mark .logo-b { display: none !important; }
  :root[data-theme="dark"] .tb-mark .logo-w { display: block !important; }
}
@media print {
  .print-head { display: flex !important; align-items: center; gap: 16px; padding: 0 0 14px; margin-bottom: 18px; border-bottom: 1px solid #ddd; font-size: 12px; color: #555; }
  .print-head img { height: 44px; width: auto; }
}

/* collapse control as a floating tab on the sidebar edge, so the DWTC logo gets the full width */
.sidebar { position: relative; overflow: visible; }
.rail-btn { position: absolute; right: -14px; top: 34px; width: 28px; height: 28px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line2); box-shadow: var(--shadow-sm); z-index: 30; color: var(--muted); }
.rail-btn:hover { color: var(--text); background: var(--panel); border-color: var(--faint); }
.rail-btn svg { width: 14px; height: 14px; }
.brand { padding: 24px 22px 16px 22px; }
.logo-full { max-width: 220px; }
.app.rail .brand { padding: 20px 12px 14px; align-items: center; }
.app.rail .rail-btn { top: 32px; }
