:root {
    --ink: #16211d;
    --muted: #66736e;
    --surface: #ffffff;
    --surface-soft: #f5f7f6;
    --line: #dce4e0;
    --brand: #126348;
    --brand-dark: #0b4431;
    --brand-soft: #e9f3ef;
    --accent: #bc8b2c;
    --danger: #9b3434;
    --shadow: 0 14px 34px rgba(22, 33, 29, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--surface-soft);
}

a { color: inherit; }
button, input { font: inherit; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.eyebrow {
    margin: 0 0 7px;
    color: var(--brand);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .11em;
    text-transform: uppercase;
}

.brand-mark {
    display: inline-grid;
    width: 68px;
    height: 68px;
    place-items: center;
    border-radius: 20px;
    background: var(--brand);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 900;
    letter-spacing: .04em;
    box-shadow: var(--shadow);
}

.brand-mark-small {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    font-size: .82rem;
    box-shadow: none;
}

/* Secure access */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        radial-gradient(circle at 10% 20%, rgba(18, 99, 72, .12), transparent 34rem),
        radial-gradient(circle at 90% 85%, rgba(188, 139, 44, .10), transparent 28rem),
        var(--surface-soft);
}

.login-shell {
    width: min(100%, 980px);
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 28px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-brand {
    min-height: 520px;
    padding: 58px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(150deg, #eff7f3, #fff 72%);
}

.login-brand h1 {
    max-width: 590px;
    margin: 12px 0 16px;
    font-size: clamp(2.25rem, 5vw, 4.2rem);
    line-height: .98;
    letter-spacing: -.055em;
}

.login-intro {
    max-width: 560px;
    margin: 0;
    color: var(--muted);
    font-size: 1.03rem;
    line-height: 1.7;
}

.login-card {
    padding: 58px 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-left: 1px solid var(--line);
}

.login-card h2 { margin: 0 0 28px; font-size: 1.9rem; }

.login-card label {
    display: block;
    margin: 14px 0 7px;
    font-size: .88rem;
    font-weight: 700;
}

.login-card input {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid #cbd6d1;
    border-radius: 11px;
    background: #fff;
    outline: none;
}

.login-card input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(18, 99, 72, .12);
}

.primary-button,
.ghost-button {
    border: 0;
    border-radius: 11px;
    cursor: pointer;
    font-weight: 750;
}

.primary-button {
    width: 100%;
    margin-top: 24px;
    padding: 14px;
    background: var(--brand);
    color: #fff;
}

.primary-button:hover { background: var(--brand-dark); }

.ghost-button {
    padding: 9px 13px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
}

.alert {
    padding: 11px 13px;
    border-radius: 10px;
    background: #fff1f1;
    color: var(--danger);
    font-size: .9rem;
}

.security-note {
    margin: 20px 0 0;
    color: var(--muted);
    font-size: .78rem;
    line-height: 1.5;
}

/* Directorate dashboard */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1100;
    min-height: 68px;
    padding: 10px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
}

.brand-lockup {
    display: flex;
    gap: 11px;
    align-items: center;
    text-decoration: none;
}

.brand-lockup strong,
.brand-lockup small { display: block; }

.brand-lockup strong { font-size: .95rem; }

.brand-lockup small {
    margin-top: 2px;
    color: var(--muted);
    font-size: .74rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.user-chip { text-align: right; }
.user-name, .user-role { display: block; }
.user-name { font-size: .86rem; font-weight: 750; }
.user-role { margin-top: 2px; color: var(--muted); font-size: .72rem; }

.app-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: calc(100vh - 68px);
}

.sidebar {
    position: sticky;
    top: 68px;
    align-self: start;
    height: calc(100dvh - 68px);
    max-height: calc(100dvh - 68px);
    padding: 22px 16px calc(22px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    border-right: 1px solid var(--line);
    background: var(--surface);
}

.nav-toggle { display: none; }

.nav-links { display: grid; gap: 4px; }

.nav-links a {
    padding: 10px 12px;
    border-radius: 10px;
    color: #48554f;
    text-decoration: none;
    font-size: .88rem;
    font-weight: 650;
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--brand-soft);
    color: var(--brand-dark);
}

.nav-group {
    margin: 0;
}

.nav-group summary {
    position: relative;
    padding: 10px 28px 10px 12px;
    border-radius: 10px;
    color: #48554f;
    cursor: pointer;
    list-style: none;
    font-size: .88rem;
    font-weight: 700;
}

.nav-group summary::-webkit-details-marker {
    display: none;
}

.nav-group summary::after {
    content: "▾";
    position: absolute;
    right: 11px;
    top: 50%;
    transform: translateY(-50%) rotate(-90deg);
    color: var(--muted);
    font-size: .7rem;
    transition: transform .15s ease;
}

.nav-group[open] summary::after {
    transform: translateY(-50%) rotate(0);
}

.nav-group summary:hover,
.nav-group[open] summary {
    background: var(--brand-soft);
    color: var(--brand-dark);
}

.nav-submenu {
    display: grid;
    gap: 1px;
    padding: 3px 0 4px 10px;
}

.nav-submenu a {
    padding: 7px 9px;
    font-size: .73rem;
    font-weight: 650;
}

.main-content {
    width: min(100%, 1500px);
    padding: 30px clamp(18px, 3vw, 42px) 72px;
}

.page-heading {
    display: flex;
    gap: 20px;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 22px;
}

.page-heading h1 {
    margin: 0;
    font-size: clamp(1.8rem, 3vw, 2.7rem);
    letter-spacing: -.035em;
}

.page-heading p:not(.eyebrow) {
    margin: 8px 0 0;
    color: var(--muted);
}

.system-status {
    padding: 8px 11px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-size: .76rem;
    font-weight: 750;
    white-space: nowrap;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric-card,
.panel {
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 4px 18px rgba(22, 33, 29, .035);
}

.metric-card {
    min-height: 142px;
    padding: 19px;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.metric-label {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
}

.metric-value {
    font-size: clamp(1.75rem, 3vw, 2.6rem);
    letter-spacing: -.04em;
}

.metric-card small { color: var(--muted); }

.panel {
    margin-top: 18px;
    padding: 22px;
    border-radius: var(--radius);
}

.panel-heading {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 18px;
}

.panel-heading h2 {
    margin: 0;
    font-size: 1.35rem;
}

.panel-heading p:not(.eyebrow) {
    max-width: 720px;
    margin: 7px 0 0;
    color: var(--muted);
    font-size: .88rem;
    line-height: 1.55;
}

.map-key {
    display: flex;
    flex-wrap: wrap;
    gap: 11px;
    color: var(--muted);
    font-size: .72rem;
}

.map-key span {
    display: flex;
    gap: 5px;
    align-items: center;
}

.key-dot {
    width: 9px;
    height: 9px;
    border-radius: 99px;
    display: inline-block;
}

.key-zero { background: #dbe3df; }
.key-low { background: #7db5a0; }
.key-high { background: #126348; }

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    min-height: 570px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 15px;
}

.nigeria-map {
    min-height: 570px;
    background: #eef2f0;
}

.state-panel {
    padding: 22px;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    background: #fbfcfb;
}

.state-panel h3 {
    margin: 0 0 8px;
    font-size: 1.3rem;
}

.state-panel > p:not(.eyebrow) {
    color: var(--muted);
    line-height: 1.55;
}

.state-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin: 18px 0;
}

.state-stat {
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
}

.state-stat strong,
.state-stat span { display: block; }

.state-stat strong { font-size: 1.18rem; }

.state-stat span {
    margin-top: 3px;
    color: var(--muted);
    font-size: .68rem;
}

.state-groups {
    display: grid;
    gap: 7px;
    margin-top: 14px;
}

.state-group {
    padding: 10px 11px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
}

.state-group strong {
    display: block;
    font-size: .82rem;
}

.state-group small { color: var(--muted); }
.map-fallback { padding: 14px; color: var(--muted); }

.search-box input {
    width: min(340px, 70vw);
    padding: 10px 13px;
    border: 1px solid #cbd6d1;
    border-radius: 11px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(18, 99, 72, .1);
}

.group-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.group-row {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfcfb;
}

.group-row h3 {
    margin: 0;
    font-size: .94rem;
}

.group-row .group-acronym {
    color: var(--muted);
    font-weight: 600;
}

.group-meta {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: .72rem;
}

.status-pill {
    padding: 3px 7px;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 800;
}

.empty-state {
    grid-column: 1 / -1;
    padding: 28px;
    text-align: center;
    color: var(--muted);
}

.leaflet-container { font: inherit; }

.leaflet-tooltip {
    border: 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .group-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .map-layout { grid-template-columns: 1fr; }
    .state-panel {
        border-left: 0;
        border-top: 1px solid var(--line);
    }
}

@media (max-width: 760px) {
    .topbar { padding: 9px 12px; }
    .brand-lockup strong { font-size: .8rem; }
    .brand-lockup small,
    .user-chip { display: none; }

    .app-shell { display: block; }

    .sidebar {
        position: fixed;
        top: 58px;
        right: 5px;
        left: 5px;
        z-index: 1300;
        width: auto;
        height: 0;
        max-height: none;
        padding: 0;
        border: 0;
        overflow: visible;
        background: transparent;
        pointer-events: none;
    }

    .nav-toggle {
        display: inline-block;
        padding: 7px 10px;
        border: 1px solid var(--line);
        border-radius: 9px;
        background: var(--surface);
    }

    .nav-links {
        display: none;
        max-height: calc(100dvh - 68px);
        margin-top: 7px;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-gutter: stable;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: rgba(255,255,255,.99);
        box-shadow: 0 16px 38px rgba(22,33,29,.16);
        pointer-events: auto;
    }
    .nav-links.open { display: grid; }

    .main-content { padding: 20px 12px 50px; }

    .page-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .metric-card {
        min-height: 122px;
        padding: 14px;
    }

    .panel { padding: 14px; }
    .panel-heading { flex-direction: column; }
    .nigeria-map { min-height: 470px; }
    .map-layout { min-height: auto; }
    .group-list { grid-template-columns: 1fr; }
    .search-box,
    .search-box input { width: 100%; }

    .login-shell { grid-template-columns: 1fr; }
    .login-brand {
        min-height: auto;
        padding: 34px 28px;
    }

    .login-card {
        padding: 34px 28px;
        border-left: 0;
        border-top: 1px solid var(--line);
    }
}

@media (max-width: 430px) {
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .metric-value { font-size: 1.75rem; }
    .state-stats { grid-template-columns: 1fr 1fr; }
}
