:root {
  --bg: #f6f4ef;
  --side: #efece5;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1d1c1a;
  --muted: #6c6860;
  --line: #e2ded5;
  --accent: #1f5f5b;
  --accent-ink: #ffffff;
  --accent-soft: #e2efed;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --ok: #2f7d4f;
  --warn: #b7791f;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(29 28 26 / 0.05), 0 4px 16px rgb(29 28 26 / 0.05);
  --radius: 14px;
  --side-w: 288px;
  --chart: #0d9488;  /* validated: dataviz validate_palette light vs #ffffff */
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131312;
    --side: #181817;
    --surface: #1c1c1a;
    --surface-2: #262623;
    --ink: #eceae4;
    --muted: #a19c92;
    --line: #33322e;
    --accent: #6fbdb3;
    --accent-ink: #0d1f1d;
    --accent-soft: #1d3331;
    --danger: #f97066;
    --danger-soft: #3b1a17;
    --ok: #6cc28f;
    --warn: #e0b04f;
    --focus: #7aa7ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    --chart: #1fa396;  /* validated: dark vs #1c1c1a */
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; line-height: 1.3; text-wrap: balance; }
p { margin: 0; }
.tnum { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  padding: 8px 14px; border-radius: 8px;
  background: var(--ink); color: var(--bg); text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus-visible { top: 12px; }

/* ---------- app shell: left menu + right content ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100dvh; }

.side {
  position: sticky; top: 0; height: 100dvh; z-index: 20;
  display: flex; flex-direction: column;
  background: var(--side); border-right: 1px solid var(--line);
  padding-left: env(safe-area-inset-left);
}
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 16px 10px; }
.side-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 18px; }
.side-foot { padding: 12px 16px max(16px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.side .side-toggle { display: none; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; border-radius: 10px; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { stroke: var(--accent-ink); stroke-width: 2.4; fill: none; stroke-linecap: round; }
.brand-mark circle { fill: var(--accent-ink); }
.brand-title { font-size: 16px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; line-height: 1.3; }
.brand-sub { font-size: 12px; color: var(--muted); }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.nav-item .nav-count { margin-left: auto; font-size: 12px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item .nav-count.err { color: var(--danger); font-weight: 700; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  color: var(--muted); border: 1px solid transparent; background: none; cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--surface); color: var(--ink); border-color: var(--line); }

.status-pill {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  font-size: 13px; color: var(--muted);
}
.status-pill .status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status-pill[data-state="idle"] .dot { background: var(--ok); }
.status-pill[data-state="busy"] .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.status-pill[data-state="error"] .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; transform: scale(0.8); } }

.cap { display: flex; flex-direction: column; gap: 6px; }
.cap-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--muted); font-weight: 600; }
.cap-num { color: var(--ink); font-weight: 700; }
.meter { height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.3s ease; }
.meter span.full { background: var(--warn); }
.cap .hint { font-size: 11.5px; line-height: 1.5; }
.side-note { font-size: 11.5px; line-height: 1.5; }
.side-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.side-user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- login ---------- */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-wrap { width: min(380px, 100%); display: flex; flex-direction: column; gap: 20px; }
.login-brand { display: flex; align-items: center; gap: 12px; justify-content: center; }
.login-card { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; }
.login-card input {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.login-card input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); border-radius: 10px; }

.content { min-width: 0; padding: 32px 36px 48px; outline: none; }
.content-inner { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; overflow-wrap: anywhere; }
.page-head .hint { margin-top: 2px; font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 14px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 86%, var(--ink)); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: color-mix(in srgb, var(--line) 60%, var(--ink)); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 85%, #000); }
.btn-text { background: none; color: var(--muted); padding-inline: 8px; }
.btn-text:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }
.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn .spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-title { font-size: 15px; font-weight: 700; }

.field-label { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; }
.add-form input[type="text"] {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink); font: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.add-form input[type="text"]:hover { border-color: color-mix(in srgb, var(--line) 50%, var(--ink)); }
.add-form input[type="text"]:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); border-radius: 10px; }
.add-form input[aria-invalid="true"] { border-color: var(--danger); }
.hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 13px; color: var(--danger); }
.field-error:empty { display: none; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 6px 0 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: border-color 0.15s ease, background-color 0.15s ease;
}
.switch-row:hover { border-color: color-mix(in srgb, var(--line) 50%, var(--ink)); }
.switch-row:has(.switch:checked) { border-color: var(--accent); background: var(--accent-soft); }
.switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-text strong { font-size: 14px; }
.switch-text small { font-size: 11.5px; color: var(--muted); line-height: 1.4; }

/* Checkbox styled as a switch; still a native input for forms, keyboard and screen readers. */
.switch {
  appearance: none; flex: none; position: relative; margin: 0;
  width: 40px; height: 24px; border-radius: 99px; cursor: pointer;
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  transition: background-color 0.15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: transform 0.15s ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(16px); }
.switch:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 99px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- keyword list page ---------- */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.add-form { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; }
.add-row { display: flex; gap: 10px; align-items: stretch; }
.add-row .field-grow { flex: 1; }
.add-row .switch-inline { margin: 0; flex: none; gap: 10px; }
.add-row .btn { flex: none; min-height: 44px; }
.add-help { display: flex; flex-direction: column; gap: 8px; }
.add-help .chips { align-items: center; }
.add-help .chip { padding: 3px 12px; font-size: 12.5px; }

.table-card { overflow: hidden; }
.kw-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kw-table thead th {
  padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface-2); white-space: nowrap;
}
.kw-table tbody tr { border-top: 1px solid var(--line); transition: background-color 0.15s ease; }
.kw-table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.kw-table tbody th, .kw-table td { padding: 12px 14px; vertical-align: middle; text-align: left; font-weight: 400; }
.kw-table .num { text-align: right; }
.kw-table tbody th { min-width: 0; }
.kw-link { display: block; font-weight: 700; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; border-radius: 4px; }
.kw-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.row-sub { display: block; font-size: 12px; color: var(--muted); }
.kw-table tr.is-paused .kw-link { color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.err-text { color: var(--danger); font-weight: 600; }
.count-link { color: var(--accent); font-weight: 700; text-decoration: none; border-radius: 4px; }
.count-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.kw-table td .badge.new { margin-left: 6px; }
.row-actions { white-space: nowrap; text-align: right !important; }
.row-actions .btn + .btn { margin-left: 4px; }
.table-empty { padding: 36px 16px !important; text-align: center !important; color: var(--muted); }

.back-link {
  display: inline-flex; align-items: center; gap: 4px; align-self: flex-start;
  margin: -4px 0 -6px -4px; padding: 2px 6px; border-radius: 6px;
  color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.back-link svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back-link:hover { color: var(--ink); background: var(--surface-2); }

.bell { width: 14px; height: 14px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bell.off { opacity: 0.7; }

/* ---------- account tracking ---------- */
.notice {
  padding: 10px 14px; border-radius: 10px; font-size: 13px; line-height: 1.6;
  background: var(--accent-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.panel-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.panel-toolbar select {
  min-height: 36px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px;
  background-color: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
}
.panel-toolbar select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.panel-toolbar option { background-color: var(--surface); color: var(--ink); }
.eng { margin-left: auto; font-size: 13px; font-weight: 700; }
.growth { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.growth.up { color: var(--ok); font-weight: 700; }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.chart-grid > .chart:first-child { grid-column: 1 / -1; }
.chart { margin: 0; padding: 16px 16px 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.chart-title { font-size: 14px; font-weight: 700; }
.chart-plot { position: relative; min-width: 0; }
.chart-plot svg { display: block; overflow: visible; }
.chart-grid line.chart-grid, .chart line.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart line.chart-base { stroke: color-mix(in srgb, var(--line) 50%, var(--muted)); stroke-width: 1; }
.chart-tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-bar { fill: var(--chart); transition: opacity 0.15s ease; }
.chart-hit { cursor: default; outline: none; }
.chart-hit-area { fill: transparent; }
.chart-hit.is-active .chart-hit-area { fill: color-mix(in srgb, var(--chart) 10%, transparent); }
.chart-hit:focus-visible .chart-hit-area { stroke: var(--focus); stroke-width: 2; }
.chart-tip {
  position: absolute; top: 0; left: 0; z-index: 3; pointer-events: none; min-width: 120px; max-width: 170px;
  display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 20px rgb(0 0 0 / 0.18); font-size: 12px;
}
.chart-tip strong { font-size: 15px; color: var(--ink); }
.chart-tip span { color: var(--muted); }
.chart-table summary { font-size: 12px; color: var(--muted); cursor: pointer; width: fit-content; border-radius: 4px; }
.chart-table summary:hover { color: var(--ink); }
.chart-table table, .mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 6px; }
.chart-table th, .chart-table td, .mini-table th, .mini-table td { padding: 5px 8px; text-align: left; border-top: 1px solid var(--line); font-weight: 400; }
.chart-table thead th, .mini-table thead th { color: var(--muted); font-weight: 600; border-top: 0; }
.chart-table td, .mini-table .num { text-align: right; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge.new { background: var(--accent); color: var(--accent-ink); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.busy { background: var(--accent-soft); color: var(--accent); }

/* ---------- keyword detail ---------- */
.detail-head { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.detail-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.detail-title-row h1 { font-size: 24px; overflow-wrap: anywhere; min-width: 0; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.updated { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.updated strong { color: var(--ink); font-weight: 600; }
.error-banner { padding: 10px 12px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 13px; overflow-wrap: anywhere; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stat { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.stat dt { font-size: 12px; color: var(--muted); }
.stat dd { margin: 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat dd.err-text { color: var(--danger); }

.tabs { display: flex; gap: 4px; margin: 4px 4px 0; border-bottom: 1px solid var(--line); }
.tab {
  padding: 8px 12px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--muted); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab .count { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 500; margin-left: 4px; }
.tab-note { font-size: 12.5px; color: var(--muted); margin: 0 4px 10px; }

.post-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.post { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; content-visibility: auto; contain-intrinsic-size: auto 140px; }
.post-head { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; }
.post-rank { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 7px; background: var(--surface-2); font-size: 12px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.post-user { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.post-time { color: var(--muted); white-space: nowrap; }
.post-head .badge { margin-left: auto; }
.post-text { white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.post-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.metrics { display: flex; gap: 14px; font-variant-numeric: tabular-nums; }
.metrics span { display: inline-flex; gap: 4px; align-items: center; }
.metrics-wrap { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.metrics-age { font-size: 12px; color: var(--muted); }
.metrics svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.post-link { color: var(--accent); font-weight: 600; text-decoration: none; border-radius: 4px; }
.post-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.list-empty { padding: 32px 16px; text-align: center; color: var(--muted); font-size: 14px; border: 1px dashed var(--line); border-radius: var(--radius); }
.more-link { margin-top: 10px; }

/* ---------- dialog & toast ---------- */
.dialog {
  width: min(420px, calc(100% - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 0.25); overscroll-behavior: contain;
}
.dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.dialog h2 { font-size: 18px; margin-bottom: 8px; }
.dialog p { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast-region { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  max-width: min(360px, calc(100vw - 32px)); padding: 10px 14px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
  animation: toast-in 0.2s ease; overflow-wrap: anywhere;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- records page ---------- */
.filters { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.filter-grid { display: grid; grid-template-columns: 180px minmax(0, 1fr) 150px 96px; gap: 10px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filter-grid-activity { grid-template-columns: 220px 110px minmax(0, 1fr); }
.switch-inline { margin: 0; min-height: 40px; padding: 6px 12px; }
.filters select, .filters input[type="search"] {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background-color: var(--bg); color: var(--ink); font: inherit; font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.filters select:hover, .filters input[type="search"]:hover { border-color: color-mix(in srgb, var(--line) 50%, var(--ink)); }
.filters select:focus-visible, .filters input[type="search"]:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); border-radius: 10px;
}
.filters option { background-color: var(--surface); color: var(--ink); }

.status-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; border: 0; }
.status-chips legend { margin-bottom: 6px; }
.chip-radio { position: relative; cursor: pointer; }
.chip-radio input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.chip-radio > span {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  border: 1px solid var(--line); border-radius: 99px; font-size: 13px; font-weight: 600;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.chip-radio:hover > span { border-color: color-mix(in srgb, var(--line) 40%, var(--ink)); }
.chip-radio input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip-radio input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip-count { font-weight: 500; color: var(--muted); }
.chip-radio input:checked + span .chip-count { color: inherit; opacity: 0.8; }

.result-summary { font-size: 13px; color: var(--muted); margin: 0 4px; }
#results { outline: none; display: flex; flex-direction: column; gap: 16px; }

.day-group { display: flex; flex-direction: column; gap: 8px; }
.day-head {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 8px 4px; font-size: 14px; font-weight: 700;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px);
}
.day-count { font-size: 12px; font-weight: 500; color: var(--muted); }

.rec-list { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.rec {
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--line);
  content-visibility: auto; contain-intrinsic-size: auto 110px;
}
.rec:first-child { border-top: 0; }
.rec-time { font-size: 13px; font-weight: 700; color: var(--muted); padding-top: 1px; }
.rec-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rec-head { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; }
.rec-head .badge { margin-left: auto; }
.kw-chip {
  flex: none; max-width: 40%; padding: 1px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink); font-size: 12px; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background-color 0.15s ease;
}
.kw-chip:hover { background: var(--accent-soft); color: var(--accent); }
.rec-text { white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.rec-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.rec-time.long { font-size: 12.5px; }
.rec.is-error .rec-text { color: var(--danger); }
.rec .kw-chip.muted { color: var(--muted); }
.content :focus-visible { scroll-margin-top: 56px; }
.clear-btn { margin-top: 12px; }

.pager { display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager:empty { display: none; }
.pager-btn {
  display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--ink); font-size: 14px; font-weight: 600; text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.pager-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a.pager-btn:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--line) 50%, var(--ink)); }
.pager-btn.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pager-btn.disabled { opacity: 0.35; }
.pager-gap { color: var(--muted); padding: 0 2px; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .filter-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filter-grid .field-grow { grid-column: 1 / -1; order: -1; }
  .filter-grid-activity .switch-inline { grid-column: 1 / -1; }
}

/* Phones: the menu collapses into a drawer opened from a compact header. */
@media (max-width: 860px) {
  .add-row { flex-wrap: wrap; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .add-row .field-grow { flex-basis: 100%; }
  .add-row .switch-inline { flex: 1; }
  .kw-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .kw-table, .kw-table tbody, .kw-table tr { display: block; }
  .kw-table tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 14px; }
  .kw-table tbody th { grid-column: 1 / -1; padding: 0; }
  .kw-table td { display: flex; flex-direction: column; gap: 2px; padding: 0; }
  .kw-table td::before { content: attr(data-label); font-size: 11.5px; font-weight: 600; color: var(--muted); }
  .kw-table .num { text-align: left; }
  .row-actions { grid-column: 1 / -1; flex-direction: row !important; justify-content: flex-start; flex-wrap: wrap; gap: 6px !important; text-align: left !important; }
  .row-actions::before { display: none; }
  .row-actions .btn + .btn { margin-left: 0; }
  .table-empty { display: block !important; }
  .table-empty::before { display: none; }
  .shell { display: block; }
  .side { height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-top { padding: 10px 14px; }
  .brand-sub { display: none; }
  .side .side-toggle { display: inline-grid; }
  .side-body {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    max-height: calc(100dvh - 58px); background: var(--side);
    border-bottom: 1px solid var(--line); box-shadow: 0 16px 32px rgb(0 0 0 / 0.18);
  }
  .side[data-open="true"] .side-body { display: flex; }
  .content { padding: 18px 14px 40px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rec { grid-template-columns: 44px minmax(0, 1fr); padding: 12px; gap: 10px; }
  .day-head { top: 58px; }
  .content :focus-visible { scroll-margin-top: 110px; }
}
@media (max-width: 480px) {
  .page-head h1, .detail-title-row h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
