/* EAM web — design system + app chrome.
   Mirrors the macOS EAMCapture memory browser: sidebar (All, Screen, Audio,
   Clipboard, Web, Tags), list + detail pane, filter chips, translucent
   materials, light and dark. Theme: [data-tdh-theme] on <html> (shared with
   the Thundera shell, key "tdh.theme"), prefers-color-scheme as fallback. */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --bg-sunken: #ececf0;
  --material: rgba(246, 246, 248, 0.78);
  --material-strong: rgba(255, 255, 255, 0.86);
  --hover: rgba(0, 0, 0, 0.045);
  --selected: rgba(0, 113, 227, 0.12);
  --text: #1d1d1f;
  --text-2: #55555a;    /* 7.4:1 on white */
  --text-3: #6e6e73;    /* 4.9:1 on white */
  --border: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.18);
  --accent: #0071e3;
  --accent-text: #0066cc; /* 5.6:1 on white */
  --on-accent: #ffffff;
  --focus: rgba(0, 113, 227, 0.55);
  --danger: #d70015;
  --danger-bg: rgba(215, 0, 21, 0.08);
  --success: #1a7f37;
  --warning: #9a6700;
  --mark: rgba(255, 204, 0, 0.45);
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.18);

  --src-screen: #0071e3;
  --src-audio: #a22ed1;
  --src-clipboard: #c45500;
  --src-web: #1a7f37;
  --src-note: #6e6e73;

  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-xl: 20px;
  --sidebar-w: 236px;
  --detail-w: 440px;
  --row-h: 84px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --top: 0px;
}

:root[data-tdh-theme="dark"] {
  color-scheme: dark;
  --bg: #161618;
  --bg-elev: #1f1f22;
  --bg-sunken: #121214;
  --material: rgba(30, 30, 33, 0.72);
  --material-strong: rgba(36, 36, 40, 0.86);
  --hover: rgba(255, 255, 255, 0.06);
  --selected: rgba(10, 132, 255, 0.22);
  --text: #f5f5f7;
  --text-2: #c7c7cc;
  --text-3: #a1a1a6;    /* 6.9:1 on #1f1f22 */
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #0a84ff;
  --accent-text: #4da3ff;
  --on-accent: #ffffff;
  --focus: rgba(10, 132, 255, 0.6);
  --danger: #ff6961;
  --danger-bg: rgba(255, 69, 58, 0.14);
  --success: #32d74b;
  --warning: #ffd60a;
  --mark: rgba(255, 214, 10, 0.32);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 56px rgba(0,0,0,.55);
  --src-screen: #4da3ff;
  --src-audio: #da8fff;
  --src-clipboard: #ffb340;
  --src-web: #4cd964;
  --src-note: #a1a1a6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-tdh-theme]) {
    color-scheme: dark;
    --bg: #161618; --bg-elev: #1f1f22; --bg-sunken: #121214;
    --material: rgba(30, 30, 33, 0.72); --material-strong: rgba(36, 36, 40, 0.86);
    --hover: rgba(255, 255, 255, 0.06); --selected: rgba(10, 132, 255, 0.22);
    --text: #f5f5f7; --text-2: #c7c7cc; --text-3: #a1a1a6;
    --border: rgba(255, 255, 255, 0.1); --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #0a84ff; --accent-text: #4da3ff; --focus: rgba(10, 132, 255, 0.6);
    --danger: #ff6961; --danger-bg: rgba(255, 69, 58, 0.14); --success: #32d74b; --warning: #ffd60a;
    --mark: rgba(255, 214, 10, 0.32);
    --src-screen: #4da3ff; --src-audio: #da8fff; --src-clipboard: #ffb340; --src-web: #4cd964; --src-note: #a1a1a6;
  }
}

/* ------------------------------------------------------------------ Shell v2 mapping
   The app wears Thundera Shell v2 tokens (surfaces, text, borders, status) and the EAM
   brand accent (data-brand="eam" on <html>). The fallbacks are the dark values, used only
   if thundera.eu is unreachable. Source colours (--src-*) stay: they encode data, not brand. */
:root, :root[data-tdh-theme], body[data-brand] {
  --font: var(--th-font-sans, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
  --bg: var(--th-bg, #06080d);
  --bg-elev: var(--th-surface-1, #0e1219);
  --bg-sunken: var(--th-bg, #06080d);
  --material: color-mix(in srgb, var(--th-surface-1, #0e1219) 78%, transparent);
  --material-strong: color-mix(in srgb, var(--th-surface-2, #151a25) 88%, transparent);
  --hover: var(--th-surface-2, #151a25);
  --selected: var(--brand-soft, rgba(168, 85, 247, .16));
  --text: var(--th-text, #f4f6f9);
  --text-2: var(--th-text-2, #a6b0be);
  --text-3: var(--th-text-3, #808a99);
  --border: var(--th-border-2, rgba(255, 255, 255, .12));
  --border-strong: var(--th-border-3, rgba(255, 255, 255, .2));
  --accent: var(--brand-accent, #a855f7);
  --accent-text: var(--brand-accent, #a855f7);
  --on-accent: var(--brand-on, #0b0d12);
  --focus: var(--brand-glow, rgba(168, 85, 247, .55));
  --danger: var(--th-danger-text, #f87171);
  --danger-bg: var(--th-danger-soft, rgba(248, 113, 113, .14));
  --success: var(--th-success-text, #4ade80);
  --warning: var(--th-warning-text, #fbbf24);
  --r-sm: 8px; --r: 12px; --r-lg: 16px;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 14px/1.45 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
/* Shell v2 bar: sticky, 60px desktop / 56px mobile (--th-bar-h). The fixed app layout sits below it. */
body { --top: var(--th-bar-h, 60px); }
body:not(:has([data-th-bar])) { --top: 0px; }
/* The Shell v2 bar already carries the EAM mark and name. */
body:has([data-th-bar]) .sidebar-brand { display: none; }
/* Thundera shell dropdowns (apps, profile) are body children at z 9000. Closed,
   the shell only sets opacity:0 + pointer-events:none, and on phones (<=640px)
   the apps dropdown spans left:8px..right:8px under the bar: an invisible layer
   over the whole drawer. Real iOS Safari still targets it for touches and
   long-press selection (drawer items untappable, 2026-10-20), so closed
   dropdowns are visibility:hidden too; the delay keeps the close fade. */
/* Thundera consent manager's "Privacy choices" pill: position:fixed bottom-left
   at the top z-index, so it covered the sidebar/drawer footer ("Sign out",
   2026-10-20). On pages with the sidebar it is replaced by the sidebar's
   "Privacy choices" item, shown only while the consent manager has a pill. Old
   browsers without :has() keep the pill. */
.sidebar .side-privacy { display: none; }
@supports selector(:has(*)) {
  body.app .tdh-consent-settings { display: none; }
  :root:has(.tdh-consent-settings) .sidebar .side-privacy { display: flex; }
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre, kbd { font-family: var(--mono); font-size: 12.5px; }
pre { max-width: 100%; overflow-x: auto; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 5px; border: 1px solid var(--border-strong);
  border-bottom-width: 2px; border-radius: 5px; font-size: 11px; line-height: 1.5; text-align: center; color: var(--text-3);
}
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 1000; padding: 10px 14px; border-radius: var(--r);
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.skip-link:focus { top: calc(var(--top) + 12px); text-decoration: none; }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 15px; height: 15px; }
.i-lg { width: 22px; height: 22px; }

/* ------------------------------------------------------------------ controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; padding: 0 13px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger-solid { background: var(--danger); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; border-radius: 11px; }
.btn-icon { width: 32px; padding: 0; }
.btn-block { width: 100%; }

.field { display: grid; gap: 6px; }
.field > span, .label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%; height: 34px; padding: 0 11px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 160px; padding: 10px 11px; resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.hint { font-size: 12px; color: var(--text-3); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-2); font-size: 12.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { background: var(--hover); }
.chip[aria-pressed="true"] { background: var(--selected); color: var(--text); border-color: transparent; }
.chip[aria-pressed="true"] .i { color: var(--chip-color, var(--accent)); }
.chip .i { width: 15px; height: 15px; }
.chip-x { border: 0; background: none; padding: 0; margin-right: -4px; display: inline-flex; cursor: pointer; color: var(--text-3); }
.tag {
  display: inline-flex; align-items: center; gap: 4px; max-width: 160px; height: 20px; padding: 0 7px; border-radius: 999px;
  background: var(--bg-sunken); color: var(--text-2); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.material {
  background: var(--material);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
}

.src { color: var(--src-color); }
.src-screen { --src-color: var(--src-screen); }
.src-audio { --src-color: var(--src-audio); }
.src-clipboard { --src-color: var(--src-clipboard); }
.src-web { --src-color: var(--src-web); }
.src-note { --src-color: var(--src-note); }
.src-all { --src-color: var(--accent); }
.src-tile {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; flex: none;
  color: var(--src-color); background: color-mix(in srgb, var(--src-color) 14%, transparent);
}

/* ------------------------------------------------------------------ app layout */
.layout {
  position: fixed; inset: var(--top) 0 0 0; display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}
.sidebar {
  display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow-y: auto; padding: 14px 10px;
  border-right: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 14px; font-weight: 700; font-size: 15px; color: var(--text); }
.sidebar-brand .i { color: var(--accent); width: 22px; height: 22px; }
.sidebar-brand:hover { text-decoration: none; }
.side-section { margin: 14px 10px 4px; font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 32px; padding: 0 10px; border-radius: 8px;
  border: 0; background: none; color: var(--text); font-size: 13.5px; text-align: left; cursor: pointer; text-decoration: none;
}
.side-item:hover { background: var(--hover); text-decoration: none; }
.side-item[aria-current="page"], .side-item[aria-current="true"] { background: var(--selected); font-weight: 600; }
.side-item .i { color: var(--src-color, var(--accent)); }
.side-item .count { margin-left: auto; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.side-item .label-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-tags { display: grid; gap: 1px; }
.side-spacer { flex: 1; min-height: 16px; }
.side-foot { display: grid; gap: 2px; padding-top: 8px; border-top: 1px solid var(--border); }

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  position: relative; z-index: 5; display: grid; gap: 10px; padding: 12px 18px 10px;
  border-bottom: 1px solid var(--border); background: var(--material-strong);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
}
.toolbar-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.toolbar h1 { font-size: 20px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar .menu-btn { display: none; }
.search {
  position: relative; flex: 1; max-width: 520px; margin-left: auto;
}
.search .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search input { padding-left: 34px; padding-right: 34px; border-radius: 9px; background: var(--bg-sunken); border-color: transparent; }
.search input:focus { background: var(--bg-elev); }
.search kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search input:focus + kbd, .search input:not(:placeholder-shown) + kbd { display: none; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filters .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.filters select.input, .filters input.input { width: auto; height: 28px; font-size: 12.5px; border-radius: 999px; padding: 0 10px; }
.filters input[type="date"].input { padding: 0 8px; }
.filters .app-filter { width: 150px; }
.result-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-3); min-height: 18px; }
.result-meta .spacer { flex: 1; }
.kbd-hints { display: flex; gap: 10px; align-items: center; }

body.is-overview .filters, body.is-overview .result-meta { display: none; }
/* Brain Map tab: simplified map embedded in the browser (hidden via [hidden]). */
.brain-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.brain-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--bg-elev); min-width: 0; }
.brain-hint { color: var(--text); opacity: .75; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brain-bar .btn { flex: none; }
.brain-frame { flex: 1; min-height: 0; width: 100%; border: 0; background: var(--bg); }
body.is-brain .filters, body.is-brain .result-meta, body.is-brain #search-form { display: none; }
.panes { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) var(--detail-w); }
.panes.no-detail { grid-template-columns: minmax(0, 1fr); }

/* ------------------------------------------------------------------ list (virtualized) */
.list { position: relative; overflow-y: auto; min-height: 0; outline: none; overscroll-behavior: contain; }
.list:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); border-radius: 0; outline: none; }
.list-spacer { position: relative; width: 100%; }
.row {
  position: absolute; left: 0; right: 0; top: 0; height: var(--row-h); display: grid; grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); cursor: pointer; contain: strict;
}
.row:hover { background: var(--hover); }
.row[aria-selected="true"] { background: var(--selected); }
.row.active { box-shadow: inset 3px 0 0 var(--accent); }
.row-main { min-width: 0; display: grid; gap: 3px; align-content: start; }
.row-meta { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 12px; color: var(--text-3); }
/* The source/app label and time never shrink; tags take what is left and a chip
   that doesn't fit wraps out of sight (fixed height) instead of being cut mid-word. */
.row-meta .app { flex: none; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.row-meta .time { flex: none; white-space: nowrap; }
.row-meta .tags { flex: 1 1 0; display: flex; flex-wrap: wrap; gap: 4px; height: 20px; overflow: hidden; min-width: 0; }
.row-meta .sal { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-text {
  font-size: 13px; color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.list-footer { position: absolute; left: 0; right: 0; padding: 18px; text-align: center; font-size: 12px; color: var(--text-3); }
.sentinel { position: absolute; left: 0; right: 0; height: 1px; }

.skeleton { padding: 0; }
.sk-row { display: grid; grid-template-columns: 32px 1fr; gap: 12px; height: var(--row-h); padding: 12px 18px; border-bottom: 1px solid var(--border); }
.sk { border-radius: 6px; background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--hover) 50%, var(--bg-sunken) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
.sk-tile { width: 32px; height: 32px; border-radius: 9px; }
.sk-lines { display: grid; gap: 8px; align-content: start; }
.sk-line { height: 11px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.state {
  display: grid; place-items: center; align-content: center; gap: 10px; padding: 48px 24px; text-align: center; min-height: 260px; color: var(--text-2);
}
.state .i { width: 40px; height: 40px; color: var(--text-3); stroke-width: 1.4; }
.state h2 { font-size: 17px; color: var(--text); }
.state p { max-width: 420px; font-size: 13px; }
.state .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ------------------------------------------------------------------ detail */
.detail { min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-left: 1px solid var(--border); background: var(--bg-elev); }
.detail-inner { display: grid; gap: 18px; padding: 18px 22px 40px; }
.detail-head { display: flex; align-items: center; gap: 12px; }
.detail-head .title { min-width: 0; flex: 1; }
.detail-head h2 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-head .sub { font-size: 12px; color: var(--text-3); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.detail .back-btn { display: none; }
.meta-grid { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 12px; font-size: 13px; margin: 0; }
.meta-grid dt { color: var(--text-3); }
.meta-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter-bar { width: 120px; height: 6px; border-radius: 3px; background: var(--bg-sunken); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.mono { font-family: var(--mono); font-size: 12px; }
.detail-body {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; padding: 14px 16px; border-radius: var(--r);
  background: var(--bg-sunken); max-height: none;
}
.tag-editor { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-editor .tag { height: 26px; font-size: 12.5px; padding: 0 6px 0 10px; max-width: 220px; }
.tag-editor .tag button { border: 0; background: none; color: var(--text-3); cursor: pointer; display: inline-flex; padding: 2px; border-radius: 50%; }
.tag-editor .tag button:hover { color: var(--text); background: var(--hover); }
.tag-editor input { width: 140px; height: 26px; border-radius: 999px; font-size: 12.5px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.notice { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--r); background: var(--bg-sunken); font-size: 12.5px; color: var(--text-2); }
.notice .i { color: var(--accent); margin-top: 1px; }
.notice.warn { background: color-mix(in srgb, var(--warning) 12%, transparent); }
.notice.warn .i { color: var(--warning); }
.notice.danger { background: var(--danger-bg); }
.notice.danger .i { color: var(--danger); }

/* ------------------------------------------------------------------ overview */
.overview { overflow-y: auto; overscroll-behavior: contain; min-height: 0; padding: 22px 22px 60px; }
.overview-inner { max-width: 1100px; margin: 0 auto; display: grid; gap: 26px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.stat {
  display: grid; gap: 10px; padding: 16px; text-align: left; cursor: pointer; color: var(--text);
  transition: transform .15s var(--ease), box-shadow .15s;
}
.stat:hover { transform: translateY(-1px); text-decoration: none; }
.stat-top { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 13px; }
.stat-num { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-3); }
.recent { padding: 6px 0; }
.recent-row { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; padding: 10px 16px; color: var(--text); }
.recent-row:hover { background: var(--hover); text-decoration: none; }
.recent-row + .recent-row { border-top: 1px solid var(--border); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font-size: 16px; }
.getting-started { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.getting-started .card { padding: 18px; display: grid; gap: 8px; align-content: start; }

/* ------------------------------------------------------------------ toasts + dialogs */
.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 900; display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: var(--text);
  background: var(--material-strong); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  animation: toast-in .22s var(--ease);
}
.toast .msg { flex: 1; font-size: 13px; }
.toast.error .i { color: var(--danger); }
.toast.success .i { color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

dialog {
  border: 1px solid var(--border); border-radius: var(--r-xl); padding: 0; width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog-body { display: grid; gap: 12px; padding: 22px 22px 16px; }
.dialog-body h2 { font-size: 17px; }
.dialog-body p { color: var(--text-2); font-size: 13.5px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }
.secret-box { display: flex; gap: 8px; }
.secret-box input { font-family: var(--mono); font-size: 12px; }

/* ------------------------------------------------------------------ settings */
.settings { overflow-y: auto; overscroll-behavior: contain; min-height: 0; padding: 0 0 60px; }
.settings-inner { max-width: 860px; margin: 0 auto; padding: 18px 22px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.settings-inner .panel, .settings-inner .card { min-width: 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 2px; scrollbar-width: none; }

/* Horizontal strips (settings tabs, mobile filter row): fade the edge that has more
   content off-screen. Classes are set by scrollHint() in js/lib/dom.js. */
.scroll-hint.more-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
.scroll-hint.more-left { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); }
.scroll-hint.more-left.more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); }
.tabs [role="tab"] {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border: 0; border-radius: 8px;
  background: none; color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tabs [role="tab"]:hover { background: var(--hover); }
.tabs [role="tab"][aria-selected="true"] { background: var(--selected); color: var(--text); font-weight: 600; }
.panel { display: grid; gap: 16px; }
.panel > .card { padding: 20px; display: grid; gap: 14px; }
.panel h2 { font-size: 17px; }
.panel h3 { font-size: 14px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 10px 14px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.row-list { display: grid; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.row-item:first-child { border-top: 0; }
.row-item .grow { flex: 1; min-width: 0; }
.row-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .sub { font-size: 12px; color: var(--text-3); }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg-sunken); color: var(--text-2); }
.badge.ok { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.off { color: var(--text-3); }
.code-block { position: relative; }
.code-block pre {
  margin: 0; padding: 14px 16px; padding-right: 86px; border-radius: var(--r); background: var(--bg-sunken); overflow-x: auto;
  white-space: pre; line-height: 1.55;
}
.code-block .btn { position: absolute; top: 8px; right: 8px; height: 28px; font-size: 12px; }
.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--bg-sunken); gap: 2px; }
.segmented button { height: 28px; padding: 0 14px; border: 0; border-radius: 7px; background: none; color: var(--text-2); cursor: pointer; font-size: 13px; }
.segmented button[aria-checked="true"] { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.plan { padding: 14px; border-radius: var(--r); border: 1px solid var(--border); display: grid; gap: 6px; align-content: start; }
.plan.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan ul { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); }
.danger-card { border-color: color-mix(in srgb, var(--danger) 45%, transparent) !important; }

/* ------------------------------------------------------------------ auth pages */
.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--src-audio) 14%, transparent), transparent 60%), var(--bg); }
.auth-card { width: min(420px, 100%); padding: 32px 28px 26px; display: grid; gap: 18px; }
.auth-card .logo { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 15px; margin: 0 auto; color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--src-audio)); box-shadow: var(--shadow); }
.auth-card .logo .i { width: 30px; height: 30px; }
.auth-card h1 { font-size: 22px; text-align: center; }
.auth-card .lead { text-align: center; color: var(--text-2); font-size: 13.5px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.auth-foot { text-align: center; font-size: 12px; color: var(--text-3); }
details > summary { list-style: none; }
summary::-webkit-details-marker { display: none; }
details[open] > summary { background: var(--hover); }
.mt { margin-top: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.form-error { color: var(--danger); font-size: 13px; }

/* ------------------------------------------------------------------ mobile tab bar */
.tabbar { display: none; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  .panes { grid-template-columns: minmax(0, 1fr); }
  .detail {
    position: absolute; inset: 0 0 0 auto; width: min(var(--detail-w), 100%); z-index: 20; box-shadow: var(--shadow-lg);
    animation: slide-in .2s var(--ease);
  }
  .detail .back-btn { display: inline-flex; }
  .detail .close-btn { display: none; }
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 760px) {
  :root { --row-h: 92px; }
  .layout { grid-template-columns: minmax(0, 1fr); bottom: 58px; }
  :root { --drawer-w: min(300px, 86vw); }
  /* No -webkit-overflow-scrolling: a no-op since iOS 13 that still gives the
     drawer its own hit-testing layer under fixed/backdrop-filter parents. The
     drawer is navigation, not text: no selection or callout on long-press. */
  .sidebar {
    position: fixed; z-index: 60; top: var(--top); bottom: 0; left: 0; width: var(--drawer-w);
    max-height: calc(100dvh - var(--top)); padding-bottom: calc(14px + env(safe-area-inset-bottom));
    overscroll-behavior: contain; touch-action: pan-y;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
    background: var(--material-strong); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
    box-shadow: var(--shadow-lg); transform: translateX(-105%); transition: transform .22s var(--ease); visibility: hidden;
  }
  .sidebar > * { flex-shrink: 0; }
  .sidebar.open { transform: none; visibility: visible; }
  .sidebar .side-item, .sidebar .sidebar-brand {
    cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: var(--hover);
  }
  /* The scrim starts where the drawer ends, so it can never sit over a drawer
     item whatever iOS makes of the z-index (60 vs 55). Tap on it still closes. */
  .scrim { position: fixed; inset: 0 0 0 var(--drawer-w); z-index: 55; background: rgba(0,0,0,.3); touch-action: none; }
  /* While the drawer is open nothing invisible may sit above it. */
  html.drawer-open .tdh-dropdown:not([data-open="true"]) { display: none; }
  /* Drawer open: .layout (position:fixed = its own stacking context, holding the
     drawer + scrim) goes above the tab bar; the page behind is locked. */
  html.drawer-open .layout { z-index: 70; }
  html.drawer-open, html.drawer-open body { overflow: hidden; overscroll-behavior: none; }
  .toolbar { padding: 10px 12px 8px; }
  .toolbar .menu-btn { display: inline-flex; }
  .toolbar-row.top { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .search kbd, .kbd-hints { display: none; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px; }
  .row { padding: 12px 14px; }
  .detail { width: 100%; }
  /* Phones: the memory text comes right after the title; actions and metadata follow. */
  .detail-head { order: -2; }
  .detail-content { order: -1; }
  .meta-grid, .kv { grid-template-columns: 96px minmax(0, 1fr); }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(58px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--border); background: var(--material-strong);
    -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  }
  .tabbar a, .tabbar button {
    display: grid; place-items: center; align-content: center; gap: 2px; border: 0; background: none; color: var(--text-3);
    font-size: 10.5px; font-weight: 500; text-decoration: none; cursor: pointer;
  }
  .tabbar [aria-current="page"] { color: var(--accent-text); }
  .tabbar .i { width: 22px; height: 22px; }
  .overview, .settings-inner { padding-left: 14px; padding-right: 14px; }
  .toasts { bottom: 74px; }
}

/* No backdrop-filter: translucent materials would go see-through, so use solid surfaces. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .material, .toolbar, .toast, .sidebar, .tabbar { background: var(--bg-elev); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .sk { animation: none; }
}

@media (forced-colors: active) {
  .row[aria-selected="true"], .side-item[aria-current] { outline: 2px solid Highlight; }
}
