html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: #0f0f1a;
    color: #e2e8f0;
    overflow: hidden;
    height: 100%;
}

/* Glassmorphism card effect */
.glass-card {
    background: rgba(26, 26, 46, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    transition: all 0.3s ease;
}

.glass-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

/* ============================
   3-Panel Portal Layout
   ============================ */
.portal-layout {
    display: flex;
    height: 100%;
    gap: 0;
}

.portal-insights {
    width: 300px;
    min-width: 260px;
    max-width: 340px;
    display: flex;
    flex-direction: column;
    background: rgba(26, 26, 46, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.portal-keywords {
    width: 280px;
    min-width: 240px;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    background: rgba(26, 26, 46, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
}

.portal-left {
    width: 380px;
    min-width: 320px;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    background: rgba(26, 26, 46, 0.5);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.portal-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 300px;
    position: relative;
}

.portal-right {
    width: 380px;
    min-width: 340px;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    background: rgba(26, 26, 46, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
}

.portal-right.collapsed {
    width: 0;
    min-width: 0;
    max-width: 0;
    border-left: none;
    opacity: 0;
    overflow: hidden;
}

.portal-header {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Leaflet map container */
.map-container {
    width: 100%;
    height: 100%;
    min-height: 400px;
}

/* Chat panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

/* Leaflet zoom control — ensure visible below app bar */
.leaflet-top.leaflet-left {
    top: 10px;
    left: 10px;
}

/* Push Leaflet attribution to avoid overlap */
.leaflet-bottom {
    bottom: 0;
}

/* Quick questions in left panel */
.quick-questions-section {
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.quick-questions-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.5;
    margin-bottom: 6px;
}

.quick-question-pill {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid color-mix(in srgb, var(--qc) 20%, transparent);
    color: var(--qc);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-family: inherit;
    text-align: left;
    line-height: 1.35;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    width: 100%;
    display: block;
    margin-bottom: 4px;
}

.quick-question-pill:hover {
    background: color-mix(in srgb, var(--qc) 10%, rgba(26, 26, 46, 0.95));
    border-color: color-mix(in srgb, var(--qc) 45%, transparent);
}

/* ============================
   Keyword List (vertical bar chart)
   ============================ */
.keyword-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.keyword-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.keyword-row-label {
    width: 90px;
    min-width: 90px;
    font-size: 0.7rem;
    font-weight: 500;
    color: #e2e8f0;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.keyword-row-bar-track {
    flex: 1;
    height: 14px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 3px;
    overflow: hidden;
}

.keyword-row-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
    min-width: 3px;
}

.keyword-row-score {
    width: 32px;
    min-width: 32px;
    font-size: 0.62rem;
    font-weight: 600;
    opacity: 0.6;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ============================
   Map / Table Tabs
   ============================ */
.center-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    background: rgba(26, 26, 46, 0.4);
    backdrop-filter: blur(10px);
}

.center-tab {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.78rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    border: none;
    background: transparent;
    color: rgba(226, 232, 240, 0.5);
    transition: all 0.2s ease;
    font-family: inherit;
    border-bottom: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.center-tab:hover {
    color: rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.03);
}

.center-tab.active {
    color: var(--tab-color, #e2e8f0);
    border-bottom-color: var(--tab-color, #e2e8f0);
    background: rgba(255, 255, 255, 0.04);
}

.center-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* ============================
   Location Table
   ============================ */
.location-table-wrap {
    height: 100%;
    overflow-y: auto;
    padding: 8px;
}

.location-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.75rem;
}

.location-table thead th {
    position: sticky;
    top: 0;
    background: rgba(15, 15, 26, 0.95);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(226, 232, 240, 0.5);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    z-index: 1;
}

.location-table thead th:hover {
    color: rgba(226, 232, 240, 0.8);
}

.location-table thead th .sort-arrow {
    font-size: 0.6rem;
    margin-left: 3px;
    opacity: 0.6;
}

.location-table tbody tr {
    cursor: pointer;
    transition: background 0.15s ease;
}

.location-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

.location-table tbody tr.selected {
    background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.location-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    vertical-align: middle;
}

.prediction-badge {
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 8px;
    white-space: nowrap;
    font-weight: 500;
}

/* ============================
   Detail Panel (Right)
   ============================ */
.detail-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.detail-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.detail-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    opacity: 0.35;
    text-align: center;
    padding: 32px;
    gap: 12px;
}

.prediction-display {
    text-align: center;
    padding: 16px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.prediction-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.prediction-label {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-top: 8px;
}

/* Detail panel section title */
.section-title {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.4;
    margin-bottom: 10px;
}

/* Knowledge support section */
.knowledge-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.knowledge-text {
    font-size: 0.72rem;
    line-height: 1.6;
    opacity: 0.8;
}

/* ============================
   Source Confidence Bars
   ============================ */
.source-confidence {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}

.source-confidence-bar {
    height: 4px;
    border-radius: 2px;
    max-width: 80px;
    min-width: 3px;
}

.source-confidence-label {
    font-size: 0.58rem;
    opacity: 0.45;
}

/* ============================
   Pulse animation for selected marker
   ============================ */
@keyframes marker-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.8; }
}

/* ============================
   Top bar (white, on every page)
   ============================ */
.mud-appbar.top-bar {
    background: #ffffff;
    color: #0f1f3d;
    border-bottom: 1px solid #e7e2d9;
}

.top-brand {
    color: #0f1f3d;
    text-decoration: none;
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: 0.18em;
}

.top-sub {
    margin-left: 0.6rem;
    font-weight: 400;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
    color: #64748b;
}

.top-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    color: #334155;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.top-link:hover { background: #f1efe9; color: #0f1f3d; }
.top-brand:focus-visible, .top-link:focus-visible { outline: 2px solid #0f766e; outline-offset: 2px; }

/* ============================
   Landing page (light)
   ============================ */
.home {
    height: 100%;
    overflow-y: auto;
    background: #fbf9f5;
    color: #475569;
}

.home-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 2rem;
    box-sizing: border-box;
}

.home-eyebrow {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #0f766e;
}

.home-title {
    margin: 0;
    font-size: clamp(2rem, 5vw, 3.4rem);
    line-height: 1.08;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #0f1f3d;
    max-width: 16ch;
}

/* FocusOnNavigate focuses the h1 on load; it is not interactive, so no ring. */
.home-title:focus { outline: none; }

.home-lead {
    margin: 1rem 0 2rem;
    max-width: 52ch;
    font-size: 1.1rem;
    line-height: 1.55;
    color: #475569;
}

.home-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    background: #ffffff;
    border: 1px solid #e7e2d9;
    border-radius: 14px;
    box-shadow: 0 2px 10px rgba(15, 31, 61, 0.05);
    overflow: hidden;
}

.home-card-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.9rem;
    padding: 1.75rem;
}

.home-card-title {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: #0f1f3d;
    line-height: 1.2;
}

.home-card-title.small { font-size: 1.3rem; }

.home-card-desc {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.home-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
}

.home-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.home-pill.available { background: #dcf3ea; color: #0f6b52; }
.home-pill.dev { background: #fdf0d8; color: #92580a; }

.home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: auto;
    padding: 0.75rem 1.4rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
}

.home-btn.primary { background: #0f766e; color: #ffffff; }
.home-btn.primary:hover { background: #0b5f58; }
.home-btn.primary:focus-visible { outline: 2px solid #0f1f3d; outline-offset: 2px; }
.home-btn.disabled { background: #e5e7eb; color: #6b7280; cursor: not-allowed; font-weight: 500; }

.home-art {
    position: relative;
    margin: 0;
    min-height: 220px;
    background: #f3f1ea;
}

.home-art img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.home-art-tag {
    position: absolute;
    right: 10px;
    bottom: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.85);
    color: #64748b;
    font-size: 0.7rem;
}

.home-feature { min-height: 280px; }
.home-feature .home-btn { margin-top: 0.5rem; }
.home-feature + .home-feature { margin-top: 1rem; }

.home-section-title {
    margin: 2.5rem 0 1rem;
    font-size: 1.6rem;
    font-weight: 700;
    color: #0f1f3d;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
}

.home-small { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.home-small .home-card-text { padding: 1.4rem; }


/* Desktop: a compact block centred in the window (horizontally and vertically), as on the previous home
   page. Cards keep their natural size; sizes shrink a little on short windows so the page fits without
   scrolling, and only a very short window scrolls. */
@media (min-width: 821px) {
    .home-inner {
        min-height: 100%;
        max-width: 1080px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: clamp(0.75rem, 3vh, 2rem) 1.5rem;
    }
    .home-hero { text-align: center; }
    .home-eyebrow { margin-bottom: 0.25rem; }
    .home-title { font-size: clamp(1.7rem, 5vh, 3rem); max-width: none; }
    .home-lead { max-width: 60ch; margin: 0.5rem auto clamp(1rem, 3vh, 2rem); font-size: clamp(0.92rem, 2vh, 1.1rem); }
    .home-feature { min-height: clamp(200px, 30vh, 280px); }
    .home-section-title { text-align: center; margin: clamp(1rem, 3.5vh, 2rem) 0 clamp(0.5rem, 1.5vh, 1rem); font-size: clamp(1.1rem, 2.8vh, 1.4rem); }
    .home-small { min-height: clamp(160px, 22vh, 210px); grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
    .home-card-text { gap: clamp(0.35rem, 1.2vh, 0.8rem); padding: clamp(0.9rem, 2.8vh, 1.75rem) 1.5rem; }
    .home-small .home-card-text { padding: clamp(0.75rem, 2.2vh, 1.4rem) 1.25rem; }
    .home-card-title { font-size: clamp(1.25rem, 3.3vh, 1.7rem); }
    .home-card-title.small { font-size: clamp(1.05rem, 2.4vh, 1.25rem); }
    .home-card-desc { font-size: clamp(0.85rem, 1.9vh, 0.95rem); }
    .home-pill { padding: 0.15rem 0.7rem; }
    .home-btn { padding: clamp(0.4rem, 1.3vh, 0.7rem) 1.2rem; font-size: clamp(0.9rem, 2vh, 1rem); }
    .home-feature .home-btn { margin-top: 0.25rem; }
    .home-art { min-height: 0; }
}

@media (max-width: 820px) {
    .home-card, .home-small { grid-template-columns: 1fr; }
    .home-art { min-height: 170px; order: -1; }
    .home-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .home-inner { padding: 1.5rem 16px; }
    .top-link-text { display: none; }
}

/* ============================
   Mobile Responsiveness
   ============================ */

/* Bottom tab bar — only shown on mobile */
.mobile-tab-bar {
    display: none;
}

/* Mobile-hidden class — hides a panel on mobile when not active */
.mobile-hidden {
    display: flex; /* default: visible on desktop */
}

/* Hide nav icons in AppBar on very small screens */
@media (max-width: 480px) {
    .hide-on-mobile {
        display: none !important;
    }
}

@media (max-width: 767px) {
    /* Keywords and Insights panels hidden on mobile — controlled via mobile-hidden class instead */

    /* Landing page and portal main content scrollable on mobile */
    .mud-main-content {
        overflow-y: auto !important;
        height: auto !important;
        min-height: calc(100dvh - 48px) !important;
    }

    /* Allow scroll on mobile */
    html, body {
        overflow: auto;
        height: auto;
    }

    /* Portal layout scrolls vertically on mobile (panels stack) */
    .portal-layout {
        flex-direction: column;
        height: auto;
        min-height: calc(100dvh - 48px - 56px);
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 56px; /* space for tab bar */
    }

    /* Each panel takes full width & stacks on mobile */
    .portal-left,
    .portal-right,
    .portal-keywords,
    .portal-insights {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        min-height: calc(100dvh - 48px - 56px);
        height: auto;
        border: none;
        border-bottom: 1px solid rgba(255,255,255,0.06);
    }

    /* Portal-center (map panel) needs fixed height so Leaflet can fill it */
    .portal-center {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: calc(100dvh - 48px - 56px) !important;
        min-height: 0 !important;
        overflow: hidden;
        border: none;
        border-bottom: 1px solid rgba(255,255,255,0.06);
    }

    .center-content {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Map container grows to fill center-content via flex:1 (reliable measured height for Leaflet) */
    .map-container {
        flex: 1 !important;
        height: auto !important;
        min-height: 0 !important;
    }

    /* Table view also needs flex:1 so it fills center-content */
    .location-table-wrap {
        flex: 1 !important;
        height: auto !important;
    }

    /* Hide inactive panels on mobile */
    .mobile-hidden {
        display: none !important;
    }

    /* Right panel: override collapse transition on mobile */
    .portal-right.collapsed {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        opacity: 1;
    }

    /* Bottom tab bar */
    .mobile-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 56px;
        background: rgba(15, 15, 26, 0.97);
        backdrop-filter: blur(12px);
        border-top: 1px solid rgba(255,255,255,0.08);
        z-index: 100;
    }

    .mobile-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: none;
        background: transparent;
        color: rgba(226, 232, 240, 0.45);
        font-family: inherit;
        font-size: 0.65rem;
        font-weight: 500;
        cursor: pointer;
        transition: color 0.2s;
        padding: 4px 0;
    }

    .mobile-tab .mobile-tab-icon {
        font-size: 1.2rem;
        line-height: 1;
    }

    .mobile-tab.active {
        color: var(--qc, #818cf8);
    }

}

@media (min-width: 768px) and (max-width: 1023px) {
    /* Tablet: hide right panel behind overlay, keep left+center */
    .portal-right {
        position: absolute;
        right: 0;
        top: 0;
        height: 100%;
        z-index: 10;
        box-shadow: -4px 0 24px rgba(0,0,0,0.4);
    }
}

/* Blazor error UI */
#blazor-error-ui {
    background: #b32121;
    color: white;
    padding: 0.6rem 1.2rem;
    display: none;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 9999;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

/* Leaflet marker overrides */
.custom-marker {
    background: none !important;
    border: none !important;
}

/* ============================
   Featured Insights (Left Panel)
   ============================ */
.left-insights {
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.left-insights-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    opacity: 0.5;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.left-insight-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.left-insight-card:hover {
    background: color-mix(in srgb, var(--qc) 8%, rgba(26, 26, 46, 0.9));
    border-color: color-mix(in srgb, var(--qc) 30%, transparent);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.insight-icon {
    font-size: 1.4rem;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 2px;
}

.insight-body {
    flex: 1;
    min-width: 0;
}

.insight-question {
    font-weight: 600;
    font-size: 0.72rem;
    color: var(--qc);
    margin-bottom: 4px;
    line-height: 1.3;
}

.insight-summary {
    font-size: 0.66rem;
    opacity: 0.55;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.insight-meta {
    font-size: 0.6rem;
    opacity: 0.3;
    margin-top: 6px;
}