:root {
  --bg: #0b111b;
  --card: #121b2b;
  --card-2: #172236;
  --border: #24324a;
  --text: #e6edf7;
  --muted: #8ea0bc;
  --accent: #10b981;
  --accent-2: #38bdf8;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 650; }
.muted { color: var(--muted); font-size: 12.5px; }
.err-msg { color: #fca5a5; background: rgba(239,68,68,.12); padding: 8px 10px; border-radius: 8px; margin: 4px 0; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top, #13253e 0%, var(--bg) 65%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--accent);
  background: rgba(16,185,129,.12);
  border: 1px solid rgba(16,185,129,.35);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.form-stack { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.form-stack label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form-stack input, .ctrl {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
}
.ctrl-sm { padding: 5px 9px; font-size: 12.5px; width: 120px; }

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: .15s ease;
}
.btn-primary { background: var(--accent); color: #052016; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--card-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent-2); }
.btn-danger { background: rgba(239,68,68,.16); color: #fca5a5; border-color: rgba(239,68,68,.35); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-filters, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-title { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--muted); }
.chk { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.user-pill { font-size: 12px; color: var(--accent-2); background: rgba(56,189,248,.12); padding: 5px 10px; border-radius: 999px; }

/* Live Pulse & Drawer */
.live-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.4);
  color: #6ee7b7; border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 650; cursor: pointer;
}
.live-pill:hover { background: rgba(16,185,129,.22); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,.7); } 70% { box-shadow: 0 0 0 8px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }
.live-drawer { background: #0e1726; border-bottom: 1px solid var(--border); padding: 12px 20px; }
.live-drawer-inner { max-width: 1440px; margin: 0 auto; }
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.live-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }

/* Insights strip */
.insights-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; margin-bottom: 14px; }
.insight { background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: 10px; padding: 10px 13px; }
.insight.ok { border-left-color: var(--accent); }
.insight.warn { border-left-color: var(--warn); }
.insight.bad { border-left-color: var(--danger); }
.insight-t { font-weight: 650; font-size: 13px; }
.insight-d { color: var(--muted); font-size: 12px; margin-top: 2px; }

.tag-ch { color: #7dd3fc; border-color: rgba(56,189,248,.35); background: rgba(56,189,248,.1); }
.tag-ai { color: #d8b4fe; border-color: rgba(192,132,252,.4); background: rgba(192,132,252,.12); }
.ref-link { color: var(--accent-2); text-decoration: none; word-break: break-all; font-size: 12px; }
.ref-link:hover { text-decoration: underline; }

/* Live Panel Command Center */
.live-top-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.live-big-num { display: inline-flex; align-items: center; gap: 10px; font-size: 16px; }
.live-big-num b { font-size: 26px; color: var(--accent); line-height: 1; }
.live-split { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1080px) { .live-split { grid-template-columns: 1fr; } }
.live-sidebar { max-height: 78vh; overflow-y: auto; }
.live-visitors-list { display: flex; flex-direction: column; gap: 10px; }
.live-v-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  transition: .15s ease;
}
.live-v-card.watching { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(16,185,129,.45); }
.live-viewer-card { display: flex; flex-direction: column; gap: 12px; }
.live-viewer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.live-screen-stage {
  position: relative; width: 100%; height: 540px; background: #05080f;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.live-empty-stage { text-align: center; max-width: 380px; padding: 20px; }
.live-replayer-host { position: relative; overflow: hidden; border-radius: 6px; box-shadow: 0 10px 35px rgba(0,0,0,.6); background: #fff; }
.live-replayer-host .replayer-wrapper { transform-origin: top left; }
.live-feed-wrap { border-top: 1px solid var(--border); padding-top: 10px; }
.lv-feed { display: flex; gap: 8px; flex-wrap: wrap; max-height: 92px; overflow-y: auto; }
.lv-chip { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 4px 9px; font-size: 12px; }
.lv-chip.conv { border-color: rgba(16,185,129,.5); color: #6ee7b7; }
.lv-chip.rage { border-color: rgba(239,68,68,.5); color: #fca5a5; }

/* Tabs */
.tabs-bar {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 12px 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.content { max-width: 1440px; margin: 0 auto; padding: 18px 20px 40px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; margin-bottom: 16px; }
.geo-grid { display: grid; grid-template-columns: 1.5fr 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1080px) { .geo-grid { grid-template-columns: 1fr; } }
.geo-map-box { background: #070c14; border: 1px solid var(--border); border-radius: 10px; padding: 8px; overflow: hidden; }

.chart-box { min-height: 210px; display: flex; align-items: center; justify-content: center; }
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-row-top { display: flex; justify-content: space-between; font-size: 12.5px; }
.bar-track { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; }
.bar-fill.danger { background: linear-gradient(90deg, var(--warn), var(--danger)); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.8px; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.tbl tr:hover td { background: rgba(255,255,255,.02); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--card-2); border: 1px solid var(--border); }
.tag-ok { color: var(--accent); border-color: rgba(16,185,129,.4); background: rgba(16,185,129,.1); }
.tag-warn { color: var(--warn); border-color: rgba(245,158,11,.4); background: rgba(245,158,11,.1); }
.tag-bad { color: #fca5a5; border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.12); }
.pill-stat { background: var(--card-2); border: 1px solid var(--border); padding: 6px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }

/* Segmented controls */
.seg { display: inline-flex; background: var(--bg); padding: 3px; border-radius: 9px; border: 1px solid var(--border); gap: 2px; flex-wrap: wrap; }
.seg-btn {
  background: transparent; border: 0; color: var(--muted); padding: 6px 11px;
  border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.seg-btn.active { background: var(--card-2); color: var(--text); }

/* Heatmap */
.hm-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.hm-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ctrl-inline { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.hm-layout { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
@media (max-width: 1080px) { .hm-layout { grid-template-columns: 1fr; } }
.hm-stage-wrap { padding: 10px; }
.hm-stage-scroll { max-height: 78vh; overflow: auto; border-radius: 8px; background: #060910; border: 1px solid var(--border); padding: 12px; }
.hm-stage-sizer { position: relative; margin: 0 auto; overflow: hidden; background: #fff; border-radius: 6px; box-shadow: 0 8px 30px rgba(0,0,0,.45); }
.hm-stage { position: absolute; top: 0; left: 0; transform-origin: top left; background: #fff; }
.hm-stage iframe { position: relative; z-index: 1; width: 100%; height: 100%; border: 0; pointer-events: none; display: block; overflow: hidden; }
#hm-canvas { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; }
#hm-scroll-overlay { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.scroll-band {
  width: 100%;
  border-bottom: 1px dashed rgba(255,255,255,.45);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.9);
}
.att-zone {
  position: absolute;
  left: 0;
  width: 100%;
  border-top: 3px solid rgba(255,255,255,.75);
  border-bottom: 2px dashed rgba(255,255,255,.35);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 16px 20px;
}
.att-badge {
  background: rgba(8, 13, 24, 0.92);
  border: 2px solid rgba(255,255,255,.55);
  color: #fff;
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 750;
  box-shadow: 0 8px 24px rgba(0,0,0,.65);
}
.hm-jump-row { cursor: pointer; }
.hm-jump-row:hover td { background: rgba(16,185,129,.12) !important; }

.pager { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 12px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-top: 8px; }
.code-box {
  background: #070b12; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-family: ui-monospace, monospace; font-size: 11.5px;
  color: #93c5fd; word-break: break-all; margin-top: 6px;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4,7,13,.82); z-index: 999;
  display: grid; place-items: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 1320px; max-height: 92vh;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-body {
  display: grid; grid-template-columns: 1fr 340px; gap: 0; overflow: hidden; flex: 1; min-height: 520px;
}
@media (max-width: 980px) { .modal-body { grid-template-columns: 1fr; overflow: auto; } }
.rm-left-col { display: flex; flex-direction: column; overflow: auto; background: #060910; }
.rm-sync-hud { background: #0d1524; border-bottom: 1px solid var(--border); padding: 10px 14px; }
.rm-now-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.rm-clock { margin-left: auto; font-family: ui-monospace, monospace; font-size: 12px; color: var(--accent-2); background: rgba(56,189,248,.1); padding: 3px 8px; border-radius: 6px; }
.rm-ribbon-wrap { position: relative; height: 28px; background: #080d17; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.rm-sec-ribbon { display: flex; width: 100%; height: 100%; }
.rm-seg {
  height: 100%; border: 0; border-right: 1px solid rgba(0,0,0,.35);
  color: #fff; font-size: 11px; font-weight: 650; padding: 0 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer; text-align: left; transition: filter .15s;
}
.rm-seg:hover { filter: brightness(1.22); }
.rm-seg.is-active { box-shadow: inset 0 0 0 2px #fff; filter: brightness(1.18); }
.rm-playhead {
  position: absolute; top: 0; bottom: 0; width: 3px; background: #fff;
  box-shadow: 0 0 10px #fff, 0 0 4px var(--accent); pointer-events: none; z-index: 5;
  transition: left .18s linear;
}
.rm-player-box {
  background: #060910; padding: 14px; overflow: auto; display: flex; align-items: flex-start; justify-content: center; flex: 1;
}
.rm-timeline-box {
  border-left: 1px solid var(--border); padding: 14px; overflow-y: auto; max-height: 76vh;
}
.tl-item {
  border-left: 2px solid var(--border); padding: 5px 8px 8px 12px; margin-left: 6px;
  position: relative; border-radius: 0 8px 8px 0; cursor: pointer; transition: background .15s;
}
.tl-item:hover { background: rgba(255,255,255,.04); }
.tl-item.is-now { background: rgba(16,185,129,.14); border-left-color: var(--accent); }
.tl-item::before { content: ""; position: absolute; left: -5px; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }
.tl-item.is-now::before { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.tl-item.conv::before { background: var(--accent); }
.tl-item.rage::before { background: var(--danger); }

/* Pack A: custom date range, KPI period deltas, thermal legend & site settings */
.custom-dates { display: inline-flex; align-items: center; gap: 6px; }
.ctrl-date { width: 132px; padding: 6px 8px; }
.kpi-top-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.kpi-delta { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 999px; white-space: nowrap; }
.kpi-delta.up { color: #34d399; background: rgba(16,185,129,.14); border: 1px solid rgba(16,185,129,.32); }
.kpi-delta.down { color: #fca5a5; background: rgba(239,68,68,.14); border: 1px solid rgba(239,68,68,.32); }
.kpi-delta.flat { color: var(--muted); background: rgba(148,163,184,.1); border: 1px solid var(--border); }

.hm-legend-bar {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.hm-grad-wrap { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hm-grad-bar {
  display: inline-block;
  width: 150px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, hsl(215,92%,52%), hsl(165,92%,50%), hsl(110,92%,48%), hsl(48,95%,52%), hsl(0,92%,52%));
  border: 1px solid rgba(255,255,255,.25);
}
.hm-mode-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(56,189,248,.1);
  border: 1px solid rgba(56,189,248,.32);
  color: #e0f2fe;
}

.site-tools-box { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 8px; }
.ip-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ip-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px;
  border-radius: 999px; font-size: 11.5px; font-family: ui-monospace, monospace;
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
}
.ip-chip button { background: 0; border: 0; color: #fca5a5; cursor: pointer; font-weight: 700; padding: 0; line-height: 1; }
.sec-editor-details summary { cursor: pointer; font-size: 12px; color: var(--accent-2); font-weight: 600; user-select: none; }
.sec-textarea {
  width: 100%; min-height: 140px; margin-top: 6px; padding: 8px 10px; border-radius: 8px;
  background: #070b12; color: var(--text); border: 1px solid var(--border);
  font-family: ui-monospace, monospace; font-size: 11.5px; line-height: 1.5; resize: vertical;
}

/* Pack B: Executive Export, Form Drop-off, Session Starring/Tags/Notes, Hardware/JA4 & Telegram Alerts */
.ov-action-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.rm-hw-fp { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.fp-pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 6px;
  background: #080d17; border: 1px solid var(--border); font-size: 11px; color: #cbd5e1;
  font-family: ui-monospace, monospace;
}
.fp-pill b { color: var(--accent-2); font-family: inherit; }
.rm-crm-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 18px; background: #0c1321; border-bottom: 1px solid var(--border);
}
.rm-tags-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pick {
  background: var(--bg); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.tag-pick.active { background: rgba(16,185,129,.18); color: #6ee7b7; border-color: rgba(16,185,129,.55); }
.rm-note-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 260px; }
.star-btn {
  background: 0; border: 0; cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 4px;
  color: #64748b; transition: transform .12s;
}
.star-btn.is-on { color: #fbbf24; }
.star-btn:hover { transform: scale(1.18); }
.form-kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.form-mini-kpi { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.tg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-top: 8px; }
.tg-grid label { display: flex; flex-direction: column; gap: 4px; }
.tg-grid .ctrl { width: 100%; }
