/* Histotree v2 — earth & parchment, now with dark mode */
:root {
  --bg: #fcf9f2;
  --surface: #f7f2e7;
  --surface-2: #ffffff;
  --trunk: #33241b;
  --trunk-2: #433126;
  --bark: #5a4233;
  --line: #e1d6c2;
  --line-strong: #d2c4b0;
  --text: #261f1a;
  --text-muted: #6e6155;
  --text-on-trunk: #fefae0;
  --dot: #ebe1cf;
  --accent: #047857;
  --accent-soft: #d1fae5;
  --accent-ink: #065f46;
  --focus: #1d63ed;
  --shadow: 0 12px 28px rgba(40, 28, 20, .18), 0 4px 10px rgba(40, 28, 20, .08);
  --radius: 14px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1511;
    --surface: #231b16;
    --surface-2: #2c231d;
    --trunk: #120d0a;
    --trunk-2: #2a1f18;
    --bark: #4a372b;
    --line: #3a2e26;
    --line-strong: #4d3e33;
    --text: #f3ece0;
    --text-muted: #b3a595;
    --text-on-trunk: #fefae0;
    --dot: #2e241d;
    --accent: #34d399;
    --accent-soft: #11382b;
    --accent-ink: #a7f3d0;
    --focus: #7aa7ff;
    --shadow: 0 12px 28px rgba(0, 0, 0, .5), 0 4px 10px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1511; --surface: #231b16; --surface-2: #2c231d; --trunk: #120d0a; --trunk-2: #2a1f18;
  --bark: #4a372b; --line: #3a2e26; --line-strong: #4d3e33; --text: #f3ece0; --text-muted: #b3a595;
  --text-on-trunk: #fefae0; --dot: #2e241d; --accent: #34d399; --accent-soft: #11382b; --accent-ink: #a7f3d0;
  --focus: #7aa7ff; --shadow: 0 12px 28px rgba(0, 0, 0, .5), 0 4px 10px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font-ui);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -40px; z-index: 50; background: var(--trunk); color: var(--text-on-trunk); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
kbd { font: 600 11px var(--font-ui); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; margin: 0 1px; }

.scroll-x { overflow-x: auto; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
/* Computers with a mouse: show a thin scrollbar so hidden chips are discoverable */
@media (pointer: fine) {
  .scroll-x { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
}
/* Fade whichever edge has more content beyond it */
.fade-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 56px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 56px), transparent); }
.fade-left { -webkit-mask-image: linear-gradient(to right, transparent, #000 56px); mask-image: linear-gradient(to right, transparent, #000 56px); }
.fade-left.fade-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 56px, #000 calc(100% - 56px), transparent); mask-image: linear-gradient(to right, transparent, #000 56px, #000 calc(100% - 56px), transparent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 7px 14px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s, transform .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent-soft); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent-soft) 70%, var(--accent) 30%); }
.btn-dark { background: var(--trunk); color: var(--text-on-trunk); }
.btn-dark:hover { background: var(--trunk-2); }
.btn-ghost { background: var(--surface-2); border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { border-color: var(--bark); }
.btn-link { background: none; border: none; color: var(--text-muted); text-decoration: underline; padding: 4px 6px; }

.icon-btn {
  display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface-2);
  cursor: pointer; font-size: 17px; line-height: 1; font-weight: 600;
}
.icon-btn.wide { font-size: 12px; }
.icon-btn:hover { border-color: var(--bark); }

.chip {
  flex: none; padding: 5px 12px; border-radius: 999px; border: 1.5px solid var(--line-strong);
  background: var(--surface-2); font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: var(--bark); }
.chip[aria-pressed="true"] { background: var(--c, var(--trunk)); border-color: var(--c, var(--trunk)); color: #fff; }
.chip .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 6px; vertical-align: 1px; }
.chip[aria-pressed="true"] .swatch { background: #fff; }
.chip .n { opacity: .6; font-weight: 500; margin-left: 4px; }

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { width: 38px; height: 38px; color: var(--trunk); flex: none; }
.brand h1 { margin: 0; font: 800 24px/1 var(--font-display); letter-spacing: .01em; }
.tagline { margin: 3px 0 0; font-size: 12px; color: var(--text-muted); }

.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search svg { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--text-muted); stroke-width: 2; stroke-linecap: round; }
.search input {
  width: 100%; padding: 9px 14px 9px 36px; border-radius: 999px;
  border: 1.5px solid var(--line-strong); background: var(--surface-2);
}
.search input:focus { border-color: var(--bark); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }

.header-actions { display: flex; align-items: center; gap: 8px; }
.segmented { display: inline-flex; border: 1.5px solid var(--line-strong); border-radius: 999px; padding: 2px; background: var(--surface-2); }
.segmented button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--text-muted); }
.segmented button[aria-pressed="true"] { background: var(--trunk); color: var(--text-on-trunk); }

/* ---------- Toolbar & filters ---------- */
.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 20px 6px; background: var(--surface);
}
.eras { display: flex; gap: 6px; flex: 0 1 auto; min-width: 0; }
.range { display: flex; align-items: center; gap: 6px; position: relative; }
.range input {
  width: 92px; padding: 6px 10px; border-radius: 8px; border: 1.5px solid var(--line-strong);
  background: var(--surface-2); font-size: 13px;
}
.range input[aria-invalid="true"] { border-color: #d92652; }
.range-error { position: absolute; top: 100%; left: 0; font-size: 11px; color: #d92652; white-space: nowrap; }
.zoom { display: flex; gap: 4px; }
.group-select select {
  padding: 6px 30px 6px 12px; border-radius: 999px; border: 1.5px solid var(--line-strong);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' stroke='%236e6155' stroke-width='2' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center / 10px;
  appearance: none; font-weight: 600; font-size: 13px; cursor: pointer;
}

.filters {
  display: flex; align-items: center; gap: 18px; padding: 6px 20px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.filter-set { display: flex; align-items: center; gap: 8px; flex: none; }
.filter-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.chip-row { display: flex; gap: 6px; }
.chip-row:empty::after { content: "—"; color: var(--text-muted); }

.breadcrumb {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 20px; background: var(--trunk); color: var(--text-on-trunk); font-size: 13px;
}
.breadcrumb button { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; padding: 2px 4px; font-weight: 600; }
.breadcrumb [aria-current] { font-weight: 700; }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .back { margin-right: 8px; text-decoration: none; background: var(--trunk-2); border-radius: 999px; padding: 4px 12px; }

/* ---------- Stage ---------- */
/* position: relative keeps .sr-only labels inside the scrolling rows (otherwise they widen the page) */
.app-header, .toolbar, .filters, .breadcrumb, .app-footer { flex: none; position: relative; }
.stage { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
#timeline { /* vis-timeline forces position: relative on its container */
  width: 100%; height: 100%;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px);
  background-size: 28px 28px;
}
.overlay {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 12px;
  text-align: center; color: var(--text-muted); z-index: 5; pointer-events: none;
}
.overlay > * { pointer-events: auto; }
.loading { background: var(--bg); }
.skeleton { display: grid; gap: 10px; width: min(420px, 80vw); }
.skeleton span { height: 22px; border-radius: 18px 3px 18px 3px; background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.skeleton span:nth-child(1) { width: 60%; }
.skeleton span:nth-child(2) { width: 85%; margin-left: 12%; }
.skeleton span:nth-child(3) { width: 45%; margin-left: 30%; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton span { animation: none; } * { transition: none !important; } }

.notice {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px);
  padding: 8px 8px 8px 16px; border-radius: 999px; background: var(--trunk); color: var(--text-on-trunk);
  box-shadow: var(--shadow); font-size: 13px;
}
.notice .btn-link { color: var(--text-on-trunk); }
.notice .icon-btn { background: transparent; border-color: transparent; color: inherit; height: 26px; min-width: 26px; }

/* ---------- Footer ---------- */
.app-footer {
  display: flex; gap: 16px; align-items: center; padding: 6px 20px;
  font-size: 12px; color: var(--text-muted); background: var(--surface); border-top: 1px solid var(--line);
}
.app-footer .credit { margin-left: auto; }
#count { font-weight: 600; color: var(--text); }

/* ---------- vis-timeline theme ---------- */
.vis-timeline { border: none !important; font-family: var(--font-ui); }
.vis-panel.vis-left {
  background: var(--trunk) !important; border-right: 4px solid var(--bark) !important;
  box-shadow: 4px 0 12px rgba(40, 28, 20, .2);
}
.vis-panel.vis-top, .vis-panel.vis-bottom, .vis-panel.vis-center, .vis-panel.vis-left, .vis-panel.vis-right { border-color: var(--line) !important; }
.vis-labelset .vis-label {
  color: var(--text-on-trunk); border-bottom: 2px solid var(--bark) !important;
  border-left: 6px solid var(--c, var(--bark));
}
.vis-labelset .vis-label .vis-inner {
  color: color-mix(in srgb, var(--c, #fff) 45%, #fff) !important;
  padding: 12px 16px 12px 12px; font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap;
}
.vis-foreground .vis-group { border-bottom: 2px solid var(--line) !important; }
.vis-time-axis .vis-text { color: var(--text-muted) !important; font-weight: 700; font-size: 11px; }
.vis-time-axis .vis-grid.vis-minor { border-color: color-mix(in srgb, var(--line) 70%, transparent) !important; border-left-style: dashed !important; }
.vis-time-axis .vis-grid.vis-major { border-color: var(--line) !important; }

.vis-item {
  background: var(--c, #6b5a4c) !important; border: 1.5px solid rgba(255, 255, 255, .45) !important;
  color: #fff !important; font-size: 12px; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 8px rgba(45, 32, 24, .22);
}
.vis-item.vis-box, .vis-item.vis-range { border-radius: 18px 3px 18px 3px !important; transition: box-shadow .15s, filter .15s; }
.vis-item.vis-box:hover, .vis-item.vis-range:hover { box-shadow: 0 6px 14px rgba(45, 32, 24, .35); filter: brightness(1.08); }
.vis-item.vis-selected { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--c) !important; z-index: 3; }
.vis-item.vis-dimmed { opacity: .35; }
.vis-item .vis-item-content { padding: 4px 12px !important; white-space: nowrap; }
.vis-item .vis-item-overflow { overflow: visible !important; }
/* Ranges: tinted span with ink text, so labels stay readable when the span is narrower than its title */
.vis-item.vis-range {
  background: color-mix(in srgb, var(--c) 20%, var(--bg)) !important;
  border: 2px solid var(--c) !important; color: var(--text) !important; box-shadow: none;
}
.vis-item.vis-range .vis-item-content { color: var(--text); padding-left: 10px !important; }
.vis-item.vis-range .sub-count { background: var(--c); color: #fff; }
.vis-item.vis-line { background: none !important; border: 0 !important; border-left: 2px dashed var(--c) !important; box-shadow: none !important; opacity: .7; }
.vis-item.vis-dot { border-color: var(--c) !important; box-shadow: none !important; }
/* Single-year events: colored dot + ink title, no pill, so they take one slim line */
.vis-item.vis-point {
  background: none !important; border: 0 !important; box-shadow: none !important; color: var(--text) !important;
  transition: filter .15s;
}
.vis-item.vis-point .vis-item-content { color: var(--text); padding: 2px 6px 2px 4px !important; border-radius: 6px; }
.vis-item.vis-point:hover .vis-item-content { background: color-mix(in srgb, var(--c) 14%, transparent); }
.vis-item.vis-point.vis-selected { box-shadow: none !important; }
.vis-item.vis-point.vis-selected .vis-item-content { background: color-mix(in srgb, var(--c) 22%, transparent); box-shadow: 0 0 0 2px var(--c); }
.vis-item.vis-point .vis-dot {
  background: var(--c) !important; border: 2px solid var(--bg) !important; box-shadow: 0 0 0 1.5px var(--c) !important;
  width: 12px; height: 12px; border-radius: 50%;
}
.vis-item.vis-point .sub-count { background: var(--c); color: #fff; }
.vis-item .sub-count { margin-left: 6px; padding: 0 6px; border-radius: 999px; background: rgba(255, 255, 255, .25); font-size: 11px; }
.vis-current-time { background: var(--text-muted) !important; width: 2px !important; opacity: .6; }
.vis-current-time::after {
  content: "Today"; position: absolute; bottom: 8px; left: 6px; /* bottom: clear of the axis labels */
  font: 700 10px var(--font-ui); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted);
}
div.vis-tooltip { font-family: var(--font-ui) !important; background: var(--trunk) !important; color: var(--text-on-trunk) !important; border: 0 !important; border-radius: 8px !important; padding: 6px 10px !important; box-shadow: var(--shadow) !important; font-size: 12px !important; }

/* ---------- Popover / bottom sheet ---------- */
.popover {
  position: fixed; z-index: 40; width: min(340px, calc(100vw - 32px)); max-height: min(70vh, 520px); overflow: auto;
  padding: 18px 18px 16px; border-radius: var(--radius); background: var(--surface-2);
  border: 1px solid var(--line-strong); box-shadow: var(--shadow);
}
.popover:focus { outline: none; }
.pop-close { position: absolute; top: 10px; right: 10px; }
.pop-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-right: 36px; }
.badge { padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #fff; background: var(--c, var(--bark)); }
.badge.outline { background: none; color: var(--text-muted); border: 1px solid var(--line-strong); }
.popover h2 { margin: 10px 0 2px; font: 700 19px/1.25 var(--font-display); }
.pop-date { margin: 0 0 10px; font-size: 12px; font-weight: 700; color: var(--text-muted); }
.pop-synopsis { margin: 0 0 12px; font-size: 13.5px; line-height: 1.55; }
.pop-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; }
.pop-tags button { border: 0; background: var(--surface); color: var(--text-muted); border-radius: 999px; padding: 2px 8px; font-size: 11px; cursor: pointer; }
.pop-tags button:hover { color: var(--text); }
.pop-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- List view ---------- */
.list-view { position: absolute; inset: 0; overflow: auto; padding: 20px max(20px, calc((100% - 820px) / 2)); background: var(--bg); z-index: 4; }
.list-view:focus { outline: none; }
.list-view h2 { font: 700 15px var(--font-display); color: var(--text-muted); margin: 24px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.list-view h2:first-child { margin-top: 0; }
.list-view ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card {
  position: relative; padding: 14px 16px 14px 20px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--line); overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.card h3 { margin: 6px 0 2px; font: 700 17px/1.3 var(--font-display); }
.card .pop-date { margin-bottom: 6px; }
.card p { margin: 0 0 10px; }
.card .pop-actions .btn { padding: 5px 12px; font-size: 12px; }
.list-empty { text-align: center; color: var(--text-muted); padding: 40px 0; }

/* ---------- Suggest dialog ---------- */
.suggest {
  width: min(640px, calc(100vw - 24px)); height: min(760px, calc(100dvh - 24px)); padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface-2); color: var(--text);
  box-shadow: var(--shadow);
}
.suggest[open] { display: grid; grid-template-rows: auto 1fr; }
.suggest::backdrop { background: rgba(35, 25, 20, .6); backdrop-filter: blur(2px); }
.suggest-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.suggest-head h2 { margin: 0; font: 700 20px var(--font-display); }
.suggest-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }
.suggest-frame { position: relative; background: #fff; }
.suggest-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- Custom timelines ---------- */
.tl-switch select { max-width: 220px; text-overflow: ellipsis; }
.custom-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: none; position: relative;
  padding: 8px 20px; background: var(--accent-soft); color: var(--accent-ink); border-bottom: 1px solid var(--line); font-size: 13px;
}
.custom-bar .name { font: 700 15px var(--font-display); color: var(--text); }
.custom-bar .meta { color: var(--text-muted); }
.custom-bar .toggle { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text); font-weight: 600; }
.custom-bar .toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.custom-bar .legend { color: var(--text-muted); }
.custom-bar .spacer { flex: 1; }
.custom-bar .btn { padding: 5px 12px; }
.btn-link.danger { color: #c8234b; }

/* Visitor-made events: diamond dot / dashed span, so they stand out when mixed with world events */
.vis-item.vis-point.is-custom .vis-dot { border-radius: 2px; rotate: 45deg; } /* `rotate`, not transform: vis sets an inline transform */
.vis-item.vis-range.is-custom { border-style: dashed !important; }
.legend-diamond { display: inline-block; width: 9px; height: 9px; background: var(--accent); transform: rotate(45deg); border-radius: 1px; margin-right: 4px; }

.panel-dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: auto;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface-2); color: var(--text); box-shadow: var(--shadow);
}
.panel-dialog::backdrop { background: rgba(35, 25, 20, .6); backdrop-filter: blur(2px); }
.panel-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font: 700 20px var(--font-display); }
.panel-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 13px; }
.panel-body { padding: 16px 20px; }
.panel-foot { display: flex; align-items: center; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.panel-foot .spacer { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.field em { font-style: normal; font-weight: 500; opacity: .8; }
.field input, .field textarea, .manage-row input, .manage-new input {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--line-strong); background: var(--bg); font-size: 14px;
}
.field textarea { resize: vertical; min-height: 70px; font-family: inherit; }
.field input:focus, .field textarea:focus, .manage-row input:focus, .manage-new input:focus { outline: none; border-color: var(--bark); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.field input[aria-invalid="true"] { border-color: #d92652; }
.field-error { color: #d92652; font-size: 12px; min-height: 0; }
.field-error:empty { display: none; }

.manage-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.manage-row { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.manage-row.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.manage-row input { flex: 1; min-width: 0; font-weight: 600; }
.manage-row .n { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.manage-row .btn { padding: 5px 10px; font-size: 12px; }
.manage-empty { color: var(--text-muted); margin: 0 0 16px; }
.manage-new { display: flex; gap: 8px; margin-bottom: 14px; }
.manage-new input { flex: 1; }
.manage-import { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); padding-top: 14px; border-top: 1px solid var(--line); }
.manage-import input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  body { font-size: 14px; }
  .app-header { padding: 10px 16px; gap: 10px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand h1 { font-size: 21px; }
  .tagline { display: none; }
  .search { order: 3; flex: 1 1 100%; max-width: none; }
  .hide-sm { display: none; }
  /* One swipeable row instead of three stacked ones */
  .toolbar { padding: 8px 16px 4px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: none; }
  .eras { overflow: visible; }
  .range input { width: 76px; }
  .range-error { display: none; }
  .vis-labelset .vis-label .vis-inner { padding: 8px 8px 8px 6px; font-size: 10px; letter-spacing: .04em; }
  .vis-labelset .vis-label { border-left-width: 4px; }
  .filters { padding: 4px 16px 8px; }
  .breadcrumb { padding: 8px 16px; }
  .app-footer { padding: 6px 16px; }
  .app-footer .credit { display: none; }
  .list-view { padding: 16px; }
  .header-actions { flex-wrap: wrap; width: 100%; }
  .tl-switch { flex: 1 1 100%; }
  .tl-switch select { max-width: none; width: 100%; }
  .custom-bar { padding: 8px 16px; gap: 6px 8px; }
  .custom-bar .legend, .custom-bar .spacer { display: none; }
  .custom-bar .btn { padding: 4px 10px; font-size: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .manage-row { flex-wrap: wrap; }
  .manage-row input { flex-basis: 100%; }

  .popover {
    left: 0 !important; right: 0; bottom: 0; top: auto !important; width: 100%; max-height: 65dvh;
    border-radius: 18px 18px 0 0; border-width: 1px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}
