* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --ink: #0f1f3d;
    --ink-soft: #1f2a44;
    --muted: #6b7689;
    --accent: #0ea5e9;
    --accent-strong: #0f7ae5;
    --accent-emerald: #12b886;
    --panel: #ffffff;
    --panel-soft: #f6f8fb;
    --panel-softer: #f0f3f8;
    --border: #e6ebf2;
    --border-strong: #d6dde8;
    --shadow-sm: 0 1px 2px rgba(15, 31, 61, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 31, 61, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 31, 61, 0.12);
    --shadow: var(--shadow-lg);
    --badge-placeholder-bg: #ffedd5;
    --badge-placeholder-fg: #c2410c;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    overflow: hidden;
    background: var(--panel-soft);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: grid;
    grid-template-rows: 64px 1fr;
    height: 100vh;
    width: 100vw;
}

/* ========================================
   Top Header
   ======================================== */

.top-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    z-index: 20;
    position: relative;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent-emerald), var(--accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-logo svg {
    width: 30px;
    height: 30px;
}

.brand-text h1 {
    font-size: 17px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.brand-text p {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.2;
    margin-top: 2px;
}

.header-partners {
    display: flex;
    align-items: center;
    gap: 14px;
    justify-self: center;
}

.partner-logo {
    height: 54px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.04));
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: end;
}

.header-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.header-icon-btn svg {
    width: 16px;
    height: 16px;
}

.header-icon-btn:hover {
    background: var(--panel-soft);
    color: var(--ink);
    border-color: var(--border-strong);
}

.header-user-widget {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-logged-in {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-email-display {
    display: none; /* hide by default; rail-narrow viewports rely on avatar */
    font-size: 13px;
    color: var(--muted);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 1280px) {
    .user-email-display { display: inline-block; }
}

.header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.02em;
    cursor: pointer;
    user-select: none;
}

/* ========================================
   Workspace (rail + panel + map)
   ======================================== */

.workspace {
    display: grid;
    grid-template-columns: 84px 430px 1fr;
    grid-template-rows: 1fr;
    min-height: 0;
    height: 100%;
}

.workspace.panel-collapsed {
    grid-template-columns: 84px 0 minmax(0, 1fr);
}

.workspace.panel-collapsed #sidebar {
    display: none !important;
}

.icon-rail {
    grid-column: 1;
}

#sidebar.content-panel {
    grid-column: 2;
}

.workspace > #map {
    grid-column: 3;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
}

/* ========================================
   Icon Rail (left navigation)
   ======================================== */

.icon-rail {
    background: #fff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 14px 10px;
    z-index: 5;
}

.rail-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px 4px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.15;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.rail-btn svg {
    width: 22px;
    height: 22px;
}

.rail-btn:hover {
    background: var(--panel-soft);
    color: var(--ink);
}

.rail-btn.active {
    background: rgba(14, 165, 233, 0.10);
    color: var(--accent-strong);
}

.rail-btn .rail-label {
    display: block;
}

.rail-collapse {
    margin-top: auto;
    color: var(--muted);
}

.rail-collapse svg {
    transition: transform 0.15s ease;
}

.workspace.panel-collapsed .rail-collapse svg {
    transform: rotate(180deg);
}

/* ========================================
   Content Panel (sidebar)
   ======================================== */

#sidebar.content-panel {
    position: relative;
    background: #fff;
    border-right: 1px solid var(--border);
    display: none; /* Auth flow toggles to flex */
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 4;
    padding: 0;
}

.tab-panel {
    display: none;
    padding: 18px 16px 16px;
}

.tab-panel.active {
    display: block;
}

.mobile-panel-close { display: none; }

.panel-footer {
    padding: 16px 18px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

.logo-darwin-small {
    height: 18px;
    display: inline-block;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.04));
}

.darwin-link {
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
    transition: color 0.15s;
}

.darwin-link:hover {
    color: var(--accent-strong);
    text-decoration: underline;
}

/* ========================================
   Region Selector (top of catalog)
   ======================================== */

.region-selector {
    margin-bottom: 14px;
}

.region-selector > label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.region-select-wrapper {
    position: relative;
}

.region-select-wrapper select {
    width: 100%;
    padding: 11px 36px 11px 44px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-soft);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.region-selector.form-group .region-select-wrapper select {
    padding-left: 44px;
    padding-right: 36px;
}

.region-select-wrapper select:focus {
    outline: none;
    background: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.12);
}

.region-select-icon,
.region-select-chevron {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    display: inline-flex;
}

.region-select-icon { left: 14px; width: 16px; height: 16px; color: var(--accent-strong); }
.region-select-icon svg { width: 100%; height: 100%; }
.region-select-chevron { right: 12px; width: 14px; height: 14px; }
.region-select-chevron svg { width: 100%; height: 100%; }

/* ========================================
   Region Summary
   ======================================== */

.region-summary {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px 16px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}

.region-summary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.region-summary-header h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.005em;
}

.region-summary-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--badge-placeholder-fg);
    background: var(--badge-placeholder-bg);
    padding: 3px 8px;
    border-radius: 999px;
}

.region-summary-badge.is-live {
    color: #075985;
    background: #e0f2fe;
}

.region-summary-badge.is-error {
    color: var(--muted);
    background: var(--panel-softer);
}

.region-summary-area {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 10px 12px;
    background: var(--panel-soft);
    border-radius: 10px;
    margin-bottom: 12px;
}

.rs-area-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.rs-area-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
    margin-left: auto;
}

.region-summary-subtitle {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 10px;
}

.habitat-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.habitat-row {
    display: grid;
    grid-template-columns: 14px 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    background: var(--panel-soft);
    border-radius: 10px;
    transition: background 0.15s;
}

.habitat-row:hover {
    background: var(--panel-softer);
}

.habitat-swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(15, 31, 61, 0.10);
    flex-shrink: 0;
}

.habitat-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.habitat-code {
    font-size: 12px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.habitat-label {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.habitat-cover {
    font-size: 12px;
    font-weight: 700;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    text-align: right;
    min-width: 52px;
}

.habitat-status {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.status-fv { background: #d1fadf; color: #047857; }
.status-u1 { background: #fef3c7; color: #b45309; }
.status-u2 { background: #fee2e2; color: #b91c1c; }
.status-xx { background: var(--panel-softer); color: var(--muted); }

.region-summary-empty {
    font-size: 12px;
    color: var(--muted);
    padding: 8px 10px;
}

.card-chevron {
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    font-weight: 400;
}

/* ========================================
   Quick Access cards
   ======================================== */

.quick-access {
    margin-top: 18px;
    margin-bottom: 14px;
}

.quick-access h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 10px;
    letter-spacing: -0.005em;
}

.quick-access-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.quick-access-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}

.quick-access-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.qa-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--accent-strong);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.qa-icon svg {
    width: 16px;
    height: 16px;
}

.qa-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
}

.qa-desc {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.3;
}

/* ========================================
   Data Sources card
   ======================================== */

.data-sources-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    margin-top: 6px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: var(--ink);
    transition: box-shadow 0.15s, border-color 0.15s;
}

.data-sources-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}

.ds-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--panel-soft);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ds-icon svg {
    width: 16px;
    height: 16px;
}

.ds-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ds-body strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
}

.ds-body span {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.3;
}

/* ========================================
   Home tab — uses .section / .instruction so it matches Active Layers
   The only home-specific bit is the compact 3-column stat grid that
   sits inside the section card.
   ======================================== */

.home-stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}

.home-stat {
    min-width: 0;
    padding: 10px 8px;
    border-radius: 10px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    text-align: center;
}

.home-stat strong {
    display: block;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.home-stat span {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.25;
    color: var(--muted);
}

/* The home tab's data-sources-card chevron uses an SVG (see index.html);
   render it at the same size as the other arrow icons. */
.data-sources-card .card-chevron svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* ========================================
   Sections
   ======================================== */

.section {
    margin-bottom: 20px;
    padding: 18px 18px 16px;
    background: var(--panel);
    border-radius: 16px;
    border: 1px solid rgba(223, 231, 242, 0.8);
    box-shadow: 0 6px 14px rgba(15, 31, 61, 0.05);
}

.section:last-child {
    margin-bottom: 0;
}

.section h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 10px;
    letter-spacing: -0.01em;
}

.instruction {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 12px;
    line-height: 1.5;
}

/* ========================================
   Form Elements
   ======================================== */

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    background: var(--panel-soft);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.16);
}

.form-group select[multiple] {
    min-height: 120px;
}

/* ========================================
   Buttons
   ======================================== */

.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

/* Compact button variant for small actions */
.btn-compact {
    width: auto;
    padding: 8px 12px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: white;
    box-shadow: 0 12px 28px rgba(14, 165, 233, 0.22);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent-emerald));
    transform: translateY(-1px);
    box-shadow: 0 14px 32px rgba(14, 165, 233, 0.3);
}

.btn-primary:disabled {
    background: #cdd7e3;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background: white;
    color: var(--ink);
    border: 1.5px solid var(--border);
    box-shadow: 0 8px 18px rgba(15, 31, 61, 0.06);
}

.btn-secondary:hover {
    background: rgba(14, 165, 233, 0.08);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

/* ========================================
   Status Indicators
   ======================================== */

.status-indicator {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    background: var(--panel-soft);
    color: var(--muted);
    border-left: 4px solid var(--border);
    box-shadow: 0 6px 18px rgba(15, 31, 61, 0.06);
}

.status-indicator.active {
    background: #e7f7ef;
    color: #0f9d58;
    border-left-color: #12b886;
}

.status-indicator.drawing {
    background: #fff3da;
    color: #b56b11;
    border-left-color: #f6b73c;
}

.status-indicator.error {
    background: #ffe7eb;
    color: #b4233d;
    border-left-color: #ef476f;
}

/* ========================================
   Results
   ======================================== */

#results-content {
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 12px 30px rgba(15, 31, 61, 0.08);
}

.result-item {
    margin-bottom: 12px;
    padding: 12px;
    background: white;
    border-radius: 12px;
    border-left: 3px solid var(--accent);
    box-shadow: 0 10px 22px rgba(15, 31, 61, 0.08);
}

.result-item h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}

.result-item p {
    font-size: 13px;
    color: var(--muted);
    margin: 4px 0;
}

.result-item .value {
    font-weight: 600;
    color: var(--accent);
}

/* ========================================
   Status Messages
   ======================================== */

#status-messages {
    margin-top: 16px;
}

.message {
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.5;
    box-shadow: 0 8px 18px rgba(15, 31, 61, 0.06);
}

.message.info {
    background: #e8f3ff;
    color: #0f5f9c;
    border-left: 4px solid var(--accent);
}

.message.success {
    background: #e7f7ef;
    color: #0f9d58;
    border-left: 4px solid #12b886;
}

.message.error {
    background: #ffe7eb;
    color: #b4233d;
    border-left: 4px solid #ef476f;
}

.message.warning {
    background: #fff3da;
    color: #b56b11;
    border-left: 4px solid #f6b73c;
}

/* ========================================
   Trees and Lists
   ======================================== */

.tree {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.tree details {
    border: none;
    border-radius: 10px;
    padding: 8px 9px;
    margin: 0;
    background: #f9fbfd;
    box-shadow: 0 4px 12px rgba(15, 31, 61, 0.05);
}
.tree summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    line-height: 1.25;
    list-style: none;
}
.tree summary .summary-title {
    flex: 1;
}
.tree summary .info-tooltip {
    margin-left: auto;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(15, 31, 61, 0.15);
    background: rgba(15, 31, 61, 0.06);
    color: var(--ink);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
}
.tree summary .info-tooltip:focus {
    outline: 2px solid rgba(15, 31, 61, 0.2);
    outline-offset: 2px;
}
.tree summary .info-tooltip__content {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    max-width: 260px;
    min-width: 180px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(15, 31, 61, 0.85);
    color: #f8fbff;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.4;
    box-shadow: 0 10px 24px rgba(15, 31, 61, 0.2);
    z-index: 5;
}
.tree summary .info-tooltip:hover .info-tooltip__content,
.tree summary .info-tooltip:focus .info-tooltip__content {
    display: block;
}
.tree summary .info-tooltip__cite {
    display: block;
    margin-top: 6px;
    opacity: 0.85;
    font-size: 9px;
}
.layer-leaf .info-tooltip {
    margin-left: 6px;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 1px solid rgba(15, 31, 61, 0.15);
    background: rgba(15, 31, 61, 0.06);
    color: var(--ink);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    vertical-align: middle;
}
.layer-leaf .info-tooltip:hover {
    background: rgba(15, 31, 61, 0.12);
}
.layer-leaf .info-tooltip__content {
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: calc(100% + 6px);
    max-width: 240px;
    min-width: 160px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(15, 31, 61, 0.9);
    color: #f8fbff;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.4;
    box-shadow: 0 8px 20px rgba(15, 31, 61, 0.25);
    z-index: 10;
    white-space: normal;
    text-align: left;
}
.layer-leaf .info-tooltip:hover .info-tooltip__content {
    display: block;
}
.layer-leaf .doc-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: rgba(14, 165, 233, 0.10);
    color: var(--accent);
    opacity: 1;
    flex-shrink: 0;
    line-height: 1;
    text-decoration: none;
    margin-left: auto;
    transition: background 0.15s ease, color 0.15s ease;
}
.layer-leaf .doc-link-icon:hover {
    background: rgba(14, 165, 233, 0.18);
    color: var(--accent-strong);
}
.tree details[data-depth="0"] > summary {
    font-size: 13px;
}
.tree summary::marker {
    content: '';
}
.tree summary::-webkit-details-marker {
    display: none;
}
.tree summary::before {
    content: '';
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 6px solid var(--accent);
    transition: transform 0.15s ease;
}
.tree details[open] > summary::before {
    transform: rotate(90deg);
}
.tree .tree-group {
    margin-left: 6px;
    margin-top: 7px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.tree .layer-leaf {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    padding: 6px 7px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 31, 61, 0.05);
}
.tree .layer-leaf label {
    cursor: pointer;
    color: var(--ink);
    font-size: 11.5px;
    line-height: 1.25;
    flex: 1;
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
}

.active-layers .layer-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--border); border-radius: 12px; background: linear-gradient(135deg, #ffffff 0%, #f7fbff 100%);
    padding: 10px 12px; margin-bottom: 10px; box-shadow: 0 6px 14px rgba(15, 31, 61, 0.05);
}
.active-layers .layer-title { font-weight: 700; color: var(--ink); font-size: 13px; line-height: 1.35; word-break: break-word; }
.active-layers .controls { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.active-layers .control-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.active-layers .control-row.moves { gap: 4px; }
.active-layers .controls .icon.tiny {
    width: 26px;
    height: 26px;
    padding: 0;
    font-size: 12px;
    line-height: 1;
}
.active-layers input[type="range"] { width: 110px; flex-shrink: 0; }

.active-layers .vector-filters {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}
.active-layers .vector-filter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
}
.active-layers .vector-filter-label {
    font-weight: 600;
    color: var(--ink);
}
.active-layers .vector-filter-value {
    color: var(--muted);
    font-size: 11px;
}
.active-layers .vector-filter-range {
    position: relative;
    width: 100%;
    height: 28px;
}
.active-layers .vector-filter-selects {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 6px;
}
.active-layers .vector-filter-select {
    width: 100%;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--ink);
    font-size: 12px;
}
.active-layers .vector-filter-taxonomy {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.active-layers .vector-taxonomy-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 6px;
    align-items: center;
}
.active-layers .vector-taxonomy-row .vector-filter-label {
    margin: 0;
}
.active-layers .vector-taxonomy-row .vector-filter-select {
    width: 100%;
}
.active-layers .vector-filter-select:focus {
    outline: 2px solid rgba(17, 24, 39, 0.2);
    outline-offset: 1px;
}

/* Taxonomy search autocomplete */
.taxonomy-search-wrapper {
    position: relative;
    width: 100%;
}
.taxonomy-search-input {
    width: 100%;
    padding: 6px 28px 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--ink);
    font-size: 12px;
    font-family: inherit;
    box-sizing: border-box;
}
.taxonomy-search-input::placeholder {
    color: var(--muted);
    opacity: 0.7;
}
.taxonomy-search-input:focus {
    outline: 2px solid rgba(17, 24, 39, 0.2);
    outline-offset: 1px;
}
.taxonomy-search-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.taxonomy-search-clear:hover {
    color: var(--ink);
}
.taxonomy-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(15, 31, 61, 0.12);
    z-index: 20;
    font-size: 12px;
}
.taxonomy-search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    cursor: pointer;
    gap: 8px;
}
.taxonomy-search-item:hover {
    background: var(--panel-soft);
}
.taxonomy-search-item-name {
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.taxonomy-search-item-rank {
    color: var(--muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.active-layers .vector-filter-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 4px;
    transform: translateY(-50%);
    background: var(--panel-soft);
    border-radius: 999px;
}
.active-layers .vector-filter-fill {
    position: absolute;
    height: 100%;
    background: var(--ink);
    border-radius: 999px;
}
.active-layers .vector-filter-range input[type="range"] {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    height: 28px;
    margin: 0;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
}
.active-layers .vector-filter-range input[type="range"]::-webkit-slider-runnable-track {
    background: transparent;
}
.active-layers .vector-filter-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    pointer-events: auto;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid var(--ink);
    box-shadow: 0 2px 6px rgba(15, 31, 61, 0.18);
}
.active-layers .vector-filter-range input[type="range"]::-moz-range-track {
    background: transparent;
}
.active-layers .vector-filter-range input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid var(--ink);
    box-shadow: 0 2px 6px rgba(15, 31, 61, 0.18);
}

.export-layers .export-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--panel-soft);
}

.histogram-panel {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(135deg, #ffffff 0%, #f6f8fb 100%);
    box-shadow: 0 8px 18px rgba(15, 31, 61, 0.08);
}
.histogram-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.histogram-header h4 {
    margin: 0;
    font-size: 14px;
    color: var(--ink);
}
.histogram-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 10px;
}
.histogram-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    background: #fff;
}
.histogram-title {
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    margin-bottom: 6px;
}
.histogram-chart {
    position: relative;
}
.histogram-panel img,
.histogram-panel canvas {
    max-width: 100%;
    height: auto;
}
.histogram-canvas {
    width: 100%;
    height: 220px;
    display: block;
    background: #fdfefe;
    border-radius: 10px;
    border: 1px solid var(--border);
}
.histogram-meta {
    font-size: 12px;
    color: #5b6474;
    margin-top: 6px;
}
.histogram-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 6px;
    margin-top: 10px;
}
.histogram-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--ink);
}
.histogram-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.2);
}
.histogram-tooltip {
    position: fixed;
    z-index: 1000;
    background: rgba(17, 24, 39, 0.92);
    color: #fff;
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.12s ease, transform 0.12s ease;
    white-space: nowrap;
}
.histogram-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Time Trend Box Plot */
.time-trend-canvas {
    height: 260px;
}

/* ========================================
   Map
   ======================================== */

#map {
    flex: 1;
    position: relative;
}

.basemap-control {
    position: relative;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.basemap-toggle {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(15, 31, 61, 0.14);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #0d3c96;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.basemap-toggle:hover {
    background: #f6f9fd;
    box-shadow: 0 12px 28px rgba(15, 31, 61, 0.18);
    transform: translateY(-1px);
}
.basemap-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2), 0 12px 28px rgba(15, 31, 61, 0.18);
}
.basemap-toggle svg { width: 16px; height: 16px; }

.basemap-menu {
    position: absolute;
    right: 0;
    top: 40px;
    width: 240px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(15, 31, 61, 0.18);
    padding: 8px;
    display: none;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    z-index: 5;
    max-height: min(240px, calc(100vh - 510px));
    overflow-y: auto;
    box-sizing: border-box;
}
.basemap-menu.open { display: block; }
.basemap-option {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 9px 10px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.01em;
    color: var(--ink);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
.basemap-option:hover {
    background: rgba(14, 165, 233, 0.08);
}
.basemap-option.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.3);
}
.basemap-option.active:hover {
    background: linear-gradient(135deg, var(--accent-strong), var(--accent));
}
.basemap-group {
    border-top: 1px solid var(--border);
    margin-top: 6px;
    padding-top: 6px;
}
.basemap-option-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 700;
}
.basemap-submenu {
    display: none;
    margin-top: 4px;
    padding-left: 8px;
    max-height: 240px;
    overflow-y: auto;
}
.basemap-subgroup {
    margin-top: 6px;
}
.basemap-submenu .basemap-submenu {
    padding-left: 12px;
}
.basemap-submenu.open { display: block; }
.basemap-option-sub {
    font-weight: 600;
    font-size: 12px;
    padding-left: 12px;
}
/* Slim scrollbar for basemap menus */
.basemap-menu::-webkit-scrollbar,
.basemap-submenu::-webkit-scrollbar {
    width: 6px;
}
.basemap-menu::-webkit-scrollbar-thumb,
.basemap-submenu::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 999px;
}
.basemap-menu::-webkit-scrollbar-track,
.basemap-submenu::-webkit-scrollbar-track {
    background: transparent;
}

.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
    z-index: 1;
}

/* ========================================
   Legend Control & Panel
   ======================================== */

.map-legend-control .legend-btn {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 10px;
    background: #fff;
    box-shadow: var(--shadow-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.map-legend-control .legend-btn:hover { background: var(--panel-soft); }
.map-legend-control .legend-btn svg { width: 14px; height: 14px; fill: var(--ink); }

.map-legend-panel {
    position: absolute;
    bottom: 32px;
    right: 10px;
    width: 240px;
    max-height: max(220px, calc(100vh - 530px));
    overflow: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-md);
    padding: 14px 16px;
    z-index: 4;
    display: block; /* visible by default; toggled via legend button */
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--ink);
    box-sizing: border-box;
}

.map-legend-panel > div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.map-legend-panel strong {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.005em;
}
.map-legend-panel h4 {
    font-size: 12px;
    font-weight: 700;
    margin: 10px 0 6px;
    color: var(--ink);
}
.legend-entry { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 12px; color: var(--ink-soft); }
.legend-swatch { width: 14px; height: 14px; border: 1px solid var(--border-strong); border-radius: 4px; flex-shrink: 0; }
.legend-ramp { height: 10px; border: 1px solid var(--border-strong); border-radius: 4px; background: linear-gradient(90deg,#000,#fff); }
.legend-subheader { font-weight: 600; font-size: 11px; margin: 10px 0 4px 0; padding-top: 6px; border-top: 1px solid var(--border); color: var(--muted); }
.legend-subheader:first-of-type { border-top: none; margin-top: 4px; padding-top: 0; }
.legend-empty { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* MapLibre control re-skin (zoom, fullscreen, navigation) */
.maplibregl-ctrl-group {
    border-radius: 10px !important;
    box-shadow: var(--shadow-md) !important;
    overflow: hidden;
    border: 1px solid var(--border) !important;
}
.maplibregl-ctrl-group button {
    width: 30px !important;
    height: 30px !important;
}
.maplibregl-ctrl-group button + button {
    border-top: 1px solid var(--border) !important;
}
.maplibregl-ctrl-attrib {
    background: rgba(255, 255, 255, 0.85) !important;
    border-radius: 6px !important;
    font-size: 11px !important;
    font-family: 'Inter', sans-serif !important;
}

/* Ensure top-right controls stay above floating panels */
.maplibregl-ctrl-top-right { z-index: 3; }

/* ========================================
   MapLibre Draw Customization
   ======================================== */

.mapbox-gl-draw_ctrl-draw-btn {
    background-color: #ffffff;
}

.mapbox-gl-draw_ctrl-draw-btn:hover {
    background-color: #f5f5f5;
}

.mapbox-gl-draw_ctrl-draw-btn.active {
    background-color: var(--accent);
}

.mapbox-gl-draw_polygon,
.mapbox-gl-draw_rectangle {
    background-repeat: no-repeat;
    background-position: center;
    background-size: 18px 18px;
}

.mapbox-gl-draw_polygon {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 17c3-6 6 2 9-4s6 2 9-4'/><circle cx='3' cy='17' r='1.6' fill='%23333' stroke='none'/><circle cx='21' cy='5' r='1.6' fill='%23333' stroke='none'/></svg>");
}

.mapbox-gl-draw_rectangle {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2'><rect x='4' y='6' width='16' height='12' rx='1'/></svg>");
}

/* ========================================
   Loading Spinner
   ======================================== */

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.7s linear infinite;
    margin-right: 10px;
    vertical-align: middle;
}

.download-progress-container {
    margin-top: 10px;
}

.download-progress-track {
    position: relative;
    height: 6px;
    background: var(--border, #e2e8f0);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.download-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-emerald));
    border-radius: 3px;
    transition: width 0.25s ease;
    width: 0%;
}

.download-progress-track[data-indeterminate] .download-progress-fill {
    width: 40%;
    position: absolute;
    animation: indeterminate-slide 1.4s ease-in-out infinite;
}

@keyframes indeterminate-slide {
    0%   { left: -40%; }
    100% { left: 140%; }
}

.download-progress-info {
    font-size: 12px;
    color: var(--text-muted, #64748b);
    margin: 0;
}

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

/* ========================================
   Documentation Page
   ======================================== */

.doc-body {
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
}

.doc-page {
    max-width: 1240px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 24px 56px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.doc-hero {
    position: relative;
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 18px;
    padding: 28px;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.06), rgba(18, 184, 134, 0.08)), #ffffff;
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.doc-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url('assets/contours-blue.png'), url('assets/contours.png'), url('assets/contours.svg');
    background-repeat: repeat;
    background-size: 360px auto;
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
}

.doc-hero > * {
    position: relative;
    z-index: 1;
}

.doc-hero-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.eyebrow {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 700;
}

.doc-hero h1 {
    font-size: 28px;
    letter-spacing: -0.02em;
}

.hero-copy {
    font-size: 15px;
    line-height: 1.6;
    color: var(--muted);
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}

.doc-hero-logo {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    pointer-events: none;
}

.doc-partner-logo {
    height: 76px;
    width: auto;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.06));
}

.link-quiet {
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 600;
}

.link-quiet:hover {
    text-decoration: underline;
}

.dot-divider {
    color: var(--border);
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.pill-soft {
    background: rgba(14, 165, 233, 0.08);
    color: var(--ink);
    border: 1px solid rgba(14, 165, 233, 0.18);
}

.pill-outline {
    background: #fff;
    color: var(--muted);
    border: 1px solid var(--border);
}

.pill-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.25);
}

.doc-main {
    display: flex;
    flex-direction: column;
    gap: 22px;
    min-width: 0;
}

.doc-section {
    background: var(--panel);
    border: 1px solid rgba(223, 231, 242, 0.9);
    border-radius: 20px;
    padding: 24px 22px;
    box-shadow: 0 10px 26px rgba(15, 31, 61, 0.08);
    min-width: 0;
}

.doc-section + .doc-section {
    margin-top: 4px;
}

.doc-section-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
    min-width: 0;
}

.doc-section-heading > * {
    min-width: 0;
}

.doc-section-heading h2 {
    font-size: 22px;
    letter-spacing: -0.02em;
}

.section-subtitle {
    font-size: 14px;
    color: var(--muted);
    margin-top: 6px;
    max-width: 760px;
}

.doc-group-card {
    background: linear-gradient(180deg, #f9fbff 0%, #ffffff 55%, #f5fbf7 100%);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 10px 22px rgba(15, 31, 61, 0.06);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.doc-group-card__head {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dataset-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.dataset-grid.single {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.dataset-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 22px rgba(15, 31, 61, 0.06);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.dataset-card__header {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dataset-card h4 {
    font-size: 16px;
    letter-spacing: -0.01em;
}

.dataset-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.field-row {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 10px;
    align-items: start;
    padding: 10px 12px;
    background: var(--panel-soft);
    border-radius: 12px;
    border: 1px dashed var(--border);
    min-width: 0;
}

.field-row dt {
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
}

.field-row dd {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    min-width: 0;
    overflow-wrap: anywhere;
}

.method-flow {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.method-step,
.method-panel {
    background: linear-gradient(180deg, #ffffff 0%, #f6fbff 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.method-step strong,
.method-panel h4 {
    display: block;
    font-size: 13px;
    color: var(--ink);
    margin-bottom: 4px;
}

.method-step span,
.method-panel p {
    display: block;
    font-size: 12px;
    line-height: 1.45;
    color: var(--muted);
}

.method-panel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.method-panel-grid.method-panel-grid-wide {
    grid-template-columns: minmax(0, 1fr);
}

.percentile-diagram {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    min-height: 34px;
    overflow: hidden;
    border-radius: 999px;
    border: 1px solid var(--border);
    margin: 6px 0 8px;
    font-size: 11px;
    font-weight: 700;
    color: #0f1f3d;
}

.percentile-diagram span {
    display: flex;
    align-items: center;
    justify-content: center;
}

.risk-low,
.risk-high {
    background: #fee2e2;
}

.normal-zone {
    background: #dbeafe;
}

.method-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    color: var(--muted);
}

.method-table th,
.method-table td {
    text-align: left;
    padding: 6px 7px;
    border-bottom: 1px solid var(--border);
}

.method-table th {
    color: var(--ink);
    font-weight: 700;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    border-radius: 999px;
    padding: 2px 7px;
    font-size: 11px;
    font-weight: 800;
}

.status-fv { background: #dbeafe; color: #1d4ed8; }
.status-u1 { background: #fef3c7; color: #92400e; }
.status-u2 { background: #fee2e2; color: #b91c1c; }
.status-xx { background: #e5e7eb; color: #374151; }

.rule-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin: 7px 0 8px;
}

.rule-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    background: #fff;
}

.rule-card strong {
    display: block;
    font-size: 11px;
    color: var(--ink);
    margin-bottom: 3px;
}

.rule-card span {
    display: block;
    font-size: 11px;
    line-height: 1.35;
    color: var(--muted);
}

.variable-table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    max-height: 360px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.variable-table-wrap .method-table {
    min-width: min(620px, 100%);
}

.formula-note {
    display: block;
    margin-top: 6px;
    padding: 8px;
    border-radius: 10px;
    background: var(--panel-soft);
    color: var(--ink-soft);
    font-size: 12px;
}

.pillar-stack {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 7px 0 8px;
}

.pillar-stack span,
.overall-formula span,
.overall-formula strong {
    border-radius: 10px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    padding: 7px;
    font-size: 11px;
    font-weight: 700;
    color: var(--ink-soft);
    text-align: center;
}

.overall-formula {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1fr;
    gap: 6px;
    align-items: center;
    margin: 7px 0 8px;
}

.overall-formula strong {
    grid-column: 1 / -1;
    background: #dbeafe;
    color: #1d4ed8;
}

.placeholder-text {
    color: #9aa8bf;
    font-style: italic;
}

.doc-footer {
    margin-top: 8px;
    padding: 18px 10px 8px;
    display: flex;
    justify-content: center;
}

.footer-content {
    width: 100%;
    max-width: 1180px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 13px;
}

.doc-footer-credit {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--muted);
}

.doc-footer-credit .logo-darwin-small {
    height: 14px;
}

.muted {
    color: var(--muted);
}

/* ========================================
   Browser layout (type -> subgroup -> indicator)
   ======================================== */

.browser-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 16px;
    align-items: start;
    min-width: 0;
}

.dataset-type-toggle {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 10px;
    background: #f4f7fb;
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 100%;
}

.type-chip {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: #fff;
    color: var(--muted);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.16s ease;
}

.type-chip:hover {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(14, 165, 233, 0.08);
}

.type-chip.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    box-shadow: 0 10px 24px rgba(14, 165, 233, 0.24);
}

.subgroup-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.subgroup-label {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.subgroup-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 22px rgba(15, 31, 61, 0.08);
}

.methodology-note {
    font-size: 12px;
    line-height: 1.5;
    padding: 6px 4px 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
}
.methodology-note a {
    color: var(--accent);
}

.subgroup-button {
    text-align: left;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
    color: var(--ink);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.16s ease;
}

.subgroup-button:hover {
    border-color: var(--accent);
    background: rgba(14, 165, 233, 0.08);
    box-shadow: 0 10px 22px rgba(14, 165, 233, 0.14);
}

.subgroup-button.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 12px 28px rgba(14, 165, 233, 0.24);
}

.group-panel-area {
    min-height: 420px;
    min-width: 0;
}

.group-panels .doc-group-card {
    display: none;
}

.group-panels .doc-group-card.active {
    display: flex;
}

/* ========================================
   Indicator Tabs (single visible)
   ======================================== */

.indicator-layout {
    display: grid;
    grid-template-columns: 230px 1fr;
    gap: 14px;
    align-items: start;
    min-width: 0;
}

.browser-layout > *,
.indicator-layout > *,
.method-flow > *,
.method-panel-grid > *,
.rule-card-grid > *,
.overall-formula > * {
    min-width: 0;
}

.indicator-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 10px 22px rgba(15, 31, 61, 0.08);
}

.indicator-chip {
    width: 100%;
    padding: 10px 12px;
    text-align: left;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--panel-soft);
    color: var(--ink);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.16s ease;
}

.indicator-chip:hover {
    border-color: var(--accent);
    background: rgba(14, 165, 233, 0.08);
    box-shadow: 0 10px 22px rgba(14, 165, 233, 0.14);
}

.indicator-chip.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 12px 28px rgba(14, 165, 233, 0.24);
}

.indicator-panels .dataset-card {
    display: none;
}

.indicator-panels .dataset-card.active {
    display: flex;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 980px) {
    .doc-hero {
        grid-template-columns: 1fr;
    }

    .doc-section-heading {
        flex-direction: column;
    }

    .doc-page {
        padding: 22px 18px 40px;
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .indicator-layout {
        grid-template-columns: 1fr;
    }

    .browser-layout {
        grid-template-columns: 1fr;
    }

    .method-flow,
    .method-panel-grid,
    .rule-card-grid {
        grid-template-columns: 1fr;
    }

    .overall-formula {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .doc-hero {
        padding: 22px;
    }

    .doc-section {
        padding: 18px;
    }

    .hero-actions {
        flex-direction: column;
        align-items: flex-start;
    }
}


@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 64px 300px 1fr;
    }
    .workspace.panel-collapsed {
        grid-template-columns: 64px 0 minmax(0, 1fr);
    }
    .rail-btn .rail-label { font-size: 10px; }
    .header-partners { gap: 8px; }
    .partner-logo { height: 32px; }
    .brand-text p { display: none; }
}

@media (max-width: 768px) {
    #app {
        grid-template-rows: 56px 1fr;
    }

    .top-header {
        padding: 0 12px;
        gap: 8px;
    }
    .header-partners { display: none; }
    .brand-text p { display: none; }
    .brand-text h1 { font-size: 14px; }

    .workspace {
        grid-template-columns: 56px 1fr;
        position: relative;
    }

    .workspace.panel-collapsed {
        grid-template-columns: 56px minmax(0, 1fr);
    }

    .workspace > #map {
        grid-column: 2;
    }

    /* Hide content panel by default on mobile; show when .panel-open is set */
    #sidebar.content-panel {
        grid-column: 2;
        position: absolute;
        top: 0;
        left: 56px;
        right: 0;
        bottom: 0;
        z-index: 6;
        max-width: 360px;
        box-shadow: 8px 0 24px rgba(15, 31, 61, 0.12);
    }

    #sidebar.content-panel:not(.panel-open) {
        display: none !important;
    }

    .rail-btn .rail-label { display: none; }
    .rail-btn { padding: 12px 4px; }
}

/* Auth Modal Styles */
.modal-overlay { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.5); 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 2000; 
}

/* Landing Page Mode */
.landing-page-overlay {
    background: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
                url('assets/pexels-altamar-35479203.jpg') no-repeat center center / cover !important;
}

/* Landing stack: brand header + login card + footer */
.landing-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    width: 100%;
    max-width: 460px;
    padding: 16px;
    margin-top: -12vh;
}

.landing-header,
.landing-footer {
    display: none;
}

.landing-page-overlay .landing-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.landing-page-overlay .landing-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #fff;
    font-size: 13px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

.landing-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.landing-brand-logo {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent-emerald), var(--accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
}

.landing-brand-logo svg {
    width: 50px;
    height: 50px;
}

.landing-brand-text {
    text-align: left;
}

.landing-brand-text h1 {
    margin: 0;
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.1;
    color: #fff;
}

.landing-brand-text p {
    margin: 6px 0 0 0;
    font-size: 15px;
    color: rgba(255, 255, 255, 0.88);
    line-height: 1.2;
    letter-spacing: 0.02em;
}

.landing-partner-logo {
    height: 64px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.landing-darwin-logo {
    height: 18px;
    display: inline-block;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.landing-page-overlay .landing-footer .darwin-link {
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
    transition: border-color 0.15s;
}

.landing-page-overlay .landing-footer .darwin-link:hover {
    border-color: #fff;
}

@media (max-width: 480px) {
    .landing-brand { flex-direction: column; gap: 8px; }
    .landing-brand-text { text-align: center; }
    .landing-brand-text h1 { font-size: 22px; }
    .landing-partner-logo { height: 38px; }
}

.modal-content { 
    background: #fff; 
    border-radius: 12px; 
    width: 100%; 
    max-width: 400px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.25); 
    animation: modal-in 0.3s ease-out; 
    display: flex;
    flex-direction: column;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header { padding: 20px 24px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { margin: 0; font-size: 1.5rem; font-weight: 700; color: var(--ink); }
.close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #999; transition: color 0.2s; }
.close-btn:hover { color: var(--ink); }
.modal-body { padding: 24px; }
.btn-link { background: none; border: none; color: #ff6b00; cursor: pointer; text-decoration: underline; padding: 0; font-weight: 600; }

.btn-guest {
    width: 100%;
    padding: 12px 20px;
    border: 1px solid #dfe7f2;
    background: #fff;
    color: var(--muted);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 12px;
}
.btn-guest:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: #f4f7fb;
}


/* ========================================
   File Browser Modal
   ======================================== */

.file-browser-content {
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;  /* Prevent double scrollbars */
}

.file-browser-content .modal-body {
    overflow-y: auto;
    flex: 1;           /* Allow body to grow/shrink */
    min-height: 0;     /* Enable flex shrinking for overflow */
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
}

/* Tenant Info Panel */
.tenant-info {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.08), rgba(18, 184, 134, 0.06));
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    flex-shrink: 0;  /* Don't compress */
}

.tenant-info-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
}

.tenant-info-row:last-child {
    margin-bottom: 0;
}

.tenant-info-row .label {
    font-weight: 700;
    color: var(--muted);
    min-width: 120px;
}

.tenant-badge {
    background: linear-gradient(135deg, var(--accent), var(--accent-emerald));
    color: #fff;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.tenant-badge.unassigned {
    background: #f0ad4e;
}

.path-list {
    margin: 0;
    padding-left: 16px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    color: var(--ink);
}

/* File List Section */
.file-list-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;  /* Don't compress */
}

.file-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--panel-soft);
    border-bottom: 1px solid var(--border);
}

.file-list-header h3 {
    margin: 0;
    font-size: 14px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.file-list {
    max-height: 200px;  /* Reduced to leave room for preview */
    overflow-y: auto;
    padding: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.file-item:last-child {
    margin-bottom: 0;
}

.file-item:hover {
    background: rgba(14, 165, 233, 0.06);
    border-color: var(--accent);
}

.file-item.common {
    border-left: 3px solid var(--accent-emerald);
}

.file-item.tenant {
    border-left: 3px solid var(--accent);
}

.file-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--ink);
    word-break: break-all;
}

.file-meta {
    font-size: 11px;
    color: var(--muted);
}

.file-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.loading-placeholder {
    text-align: center;
    padding: 20px;
    color: var(--muted);
    font-style: italic;
}

.empty-list {
    text-align: center;
    padding: 30px;
    color: var(--muted);
}

.empty-list.error {
    color: #d32f2f;
}

/* File Preview */
.file-preview-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;  /* Don't compress */
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--panel-soft);
    border-bottom: 1px solid var(--border);
}

.preview-header h3 {
    margin: 0;
    font-size: 14px;
}

.preview-meta {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--muted);
    background: #f9fbfd;
    border-bottom: 1px solid var(--border);
}

.file-preview-content {
    margin: 0;
    padding: 16px;
    max-height: 300px;  /* Increased for better visibility */
    overflow: auto;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 12px;
    font-family: 'Monaco', 'Consolas', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Upload Section */
.upload-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    background: var(--panel-soft);
    flex-shrink: 0;  /* Don't compress */
}

.upload-section h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
}

.upload-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.upload-path {
    flex: 1;
    min-width: 150px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
}

.upload-path:focus {
    outline: none;
    border-color: var(--accent);
}

/* Compact button variant */
.btn-compact {
    padding: 6px 12px;
    font-size: 12px;
}

