:root {
    --sidebar-bg: #0c1a34;
    --sidebar-fg: #c6d2e8;
    --sidebar-active: #2563eb;
    --bg: #f2f5f9;
    --card: #ffffff;
    --border: #e4e9f0;
    --text: #16233b;
    --muted: #64748b;
    --accent: #2563eb;
    --accent-dark: #1e40af;
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
    --shadow: 0 1px 3px rgba(16, 30, 54, .07);
    --radius: 10px;
}

[data-theme="dark"] {
    --sidebar-bg: #0a1526;
    --sidebar-fg: #9fb0cc;
    --bg: #0f1a2e;
    --card: #16233b;
    --border: #24344f;
    --text: #e6ecf5;
    --muted: #8ea0bd;
    --shadow: 0 1px 3px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 232px;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    transition: margin-left .2s;
}
.shell.collapsed .sidebar { margin-left: -232px; }
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 16px 14px;
    color: #fff; font-weight: 600; font-size: 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
    background: var(--accent); color: #fff; border-radius: 8px;
    width: 34px; height: 34px; display: grid; place-items: center; flex-shrink: 0;
}
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: 8px;
    color: var(--sidebar-fg); text-decoration: none; font-size: 13px;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.sidebar-widget {
    margin: 10px 12px 16px; padding: 14px;
    background: rgba(255,255,255,.05); border-radius: var(--radius);
    font-size: 12px;
}

/* ---------- Topbar ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 14px;
    background: var(--card); border-bottom: 1px solid var(--border);
    padding: 10px 22px; position: sticky; top: 0; z-index: 50;
}
.page-title { display: flex; align-items: baseline; gap: 8px; flex: 1; }
.page-title h1 { font-size: 19px; margin: 0; }
.crumb { color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.icon-btn {
    background: none; border: 1px solid var(--border); border-radius: 8px;
    width: 32px; height: 32px; display: grid; place-items: center;
    color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.user-menu { display: flex; align-items: center; gap: 9px; }
.avatar {
    background: var(--accent); color: #fff; width: 32px; height: 32px;
    display: grid; place-items: center; border-radius: 50%;
    font-size: 12px; font-weight: 600;
}
.user-meta { line-height: 1.15; }
.user-meta strong { font-size: 12.5px; display: block; }
.user-meta small { color: var(--muted); font-size: 11px; }
.logout-form { margin: 0; }

/* ---------- Content ---------- */
.content { padding: 20px 22px 40px; }

.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px;
}
.card h3 {
    margin: 0 0 12px; font-size: 13.5px; font-weight: 600;
}
.card .sub { color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 14px; }
.kpi-row { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.two-col { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .two-col, .three-col { grid-template-columns: 1fr; } }

/* KPI cards */
.kpi { display: flex; gap: 12px; align-items: flex-start; }
.kpi-icon {
    width: 38px; height: 38px; border-radius: 9px;
    display: grid; place-items: center; flex-shrink: 0;
}
.kpi .label { color: var(--muted); font-size: 11.5px; }
.kpi .value { font-size: 21px; font-weight: 700; margin: 2px 0; }
.kpi .delta { font-size: 11px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

.tint-blue { background: #dbeafe; color: #1d4ed8; }
.tint-green { background: #dcfce7; color: #15803d; }
.tint-purple { background: #ede9fe; color: #6d28d9; }
.tint-amber { background: #fef3c7; color: #b45309; }
.tint-cyan { background: #cffafe; color: #0e7490; }
.tint-red { background: #fee2e2; color: #b91c1c; }
[data-theme="dark"] .tint-blue { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .tint-green { background: #14532d; color: #86efac; }
[data-theme="dark"] .tint-purple { background: #3b2b63; color: #c4b5fd; }
[data-theme="dark"] .tint-amber { background: #4a3411; color: #fcd34d; }
[data-theme="dark"] .tint-cyan { background: #164e63; color: #67e8f9; }
[data-theme="dark"] .tint-red { background: #5c1a1a; color: #fca5a5; }

/* Filter bar — fixed field widths so long survey names cannot shove Source onto a new row */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px;
    overflow: visible;
}
.filter-bar .field {
    display: flex; flex-direction: column; gap: 4px;
    flex: 0 0 128px; width: 128px; min-width: 0; max-width: 128px;
    overflow: visible;
}
.filter-bar .field-survey { flex-basis: 168px; width: 168px; max-width: 168px; }
.filter-bar .field-compact { flex-basis: 84px; width: 84px; max-width: 84px; }
.filter-bar label { font-size: 11px; color: var(--muted); }
.filter-bar .spacer { flex: 1 1 auto; min-width: 8px; }
.filter-bar .filter-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
.filter-bar select,
.filter-bar .ms-wrap { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }

/* Searchable / multi-select filter control */
.ms-wrap { position: relative; }
.ms-native {
    position: absolute !important; left: 0; top: 0;
    opacity: 0 !important; pointer-events: none !important;
    width: 1px !important; height: 1px !important; margin: 0 !important; padding: 0 !important;
    border: 0 !important; overflow: hidden !important; clip: rect(0, 0, 0, 0);
}
.ms-trigger {
    display: block; width: 100%; text-align: left;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    border-radius: 8px; padding: 7px 10px; font-size: 13px; font-family: inherit; cursor: pointer;
    min-height: 34px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ms-trigger.is-empty { color: var(--muted); }
.ms-wrap.is-open .ms-trigger { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12); }
/* Important: class display:flex must not override [hidden] — panels stay closed until .is-open */
.ms-panel {
    display: none;
    position: absolute; z-index: 80; top: calc(100% + 4px); left: 0; right: auto; min-width: 220px; width: max-content; max-width: min(320px, 80vw);
    background: var(--card); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14); padding: 8px; max-height: 280px;
    flex-direction: column; gap: 6px;
}
.ms-panel[hidden] { display: none !important; }
.ms-wrap.is-open .ms-panel,
.ms-wrap.is-open .ms-panel:not([hidden]) {
    display: flex !important;
}
.ms-search {
    width: 100%; border: 1px solid var(--border); border-radius: 6px;
    padding: 6px 8px; font-size: 12px; font-family: inherit; background: var(--bg); color: var(--text);
    box-sizing: border-box;
}
.ms-options { overflow: auto; max-height: 210px; display: flex; flex-direction: column; gap: 2px; }
.ms-option {
    display: flex; align-items: flex-start; gap: 8px; padding: 5px 6px; border-radius: 6px;
    font-size: 12px; cursor: pointer; color: var(--text);
}
.ms-option:hover, .ms-option.is-selected { background: var(--bg); }
.ms-empty { padding: 8px; font-size: 12px; }

/* Active filter chips */
.filter-chips {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 8px; margin: -8px 0 14px;
}
.filter-chips-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filter-chip {
    display: inline-flex; align-items: center; gap: 5px;
    border: 1px solid var(--border); background: var(--card); color: var(--text);
    border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; font-family: inherit;
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip-label { color: var(--muted); font-weight: 500; }
.filter-chip-x { color: var(--muted); font-weight: 700; }

/* Geographic drill-down breadcrumb */
.geo-crumb {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 10px; margin: -6px 0 14px; padding: 10px 14px;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
}
.geo-crumb-list {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    list-style: none; margin: 0; padding: 0;
}
.geo-crumb-sep { color: var(--muted); font-size: 12px; user-select: none; }
.geo-crumb-link {
    border: none; background: none; padding: 0; cursor: pointer;
    color: var(--accent); font: inherit; font-size: 13px; font-weight: 600;
}
.geo-crumb-link:hover { text-decoration: underline; }
.geo-crumb-current { font-size: 13px; font-weight: 700; color: var(--text); }
.geo-crumb-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.geo-focus-list { font-size: 12px; }

/* §25 Command palette */
.cmd-palette { position: fixed; inset: 0; z-index: 1200; display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.cmd-palette[hidden] { display: none !important; }
.cmd-palette-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.cmd-palette-panel {
    position: relative; width: min(560px, 100%); background: var(--surface, #fff); color: var(--text);
    border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.22);
    overflow: hidden; animation: gsa-scale-in .16s ease-out;
}
.cmd-palette-input-wrap { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cmd-palette-input-wrap input {
    flex: 1; border: 0; outline: none; background: transparent; font-size: 15px; color: inherit;
}
.cmd-kbd {
    font-size: 11px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 4px;
    color: var(--muted); font-family: inherit;
}
.cmd-palette-list { list-style: none; margin: 0; padding: 6px; max-height: min(360px, 50vh); overflow: auto; }
.cmd-palette-list li { margin: 0; }
.cmd-palette-item {
    display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
    padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; color: inherit;
    cursor: pointer; font: inherit;
}
.cmd-palette-item:hover, .cmd-palette-item.active { background: rgba(13, 148, 136, .12); }
.cmd-palette-item .cmd-label { flex: 1; font-size: 13px; font-weight: 600; }
.cmd-palette-item .cmd-hint { font-size: 11px; color: var(--muted); }
.cmd-palette-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 13px; }
.cmd-palette-foot {
    display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 11px;
}
/* Guided insights — collapsed by default, expand on hover/focus */
.insights-hover {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    transition: border-color .18s ease, box-shadow .18s ease;
}
.insights-hover:hover,
.insights-hover:focus-within {
    border-color: rgba(13, 148, 136, .45);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
    z-index: 5;
}
.insights-hover-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 14px;
    cursor: default;
    min-height: 42px;
}
.insights-hover-bar strong { font-size: 13px; }
.insights-hover-bar #insightsHoverHint { font-size: 12px; }
.insights-hover-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.insights-hover-panel {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: max-height .28s ease, opacity .2s ease, padding .2s ease;
    padding: 0 14px;
}
.insights-hover:hover .insights-hover-panel,
.insights-hover:focus-within .insights-hover-panel {
    max-height: 420px;
    opacity: 1;
    pointer-events: auto;
    padding: 0 14px 14px;
    overflow: auto;
}
.insights-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.insights-strip .insight-card { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg, #f8fafc); }
.insights-strip .insight-card h4 { margin: 0 0 4px; font-size: 13px; }
.insights-strip .insight-card p { margin: 0; font-size: 12px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
    .insights-hover-panel { transition: none; }
}
table.data tr.rank-row { cursor: pointer; }
table.data tr.rank-row:hover td { background: rgba(37, 99, 235, .08); }

select, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="file"], textarea {
    background: var(--card); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 7px 10px; font-size: 13px; font-family: inherit;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--card); color: var(--text);
    padding: 8px 14px; font-size: 13px; cursor: pointer;
    text-decoration: none; font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); }
.btn-ghost { border: none; background: none; }
.btn-sm { padding: 5px 9px; font-size: 12px; }

/* Charts */
.chart { width: 100%; min-height: 300px; }
.chart-sm { min-height: 220px; }
.chart-lg { min-height: 430px; }
#map, .maplibre-map { width: 100%; height: 430px; border-radius: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%; border-collapse: collapse; font-size: 12.5px;
}
table.data th {
    text-align: left; color: var(--muted); font-weight: 600;
    padding: 8px 10px; border-bottom: 1px solid var(--border);
    font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
    white-space: nowrap;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: rgba(37, 99, 235, .04); }

.badge {
    display: inline-block; padding: 3px 9px; border-radius: 20px;
    font-size: 11px; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-muted { background: var(--border); color: var(--muted); }
[data-theme="dark"] .badge-success { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-warning { background: #4a3411; color: #fcd34d; }
[data-theme="dark"] .badge-danger { background: #5c1a1a; color: #fca5a5; }
[data-theme="dark"] .badge-info { background: #1e3a5f; color: #93c5fd; }

/* Progress bars (indicators) */
.indicator { margin-bottom: 12px; }
.indicator .row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 4px; }
.indicator .bar { background: var(--border); height: 7px; border-radius: 4px; overflow: hidden; }
.indicator .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.indicator .fill.good { background: var(--green); }
.indicator .fill.warn { background: var(--amber); }
.indicator .fill.bad { background: var(--red); }

/* Alerts */
.alert { border-radius: 8px; padding: 11px 14px; margin-bottom: 14px; font-size: 13px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
[data-theme="dark"] .alert-info { background: #1e3a5f; color: #bfdbfe; border-color: #1e40af; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
[data-theme="dark"] .alert-success { background: #14532d; color: #bbf7d0; border-color: #166534; }
[data-theme="dark"] .alert-error { background: #5c1a1a; color: #fecaca; border-color: #991b1b; }

/* Section header inside cards */
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h3 { margin: 0; }

/* Login */
.login-page {
    min-height: 100vh; display: grid; place-items: center;
    background: linear-gradient(135deg, #0c1a34 0%, #1e3a5f 100%);
}
.login-card {
    background: #fff; color: #16233b; border-radius: 14px; padding: 34px;
    width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-card .brand-mark { margin: 0 auto 12px; width: 46px; height: 46px; }
.login-card h1 { font-size: 19px; text-align: center; margin: 0 0 4px; }
.login-card p { text-align: center; color: #64748b; font-size: 12.5px; margin: 0 0 20px; }
.login-card label { display: block; font-size: 12px; color: #475569; margin: 12px 0 5px; }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 18px; }
.login-hint { margin-top: 16px; font-size: 11.5px; color: #64748b; text-align: center; }

/* Pagination */
.pager { display: flex; gap: 6px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.pager a, .pager span {
    padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 12px; text-decoration: none; color: var(--text);
}
.pager .current { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Forms in cards */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-grid .field { display: flex; flex-direction: column; gap: 5px; }
.form-grid label { font-size: 12px; color: var(--muted); }

/* Wizard steps */
.steps { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.step {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px; border-radius: 20px; font-size: 12.5px;
    background: var(--card); border: 1px solid var(--border); color: var(--muted);
}
.step.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.step.done { border-color: var(--green); color: var(--green); }
.step .n {
    width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center; font-size: 11px;
    background: var(--border);
}
.step.active .n { background: var(--accent); color: #fff; }
.step.done .n { background: var(--green); color: #fff; }

.muted { color: var(--muted); }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.text-right { text-align: right; }
.meta-list { margin: 0; display: grid; gap: 10px; }
.meta-list > div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; font-size: 13px; }
.meta-list dt { color: var(--muted); margin: 0; }
.meta-list dd { margin: 0; }
.answer-pre { margin: 0; white-space: pre-wrap; font-size: 12px; max-width: 480px; }
.pagination { display: flex; gap: 4px; list-style: none; padding: 0; margin: 12px 0 0; flex-wrap: wrap; }
.pagination .page-link {
    display: inline-block; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    text-decoration: none; color: var(--text); font-size: 12px; background: #fff;
}
.pagination .page-item.active .page-link { background: #0d9488; border-color: #0d9488; color: #fff; }
.pagination .page-item.disabled .page-link { opacity: .45; pointer-events: none; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Map legend + tooltip */
.map-legend {
    position: absolute; bottom: 14px; left: 14px; z-index: 5;
    background: var(--card); border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font-size: 11.5px; box-shadow: var(--shadow);
}
.map-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; }
.map-wrap { position: relative; }
.map-tooltip {
    position: absolute; pointer-events: none; z-index: 6;
    background: var(--card); color: var(--text); border: 1px solid var(--border);
    padding: 8px 11px; border-radius: 8px; font-size: 12px;
    box-shadow: var(--shadow); display: none; min-width: 150px;
}
.map-controls { position: absolute; top: 14px; right: 14px; z-index: 5; display: flex; gap: 6px; }

/* Map responses (survey workspace) */
.map-responses-grid {
    display: grid;
    grid-template-columns: 1.45fr 1fr;
    gap: 14px;
    align-items: stretch;
}
@media (max-width: 980px) {
    .map-responses-grid { grid-template-columns: 1fr; }
}
.map-responses-map-card { min-width: 0; }
.map-responses-canvas {
    position: relative;
    height: min(62vh, 560px);
    min-height: 420px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #e8eef2;
}
.map-responses-canvas .maplibregl-canvas { outline: none; }
.map-responses-side { min-width: 0; display: flex; flex-direction: column; }
.map-responses-table {
    max-height: min(62vh, 560px);
    overflow: auto;
    flex: 1;
}
.map-region-row { cursor: pointer; }
.map-region-row:hover td { background: #f0fdfa; }
.map-region-row.is-active td { background: #ccfbf1; }
.map-popup { font-size: 12.5px; line-height: 1.45; color: #0f172a; }
.map-popup strong { display: block; margin-bottom: 6px; font-size: 13px; }
.map-popup a { display: inline-block; margin-top: 8px; font-weight: 700; color: #0d9488; }
.maplibregl-popup-content { border-radius: 10px; padding: 12px 14px; box-shadow: 0 12px 28px rgba(15,23,42,.16); }

@media print {
    .sidebar, .topbar, .filter-bar, .no-print { display: none !important; }
    .content { padding: 0; }
    .card { break-inside: avoid; box-shadow: none; }
}

@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 100; margin-left: -232px; }
    .shell.collapsed .sidebar { margin-left: 0; }
    .user-meta { display: none; }
}

/* ---------- Accessibility ---------- */
.skip-link {
    position: absolute; left: -9999px; top: 0;
    background: var(--accent); color: #fff; padding: 8px 14px;
    border-radius: 0 0 8px 0; text-decoration: none; z-index: 1000;
    font-size: 13px; font-weight: 600;
}
.skip-link:focus { left: 0; outline: 2px solid #fff; outline-offset: 2px; }

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

#main-content:focus { outline: none; }

.btn, .nav-item, .icon-btn, a, button, input, select, textarea {
    outline-color: var(--accent);
}
.btn:focus-visible, .nav-item:focus-visible, .icon-btn:focus-visible,
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Lite mode banner + reduced payload hints */
.lite-mode-banner {
    background: #fef3c7; color: #92400e; border: 1px solid #fde68a;
    padding: 8px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 14px;
}
[data-theme="dark"] .lite-mode-banner { background: #4a3411; color: #fcd34d; border-color: #92400e; }
.lite-mode .chart { min-height: 220px !important; }
.lite-mode .no-lite { display: none; }

/* Offline indicator */
.offline-banner {
    background: #fee2e2; color: #991b1b; border: 1px solid #fecaca;
    padding: 8px 14px; border-radius: 8px; font-size: 12.5px; margin-bottom: 14px;
}
[data-theme="dark"] .offline-banner { background: #5c1a1a; color: #fecaca; border-color: #991b1b; }

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Higher contrast text in muted contexts */
.muted { color: var(--muted); }
[data-theme="dark"] .muted { color: #adb9d2; }

/* ============================================================
   ANIMATIONS & EFFECTS (applies to all pages: dashboard, survey,
   form builder, login). Respects prefers-reduced-motion (above).
   ============================================================ */

/* ---- Keyframes ---- */
@keyframes gsa-fade-up {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes gsa-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes gsa-scale-in {
    from { opacity: 0; transform: scale(.94); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes gsa-slide-in-left {
    from { opacity: 0; transform: translateX(-18px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes gsa-slide-in-right {
    from { opacity: 0; transform: translateX(18px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes gsa-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}
@keyframes gsa-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
@keyframes gsa-gradient-pan {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes gsa-spin {
    to { transform: rotate(360deg); }
}
@keyframes gsa-bar-grow {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
}
@keyframes gsa-bell-ring {
    0%, 100% { transform: rotate(0); }
    20%      { transform: rotate(12deg); }
    40%      { transform: rotate(-10deg); }
    60%      { transform: rotate(6deg); }
    80%      { transform: rotate(-4deg); }
}

/* ---- Page load entrance (staggered) ---- */
.content > .card,
.content > .grid > .card,
.content > .grid > div,
.content > .alert,
.forms-content > .card,
.forms-content > .grid > .card,
.forms-content > .grid > div,
.forms-content > .alert,
.forms-content > .fb-hero,
.forms-content > .fb-kpi-grid > * {
    animation: gsa-fade-up .5s cubic-bezier(.22,.61,.36,1) both;
}
.content > .grid > .card:nth-child(1),
.content > .grid > div:nth-child(1),
.forms-content > .grid > .card:nth-child(1),
.forms-content > .grid > div:nth-child(1),
.forms-content > .fb-kpi-grid > *:nth-child(1) { animation-delay: .04s; }
.content > .grid > .card:nth-child(2),
.content > .grid > div:nth-child(2),
.forms-content > .grid > .card:nth-child(2),
.forms-content > .grid > div:nth-child(2),
.forms-content > .fb-kpi-grid > *:nth-child(2) { animation-delay: .10s; }
.content > .grid > .card:nth-child(3),
.content > .grid > div:nth-child(3),
.forms-content > .grid > .card:nth-child(3),
.forms-content > .grid > div:nth-child(3),
.forms-content > .fb-kpi-grid > *:nth-child(3) { animation-delay: .16s; }
.content > .grid > .card:nth-child(4),
.content > .grid > div:nth-child(4),
.forms-content > .grid > .card:nth-child(4),
.forms-content > .grid > div:nth-child(4),
.forms-content > .fb-kpi-grid > *:nth-child(4) { animation-delay: .22s; }
.content > .grid > .card:nth-child(5),
.content > .grid > div:nth-child(5),
.forms-content > .grid > .card:nth-child(5),
.forms-content > .grid > div:nth-child(5) { animation-delay: .28s; }
.content > .grid > .card:nth-child(6),
.content > .grid > div:nth-child(6),
.forms-content > .grid > .card:nth-child(6),
.forms-content > .grid > div:nth-child(6) { animation-delay: .34s; }
.content > .grid > .card:nth-child(n+7),
.content > .grid > div:nth-child(n+7),
.forms-content > .grid > .card:nth-child(n+7),
.forms-content > .grid > div:nth-child(n+7) { animation-delay: .40s; }

/* KPI row gets a slightly snappier entrance */
.kpi-row > .card { animation-duration: .42s; }

/* ---- Card hover lift ---- */
.card {
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.kpi-row > .card:hover,
.grid.two-col > .card:hover,
.grid.three-col > .card:hover,
.grid > .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(16, 30, 54, .10);
    border-color: rgba(37, 99, 235, .25);
}
[data-theme="dark"] .kpi-row > .card:hover,
[data-theme="dark"] .grid.two-col > .card:hover,
[data-theme="dark"] .grid.three-col > .card:hover,
[data-theme="dark"] .grid > .card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

/* ---- KPI icon pop on hover ---- */
.kpi-icon { transition: transform .2s ease; }
.kpi:hover .kpi-icon { transform: scale(1.12) rotate(-3deg); }

/* ---- Buttons: press + shine ---- */
.btn {
    transition: transform .12s ease, background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
    position: relative;
    overflow: hidden;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-primary {
    box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
}
.btn-primary:hover {
    box-shadow: 0 6px 18px rgba(37, 99, 235, .38);
}
.btn-primary::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.25) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform .6s ease;
    pointer-events: none;
}
.btn-primary:hover::after { transform: translateX(120%); }

/* ---- Sidebar nav: slide-in indicator + icon nudge ---- */
.nav-item, .forms-nav a {
    transition: background .15s ease, color .15s ease, transform .15s ease, padding-left .15s ease;
    position: relative;
}
.nav-item:hover, .forms-nav a:hover { transform: translateX(2px); }
.nav-item.active::before, .forms-nav a.active::before {
    content: ""; position: absolute; left: 0; top: 18%; bottom: 18%;
    width: 3px; border-radius: 0 3px 3px 0;
    background: #fff;
    animation: gsa-slide-in-left .25s ease both;
}
.nav-item svg, .forms-nav a svg { transition: transform .18s ease; }
.nav-item:hover svg, .forms-nav a:hover svg { transform: scale(1.12); }

/* ---- Sidebar brand mark gentle float ---- */
.brand-mark, .forms-brand-mark {
    animation: gsa-pulse 3.4s ease-in-out infinite;
}

/* ---- Topbar entrance ---- */
.topbar, .forms-topbar {
    animation: gsa-fade-in .4s ease both;
}

/* ---- Alerts slide in ---- */
.alert {
    animation: gsa-slide-in-left .35s ease both;
}
.alert-error { animation-name: gsa-fade-up; }

/* ---- Badges: subtle pulse for warning/danger ---- */
.badge-warning, .badge-danger {
    animation: gsa-pulse 2.4s ease-in-out infinite;
}
.fb-alert-badge { animation: gsa-pulse 1.6s ease-in-out infinite; }

/* ---- Table rows: hover slide ---- */
table.data tr {
    transition: background .12s ease;
}
table.data tbody tr:hover td { transform: translateX(2px); }
table.data td { transition: background .12s ease, transform .12s ease; }

/* ---- Progress / indicator bars: grow on load ---- */
.indicator .fill, .progress-bar span {
    transform-origin: left;
    animation: gsa-bar-grow .9s cubic-bezier(.22,.61,.36,1) both;
}

/* ---- Pagination nudge ---- */
.pager a, .pagination .page-link {
    transition: transform .12s ease, background .12s ease, color .12s ease, border-color .12s ease;
}
.pager a:hover, .pagination .page-link:hover { transform: translateY(-1px); }

/* ---- Filter chips: pop in ---- */
.filter-chip {
    animation: gsa-scale-in .2s ease both;
    transition: border-color .12s ease, color .12s ease, transform .12s ease;
}
.filter-chip:hover { transform: translateY(-1px); }

/* ---- Modal / popup scale-in ---- */
.fb-modal[hidden] { display: none !important; }
.fb-modal-panel {
    animation: gsa-scale-in .22s cubic-bezier(.22,.61,.36,1) both;
}
.fb-modal-backdrop { animation: gsa-fade-in .2s ease both; }

/* ---- Form builder alert bell ring on hover ---- */
.fb-alert-bell:hover svg { animation: gsa-bell-ring .7s ease; transform-origin: top center; }

/* ---- Maplibre / chart fade-in ---- */
.chart, #map, .maplibre-map, .map-responses-canvas {
    animation: gsa-fade-in .5s ease both;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    background: linear-gradient(135deg, #0c1a34 0%, #1e3a5f 45%, #0d9488 100%);
    background-size: 200% 200%;
    animation: gsa-gradient-pan 14s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}
.login-page::before {
    content: ""; position: absolute; inset: -20%;
    background:
        radial-gradient(circle at 20% 30%, rgba(20, 184, 166, .18), transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(37, 99, 235, .18), transparent 40%);
    animation: gsa-gradient-pan 18s ease-in-out infinite reverse;
    pointer-events: none;
}
.login-card {
    animation: gsa-scale-in .5s cubic-bezier(.22,.61,.36,1) both;
    position: relative;
    z-index: 1;
    transition: transform .25s ease, box-shadow .25s ease;
}
.login-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 28px 70px rgba(0,0,0,.42);
}
.login-card .brand-mark {
    animation: gsa-pulse 2.8s ease-in-out infinite;
}
.login-card input {
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.login-card input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.login-card .btn-primary {
    animation: gsa-fade-up .5s ease .15s both;
}
.login-card .alert-error {
    animation: gsa-fade-up .3s ease both;
}

/* ============================================================
   SCROLL REVEAL (driven by IntersectionObserver in app.js)
   ============================================================ */
.gsa-reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity .55s cubic-bezier(.22,.61,.36,1), transform .55s cubic-bezier(.22,.61,.36,1);
    will-change: opacity, transform;
}
.gsa-reveal.in-view {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Loading spinner (utility) ---- */
.gsa-spinner {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    animation: gsa-spin .7s linear infinite;
    display: inline-block;
    vertical-align: -3px;
}

/* ---- Reduced motion: disable all the above ---- */
@media (prefers-reduced-motion: reduce) {
    .content > .card, .content > .grid > .card, .content > .grid > div,
    .content > .alert, .forms-content > .card, .forms-content > .grid > .card,
    .forms-content > .grid > div, .forms-content > .alert, .forms-content > .fb-hero,
    .forms-content > .fb-kpi-grid > *,
    .kpi-row > .card, .topbar, .forms-topbar, .alert, .badge-warning, .badge-danger,
    .fb-alert-badge, .indicator .fill, .progress-bar span, .filter-chip,
    .fb-modal-panel, .fb-modal-backdrop, .chart, #map, .maplibre-map,
    .map-responses-canvas, .login-page, .login-page::before, .login-card,
    .login-card .brand-mark, .login-card .btn-primary, .login-card .alert-error,
    .brand-mark, .forms-brand-mark, .gsa-reveal, .gsa-spinner {
        animation: none !important;
        transition: none !important;
    }
    .gsa-reveal { opacity: 1; transform: none; }
}
