/* ═══════════════════════════════════════════════════════════════════════════
   UBC Weather — Home Page (NWS-style national overview)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Page shell ─────────────────────────────────────────────────────────── */
.page-home {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── National stats bar ─────────────────────────────────────────────────── */
#home-stats-bar {
    display: flex;
    align-items: center;
    gap: .1rem;
    padding: 0 1rem;
    height: 42px;
    flex-shrink: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: .77rem;
    overflow-x: auto;
    scrollbar-width: none;
}
#home-stats-bar::-webkit-scrollbar { display: none; }

.hstat {
    display: flex;
    align-items: center;
    gap: .3rem;
    padding: .2rem .65rem;
    border-radius: var(--r-xs);
    white-space: nowrap;
    flex-shrink: 0;
}
.hstat-count { font-weight: 800; font-size: .88rem; font-variant-numeric: tabular-nums; }
.hstat-label { color: var(--muted); font-size: .68rem; }
.hstat-sep   { width: 1px; height: 22px; background: var(--border-md); flex-shrink: 0; margin: 0 .35rem; }
.hstat-dot   { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

#hstat-total     .hstat-count { color: var(--text); }
.hstat-extreme   .hstat-dot  { background: var(--extreme); }
.hstat-extreme   .hstat-count{ color: var(--extreme); }
.hstat-severe    .hstat-dot  { background: var(--severe); }
.hstat-severe    .hstat-count{ color: var(--severe); }
.hstat-moderate  .hstat-dot  { background: var(--moderate); }
.hstat-moderate  .hstat-count{ color: var(--moderate); }
.hstat-minor     .hstat-dot  { background: var(--minor); }
.hstat-minor     .hstat-count{ color: var(--minor); }

.hstat-updated {
    margin-left: auto;
    color: var(--muted);
    font-size: .67rem;
    white-space: nowrap;
    flex-shrink: 0;
    padding-left: .75rem;
}

/* ── Main content split ─────────────────────────────────────────────────── */
#home-content {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}

/* ── Map column ─────────────────────────────────────────────────────────── */
#home-map-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

#home-map-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: .55rem 1rem .4rem;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}
#home-map-header h1 {
    font-size: .9rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}
.map-hint {
    font-size: .72rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.map-hint i { font-size: .68rem; }

#home-map {
    flex: 1;
    min-height: 0;
    background: var(--bg2);
}

/* ── Map legend ─────────────────────────────────────────────────────────── */
#home-map-legend {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .35rem 1rem;
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    font-size: .67rem;
    overflow-x: auto;
    scrollbar-width: none;
}
#home-map-legend::-webkit-scrollbar { display: none; }
.ml-item { display: flex; align-items: center; gap: .3rem; white-space: nowrap; color: var(--text-dim); }
.ml-dot  { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.ml-extreme  .ml-dot { background: #dc2626; }
.ml-severe   .ml-dot { background: #ea580c; }
.ml-moderate .ml-dot { background: #d97706; }
.ml-minor    .ml-dot { background: #16a34a; }
.ml-none     .ml-dot { background: #1f3450; border: 1px solid rgba(255,255,255,.18); }

/* ── Territory inset control (Leaflet bottomleft) ───────────────────────── */
.terr-panel {
    background: rgba(8, 18, 30, 0.92);
    border: 1px solid var(--border-md);
    border-radius: var(--r-sm);
    padding: .45rem .55rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    min-width: 118px;
}
.terr-panel-title {
    font-size: .58rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: .35rem;
    padding-bottom: .25rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.terr-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .22rem;
}
.terr-box {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    background: var(--surface2);
    border: 1px solid var(--border-md);
    border-radius: var(--r-xs);
    font-size: .65rem;
    font-weight: 800;
    color: var(--text-dim);
    cursor: pointer;
    transition: opacity .12s, transform .1s;
    user-select: none;
    letter-spacing: .02em;
}
.terr-box:hover { opacity: .82; transform: scale(1.06); }
.terr-box.sev-extreme  { background: #7f1d1d; border-color: #dc2626; color: #fca5a5; }
.terr-box.sev-severe   { background: #7c2d12; border-color: #ea580c; color: #fdba74; }
.terr-box.sev-moderate { background: #78350f; border-color: #d97706; color: #fcd34d; }
.terr-box.sev-minor    { background: #14532d; border-color: #16a34a; color: #86efac; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
#home-sidebar {
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-md);
    overflow: hidden;
    background: var(--bg2);
}

/* ── Panels ─────────────────────────────────────────────────────────────── */
.home-panel           { border-bottom: 1px solid var(--border); flex-shrink: 0; }
.home-panel-alerts    { flex: 1 1 0; min-height: 80px; overflow: hidden; display: flex; flex-direction: column; }
.home-panel-eas       { flex: 0 1 auto; max-height: 210px; overflow: hidden; display: flex; flex-direction: column; }

.home-panel-title {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .85rem;
    font-size: .72rem;
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: .02em;
    text-transform: uppercase;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.home-panel-title i { color: var(--accent-lt); font-size: .72rem; }
.panel-count {
    font-size: .7rem;
    font-weight: 800;
    color: var(--accent-lt);
    background: var(--surface2);
    border: 1px solid var(--border-a);
    padding: .06rem .4rem;
    border-radius: 999px;
}
.hpt-link {
    margin-left: auto;
    font-size: .67rem;
    color: var(--accent-lt);
    text-decoration: none;
    white-space: nowrap;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}
.hpt-link i { font-size: .6rem; }
.hpt-link:hover { text-decoration: underline; }

/* ── Quick links ────────────────────────────────────────────────────────── */
.home-quicklinks {
    display: flex;
    gap: .5rem;
    padding: .6rem .85rem;
}
.hql {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .28rem;
    padding: .5rem .35rem;
    background: var(--surface2);
    border: 1px solid var(--border-md);
    border-radius: var(--r-sm);
    color: var(--text-dim);
    font-size: .65rem;
    font-weight: 600;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: .04em;
    transition: background .14s, color .14s, border-color .14s;
    text-align: center;
}
.hql i  { font-size: 1.05rem; color: var(--accent-lt); transition: color .14s; }
.hql:hover { background: var(--surface3); color: var(--text); border-color: var(--border-a); text-decoration: none; }
.hql:hover i { color: var(--text); }

/* ── NWS Alert cards ────────────────────────────────────────────────────── */
#home-alerts-list {
    flex: 1;
    overflow-y: auto;
    padding: .4rem .5rem;
    display: flex;
    flex-direction: column;
    gap: .28rem;
}

.home-alert-card {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    padding: .5rem .6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background .13s, border-color .13s;
}
.home-alert-card:hover { background: var(--surface2); border-color: var(--border-a); }
.hac-body  { flex: 1; min-width: 0; }
.hac-event { font-size: .77rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hac-area  { font-size: .67rem; color: var(--muted); margin-top: .06rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hac-time  { font-size: .62rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; padding-top: .05rem; }

.home-panel-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .5rem;
    font-size: .7rem;
    color: var(--accent-lt);
    background: var(--surface);
    border-top: 1px solid var(--border);
    text-decoration: none;
    transition: background .13s;
    flex-shrink: 0;
}
.home-panel-more:hover { background: var(--surface2); text-decoration: none; }
.home-panel-more i { font-size: .62rem; }

/* ── EAS compact cards (home sidebar) ──────────────────────────────────── */
#home-eas-list {
    flex: 1;
    overflow-y: auto;
    padding: .35rem .5rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.home-eas-card {
    display: flex;
    align-items: flex-start;
    gap: .45rem;
    padding: .45rem .55rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}
.hec-body    { flex: 1; min-width: 0; }
.hec-type    { font-size: .75rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hec-station { font-size: .67rem; color: var(--muted); margin-top: .04rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hec-time    { font-size: .62rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; padding-top: .05rem; }
.hec-audio   { margin-top: .3rem; }

/* ── Leaflet overrides for home map ─────────────────────────────────────── */
#home-map .leaflet-container { background: var(--bg); cursor: pointer; }
#home-map .leaflet-control-zoom a        { background: var(--surface2) !important; color: var(--text) !important; border-color: var(--border-md) !important; }
#home-map .leaflet-control-zoom a:hover  { background: var(--surface3) !important; }
#home-map .leaflet-control-attribution   { background: rgba(8,18,30,.7) !important; color: var(--muted) !important; font-size: .6rem !important; }
#home-map .leaflet-control-attribution a { color: var(--accent-lt) !important; }
#home-map .leaflet-tooltip {
    background: var(--surface) !important;
    border: 1px solid var(--border-md) !important;
    color: var(--text) !important;
    border-radius: var(--r-xs) !important;
    font-size: .75rem;
    padding: .3rem .55rem;
    box-shadow: var(--shadow-sm) !important;
    pointer-events: none;
}

/* ── Breaking Alerts Crawler ────────────────────────────────────────────── */
#alert-crawler {
    display: flex;
    align-items: center;
    height: 30px;
    flex-shrink: 0;
    background: rgba(220, 38, 38, 0.12);
    border-bottom: 1px solid rgba(220, 38, 38, 0.28);
    overflow: hidden;
    position: relative;
}
#alert-crawler[hidden] { display: none; }

.crawler-label {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: 0 .75rem 0 .9rem;
    height: 100%;
    background: var(--extreme);
    color: #fff;
    font-size: .65rem;
    font-weight: 900;
    letter-spacing: .10em;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
    clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%);
    padding-right: 1.1rem;
}
.crawler-label i { font-size: .7rem; }

.crawler-stage {
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
}

.crawler-track {
    display: flex;
    align-items: center;
    gap: 0;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    white-space: nowrap;
    will-change: transform;
    animation: crawl linear infinite;
    animation-play-state: running;
}
.crawler-track:hover { animation-play-state: paused; }

@keyframes crawl {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

.crawler-item {
    display: inline-flex;
    align-items: center;
    gap: .42rem;
    padding: 0 1.2rem 0 .8rem;
    font-size: .7rem;
    cursor: pointer;
    color: var(--text-dim);
    border-right: 1px solid rgba(255,255,255,.08);
    height: 100%;
    transition: color .12s;
    -webkit-tap-highlight-color: transparent;
}
.crawler-item:hover { color: var(--text); }

.crawler-item .severity-badge {
    font-size: .58rem;
    padding: .06rem .32rem;
    flex-shrink: 0;
}
.crawler-event {
    font-weight: 700;
    color: var(--text);
}
.crawler-area {
    color: var(--muted);
    font-size: .67rem;
}
.crawler-sep {
    display: inline-flex;
    align-items: center;
    padding: 0 .6rem;
    color: var(--extreme);
    font-size: .55rem;
    opacity: .6;
    flex-shrink: 0;
}

/* ── Territory inset mini-maps (large screens only) ─────────────────────── */
.inset-maps-panel {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    background: rgba(8, 18, 30, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--r-md);
    padding: .45rem .5rem .4rem;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: 0 4px 24px rgba(0,0,0,.6), 0 1px 4px rgba(0,0,0,.4);
}

.inset-row {
    display: flex;
    gap: .35rem;
}

.inset-item {
    display: flex;
    flex-direction: column;
    gap: .18rem;
    cursor: pointer;
    border-radius: var(--r-xs);
    transition: opacity .13s;
}
.inset-item:hover { opacity: .82; }

/* Large insets — AK, HI, PR */
.inset-map-el {
    width: 110px;
    height: 70px;
    border-radius: var(--r-xs);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: var(--bg2);
    pointer-events: none;
}
.inset-lg .inset-map-el {
    width: 140px;
    height: 86px;
}

/* Leaflet inside inset: minimal chrome */
.inset-map-el .leaflet-container { background: var(--bg); cursor: default !important; }

.inset-name {
    font-size: .5rem;
    font-weight: 700;
    color: var(--muted);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: .07em;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Responsive: insets vs boxes vs nothing ─────────────────────────────── */
/* Large (> 900px): show insets, hide boxes */
@media (min-width: 901px) {
    .terr-panel { display: none; }
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    /* Layout: single column, natural page scroll */
    .page-home    { overflow: visible; }
    #home-content { flex-direction: column; overflow: visible; }

    /* Map: fixed height slab, not stretchy */
    #home-map-col { flex: 0 0 260px; min-height: 260px; overflow: hidden; }

    /* Sidebar: full height, no inner scroll trap */
    #home-sidebar {
        flex: 0 0 auto;
        border-left: none;
        border-top: 1px solid var(--border-md);
        max-height: none;
        overflow: visible;
        background: var(--bg2);
    }

    /* Panel overflow: allow natural height */
    .home-panel-alerts { overflow: visible; max-height: none; }
    .home-panel-eas    { max-height: none; overflow: visible; }
    #home-alerts-list  { overflow: visible; max-height: none; }
    #home-eas-list     { overflow: visible; max-height: none; }
    #home-cam-list     { max-height: none; overflow: visible; }

    /* Hide inset mini-maps, show territory boxes */
    .inset-maps-panel { display: none; }

    /* ── Quick access: 4-up grid with proper touch targets ── */
    .home-quicklinks {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: .55rem;
        padding: .75rem;
    }
    .hql {
        padding: .85rem .3rem;
        min-height: 72px;
        border-radius: var(--r-md);
        font-size: .7rem;
        gap: .38rem;
    }
    .hql i    { font-size: 1.35rem; }
    .hql span { display: block !important; }
}

@media (max-width: 500px) {
    .map-hint { display: none; }

    /* ── Map: slightly shorter on small phones ── */
    #home-map-col { flex: 0 0 220px; min-height: 220px; }

    /* ── Quick access: 2×2 grid — big thumb-friendly tiles ── */
    .home-quicklinks {
        grid-template-columns: repeat(2, 1fr);
        gap: .6rem;
        padding: .75rem;
    }
    .hql {
        min-height: 84px;
        padding: 1rem .5rem;
        border-radius: var(--r-md);
        font-size: .74rem;
        gap: .42rem;
    }
    .hql i    { font-size: 1.6rem; }
    .hql span { display: block !important; font-size: .72rem; }

    /* Territory boxes and insets hidden on tiny screens */
    .terr-panel       { display: none; }
    .inset-maps-panel { display: none; }
}

/* ── Live Cams panel (home sidebar) ────────────────────────────────────── */
.home-panel-livecams { flex-shrink: 0; }

#home-cam-list {
    padding: .3rem .5rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
    max-height: 110px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-md) transparent;
}

.home-cam-card {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .26rem .45rem;
    border-radius: var(--r-xs);
    font-size: .72rem;
    color: var(--text-dim);
    background: rgba(255,255,255,.03);
    border: 1px solid var(--border);
    transition: background .1s;
}
.home-cam-card:hover { background: rgba(255,255,255,.07); }

.hcc-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #ef4444;
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.hcc-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
    font-size: .72rem;
}
.hcc-type {
    font-size: .58rem;
    font-family: var(--mono);
    color: var(--muted);
    flex-shrink: 0;
}
