@font-face {
    font-family: 'Work Sans';
    src: url("../fonts/WorkSans.eec91aaffb70.ttf") format('truetype');
    font-weight: 100 900;
    font-display: swap;
}

:root {
    --sidebar-width: 230px;
    --topbar-height: 52px;
    --border-color: #d9d9d9;
    --text-color: #222;
    --muted-color: #666;
    --link-color: #0b5fa5;
    --bg-color: #fff;
    --sidebar-bg: #f5f5f3;
    --heading-bg: #ececea;
    --current-bg: #eaf3ea;
    --future-bg: #fdf6e3;
    --max-content-width: 900px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--text-color);
    background: var(--bg-color);
    line-height: 1.45;
}

a { color: var(--link-color); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin-top: 2rem; }
h3 { font-size: 1.05rem; }

.sidebar-toggle-checkbox { display: none; }

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

/* -- sidebar --------------------------------------------------------- */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 1.25rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.sidebar-logo {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-color);
}

.sidebar-collapse-btn,
.sidebar-expand-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--muted-color);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1.2;
    padding: 0.15rem 0.5rem;
}

.sidebar-collapse-btn:hover,
.sidebar-expand-btn:hover {
    background: var(--heading-bg);
}

.sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 25;
    background: var(--sidebar-bg);
}

body.sidebar-collapsed .sidebar-expand-btn { display: block; }

.sidebar-close-btn {
    display: none;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--muted-color);
}

.sidebar-backdrop {
    display: none;
}

.sidebar ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar li { margin-bottom: 0.6rem; }

.sidebar-social {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.9rem;
}

/* -- topbar (mobile only) --------------------------------------------- */

.topbar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    height: var(--topbar-height);
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    position: sticky;
    top: 0;
    z-index: 20;
}

.menu-button {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    color: var(--text-color);
}

.topbar .site-title {
    font-weight: 700;
    color: var(--text-color);
    font-size: 1.1rem;
}

/* -- content ------------------------------------------------------------ */

.content {
    /* flex-basis: auto (not the "flex: 1" shorthand's 0%) so an explicit height, like
       .page-home sets below, isn't overridden by flex-grow's basis calculation. */
    flex: 1 1 auto;
    min-width: 0;
    padding: 1.5rem 2rem 3rem;
}

.content-inner {
    max-width: var(--max-content-width);
}

.page-home .content {
    padding: 0;
    height: 100vh;
    position: relative;
}

/* -- map ------------------------------------------------------------- */

/* Full-bleed map (home/contested pages only) -- the small inline map embedded on the
   district detail page keeps normal document flow so it doesn't overlap page content. */
.page-home #map { position: absolute; inset: 0; }

.map-info-panel {
    position: absolute;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    right: 1rem;
    width: 320px;
    max-width: calc(100% - 2rem);
    max-height: calc(100% - 2rem);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.map-info-panel.hidden { display: none; }

.map-info-panel h3 { margin-top: 0; }

.map-info-close {
    position: absolute;
    top: 0.4rem;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--muted-color);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}

.map-info-close:hover { color: var(--text-color); }

#map-info-panel-body { padding-right: 1.25rem; }

#geocoder-container > div {
    min-width: 50%;
    margin-left: 25%;
}

/* -- tables and data blocks -------------------------------------------- */

table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.75rem 0 1.5rem;
    font-size: 0.95rem;
}

th, td {
    border: 1px solid var(--border-color);
    padding: 0.45rem 0.6rem;
    text-align: left;
}

th { background: var(--heading-bg); }

tr.term-current { background: var(--current-bg); }
tr.term-future { background: var(--future-bg); }

/* Fixed District column width, so a page listing many of these tables back to back (e.g. one
   per ANC on the district list) keeps District/Commissioner lined up from one table to the
   next, instead of each table auto-sizing its columns to its own widest content. */
.district-table { table-layout: fixed; }
.district-table th:first-child,
.district-table td:first-child {
    width: 7rem;
    white-space: nowrap;
}

.breadcrumbs {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--muted-color);
}

.view-tabs {
    display: flex;
    gap: 0.5rem;
    margin: 1rem 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.view-tab {
    padding: 0.5rem 0.9rem;
    color: var(--muted-color);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.view-tab:hover { color: var(--text-color); text-decoration: none; }

.view-tab.active {
    color: var(--text-color);
    font-weight: 600;
    border-bottom-color: var(--link-color);
}

.view-tab-separator {
    align-self: center;
    color: var(--muted-color);
}

.status-group { margin-bottom: 1.25rem; }
.status-group h3 { margin-bottom: 0.4rem; }

.tag {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    background: var(--heading-bg);
    color: var(--muted-color);
    margin-left: 0.4rem;
}

.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { margin-bottom: 0.35rem; }

.card-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }

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

/* -- forms ------------------------------------------------------------- */

.form-field { margin-bottom: 1rem; }
.form-field label { display: block; font-weight: 600; margin-bottom: 0.3rem; }

.form-field input[type="text"],
.form-field input[type="email"],
.form-field select,
.form-field textarea {
    width: 100%;
    max-width: 480px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font: inherit;
}

button[type="submit"] {
    background: var(--link-color);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0.6rem 1.25rem;
    font-size: 1rem;
    cursor: pointer;
}

button[type="submit"]:hover { opacity: 0.9; }

/* -- responsive: collapse sidebar behind a hamburger on small screens --- */

@media (min-width: 821px) {
    body.sidebar-collapsed .sidebar {
        width: 0;
        padding: 0;
        border-right: none;
        overflow: hidden;
    }
}

@media (max-width: 820px) {
    /* The mobile hamburger menu already hides/shows the sidebar; the desktop collapse
       button and its floating "show sidebar" counterpart don't apply here. */
    .sidebar-collapse-btn, .sidebar-expand-btn { display: none; }
    .sidebar-close-btn { display: block; }

    .topbar { display: flex; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.18s ease;
        z-index: 30;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.15);
    }

    .sidebar-toggle-checkbox:checked ~ .layout .sidebar {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: 29;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.18s ease;
    }

    .sidebar-toggle-checkbox:checked ~ .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    /* The topbar sits outside .layout and adds its own height above it, so .layout's
       height budget has to leave room for it or the page overflows by topbar-height. */
    .layout { flex-direction: column; min-height: calc(100vh - var(--topbar-height)); }

    .content { padding: 1.25rem 1.25rem 2.5rem; }

    .page-home .content {
        height: calc(100vh - var(--topbar-height));
        height: calc(100dvh - var(--topbar-height));
    }

    .map-info-panel {
        width: calc(100% - 2rem);
        /* Extra clearance beyond the safe-area inset: some mobile browsers (e.g. Orion)
           draw their own bottom URL/tab bar without reporting it via env(safe-area-inset-*)
           or shrinking the page's dvh, so a plain safe-area offset still gets covered. */
        bottom: calc(3rem + env(safe-area-inset-bottom, 0px));
        max-height: calc(100% - 4.5rem);
    }
}
