/* =============================================================================
   Anatomy of a Budget — what only this tool uses
   -----------------------------------------------------------------------------
   Tokens and the shared components (bar, buttons, segmented controls, panels,
   tooltip, drawer) are in projects/static/projects/tools/tool.css, linked first
   by projects/_tool_base.html; the design direction is docs/unga-design.md.
   Plain CSS, linked with {% static_v %}; the treemaps stay crisp (no textures,
   filters or tilt — core/tests.py enforces it).

   Layout: one viewport from 1024 x 600 up (section 7): the bar, the options
   band, then the two country panels, each map taking half of what is left of
   its panel. budgets.js reads the maps' boxes after layout and draws into them,
   so the CSS decides the size and the JS only fills it. Smaller screens stack
   the panels and scroll.

   Tiles: flat fills with straight edges on whole pixels; the treemap's 3px
   inner padding is the border, so the panel surface shows between tiles.
   Hover changes the outline only, as everywhere in the tools.

   Category colours: the owner's palette for this tool,
       #001219 #005f73 #0a9396 #94d2bd #e9d8a6 #ee9b00 #ca6702 #bb3e03 #ae2012 #9b2226
   as flat fills, the same hexes in both themes. These are data, not UI, so they
   stay hex here. Which colour went where was computed (2026-10-03): every
   country's maps were laid out at four viewports (1440x900, 1280x720,
   1024x768, 375x812), the tiles that touch were listed with their shared
   border, and every assignment was scored by the closest touching pair (OKLab
   dE, the worst of normal, protan and deutan vision, the dataviz validator's
   model), then by the touching border weighted over all pairs. Revenue uses
   seven of the ten (closest touching pair dE 14.2). Spending uses all ten; its
   categories touch almost every other one somewhere, and the palette holds
   three near-identical dark reds (#bb3e03 #ae2012 #9b2226), so the best
   possible closest pair is dE 6.3: the two closest reds went to General public
   services and Culture, which never touch. Re-run the assignment before
   swapping two colours. Contrast below 3:1 against the panel (light: the sand,
   mint and amber; dark: the navy, petrol and reds) is relieved by the labels,
   the hover card and the table. No legend.

   Spending has 12 categories for 10 colours: Interest on the debt is a neutral
   "ink" grey (not a service, the cost of past borrowing, kin to the empty
   dashed Borrowing tile), dark on the light page and light on the dark one;
   Other / unallocated a mid grey. The two sit at least dE 15 apart in each
   theme, and as far from all ten colours as a neutral can (dE 12-16).
   ============================================================================= */

/* 1. Data colours -------------------------------------------------------------- */
.wmg {
    /* spending */
    --c-social: #bb3e03;
    --c-health: #001219;
    --c-education: #e9d8a6;
    --c-defence: #005f73;
    --c-economic: #ca6702;
    --c-gps: #9b2226;
    --c-order: #ee9b00;
    --c-housing: #94d2bd;
    --c-environment: #0a9396;
    --c-culture: #ae2012;
    --c-interest: #353230;      /* neutral, outside the palette (see above) */
    --c-other: #a39d98;

    /* revenue */
    --r-income: #94d2bd;
    --r-ssc: #005f73;
    --r-goods: #001219;
    --r-property: #ae2012;
    --r-trade: #0a9396;
    --r-othertax: #e9d8a6;
    --r-nontax: #ee9b00;

    --paper-tile: var(--surface);       /* the empty Borrowing / surplus tile (budgets.js fillFor) */
    --alert: rgb(var(--pe-down));       /* the deficit figure, "not to scale" */
    font-variant-numeric: tabular-nums;
}
html.dark .wmg {
    /* The palette stays; only the two greys flip with the page. */
    --c-interest: #a39d97;
    --c-other: #736e69;
}

.wmg-defs { position: absolute; width: 0; height: 0; }
.wmg-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 2. Top bar: the two countries and the drawer button ------------------------ */
.wmg-pick { display: flex; align-items: center; gap: 6px; min-width: 0; }
.wmg-pick .u-select { width: clamp(150px, 13vw, 190px); font-weight: 700; cursor: pointer; }
.wmg-pick .u-select:hover { border-color: var(--text-3); }
/* A click on a <select> matches :focus-visible too, so the pickers get no ring
   from the mouse; budgets.js sets .is-kbd while the keyboard is in use. */
.wmg-pick .u-select:focus-visible { outline: none; }
.wmg.is-kbd .wmg-pick .u-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.wmg-swap svg { transition: transform .25s ease-out; }
.wmg-swap:hover svg { transform: rotate(180deg); }
@media (max-width: 1023px) {
    .wmg-pick { flex: 1; }
    .wmg-pick .u-select { flex: 1; min-width: 0; width: auto; }
}
@media (max-width: 639px) {
    .wmg-sources-btn { width: 32px; padding: 0; }
    .wmg-sources-btn span { display: none; }
}

/* 3. Options band ------------------------------------------------------------- */
.wmg-options {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
    padding: 10px 24px; flex: none;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.wmg-options .u-seg button[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }
@media (max-width: 1023px) { .wmg-options { padding: 10px 16px; } }

/* 4. The two country panels --------------------------------------------------- */
.wmg-ledgers {
    display: grid; gap: 16px; padding: 16px;
    grid-template-columns: minmax(0, 1fr);
}
.wmg-ledger { position: relative; padding: 16px; }

/* The head stays one row: the country takes what the key figures leave (its
   period line ends in an ellipsis; the drawer has it in full). Phones give the
   figures their own row. */
.wmg-ledger__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; flex: none; }
.wmg-ledger__id { flex: 1 1 0; display: flex; align-items: center; gap: 10px; min-width: 0; }
.wmg-ledger__id > div { min-width: 0; }
.wmg-ledger__flag { width: 28px; height: 28px; flex: none; border-radius: 999px; box-shadow: 0 0 0 1px var(--border); }
.wmg-ledger__line { display: flex; align-items: center; gap: 8px; }
.wmg-ledger__name { font-size: var(--fs-lg); line-height: 22px; font-weight: 700; white-space: nowrap; }
.wmg-ledger__period { color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* A small pill: the year, and "not to scale" when a page is blown up */
.wmg-pill {
    display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-2); font-size: var(--fs-xs); white-space: nowrap;
}
.wmg-pill.is-alert { color: var(--alert); font-weight: 700; }

/* Key figures: revenue, spending, and the gap between them */
.wmg-figs { margin-left: auto; display: flex; gap: 20px; }
.wmg-fig { display: flex; flex-direction: column; align-items: flex-end; }
.wmg-fig b { font-size: var(--fs-md); line-height: 20px; }
.wmg-fig span { color: var(--text-3); font-size: var(--fs-xs); line-height: 16px; white-space: nowrap; }
.wmg-fig.is-deficit b { color: var(--alert); }
@media (max-width: 639px) {
    .wmg-ledger__id { flex-basis: 100%; }
    .wmg-figs { margin-left: 0; width: 100%; justify-content: space-between; }
    .wmg-fig { align-items: flex-start; }
}

.wmg-badge { display: none; flex-basis: 100%; align-items: center; gap: 12px; flex-wrap: wrap; }
.wmg-ledger.is-big .wmg-badge { display: flex; }

/* 5. Maps ---------------------------------------------------------------------- */
.wmg-map { margin-top: 14px; }
.wmg-map__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; min-height: 18px; }
.wmg-crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); line-height: 16px; color: var(--text-3); }
.wmg-crumbs b { color: var(--text); font-weight: 700; }
/* The box a map may fill. Scrolling layouts give it a height here; the
   full-viewport layout (section 7) lets it take what is left instead. */
.wmg-map__area {
    position: relative;
    margin-top: 8px;
    height: clamp(15rem, 64vw, 30rem);
}
.wmg-ghost {
    position: absolute; top: 0; left: 0;
    border: 1px dashed var(--border);
    border-radius: 4px;
    pointer-events: none;
}
.wmg-frame {
    position: relative;
    transition: width .7s cubic-bezier(.2, .8, .2, 1), height .7s cubic-bezier(.2, .8, .2, 1);
}
.wmg-frame svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* Tiles: straight edges on whole pixels; the 3px treemap padding is the border. */
.wmg-tile { cursor: default; outline: none; }
.wmg-tile.is-zoomable { cursor: zoom-in; }
.wmg-tile__shape { stroke: none; shape-rendering: crispEdges; }
.wmg-tile.is-deficit .wmg-tile__shape { stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 5 4; shape-rendering: auto; }
/* Hover and focus change the outline only. */
.wmg-tile:hover .wmg-tile__shape { stroke: var(--text); stroke-width: 2; stroke-dasharray: none; }
.wmg-tile:focus-visible .wmg-tile__shape { stroke: var(--accent); stroke-width: 3; stroke-dasharray: none; }
.wmg-tile text { font-family: var(--font); font-variant-numeric: tabular-nums; pointer-events: none; }
.wmg-tile__name { font-size: 11px; font-weight: 700; }
.wmg-tile__value { font-size: 10px; }
/* Text on a data fill: the chrome pair, which is the same dark and light in
   both themes, because the fills are too. On the empty tile: the page ink. */
.wmg-tile text.t-dark { fill: rgb(var(--pe-chrome)); }
.wmg-tile text.t-light { fill: rgb(var(--pe-on-chrome)); }
.wmg-tile text.t-ink { fill: var(--text); }
/* Category icons are line drawings in the text colour. */
.wmg-tile__doodle { fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.wmg-tile__doodle.t-dark { stroke: rgb(var(--pe-chrome)); }
.wmg-tile__doodle.t-light { stroke: rgb(var(--pe-on-chrome)); }
.wmg-tile__doodle.t-ink { stroke: var(--text); }

/* Redraw: tiles fade in one after another, then their labels. */
.wmg-frame.is-drawing .wmg-tile__shape {
    animation: wmg-fade .45s ease-out both;
    animation-delay: var(--d, 0s);
}
.wmg-frame.is-drawing .wmg-tile text, .wmg-frame.is-drawing .wmg-tile__doodle {
    animation: wmg-fade .4s ease-out both;
    animation-delay: calc(var(--d, 0s) + .25s);
}
@keyframes wmg-fade { from { opacity: 0; } to { opacity: 1; } }

/* Notes: facts computed from the numbers, under the maps */
.wmg-notes { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 2px 20px; flex: none; }
.wmg-note { font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.wmg-map > .wmg-note { margin-top: 6px; }

/* 6. The "hard to see" card --------------------------------------------------- */
.wmg-popup {
    position: absolute; z-index: 5; right: 16px;
    max-width: 280px; padding: 14px 16px;
    animation: wmg-pop .2s ease-out both;
}
@keyframes wmg-pop { from { opacity: 0; transform: translateY(6px); } }
.wmg-popup p { font-size: var(--fs-sm); line-height: 18px; color: var(--text); }
.wmg-popup p em { color: var(--text-2); font-style: normal; }
.wmg-popup__actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.wmg-popup .u-primary { height: 32px; padding: 0 14px; font-size: var(--fs-sm); }

/* 7. One viewport ------------------------------------------------------------- */
/* Wide and tall enough: no page scroll. The bar and the options band take their
   height, the panels the rest, and inside each panel the head and notes take
   theirs while the two maps split what remains. Shorter screens scroll even when
   wide (the shell's body would otherwise clip them). */
@media (min-width: 1024px) and (min-height: 600px) {
    .wmg { height: 100vh; height: 100dvh; }
    .wmg-ledgers { flex: 1 1 auto; min-height: 0; padding: 16px 24px 24px;
                   grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
    .wmg-ledger { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
    .wmg-map { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
    .wmg-map__bar { flex: none; }
    .wmg-map__area { flex: 1 1 0; min-height: 0; height: auto; }
}
@media (min-width: 1024px) and (max-height: 599px) {
    .u-page { height: auto; overflow: auto; }
    .wmg-ledgers { padding: 16px 24px 24px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* 8. Hover card (the shell's #tool-tip) --------------------------------------- */
.u-tip .tip-title { display: block; font-weight: 700; }
.u-tip .tip-status { display: inline-block; margin-top: 4px; padding: 0 6px; border: 1px solid currentColor; border-radius: 999px;
                     font-size: var(--fs-xs); line-height: 16px; opacity: .85; }
.u-tip .tip-note, .u-tip .tip-src, .u-tip .tip-act { display: block; margin-top: 4px; font-size: var(--fs-xs); line-height: 16px; opacity: .75; }
.u-tip .tip-act { opacity: .6; }

/* 9. Drawer: method, each country's sources, and every number ----------------- */
.wmg-method .u-label { margin-bottom: 8px; }
.wmg-source { padding-top: 24px; border-top: 1px solid var(--border); }
.wmg-source__head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: var(--fs-md); font-weight: 700; color: var(--text); }
.wmg-source__head img { border-radius: 999px; }
.wmg-source.is-hit .wmg-source__head { color: var(--accent); }
.wmg-source.is-hit { scroll-margin-top: 16px; }
.wmg-source__notes { margin-top: 8px; padding-left: 18px; list-style: disc; }
.wmg-source__notes li + li { margin-top: 4px; }
.wmg-source__list { margin-top: 10px; padding-left: 20px; list-style: decimal; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.wmg-source__list li + li { margin-top: 4px; }
.wmg-source__list a { overflow-wrap: anywhere; }

.wmg-table { padding-top: 24px; border-top: 1px solid var(--border); }
.wmg-table summary { cursor: pointer; }
.wmg-table summary:hover { color: var(--text); }
.wmg-table__country { margin-top: 16px; overflow-x: auto; }
.wmg-table table { margin-top: 6px; border-collapse: collapse; font-size: var(--fs-xs); line-height: 16px; min-width: 100%; }
.wmg-table caption { text-align: left; padding: 4px 0; color: var(--text-3); font-size: var(--fs-xs); }
.wmg-table th, .wmg-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.wmg-table th[scope="row"] { text-align: left; white-space: normal; min-width: 9rem; font-weight: 400; color: var(--text); }
.wmg-table thead th { color: var(--text-3); font-weight: 400; }
.wmg-table thead th:first-child { text-align: left; }

/* 10. Reduced motion (the shell already stops its own transitions) ------------ */
@media (prefers-reduced-motion: reduce) {
    .wmg-frame, .wmg-swap svg { transition: none; }
    .wmg-frame.is-drawing .wmg-tile__shape,
    .wmg-frame.is-drawing .wmg-tile text,
    .wmg-frame.is-drawing .wmg-tile__doodle, .wmg-popup { animation: none; }
}
