:root {
  color-scheme: light;
  --bg: #eaf1f1;
  --surface: #f6f9f8;
  --paper: #fcfefe;
  --ink: #193b45;
  --muted: #4f6570;
  --line: #d5e2e2;
  --control: #738e91;
  --brand: #39c4bb;
  --accent: #086b65;
  --on-accent: #ffffff;
  --tint: #e1f2ef;
  --blue: #548fbd;
  --focus: #087eaa;
  --warning: #8c5227;
  --warning-bg: #f9eddf;
  --shadow: 0 16px 45px #355b6710;
  font: 16px/1.55 "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101f2a;
  --surface: #1a303d;
  --paper: #1d3542;
  --ink: #e2f0f2;
  --muted: #a3bac4;
  --line: #36515b;
  --control: #6f8a92;
  --brand: #39c4bb;
  --accent: #5addd1;
  --on-accent: #10232d;
  --tint: #233f48;
  --blue: #80bae2;
  --focus: #69ddd4;
  --warning: #f3c394;
  --warning-bg: #473828;
  --shadow: 0 16px 45px #0002;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
h1, h2, p, ul, ol, dl, dd { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.skip-link:focus { position: fixed; top: 10px; left: 10px; z-index: 5; padding: 10px 14px; background: var(--paper); }
::selection { background: var(--brand); color: #193b45; }

.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar-inner, .shell { width: min(100%, 1256px); margin-inline: auto; padding-inline: clamp(16px, 4vw, 48px); }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; min-height: 68px; gap: 8px; }
.brand, .topbar nav, .masthead-actions, .status-chip, .refresh { display: flex; align-items: center; }
.brand { gap: 11px; min-width: 0; }
.brand img { flex: none; }
.brand strong, .brand small { display: block; line-height: 1.28; }
.brand strong { font-size: 1rem; font-weight: 670; white-space: nowrap; }
.brand small { margin-top: 4px; color: var(--muted); font-size: .73rem; }
.topbar nav { gap: 2px; }
.quiet, .primary {
  display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 44px;
  padding: 7px 13px; border: 1px solid var(--control); border-radius: 9px; font-size: .87rem;
  font-weight: 630; background: var(--paper); color: var(--ink); white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.topbar .quiet { border-color: transparent; background: transparent; color: var(--muted); }
.quiet:hover, .topbar .quiet:hover { background: var(--tint); border-color: var(--control); color: var(--accent); }
.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.primary:hover { filter: brightness(.91); }

.shell { padding-top: 36px; padding-bottom: 24px; }
.masthead { display: flex; align-items: end; justify-content: space-between; gap: 15px 22px; margin-bottom: 25px; }
h1 { font-size: clamp(2rem, 4.5vw, 3.15rem); line-height: 1.18; letter-spacing: -.045em; font-weight: 680; }
.masthead p { margin-top: 8px; color: var(--muted); font-size: .94rem; }
.masthead-actions { gap: 10px; flex-wrap: wrap; }
.mobile-jump { display: none; }
.status-chip { gap: 7px; min-height: 34px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 100px; color: var(--muted); background: var(--surface); font-size: .78rem; }
.status-chip[data-state="online"] { color: var(--accent); border-color: var(--control); background: var(--tint); }
.status-chip[data-state="offline"] { color: var(--warning); background: var(--warning-bg); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 14px; background: var(--paper); overflow: hidden; }
.metric-strip > div { padding: 16px clamp(13px, 2.5vw, 25px) 15px; }
.metric-strip > div + div { border-left: 1px solid var(--line); }
.metric-strip dt { color: var(--muted); font-size: .84rem; font-weight: 600; }
.metric-value { margin-block: 3px; font-size: clamp(1.7rem, 4vw, 2.35rem); line-height: 1.22; font-weight: 670; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.metric-strip div:first-child .metric-value { color: var(--accent); }
.metric-note { color: var(--muted); font-size: .75rem; }

.overview-grid, .archive-grid { display: grid; grid-template-columns: minmax(0, 2.15fr) minmax(235px, 1fr); gap: 15px; margin-top: 15px; align-items: start; }
.overview-grid { align-items: stretch; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: start; gap: 8px 15px; }
.panel-head h2, dialog h2 { font-size: 1.14rem; line-height: 1.28; letter-spacing: -.01em; font-weight: 690; }
.panel-head p, .detail-head p { margin-top: 4px; font-size: .79rem; color: var(--muted); overflow-wrap: anywhere; }
.chart-panel, .collector-panel { padding: 17px 19px 14px; }
.legend { display: flex; gap: 6px 13px; flex-wrap: wrap; list-style: none; padding: 0; color: var(--muted); font-size: .75rem; }
.legend li { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; }
.swatch.live { background: var(--accent); }
.swatch.history { background: var(--blue); }
.chart {
  min-height: 122px; margin-top: 9px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px; padding: 0; list-style: none; text-align: center;
}
.chart li { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: end; }
.chart svg { width: min(75%, 48px); height: 82px; display: block; overflow: visible; }
.chart-count { font-size: .76rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart-day { display: block; width: 100%; padding-top: 4px; border-top: 1px solid var(--line); font-size: .72rem; color: var(--muted); }
.chart li:last-child .chart-day { color: var(--accent); font-weight: 690; }
.bar-live { fill: var(--accent); }
.bar-history { fill: var(--blue); }
.collector-info { margin-top: 12px; }
.collector-info > div { min-height: 34px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1px 9px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: .8rem; }
.collector-info dt { color: var(--muted); }
.collector-info dd { font-weight: 630; font-variant-numeric: tabular-nums; }
.backfill { padding: 0; color: var(--muted); font-size: .79rem; }
.backfill summary { min-height: 44px; padding-block: 11px; cursor: pointer; color: var(--accent); }
.backfill ul { padding-inline-start: 17px; overflow-wrap: anywhere; }

.archive-panel { padding: 19px 19px 8px; }
.archive-head { align-items: center; flex-wrap: wrap; }
.view-switch { display: flex; gap: 3px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.view-switch button { min-height: 44px; border: 1px solid transparent; padding: 5px 12px; border-radius: 7px; background: transparent; color: var(--muted); font-size: .81rem; font-weight: 600; }
.view-switch button[aria-pressed="true"] { color: var(--accent); background: var(--tint); border-color: var(--control); }
.filters { display: grid; grid-template-columns: minmax(8rem, 2fr) minmax(6rem, 1fr) minmax(6.25rem, .7fr) auto; gap: 8px; margin: 15px 0 13px; align-items: center; }
input, select { width: 100%; min-width: 0; min-height: 44px; border: 1px solid var(--control); border-radius: 9px; background: var(--paper); padding: 7px 10px; font-size: .83rem; }
input::placeholder { color: var(--muted); opacity: 1; }
.search-field { position: relative; }
.search-field svg { position: absolute; left: 10px; top: 14px; color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 33px; }
.timeline, .source-list { list-style: none; padding: 0; }
.day-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 9px 0 4px; font-size: .77rem; font-weight: 620; }
.day-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.timeline-entry + .timeline-entry { border-top: 1px solid var(--line); }
.record { width: 100%; display: grid; grid-template-columns: 44px minmax(0, 1fr) 17px; gap: 10px; align-items: start; min-height: 58px; text-align: left; padding: 9px 5px; border: 1px solid transparent; border-radius: 8px; background: transparent; }
.record:hover { border-color: var(--line); background: var(--surface); }
.record svg { align-self: center; color: var(--muted); }
.record-time { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.record-content { min-width: 0; }
.record-meta { display: flex; flex-wrap: wrap; gap: 3px 8px; align-items: baseline; min-width: 0; }
.record-sender { font-size: .83rem; overflow-wrap: anywhere; }
.record-source { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.record-body { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; color: var(--ink); font-size: .88rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 5px; background: var(--tint); color: var(--accent); font-size: .72rem; font-weight: 620; }
.badge[data-kind="missing"] { background: var(--warning-bg); color: var(--warning); }
.empty { padding: 26px 7px; color: var(--ink); text-align: center; }
.empty p { color: var(--muted); font-size: .84rem; margin-top: 4px; }
.load-actions { display: flex; justify-content: center; }
.load-actions button { margin-block: 10px; }
.notice { padding: 9px 11px; margin-block: 8px; border-radius: 8px; background: var(--tint); color: var(--accent); font-size: .83rem; }
.notice.error { background: var(--warning-bg); color: var(--warning); }

.sources-panel { padding: 17px 12px 10px; }
.sources-panel .panel-head { padding-inline: 7px; margin-bottom: 8px; }
.source-list { max-height: 560px; overflow: auto; scrollbar-gutter: stable; }
.source-list button { display: grid; grid-template-columns: 27px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; min-height: 49px; padding: 5px 7px; border: 1px solid transparent; border-radius: 8px; background: transparent; text-align: left; }
.source-list button:hover { background: var(--surface); }
.source-list button[aria-pressed="true"] { background: var(--tint); border-color: var(--control); }
.source-icon { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 7px; background: var(--tint); color: var(--accent); font-size: .73rem; font-weight: 650; }
.source-label strong, .source-label small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-label strong { font-size: .81rem; }
.source-label small, .source-count, .source-empty { font-size: .73rem; color: var(--muted); }
.source-count { font-variant-numeric: tabular-nums; }
.source-empty { padding: 7px; }
.footer { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; color: var(--muted); font-size: .73rem; }

body:has(dialog[open]) { overflow: hidden; }
dialog { width: min(590px, calc(100vw - 24px)); max-height: min(83vh, 650px); padding: 19px; border: 1px solid var(--control); border-radius: 15px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: #101f2a94; }
.detail-head { display: flex; justify-content: space-between; align-items: start; gap: 15px; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-block: 13px; padding: 12px; background: var(--surface); border-radius: 8px; }
.detail-meta > div { display: grid; grid-template-columns: minmax(5rem, .45fr) minmax(0, 1fr); gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .83rem; }
.detail-meta dt { color: var(--muted); }
.detail-meta dd { overflow-wrap: anywhere; }

.login-shell { display: grid; place-items: start center; padding: clamp(32px, 11vh, 110px) 16px; }
.login-panel { width: min(100%, 440px); padding: clamp(22px, 6vw, 38px); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: 17px; background: var(--paper); box-shadow: var(--shadow); }
.lock-mark { display: inline-grid; place-items: center; width: 45px; height: 45px; border-radius: 12px; background: var(--tint); color: var(--accent); margin-bottom: 14px; }
.login-panel h1 { font-size: 2.05rem; }
.login-intro { margin-block: 9px 21px; color: var(--muted); font-size: .9rem; }
.login-panel label { display: block; font-weight: 630; font-size: .86rem; margin-bottom: 5px; }
.login-panel .remember-device { display: flex; align-items: center; gap: 9px; min-height: 44px; margin: 6px 0 0; cursor: pointer; }
.remember-device input { width: 17px; height: 17px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); }
.login-panel .primary { width: 100%; margin-top: 12px; }
.login-foot { color: var(--muted); font-size: .79rem; margin-top: 15px; }
.login-error { color: var(--warning); font-size: .85rem; margin-top: 5px; }

@media (max-width: 900px) {
  .filters { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) auto; }
  .search-field { grid-column: 1 / -1; }
}
@media (max-width: 740px) {
  .overview-grid, .archive-grid { grid-template-columns: 1fr; }
  .sources-panel { display: none; }
  .masthead { align-items: start; flex-direction: column; }
  .mobile-jump { display: inline-flex; }
  .shell { padding-top: 22px; }
}
@media (max-width: 510px) {
  .topbar-inner { min-height: 62px; }
  .topbar .quiet { padding-inline: 8px; min-width: 44px; }
  .brand { gap: 8px; }
  .brand img { width: 33px; height: 33px; }
  .brand strong { font-size: .93rem; }
  .metric-strip { grid-template-columns: 1fr 1fr; }
  .metric-strip > div:nth-child(3) { border-left: none; }
  .metric-strip > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .panel { border-radius: 12px; }
  .chart-panel, .collector-panel, .archive-panel { padding-inline: 12px; }
  .record { grid-template-columns: 39px minmax(0, 1fr) 14px; gap: 6px; }
  .chart { gap: 4px; }
  input, select { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
