:root {
  --bg: #12151c;
  --panel: #1a1f29;
  --panel-2: #222836;
  --line: #2e3646;
  --text: #dfe4ec;
  --muted: #8b95a7;
  --accent: #4ab884;
  --accent-2: #56ccf2;
  --warn: #e8a860;
  --danger: #e07a6a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

body { display: flex; height: 100vh; overflow: hidden; }

/* Generic hide — robust across every element (the specific #x.hidden rules
   below are kept but this guarantees a .hidden element is never shown). */
.hidden { display: none !important; }

#sidebar {
  width: var(--sidebar-w, 360px); flex: 0 0 var(--sidebar-w, 360px); height: 100%;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
body.sidebar-collapsed #sidebar,
body.sidebar-collapsed #sidebar-resize { display: none; }

/* Drag handles */
#sidebar-resize { flex: 0 0 5px; cursor: col-resize; background: var(--line); }
#sidebar-resize:hover, #split-resize:hover { background: var(--accent); }
#sidebar-toggle {
  position: fixed; top: 12px; z-index: 30;
  left: calc(var(--sidebar-w, 360px) - 1px);
  width: 20px; height: 42px; padding: 0;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-left: none;
  border-radius: 0 6px 6px 0; cursor: pointer; font-size: 14px; line-height: 42px;
}
body.sidebar-collapsed #sidebar-toggle { left: 0; }

/* Stage: map on top, cross-section pane below. */
#stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#map-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#split-resize { flex: 0 0 6px; cursor: row-resize; background: var(--line); }
#section-pane {
  flex: 0 0 var(--section-h, 280px); position: relative;
  display: flex; flex-direction: column; overflow: hidden;
  background: #0d1117; border-top: 1px solid var(--line); min-height: 0;
}

#sidebar header { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
#sidebar h1 { margin: 0; font-size: 18px; letter-spacing: .14em; font-weight: 600; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 11.5px; }
#userbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
#user-email { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#signout { flex: none; background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; font-size: 11px; cursor: pointer; }
#signout:hover { color: var(--fg, #fff); border-color: var(--muted); }

#tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 9px 4px; background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 11.5px; font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel { display: none; padding: 14px 16px 40px; overflow-y: auto; flex: 1; }
.panel.active { display: block; }

.group { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h3 {
  margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); font-weight: 600;
}

.field { margin-bottom: 10px; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.val { color: var(--accent-2); float: right; font-variant-numeric: tabular-nums; }

input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 6px 8px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 4px; color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=file] { width: 100%; font-size: 11px; color: var(--muted); }

button {
  padding: 7px 12px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; cursor: pointer; font: inherit;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.12); }
button.wide { width: 100%; margin-bottom: 8px; }
button.mini { padding: 4px 8px; font-size: 11px; }
.btn-row { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.btn-row button { flex: 1; }
.btn-row button.on { background: var(--accent); color: #06231a; border-color: var(--accent); }

/* Collapsible sidebar sections — click the header to fold, so the panel scrolls less. */
.group > h3 { cursor: pointer; user-select: none; }
.group > h3::before { content: '▾'; display: inline-block; width: 12px;
  font-size: 9px; color: var(--muted); }
.group.collapsed > h3::before { content: '▸'; }
.group.collapsed > *:not(h3) { display: none; }

.hint { color: var(--muted); font-size: 11.5px; margin: 0 0 10px; }
label.check { display: flex; align-items: center; gap: 7px; font-size: 12px; margin: 0 0 10px; cursor: pointer; }
label.check .hint { margin: 0; }
label.check input { flex: none; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.seg button { flex: 1; background: transparent; color: var(--muted); border: none; border-right: 1px solid var(--line); padding: 5px; font-size: 11px; cursor: pointer; }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent, #4ab884); color: #06231a; }

/* Document repository browser (Docs tab) */
.doc-cat { border: 1px solid var(--line); border-radius: 5px; margin-bottom: 5px; }
.doc-cat > summary { padding: 6px 9px; cursor: pointer; font-size: 12px;
  display: flex; justify-content: space-between; align-items: center; list-style: none; }
.doc-cat > summary::before { content: '▸'; margin-right: 6px; color: var(--muted); }
.doc-cat[open] > summary::before { content: '▾'; }
.doc-item { display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 4px 10px 4px 22px; font-size: 11.5px; color: var(--text); text-decoration: none;
  border-top: 1px solid var(--line); }
.doc-item:hover { background: rgba(255,255,255,.04); color: var(--accent); }
.doc-item .meta { flex: none; color: var(--muted); font-size: 10px; }
.doc-repo > summary { cursor: pointer; font-size: 11px; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted); margin: 12px 0 6px; list-style: none; }
.doc-repo > summary::before { content: '▸ '; }
.doc-repo[open] > summary::before { content: '▾ '; }
.doc-cat-table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; font-size: 11px; }
.doc-cat-table td, .doc-cat-table th { text-align: left; padding: 2px 6px; border-bottom: 1px solid var(--line); }
.doc-cat-table td:nth-child(2), .doc-cat-table td:nth-child(3),
.doc-cat-table th:nth-child(2), .doc-cat-table th:nth-child(3) { text-align: right; width: 44px; }
.doc-cat-table td:first-child { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-cat-table tr.tot td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: none; }

/* Docs chat */
#chat-log { max-height: 46vh; overflow-y: auto; margin-bottom: 8px;
  display: flex; flex-direction: column; gap: 8px; }
#chat-log:empty { display: none; }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg .bubble { max-width: 92%; padding: 7px 10px; border-radius: 8px;
  font-size: 12px; white-space: pre-wrap; line-height: 1.45; }
.chat-msg.user .bubble { background: var(--accent); color: #06231a; }
.chat-msg.bot .bubble { background: rgba(255,255,255,.05); border: 1px solid var(--line); }
.chat-msg.passages .bubble { background: transparent; border: 1px dashed var(--line); max-width: 100%; }
.chat-msg .cites { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.chat-msg .tools { margin-top: 6px; font-size: 10px; color: var(--muted); }
.chat-msg .tools .tool { color: var(--accent); font-family: var(--mono, monospace); margin-right: 6px; }

/* Swipe compare overlay (over the map area) */
#compare { position: absolute; inset: 0; z-index: 4; }
#cmp-a, #cmp-b { position: absolute; inset: 0; }
#cmp-b { clip-path: inset(0 0 0 50%); }        /* right side; JS updates the % */
#cmp-divider { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px;
  background: #fff; transform: translateX(-1px); cursor: col-resize; z-index: 5; }
.cmp-grip { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 30px; height: 30px; border-radius: 50%; background: #fff; color: #0d1117;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  box-shadow: 0 1px 6px rgba(0,0,0,.5); user-select: none; }
#cmp-labels { position: absolute; top: 10px; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; padding: 0 14px; pointer-events: none; }
#cmp-labels span { background: rgba(13,17,23,.82); color: #fff; font-size: 12px;
  padding: 3px 9px; border-radius: 4px; }

/* Cross-section pane (inside #stage, below the map) */
.sec-head { display: flex; align-items: center; gap: 12px; padding: 6px 10px;
  border-bottom: 1px solid var(--line); font-size: 12px; }
#sec-title { font-weight: 600; white-space: nowrap; }
#sec-legend { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: 11px; }
#sec-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  vertical-align: middle; margin: 0 3px 0 8px; }
#sec-close { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 14px; }
.sec-body { position: relative; flex: 1; overflow: auto; }
#sec-frame { position: relative; width: 100%; height: 100%; }
.sec-ctl { font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.sec-ctl select { font-size: 11px; }
#sec-labels { position: absolute; inset: 0; pointer-events: none; }
#sec-labels span { position: absolute; font-size: 9px; color: var(--muted);
  background: rgba(13,17,23,.6); padding: 0 2px; white-space: nowrap; }
#sec-labels span.elev { left: 1px; transform: translateY(-50%); }
#sec-labels span.dist { bottom: 1px; transform: translateX(-50%); }
#sec-labels span.boring { transform: translate(-50%, -110%); color: #ffd166;
  font-weight: 600; background: rgba(13,17,23,.75); }
#sec-canvas { position: absolute; inset: 0; width: 100%; height: 100%;
  image-rendering: pixelated; }
#sec-overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.radio-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.row {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px;
  border-radius: 4px; cursor: pointer;
}
.row:hover { background: var(--panel-2); }
.row input { margin: 0; accent-color: var(--accent); }
.row span.name { flex: 1; font-size: 12px; }
.row span.meta { color: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.swatch { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 11px; }

#legend { display: flex; flex-wrap: wrap; gap: 5px 10px; margin-top: 8px; }
#legend div { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--muted); }

table.kv { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 11.5px; }
table.kv th, table.kv td { padding: 3px 5px; text-align: right; border-bottom: 1px solid var(--line); }
table.kv th { color: var(--muted); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
table.kv td:first-child, table.kv th:first-child { text-align: left; }
table.kv td { font-variant-numeric: tabular-nums; }
table.kv tr.void td { color: var(--muted); font-style: italic; }
table.kv tr.top td { color: var(--accent); font-weight: 600; }

.card {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 10px; margin: 10px 0;
}
.card h4 { margin: 0 0 6px; font-size: 12px; }
.big { font-size: 19px; font-weight: 600; color: var(--accent); font-variant-numeric: tabular-nums; }
.unit { font-size: 11px; color: var(--muted); font-weight: 400; }

.warn { color: var(--warn); font-size: 11px; margin: 4px 0; }
.err { color: var(--danger); font-size: 11.5px; margin: 6px 0; }
.ok { color: var(--accent); font-size: 11.5px; }

.cite { color: var(--accent-2); font-size: 11px; }
.passage {
  background: var(--panel-2); border-left: 2px solid var(--accent-2);
  padding: 7px 9px; margin: 7px 0; font-size: 11px; max-height: 140px; overflow-y: auto;
}
.answer { white-space: pre-wrap; font-size: 12.5px; line-height: 1.55; }

#map { position: absolute; inset: 0; }

#view3d { position: absolute; inset: 0; background: #0a0c11; }
#view3d.hidden { display: none; }
#v3-canvas { width: 100%; height: 100%; }
#v3-canvas canvas { display: block; }
#v3-legend {
  position: absolute; left: 14px; bottom: 14px;
  background: rgba(26, 31, 41, .9); border: 1px solid var(--line);
  border-radius: 5px; padding: 8px 10px; font-size: 10.5px;
  display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 340px;
}
#v3-legend div { display: flex; align-items: center; gap: 5px; color: var(--muted); }
#v3-hud {
  position: absolute; right: 14px; top: 14px;
  background: rgba(26, 31, 41, .9); border: 1px solid var(--line);
  border-radius: 5px; padding: 8px 10px; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#readout {
  position: absolute; right: 14px; top: 14px; width: 300px; max-height: 70vh;
  overflow-y: auto; background: rgba(26, 31, 41, .96);
  border: 1px solid var(--line); border-radius: 6px; padding: 12px;
  backdrop-filter: blur(6px);
}
#readout.hidden { display: none; }
#readout.wide { width: 520px; max-width: calc(100vw - 40px); }
#readout .logwrap { max-height: 56vh; overflow: auto; }
#readout .logwrap table.kv { min-width: 480px; }
#readout h4 { margin: 0 0 6px; font-size: 12.5px; }
#readout .close { position: absolute; right: 8px; top: 6px; padding: 2px 7px; font-size: 12px; }

.maplibregl-popup-content {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; font-size: 12px;
}
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.spin { color: var(--muted); font-size: 11.5px; }

/* ---- sign-in, site selection, environment badge ---- */
#site-select { min-width: 0; max-width: 60%; flex: 1; background: var(--panel, #1a1f29); color: inherit; border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; font-size: 11px; }
#auth-gate { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; background: rgba(10, 12, 16, 0.92); }
#auth-gate[hidden], #auth-banner[hidden] { display: none; }
.auth-card { width: min(440px, 92vw); background: #1a1f29; border: 1px solid var(--line); border-radius: 8px; padding: 22px 24px; color: #e6e9ef; }
.auth-card h2 { margin: 0 0 10px; font-size: 17px; }
.auth-card p { font-size: 13px; line-height: 1.5; color: #b8bfcc; }
.auth-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.auth-list button, .auth-card #auth-signout { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; background: #232a37; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; font-size: 13px; cursor: pointer; }
.auth-list button:hover, .auth-card #auth-signout:hover { border-color: #6c7a93; }
.auth-list button span { color: var(--muted); font-size: 11px; }
#auth-banner { position: fixed; left: 50%; top: 12px; transform: translateX(-50%); z-index: 9999; max-width: min(560px, 92vw); background: #4a2a2a; color: #ffd9d9; border: 1px solid #8a4747; border-radius: 6px; padding: 8px 14px; font-size: 12px; }
#env-badge { position: fixed; right: 8px; top: 8px; z-index: 900; pointer-events: none; background: rgba(242, 153, 74, 0.85); color: #1a1205; border-radius: 3px; padding: 1px 7px; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; }

.doc-row { display: flex; align-items: center; gap: 6px; }
.doc-row .doc-item { flex: 1; min-width: 0; }
.acl { font-size: 9px; color: var(--muted); white-space: nowrap; }
.acl label { margin-left: 4px; }
