:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --ink: #17325a;
  --ink-2: #44587a;
  --ink-3: #6b7c99;
  --line: #dde3ed;
  --accent: #e87090;
  --accent-ink: #b3214a;
  --s1: #17325a;      /* series: visitor wrote */
  --s2: #7f9abf;      /* series: browsing only */
  --good: #0b7a4b;
  --warn: #8a5a00;
  --shadow: 0 1px 2px rgba(23, 50, 90, .06), 0 4px 16px rgba(23, 50, 90, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #11151c; --surface: #1a1f29; --surface-2: #232a36; --ink: #eef2f9; --ink-2: #c3cddd; --ink-3: #93a1b8;
    --line: #2d3645; --accent: #ee84a0; --accent-ink: #f59ab3; --s1: #6da7ec; --s2: #3d5f94; --good: #4cc38a; --warn: #e3b04b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11151c; --surface: #1a1f29; --surface-2: #232a36; --ink: #eef2f9; --ink-2: #c3cddd; --ink-3: #93a1b8;
  --line: #2d3645; --accent: #ee84a0; --accent-ink: #f59ab3; --s1: #6da7ec; --s2: #3d5f94; --good: #4cc38a; --warn: #e3b04b;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.5 'Mulish', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 9px; letter-spacing: .01em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.tabs { display: flex; gap: 4px; }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.tab:hover { background: var(--surface-2); }
.tab.is-active { background: var(--ink); color: var(--surface); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.updated { font-size: 12px; color: var(--ink-3); }
.range select, .filters select, .filters input[type="search"] { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }

.banner { background: var(--surface-2); border-bottom: 1px solid var(--line); padding: 8px 24px; font-size: 13px; color: var(--ink-2); }
.banner.err { color: var(--accent-ink); }

main { max-width: 1240px; margin: 0 auto; padding: 22px 24px 60px; }
.h { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 22px 0 10px; font-weight: 800; }
.h:first-child { margin-top: 0; }

.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.live-card, .card, .kpi, .list-row { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.live-card { padding: 14px 16px; cursor: pointer; text-align: left; }
.live-card:hover { border-color: var(--accent); }
.live-top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(11, 122, 75, .5); animation: pulse 1.8s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(11, 122, 75, 0); } 100% { box-shadow: 0 0 0 0 rgba(11, 122, 75, 0); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.live-page { font-weight: 700; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tail { display: flex; flex-direction: column; gap: 5px; }
.tail .b { padding: 6px 10px; border-radius: 12px; font-size: 13px; max-width: 92%; overflow-wrap: anywhere; }
.tail .b.user { align-self: flex-end; background: var(--ink); color: var(--surface); }
.tail .b.agent { align-self: flex-start; background: var(--surface-2); }
.empty { padding: 26px; text-align: center; color: var(--ink-3); background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; grid-column: 1 / -1; }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center; padding: 10px 14px; cursor: pointer; text-align: left; width: 100%; }
.list-row:hover { border-color: var(--accent); }
.muted { color: var(--ink-3); }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.filters input[type="search"] { min-width: 260px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-2); }
.count { margin-left: auto; font-size: 13px; color: var(--ink-3); }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; box-shadow: var(--shadow); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td, .tbl tbody tr:focus-visible td { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .first { max-width: 440px; overflow-wrap: anywhere; }
.tbl .when { white-space: nowrap; }
.btn { margin-top: 14px; border: 1px solid var(--line); background: var(--surface); padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 700; }
.btn:hover { background: var(--surface-2); }

.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); margin: 0 4px 4px 0; white-space: nowrap; }
.chip.ticket { background: rgba(232, 112, 144, .16); color: var(--accent-ink); }
.chip.live { background: rgba(11, 122, 75, .14); color: var(--good); }
.chip.warn { background: rgba(138, 90, 0, .14); color: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 30px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.kpi .s { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card { padding: 16px 18px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 16px; font-weight: 800; }
.card-head .sub { font-size: 13px; color: var(--ink-3); }
.card-head .btn { margin: 0 0 0 auto; padding: 4px 10px; font-size: 12px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.s1 { background: var(--s1); }
.legend i.s2 { background: var(--s2); }
.chart { width: 100%; height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--ink-3); font-size: 11px; font-family: inherit; }
.chart .seg1 { fill: var(--s1); }
.chart .seg2 { fill: var(--s2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit:focus-visible { fill: var(--ink); fill-opacity: .06; outline: none; }
.chart-empty { height: 240px; display: flex; align-items: center; justify-content: center; color: var(--ink-3); }

.bars { display: flex; flex-direction: column; gap: 12px; }
.brow .top2 { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; gap: 10px; }
.brow .top2 b { font-variant-numeric: tabular-nums; }
.track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.fill { height: 100%; background: var(--s1); border-radius: 5px; min-width: 2px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--surface); border-radius: 10px; padding: 8px 11px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: 260px; }
.tip .t-h { font-weight: 700; margin-bottom: 4px; }
.tip .t-r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .t-r b { font-variant-numeric: tabular-nums; }
.tip .key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

.scrim { position: fixed; inset: 0; background: rgba(10, 18, 34, .45); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 50; border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .18); }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; min-width: 0; }
.drawer-title h3 { margin: 0 0 4px; font-size: 16px; }
.drawer-title .meta { font-size: 13px; color: var(--ink-3); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 30px; display: flex; flex-direction: column; gap: 8px; }
.pages { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.pages a { color: var(--ink); text-decoration-color: var(--accent); overflow-wrap: anywhere; }
.pages li { margin: 2px 0; }
.bub { padding: 9px 13px; border-radius: 16px; max-width: 88%; overflow-wrap: anywhere; white-space: pre-wrap; }
.bub.user { align-self: flex-end; background: var(--ink); color: var(--surface); border-bottom-right-radius: 4px; }
.bub.agent { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.event { align-self: center; text-align: center; font-size: 12px; color: var(--ink-3); padding: 2px 8px; }
.event.seg { width: 100%; border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 6px; }
.toolline { align-self: flex-start; font-size: 12px; color: var(--ink-3); }

@media (max-width: 800px) {
  .top { padding: 10px 14px; gap: 10px; }
  main { padding: 16px 14px 50px; }
  .grid { grid-template-columns: 1fr; }
  .list-row { grid-template-columns: 1fr; gap: 4px; }
  .tbl th:nth-child(3), .tbl td:nth-child(3), .tbl th:nth-child(4), .tbl td:nth-child(4), .tbl th:nth-child(5), .tbl td:nth-child(5) { display: none; }
  .tbl td, .tbl th { padding: 10px; }
  .filters input[type="search"] { min-width: 0; flex: 1 1 100%; }
  .count { margin-left: 0; }
}

/* sign-in page and sign-out button */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 28px 30px; }
.login-brand { margin-bottom: 18px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.login-sub { margin: 0 0 18px; color: var(--ink-3); font-size: 14px; }
.login-card label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 14px 0 5px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px; }
.login-card input:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 0; }
.login-btn { width: 100%; margin-top: 22px; padding: 11px 14px; border: 0; border-radius: 10px; background: var(--ink); color: var(--surface); font-weight: 800; font-size: 15px; cursor: pointer; }
.login-btn:hover { opacity: .92; }
.login-error { margin: 0 0 4px; padding: 9px 12px; border-radius: 10px; background: rgba(232, 112, 144, .15); color: var(--accent-ink); font-size: 14px; font-weight: 600; }
.signout { margin: 0; }
.signout button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; height: 34px; padding: 0 12px; cursor: pointer; color: var(--ink-2); font-weight: 700; font-size: 13px; }
.signout button:hover { background: var(--surface-2); }

.who { font-size: 13px; font-weight: 700; color: var(--ink-2); }
@media (max-width: 800px) { .who { display: none; } }

.working { font-size: 12px; font-weight: 700; color: var(--accent-ink); margin: 6px 0 2px; }
.tx { display: flex; flex-direction: column; gap: 8px; }
.feed-status { font-size: 13px; color: var(--ink-3); margin: -4px 0 12px; }
.feed-status.warn { color: var(--warn); }
.feed-status.bad { color: var(--accent-ink); font-weight: 700; }
