/* ========================================================================
   BGP Bangladesh - Styles
   Light house palette, responsive layout, tab navigation
   ======================================================================== */

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Base ── */
:root {
  /* House palette: calm sand paper, ink text, phthalo green accent, rust and
     ochre as the only warm signals. Text pairs are checked in
     tests-js/colors.test.js. */
  --bg-primary: #e8e1cf;    /* paper */
  --bg-secondary: #f1ebda;  /* panels: header, sidebar, dialogs */
  --bg-card: #f5f0e2;       /* fields and cards */
  --bg-raised: #dcd4bf;     /* hover, selection, tracks */
  --border: #a9a88c;
  --border-soft: #cac6ac;
  --accent: #14453a;
  --accent-hover: #0f3b31;
  --accent-soft: #cfdbd0;
  --green: #14453a;
  --red: #8c4328;
  --red-soft: #efdbca;
  --warn: #6f5416;
  --warn-soft: #e9ddbb;
  --text: #2b3129;
  --text-muted: #4e5346;
  --text-dim: #56584b;      /* lightest ink that still meets 4.5:1 on --bg-raised */
  --reverse: #f5f0e2;       /* text on a filled block */
  --shadow: 0 1px 2px rgba(43, 49, 41, 0.08), 0 12px 26px -18px rgba(43, 49, 41, 0.55);
  /* Network categories: muted Okabe-Ito hues, safe for colour vision
     deficiency. Same values as CATEGORY_COLORS in assets/js/ui/colors.js. */
  --cat-local-company: #27598a;
  --cat-iig: #2f8a68;
  --cat-detected-iig: #c4901f;
  --cat-offshore-enterprise: #67a8cc;
  --cat-offshore-gateway: #b26a98;
  --cat-outside: #b4532a;
  --radius: 6px;
  --transition: 0.2s ease;
  /* What buttons and list items animate; never `all` (CLAUDE.md). */
  --transition-ui: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease, filter 0.2s ease;
  color-scheme: light;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  accent-color: var(--accent);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;   /* the visible height on phones, as browser bars come and go */
  /* Better mobile scrolling */
  -webkit-overflow-scrolling: touch;
  -webkit-tap-highlight-color: transparent;
}

/* ── Accessibility helpers ── */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -100px;
  z-index: 30000;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: bold;
  border-radius: var(--radius);
  text-decoration: none;
}

.skip-link:focus { top: 8px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* These turn the default outline off for their custom focus style; restore a
   visible ring for keyboard focus. */
input[type="range"]:focus-visible,
.table-search:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Charts are focusable for keyboard pan/zoom. */
#viz-panel svg:focus-visible { outline-offset: -3px; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.noscript-message {
  position: fixed;
  inset: auto 16px 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  z-index: 30000;
}

.noscript-message a { color: var(--accent); }

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

/* ── Layout ── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

#sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 2px solid var(--border);
  overflow: hidden;
  z-index: 100;
  transition: transform 0.3s ease;
}

#sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-footer-copy { display: none; }

#sidebar-header .site-name {
  font-size: 18px;
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 8px;
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 16px;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Top Bar ── */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.top-bar-title { font-size: 14px; font-weight: 600; color: var(--accent); }

/* ── Header search (assets/js/ui/search.js) ── */
.site-search { position: relative; display: flex; align-items: center; width: min(320px, 40vw); }
.site-search-icon { position: absolute; left: 10px; width: 14px; height: 14px; color: var(--text-muted); pointer-events: none; }
.site-search-input {
  width: 100%;
  min-height: 32px;
  padding: 6px 30px 6px 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}
.site-search-input::placeholder { color: var(--text-dim); }
.site-search-input:focus { border-color: var(--accent); outline: none; }
.site-search-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.site-search-key {
  position: absolute;
  right: 8px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-muted);
  font: 11px/16px ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
}
.site-search-input:focus ~ .site-search-key { display: none; }
.site-search-list {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 2000;
  width: max(100%, 360px);
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.site-search-list [role="option"] {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.site-search-list [role="option"][aria-selected="true"] { background: var(--bg-raised); }
@media (hover: hover) and (pointer: fine) { .site-search-list [role="option"]:hover { background: var(--bg-raised); } }
.site-search-list [role="option"][aria-selected="true"] { box-shadow: inset 3px 0 0 var(--accent); }
/* Whole names: two networks often share the start ("Summit Communications ..."). */
.search-opt-name { color: var(--text); font-size: 13px; line-height: 1.25; overflow-wrap: anywhere; }
.search-opt-meta { color: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.search-empty { padding: 8px; color: var(--text-muted); font-size: 13px; }
/* Phone-only controls (see the compact breakpoint) */
.site-search-close, .site-search-open { display: none; }

#data-source-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Tabs ── */
/* The baseline is an inset shadow rather than a border so the active tab's
   underline can cover it without a negative margin; overflow clips to the
   padding box, and a tab reaching into the border made the bar scroll
   vertically. When the tabs don't fit, they scroll sideways and the right
   edge fades to show there is more. */
#tab-nav {
  display: flex;
  flex-shrink: 0;
  gap: 2px;
  padding: 0 16px;
  background: var(--bg-secondary);
  box-shadow: inset 0 -2px 0 var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  /* A side fades only while it hides more tabs (classes from ui/tab-strip.js),
     so a reader can tell more views exist. --strip-edge: the part of each end
     covered by the menu and search buttons on phones, hidden outright. */
  --strip-edge: 0px;
  --fade-l: 0px;
  --fade-r: 0px;
  --strip-mask: linear-gradient(to right,
    transparent var(--strip-edge),
    black calc(var(--strip-edge) + var(--fade-l)),
    black calc(100% - var(--strip-edge) - var(--fade-r)),
    transparent calc(100% - var(--strip-edge)));
  mask-image: var(--strip-mask);
  -webkit-mask-image: var(--strip-mask);
}
#tab-nav.more-left { --fade-l: 40px; }
#tab-nav.more-right { --fade-r: 40px; }

#tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 10px 16px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: var(--transition-ui);
}

/* Narrow desktops: tighter tabs so all six fit beside the sidebar. */
@media (max-width: 1150px) {
  .tab-btn { padding: 10px 11px; }
}

@media (hover: hover) and (pointer: fine) {
  .tab-btn:hover {
    color: var(--text);
    background: var(--bg-card);
  }
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* ── Viz Panel ── */
#viz-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#viz-panel svg {
  width: 100%;
  height: 100%;
}

/* ── Buttons ── */
.btn {
  background: var(--accent);
  color: var(--bg-primary);
  border: none;
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  transition: var(--transition-ui);
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) { .btn:hover { background: var(--accent-hover); transform: translateY(-1px); } }
.btn:active { transform: translateY(0); }

/* Touch screens get no hover styles (they stick after a tap), so a press
   shows its own feedback. */
.btn:active, .btn-my-asn:active { background: var(--accent-hover); }
.btn-outline:active, .tab-btn:active, .viz-ctrl-btn:active, .timeline-btn:active,
.mobile-menu-btn:active, .detail-close:active, .asn-item:active, .bar-row:active,
.clickable-row:active td { background: var(--bg-raised); }

/* Controls aren't text: a long press (holding the date arrows, say) must not
   select the page or open the copy menu, and taps fire without waiting to see
   whether a double-tap zoom follows. */
button, [role="button"], .asn-item, #viz-panel svg {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button, a, [role="button"], label, input[type="range"] { touch-action: manipulation; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-small { padding: 4px 10px; font-size: 11px; }
.btn-active { background: var(--accent); color: var(--bg-primary); }

.btn-danger { background: var(--red); }
@media (hover: hover) and (pointer: fine) { .btn-danger:hover { background: #7d3b23; } }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
@media (hover: hover) and (pointer: fine) { .btn-outline:hover { border-color: var(--accent); color: var(--accent); background: transparent; } }

.btn-primary { background: var(--accent); }
.btn-cancel { background: var(--red); }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Stats ── */
.stat {
  background: var(--bg-card);
  padding: 8px 10px;
  margin: 6px 0;
  border-radius: 4px;
  border-left: 3px solid var(--accent);
}

.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
/* Keep the "?" beside the label when a narrow tile wraps it onto two lines. */
.stat-label:has(.term-help) { display: flex; align-items: flex-start; }
.stat-label .term-help { margin: -1px 0 0 3px; }
.stat-value { font-size: 18px; font-weight: bold; color: var(--accent); font-variant-numeric: tabular-nums; }

/* ── ASN List ── */
.sidebar-section-title {
  font-size: 13px;
  margin: 16px 0 8px 0;
  font-weight: 600;
}

.sidebar-section-title.outside { color: var(--red); }

/* Scrollable ASN lists */
#local-company-list, #iig-list, #outside-list {
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-x: hidden;
  padding-right: 4px;
}

.asn-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  border: 0;
  background: var(--bg-card);
  padding: 6px 8px;
  margin: 4px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition-ui);
  border-left: 3px solid transparent;
}

.asn-item > span { display: block; }

@media (hover: hover) and (pointer: fine) { .asn-item:hover { background: var(--bg-raised); transform: translateX(3px); } }
.asn-item.outside { border-left-color: var(--red); }
.asn-item.highlighted { background: var(--bg-raised); border-left-width: 5px; }

.asn-name { font-weight: bold; font-size: 12px; }
.asn-details { font-size: 10px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asn-traffic { font-size: 11px; color: var(--accent); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ── Controls ── */
.controls-section {
  margin: 12px 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.control-group { margin: 10px 0; }

.control-group label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  background: var(--border);
  outline: none;
  border-radius: 2px;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  cursor: pointer;
  border-radius: 50%;
}

.filter-value { color: var(--accent); font-weight: bold; }

/* ── Tooltip ── */
.tooltip {
  position: fixed;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px;
  pointer-events: none;
  font-size: 12px;
  max-width: 380px;
  box-shadow: var(--shadow);
  z-index: 10000;
}

.tooltip-title { font-weight: bold; font-size: 13px; margin-bottom: 4px; color: var(--accent); }
.tip-licensed { color: var(--accent); font-size: 9px; }
.tip-warn { color: var(--warn); font-weight: bold; }
.tip-offshore { color: var(--red); }
.tooltip-insight a { color: inherit; text-decoration: underline; }
.tooltip-row { margin: 3px 0; display: flex; justify-content: space-between; gap: 12px; }
.tooltip-label { color: var(--text-muted); }
.tooltip-value { color: var(--text); font-weight: bold; }
.tooltip-insight { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border-soft); font-size: 10px; color: var(--text-muted); line-height: 1.4; font-style: italic; }
.tooltip-detail { font-size: 10px; color: var(--text-muted); line-height: 1.5; padding-left: 4px; }
/* Only the phone details sheet can be closed by hand; a hover tooltip closes
   when the pointer leaves. */
.tooltip .tooltip-close { display: none; }

/* ── Glossary "?" buttons and their popover (assets/js/ui/glossary.js) ── */
.term-help {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  /* With the margins, a 24px circle around it touches no other control (WCAG 2.5.8). */
  margin: 0 5px 0 6px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: none;
  color: var(--accent);
  font: bold 10px/1 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  text-transform: none;
  letter-spacing: 0;
  vertical-align: 1px;
  cursor: help;
  flex: none;
}
/* 24px target (WCAG 2.5.8) without a bigger circle */
.term-help::after { content: ''; position: absolute; inset: -5px; }
.term-help[aria-expanded="true"] { background: var(--accent); color: var(--bg-primary); }
@media (hover: hover) and (pointer: fine) { .term-help:hover { background: var(--accent); color: var(--bg-primary); } }
.term-help:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.term-popover {
  position: fixed;
  z-index: 20000;
  max-width: calc(100vw - 16px);
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  font: normal 13px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
  cursor: auto;
}
.term-popover p { margin: 0 0 6px; }
.term-popover p:last-child { margin-bottom: 0; }
.term-popover-title { font-weight: bold; color: var(--text); }
.term-example-btn {
  min-height: 24px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.term-example-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.term-example { margin-top: 6px !important; padding-left: 8px; border-left: 3px solid var(--green); }

/* ── D3 Visualization Classes ── */
/* Only transition highlight properties: a blanket transition also animates the
   SVG transform/d attributes on every simulation tick, which stalls rendering. */
.node { cursor: pointer; transition: opacity var(--transition), filter var(--transition); }
@media (hover: hover) and (pointer: fine) { .node:hover { filter: brightness(1.12); } }
.node.highlighted { filter: drop-shadow(0 0 6px rgba(20, 69, 58, 0.75)); }
.node.dimmed { opacity: 0.08; }

.link { stroke-opacity: 0.35; fill: none; transition: stroke-opacity var(--transition), filter var(--transition); }
/* No glow filter on links: a big gateway highlights ~700 links and filtering
   them all took ~0.7 s per redraw (e.g. on each history slider step). */
.link.highlighted { stroke-opacity: 0.95; stroke-width: 3px !important; }
.link.dimmed { stroke-opacity: 0.01; }

.node-label {
  font-size: 10px;
  fill: var(--text);
  text-anchor: middle;
  pointer-events: none;
  font-weight: bold;
  /* a paper-coloured halo keeps labels readable over connections */
  paint-order: stroke;
  stroke: var(--bg-primary);
  stroke-width: 3px;
  stroke-linejoin: round;
}

/* ── Modal ── */
/* Native <dialog>: the card fills it, so a click on the dialog itself is a backdrop click. */
.modal-dialog {
  border: none;
  padding: 0;
  margin: auto;
  background: transparent;
  color: var(--text);
  width: calc(100% - 40px);
  max-width: 640px;
  max-height: 85vh;
  overflow: visible;
}

.modal-dialog[open] { animation: fadeIn 0.3s; }
.modal-dialog::backdrop { background: rgba(43, 49, 41, 0.45); }

.modal-card a { color: var(--accent); text-decoration: underline; }

.modal-diagram { list-style: none; padding: 0; }
.modal-layer-local { background: color-mix(in srgb, var(--cat-local-company) 14%, var(--bg-card)); border: 1px solid var(--cat-local-company); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 49, 41, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  animation: fadeIn 0.3s;
  padding: 20px;
}

.modal-overlay.modal-exit { animation: fadeOut 0.3s forwards; }

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px;
  position: relative;
}

/* A 44px square in the corner; the disclaimer starts below it. */
.modal-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

@media (hover: hover) and (pointer: fine) { .modal-close:hover { color: var(--text); } }

.modal-title { font-size: 20px; color: var(--accent); margin-bottom: 16px; }

.modal-body { font-size: 14px; line-height: 1.6; }

.modal-section { margin: 16px 0; }
.modal-section h3 { font-size: 15px; color: var(--accent); margin-bottom: 8px; }
.modal-section p { color: var(--text-muted); }

.modal-section-why {
  background: var(--bg-card);
  padding: 14px;
  border-radius: var(--radius);
  border-left: 3px solid var(--red);
}

.modal-section-why p { color: var(--text); }

.modal-disclaimer {
  margin-top: 24px;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  text-align: center;
}

.modal-section-algorithm {
  background: var(--bg-card);
  padding: 14px;
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}

.modal-section-contact {
  text-align: center;
  padding: 10px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-diagram { margin: 20px 0; text-align: center; }

.modal-layer {
  padding: 12px;
  margin: 4px 0;
  border-radius: var(--radius);
  text-align: center;
}

.modal-layer-inside { background: color-mix(in srgb, var(--cat-iig) 14%, var(--bg-card)); border: 1px solid var(--cat-iig); }
.modal-layer-outside { background: color-mix(in srgb, var(--cat-outside) 14%, var(--bg-card)); border: 1px solid var(--cat-outside); }
.modal-layer-world { background: var(--accent-soft); border: 1px solid var(--accent); }

.modal-layer-label { font-weight: bold; font-size: 13px; }
.modal-layer-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.modal-arrow { color: var(--text-muted); font-size: 16px; margin: 2px 0; }

.modal-terms { margin: 8px 0; }
.modal-terms dt { font-weight: bold; color: var(--accent); margin-top: 8px; font-size: 13px; }
.modal-terms dd { color: var(--text-muted); margin-left: 0; font-size: 13px; }

.modal-tips { list-style: none; padding: 0; }
.modal-tips li { padding: 3px 0; color: var(--text-muted); font-size: 13px; }
.modal-tips li::before { content: "→ "; color: var(--accent); }

.modal-footer {
  margin-top: 20px;
  text-align: center;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Progress Overlay ── */
#progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 49, 41, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 15000;
  padding: 20px;
}

.progress-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  max-width: 520px;
  width: 100%;
}

.progress-title { font-size: 18px; color: var(--accent); margin-bottom: 16px; }

.progress-steps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }

.progress-step { font-size: 12px; padding: 4px 8px; border-radius: 3px; }
.progress-step.step-done { color: var(--green); }
.progress-step.step-active { color: var(--accent); font-weight: bold; background: var(--bg-card); }
.progress-step.step-pending { color: var(--text-dim); }

.progress-message { font-size: 13px; margin-bottom: 8px; color: var(--text); }
.progress-message.progress-warning { color: var(--warn); }

.progress-bar-container {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-details { font-size: 11px; color: var(--text-muted); }

.progress-actions { margin-top: 16px; text-align: right; }

/* ── Toast Notifications ── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 25000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: 380px;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow);
}

.toast-exit { animation: slideOut 0.3s forwards; }

.toast-info { background: var(--accent); color: var(--reverse); }
.toast-warning { background: var(--warn); color: var(--reverse); }
.toast-error { background: var(--red); color: var(--reverse); }
.toast-success { background: var(--accent); color: var(--reverse); }

.toast-message { flex: 1; }
.toast-close { background: none; border: none; color: var(--reverse); font-size: 18px; cursor: pointer; opacity: 0.7; padding: 0 4px; }
@media (hover: hover) and (pointer: fine) { .toast-close:hover { opacity: 1; } }

/* ── Data Table ── */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.table-toolbar-right { display: flex; gap: 6px; align-items: center; }

.table-search {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 240px;
}

.table-search:focus { border-color: var(--accent); }

.table-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 11px;
}

.table-wrapper { overflow: auto; overscroll-behavior: contain; flex: 1; padding: 0 16px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  /* Fixed layout: column widths come from <colgroup>, not the content, so
     a date step never resizes columns. Narrow screens scroll sideways inside
     .table-wrapper instead of squeezing. */
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.data-table-nodes { min-width: 1060px; }
.data-table-edges { min-width: 820px; }

/* One line per cell at a fixed height; long names end in an ellipsis and
   show in full on hover (title) and in the row's details. */
.data-table > thead > tr > th,
.data-table > tbody > tr:not(.detail-row) > td {
  height: 34px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th {
  background: var(--bg-card);
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 2px solid var(--border);
}

.data-table th.sortable { cursor: pointer; user-select: none; }
@media (hover: hover) and (pointer: fine) { .data-table th.sortable:hover { color: var(--accent); } }

/* Header sort buttons and row expand buttons look like the text they replace. */
.th-sort, .row-toggle {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  text-align: inherit;
  cursor: pointer;
}

.row-toggle { color: var(--accent); text-decoration: underline; }

.data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

@media (hover: hover) and (pointer: fine) { .data-table tr:hover td { background: var(--bg-card); color: var(--text); } }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.type-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: bold;
}


.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.table-pagination { display: flex; align-items: center; gap: 8px; }

/* ── Table Container Layout ── */
#table-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Treemap Container ── */
#treemap-container {
  display: flex;
  width: 100%;
  height: 100%;
  gap: 8px;
  padding: 8px;
}

/* ── Scrollbar ── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg-card);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-card); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── In-viz floating controls (e.g. Traffic Flow orientation/fit) ── */
.viz-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  display: flex;
  gap: 4px;
  padding: 3px;
  background: color-mix(in srgb, var(--bg-secondary) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.viz-ctrl-btn {
  font-size: 11px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
}

@media (hover: hover) and (pointer: fine) { .viz-ctrl-btn:hover { color: var(--accent); } }
.viz-ctrl-btn.active { color: var(--bg-primary); background: var(--accent); }

/* Pan/zoom buttons (chart-a11y.js): at least 24px targets (WCAG 2.5.8). */
.viz-nav .viz-ctrl-btn {
  min-width: 26px;
  min-height: 26px;
  font-size: 14px;
  line-height: 1;
  padding: 4px 6px;
}

.viz-controls > .viz-nav {
  display: flex;
  gap: 4px;
  padding-left: 4px;
  border-left: 1px solid var(--border);
}

/* ── Ranking bar lists (bar-list.js): static, fit the width, scroll down ── */
.bar-view {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px 24px;
}

.bar-view:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.bar-view-head { max-width: 960px; margin-bottom: 12px; }
.bar-view-title { font-size: 16px; font-weight: 600; color: var(--text); }
.bar-view-summary { margin-top: 4px; font-size: 13px; color: var(--text-muted); }
.bar-view-empty { font-size: 14px; color: var(--text-muted); }

.bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 8px;
  list-style: none;
  font-size: 12px;
  color: var(--text-muted);
}

.bar-legend li { display: flex; align-items: center; gap: 6px; }
.bar-legend-swatch { width: 12px; height: 12px; border-radius: 2px; }

.bar-list {
  max-width: 960px;
  list-style: none;
  font-variant-numeric: tabular-nums;
}

/* Fixed row height and columns, so a date step changes bar lengths and
   numbers but never moves anything else. */
.bar-row {
  display: grid;
  grid-template-columns: 2.5ch minmax(0, 15rem) minmax(0, 1fr) 10ch;
  align-items: center;
  gap: 10px;
  height: 30px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 12px;
}

@media (hover: hover) and (pointer: fine) { .bar-row:hover { background: var(--bg-card); } }
.bar-row.highlighted { background: var(--bg-raised); box-shadow: inset 3px 0 0 var(--accent); }

.bar-rank { color: var(--text-dim); text-align: right; }

.bar-label { display: flex; align-items: center; gap: 6px; min-width: 0; }

/* Up to two lines inside the fixed row height, so names that share a start
   ("Summit Communications Ltd" / "... Limited") can be told apart. */
.bar-name {
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  line-height: 1.2;
  overflow-wrap: anywhere;
  color: var(--text);
}

.bar-tag {
  flex: 0 0 auto;
  padding: 1px 5px;
  border: 1px solid var(--tag-color);
  border-left-width: 3px;
  border-radius: 3px;
  font-size: 10px;
  color: var(--text);
  white-space: nowrap;
}

.bar-track { display: flex; height: 14px; min-width: 0; }
.bar-seg { min-width: 0; height: 100%; }
.bar-seg:first-child { border-radius: 2px 0 0 2px; }
.bar-seg:last-child { border-radius: 0 2px 2px 0; }

.bar-value { color: var(--text-muted); text-align: right; white-space: nowrap; }

@media (max-width: 600px) {
  .bar-view { padding: 10px 10px 16px; }
  .bar-view-title { font-size: 14px; }
  .bar-view-summary { font-size: 12px; }
  /* Name and tag stack so the name keeps its width. */
  .bar-row {
    grid-template-columns: 2.5ch minmax(0, 42%) minmax(0, 1fr) 8ch;
    gap: 6px;
    height: 48px;
    padding: 0 2px;
    font-size: 12px;
  }
  .bar-label { flex-direction: column; align-items: flex-start; gap: 2px; }
  .bar-name { max-width: 100%; }
  .bar-tag { padding: 0 4px; font-size: 9px; }
}

/* ── Layered View ── */
/* A page of boxes that scrolls vertically. Zoom changes --box-min and
   --box-h; the grid reflows, so nothing ever pans sideways. */
.layered-view {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 0 20px 24px;
  --box-min: 150px;
  --box-h: 48px;
}
.layered-view:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.layered-zoom {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 -20px;
  padding: 8px 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-soft);
}
.layered-zoom-level {
  width: 9.5rem;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.layered-zoom-btn {
  width: 32px;
  height: 32px;
  font-size: 18px;
  line-height: 1;
  color: var(--accent);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.layered-zoom-btn:disabled { color: var(--text-dim); opacity: 0.6; cursor: default; }
@media (hover: hover) and (pointer: fine) { .layered-zoom-btn:not(:disabled):hover { border-color: var(--accent); } }
.layered-zoom-btn:not(:disabled):active { background: var(--bg-raised); }

.layered-head { max-width: 960px; margin: 14px 0 6px; }
.layered-title { font-size: 16px; font-weight: 600; color: var(--text); }
.layered-summary { margin-top: 4px; font-size: 13px; color: var(--text-muted); }
.layered-empty { margin-top: 16px; font-size: 14px; color: var(--text-muted); }

/* "Is one of these yours?": one fixed height in every state, so the grid
   below never moves when the lookup finishes. */
.layered-mine {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 960px;
  min-height: 64px;
  margin-top: 12px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}
.layered-mine-text { min-width: 0; }
.layered-mine-note { font-size: 12px; color: var(--text-muted); }
.layered-mine-btn { flex: 0 0 auto; }
.layered-mine-btn[aria-disabled="true"] { color: var(--text-dim); cursor: progress; }

.layered-tag {
  display: inline-block;
  flex: 0 0 auto;
  margin-right: 6px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  line-height: 16px;
  vertical-align: 1px;
  color: var(--reverse);
  background: var(--accent);
  border-radius: 3px;
}
.layered-box.mine { outline: 2px solid var(--accent); outline-offset: 1px; }

.layered-layer { margin-top: 18px; }
.layered-layer-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.layered-swatch { width: 12px; height: 12px; border-radius: 2px; flex: 0 0 auto; }
.layered-count {
  font-weight: 400;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.layered-layer-note { margin: 2px 0 8px; font-size: 12px; color: var(--text-muted); max-width: 70ch; }

.layered-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--box-min), 100%), 1fr));
  gap: 6px;
  list-style: none;
}
.layered-grid > li { min-width: 0; }   /* long names ellipsize instead of widening a column */

/* Category as a stripe beside ink text (the hues are too light for text). */
.layered-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  height: var(--box-h);
  padding: 0 8px 0 10px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-left: 4px solid var(--cat);
  border-radius: 4px;
  cursor: pointer;
}
/* Up to two lines: every zoom level's box height has room for them. */
.layered-box-name {
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  line-height: 1.2;
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 600;
}
.layered-box-share {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.zoom-names .layered-box-share { display: none; }
.zoom-large .layered-box-name { font-size: 14px; }
.zoom-large .layered-box-share { font-size: 12px; }
@media (hover: hover) and (pointer: fine) { .layered-box:hover { border-color: var(--accent); border-left-color: var(--cat); } }
.layered-box:active { background: var(--bg-raised); }
.layered-box.selected { outline: 2px solid var(--accent); outline-offset: 1px; }

.layered-more {
  margin-top: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .layered-more:hover { border-color: var(--accent); } }
.layered-more:active { background: var(--bg-raised); }

/* Phones: in the Layered View and the rankings the page scrolls instead of
   the panel, since iOS only scrolls the page to the top on a tap on the
   status bar (ui/page-scroll.js). The tabs stick to the top, the history bar
   and footer to the bottom; scroll padding keeps a focused or highlighted
   row clear of them. */
@media (max-width: 600px), (max-height: 500px) {
  :root:has(> body.page-scroll) {
    scroll-padding: var(--tabs-h, 0px) 0 calc(var(--timeline-h, 0px) + var(--footer-h, 0px));
  }
  /* The Layered View's size bar (6px padding, 32px buttons, 1px border) sticks under the tabs. */
  :root:has(> body.page-scroll .layered-zoom) { scroll-padding-top: calc(var(--tabs-h, 0px) + 45px); }
  body.page-scroll { height: auto; overflow: visible; }
  body.page-scroll #app { height: auto; min-height: 100dvh; overflow-x: clip; }
  body.page-scroll #main { overflow: visible; }
  body.page-scroll #tab-nav { position: sticky; top: 0; z-index: 50; }
  body.page-scroll #viz-panel { flex: 1 0 auto; overflow: visible; }
  body.page-scroll .layered-view,
  body.page-scroll .layered-path,
  body.page-scroll .bar-view { height: auto; overflow: visible; }
  body.page-scroll .layered-zoom { top: var(--tabs-h, 0px); }
  body.page-scroll #timeline-bar { position: sticky; bottom: var(--footer-h, 0px); z-index: 50; }
  body.page-scroll #app-footer { position: sticky; bottom: 0; z-index: 50; }
}

@media (max-width: 600px), (max-height: 500px) {
  .layered-view { padding: 0 12px 16px; }
  .layered-zoom { justify-content: center; margin: 0 -12px; padding: 6px 12px; }
  .layered-title { font-size: 14px; }
  .layered-summary { font-size: 12px; }
}

@media (max-width: 600px) {
  .layered-mine { flex-direction: column; align-items: stretch; gap: 6px; min-height: 104px; }
  .layered-mine-btn { align-self: flex-start; }
}

/* Landscape phones: height is scarce, so the boxes come first; the layer
   notes and summary stay one "?" away. */
@media (max-height: 500px) {
  .layered-summary, .layered-layer-note { display: none; }
  .layered-head { margin-top: 8px; }
  .layered-mine { min-height: 52px; margin-top: 8px; padding: 4px 12px; }
  .layered-layer { margin-top: 10px; }
  .layered-layer-title { margin-bottom: 6px; }
  .layered-path-summary { min-height: 0; }
}

/* ── Layered View: one network's path ── */
.layered-path {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 0 20px 24px;
}
.layered-path:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.layered-path > * { max-width: 760px; }

.layered-path-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 -20px;
  padding: 8px 20px;
  max-width: none;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-soft);
}
.layered-back {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .layered-back:hover { border-color: var(--accent); } }
.layered-back:active { background: var(--bg-raised); }
.layered-path-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}
.layered-path-title:focus { outline: none; }
.layered-path-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Three lines reserved, so a longer sentence on another date moves nothing. */
.layered-path-summary {
  min-height: calc(3 * 1.45em);
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.45;
}
.layered-path-note { margin-top: 4px; font-size: 12px; color: var(--text-muted); }

.layered-picked {
  margin: 12px 0 0;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--text);
  border-left: 6px solid var(--cat);
  border-radius: var(--radius);
}
.layered-picked-name { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layered-picked-sub { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.layered-path-graph { position: relative; padding-left: 10px; }
.layered-path-lines { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.layered-path-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 36px;
  margin-top: 14px;
}
.layered-path-col-title {
  margin: 14px 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.layered-path-cols .layered-path-col-title { margin-top: 0; }

.layered-cards { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.layered-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
}
.layered-card-item { min-width: 0; height: 52px; }
.layered-card-item.fading { opacity: 0.35; transition: opacity 0.3s; }

.layered-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  padding: 0 8px 0 10px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 5px solid var(--cat);
  border-radius: 5px;
  overflow: hidden;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) { .layered-card:hover { border-color: var(--accent); border-left-color: var(--cat); } }
.layered-card:active { background: var(--bg-raised); }
.layered-card[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.layered-card-name { display: flex; align-items: center; width: 100%; min-width: 0; font-size: 12px; font-weight: 600; }
.layered-card-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layered-card-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.layered-card-track { flex: 1 1 auto; min-width: 20px; height: 7px; background: var(--bg-raised); border-radius: 2px; overflow: hidden; }
.layered-card-fill { display: block; height: 100%; background: var(--cat); transition: width 0.5s ease; }
.layered-card-value { flex: 0 0 3.5ch; text-align: right; }
.layered-card-delta { flex: 0 0 auto; color: var(--text-muted); white-space: nowrap; }
.layered-card-delta:empty { display: none; }
.layered-card-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }

/* GONE: a text tag, a dashed outline and a crossed-out name, never colour alone. */
.layered-card-item.gone .layered-card { border-style: dashed; border-left-style: dashed; background: transparent; }
.layered-card-item.gone .layered-card-label { text-decoration: line-through; }
.layered-tag.tag-new { background: var(--accent); }
.layered-tag.tag-gone { color: var(--text); background: var(--warn-soft); border: 1px solid var(--warn); }

/* The one deliberate movement: a GONE card collapses and the cards below move up. */
.layered-card-item.leaving { height: 0; margin-bottom: -8px; opacity: 0; overflow: hidden; animation: layered-collapse 0.3s ease; }
@keyframes layered-collapse {
  from { height: 52px; margin-bottom: 0; opacity: 0.35; }
  to { height: 0; margin-bottom: -8px; opacity: 0; }
}

.layered-changes { margin-top: 20px; }
.layered-changes-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.layered-change {
  width: 100%;
  padding: 6px 8px;
  text-align: left;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}
.layered-change time { display: block; font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
@media (hover: hover) and (pointer: fine) { .layered-change:hover { background: var(--bg-card); border-color: var(--border-soft); } }
.layered-change:active { background: var(--bg-raised); }
.layered-changes-list li.current .layered-change { background: var(--bg-raised); box-shadow: inset 3px 0 0 var(--accent); }
.layered-changes-empty, .layered-cutoff { margin-top: 8px; font-size: 12px; color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) {
  .layered-card-fill, .layered-card-item.fading { transition: none; }
}

@media (max-width: 600px), (max-height: 500px) {
  .layered-path { padding: 0 12px 16px; }
  .layered-path-head { margin: 0 -12px; padding: 6px 12px; }
  .layered-path-cols { column-gap: 24px; }
  .layered-path-summary { font-size: 13px; }
  .layered-card-delta { font-size: 10px; }
}

/* ── History time-slider ── */
/* Until the history list loads the bar keeps its space but stays invisible, so
   the chart panel already has its final height when the first view draws
   (collapsing it moved the Network Graph legend below the panel's edge). */
#timeline-bar.timeline-pending { visibility: hidden; }
#timeline-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

/* The slider and the change marks drawn over its track. */
.timeline-track {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

#timeline-bar #timeline-slider {
  flex: 1;
  min-width: 0;
  width: 100%;
  margin: 0;
}

/* Thumb is 16px on desktop, 22px on phones: marks line up with its centre. */
#timeline-marks {
  --thumb: 16px;
  position: absolute;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  top: 0;
  bottom: 0;
  pointer-events: none;
}

.timeline-mark {
  position: absolute;
  left: calc(var(--at) * 100%);
  top: 50%;
  width: 3px;
  height: 7px;
  margin: -3.5px 0 0 -1.5px;   /* centred on the track, whatever the slider's height */
  background: var(--red);
  border-radius: 1px;
}

.timeline-btn {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

@media (hover: hover) and (pointer: fine) { .timeline-btn:hover { border-color: var(--accent); color: var(--accent-hover); } }

/* Fixed width, so swapping Play and Pause never moves the slider. */
.timeline-play {
  width: 5.5rem;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}
.timeline-play-icon { font-size: 11px; width: 1em; text-align: center; }

#timeline-readout {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--text-dim);
}

/* Fixed-width date and space kept for the spinner and LATEST badge, so
   stepping through dates never resizes the slider. */
#timeline-label {
  display: inline-block;
  width: 11.5rem;   /* fits "30 Dec, 23:59 Dhaka time" so a date step doesn't move the badge */
  text-align: right;
  color: var(--text);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#timeline-readout .hidden { display: inline-block !important; visibility: hidden; }

.timeline-badge {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0.5px;
  color: var(--bg-primary);
  background: var(--accent);
  padding: 2px 6px;
  border-radius: 3px;
}

.timeline-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: timelineSpin 0.7s linear infinite;
}

@keyframes timelineSpin { to { transform: rotate(360deg); } }

/* ── Footer ── */
#app-footer {
  padding: 6px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#app-footer a { color: var(--accent); text-decoration: underline; }
@media (hover: hover) and (pointer: fine) { #app-footer a:hover { color: var(--accent-hover); } }

/* ── Category colours ── */
/* Category colour as a mark beside ink text: the hues are too light for text. */
.sidebar-section-title.iig::before, .sidebar-section-title.detected-iig::before,
.sidebar-section-title.offshore-enterprise::before, .sidebar-section-title.offshore-gateway::before,
.sidebar-section-title.local-company::before, .sidebar-section-title.outside::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
  border: 1px solid var(--text);
  background: var(--cat);
}

.cat-local-company, .sidebar-section-title.local-company, .asn-item.local-company, .type-local-company { --cat: var(--cat-local-company); }
.cat-iig, .sidebar-section-title.iig, .asn-item.iig, .type-iig { --cat: var(--cat-iig); }
.cat-detected-iig, .sidebar-section-title.detected-iig, .asn-item.detected-iig, .type-detected-iig { --cat: var(--cat-detected-iig); }
.cat-offshore-enterprise, .sidebar-section-title.offshore-enterprise, .asn-item.offshore-enterprise, .type-offshore-enterprise { --cat: var(--cat-offshore-enterprise); }
.cat-offshore-gateway, .sidebar-section-title.offshore-gateway, .asn-item.offshore-gateway, .type-offshore-gateway { --cat: var(--cat-offshore-gateway); }
.cat-outside, .sidebar-section-title.outside, .asn-item.outside, .type-outside { --cat: var(--cat-outside); }
.legend-dot[class*="cat-"] { background: var(--cat); }

.asn-item { border-left-color: var(--cat, transparent); }

/* Category chips: a tint of the hue, ink text, a solid edge in the hue. */
.type-iig, .type-detected-iig, .type-offshore-enterprise, .type-offshore-gateway,
.type-local-company, .type-outside {
  background: color-mix(in srgb, var(--cat) 22%, var(--bg-card));
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--cat);
}

/* ── Stats Row ── */
.stat-row {
  /* Two per row: three left the labels (and their "?") too little room. */
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 6px;
}

.stat-mini {
  padding: 6px 8px;
  min-width: 0;
}

.stat-mini .stat-value { font-size: 15px; }
.stat-mini .stat-label { font-size: 9px; }

/* ── How do I reach the world? ── */
.my-asn-section {
  text-align: center;
}

.btn-my-asn {
  width: 100%;
  background: var(--accent);
  color: var(--reverse);
  font-size: 13px;
  padding: 10px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: bold;
  transition: var(--transition-ui);
}

@media (hover: hover) and (pointer: fine) {
  .btn-my-asn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
  }
}

.btn-my-asn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.my-path-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 8px;
  text-align: left;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.my-path-card p + p, .my-path-card .btn { margin-top: 6px; }
.my-path-card strong { color: var(--text); }
.my-path-hint { font-size: 11px; color: var(--text-dim); }

.my-asn-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 6px;
}

.my-asn-note {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 8px;
  line-height: 1.4;
  font-style: italic;
}

/* ── Legend ── */
.legend-section { padding-bottom: 4px; }

.legend-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
  list-style: none;
}

.legend-item {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
}

/* ── Clickable Table Rows ── */
.clickable-row { cursor: pointer; transition: background 0.15s; }
@media (hover: hover) and (pointer: fine) { .clickable-row:hover { background: var(--bg-raised); } }
.clickable-row.row-expanded { background: var(--accent-soft); border-bottom: none; }

/* ── Geo Mismatch Highlight ── */
.geo-mismatch { color: var(--warn); font-weight: 600; }

/* ── License Badge (table) ── */
.license-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 4px;
  vertical-align: middle;
}

/* ── Detail Panel (expanded table row) ── */
.detail-row td { padding: 0 !important; background: var(--bg-card); border-top: none; }

.detail-panel {
  padding: 16px 20px;
  border: 1px solid var(--border-soft);
  border-top: 2px solid var(--accent);
  border-radius: 0 0 var(--radius) var(--radius);
}

.detail-row-enter .detail-panel { animation: detailSlideDown 0.2s ease-out; }

@keyframes detailSlideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.detail-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.detail-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: var(--transition-ui);
}
@media (hover: hover) and (pointer: fine) { .detail-close:hover { background: var(--bg-raised); color: var(--text); } }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.detail-section {
  margin-bottom: 12px;
}

.detail-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
}

.detail-section-subtitle {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-style: italic;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin: 4px 0;
  font-size: 12px;
}

.detail-label {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.detail-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

.detail-value a {
  color: var(--accent);
  text-decoration: underline;
}
@media (hover: hover) and (pointer: fine) { .detail-value a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; } }

.detail-value.detail-warning { color: var(--warn); }
.detail-value.detail-licensed { color: var(--accent); }

.detail-explanation {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 8px 10px;
  margin-top: 8px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
}

.detail-connections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.detail-connections-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 4px;
}

.detail-connections-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.detail-connections-table td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-muted);
}

@media (hover: hover) and (pointer: fine) { .detail-connections-table tr:hover td { background: var(--bg-raised); } }

.detail-empty {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 8px 0;
}

.detail-more {
  font-size: 10px;
  color: var(--text-dim);
  padding: 4px 0;
  font-style: italic;
}

/* ── Type Filter Checkboxes ── */
.type-filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}
.type-filter-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
}
.type-filter-group input[type="checkbox"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  margin: 3px;
}

.type-filter-fieldset {
  border: 0;
  min-width: 0;
}

.type-filter-fieldset legend { padding: 0; }

/* ── Mobile Menu Button ── */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
  transition: var(--transition-ui);
}

@media (hover: hover) and (pointer: fine) {
  .mobile-menu-btn:hover {
    background: var(--bg-card);
    border-color: var(--accent);
  }
}

.mobile-menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  transition: transform var(--transition), opacity var(--transition);
  border-radius: 2px;
}

.mobile-menu-btn.active span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.mobile-menu-btn.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-btn.active span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(43, 49, 41, 0.45);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ── Responsive ── */
/* Phones and tablets, and landscape phones (short but wide viewports). */
@media (max-width: 900px), (max-height: 500px) {
  #app { flex-direction: column; }
  
  .mobile-menu-btn {
    display: flex;
  }
  
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    min-width: auto;
    border-right: 2px solid var(--border);
    border-bottom: none;
    transform: translateX(-100%);
    z-index: 100;
  }
  
  #sidebar.active {
    transform: translateX(0);
  }
  
  #main {
    width: 100%;
  }
  
  #top-bar {
    padding-left: 64px;
  }
  
  /* Title truncation on mobile */
  #top-bar > .top-bar-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
  }
  
  .tab-btn {
    font-size: 11px;
    padding: 8px 10px;
  }
  
  /* Footer stacks vertically on mobile */
  #app-footer {
    flex-direction: column;
    gap: 4px;
    text-align: center;
  }

  /* Timeline: full-width, readout drops under the slider */
  #timeline-bar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  /* Zero basis: range inputs are width:100% globally, which would push the
     buttons onto their own rows. */
  .timeline-track {
    flex: 1 1 0;
    order: 1;
  }

  #timeline-play { order: -1; }
  #timeline-prev { order: 0; }
  #timeline-next { order: 2; }

  #timeline-readout {
    order: 3;
    flex: 1 0 100%;
    min-width: 0;
    justify-content: center;
  }
  
  /* Table search responsive */
  .table-search {
    width: 100%;
    max-width: 240px;
  }
  
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  
  .table-toolbar-right {
    justify-content: flex-end;
  }
}

@media (max-width: 600px), (max-height: 500px) {
  .mobile-menu-btn {
    top: 8px;
    left: 8px;
    width: 44px;
    height: 44px;
  }
  
  #sidebar {
    width: 90%;
  }
  
  #sidebar-header .site-name {
    font-size: 16px;
  }

  /* Keep the title clear of the menu (close) button. */
  #sidebar-header {
    padding-left: 56px;
  }

  /* "Static data from: 1 Dec 2026, 09:20 Dhaka time" takes two lines here and
     "Snapshot: ..." one: keep room for two so a date step moves nothing. */
  #data-source-label { min-height: 2.6em; line-height: 1.3; }
  
  /* Phones: hide the title bar visually (it holds the page's h1, so it stays
     for screen readers) and put the tabs between the menu and search buttons
     to give the chart the height. Search opens as a bar along the top. */
  #top-bar {
    height: 0;
    padding: 0;
    border: 0;
  }
  #top-bar > .top-bar-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .site-search { display: none; }
  #top-bar.search-open .site-search {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1100;
    width: auto;
    gap: 8px;
    padding: max(6px, env(safe-area-inset-top)) 8px 6px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
  }
  .site-search-icon { left: 18px; }
  .site-search-input { min-height: 40px; padding-right: 10px; }
  .site-search-key { display: none; }
  .site-search-list { left: 8px; right: 8px; width: auto; }
  .site-search-close,
  .site-search-open {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 22px;
    cursor: pointer;
  }
  .site-search-open {
    position: fixed;
    top: 2px;
    right: 8px;
    z-index: 1001;
  }
  .site-search-open svg { width: 18px; height: 18px; }
  .mobile-menu-btn {
    top: 2px;
  }

  /* The menu and search buttons cover each end of the strip; the mask hides
     tabs scrolled under them (they used to show through at the edges). */
  #tab-nav {
    padding-left: 52px;
    padding-right: 52px;
    min-height: 48px;
    --strip-edge: 52px;
  }

  .tab-btn {
    font-size: 13px;
    padding: 13px 12px;
    min-height: 48px;
  }

  #timeline-bar {
    gap: 4px 8px;
    padding: 6px 12px 4px;
  }

  #timeline-readout {
    font-size: 13px;
  }

  /* The close square replaces the input's own clear cross (two × side by side). */
  .site-search-input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
  
  .btn {
    font-size: 13px;
    padding: 6px 12px;
    min-height: 44px; /* touch target */
  }
  
  .btn-small {
    font-size: 12px;
    padding: 4px 10px;
    min-height: 44px;
  }

  /* Bigger touch targets for the timeline slider/buttons */
  #timeline-bar #timeline-slider { height: 6px; }

  #timeline-bar #timeline-slider::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
  }

  #timeline-bar #timeline-slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  .timeline-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  #timeline-marks { --thumb: 22px; }

  /* Icon only on phones; the name stays for screen readers. */
  .timeline-play { width: 44px; }
  .timeline-play .timeline-play-text {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }

  /* Bigger touch targets for in-viz controls */
  .viz-ctrl-btn {
    font-size: 13px;
    padding: 7px 10px;
    min-height: 44px;
    min-width: 44px;
  }
  
  .control-group label {
    font-size: 12px;
  }
  
  .stat-value {
    font-size: 16px;
  }
  
  /* One line: the long source note truncates instead of wrapping. */
  #app-footer {
    font-size: 12px;
    padding: 4px 8px;
    flex-direction: row;
    gap: 8px;
    text-align: left;
  }

  #app-footer > span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #app-footer > span:last-child {
    flex: 0 0 auto;
  }

  /* A 24px tap target without a taller footer: content scrolls under the
     footer in the Layered View, so other targets can come close. */
  #btn-show-intro { padding: 7px 0; margin: -7px 0; }

  /* Better touch targets for range sliders */
  input[type="range"]::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
  }
  
  input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
  }
  
  /* Improve ASN list items for touch */
  .asn-item {
    padding: 10px 12px;
    margin: 6px 0;
    min-height: 44px; /* Minimum touch target size */
  }
  
  .type-filter-group label {
    padding: 8px 0;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  
  .type-filter-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 8px;
  }
  
  /* Tooltip becomes a bottom sheet on mobile, above the date bar (main.js
     measures it) so the date can still be changed while the sheet is open. */
  .tooltip {
    position: fixed !important;
    bottom: var(--sheet-bottom, 0px) !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: 40vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
    font-size: 11px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(43, 49, 41, 0.25);
    transform: translateY(100%);
    transition: transform 0.2s ease;
    z-index: 10000;
    pointer-events: auto;
  }
  
  .tooltip[style*="display: block"],
  .tooltip[style*="display:block"] {
    transform: translateY(0);
  }
  
  .tooltip-title {
    font-size: 13px;
    padding-right: 36px; /* room for the close button */
  }

  .tooltip .tooltip-close {
    display: flex;
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: var(--bg-card);
  }
  
  /* Add a grab bar at top */
  .tooltip::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--text-dim);
    border-radius: 2px;
    margin: 0 auto 8px;
  }
  
  /* Hide verbose insight text on mobile to save space */
  .tooltip-insight {
    display: none;
  }
  
  /* Modal improvements */
  .modal-card {
    padding: 20px;
    max-height: 90vh;
  }
  
  .modal-title {
    font-size: 18px;
  }
  
  .modal-content {
    font-size: 13px;
  }
  
  /* Toast responsive */
  #toast-container {
    right: 8px;
    left: 8px;
    max-width: none;
  }
  
  .toast {
    font-size: 12px;
  }
  
  /* Legend section improvements */
  .legend-item {
    font-size: 10px;
  }
  
  .legend-dot {
    min-width: 8px;
    min-height: 8px;
  }
}

/* Landscape phones: height is what's scarce, so the timeline stays on one
   row with its date beside the slider. */
@media (max-height: 500px) {
  #timeline-bar { flex-wrap: nowrap; }
  #timeline-readout { flex: 0 0 auto; }

  /* A full-width sheet would cover most of the chart, so the details sit in
     the bottom-right corner instead. */
  .tooltip {
    left: auto !important;
    width: min(320px, 45vw) !important;
    max-height: calc(100vh - var(--sheet-bottom, 0px) - 56px);
    border-radius: 12px 0 0 0;
    padding-bottom: 12px;
  }
  .tooltip::before { display: none; }
}

@media (max-width: 400px) {
  #sidebar {
    width: 95%;
  }
  
  #sidebar-header {
    padding: 12px 12px 12px 56px;
  }
  
  #sidebar-content {
    padding: 10px 12px;
  }
  
  .btn-group {
    flex-direction: column;
  }
  
  .btn-group .btn {
    width: 100%;
  }
  
  /* Make stats more compact */
  .stat-mini .stat-label {
    font-size: 9px;
  }
  
  .stat-mini .stat-value {
    font-size: 13px;
  }
  
  /* Progress overlay fits small screens */
  .progress-card {
    padding: 20px;
    max-width: 95vw;
  }
  
  .progress-title {
    font-size: 16px;
  }
  
  /* Modal further compacted */
  .modal-overlay {
    padding: 10px;
  }
  
  .modal-card {
    padding: 16px;
    border-radius: 8px;
  }
  
  /* Treemap container stacks on tiny screen */
  #treemap-container {
    flex-direction: column;
  }
  
  /* Table pagination stacks */
  .table-footer {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }
}

/* iOS Safari zooms into a text field whose text is under 16px (#31). */
@media (pointer: coarse) {
  .site-search-input,
  .table-search,
  .table-select { font-size: 16px; }
}

/* ── Touch targets (#64) ── */
@media (pointer: coarse) {
  /* Glossary "?": a 44px hit area around the same small circle. */
  .term-help::after { inset: -14px; }
  /* Range inputs: 44px tall to tap and drag, the same thin track drawn centred. */
  input[type="range"] {
    height: 44px;
    background: linear-gradient(var(--border), var(--border)) center / 100% 4px no-repeat;
  }
  #timeline-bar #timeline-slider { height: 44px; background-size: 100% 6px; }
}

/* ── Forced colours (Windows high contrast) ── */
@media (forced-colors: active) {
  /* The menu icon's bars are backgrounds, which forced colours remove. */
  .mobile-menu-btn span { background: ButtonText; forced-color-adjust: none; }
}

/* ── Phones on their side: the footer moves into the menu (#68) ── */
@media (max-height: 500px) and (orientation: landscape) {
  #app-footer { display: none; }
  /* Both pinned bars at the 44px of their buttons, no padding. */
  #tab-nav, .tab-btn { min-height: 44px; }
  .tab-btn { padding-top: 11px; padding-bottom: 11px; }
  #timeline-bar { padding-top: 0; padding-bottom: 0; }
  .sidebar-footer-copy { display: block; margin-top: 6px; font-size: 13px; color: var(--text-muted); }
  .sidebar-footer-copy a { color: var(--accent); }
}

/* ── Notches, rounded corners and the home bar (viewport-fit=cover) ──
   env() is 0 where a screen has none of them, so this only moves things in the
   installed app or on a phone with a notch, mostly on its side. */
#app {
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px);
}
#app-footer { padding-bottom: max(6px, env(safe-area-inset-bottom, 0px)); }

@media (max-width: 900px), (max-height: 500px) {
  .mobile-menu-btn {
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
  }
  #sidebar { padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
}

@media (max-width: 600px), (max-height: 500px) {
  .mobile-menu-btn {
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: calc(8px + env(safe-area-inset-left, 0px));
  }
  body.page-scroll #tab-nav { top: env(safe-area-inset-top, 0px); }
  body.page-scroll .layered-zoom { top: calc(var(--tabs-h, 0px) + env(safe-area-inset-top, 0px)); }
  #top-bar.search-open .site-search {
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }
}

/* The footer is hidden on a phone on its side: the history bar is the lowest. */
@media (max-height: 500px) and (orientation: landscape) {
  #timeline-bar { padding-bottom: env(safe-area-inset-bottom, 0px); }
}
