/* ==========================================================================
   Charts
   Conventions (keep these when adding charts):
   - Each area is a coloured bar (--area-1/2/3, in that order).
   - Australia is ALWAYS a thin --baseline line, never a bar or a colour.
   - Values are printed beside bars (mono), so colour is never the only cue.
   - Grain: fine dots that build up towards the value (toggle via
     <html data-grain="on|off">).
   ========================================================================== */

/* ---- Grain ------------------------------------------------------------- */
[data-grain="on"] .grain-h,
[data-grain="on"] .grain-v {
  -webkit-mask-size: 128px 128px, 100% 100%;
          mask-size: 128px 128px, 100% 100%;
  -webkit-mask-repeat: repeat, no-repeat;
          mask-repeat: repeat, no-repeat;
  -webkit-mask-composite: source-in;
          mask-composite: intersect;
}
[data-grain="on"] .grain-h {
  -webkit-mask-image: url(../assets/grain.png), linear-gradient(to right, rgba(0,0,0,.2), #000 70%);
          mask-image: url(../assets/grain.png), linear-gradient(to right, rgba(0,0,0,.2), #000 70%);
}
[data-grain="on"] .grain-v {
  -webkit-mask-image: url(../assets/grain.png), linear-gradient(to top, rgba(0,0,0,.2), #000 70%);
          mask-image: url(../assets/grain.png), linear-gradient(to top, rgba(0,0,0,.2), #000 70%);
}

/* ---- Horizontal bar rows ---------------------------------------------- */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: flex; flex-direction: column; gap: 6px; }
.bar-row__head { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.bar-row__head .num { font-size: 13px; }
.bar-row__multi { display: grid; grid-template-columns: minmax(0, 1fr) 56px; gap: 6px 10px; align-items: center; }
.bar-row__multi .num { font-size: 13px; text-align: right; }

.bar { position: relative; height: 10px; border-radius: 5px; background: var(--bg); }
.bar--thin { height: 8px; border-radius: 4px; }
.bar__fill { position: absolute; left: 0; top: 0; bottom: 0; width: var(--w); background: var(--c, var(--area-1)); border-radius: 0 4px 4px 0; }
.bar__base { position: absolute; top: -4px; bottom: -4px; left: var(--x); width: 2px; margin-left: -1px; background: var(--baseline); }

/* ---- Column chart (age profile) --------------------------------------- */
.age-chart { display: flex; flex-direction: column; gap: 10px; }
.age-chart__readout { font-size: 13.5px; min-height: 20px; }
.age-chart__plot { display: flex; gap: 8px; }
.age-chart__axis { position: relative; width: 28px; flex: none; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.age-chart__axis span { position: absolute; right: 0; transform: translateY(50%); }
.age-chart__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.age-chart__area { position: relative; height: var(--h, 170px); border-bottom: 1px solid var(--axis); }
.age-chart__grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.age-chart__cols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n, 9), minmax(0, 1fr)); gap: 6px; }
.age-col { position: relative; height: 100%; padding: 0; border: 0; border-radius: 4px 4px 0 0; background: transparent; display: flex; align-items: flex-end; gap: 2px; padding: 0 2px; }
.age-col[aria-pressed="true"] { background: var(--line); }
.age-col__bar { flex: 1; height: var(--h); background: var(--c); border-radius: 4px 4px 0 0; }
.age-col__base { position: absolute; left: -2px; right: -2px; bottom: var(--x); height: 2px; background: var(--baseline); pointer-events: none; }
.age-chart__labels { display: grid; grid-template-columns: repeat(var(--n, 9), minmax(0, 1fr)); gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); text-align: center; }

/* ---- Measures table ---------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.measures { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 14px; }
.measures th, .measures td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
.measures thead th { padding-top: 8px; padding-bottom: 8px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.measures th:first-child, .measures td:first-child { padding-left: 0; }
.measures th:last-child, .measures td:last-child { padding-right: 0; text-align: right; }
.measures tbody th { font-weight: 500; }
.measures .unit { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.measures .val { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.measures .val strong { font-size: 16px; font-weight: 600; }
.measures .val span { font-size: 12.5px; color: var(--muted); }
.measures .bar { margin-top: 8px; height: 8px; }
.measures .aus { font-size: 16px; font-weight: 600; }

/* Mobile: one card per measure */
.measure-card { display: flex; flex-direction: column; gap: 10px; }
.measure-card__head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }

/* ---- Map --------------------------------------------------------------- */
.map { position: relative; width: 100%; height: 100%; }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map path[data-state] { stroke: var(--card); stroke-width: 1.5; stroke-linejoin: round; transition: opacity .15s; }
.map path[data-state]:hover { opacity: .85; }
.map .map-pin { fill: var(--map-pin); stroke: var(--card); stroke-width: 3; }
.map .map-label rect { fill: var(--card); stroke: var(--line-strong); }
.map .map-label text { fill: var(--text); font-family: var(--font-sans); font-weight: 600; }

.map-card__canvas { position: relative; height: 500px; background: var(--card); }
.map-card__canvas .map { position: absolute; top: 56px; left: 16px; right: 72px; bottom: 16px; width: auto; height: auto; }
.map-card__overlay { position: absolute; z-index: 2; }
.map-card__tl { top: 14px; left: 14px; }
.map-card__readout { top: 62px; left: 14px; min-width: 180px; padding: 8px 12px; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-md); display: flex; flex-direction: column; }
.map-card__readout .name { font-size: 12.5px; color: var(--muted); }
.map-card__readout .value { font-size: 16px; font-weight: 600; }
.map-card__tools { top: 14px; right: 14px; display: flex; flex-direction: column; gap: 8px; }
.toolstack { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius-md); overflow: hidden; }
.toolstack button { width: 44px; height: 44px; border: 0; border-bottom: 1px solid var(--line); background: var(--card); color: var(--text); display: flex; align-items: center; justify-content: center; font-size: 20px; }
.toolstack button:last-child { border-bottom: 0; }
.toolstack button[aria-pressed="true"] { background: var(--line); }
.toolstack svg { width: 18px; height: 18px; }
.map-card__foot { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 24px; padding: 14px 16px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field select { height: 36px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 0 8px; background: var(--card); }

.legend { flex: 1 1 300px; display: flex; flex-direction: column; gap: 6px; }
.legend__ramp, .legend__labels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; }
.legend__ramp span { height: 10px; }
.legend__ramp span:first-child { border-radius: 4px 0 0 4px; }
.legend__ramp span:last-child { border-radius: 0 4px 4px 0; }
.legend__labels { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.legend--mini { flex: none; flex-direction: row; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.legend--mini .legend__ramp { display: flex; gap: 2px; }
.legend--mini .legend__ramp span { width: 16px; height: 8px; }
