:root {
  --navy: #173a63;
  --navy-dark: #0e2947;
  --blue: #2f76b7;
  --teal: #159b8d;
  --green: #2f9e62;
  --amber: #efa900;
  --red: #df3348;
  --gray: #93a0af;
  --ink: #1e2d3e;
  --muted: #667589;
  --line: #dce4ec;
  --soft: #f3f6f9;
  --white: #fff;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--soft);
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  line-height: 1.55;
}
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
button, a, select, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(47, 118, 183, .25); outline-offset: 3px; }
.shell { width: min(1180px, calc(100% - 40px)); margin-inline: auto; }
section { scroll-margin-top: 90px; }
.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;
}

.site-header {
  position: sticky; top: 0; z-index: 1000;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.header-inner { min-height: 74px; display: flex; align-items: center; gap: 28px; }
.brand { display: inline-flex; align-items: center; gap: 11px; min-width: max-content; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  color: var(--white); background: var(--navy); border-radius: 12px;
  font-size: 13px; font-weight: 850; letter-spacing: .04em;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .13);
}
.brand > span:last-child { display: grid; line-height: 1.1; }
.brand strong { color: var(--navy-dark); font-size: 15px; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 10px; }
nav { display: flex; gap: 26px; margin-left: auto; }
nav a { color: #4a5b70; font-size: 12px; font-weight: 700; }
nav a:hover { color: var(--navy); }
.auto-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px;
  color: #177548; background: #e0f4e9; border-radius: 999px;
  font-size: 10px; font-weight: 850; letter-spacing: .04em; text-transform: uppercase;
}
.auto-badge i, .source-status i, .freshness-strip i {
  width: 8px; height: 8px; display: inline-block; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 4px rgba(47, 158, 98, .13);
}

.hero { position: relative; overflow: hidden; color: var(--white); background: var(--navy-dark); }
.hero::before, .hero::after {
  position: absolute; content: ""; border-radius: 50%; pointer-events: none;
}
.hero::before {
  width: 440px; height: 440px; right: -130px; top: -270px;
  border: 80px solid rgba(21, 155, 141, .18);
}
.hero::after {
  width: 230px; height: 230px; left: 47%; bottom: -200px;
  border: 48px solid rgba(239, 169, 0, .12);
}
.hero-grid {
  position: relative; z-index: 1; min-height: 480px; padding-block: 64px;
  display: grid; grid-template-columns: 1.25fr .75fr; align-items: center; gap: 72px;
}
.eyebrow, .kicker {
  display: block; color: var(--teal); font-size: 10px; font-weight: 850;
  letter-spacing: .12em;
}
.hero .eyebrow { color: #62d1c5; }
.hero-copy h1 {
  max-width: 700px; margin: 15px 0 20px; font-size: clamp(42px, 5.3vw, 68px);
  line-height: 1.03; letter-spacing: -.045em;
}
.hero-copy h1 em { color: #f0bd42; font-style: normal; }
.hero-copy p { max-width: 650px; margin: 0; color: #d1deea; font-size: 16px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 28px; }
.button {
  min-height: 46px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 19px; border: 1px solid transparent; border-radius: 11px;
  font-size: 12px; font-weight: 800; transition: transform .15s ease;
}
.button:hover { transform: translateY(-2px); }
.button.primary { color: #17283c; background: var(--amber); }
.button.secondary { color: var(--white); background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.25); }
.source-card {
  padding: 27px; color: var(--ink); background: var(--white); border-radius: 20px;
  box-shadow: 0 28px 70px rgba(2, 20, 38, .28);
}
.source-label { color: var(--muted); font-size: 9px; font-weight: 850; letter-spacing: .1em; }
.source-status { display: flex; align-items: center; gap: 10px; margin: 10px 0 22px; color: var(--navy-dark); }
.source-status i.loading { background: var(--amber); box-shadow: 0 0 0 4px rgba(239,169,0,.15); }
.source-status i.failed { background: var(--red); box-shadow: 0 0 0 4px rgba(223,51,72,.13); }
.source-status strong { font-size: 18px; }
.source-card dl { margin: 0; display: grid; gap: 0; border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.source-card dl div { display: flex; justify-content: space-between; gap: 14px; padding: 12px 13px; border-bottom: 1px solid var(--line); }
.source-card dl div:last-child { border-bottom: 0; }
.source-card dt { color: var(--muted); font-size: 10px; }
.source-card dd { margin: 0; color: var(--navy-dark); font-size: 10px; font-weight: 800; text-align: right; }
.source-card > small { display: block; margin-top: 15px; color: #8491a1; font-size: 9px; }

.dashboard { padding-top: 76px; }
.section-heading, .panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; }
.section-heading h2, .panel-heading h2 {
  margin: 6px 0 4px; color: var(--navy-dark); font-size: clamp(27px, 3vw, 38px);
  line-height: 1.15; letter-spacing: -.03em;
}
.section-heading p { max-width: 650px; margin: 0; color: var(--muted); font-size: 13px; }
.province-select { min-width: 260px; display: grid; gap: 6px; }
.province-select > span { color: var(--muted); font-size: 10px; font-weight: 750; }
.province-select select {
  width: 100%; min-height: 45px; padding: 0 40px 0 13px; color: var(--navy-dark);
  background: var(--white); border: 1px solid #cad5df; border-radius: 10px;
  font-size: 12px; font-weight: 750;
}
.freshness-strip {
  display: flex; align-items: center; gap: 9px; margin-top: 27px; padding: 10px 13px;
  color: #506176; background: #e7eef4; border-radius: 9px; font-size: 10px;
}
.freshness-strip span { flex: 1; }
.freshness-strip button {
  padding: 5px 9px; color: var(--navy); background: var(--white);
  border: 1px solid #cbd7e2; border-radius: 7px; cursor: pointer; font-size: 9px; font-weight: 800;
}
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; margin-top: 17px; }
.kpi-card {
  position: relative; min-height: 157px; padding: 21px; overflow: hidden;
  background: var(--white); border: 1px solid var(--line); border-radius: 15px;
  box-shadow: 0 10px 28px rgba(31, 45, 61, .04);
}
.kpi-card::after {
  position: absolute; right: -18px; bottom: -44px; width: 100px; height: 100px;
  content: ""; border: 18px solid rgba(47, 118, 183, .06); border-radius: 50%;
}
.kpi-symbol {
  min-width: 34px; height: 27px; display: inline-flex; align-items: center; justify-content: center;
  padding-inline: 7px; color: var(--navy); background: #e6eef7; border-radius: 8px;
  font-size: 9px; font-weight: 850;
}
.kpi-card p { margin: 14px 0 2px; color: var(--muted); font-size: 11px; }
.kpi-card > strong { display: block; color: var(--navy-dark); font-size: 24px; letter-spacing: -.035em; }
.kpi-card > small { display: block; margin-top: 5px; color: #8593a3; font-size: 9px; }
.kpi-card.risk.stable .kpi-symbol { color: #197447; background: #dff4e8; }
.kpi-card.risk.alert .kpi-symbol { color: #8a6100; background: #fff1c6; }
.kpi-card.risk.high .kpi-symbol { color: #a51e31; background: #ffe1e6; }
.kpi-card.risk.missing .kpi-symbol { color: #5e6977; background: #e9edf1; }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: 17px; box-shadow: 0 11px 32px rgba(31,45,61,.045); }
.map-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .65fr); gap: 17px; padding-block: 18px 76px; }
.map-panel, .national-card { padding: 25px; }
.panel-heading { align-items: flex-start; }
.panel-heading h2 { font-size: 22px; }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 11px; color: var(--muted); font-size: 9px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i, .chart-legend i { width: 8px; height: 8px; display: inline-block; border-radius: 50%; }
.legend i.stable { background: var(--green); }
.legend i.alert { background: var(--amber); }
.legend i.high { background: var(--red); }
.legend i.missing { background: var(--gray); }
#province-map {
  height: 455px; margin-top: 20px; overflow: hidden; background: #dfe9ef;
  border: 1px solid #d5dfe8; border-radius: 13px;
}
.map-note { margin: 12px 0 0; color: #8391a1; font-size: 9px; }
.leaflet-popup-content { font-family: "Segoe UI", Arial, sans-serif; }
.map-popup { min-width: 155px; }
.map-popup strong { display: block; color: var(--navy-dark); font-size: 13px; }
.map-popup span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.map-popup b { display: block; margin-top: 8px; color: var(--navy); font-size: 15px; }
.national-card h3 { margin: 7px 0 22px; color: var(--navy-dark); font-size: 20px; }
.national-average { padding-bottom: 19px; border-bottom: 1px solid var(--line); }
.national-average span, .national-extremes span { display: block; color: var(--muted); font-size: 9px; }
.national-average strong { display: block; margin-top: 3px; color: var(--navy-dark); font-size: 31px; letter-spacing: -.04em; }
.national-extremes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.national-extremes > div { padding: 12px; background: var(--soft); border-radius: 10px; }
.national-extremes strong { display: block; margin: 4px 0 2px; color: var(--navy-dark); font-size: 11px; }
.national-extremes small { color: var(--muted); font-size: 9px; }
.risk-counts { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 18px; }
.risk-counts span { padding: 8px; border-radius: 8px; font-size: 9px; }
.risk-counts span.stable { color: #197447; background: #e2f4e9; }
.risk-counts span.alert { color: #836000; background: #fff2ce; }
.risk-counts span.high { color: #a51e31; background: #ffe3e8; }
.risk-counts span.missing { color: #5d6876; background: #e9edf1; }

.province-section { padding-block: 75px; background: #e8eef4; border-block: 1px solid #d7e1e9; }
.table-heading { align-items: flex-end; }
.search-box input {
  min-width: 250px; min-height: 42px; padding: 0 13px; color: var(--ink);
  background: var(--white); border: 1px solid #cbd6e0; border-radius: 9px; font-size: 11px;
}
.table-wrap { max-height: 570px; margin-top: 24px; overflow: auto; background: var(--white); border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 10px; }
thead { position: sticky; top: 0; z-index: 2; color: var(--white); background: var(--navy); }
th { padding: 13px 12px; text-align: left; white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #e4eaf0; }
tbody tr:hover { background: #f3f7fa; }
.province-button { padding: 0; color: var(--navy); background: none; border: 0; cursor: pointer; font-size: 10px; font-weight: 800; text-align: left; }
.status-pill, .risk-pill {
  display: inline-flex; align-items: center; justify-content: center; padding: 5px 8px;
  border-radius: 999px; font-size: 8px; font-weight: 850; letter-spacing: .03em;
}
.status-pill.stable, .risk-pill.stable { color: #197447; background: #dff4e8; }
.status-pill.alert, .risk-pill.alert { color: #856000; background: #fff0c1; }
.status-pill.high, .risk-pill.high { color: #a51e31; background: #ffe1e6; }
.status-pill.missing, .risk-pill.missing { color: #5c6876; background: #e8edf1; }

.trend-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(310px, .65fr); gap: 17px; padding-block: 76px; }
.chart-panel { padding: 25px; }
.chart-period { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.history-controls { margin-top: 20px; padding: 14px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; }
.quick-ranges { display: flex; flex-wrap: wrap; gap: 7px; }
.quick-ranges button {
  min-height: 31px; padding: 0 10px; color: var(--navy); background: var(--white);
  border: 1px solid #cbd7e2; border-radius: 8px; cursor: pointer; font-size: 9px; font-weight: 800;
}
.quick-ranges button:hover, .quick-ranges button.active { color: var(--white); background: var(--navy); border-color: var(--navy); }
.history-filter { display: grid; grid-template-columns: 1fr 1fr .9fr auto; align-items: end; gap: 9px; margin-top: 12px; }
.history-filter label { display: grid; gap: 5px; }
.history-filter label span { color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
.history-filter input, .history-filter select {
  width: 100%; min-height: 39px; padding: 0 9px; color: var(--ink); background: var(--white);
  border: 1px solid #cbd7e2; border-radius: 8px; font-size: 10px;
}
.history-filter > button {
  min-height: 39px; padding: 0 13px; color: var(--white); background: var(--blue);
  border: 0; border-radius: 8px; cursor: pointer; font-size: 9px; font-weight: 850;
}
.history-filter > button:hover { background: var(--navy); }
.history-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.history-stats > div { min-width: 0; padding: 10px; background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; }
.history-stats span { display: block; color: var(--muted); font-size: 7px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
.history-stats strong { display: block; margin-top: 4px; overflow-wrap: anywhere; color: var(--navy-dark); font-size: 10px; }
.chart-container { position: relative; width: 100%; min-height: 340px; margin-top: 14px; }
#price-chart { width: 100%; height: 340px; display: block; }
.chart-legend { display: flex; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 9px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { background: var(--blue); }
.chart-legend i.forecast { background: var(--amber); }
.explanation-card { padding: 28px; background: var(--navy-dark); color: var(--white); border-radius: 17px; }
.explanation-card h3 { margin: 15px 0 10px; font-size: 19px; }
.explanation-card > p { min-height: 94px; margin: 0; color: #cbd8e5; font-size: 13px; line-height: 1.7; }
.factor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 21px; }
.factor-grid > div { padding: 12px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); border-radius: 10px; }
.factor-grid span, .recommendation span { display: block; color: #9eb1c3; font-size: 8px; text-transform: uppercase; letter-spacing: .07em; }
.factor-grid strong { display: block; margin-top: 4px; font-size: 15px; }
.recommendation { margin-top: 9px; padding: 13px; background: rgba(239,169,0,.13); border: 1px solid rgba(239,169,0,.3); border-radius: 10px; }
.recommendation strong { display: block; margin-top: 4px; color: #f2c65e; font-size: 12px; }

.flow-section { padding-block: 77px; color: var(--white); background: var(--navy-dark); }
.section-heading.light h2 { color: var(--white); }
.section-heading.light p { color: #afc1d2; }
.flow-section .kicker { color: #62d1c5; }
.flow-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 15px; margin-top: 30px; }
.flow-grid article {
  position: relative; min-height: 150px; display: flex; flex-direction: column; justify-content: flex-end;
  padding: 19px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); border-radius: 13px;
}
.flow-grid article:not(:last-child)::after {
  position: absolute; right: -21px; top: 50%; z-index: 2; width: 27px; height: 27px;
  display: grid; place-items: center; content: "→"; color: var(--navy-dark); background: #f0bd42;
  border: 4px solid var(--navy-dark); border-radius: 50%; font-size: 11px; font-weight: 900;
}
.flow-grid article > span { position: absolute; left: 18px; top: 15px; color: #62d1c5; font-size: 10px; font-weight: 850; }
.flow-grid strong { font-size: 13px; }
.flow-grid small { margin-top: 5px; color: #aec0d1; font-size: 9px; }
.source-explanation { margin-top: 23px; padding: 14px 17px; color: #b8c8d7; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.11); border-radius: 10px; font-size: 10px; }
.source-explanation strong { color: var(--white); }
.method-detail { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }
.method-detail article { padding: 18px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.13); border-radius: 13px; }
.method-detail article > span { color: #62d1c5; font-size: 8px; font-weight: 850; letter-spacing: .08em; }
.method-detail h3 { margin: 8px 0 8px; color: var(--white); font-size: 17px; }
.method-detail p { margin: 0; color: #c6d5e3; font-size: 10px; }
.method-detail ul { margin: 12px 0 0; padding-left: 16px; color: #d5e0ea; font-size: 9px; }
.method-detail li + li { margin-top: 4px; }

footer { padding-block: 29px; color: #9fb2c5; background: #091f36; border-top: 1px solid rgba(255,255,255,.08); }
.footer-inner { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 22px; }
.footer-inner .brand strong { color: var(--white); }
.footer-inner .brand small { color: #91a6b9; }
.footer-inner p { margin: 0; font-size: 9px; text-align: center; }
.footer-inner > a { justify-self: end; color: #d8e3ec; font-size: 10px; font-weight: 750; }
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 2000; max-width: 340px;
  padding: 11px 14px; color: var(--white); background: var(--navy-dark); border-radius: 9px;
  box-shadow: 0 12px 30px rgba(0,0,0,.2); font-size: 10px; opacity: 0; pointer-events: none;
  transform: translateY(10px); transition: .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #a51e31; }

@media (max-width: 980px) {
  nav { display: none; }
  .hero-grid { grid-template-columns: 1fr .85fr; gap: 35px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .map-layout, .trend-layout { grid-template-columns: 1fr; }
  .history-stats { grid-template-columns: repeat(3, 1fr); }
  .flow-grid { grid-template-columns: repeat(3, 1fr); }
  .method-detail { grid-template-columns: 1fr; }
  .flow-grid article:not(:last-child)::after { display: none; }
}

@media (max-width: 720px) {
  .shell { width: min(100% - 28px, 1180px); }
  .header-inner { min-height: 67px; }
  .auto-badge { display: none; }
  .hero-grid { grid-template-columns: 1fr; min-height: auto; padding-block: 52px; }
  .hero-copy h1 { font-size: clamp(38px, 12vw, 54px); }
  .section-heading, .panel-heading { align-items: flex-start; flex-direction: column; }
  .province-select, .search-box, .search-box input { width: 100%; min-width: 0; }
  .kpi-grid { grid-template-columns: 1fr; }
  .map-panel, .national-card, .chart-panel { padding: 20px; }
  .history-filter { grid-template-columns: 1fr 1fr; }
  .history-filter > button { grid-column: 1 / -1; }
  .history-stats { grid-template-columns: 1fr 1fr; }
  #province-map { height: 400px; }
  .legend { justify-content: flex-start; }
  .table-wrap { overflow-x: auto; }
  table { min-width: 760px; }
  .flow-grid { grid-template-columns: 1fr; }
  .flow-grid article { min-height: 120px; }
  .footer-inner { grid-template-columns: 1fr; text-align: center; }
  .footer-inner .brand, .footer-inner > a { justify-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
