/* ============================================================================
   Uganda Aquaculture Census 2025 — dashboard
   Chart surface is #fff on a #f7faf9 ground; the categorical palette was
   validated against that surface. Text always wears ink tokens, never a
   series colour.
   ========================================================================== */

:root {
    --ink:        #12212f;
    --ink-2:      #475569;
    --muted:      #6b7a89;
    --line:       #e3ebee;
    --line-soft:  #eef3f5;
    --surface:    #ffffff;
    --ground:     #f7faf9;
    --brand:      #0b7285;
    --brand-dk:   #04323f;
    --brand-lt:   #e8f6f8;
}

/* ── scope bar ───────────────────────────────────────────────────────────── */
.scope-bar {
    position: sticky; top: 0; z-index: 30;
    background: rgba(255,255,255,.94);
    backdrop-filter: saturate(160%) blur(8px);
    border-bottom: 1px solid var(--line);
    padding: .6rem 0;
}
.scope-title {
    display: flex; align-items: center; gap: .5rem;
    font-size: 1.05rem; font-weight: 700; color: var(--brand-dk);
}
.scope-title i { color: var(--brand); font-size: .95rem; }
.scope-badge {
    background: var(--brand-lt); color: var(--brand);
    font-size: .66rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; padding: 3px 9px; border-radius: 999px;
}
.scope-controls { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.scope-lbl { font-size: .74rem; color: var(--muted); font-weight: 600; margin: 0; }
.scope-select {
    border: 1px solid var(--line); border-radius: 8px; background: #fff;
    color: var(--ink); font-size: .82rem; font-weight: 500;
    padding: .35rem .6rem; min-width: 150px;
}
.scope-select:focus { outline: 2px solid var(--brand-lt); border-color: var(--brand); }
.scope-select:disabled { background: #f6f8f9; color: #9aa7b1; }
.scope-reset {
    border: 1px solid var(--line); background: #fff; color: var(--muted);
    border-radius: 8px; width: 32px; height: 32px; font-size: .78rem;
}
.scope-reset:hover { background: var(--brand-lt); color: var(--brand); border-color: var(--brand); }

/* ── headline figures ────────────────────────────────────────────────────── */
.stat-band {
    display: grid; gap: .75rem; margin: 1rem 0 1.1rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.stat {
    background: var(--surface); border: 1px solid #f0f0f0; border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
    padding: .95rem 1.05rem; position: relative; overflow: hidden;
}
.stat .ico { color: var(--muted); font-size: .95rem; margin-bottom: .35rem; }
.stat .val { font-size: 1.75rem; font-weight: 800; color: var(--brand-dk); line-height: 1.05;
             font-variant-numeric: tabular-nums; }
.stat .val .u { font-size: .82rem; font-weight: 600; color: var(--muted); margin-left: 3px; }
.stat .lbl { font-size: .84rem; font-weight: 600; color: var(--ink); margin-top: .2rem; }
.stat .meta { font-size: .71rem; color: var(--muted); margin-top: .3rem; }
.stat .share {
    display: inline-block; background: var(--brand-lt); color: var(--brand);
    font-weight: 700; border-radius: 999px; padding: 1px 7px; font-size: .68rem;
}
.stat.is-empty .val { color: #c2ced6; }

/* ── panels ──────────────────────────────────────────────────────────────── */
.panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: 14px; padding: 1.1rem 1.2rem 1.2rem; margin-bottom: 1.1rem;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start;
              gap: 1rem; flex-wrap: wrap; margin-bottom: .9rem; }
.panel-head h2 { font-size: 1.02rem; font-weight: 700; color: var(--brand-dk); margin: 0 0 .15rem; }
.panel-head h2 i { color: var(--brand); margin-right: .35rem; }
.panel-head p { font-size: .83rem; color: var(--muted); margin: 0; max-width: 62ch; }
.src-tag {
    font-size: .68rem; color: var(--muted); background: var(--ground);
    border: 1px solid var(--line-soft); border-radius: 999px; padding: 2px 10px;
    white-space: nowrap;
}

/* ── species matrix ──────────────────────────────────────────────────────────
   Card treatment follows the Education Census KPI matrix (bec/dashboard.php
   .kpi-*): a white card per species, the species colour carried by the header
   chip and the row icons, and a trailing arrow that arrives on hover to say
   the row is clickable.

   Where this differs from BEC is depth. BEC's matrix is deliberately flat;
   these cards are raised — a soft drop shadow and a wash of the species colour
   bleeding up from the bottom, the same treatment bec/index.php gives its
   level-cards. Hovering lifts the card and deepens the shadow, so the four
   species read as four objects rather than four table columns. The border
   itself stays neutral on all four sides: the colour is carried by the header
   chip, the row icons and the wash.
   ------------------------------------------------------------------------- */
.matrix { display: grid; gap: .8rem; grid-template-columns: repeat(4, minmax(0, 1fr)); }

.mx-col {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(4, 50, 63, .07);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.mx-col::after {
    /* Accent wash bleeding up from the bottom — tints the card in the species
       colour without competing with the numbers. */
    content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 78px;
    background: linear-gradient(180deg, transparent 0%, var(--sp, var(--brand)) 100%);
    opacity: .055; pointer-events: none;
}
.mx-col:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 30px rgba(4, 50, 63, .16);
}

.mx-head {
    position: relative; z-index: 1;
    display: flex; align-items: center; gap: .5rem;
    padding: .7rem .85rem .5rem;
}
.mx-chip {
    width: 26px; height: 26px; border-radius: 8px; flex: none;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: .7rem;
    background: var(--sp, var(--brand));
    background: linear-gradient(135deg, var(--sp, var(--brand)) 0%,
                color-mix(in srgb, var(--sp, var(--brand)) 72%, #04323f) 100%);
    box-shadow: 0 2px 6px rgba(4, 50, 63, .22);
    box-shadow: 0 2px 6px color-mix(in srgb, var(--sp, var(--brand)) 45%, transparent);
}
.mx-name {
    font-size: .76rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
    color: var(--sp, var(--brand-dk)); line-height: 1.1;
}

.mx-row {
    position: relative; z-index: 1;
    display: flex; align-items: flex-start; gap: .65rem;
    padding: .6rem .85rem .65rem;
    border-top: 1px solid var(--line-soft);
    text-decoration: none; color: inherit;
    transition: background .12s ease;
}
.mx-row.first { border-top: none; }
a.mx-row { cursor: pointer; }
a.mx-row:hover { background: #f7fbfc; color: inherit; }
a.mx-row:hover { background: color-mix(in srgb, var(--sp, var(--brand)) 6%, #fff); }
a.mx-row:hover .mx-cta { opacity: .9; transform: translateX(0); }
a.mx-row:hover .mx-cta i { transform: translateX(2px); }
a.mx-row:focus-visible {
    outline: 2px solid var(--sp, var(--brand)); outline-offset: -2px; border-radius: 8px;
}

.mx-ico {
    flex: none; width: 24px; text-align: center; margin-top: .2rem;
    color: var(--sp, var(--brand)); font-size: .85rem; opacity: .9;
}
.mx-body { flex: 1; min-width: 0; padding-right: 1.2rem; }
.mx-val {
    display: block;
    font-size: 1.42rem; font-weight: 800; line-height: 1.05; letter-spacing: -.015em;
    color: var(--brand-dk); font-variant-numeric: tabular-nums;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mx-val .u {
    font-size: .62rem; font-weight: 700; font-style: normal;
    color: var(--muted); margin-left: 3px; letter-spacing: .02em;
}
.mx-lbl {
    display: block; font-size: .72rem; font-weight: 600; color: var(--ink-2);
    margin-top: .2rem; line-height: 1.2;
}
.mx-sub {
    display: block; font-size: .66rem; color: var(--muted);
    margin-top: .12rem; line-height: 1.25;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mx-cta {
    position: absolute; top: 50%; right: .7rem; margin-top: -7px;
    color: var(--sp, var(--brand)); font-size: .7rem; line-height: 1;
    opacity: 0; transform: translateX(-3px); pointer-events: none;
    transition: opacity .12s ease, transform .12s ease;
}
.mx-cta i { transition: transform .12s ease; }

.mx-row.is-empty .mx-val { color: #ccd7de; }
.mx-row.is-empty .mx-ico { opacity: .32; }
.mx-row.is-empty .mx-sub { font-style: italic; }

/* ── indicator drill-down ────────────────────────────────────────────────────
   Tinted per open with --sp, the colour of the species whose figure was
   clicked, so the panel reads as an extension of that card.
   ------------------------------------------------------------------------- */
.drill-backdrop {
    position: fixed; inset: 0; z-index: 1080;
    background: rgba(4, 50, 63, .55);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
    animation: drillFade .15s ease-out;
}
.drill-backdrop[hidden] { display: none; }
@keyframes drillFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes drillUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.drill {
    position: relative; overflow: hidden;
    background: var(--surface); border-radius: 14px;
    width: 100%; max-width: 860px; max-height: calc(100vh - 2rem);
    display: flex; flex-direction: column;
    box-shadow: 0 22px 60px rgba(4, 50, 63, .3);
    animation: drillUp .18s ease-out;
}
.drill-close {
    position: absolute; top: .55rem; right: .55rem; z-index: 2;
    width: 32px; height: 32px; border: none; border-radius: 8px;
    background: transparent; color: var(--muted); cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.drill-close:hover { background: var(--line-soft); color: var(--brand-dk); }

.drill-head {
    flex: 0 0 auto; padding: 1.1rem 1.3rem .85rem;
    border-top: 4px solid var(--sp, var(--brand));
    border-bottom: 1px solid var(--line-soft);
}
.drill-eyebrow {
    font-size: .65rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase;
    color: var(--sp, var(--brand)); margin-bottom: .15rem;
}
.drill-head h3 {
    margin: 0 0 .25rem; font-size: 1.2rem; font-weight: 800;
    color: var(--brand-dk); letter-spacing: -.01em; padding-right: 2rem;
}
.drill-context { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.45; }

.drill-body { flex: 1 1 auto; overflow: auto; padding: 1rem 1.3rem 1.2rem; }
.drill-load, .drill-empty {
    padding: 2.6rem 1rem; text-align: center; color: var(--muted); font-size: .86rem;
}
.drill-load i { font-size: 1.4rem; color: var(--sp, var(--brand)); }
.drill-empty i { display: block; font-size: 1.5rem; margin-bottom: .5rem; color: #cbd5e1; }

.drill-hero {
    background: var(--brand-lt);
    background: color-mix(in srgb, var(--sp, var(--brand)) 7%, #fff);
    border: 1px solid var(--line);
    border: 1px solid color-mix(in srgb, var(--sp, var(--brand)) 22%, #fff);
    border-radius: 11px; padding: .85rem 1rem; margin-bottom: 1.1rem;
}
.drill-hero-v {
    font-size: 2rem; font-weight: 800; line-height: 1; letter-spacing: -.02em;
    color: var(--brand-dk); font-variant-numeric: tabular-nums;
}
.drill-hero-v .u {
    font-size: .8rem; font-weight: 700; font-style: normal; color: var(--muted); margin-left: 4px;
}
.drill-hero-l { font-size: .76rem; color: var(--ink-2); font-weight: 600; margin-top: .3rem; }
.drill-hero-p {
    display: inline-block; margin-top: .45rem;
    font-size: .72rem; font-weight: 700; color: var(--sp, var(--brand));
    background: #fff; border: 1px solid var(--line);
    border: 1px solid color-mix(in srgb, var(--sp, var(--brand)) 30%, #fff);
    border-radius: 999px; padding: .18rem .6rem;
}
.drill-hero-n { font-size: .7rem; color: var(--muted); margin-top: .4rem; }

.drill-sect { margin-bottom: 1.3rem; }
.drill-sect:last-child { margin-bottom: 0; }
.drill-sect h4 {
    display: flex; align-items: baseline; gap: .5rem;
    margin: 0 0 .55rem; font-size: .8rem; font-weight: 800; color: var(--brand-dk);
}
.drill-scope {
    font-size: .65rem; font-weight: 600; color: var(--muted);
    background: var(--line-soft); border-radius: 999px; padding: .1rem .5rem;
}

.drill-bars { display: grid; gap: .35rem; }
.drill-bar-row {
    display: grid; grid-template-columns: 7.5rem 1fr 5rem; align-items: center; gap: .6rem;
    font-size: .76rem;
}
.drill-bar-row.is-self .drill-bar-n,
.drill-bar-row.is-self .drill-bar-v { font-weight: 800; color: var(--brand-dk); }
.drill-bar-n { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drill-bar-t { background: var(--line-soft); border-radius: 4px; height: 10px; overflow: hidden; }
.drill-bar-t i { display: block; height: 100%; border-radius: 4px; }
.drill-bar-v { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

table.drill-t { width: 100%; border-collapse: collapse; font-size: .78rem; }
table.drill-t th {
    position: sticky; top: 0; z-index: 1;
    background: var(--brand-lt); color: var(--brand-dk); font-weight: 700;
    padding: .4rem .5rem; text-align: left; white-space: nowrap;
}
table.drill-t th.num, table.drill-t td.num { text-align: right; }
table.drill-t th.bar, table.drill-t td.bar { width: 26%; }
table.drill-t td {
    padding: .36rem .5rem; border-bottom: 1px solid var(--line-soft); color: var(--ink-2);
}
table.drill-t td.num { font-variant-numeric: tabular-nums; }
table.drill-t td.pc { color: var(--muted); }
table.drill-t tbody tr:hover td { background: #fafcfc; }
table.drill-t tbody tr.on td { background: var(--brand-lt); font-weight: 700; }
table.drill-t tbody tr.on td { background: color-mix(in srgb, var(--sp, var(--brand)) 9%, #fff); }
table.drill-t td.bar i {
    display: block; height: 8px; border-radius: 4px;
    background: var(--sp, var(--brand));
    background: color-mix(in srgb, var(--sp, var(--brand)) 55%, #fff);
}
.drill-note { margin: .45rem 0 0; font-size: .67rem; color: var(--muted); line-height: 1.4; }

.drill-foot {
    flex: 0 0 auto; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
    padding: .75rem 1.3rem; border-top: 1px solid var(--line-soft); background: #fafcfc;
}
.drill-src { flex: 1 1 14rem; min-width: 0; font-size: .68rem; color: var(--muted); line-height: 1.35; }
.drill-src-t {
    display: inline-block; font-weight: 800; text-transform: uppercase; letter-spacing: .07em;
    color: var(--sp, var(--brand)); font-size: .6rem; margin-right: .35rem;
}
.drill-src span { display: inline; }
.drill-src-c { display: block !important; color: #9bacb5; }
.drill-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .45rem .85rem; border-radius: 8px; font-size: .78rem; font-weight: 700;
    border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.drill-btn.primary { background: var(--sp, var(--brand)); color: #fff; }
.drill-btn.primary:hover { color: #fff; filter: brightness(.94); }
.drill-btn.secondary { background: #fff; color: var(--ink-2); border-color: var(--line); }
.drill-btn.secondary:hover { background: var(--line-soft); color: var(--brand-dk); }

@media (max-width: 640px) {
    .drill-head, .drill-body, .drill-foot { padding-left: 1rem; padding-right: 1rem; }
    .drill-hero-v { font-size: 1.6rem; }
    .drill-bar-row { grid-template-columns: 5.5rem 1fr 4.2rem; }
    table.drill-t th.bar, table.drill-t td.bar { display: none; }
}

/* ── section tabs ────────────────────────────────────────────────────────── */
.sect-tabs {
    display: flex; gap: .4rem; overflow-x: auto; padding: .25rem 0 .8rem;
    position: sticky; top: 49px; z-index: 20; background: var(--ground);
    scrollbar-width: thin;
}
.sect-tab {
    display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap;
    border: 1px solid var(--line); background: #fff; color: var(--ink-2);
    border-radius: 999px; padding: .38rem .85rem; font-size: .82rem; font-weight: 600;
    cursor: pointer; transition: all .15s;
}
.sect-tab i { font-size: .78rem; color: var(--tab-color, var(--muted)); }
.sect-tab:hover { border-color: var(--tab-color, var(--brand)); }
.sect-tab.on { background: var(--tab-color, var(--brand)); border-color: var(--tab-color, var(--brand)); color: #fff; }
.sect-tab.on i { color: #fff; }
.sect-tab .n { font-size: .68rem; opacity: .7; font-weight: 700; }

/* ── chart cards ─────────────────────────────────────────────────────────── */
.sect-block { display: none; }
.sect-block.on { display: block; }
.sect-intro { font-size: .87rem; color: var(--muted); margin: 0 0 .9rem; max-width: 78ch; }
.sect-head { margin: .2rem 0 .75rem; padding-bottom: .45rem; border-bottom: 2px solid #e1e8ed; }
.sect-head h2 { font-size: 1.05rem; font-weight: 800; color: #0f172a; margin: 0;
                display: flex; align-items: center; gap: .5rem; }
.sect-head .sect-icon { width: 30px; height: 30px; border-radius: 8px; color: #fff;
                        display: inline-flex; align-items: center; justify-content: center;
                        font-size: .92rem; flex: none; }
.sect-head p { font-size: .8rem; color: #64748b; margin: .2rem 0 0; }

/* dense flow so a full-width card does not leave a hole beside the card
   before it */
.chart-grid { display: grid; gap: .85rem; grid-template-columns: repeat(2, minmax(0, 1fr));
              grid-auto-flow: dense; }
/* Card chrome matches the BEC dashboard: a light header band over a white
   body, a soft shadow, and outlined toolbar buttons that fill when active. */
.card {
    background: var(--surface); border: 1px solid #f0f0f0; border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
    display: flex; flex-direction: column; overflow: hidden; height: 100%;
}
.card.wide { grid-column: 1 / -1; }
.card-head {
    background: linear-gradient(135deg, #f8f9fc 0%, #e8ecf4 100%);
    border-bottom: 1px solid #e1e8ed;
    padding: .75rem 1rem; display: flex; gap: .8rem; align-items: flex-start;
}
.card-head .t { font-size: .95rem; font-weight: 700; color: #2c3e50; line-height: 1.3; }
.card-head .s { font-size: .76rem; color: #6b7280; margin-top: .15rem; line-height: 1.35; }
.card-tools { margin-left: auto; display: flex; gap: .3rem; flex: none; }
.tool-btn {
    background: #fff; border: 1px solid #dee2e6; border-radius: 6px;
    padding: .32rem .6rem; font-size: .74rem; font-weight: 500; color: #495057;
    cursor: pointer; transition: all .15s; line-height: 1;
    display: inline-flex; align-items: center; gap: .32rem;
}
.tool-btn:hover { background: #f8f9fa; border-color: #adb5bd; }
.tool-btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.card-body { padding: 1rem 1rem .4rem; flex: 1; min-height: 0; }
.plot { position: relative; height: 320px; }
.plot.tall { height: 400px; }
.plot.xtall { height: 520px; }
.card-foot {
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    padding: .55rem 1rem .8rem; border-top: 1px solid #f1f5f9; margin-top: .4rem;
}
.card-foot .src { font-size: .68rem; color: var(--muted); }
.card-foot .spacer { margin-left: auto; }
.dl-btn {
    border: 1px solid var(--line); background: #fff; color: var(--muted);
    border-radius: 7px; font-size: .68rem; font-weight: 600;
    padding: .22rem .5rem; cursor: pointer; display: inline-flex; align-items: center; gap: .25rem;
}
.dl-btn:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-lt); }
.chart-only-tag {
    font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    background: #fff4e5; color: #8a5300; border-radius: 999px; padding: 2px 8px;
}

/* table view of a chart — the relief for low-contrast categorical hues */
.card-table { display: none; overflow-x: auto; max-height: 340px; }
.card.as-table .plot { display: none; }
.card.as-table .card-table { display: block; }
.card-table table { border-collapse: collapse; width: 100%; font-size: .78rem; }
.card-table th, .card-table td { border-bottom: 1px solid var(--line-soft);
                                 padding: .35rem .55rem; text-align: right; white-space: nowrap; }
.card-table th { color: var(--ink-2); font-weight: 600; text-align: right;
                 position: sticky; top: 0; background: #fff; }
.card-table td.k, .card-table th.k { text-align: left; color: var(--ink); white-space: normal; }
.card-table .sw { display: inline-block; width: 9px; height: 9px; border-radius: 3px;
                  margin-right: 6px; vertical-align: baseline; }

.empty-note {
    display: flex; gap: .7rem; align-items: flex-start;
    background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--brand);
    border-radius: 10px; padding: .9rem 1.1rem; font-size: .87rem; color: var(--ink);
}
.empty-note i { color: var(--brand); margin-top: .15rem; }

.skeleton { background: linear-gradient(90deg, #f1f5f7 25%, #e7eef1 37%, #f1f5f7 63%);
            background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

@media (max-width: 1200px) {
    .stat-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .matrix { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
    .chart-grid { grid-template-columns: minmax(0, 1fr); }
    .scope-controls { width: 100%; }
    .scope-select { flex: 1; min-width: 0; }
    .sect-tabs { top: 0; }
}
@media (max-width: 560px) {
    .stat-band, .matrix { grid-template-columns: minmax(0, 1fr); }
    .plot { height: 260px; }
    .plot.tall { height: 300px; }
    .plot.xtall { height: 420px; }
}
