:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --panel: rgba(30, 41, 59, 0.7);
    --border: rgba(255, 255, 255, 0.1);
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #10b981;
    --red: #ef4444;
    --amber: #f59e0b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- nav ---- */
.nav {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 14px 28px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 18px; color: var(--text); }
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 18px; flex: 1; }
.nav-links a, .nav-auth a { color: var(--text); font-weight: 500; }
.nav-auth { display: flex; gap: 14px; align-items: center; }
.inline { display: inline; margin: 0; }

/* ---- layout ---- */
.main { flex: 1; max-width: 1200px; width: 100%; margin: 0 auto; padding: 32px 24px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px; border-top: 1px solid var(--border); }
.footer a { color: var(--muted); }

h1 { font-size: 32px; margin: 0 0 8px; }
h2 { border-bottom: 2px solid var(--accent); padding-bottom: 8px; }
.subtitle { color: var(--muted); margin-bottom: 28px; }

/* ---- cards / panels ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.card h3 { margin: 0; }
.card .meta { color: var(--muted); font-size: 13px; }
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

/* ---- buttons / forms ---- */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-soft);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}
.btn:hover { text-decoration: none; filter: brightness(1.15); }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-success { background: var(--green); border-color: var(--green); }
.btn-ghost { background: transparent; border: none; color: var(--muted); }

form label { display: block; margin: 12px 0 6px; font-weight: 600; font-size: 14px; }
input, select, textarea {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #475569;
    background: var(--bg-soft);
    color: var(--text);
}
.form-narrow { max-width: 420px; margin: 0 auto; }
.form-actions { margin-top: 18px; }

/* ---- misc ---- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; }
.flash-ok { background: rgba(16, 185, 129, 0.15); border: 1px solid var(--green); }
.flash-err { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--red); }
.flash-info { background: rgba(59, 130, 246, 0.15); border: 1px solid var(--accent); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-free { background: #334155; }
.badge-paid { background: var(--accent); }
.badge-pro { background: var(--green); }
.badge-err { background: var(--red); }
.badge-warn { background: var(--amber); color: #0f172a; }

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; }

/* ---- dataset preview: full-bleed, horizontally scrollable, readable columns ---- */
/* Break the preview panel out of the centred 1200px column to the full browser width. */
.ds-preview-fullbleed { width: 100vw; margin-left: calc(50% - 50vw); margin-right: calc(50% - 50vw); border-radius: 0; }
.ds-rows-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
/* Natural column widths (not squeezed): each column gets a readable min-width, and the
   table overflows into the horizontal scroll above when the columns don't all fit. */
.ds-rows-table { width: 100%; margin: 0; font-size: 13px; table-layout: auto; }
.ds-rows-table th, .ds-rows-table td {
    min-width: 150px; max-width: 480px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

iframe.map-frame {
    width: 100%;
    height: 75vh;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.hero { text-align: center; padding: 56px 0 40px; }
.hero h1 { font-size: 44px; }
.hero p { color: var(--muted); font-size: 18px; max-width: 640px; margin: 12px auto 28px; }

.progress-track { background: #334155; border-radius: 8px; height: 14px; overflow: hidden; }
.progress-fill { background: var(--green); height: 100%; transition: width 0.3s; }

.dot-pulse { color: var(--green); animation: dot-pulse 1.1s ease-in-out infinite; }
@keyframes dot-pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.prose { max-width: 760px; line-height: 1.7; }
.prose img { max-width: 100%; }
.prose code { background: var(--bg-soft); padding: 2px 5px; border-radius: 4px; }
.prose pre { background: var(--bg-soft); padding: 14px; border-radius: 8px; overflow-x: auto; }
.muted { color: var(--muted); }

/* ---- map workbench: map on the left, collapsible feature panels on the right ---- */
/* The map viewer breaks out of the 1200px page cap and uses (almost) the full viewport
   width, so the map fills wide screens instead of sitting in a fixed rectangle. */
.main:has(.map-layout) { max-width: min(2200px, 96vw); }
/* Map fills the remaining width; the feature column scales with the viewport (clamped so it
   stays readable but never hogs the screen) so both grow together on wider windows. */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) clamp(380px, 26vw, 560px); gap: 16px; align-items: start; }
/* the map stays pinned on the left; the feature column flows at its natural height, so the
   page (not an inner scrollbar) scrolls when the panels are taller than the map */
.map-stage { position: sticky; top: 12px; }
.map-stage iframe.map-frame { height: 84vh; margin: 0; }
.map-side { display: flex; flex-direction: column; gap: 10px; }
.side-sec { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); overflow: hidden; }
.side-sec > summary { cursor: pointer; list-style: none; padding: 12px 14px; font-weight: 700; font-size: 14px;
    display: flex; align-items: center; gap: 9px; user-select: none; }
.side-sec > summary::-webkit-details-marker { display: none; }
.side-sec > summary:hover { background: rgba(148,163,184,.08); }
.side-sec > summary .chev { margin-left: auto; color: var(--muted); transition: transform .2s; font-size: 11px; }
.side-sec[open] > summary .chev { transform: rotate(90deg); }
.side-sec > summary .ico { font-size: 15px; }
.side-body { padding: 2px 14px 14px; font-size: 13px; }
.side-body h4 { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.side-body .btn { font-size: 13px; }
.wb-row { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.wb-search input { flex: 1; min-width: 120px; }
.wb-results { margin-top: 9px; max-height: 230px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.wb-result { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px;
    cursor: pointer; font-size: 12.5px; border: 1px solid transparent; }
.wb-result .wb-title { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wb-result:hover { background: var(--bg-soft); border-color: var(--border); }
.wb-tips { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.wb-tips li { margin: 5px 0; }
.wb-tips b { color: var(--text); }
.wb-pill { font-size: 12px; color: var(--muted); }
.wb-pill b { color: var(--accent); }
.wb-field { display: flex; flex-direction: column; gap: 2px; font-size: 10px; text-transform: uppercase;
    letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.wb-field select, .wb-field input { font-size: 12px; padding: 6px 6px; }
.wb-status { margin-top: 8px; font-size: 11px; font-weight: 600; color: var(--accent);
    padding: 4px 8px; background: rgba(59,130,246,.1); border-radius: 6px; }
.wb-result .wb-score { flex: 0 0 auto; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.wb-export { position: relative; display: inline-block; }
.wb-export-menu { display: none; position: absolute; right: 0; bottom: calc(100% + 4px); z-index: 20;
    background: var(--panel); border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
    box-shadow: 0 8px 22px #0006; min-width: 210px; }
.wb-export-menu.open { display: block; }
.wb-export-menu button { display: block; width: 100%; text-align: left; background: none; border: none;
    color: var(--text); padding: 9px 12px; font-size: 12.5px; cursor: pointer; }
.wb-export-menu button:hover { background: var(--bg-soft); }
/* ---- time-range block (inside the workspace panel) ---- */
.wb-timeline { margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--border); }
.wb-tl-head { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
/* ---- time-range dual slider ---- */
.wb-dual { position: relative; height: 28px; margin-top: 4px; }
.wb-dual .wb-dual-track { position: absolute; left: 0; right: 0; top: 12px; height: 4px;
    background: var(--border); border-radius: 3px; }
.wb-dual .wb-dual-fill { position: absolute; top: 12px; height: 4px; background: var(--accent); border-radius: 3px; }
.wb-dual input[type=range] { position: absolute; left: 0; top: 0; width: 100%; height: 28px; margin: 0;
    -webkit-appearance: none; appearance: none; background: transparent; pointer-events: none; }
.wb-dual input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none;
    pointer-events: auto; width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
    border: 2px solid var(--panel); cursor: pointer; box-shadow: 0 1px 3px #0008; }
.wb-dual input[type=range]::-moz-range-thumb { pointer-events: auto; width: 15px; height: 15px;
    border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); cursor: pointer; }
@media (max-width: 980px) {
    .map-layout { grid-template-columns: 1fr; }
    .map-stage { position: static; }
    .map-stage iframe.map-frame { height: 70vh; }
    .map-side { max-height: none; overflow: visible; }
}

/* ---- grounded RAG chat ("Ask this map") ---- */
.chat-panel { display: flex; flex-direction: column; gap: 12px; }
.chat-transcript {
    display: flex; flex-direction: column; gap: 10px;
    max-height: 360px; overflow-y: auto; padding: 4px 2px;
}
.chat-empty { padding: 8px 2px; font-size: 14px; }
.chat-msg { display: flex; }
.chat-msg.chat-user { justify-content: flex-end; }
.chat-msg.chat-asst { justify-content: flex-start; }
.chat-bubble {
    max-width: 80%; padding: 10px 14px; border-radius: 14px;
    font-size: 14px; line-height: 1.55;
}
.chat-user .chat-bubble {
    background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}
.chat-asst .chat-bubble {
    background: var(--bg-soft); border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-answer { white-space: pre-wrap; }
.chat-note { color: var(--amber); }
.chat-sources { margin-top: 8px; font-size: 13px; }
.chat-sources summary { cursor: pointer; color: var(--muted); }
.chat-sources ol { margin: 6px 0 0; padding-left: 22px; }
.chat-sources li { margin: 3px 0; }
.src-title { color: var(--text); }
.src-score { margin-left: 6px; font-size: 12px; }
.chat-remaining { font-size: 12px; text-align: right; }
.chat-form { display: flex; gap: 8px; align-items: center; }
.chat-form input[type="text"] { flex: 1; }
.chat-thinking { font-size: 13px; }
.chat-form select.chat-model { flex: 0 0 auto; width: auto; max-width: 230px; padding: 8px 10px; font-size: 13px; }
.chat-modelnote { font-size: 12px; margin: 4px 2px 0; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* ---- gallery card thumbnail (theme-aware) ---- */
.card-thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px;
    margin-bottom: 10px; background: var(--bg-soft); }
.card-thumb-ph { width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; margin-bottom: 10px;
    background: var(--bg-soft); border: 1px solid var(--border); display: flex;
    align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }

/* ---- light theme (toggle via data-theme="light" on <html>) ---- */
:root[data-theme="light"] {
    --bg: #ffffff;
    --bg-soft: #f8fafc;
    --panel: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
}
:root[data-theme="light"] .panel { box-shadow: 0 1px 3px rgba(15,23,42,.06); }
:root[data-theme="light"] .nav { border-bottom: 1px solid var(--border); }
.theme-toggle { background: none; border: 1px solid var(--border); color: var(--text);
    border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 15px; line-height: 1; }
.theme-toggle:hover { background: rgba(148,163,184,.15); }
