/* ============================================================
   k-economy.techvisory.io — shared design system
   Palette: validated dataviz reference instance.
   ============================================================ */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --band: rgba(11, 11, 11, 0.055);
  --chip: rgba(11, 11, 11, 0.05);
  --chip-on: rgba(42, 120, 214, 0.12);
  --shadow: 0 10px 30px rgba(11, 11, 11, 0.07);

  --maxw: 1060px;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #2b2b28;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --good-text: #0ca30c;

    --band: rgba(255, 255, 255, 0.06);
    --chip: rgba(255, 255, 255, 0.06);
    --chip-on: rgba(57, 135, 229, 0.18);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #2b2b28;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --good-text: #0ca30c;

  --band: rgba(255, 255, 255, 0.06);
  --chip: rgba(255, 255, 255, 0.06);
  --chip-on: rgba(57, 135, 229, 0.18);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 16px/1.62 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 760px; }

a { color: var(--series-1); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3, h4 { letter-spacing: -0.018em; line-height: 1.18; margin: 0 0 .5em; }
h1 { font-size: clamp(30px, 4.6vw, 46px); }
h2 { font-size: clamp(22px, 2.8vw, 30px); margin-top: 2.2em; }
h3 { font-size: 18px; margin-top: 1.8em; }
p { margin: 0 0 1.1em; }

.lede { font-size: clamp(17px, 2vw, 20px); color: var(--text-secondary); line-height: 1.55; max-width: 66ch; }
.small { font-size: 13.5px; color: var(--text-secondary); }
.mutedtext { color: var(--muted); }
.tabnum { font-variant-numeric: tabular-nums; }

/* ---------- skip link ---------- */
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--surface-1); color: var(--text-primary);
  padding: 10px 16px; border: 1px solid var(--border-strong); border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---------- header / nav ---------- */
.sitehead {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.sitehead .bar {
  max-width: var(--maxw); margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); flex: none; }
.brand:hover { text-decoration: none; }
.brand .mark { width: 26px; height: 26px; flex: none; }
.brand .txt { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand .txt span { color: var(--muted); font-weight: 450; }

.nav { display: flex; gap: 2px; flex-wrap: nowrap; margin-left: auto; align-items: center; }
.nav a {
  color: var(--text-secondary); text-decoration: none; font-size: 14px;
  padding: 7px 11px; border-radius: 8px; white-space: nowrap;
}
.nav a:hover { background: var(--chip); color: var(--text-primary); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--chip-on); color: var(--text-primary); font-weight: 600; }

.iconbtn {
  font: inherit; color: var(--text-primary); background: var(--chip);
  border: 1px solid var(--border); border-radius: 8px;
  width: 34px; height: 34px; display: inline-grid; place-items: center;
  cursor: pointer; flex: none; padding: 0;
}
.iconbtn:hover { background: var(--chip-on); }
.iconbtn:focus-visible, a:focus-visible, button:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}
.iconbtn svg { width: 16px; height: 16px; }
.navtoggle { display: none; }

@media (max-width: 1080px) {
  .navtoggle { display: inline-grid; }
  .nav {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    background: var(--surface-1); border-bottom: 1px solid var(--border);
    padding: 8px 14px 14px;
  }
  .nav.open { display: flex; }
  .nav a { padding: 11px 12px; font-size: 15px; }
}

/* ---------- hero ---------- */
.hero { padding: 56px 0 8px; }
.hero .eyebrow {
  font-size: 12px; letter-spacing: .10em; text-transform: uppercase;
  color: var(--muted); font-weight: 650; margin-bottom: 14px;
}
.hero h1 { max-width: 18ch; }
.kmark { display: block; margin: 0 0 26px; }

/* ---------- sections ---------- */
main { padding-bottom: 72px; }
section { scroll-margin-top: 76px; }
.pagehead { padding: 44px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pagehead .eyebrow {
  font-size: 12px; letter-spacing: .10em; text-transform: uppercase;
  color: var(--muted); font-weight: 650; margin-bottom: 12px;
}
.pagehead p:last-child { margin-bottom: 1.6em; }

.rule { border: 0; border-top: 1px solid var(--border); margin: 44px 0; }

/* ---------- cards & tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 22px 0; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 17px;
}
.tile .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 9px; font-weight: 600; }
.tile .v { font-size: 32px; line-height: 1.02; font-weight: 640; letter-spacing: -0.025em; }
.tile .v.sm { font-size: 24px; }
.tile .n { font-size: 12.5px; color: var(--text-secondary); margin-top: 7px; line-height: 1.45; }
.tile.up { border-left: 3px solid var(--series-1); }
.tile.down { border-left: 3px solid var(--series-2); }
.tile.flag { border-left: 3px solid var(--critical); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin: 26px 0; }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 20px 18px;
  display: flex; flex-direction: column;
}
.card h3 { margin: 0 0 8px; font-size: 17px; }
.card p { font-size: 14.5px; color: var(--text-secondary); margin: 0 0 14px; }
.card .go { margin-top: auto; font-size: 14px; font-weight: 600; text-decoration: none; }
.card .go::after { content: " →"; }
a.card { text-decoration: none; color: inherit; transition: border-color .12s, transform .12s; }
a.card:hover { border-color: var(--border-strong); text-decoration: none; transform: translateY(-1px); }

.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; margin: 24px 0;
}
.panel h3:first-child, .panel h2:first-child { margin-top: 0; }

.callout {
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--series-1);
  border-radius: 10px; padding: 15px 18px; margin: 22px 0;
  font-size: 14.5px; color: var(--text-secondary);
}
.callout.warn { border-left-color: var(--critical); }
.callout.caveat { border-left-color: var(--warning); }
.callout strong { color: var(--text-primary); }
.callout p:last-child { margin-bottom: 0; }
.callout .lbl {
  display: block; font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); font-weight: 650; margin-bottom: 7px;
}

/* ---------- numbered claim list ---------- */
ol.claims { list-style: none; counter-reset: c; padding: 0; margin: 24px 0; }
ol.claims li {
  counter-increment: c; position: relative; padding: 0 0 0 46px; margin-bottom: 20px;
}
ol.claims li::before {
  content: counter(c); position: absolute; left: 0; top: 1px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--chip); border: 1px solid var(--border);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 680; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
ol.claims li b, ol.claims li strong { color: var(--text-primary); }
ol.claims li { color: var(--text-secondary); }

/* ---------- generic lists ---------- */
ul.ticks { list-style: none; padding: 0; margin: 16px 0; }
ul.ticks li { position: relative; padding-left: 26px; margin-bottom: 10px; color: var(--text-secondary); }
ul.ticks li::before {
  content: ""; position: absolute; left: 6px; top: .62em;
  width: 7px; height: 7px; border-radius: 2px; background: var(--series-1);
}
ul.ticks.neg li::before { background: var(--series-2); }
ul.ticks.no li::before { background: var(--critical); }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; margin: 22px 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--grid); vertical-align: top; }
thead th {
  color: var(--muted); font-weight: 650; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .06em;
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
  border-bottom: 1px solid var(--axis);
}
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--band); }

.pill {
  display: inline-block; font-size: 11.5px; font-weight: 650; letter-spacing: .02em;
  padding: 2.5px 8px; border-radius: 999px; border: 1px solid var(--border-strong);
  color: var(--text-primary); white-space: nowrap;
}
.pill.crit { border-color: var(--critical); color: var(--critical); }
.pill.high { border-color: var(--serious); }
.pill.med { border-color: var(--muted); color: var(--muted); }

/* ---------- charts ---------- */
figure.chart { margin: 26px 0; }
figure.chart figcaption { font-size: 12.5px; color: var(--text-secondary); margin-top: 10px; }
figure.chart figcaption b { color: var(--text-primary); }
.chartbox {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 12px; position: relative;
}
.chartbox h3 { margin: 0 0 4px; font-size: 16.5px; padding-right: 210px; }
.chartbox .cap { font-size: 13px; color: var(--text-secondary); margin: 0 0 14px; max-width: 74ch; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 0 0 12px; font-size: 13px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { width: 14px; height: 3px; border-radius: 2px; flex: none; display: inline-block; }
.sw.blk { height: 11px; width: 11px; border-radius: 3px; }
.plot { position: relative; min-height: 280px; }
svg.plot-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-tools {
  position: absolute; top: 14px; right: 14px;
  display: flex; gap: 6px; z-index: 6; flex-wrap: wrap; justify-content: flex-end;
}
.chart-tools .chip { font-size: 12px; padding: 5px 9px; background: var(--surface-2); }
@media (max-width: 700px) {
  .chartbox h3 { padding-right: 0; }
  .chart-tools { position: static; margin: 0 0 12px; }
}
.tip {
  position: absolute; pointer-events: none; background: var(--surface-2);
  border: 1px solid var(--axis); border-radius: 9px; padding: 9px 11px;
  font-size: 12.5px; box-shadow: var(--shadow); opacity: 0;
  transition: opacity .1s; min-width: 150px; z-index: 5; color: var(--text-primary);
}
.tip .ty { font-weight: 650; margin-bottom: 6px; font-size: 13px; }
.tip .tr { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.tip .tr b { font-variant-numeric: tabular-nums; font-weight: 650; }
.tip .tg { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); color: var(--text-secondary); }

/* bar chart rows (HTML, not SVG) */
.bars { margin: 6px 0 4px; }
.bars.stack .barrow { grid-template-columns: 1fr 48px; grid-template-areas: "lab val" "track track"; row-gap: 4px; padding: 7px 0; }
.bars.stack .barrow .lab { grid-area: lab; }
.bars.stack .barrow .val { grid-area: val; }
.bars.stack .barrow .track { grid-area: track; height: 14px; }
.barrow { display: grid; grid-template-columns: minmax(96px, 200px) 1fr 62px; gap: 12px; align-items: center; padding: 6px 0; }
.barrow .lab { font-size: 13.5px; color: var(--text-primary); line-height: 1.3; }
.barrow .lab small { display: block; color: var(--muted); font-size: 11.5px; }
.barrow .track { background: var(--band); border-radius: 4px; height: 20px; position: relative; overflow: hidden; }
.barrow .fill {
  height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1);
  width: var(--w, 0); transform-origin: left center;
}
.bars.is-in .fill { animation: barin .85s cubic-bezier(.22, .7, .2, 1) both; }
@keyframes barin { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.barrow .val { font-size: 13.5px; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) {
  .barrow { grid-template-columns: 1fr 52px; grid-template-areas: "lab val" "track track"; row-gap: 3px; }
  .barrow .lab { grid-area: lab; } .barrow .val { grid-area: val; } .barrow .track { grid-area: track; }
}

/* ---------- controls ---------- */
.ctrls {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-secondary);
}
.ctrls .lbl { color: var(--muted); }
button.chip {
  font: inherit; font-size: 13px; color: var(--text-primary); background: var(--chip);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 11px; cursor: pointer; line-height: 1.2;
}
button.chip:hover { background: var(--chip-on); }
button.chip[aria-pressed="true"] { background: var(--chip-on); border-color: var(--series-1); font-weight: 650; }

.status { display: flex; align-items: center; gap: 8px; margin: 16px 0 18px; font-size: 13px; color: var(--text-secondary); flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--good); }
.dot.snap { background: var(--critical); }
.dot.load { background: var(--series-1); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

/* ---------- CTA ---------- */
.cta {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px;
  padding: 30px 28px; margin: 48px 0 0; text-align: left;
}
.cta h2 { margin-top: 0; }
.btnrow { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.btn {
  display: inline-block; text-decoration: none; font-size: 15px; font-weight: 600;
  padding: 11px 20px; border-radius: 10px; border: 1px solid var(--series-1);
  background: var(--series-1); color: #fff;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text-primary); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--chip); filter: none; }

/* ---------- footer ---------- */
.sitefoot {
  border-top: 1px solid var(--border); background: var(--surface-1);
  padding: 34px 0 44px; font-size: 13.5px; color: var(--text-secondary);
}
.sitefoot .cols { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 26px; }
.sitefoot h4 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 10px; }
.sitefoot ul { list-style: none; padding: 0; margin: 0; }
.sitefoot li { margin-bottom: 7px; }
.sitefoot a { color: var(--text-secondary); text-decoration: none; }
.sitefoot a:hover { color: var(--text-primary); text-decoration: underline; }
.sitefoot .fine { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--muted); }
@media (max-width: 700px) { .sitefoot .cols { grid-template-columns: 1fr; gap: 22px; } }

/* ---------- sources ---------- */
details.sources {
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-1);
  padding: 0; margin: 30px 0 0;
}
details.sources > summary {
  cursor: pointer; padding: 13px 18px; font-size: 13.5px; font-weight: 600;
  list-style: none; color: var(--text-primary);
}
details.sources > summary::-webkit-details-marker { display: none; }
details.sources > summary::before { content: "▸ "; color: var(--muted); }
details.sources[open] > summary::before { content: "▾ "; }
details.sources .body { padding: 0 18px 16px; font-size: 12.5px; color: var(--text-secondary); line-height: 1.65; }

[hidden] { display: none !important; }

.k-diagram { margin: 8px 0 4px; }

@media print {
  .sitehead, .sitefoot, .cta, .skip, .chart-tools, .navtoggle, #themeBtn { display: none !important; }
  .chartbox { break-inside: avoid; box-shadow: none; border-color: #ccc; }
  body { background: #fff; color: #111; }
  a { text-decoration: none; }
}
