/* ============================================================
   FINANCE DASHBOARDS · design tokens
   The printed sheet, adapted for market data. Borrowed from the
   RightWeek protocol: warm paper, press-black ink, five spot
   inks, ruled panels, three type voices. Numbers are always mono.
   Charts are drawn in ink; area fills are halftone dots — never
   gradients, never shadows.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Young+Serif&family=Instrument+Sans:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  /* ---- the sheet ---- */
  --paper: #F4F0E6;
  --ink:   #211E1A;
  --ink-soft: rgba(33, 30, 26, 0.55);
  --ink-faint: rgba(33, 30, 26, 0.18);
  --paper-soft: rgba(244, 240, 230, 0.6);

  /* ---- five spot inks (closed set — never a sixth) ---- */
  --sun:    #DFA32B;   /* the vault's ink — this world's home color */
  --leaf:   #567D3E;
  --cobalt: #2F4FB7;
  --clay:   #BF5432;
  --plum:   #7B5286;

  /* ---- market semantics (aliases only — always resolve to a spot ink) ---- */
  --gain:  var(--leaf);
  --loss:  var(--clay);
  --data:  var(--cobalt);   /* default series ink */
  --spot:  var(--sun);      /* page accent; a page may reassign to another spot ink */

  /* ---- type: one inked serif, one clean sans, one measuring mono ---- */
  --f-display: 'Young Serif', Georgia, serif;
  --f-body:    'Instrument Sans', 'Helvetica Neue', sans-serif;
  --f-mono:    'IBM Plex Mono', 'SFMono-Regular', monospace;

  --t-huge: clamp(2.1rem, 5.5vw, 4rem);
  --t-big:  clamp(1.5rem, 3vw, 2.2rem);
  --t-md:   1rem;
  --t-sm:   0.86rem;
  --t-xs:   0.72rem;

  /* ---- panel grammar ---- */
  --rule: 2px solid var(--ink);
  --rule-soft: 1.5px solid var(--ink);
  --wobble: 14px 18px 15px 12px;      /* hand-ruled corners, never perfect */
  --wobble-sm: 6px 10px 7px 5px;
  --gutter: clamp(10px, 1.6vw, 18px);
  --ease: cubic-bezier(0.22, 0.8, 0.3, 1);
}

/* ---------------- base ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--t-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--ink); color: var(--paper); }

h1, h2, h3 { font-family: var(--f-display); font-weight: 400; line-height: 1.08; margin: 0; }
h1 { font-size: var(--t-huge); letter-spacing: -0.01em; }
h2 { font-size: var(--t-big); }
h3 { font-size: 1.3rem; }

p { margin: 0 0 12px; }
a { color: inherit; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2.5px solid var(--cobalt); outline-offset: 3px;
}

.mono { font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.07em; text-transform: lowercase; }
.soft { color: var(--ink-soft); }
.up   { color: var(--gain); }
.down { color: var(--loss); }

/* ---------------- the sheet: one printed page ---------------- */
.sheet {
  position: relative;
  margin: clamp(10px, 1.6vw, 22px);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  min-height: calc(100vh - 44px);
  padding: 0 var(--gutter) var(--gutter);
  overflow: clip;
}
.reg {
  position: absolute; width: 18px; height: 18px;
  color: var(--ink); opacity: 0.55; pointer-events: none; z-index: 4;
}
.reg svg { width: 100%; height: 100%; display: block; }
.reg.tl { top: 8px; left: 8px; }
.reg.tr { top: 8px; right: 8px; }
.reg.bl { bottom: 8px; left: 8px; }
.reg.br { bottom: 8px; right: 8px; }

/* ---------------- bar ---------------- */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 18px 6px 14px;
}
.bar .mark { display: flex; align-items: center; gap: 10px; }
.bar .mark .name { font-family: var(--f-display); font-size: 1.2rem; }
.bar .right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bar a { text-decoration: none; }
.bar a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------------- caption box: metadata in a ruled box ---------------- */
.caption {
  display: inline-block;
  padding: 3px 10px 2px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-mono); font-size: var(--t-xs);
  letter-spacing: 0.07em; text-transform: lowercase;
  border-radius: 2px 8px 3px 6px;
}
.panel > .caption.corner { position: absolute; top: -1.5px; left: -1.5px; border-radius: 2px 0 8px 0; z-index: 2; }
.panel > .caption.corner.right { left: auto; right: -1.5px; border-radius: 0 2px 0 8px; }

/* ---------------- panels ---------------- */
.spread {
  display: grid; gap: var(--gutter);
  grid-template-columns: repeat(6, 1fr);
  grid-auto-flow: dense;
}
.panel {
  position: relative;
  border: var(--rule); border-radius: var(--wobble);
  background: var(--paper);
  padding: 24px 20px 18px;
  display: flex; flex-direction: column; gap: 8px;
  color: var(--ink);
}
.panel.pad-top { padding-top: 34px; }      /* room for a corner caption */
.p-6x1 { grid-column: span 6; }
.p-4x1 { grid-column: span 4; }
.p-3x1 { grid-column: span 3; }
.p-2x1 { grid-column: span 2; }
@media (max-width: 900px) {
  .spread { grid-template-columns: repeat(2, 1fr); }
  .p-6x1, .p-4x1, .p-3x1 { grid-column: span 2; }
  .p-2x1 { grid-column: span 1; }
}
@media (max-width: 560px) {
  .spread { grid-template-columns: 1fr; }
  .panel { grid-column: span 1 !important; }
}

/* night panel: ink field, paper text */
.panel.night { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.panel.night .caption { background: var(--ink); color: var(--paper); border-color: var(--paper); }

/* ---------------- buttons & chips: small ruled panels ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 10px 20px; cursor: pointer;
  font-family: var(--f-body); font-weight: 600; font-size: var(--t-sm);
  color: var(--ink); background: var(--paper);
  border: var(--rule); border-radius: var(--wobble);
  transition: background 0.25s var(--ease), color 0.25s var(--ease), transform 0.25s var(--ease);
}
.btn:hover { background: var(--spot); color: var(--paper); transform: rotate(-0.6deg) translateY(-2px); }
.btn.night { background: var(--ink); color: var(--paper); }
.btn.night:hover { background: var(--spot); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; background: var(--paper); color: var(--ink); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 13px 4px; cursor: pointer;
  font-family: var(--f-mono); font-size: var(--t-xs);
  letter-spacing: 0.05em; text-transform: lowercase;
  color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: var(--wobble-sm);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.chip:hover { background: var(--ink-faint); }
.chip.active { background: var(--ink); color: var(--paper); }

/* ---------------- form fields ---------------- */
input, select, textarea {
  font-family: var(--f-body); font-size: var(--t-sm);
  color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: var(--wobble-sm);
  padding: 9px 12px;
}
input::placeholder { color: var(--ink-soft); font-style: italic; }
label { font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.07em; text-transform: lowercase; color: var(--ink-soft); }

/* ---------------- section head: sits on the bare paper ---------------- */
.section-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 30px 2px 12px;
}
.section-head h2 { font-size: 1.35rem; }
.section-head .rule-out { flex: 1; border-top: 1.5px solid var(--ink); opacity: 0.25; align-self: center; }

/* ---------------- tags: tiny ruled labels ---------------- */
.tag {
  display: inline-block; padding: 1px 8px;
  font-family: var(--f-mono); font-size: 0.66rem;
  letter-spacing: 0.05em; text-transform: lowercase;
  border: 1.5px solid var(--ink); border-radius: var(--wobble-sm);
  color: var(--ink); background: var(--paper);
}
.tag.inked { background: var(--ink); color: var(--paper); }
.tag.spot-sun    { border-color: var(--sun);    color: var(--sun); }
.tag.spot-leaf   { border-color: var(--leaf);   color: var(--leaf); }
.tag.spot-cobalt { border-color: var(--cobalt); color: var(--cobalt); }
.tag.spot-clay   { border-color: var(--clay);   color: var(--clay); }
.tag.spot-plum   { border-color: var(--plum);   color: var(--plum); }

/* ---------------- ledger table ---------------- */
.ledger { width: 100%; border-collapse: collapse; }
.ledger th {
  text-align: left; padding: 8px 12px 6px;
  font-family: var(--f-mono); font-size: var(--t-xs); font-weight: 400;
  letter-spacing: 0.07em; text-transform: lowercase;
  color: var(--ink-soft);
  border-bottom: 2px solid var(--ink);
}
.ledger td { padding: 9px 12px; font-size: var(--t-sm); border-bottom: 1px solid var(--ink-faint); vertical-align: middle; }
.ledger tr:last-child td { border-bottom: none; }
.ledger tr:hover td { background: rgba(33, 30, 26, 0.04); }
.ledger .num { text-align: right; font-family: var(--f-mono); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.ledger .rowhead td {
  font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.07em; text-transform: lowercase;
  color: var(--ink-soft); border-bottom: 1.5px solid var(--ink); padding-top: 16px;
}

/* ---------------- vitals: a number and its label ---------------- */
.vital .n { font-family: var(--f-mono); font-size: clamp(1.2rem, 2.2vw, 1.6rem); display: block; line-height: 1.2; }
.vital .l { font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.07em; text-transform: lowercase; color: var(--ink-soft); }

/* the price line on a company panel */
.quote { display: flex; align-items: baseline; gap: 10px; font-family: var(--f-mono); }
.quote .px  { font-size: 1.05rem; }
.quote .chg { font-size: var(--t-xs); letter-spacing: 0.04em; }

/* lifecycle dot (live-data status) */
.status { display: inline-flex; align-items: center; gap: 7px; font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.07em; text-transform: lowercase; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--leaf); flex: none; }
.status[data-live="off"]::before  { background: transparent; border: 1.5px solid currentColor; }
.status[data-live="warn"]::before { background: var(--sun); }
.status[data-live="err"]::before  { background: var(--clay); }
.status[data-live="on"]::before   { animation: pulse 2.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 var(--leaf); } 50% { box-shadow: 0 0 0 6px transparent; } }

/* ---------------- notices ---------------- */
.notice {
  border: 1.5px dashed var(--ink); border-radius: var(--wobble);
  padding: 12px 16px; font-size: var(--t-sm);
  background: var(--paper);
}
.notice.err { border-color: var(--clay); color: var(--clay); border-style: solid; }
.loading { font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.07em; text-transform: lowercase; color: var(--ink-soft); padding: 14px 2px; }

/* ============================================================
   CHARTS — fin-charts.js draws into these
   Every chart is inked SVG inside a panel. Grid rules are faint
   ink; axis labels are mono lowercase; fills are halftone dots.
   ============================================================ */
.fin-chart { position: relative; width: 100%; }
.fin-chart svg { display: block; width: 100%; height: auto; }

.fin-chart .grid-rule { stroke: var(--ink); stroke-width: 1; opacity: 0.12; }
.fin-chart .axis-rule { stroke: var(--ink); stroke-width: 1.5; }
.fin-chart .axis-label {
  font-family: var(--f-mono); font-size: 10.5px; letter-spacing: 0.05em;
  fill: var(--ink); opacity: 0.6; text-transform: lowercase;
}
.fin-chart .series-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fin-chart .marker-dot { stroke: var(--paper); stroke-width: 1.5; }
.fin-chart .halftone-dot { pointer-events: none; }

/* draw-on-load: the line inks itself in (pathLength=1 set by JS) */
.fin-chart path.draw { stroke-dasharray: 1; stroke-dashoffset: 1; }
.fin-chart.drawn path.draw {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1.1s var(--ease);
  transition-delay: calc(var(--di, 0) * 130ms);
}
.fin-chart .fade { opacity: 0; }
.fin-chart.drawn .fade {
  opacity: 1;
  transition: opacity 0.6s var(--ease);
  transition-delay: calc(var(--di, 0) * 90ms + 300ms);
}

/* crosshair + tooltip: the tooltip is a caption box */
.fin-chart .crosshair { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 4; opacity: 0.5; }
.fin-tip {
  position: absolute; pointer-events: none; z-index: 5;
  padding: 4px 10px 3px;
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink);
  font-family: var(--f-mono); font-size: var(--t-xs);
  letter-spacing: 0.05em; text-transform: lowercase;
  border-radius: 2px 8px 3px 6px;
  white-space: nowrap;
  transform: translate(-50%, -130%);
}
.fin-tip b { font-weight: 500; }

/* chart legend: mono swatches */
.fin-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; }
.fin-legend .key { display: inline-flex; align-items: center; gap: 7px; font-family: var(--f-mono); font-size: var(--t-xs); letter-spacing: 0.05em; text-transform: lowercase; }
.fin-legend .key i { width: 16px; height: 0; border-top: 2.5px solid currentColor; }

/* ---------------- motion: panels print in ---------------- */
.reveal { opacity: 0; transform: translateY(16px) scale(0.99); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); transition-delay: var(--pd, 0ms); }
.reveal.in { opacity: 1; transform: none; }

/* ---------------- calm for those who ask ---------------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .status[data-live="on"]::before { animation: none; }
  .fin-chart path.draw, .fin-chart.drawn path.draw { stroke-dashoffset: 0; transition: none; }
  .fin-chart .fade, .fin-chart.drawn .fade { opacity: 1; transition: none; }
  .btn, .chip { transition: none; }
  .btn:hover { transform: none; }
}
