/*
 * Stockastic / Utdelningsklubben — global stylesheet
 * Replaces Pico.css. Drives both directions from the redesign bundle:
 *   data-theme="light"  → Direction A · Almanackan  (white, type-driven)
 *   data-theme="dark"   → Direction B · Tavlan      (navy, departure board)
 *
 * Tokens come from bg.svg palette: yellow, coral, cyan, teal, navy.
 * Type: Geist (loaded in app.html). Numbers default to tabular-nums.
 */

/* ── Tokens ───────────────────────────────────────────────────────── */
:root {
  --topbar-h: 56px;
}

:root,
html[data-theme="light"] {
  --bg: #ffffff;
  --paper: #ffffff;
  --ink: #01223e;
  --sub: #6d7682;
  --rule: #01223e;
  --rulesoft: rgba(1, 34, 62, 0.12);
  --accent: #fcb912;
  --accent-on: #01223e;
  --pos: #1bb7ad;
  --neg: #db4546;
  --cyan: #0baac6;
  --paper-elev: #f5f4ee;
  --field: rgba(1, 34, 62, 0.04);
  --field-strong: rgba(1, 34, 62, 0.08);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #01223e;
  --paper: #021830;
  --ink: #f1ead0;
  --sub: #7f8fa6;
  --rule: #0a3a66;
  --rulesoft: rgba(241, 234, 208, 0.10);
  --accent: #fcb912;
  --accent-on: #01223e;
  --pos: #1bb7ad;
  --neg: #db4546;
  --cyan: #0baac6;
  --paper-elev: #022344;
  --field: rgba(241, 234, 208, 0.05);
  --field-strong: rgba(241, 234, 208, 0.10);
  color-scheme: dark;
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Geist, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01" 0;
}

img, svg { max-width: 100%; }
hr {
  border: none;
  border-top: 1px solid var(--rulesoft);
  margin: 1.5rem 0;
}

/* ── Type ──────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 0.4em;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--ink);
}
h1 { font-size: clamp(2.5rem, 5vw, 4rem); letter-spacing: -0.04em; }
h2 { font-size: clamp(1.75rem, 3vw, 2.5rem); letter-spacing: -0.035em; }
h3 { font-size: 1.5rem; letter-spacing: -0.02em; }
h4 { font-size: 1.125rem; letter-spacing: -0.015em; }
h5, h6 { font-size: 1rem; }

p { margin: 0 0 1em; }
small { font-size: 0.85em; color: var(--sub); }
b, strong { font-weight: 600; }
em { font-style: italic; }

a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease, color 120ms ease;
}
a:hover { border-bottom-color: var(--accent); }
a[role="button"] { border-bottom: none; }

/* Section labels (uppercase, tracked) — use class .label */
.label, .kicker {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sub);
  font-weight: 600;
}

/* Tabular nums — by default on numbers */
.num, td, th, .stat-value, .price {
  font-variant-numeric: tabular-nums;
}

/* ── Layout helpers ────────────────────────────────────────────────── */
main, .container {
  width: 100%;
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 40px;
  padding-right: 40px;
}
main { padding-top: 32px; padding-bottom: 64px; }

@media (max-width: 720px) {
  main, .container { padding-left: 20px; padding-right: 20px; }
  main { padding-top: 20px; padding-bottom: 40px; }
}

.row { display: flex; gap: 1rem; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 0.5rem; }

.grid { display: grid; gap: 1rem; }
.grid.golden { grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .grid.golden { grid-template-columns: 33% auto; gap: 2rem; }
  .grid.with-aside { grid-template-columns: auto 25%; gap: 2rem; }
}

/* ── Stats row (used on lists + detail) ────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2rem;
  padding: 18px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  /* Tightened from 2rem: the first section below suppresses its own rule (the
   * stats band's bottom line already serves as that boundary), so this margin
   * now carries gap the removed rule used to. */
  margin: 1.5rem 0 1.75rem;
  font-variant-numeric: tabular-nums;
}

/* ── Sections ──────────────────────────────────────────────────────── */
/* The only place vertical rhythm between page blocks is defined. Each block
 * is a <Section>, which draws its own --rule hairline + label. No per-block
 * margin-top / padding-top anywhere. */
.sections {
  display: flex;
  flex-direction: column;
  gap: 3rem;
  margin-top: 1.5rem;
}
@media (max-width: 720px) {
  .sections { gap: 2.25rem; }
}
.stats > div { min-width: 0; }
.stat-label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sub);
  font-weight: 600;
}
.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 6px;
  line-height: 1.1;
}
.stat-sub {
  font-size: 0.78rem;
  color: var(--sub);
  margin-top: 4px;
}
.stat-sub.pos { color: var(--pos); }
.stat-sub.neg { color: var(--neg); }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); gap: 1.25rem; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; gap: 1rem; }
}

/* ── Tables ────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
/* Line weights: the section boundary (--rule, drawn by Section.svelte) is the
 * heaviest line in the page body. Everything *inside* a section drops to
 * --rulesoft so no interior line can be mistaken for a boundary — that includes
 * the table head, which previously carried full-strength --rule and so read as
 * the divider despite sitting inside a section.
 * tfoot keeps --rule: it closes a table, not a section. */
thead tr { border-bottom: 1px solid var(--rulesoft); }
tbody tr { border-bottom: 1px solid var(--rulesoft); }
tbody tr:last-child { border-bottom: 1px solid var(--rulesoft); }
tfoot tr { border-top: 1px solid var(--rule); }
th {
  text-align: left;
  padding: 10px 8px;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--sub);
  background: transparent;
}
td {
  padding: 14px 8px;
  font-size: 0.95rem;
  color: var(--ink);
  vertical-align: middle;
}
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child  { padding-right: 0; text-align: right; }
th.shrink, td.shrink { width: 1%; white-space: nowrap; }

/* figure wrapper kept for backward compat with current markup */
figure {
  margin: 0;
  overflow-x: auto;
}
figure > table { min-width: 100%; }

/* Pos/neg signals */
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }
.accent-text { color: var(--accent); }

/* ── Form controls ─────────────────────────────────────────────────── */
input, select, textarea, button {
  font: inherit;
  color: inherit;
  margin: 0;
}

input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="color"],
select,
textarea {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule);
  padding: 8px 2px;
  color: var(--ink);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  border-radius: 0;
  transition: border-color 120ms ease;
}
input::placeholder, textarea::placeholder { color: var(--sub); opacity: 0.7; }
input:focus, select:focus, textarea:focus {
  border-bottom-color: var(--accent);
}
input[aria-invalid="true"] { border-bottom-color: var(--neg); }

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--sub) 50%),
                    linear-gradient(135deg, var(--sub) 50%, transparent 50%);
  background-position: calc(100% - 14px) center, calc(100% - 8px) center;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 26px;
}

/* Color picker: render as a small inline swatch, not a full-width bar.
 * The native browser chrome around the actual color is stripped so the
 * label + swatch read as one tight unit. */
input[type="color"] {
  display: inline-block;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  background: transparent;
  vertical-align: middle;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; }
input[type="color"]::-moz-color-swatch { border: none; }

/* Range slider: themed thin navy track + square accent thumb to match the
 * "almanackan/tavlan" design language (no border-radius, ink + yellow). */
input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 1.5rem;
  background: transparent;
  cursor: pointer;
  padding: 0;
  border: none;
}
input[type="range"]:focus { outline: none; }

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--rulesoft);
  border: none;
  border-radius: 0;
}
input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--rulesoft);
  border: none;
  border-radius: 0;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 18px;
  margin-top: -7px;
  background: var(--accent);
  border: 1px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  transition: transform 120ms ease;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 18px;
  background: var(--accent);
  border: 1px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
  transition: transform 120ms ease;
}

input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:focus::-webkit-slider-thumb { transform: scaleY(1.15); }
input[type="range"]:hover::-moz-range-thumb,
input[type="range"]:focus::-moz-range-thumb { transform: scaleY(1.15); }

input[type="range"]:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="checkbox"], input[type="radio"] {
  accent-color: var(--accent);
  width: auto;
  margin-right: 0.4em;
}

input[type="checkbox"][role="switch"] {
  appearance: none;
  display: inline-block;
  width: 32px;
  height: 18px;
  background: var(--field-strong);
  border: 1px solid var(--rule);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
  vertical-align: middle;
}
input[type="checkbox"][role="switch"]::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: var(--ink);
  border-radius: 50%;
  transition: transform 160ms ease, background 120ms ease;
}
input[type="checkbox"][role="switch"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"][role="switch"]:checked::after {
  transform: translateX(14px);
  background: var(--accent-on);
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--sub);
  margin-bottom: 0.75rem;
}
label > input,
label > select,
label > textarea { margin-top: 0.25rem; }
fieldset {
  border: none;
  padding: 0;
  margin: 0 0 1rem;
}
fieldset.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
form.grid > fieldset { margin: 0; }

/* ── Buttons ───────────────────────────────────────────────────────── */
button, [role="button"], .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-on);
  border: 1px solid var(--accent);
  cursor: pointer;
  border-radius: 0;
  text-decoration: none;
  transition: opacity 120ms ease, background 120ms ease, border-color 120ms ease;
  font-family: inherit;
  line-height: 1.2;
  white-space: nowrap;
}
button:hover, [role="button"]:hover, .btn:hover { opacity: 0.88; border-bottom-color: var(--accent); }
button:disabled, [role="button"][aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

button.outline, [role="button"].outline,
button.secondary.outline, [role="button"].secondary.outline,
button.contrast.outline, [role="button"].contrast.outline {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}
button.outline:hover, [role="button"].outline:hover { border-color: var(--accent); }

button.secondary, [role="button"].secondary {
  background: var(--field-strong);
  color: var(--ink);
  border-color: var(--field-strong);
}
button.secondary:hover, [role="button"].secondary:hover { background: var(--rulesoft); }

button.contrast, [role="button"].contrast {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

button.small, [role="button"].small {
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}
button.narrow { padding: 0.3rem 0.6rem; }

/* "Link button" — like the design's accent-underlined anchors */
.link-button {
  display: inline-block;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--accent);
  color: var(--ink);
  padding: 4px 0;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.link-button:hover { opacity: 0.8; }

[role="group"] {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}

/* ── Cards / articles ──────────────────────────────────────────────── */
article {
  background: transparent;
  padding: 1.5rem 0;
  margin: 0 0 1.5rem;
  border-top: 1px solid var(--rule);
}
article:first-of-type { border-top: none; padding-top: 0; }
main > article:first-of-type { border-top: none; }

/* ── Nav (used inside breadcrumbs etc.) ────────────────────────────── */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
nav ul {
  display: flex;
  align-items: center;
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 0;
}
nav ul li { display: inline-flex; align-items: center; }
nav[aria-label="breadcrumb"] ul li + li::before {
  content: "›";
  margin: 0 0.5rem;
  color: var(--sub);
  opacity: 0.6;
}
nav[aria-label="breadcrumb"] a { color: var(--sub); }
nav[aria-label="breadcrumb"] li:last-child { color: var(--ink); font-weight: 600; }

/* ── Symbol badge ──────────────────────────────────────────────────── */
/* Ticker badge — quiet by default. It repeats once per row in the holdings and
 * search tables, where a solid accent fill stacks into a column of yellow
 * blocks and out-shouts the figures the tables exist to show. The badge keeps
 * its shape, weight and tracking, so it still reads as a ticker.
 * The accent is reserved for singular emphasis: see .symbol.lead. */
.symbol {
  display: inline-block;
  padding: 2px 8px;
  background: var(--field-strong);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85em;
  letter-spacing: 0.02em;
  font-family: Geist, monospace;
}

/* Exactly one per view (the entry modal's header names its subject), so the
 * accent still reads as emphasis rather than decoration. */
.symbol.lead {
  background: var(--accent);
  color: var(--accent-on);
}

/* The "count" badge used on portfolio rows and similar */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Dialogs ───────────────────────────────────────────────────────── */
dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: rgba(1, 34, 62, 0.55);
  border: none;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  overflow-y: auto;
}
html[data-theme="dark"] dialog { background: rgba(0, 0, 0, 0.65); }
dialog:not([open]) { display: none; }
/* `article:first-of-type` (0-1-1) outranks a bare `dialog article` (0-0-2),
 * so the card reset above was stripping every modal's top padding AND its
 * top border — the dialog body sat flush against its own top edge. Matching
 * that specificity here keeps the card rules for page content while letting
 * dialogs keep their own frame. */
dialog article,
dialog article:first-of-type {
  background: var(--paper);
  border: 1px solid var(--rule);
  width: min(92%, 720px);
  margin: 5vh auto;
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
dialog article > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  /* 1rem matches the footer's padding-top, so the header and footer rules sit
   * the same distance from their content and frame the body symmetrically. */
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 0;
}
dialog article > header p,
dialog article > header > div { margin: 0; font-weight: 600; }
dialog article > footer {
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  margin-top: 0;
}
/* Confirm/cancel rows sit at the trailing edge. Scoped to [role="group"] so
 * footers holding a full-width form instead of an action pair (e.g. the
 * add-transaction row in the entry dialog) keep their own layout. */
dialog article > footer > [role="group"] {
  display: flex;
  width: 100%;
  justify-content: flex-end;
}
dialog article header button[aria-label="Close"] {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--sub);
  font-size: 1.5rem;
  line-height: 1;
  width: 1.5rem;
  height: 1.5rem;
}
dialog article header button[aria-label="Close"]::before { content: "×"; }

/* ── Details / summary ─────────────────────────────────────────────── */
details summary {
  cursor: pointer;
  list-style: revert;
  color: var(--ink);
  padding: 0.25rem 0;
}
details.dropdown {
  position: relative;
  display: inline-block;
}
details.dropdown > summary {
  border-bottom: none;
  padding: 0.25rem 0.5rem;
}
details.dropdown > summary::-webkit-details-marker { display: none; }
details.dropdown > ul {
  position: absolute;
  right: 0;
  top: 100%;
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  background: var(--paper);
  border: 1px solid var(--rule);
  min-width: 8rem;
  z-index: 50;
}
details.dropdown > ul li { display: block; }
details.dropdown > ul li a {
  display: block;
  padding: 0.4rem 0.75rem;
  color: var(--ink);
  font-size: 0.9rem;
  border-bottom: none;
}
details.dropdown > ul li a:hover { background: var(--field); border-bottom: none; }

/* ── Aria-busy spinner replacement (Pico had one) ──────────────────── */
[aria-busy="true"]::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.5em;
  border: 2px solid var(--rulesoft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: stockastic-spin 700ms linear infinite;
  vertical-align: -0.15em;
}
@keyframes stockastic-spin { to { transform: rotate(360deg); } }

/* ── Progress ──────────────────────────────────────────────────────── */
progress {
  width: 100%;
  height: 4px;
  appearance: none;
  background: var(--field);
  border: none;
}
progress::-webkit-progress-bar { background: var(--field); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

/* ── Mark (highlight) ──────────────────────────────────────────────── */
mark {
  background: var(--accent);
  color: var(--accent-on);
  padding: 0 2px;
}

/* ── Utility ───────────────────────────────────────────────────────── */
.muted { color: var(--sub); }
.error { color: var(--neg); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.overflow-auto { overflow: auto; }
.hide { display: none !important; }

/* Print styles — leave defaults */
