/* =============================================================================
   FLOWS - Regjistri i Digave te Vogla
   Design system ported from the FLOWS-CS-DS-15 prototype.

   Condition colours are ordinal (Good -> Critical) and are never the sole
   carrier of meaning: every badge pairs the colour with its label, and map
   markers additionally vary in shape, because the good/critical pair collapses
   under deuteranopia and fair/poor sit below the normal-vision separation floor.
   ============================================================================= */

:root {
    --paper: #E7EFEC;
    --paper-deep: #D7E4DE;
    --surface: #F7FAF8;
    --surface-alt: #EEF4F1;
    --ink: #122423;
    --ink-soft: #3C5956;
    --muted: #6C8582;
    --teal-deep: #0E3134;
    --teal: #1B5B5E;
    --teal-bright: #3AA39C;
    --line: #B6C7C1;
    --line-soft: #D6E2DC;
    --amber: #B67A22;
    --rust: #A23A2A;

    --good: #3D7A54;      --good-bg: #E3F0E7;      --good-ln: #BEE0C8;
    --fair: #A67A1E;      --fair-bg: #F4EDD9;      --fair-ln: #E4D5A5;
    --poor: #BE6E1E;      --poor-bg: #F6E6D4;      --poor-ln: #EEC599;
    --critical: #A2372A;  --critical-bg: #F5DDD8;  --critical-ln: #E9B1A6;
    --neutral-bg: #E7EEEC; --neutral-ln: #CBD9D4;

    --f-display: 'IBM Plex Sans Condensed', sans-serif;
    --f-body: 'IBM Plex Sans', sans-serif;
    --f-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: var(--f-body);
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

.app-shell { display: flex; min-height: 100vh; }

/* ---------- SIDEBAR ---------- */
.sidebar {
    width: 230px; flex-shrink: 0; background: var(--teal-deep); color: #CFE6E1;
    display: flex; flex-direction: column; padding: 1.3rem 1rem;
    background-image:
        linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
    background-size: 16px 16px;
}
.brand { display: flex; align-items: center; gap: .65rem; padding: 0 .3rem .3rem; }
.brand__mark {
    width: 34px; height: 34px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.brand__mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand__title { font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; color: #fff; letter-spacing: .02em; line-height: 1.1; }
.brand__sub { font-family: var(--f-mono); font-size: .62rem; color: #8FB8B1; letter-spacing: .04em; margin-top: 2px; }
.sidebar__divider { height: 1px; background: rgba(255,255,255,.1); margin: 1.1rem 0 .8rem; }
.nav { display: flex; flex-direction: column; gap: .2rem; }
.navitem {
    display: flex; align-items: center; gap: .65rem; width: 100%; text-align: left;
    padding: .6rem .7rem; border-radius: 5px; color: #AFD1CA; background: transparent; border: none;
    font-family: var(--f-body); font-size: .86rem; font-weight: 500; cursor: pointer; transition: background .12s;
}
.navitem:hover { background: rgba(255,255,255,.06); color: #EAF6F3; }
.navitem.active { background: rgba(58,163,156,.22); color: #fff; box-shadow: inset 2px 0 0 var(--teal-bright); }
.navitem__num { font-family: var(--f-mono); font-size: .68rem; color: #6E9992; width: 16px; }
.navitem.active .navitem__num { color: var(--teal-bright); }
.sidebar__foot { margin-top: auto; padding-top: 1rem; font-family: var(--f-mono); font-size: .62rem; color: #5E8983; line-height: 1.6; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar__foot b { color: #9BC4BD; }
.sidebar__foot a { color: #9BC4BD; text-decoration: underline; cursor: pointer; }

/* ---------- MAIN ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1rem 1.6rem; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.topbar__title { font-family: var(--f-display); font-weight: 700; font-size: 1.28rem; color: var(--ink); letter-spacing: .01em; }
.topbar__sub { font-family: var(--f-mono); font-size: .68rem; color: var(--muted); margin-top: 2px; }
.topbar__actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.search {
    font-family: var(--f-body); font-size: .82rem; padding: .5rem .7rem; border: 1px solid var(--line);
    border-radius: 4px; background: #fff; width: 250px; color: var(--ink);
}
.view { flex: 1; overflow: auto; padding: 1.5rem 1.6rem 3rem; }

/* ---------- BUTTONS ---------- */
.btn {
    font-family: var(--f-body); font-weight: 600; font-size: .8rem; padding: .55rem .9rem; border-radius: 4px;
    border: 1px solid var(--line); background: #fff; color: var(--ink-soft); cursor: pointer; white-space: nowrap;
    transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--teal); color: var(--teal-deep); background: var(--surface-alt); }
.btn--primary { background: var(--teal-deep); border-color: var(--teal-deep); color: #fff; }
.btn--primary:hover { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn--danger { color: var(--critical); border-color: var(--critical-ln); background: var(--critical-bg); }
.btn--danger:hover { background: #f0c9c1; }
.btn--sm { padding: .35rem .6rem; font-size: .72rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .navitem:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .search:focus {
    outline: 2px solid var(--teal-bright); outline-offset: 1px;
}

/* ---------- SHEET ---------- */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 3px; position: relative; padding: 1.1rem 1.2rem; }
.sheet::before, .sheet::after { content: ""; position: absolute; width: 9px; height: 9px; pointer-events: none; }
.sheet::before { top: -1px; left: -1px; border-top: 2px solid var(--teal-bright); border-left: 2px solid var(--teal-bright); }
.sheet::after { bottom: -1px; right: -1px; border-bottom: 2px solid var(--teal-bright); border-right: 2px solid var(--teal-bright); }
.sheet__title { font-family: var(--f-display); font-weight: 700; font-size: .86rem; text-transform: uppercase; letter-spacing: .05em; color: var(--teal-deep); margin: 0 0 .8rem; }
.sheet__title small { display: block; font-family: var(--f-mono); text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 500; font-size: .68rem; margin-top: 2px; }

/* ---------- GRIDS ---------- */
.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } }

/* ---------- KPI ---------- */
.kpi { padding: .95rem 1.05rem; }
.kpi__label { font-family: var(--f-mono); font-size: .66rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi__value { font-family: var(--f-display); font-weight: 700; font-size: 2rem; color: var(--teal-deep); line-height: 1.15; margin-top: .15rem; }
.kpi__value span { font-size: 1rem; color: var(--muted); font-weight: 500; }
.kpi__note { font-size: .72rem; color: var(--muted); margin-top: .25rem; }

/* ---------- BADGES ---------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem; padding: .16rem .5rem; border-radius: 3px;
    font-family: var(--f-mono); font-size: .68rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .03em; border: 1px solid; white-space: nowrap;
}
.b-good { background: var(--good-bg); color: var(--good); border-color: var(--good-ln); }
.b-fair { background: var(--fair-bg); color: var(--fair); border-color: var(--fair-ln); }
.b-poor { background: var(--poor-bg); color: var(--poor); border-color: var(--poor-ln); }
.b-critical { background: var(--critical-bg); color: var(--critical); border-color: var(--critical-ln); }
.b-neutral { background: var(--neutral-bg); color: var(--ink-soft); border-color: var(--neutral-ln); }

/* ---------- BANNER ---------- */
.banner {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    background: var(--fair-bg); border: 1px solid var(--fair-ln); color: #5c4713; border-radius: 4px;
    padding: .7rem 1rem; font-size: .8rem; margin-bottom: 1.1rem;
}
.banner b { color: #4a3a10; }
.banner--good { background: var(--good-bg); border-color: var(--good-ln); color: #1f4a2c; }
.banner--error { background: var(--critical-bg); border-color: var(--critical-ln); color: #6d2419; }

/* ---------- TABLE ---------- */
table.dt { width: 100%; border-collapse: collapse; font-size: .8rem; }
table.dt thead th {
    text-align: left; font-family: var(--f-mono); font-size: .66rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--muted); border-bottom: 1px solid var(--line); padding: .5rem .55rem; cursor: pointer;
    user-select: none; white-space: nowrap; background: var(--surface); position: sticky; top: 0; z-index: 1;
}
table.dt thead th:hover, table.dt thead th.sorted { color: var(--teal-deep); }
table.dt tbody td { padding: .5rem .55rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.dt tbody tr { cursor: pointer; }
table.dt tbody tr:hover { background: var(--surface-alt); }
.mono { font-family: var(--f-mono); font-size: .78rem; }
.tcell-strong { font-weight: 600; color: var(--ink); }

/* ---------- FORM ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; }
.field label { font-family: var(--f-mono); font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.field label .req { color: var(--rust); }
.field input, .field select, .field textarea {
    font-family: var(--f-body); font-size: .84rem; padding: .5rem .6rem; border: 1px solid var(--line);
    border-radius: 4px; background: #fff; color: var(--ink); width: 100%;
}
.field textarea { resize: vertical; min-height: 60px; }
.field-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.field-row-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem; }
@media (max-width: 640px) { .field-row, .field-row-2 { grid-template-columns: 1fr; } }
/* Table-like grid: fixed-width columns so checkbox+label pairs line up row
   by row instead of drifting to wherever flex-wrap happens to break them. */
.checkgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .55rem 1rem; }
.checkitem { display: flex; align-items: center; gap: .4rem; font-size: .78rem; min-width: 0; }
/* width: auto overrides the generic ".field input { width: 100% }" rule,
   which otherwise stretches the checkbox itself to fill the column and
   strands the label text out past its right edge. */
.checkitem input { flex: 0 0 auto; width: auto; margin: 0; }
/* No wrapping to a second line - a label that doesn't fit is truncated
   rather than pushed onto its own row, which is what actually caused the
   checkbox/text separation the flex-wrap version was trying to avoid. */
.checkitem span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.formsection { margin-bottom: 1.3rem; padding-bottom: 1.1rem; border-bottom: 1px dashed var(--line-soft); }
.formsection:last-child { border-bottom: none; }
.formsection__title {
    font-family: var(--f-display); font-weight: 700; font-size: .76rem; text-transform: uppercase;
    letter-spacing: .06em; color: var(--teal); margin: 0 0 .7rem; display: flex; align-items: center; gap: .4rem;
}
.formsection__title .fsn { font-family: var(--f-mono); background: var(--teal-deep); color: #fff; border-radius: 2px; padding: .05rem .4rem; font-size: .65rem; }
.field-error { border-color: var(--critical) !important; }
/* Holds a raw imported value with no vocabulary match - worth a second look. */
.field-offvocab { border-color: var(--rust) !important; background: var(--critical-bg); }

/* ---------- MODAL ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(14,28,27,.55); display: none; align-items: flex-start;
    /* Above Leaflet, whose panes go to 700 and whose controls sit at 1000 -
       otherwise the map paints over the "kartela" opened from a marker. */
    justify-content: center; padding: 2.2rem 1rem; overflow: auto; z-index: 2000;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); width: 100%; max-width: 1400px; border-radius: 5px; border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(10,20,20,.35); position: relative; }
.modal__head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.3rem;
    border-bottom: 1px solid var(--line); background: var(--surface); border-radius: 5px 5px 0 0;
}
.modal__title { font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; color: var(--teal-deep); }
.modal__idtag { font-family: var(--f-mono); font-size: .72rem; color: var(--muted); margin-top: 2px; }
.modal__body { padding: 1.3rem; }
.modal__foot { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: 1rem 1.3rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.closeX { background: none; border: none; font-size: 1.3rem; line-height: 1; color: var(--muted); cursor: pointer; padding: .2rem .4rem; }
.closeX:hover { color: var(--rust); }

/* ---------- LIGHTBOX (photo popup viewer) ---------- */
.lightbox-overlay {
    position: fixed; inset: 0; background: rgba(6,14,14,.92); display: none; align-items: center;
    justify-content: center; z-index: 3000; /* above .modal-overlay (2000) - opens from within the modal */
}
.lightbox-overlay.open { display: flex; }
.lightbox__img { max-width: 88vw; max-height: 86vh; object-fit: contain; border-radius: 3px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lightbox__close {
    position: absolute; top: 1rem; right: 1.3rem; background: none; border: none; color: #EAF6F3;
    font-size: 2rem; line-height: 1; cursor: pointer; opacity: .8; padding: .2rem .5rem;
}
.lightbox__close:hover { opacity: 1; color: var(--rust); }
.lightbox__nav {
    position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.2); color: #EAF6F3; font-size: 1.8rem; line-height: 1;
    width: 46px; height: 46px; border-radius: 50%; cursor: pointer; display: flex; align-items: center;
    justify-content: center; transition: background .12s;
}
.lightbox__nav:hover { background: rgba(255,255,255,.18); }
.lightbox__prev { left: 1.2rem; }
.lightbox__next { right: 1.2rem; }
.lightbox__counter {
    position: absolute; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
    font-family: var(--f-mono); font-size: .7rem; color: #B7DCD6; background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.15); padding: .3rem .7rem; border-radius: 999px;
}
@media (max-width: 640px) { .lightbox__nav { width: 38px; height: 38px; font-size: 1.4rem; } }

/* ---------- VIEW MODE ---------- */
.viewgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .55rem 1.4rem; font-size: .82rem; }
@media (max-width: 640px) { .viewgrid { grid-template-columns: 1fr; } }
.vk { color: var(--muted); font-family: var(--f-mono); font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; }
.vv { color: var(--ink); font-weight: 500; }

/* ---------- PROFILE (schematic cross-section) ---------- */
.profilebox { margin-top: .9rem; padding: .9rem; background: #fff; border: 1px solid var(--line-soft); border-radius: 4px; }

/* ---------- PHOTOS ---------- */
.photogrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
@media (max-width: 640px) { .photogrid { grid-template-columns: repeat(2, 1fr); } }
.photoslot { border: 1px solid var(--line); border-radius: 4px; padding: .5rem; text-align: center; background: #fff; }
.photoslot__thumb { width: 100%; height: 90px; object-fit: cover; border-radius: 3px; display: block; margin-bottom: .4rem; cursor: pointer; transition: opacity .12s; }
.photoslot__thumb:hover { opacity: .85; }
.gallery-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; flex-wrap: wrap; }
.gallery-head .btn { cursor: pointer; }

/* ---------- SKETCH ---------- */
.sketchpad { border: 1px solid var(--line); border-radius: 4px; background: #fff; overflow: hidden; }
.sketchpad canvas {
    display: block; width: 100%; touch-action: none; cursor: crosshair;
    background: linear-gradient(0deg, transparent 24px, rgba(182,199,193,.35) 25px),
                linear-gradient(90deg, transparent 24px, rgba(182,199,193,.35) 25px);
    background-size: 25px 25px;
}
.sketch-tools { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-top: 1px solid var(--line-soft); background: var(--surface-alt); flex-wrap: wrap; }
.sw { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.sw.active { box-shadow: 0 0 0 2px var(--teal-deep); }

/* ---------- MAP ---------- */
.mapshell { display: grid; grid-template-columns: 230px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .mapshell { grid-template-columns: 1fr; } }
.filterbox { display: flex; flex-direction: column; gap: 1rem; }
.filtergroup label.fg-title { display: block; font-family: var(--f-mono); font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .4rem; }
.filtergroup select { width: 100%; font-family: var(--f-body); font-size: .8rem; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); }
.checklist { display: flex; flex-direction: column; gap: .3rem; }
.checklist label { display: flex; align-items: center; gap: .4rem; font-size: .78rem; cursor: pointer; }

#leafletMap { height: min(70vh, 640px); width: 100%; background: var(--paper-deep); }
.leaflet-container { font-family: var(--f-body); }
.flows-marker { background: transparent; border: 0; }
.flows-marker svg { display: block; overflow: visible; }
.flows-marker .glyph-ring { stroke: #fff; stroke-width: 2; }

.legend { display: flex; gap: 1rem; flex-wrap: wrap; padding: .7rem 1rem; border-top: 1px solid var(--line-soft); font-size: .72rem; color: var(--ink-soft); align-items: center; }
.legend__item { display: flex; align-items: center; gap: .35rem; }
.map-caption { margin-left: auto; font-family: var(--f-mono); font-size: .62rem; color: var(--muted); }

/* ---------- CASCADE CHAIN ---------- */
.chainrow { display: flex; align-items: center; flex-wrap: wrap; gap: .1rem; }
.chain-node { display: flex; align-items: center; gap: .5rem; padding: .4rem .55rem; border: 1px solid var(--line-soft); border-radius: 5px; background: var(--surface-alt); cursor: pointer; transition: border-color .12s; }
.chain-node:hover { border-color: var(--teal-bright); }
.chain-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(0,0,0,.25); }
.chain-label { font-size: .76rem; line-height: 1.3; }
.chain-label b { font-family: var(--f-mono); color: var(--teal-deep); }
.chain-label span { display: block; color: var(--muted); font-size: .68rem; }
.chain-arrow { color: var(--teal-bright); font-weight: 700; padding: 0 .3rem; font-size: 1rem; }

/* ---------- DASHBOARD ---------- */
.dashboard-shell { display: grid; gap: 1rem; }
.dashboard-command { display: grid; grid-template-columns: minmax(0,1.7fr) minmax(300px,.82fr); gap: 1rem; align-items: stretch; }
.dash-map-card {
    min-height: 410px; border-radius: 8px; overflow: hidden; position: relative; color: #EAF6F3; border: 1px solid #08282B;
    background: radial-gradient(circle at 76% 10%, rgba(58,163,156,.28), transparent 34%),
                radial-gradient(circle at 12% 85%, rgba(31,111,106,.34), transparent 38%),
                linear-gradient(145deg, #0A292C 0%, #0E3A3D 55%, #102E31 100%);
    box-shadow: 0 14px 36px rgba(9,40,42,.14);
    display: flex; flex-direction: column;
}
.dash-map-card::before {
    content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
    background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
    background-size: 22px 22px;
}
.dash-map-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1rem 1.15rem .35rem; position: relative; z-index: 2; }
.dash-eyebrow { font-family: var(--f-mono); font-size: .62rem; color: #78CFC5; text-transform: uppercase; letter-spacing: .08em; }
.dash-map-title { font-family: var(--f-display); font-weight: 700; font-size: 1.08rem; color: #fff; margin-top: .2rem; }
.dash-map-title small { display: block; font-family: var(--f-body); font-size: .7rem; font-weight: 400; color: #9FC5C0; margin-top: .25rem; }
.dash-live { display: flex; align-items: center; gap: .4rem; font-family: var(--f-mono); font-size: .63rem; color: #B7DCD6; border: 1px solid rgba(143,224,214,.2); background: rgba(255,255,255,.055); padding: .35rem .55rem; border-radius: 999px; white-space: nowrap; }
.dash-live i { width: 7px; height: 7px; border-radius: 50%; background: #6FE0A3; box-shadow: 0 0 0 5px rgba(111,224,163,.1); }
.dash-map-stage { flex: 1; min-height: 250px; position: relative; z-index: 1; padding: 0 .8rem; }
.dash-map-foot { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .35rem 1.15rem 1rem; position: relative; z-index: 2; }
.dash-legend { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .66rem; color: #C2DCD8; }
.dash-legend span { display: flex; align-items: center; gap: .3rem; }
.dash-map-btn { font-family: var(--f-mono); font-size: .67rem; color: #A5EEE4; background: transparent; border: none; border-bottom: 1px dotted rgba(165,238,228,.7); padding: 0 0 .12rem; cursor: pointer; }
.dash-side { display: grid; grid-template-rows: auto 1fr; gap: 1rem; min-width: 0; }
.health-card { background: linear-gradient(145deg, #F9FCFA, #EEF5F2); border: 1px solid var(--line); border-radius: 7px; padding: 1rem; display: grid; grid-template-columns: 136px 1fr; align-items: center; gap: .9rem; position: relative; overflow: hidden; }
.health-card::after { content: ""; position: absolute; width: 140px; height: 140px; border-radius: 50%; right: -65px; top: -65px; background: rgba(58,163,156,.08); }
.health-copy h3 { font-family: var(--f-display); font-size: .94rem; margin: 0; color: var(--teal-deep); }
.health-copy p { font-size: .72rem; line-height: 1.45; color: var(--muted); margin: .35rem 0 .7rem; }
.health-lines { display: grid; gap: .42rem; }
.health-line { display: grid; grid-template-columns: 78px 1fr 28px; align-items: center; gap: .45rem; font-size: .65rem; color: var(--ink-soft); }
.health-track { height: 5px; background: var(--paper-deep); border-radius: 999px; overflow: hidden; }
.health-fill { height: 100%; border-radius: 999px; }
.health-n { font-family: var(--f-mono); font-size: .64rem; text-align: right; color: var(--ink-soft); }
.quick-metrics { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; }
.quick-metric { min-height: 112px; border-radius: 7px; padding: .85rem .9rem; position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; justify-content: flex-end; }
.quick-metric::before { content: ""; position: absolute; inset: 0 auto auto 0; width: 100%; height: 3px; background: var(--teal-bright); }
.quick-metric--alert::before { background: var(--critical); }
.quick-metric--amber::before { background: var(--amber); }
.quick-metric--good::before { background: var(--good); }
.quick-metric__value { font-family: var(--f-display); font-weight: 700; font-size: 1.82rem; line-height: 1; color: var(--teal-deep); }
.quick-metric--alert .quick-metric__value { color: var(--critical); }
.quick-metric__label { font-family: var(--f-mono); font-size: .6rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: .35rem; line-height: 1.35; }
.metric-ribbon { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 1px; border: 1px solid var(--line); background: var(--line); border-radius: 7px; overflow: hidden; }
.ribbon-item { background: var(--surface); padding: .72rem .85rem; min-width: 0; }
.ribbon-value { font-family: var(--f-display); font-size: 1.25rem; font-weight: 700; color: var(--teal-deep); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ribbon-label { font-family: var(--f-mono); font-size: .58rem; text-transform: uppercase; letter-spacing: .045em; color: var(--muted); margin-top: .18rem; line-height: 1.3; }
.dashboard-bento { display: grid; grid-template-columns: repeat(12, minmax(0,1fr)); gap: 1rem; }
.bento-card { min-width: 0; }
.bento-4 { grid-column: span 4; } .bento-5 { grid-column: span 5; } .bento-6 { grid-column: span 6; }
.bento-7 { grid-column: span 7; } .bento-8 { grid-column: span 8; } .bento-12 { grid-column: span 12; }
.chartcard { padding: 1rem 1.1rem 1.3rem; }
.chartcard canvas { max-height: 230px; }
.chartcard--compact { min-height: 275px; }
.chartcard--compact canvas { height: 205px !important; max-height: 205px !important; }
.urgent-panel { background: linear-gradient(145deg, #fff 0%, #FBF5F2 100%); }
.coverage-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .65rem; }
.coverage-tile { padding: .75rem; border: 1px solid var(--line-soft); background: #fff; border-radius: 5px; }
.coverage-tile__n { font-family: var(--f-display); font-weight: 700; font-size: 1.45rem; color: var(--teal-deep); }
.coverage-tile__l { font-size: .67rem; color: var(--muted); margin-top: .18rem; line-height: 1.35; }
.coverage-tile__bar { height: 4px; background: var(--paper-deep); border-radius: 999px; margin-top: .55rem; overflow: hidden; }
.coverage-tile__bar i { display: block; height: 100%; background: var(--teal-bright); }
.panel-footnote { font-family: var(--f-mono); font-size: .6rem; color: var(--muted); margin-top: .7rem; line-height: 1.45; }

/* ---------- PIPELINE ---------- */
.pipeline { display: flex; align-items: flex-start; overflow-x: auto; padding-top: .3rem; }
.pipe-step { display: flex; flex-direction: column; align-items: center; width: 120px; text-align: center; flex-shrink: 0; }
.pipe-node { width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid; display: flex; align-items: center; justify-content: center; font-family: var(--f-mono); font-weight: 700; font-size: .8rem; background: #fff; flex-shrink: 0; }
.pipe-label { font-size: .68rem; color: var(--ink-soft); margin-top: .5rem; line-height: 1.3; min-height: 2.4em; }
.pipe-pct { font-family: var(--f-mono); font-size: .7rem; font-weight: 600; margin-top: .15rem; }
.pipe-line { flex: 1; height: 2.5px; background: var(--line-soft); margin-top: 23px; min-width: 16px; }
.pipe-line-fill { height: 100%; transition: width .4s; }
@media (max-width: 700px) {
    .pipeline { flex-direction: column; align-items: flex-start; }
    .pipe-step { flex-direction: row; width: auto; text-align: left; gap: .7rem; }
    .pipe-label { min-height: 0; }
    .pipe-line { width: 2.5px; height: 20px; margin: 0 0 0 22px; }
}

.statlist { list-style: none; margin: 0; padding: 0; font-size: .8rem; }
.statlist li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--line-soft); }
.statlist li:last-child { border-bottom: none; }
.statlist li.active { color: var(--teal-deep); font-weight: 600; }
.statlist .n { font-family: var(--f-mono); color: var(--teal-deep); font-weight: 600; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); font-size: .85rem; }
.muted { color: var(--muted); }

.finding { display: flex; gap: .6rem; padding: .5rem 0; font-size: .8rem; line-height: 1.45; border-bottom: 1px solid var(--line-soft); }
.finding:last-child { border-bottom: none; }
.finding__code { font-family: var(--f-mono); font-size: .68rem; font-weight: 600; flex-shrink: 0; width: 62px; }
.finding--critical .finding__code { color: var(--critical); }
.finding--warning .finding__code { color: var(--amber); }

.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; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1180px) {
    .dashboard-command { grid-template-columns: 1fr; }
    .dash-side { grid-template-columns: .9fr 1.1fr; grid-template-rows: auto; }
    .metric-ribbon { grid-template-columns: repeat(3, 1fr); }
    .bento-4, .bento-5, .bento-7, .bento-8 { grid-column: span 6; }
}
@media (max-width: 800px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: .7rem .9rem; overflow-x: auto; }
    .brand { padding: 0 .6rem 0 0; }
    .sidebar__divider, .sidebar__foot { display: none; }
    .nav { flex-direction: row; }
    .navitem { white-space: nowrap; }
    .main { height: auto; }
    .view { overflow: visible; }
}
@media (max-width: 760px) {
    .dash-side { grid-template-columns: 1fr; }
    .health-card { grid-template-columns: 112px 1fr; }
    .metric-ribbon { grid-template-columns: repeat(2, 1fr); }
    .dashboard-bento { grid-template-columns: 1fr; }
    .bento-4, .bento-5, .bento-6, .bento-7, .bento-8, .bento-12 { grid-column: 1; }
}

/* ---- Permission-based visibility. <html data-p="..."> lists the signed-in role's
   permissions (Views/Home/Index.cshtml). Hiding is a convenience only - the API
   rejects the action server-side regardless. ---- */
html:not([data-p~="Structures.Create"]) #btnAddDam,
html:not([data-p~="Structures.Edit"]) #mEdit,
html:not([data-p~="Structures.Edit"]) #mSave,
html:not([data-p~="Structures.Delete"]) #mDelete,
html:not([data-p~="Structures.Media"]) #photoUploadLabel,
html:not([data-p~="Structures.Media"]) .photoDel,
html:not([data-p~="Structures.Cad"]) .cadUploadBtn,
html:not([data-p~="Structures.Cad"]) #cadDelete,
html:not([data-p~="Import.Run"]) .navitem[data-tab="import"] { display: none !important; }