/* Scalisi Markets
   Fog grey ground, cold-chain blue for interaction, red for cost going up, green for cost going down.
   One family (Archivo) used at two widths: condensed and heavy for commodity names, normal for everything else. */

:root {
  color-scheme: light;
  --bg: #EEF2EF;
  --surface: #FFFFFF;
  --ink: #17211C;
  --ink-2: #4D5A53;
  --ink-3: #75817A;
  --line: #D3DBD6;
  --line-2: #E4E9E6;
  --accent: #1E5B8F;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCE8F2;
  --up: #B3261E;
  --up-soft: #F7E2E0;
  --down: #1F7A4D;
  --down-soft: #DDEFE5;
  --track: #DEE5E1;
  --range: #93A39A;
  --band: rgba(30, 91, 143, .13);
  --band-mostly: rgba(30, 91, 143, .30);
  --c1: #1E5B8F; --c2: #C27C0E; --c3: #7B4FA0; --c4: #2F8F83; --c5: #8A5A2B; --c6: #5E6A63;
  --warn: #9A6400;
  --font: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --radius: 10px;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101613; --surface: #18201C; --ink: #E7EDE9; --ink-2: #A4B0A9; --ink-3: #7D8A83;
    --line: #2B3631; --line-2: #222B27; --accent: #7DB2E3; --accent-ink: #0E1A24; --accent-soft: #1C2D3C;
    --up: #F2867D; --up-soft: #3A1F1D; --down: #66C895; --down-soft: #193225;
    --track: #27312C; --range: #5D6C64; --band: rgba(125, 178, 227, .14); --band-mostly: rgba(125, 178, 227, .32);
    --c1: #7DB2E3; --c2: #E8A93E; --c3: #B892D8; --c4: #5CC2B5; --c5: #C99A6A; --c6: #A4B0A9; --warn: #E8B44E;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101613; --surface: #18201C; --ink: #E7EDE9; --ink-2: #A4B0A9; --ink-3: #7D8A83;
  --line: #2B3631; --line-2: #222B27; --accent: #7DB2E3; --accent-ink: #0E1A24; --accent-soft: #1C2D3C;
  --up: #F2867D; --up-soft: #3A1F1D; --down: #66C895; --down-soft: #193225;
  --track: #27312C; --range: #5D6C64; --band: rgba(125, 178, 227, .14); --band-mostly: rgba(125, 178, 227, .32);
  --c1: #7DB2E3; --c2: #E8A93E; --c3: #B892D8; --c4: #5CC2B5; --c5: #C99A6A; --c6: #A4B0A9; --warn: #E8B44E;
}

*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 64px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 30; background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ type */

.display {
  font-stretch: 72%; font-weight: 800; letter-spacing: -0.01em;
  font-size: clamp(2.1rem, 7vw, 3.4rem); line-height: .98; margin: 0;
}
.title {
  font-stretch: 78%; font-weight: 750; font-size: 1.5rem; line-height: 1.1; margin: 0;
}
.name { font-stretch: 76%; font-weight: 750; font-size: 1.22rem; line-height: 1.15; }
.sub { color: var(--ink-2); margin: .35rem 0 0; }
.small { font-size: .875rem; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
h2.section {
  font-stretch: 85%; font-weight: 700; font-size: 1.05rem; margin: 2rem 0 .5rem;
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
}
h2.section .muted { font-weight: 400; font-stretch: 100%; font-size: .875rem; }

/* ------------------------------------------------------------ frame */

.app { min-height: 100vh; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1rem; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.mark { display: flex; align-items: center; gap: .55rem; color: var(--ink); font-stretch: 80%; font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
.mark:hover { text-decoration: none; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.asof { color: var(--ink-2); font-size: .85rem; white-space: nowrap; }
@media (max-width: 640px) { .asof { display: none; } }
.link-btn { background: none; border: 0; padding: .25rem; color: var(--accent); cursor: pointer; font-size: .9rem; white-space: nowrap; }

.demo {
  background: #F6E7C1; color: #4A3500; padding: .6rem 1rem; font-size: .9rem; border-bottom: 1px solid #E5CF8F;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .demo { background: #3A2E12; color: #F0D899; border-color: #5A4718; } }

.view { padding: 1.25rem 1rem 7rem; max-width: 980px; margin: 0 auto; outline: none; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .55rem .25rem .5rem; color: var(--ink-3); font-size: .72rem; font-weight: 600;
}
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); }
.tabs a[aria-current="page"] svg { stroke-width: 2.2; }
.badge {
  position: absolute; top: .3rem; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--up); color: #fff; font-size: .7rem; line-height: 18px; text-align: center;
}

@media (min-width: 900px) {
  .app {
    display: grid; grid-template-columns: 210px 1fr; grid-template-rows: auto auto 1fr;
    /* full-height divider between the sidebar and the page */
    background: linear-gradient(to right, transparent 209px, var(--line) 209px, var(--line) 210px, transparent 210px);
  }
  .topbar { grid-column: 1 / -1; }
  .demo { grid-column: 1 / -1; }
  .tabs {
    position: sticky; top: 60px; bottom: auto; left: auto; right: auto; align-self: start;
    grid-row: 3; display: flex; flex-direction: column; gap: .15rem; padding: 1rem .75rem;
    background: transparent; border-top: 0;
  }
  .tabs a { flex-direction: row; gap: .7rem; padding: .6rem .7rem; font-size: .95rem; border-radius: 8px; }
  .tabs a[aria-current="page"] { background: var(--accent-soft); }
  .badge { position: static; margin-left: auto; }
  .view { grid-row: 3; padding: 2rem 2.5rem 4rem; width: 100%; }
}

/* ------------------------------------------------------------ controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 42px; padding: .5rem 1rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.btn.on svg { fill: currentColor; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px;
  background: var(--line-2); border: 1px solid var(--line); max-width: 100%; overflow-x: auto;
}
.seg button {
  border: 0; background: transparent; padding: .38rem .8rem; border-radius: 7px; cursor: pointer;
  color: var(--ink-2); font-weight: 600; font-size: .9rem; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; padding-bottom: .25rem; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: .35rem .8rem; font-size: .88rem; cursor: pointer; color: var(--ink-2); white-space: nowrap;
}
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg); }

.search {
  width: 100%; padding: .7rem .9rem; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); font-size: 1rem;
}
.controls { display: grid; gap: .75rem; margin: 1.25rem 0 .5rem; }
@media (min-width: 700px) { .controls { grid-template-columns: minmax(220px, 340px) auto; align-items: center; justify-content: space-between; } }

select.select {
  padding: .5rem 2rem .5rem .75rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 15px) 55%, calc(100% - 10px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
  font-weight: 600;
}

/* ------------------------------------------------------------ lists */

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list > li + li { border-top: 1px solid var(--line-2); }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: .2rem 1rem; align-items: center;
  padding: .8rem 1rem; color: var(--ink);
}
a.row:hover { text-decoration: none; background: var(--line-2); }
.row .r { text-align: right; }
.row .meta { color: var(--ink-2); font-size: .875rem; }
.row .price { font-weight: 650; white-space: nowrap; }
.row.line { grid-template-areas: "a p" "b p" "s s"; row-gap: .1rem; }
.row.line .la { grid-area: a; }
.row.line .lb { grid-area: b; }
.row.line .r { grid-area: p; align-self: start; }
.row.line .strip-cell { grid-area: s; padding-top: .5rem; }
@media (min-width: 760px) {
  .row.line { grid-template-columns: minmax(120px, 1fr) minmax(150px, 1.2fr) minmax(140px, 1.1fr) 116px; grid-template-areas: "a b s p"; }
  .row.line .r { align-self: center; }
  .row.line .strip-cell { padding-top: 0; }
}

.group-head { padding: .9rem 1rem .5rem; background: var(--line-2); font-weight: 650; font-size: .92rem; color: var(--ink-2); }
.group-head b { color: var(--ink); }
.gh { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.gw { flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: .25rem .7rem; font-size: .82rem; font-weight: 600; cursor: pointer; }
.gw.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.dist-head { padding: .6rem 1rem; font-size: .92rem; font-weight: 650; background: var(--surface); border-top: 1px solid var(--line); }
.list > li.group-head + li.dist-head { border-top: 0; }
.list > li.group-head + li { border-top: 0; }

.updown { display: inline-flex; align-items: center; gap: .5rem; font-size: .85rem; color: var(--ink-2); white-space: nowrap; }
.updown .bar { display: inline-flex; width: 64px; height: 6px; border-radius: 3px; overflow: hidden; background: var(--track); }
.updown .bar i { display: block; height: 100%; }
.updown .bar .u { background: var(--up); }
.updown .bar .d { background: var(--down); }

.chg { display: inline-block; font-size: .82rem; font-weight: 650; padding: .1rem .45rem; border-radius: 5px; white-space: nowrap; }
.chg.up { color: var(--up); background: var(--up-soft); }
.chg.down { color: var(--down); background: var(--down-soft); }
.chg.flat { color: var(--ink-2); background: var(--line-2); }

/* The range strip: full low-high range as a thin line, the "mostly" range as a solid block, last report as a tick. */
.strip { position: relative; display: block; height: 12px; border-radius: 3px; background: var(--track); }
.strip-range { position: absolute; top: 5px; height: 2px; background: var(--range); }
.strip-mostly { position: absolute; top: 1px; height: 10px; min-width: 4px; border-radius: 2px; background: var(--ink); }
.strip-prev { position: absolute; top: -3px; width: 2px; height: 18px; margin-left: -1px; background: var(--accent); border-radius: 1px; }

.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font-size: .82rem; color: var(--ink-2); margin: .6rem 0 0; }
.legend .k { display: inline-flex; align-items: center; gap: .4rem; }
.legend .sw { display: inline-block; width: 18px; height: 10px; border-radius: 2px; background: var(--track); position: relative; }
.legend .sw.mostly::after { content: ""; position: absolute; inset: 1px 5px; border-radius: 1px; background: var(--ink); }
.legend .sw.prev::after { content: ""; position: absolute; left: 8px; top: -2px; width: 2px; height: 14px; background: var(--accent); }
.legend .sw.line { height: 3px; background: var(--c); }

/* ------------------------------------------------------------ detail pages */

.back { display: inline-block; margin-bottom: 1rem; font-weight: 600; }
.price-block { display: grid; gap: .25rem; margin: 1.25rem 0 0; }
.price-big { font-stretch: 75%; font-weight: 800; font-size: clamp(2.3rem, 9vw, 3.3rem); line-height: 1; }
.facts { display: flex; flex-wrap: wrap; gap: .35rem 1.25rem; color: var(--ink-2); font-size: .92rem; margin-top: .4rem; }
.facts b { color: var(--ink); font-weight: 600; }
.tag { display: inline-block; font-size: .78rem; font-weight: 650; padding: .1rem .45rem; border-radius: 5px; background: var(--down-soft); color: var(--down); vertical-align: middle; }

.chart-wrap { margin-top: 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem .75rem .75rem; }
.chart-tools { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: space-between; margin-bottom: .6rem; }
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: var(--line-2); }
.chart .axis text { fill: var(--ink-3); font-size: 11px; font-family: var(--font); }
.chart .tip {
  position: absolute; pointer-events: none; z-index: 2; min-width: 150px;
  background: var(--ink); color: var(--bg); border-radius: 8px; padding: .45rem .6rem; font-size: .82rem; line-height: 1.35;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.chart .tip b { font-weight: 700; }
.chart .tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: .35rem; }
.chart-empty { padding: 3rem 1rem; text-align: center; color: var(--ink-2); }

.row.rec { font-size: .95rem; padding: .65rem 1rem; }
.row.rec > span:first-child { white-space: nowrap; }
.row.rec .tone { grid-column: 1 / -1; color: var(--ink-2); font-size: .85rem; }
.row.rec .r .meta { display: block; }
@media (min-width: 760px) {
  .row.rec { grid-template-columns: 130px 260px 1fr; }
  .row.rec .r { text-align: left; }
  .row.rec .r .meta { display: inline; }
  .row.rec .tone { grid-column: auto; }
}

/* Phones: district name on its own line above its 12 month cells. Wider screens: name in a left column. */
.heat { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; font-size: .82rem; }
.heat .corner { display: none; }
.heat .h { color: var(--ink-3); text-align: center; padding-bottom: .2rem; }
.heat .h.now { color: var(--ink); font-weight: 700; }
.heat .m3 { display: none; }
.heat .d { grid-column: 1 / -1; padding: .55rem 0 .1rem; line-height: 1.2; font-weight: 600; }
.heat .c { height: 22px; border-radius: 3px; background: var(--accent); }
@media (min-width: 700px) {
  .heat { grid-template-columns: minmax(150px, 1.4fr) repeat(12, minmax(26px, 1fr)); }
  .heat .corner { display: block; }
  .heat .m1 { display: none; }
  .heat .m3 { display: inline; }
  .heat .d { grid-column: auto; padding: 0 .5rem 0 0; align-self: center; font-weight: 400; }
  .heat .c { height: 26px; }
}
.heat .c.now { outline: 2px solid var(--ink); outline-offset: -2px; }
.heat-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }

.avail { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--ink-2); white-space: nowrap; }
.avail i { display: inline-flex; gap: 2px; }
.avail i span { width: 6px; height: 12px; border-radius: 1.5px; background: var(--track); }
.avail.l0 i span:nth-child(-n+1), .avail.l1 i span:nth-child(-n+2) { background: var(--down); }
.avail.l2 i span:nth-child(-n+3) { background: var(--ink-2); }
.avail.l3 i span:nth-child(-n+4), .avail.l4 i span:nth-child(-n+5) { background: var(--up); }

.prose { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .25rem 1.25rem 1rem; max-width: 72ch; }
.prose h3 { font-stretch: 82%; font-weight: 750; font-size: 1.12rem; margin: 1.25rem 0 .35rem; }
.prose ul { padding-left: 1.2rem; margin: .3rem 0; }
.prose li { margin: .3rem 0; }
.prose p { margin: .4rem 0; }

.empty { padding: 2.5rem 1.25rem; text-align: center; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty b { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: .3rem; }
.error-box { padding: 1rem 1.25rem; border-radius: var(--radius); background: var(--up-soft); color: var(--ink); }
.loading { padding: 3rem 0; text-align: center; color: var(--ink-3); }
.more { display: block; width: 100%; padding: .8rem; border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; text-align: center; }

.toggle { position: relative; width: 44px; height: 26px; flex: none; appearance: none; border-radius: 13px; background: var(--track); border: 1px solid var(--line); cursor: pointer; margin: 0; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.toggle:checked { background: var(--accent); border-color: var(--accent); }
.toggle:checked::after { transform: translateX(18px); }
.icon-btn { border: 0; background: none; color: var(--ink-3); padding: .4rem; cursor: pointer; border-radius: 6px; }
.icon-btn:hover { color: var(--up); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ------------------------------------------------------------ sheet + login */

.sheet {
  border: 0; padding: 0; width: min(440px, calc(100% - 1.5rem)); border-radius: 14px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.sheet::backdrop { background: rgba(10, 16, 13, .45); }
.sheet form { padding: 1.25rem; display: grid; gap: .9rem; }
.sheet h2 { margin: 0; font-stretch: 80%; font-weight: 750; font-size: 1.3rem; }
.sheet .choice { display: grid; gap: .45rem; }
.sheet .choice label { display: flex; gap: .6rem; align-items: center; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.sheet .choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.sheet .amount { display: flex; align-items: center; gap: .5rem; }
.sheet .amount input { width: 9rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 1.1rem; }
.sheet .check { display: flex; gap: .55rem; align-items: center; }
.sheet .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(380px, 100%); display: grid; gap: .9rem; }
.login-card h1 { margin: .25rem 0 0; font-stretch: 72%; font-weight: 800; font-size: 2.4rem; line-height: 1; }
.login-card p { margin: 0; color: var(--ink-2); }
.login-card label { display: grid; gap: .3rem; font-weight: 600; font-size: .92rem; }
.login-card input { padding: .75rem .85rem; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); font-size: 1rem; }
.form-error { color: var(--up); min-height: 1.2em; font-size: .92rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
