/* Slavek Desk — foundation: tokens, reset, type, page layout, primitives.
   Component styles live in components.css. Tokens follow the spec (§5.1). */

:root {
  color-scheme: dark;
  --bg: #0B1220;
  --bg-2: #121B2C;
  --bg-3: #1A2539;
  --line: #243147;
  --line-2: #34445F;
  --text: #EDF2F9;
  --text-2: #A7B4C6;
  --text-3: #6F7E95;
  --brand: #E8B94A;
  --up: #2FBF84;
  --down: #E5605B;
  --up-soft: rgba(47, 191, 132, .14);
  --down-soft: rgba(229, 96, 91, .14);
  --focus: #E8B94A;
  --shadow: none;
  /* Brass where brass has to be read rather than seen: small text and chips.
     In dark it is the brand colour itself; in light it needs to be darker. */
  --brand-ink: #E8B94A;

  --font-sans: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-serif: "IBM Plex Serif", Georgia, "Times New Roman", serif;

  --fs-12: 12px; --fs-13: 13px; --fs-15: 15px; --fs-16: 16px;
  --fs-18: 18px; --fs-22: 22px; --fs-28: 28px; --fs-56: 56px;

  --r-panel: 12px; --r-btn: 8px; --r-chip: 6px;
  --gutter: 20px;
  --maxw: 1440px;

  --t-fast: 150ms ease;
  --t-med: 200ms ease;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F3F5F8;
  --bg-2: #FFFFFF;
  --bg-3: #EAEEF4;
  --line: #D9DFE8;
  --line-2: #C3CBD8;
  --text: #101B2D;
  --text-2: #4A5A72;
  --text-3: #7C8AA0;
  --brand: #B8860B;
  /* #178A5C measured 3.74:1 on --bg-3 at 15px - under AA, and asymmetric with a
     crisp red that passes. */
  --up: #0F7A4E;
  --down: #C8403B;
  --up-soft: rgba(23, 138, 92, .12);
  --down-soft: rgba(200, 64, 59, .12);
  --focus: #B8860B;
  --shadow: 0 1px 2px rgba(16, 27, 45, .06);
  --brand-ink: #8A6408;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #F3F5F8;
    --bg-2: #FFFFFF;
    --bg-3: #EAEEF4;
    --line: #D9DFE8;
    --line-2: #C3CBD8;
    --text: #101B2D;
    --text-2: #4A5A72;
    --text-3: #7C8AA0;
    --brand: #B8860B;
    /* #178A5C measured 3.74:1 on --bg-3 at 15px - under AA, and asymmetric with a
     crisp red that passes. */
  --up: #0F7A4E;
    --down: #C8403B;
    --up-soft: rgba(23, 138, 92, .12);
    --down-soft: rgba(200, 64, 59, .12);
    --focus: #B8860B;
    --shadow: 0 1px 2px rgba(16, 27, 45, .06);
    --brand-ink: #8A6408;
  }
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg, canvas { display: block; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
th { font-weight: 500; text-align: left; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* Type */
.serif { font-family: var(--font-serif); }
.num { font-variant-numeric: tabular-nums lining-nums; letter-spacing: 0; }
.t-12 { font-size: var(--fs-12); } .t-13 { font-size: var(--fs-13); }
.t-15 { font-size: var(--fs-15); } .t-18 { font-size: var(--fs-18); }
.t-22 { font-size: var(--fs-22); } .t-28 { font-size: var(--fs-28); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-2); }
.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;
}

/* Page layout: header, tape, then a 12-column grid of sections */
/* The page ships viewport-fit=cover, so in landscape on a notched iPhone the
   left 44px of the screen is under the camera housing. env() resolves to 0px
   where there is no inset, so this costs nothing anywhere else. */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}

main.desk {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gutter);
  padding: var(--gutter) 0 40px;
}
/* Rows 2 and 3 are one unit: the hero spans both so the tall left column and
   the board + headlines stack on the right end at exactly the same line. */
#briefing    { grid-column: 1 / -1;      grid-row: 1; }
#hero        { grid-column: 1 / span 7;  grid-row: 2 / span 2; }
#overview    { grid-column: 8 / span 5;  grid-row: 2; }
#symbol-news { grid-column: 8 / span 5;  grid-row: 3; align-self: stretch; }
#watchlist   { grid-column: 1 / -1;      grid-row: 4; }
#movers      { grid-column: 1 / span 6;  grid-row: 5; }
#sectors     { grid-column: 7 / span 6;  grid-row: 5; }
#news        { grid-column: 1 / span 7;  grid-row: 6; }
#earnings    { grid-column: 8 / span 5;  grid-row: 6; }

/* One column. Selected by id, not by `main.desk > section`, so it outranks the
   rules above.

   Order is DOM order, which keeps the visual order and the tab order identical.
   §5.3 sketched the tiles above the hero on a phone, but that was written before
   §13.1 put the briefing on top: the paragraph there already says how the market
   is doing in words, so the tiles no longer have to come first, and buying that
   swap with a CSS `order` would leave a keyboard user tabbing backwards up the
   page. */
@media (max-width: 1099px) {
  #briefing, #hero, #overview, #symbol-news, #watchlist,
  #movers, #sectors, #news, #earnings { grid-column: 1 / -1; grid-row: auto; }
}
@media (max-width: 759px) {
  :root { --gutter: 16px; }
  main.desk { gap: 16px; padding-bottom: 32px; }
}

/* Primitives */
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  min-width: 0;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: var(--fs-22);
  line-height: 1.25;
  letter-spacing: -0.005em;
}
.asof { font-size: var(--fs-13); color: var(--text-2); white-space: nowrap; }
[data-stale="true"] .asof { color: var(--brand); }
/* "Stale" is not vocabulary a non-native reader has — and *stale* is a real
   Polish adverb meaning "constantly", so "Stale · 10:00 PM ET" read as
   reassurance at the exact moment the page was trying to warn him. The healthy
   line says "as of 9:55 PM ET"; this one says when the numbers stopped. */
[data-stale="true"] .asof::before { content: "Last updated "; }
/* With no timestamp at all there is nothing to qualify, and the prefix used to
   render on its own: a dangling "Last updated" with no time after it. */
[data-stale="true"] .asof:empty::before { content: ""; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: var(--r-btn);
  background: var(--bg-3); color: var(--text);
  font-size: var(--fs-15); font-weight: 500; line-height: 1;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { background: var(--bg-2); border-color: var(--text-3); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #0B1220; }
.btn-primary:hover { background: var(--brand); filter: brightness(1.06); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-quiet:hover { background: var(--bg-3); color: var(--text); }
.btn-icon { width: 40px; padding: 0; justify-content: center; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--r-chip);
  font-size: var(--fs-13); line-height: 1.4; font-weight: 500;
  background: var(--bg-3); color: var(--text-2);
}
.chip.up { background: var(--up-soft); color: var(--up); }
.chip.down { background: var(--down-soft); color: var(--down); }
.chip.brand { background: rgba(232, 185, 74, .14); color: var(--brand-ink); }

.input {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-btn);
  background: var(--bg-3); color: var(--text);
  font-size: var(--fs-16);
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }

.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--text-3); font-size: var(--fs-13); font-weight: 500; }
.table td { font-size: var(--fs-15); }
.table th.r, .table td.r { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--bg-3); }

/* Live value flash (600ms). JS sets data-flash="up|down" then clears it. */
[data-flash="up"]   { animation: flashUp 600ms ease-out; }
[data-flash="down"] { animation: flashDown 600ms ease-out; }
@keyframes flashUp   { from { background-color: var(--up-soft); }   to { background-color: transparent; } }
@keyframes flashDown { from { background-color: var(--down-soft); } to { background-color: transparent; } }

/* Small bars used for day range and 52-week position */
.bar { position: relative; height: 4px; border-radius: 2px; background: var(--line-2); min-width: 60px; }
.bar > i { position: absolute; top: -3px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--text); }

/* Empty / notice text inside panels */
.empty { color: var(--text-2); font-size: var(--fs-15); padding: 12px 0; }
.notice { color: var(--text-2); font-size: var(--fs-13); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
