:root {
  --bg: #faf8f3;
  --fg: #201c14;
  --muted: #8a8172;
  --card: #ffffff;
  --border: #eae3d4;
  --hair: #f2eee3;
  --gold: #a8790f;
  --gold-deep: #8a6508;
  --gold-bright: #d9a324;
  --gold-soft: #f8f1dd;
  --fresh: #2e7d32;
  --down: #b3261e;
  --stale: #a58a00;
  --unknown: #98928a;
  --up-soft: #ebf3ea;
  --down-soft: #faedeb;
  --side-soft: #f6f1da;
  --shadow-card: 0 1px 2px rgba(58, 46, 20, 0.04), 0 10px 30px -18px rgba(58, 46, 20, 0.25);
  --shadow-pop: 0 4px 14px rgba(58, 46, 20, 0.12);
  --serif: "Iowan Old Style", "Palatino Nova", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151310;
    --fg: #ece6da;
    --muted: #99907f;
    --card: #1e1b16;
    --border: #2f2a21;
    --hair: #272319;
    --gold: #d5a02a;
    --gold-deep: #e2b551;
    --gold-bright: #e8bd55;
    --gold-soft: #2b2413;
    --fresh: #7fc583;
    --down: #e58e86;
    --stale: #ccb544;
    --unknown: #7c7568;
    --up-soft: #1d2a1e;
    --down-soft: #321d1a;
    --side-soft: #2b2712;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px -18px rgba(0, 0, 0, 0.6);
    --shadow-pop: 0 4px 14px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html { scrollbar-gutter: stable; }

body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

header, main, footer, .tabs {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

::selection { background: var(--gold-soft); }

/* ---------- sidhuvud ---------- */

header { padding-top: 2rem; }

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.logo {
  display: block;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(168, 121, 15, 0.35);
}

.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  line-height: 1.15;
  color: var(--fg);
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.83rem;
  max-width: 34rem;
}

.topline {
  text-align: right;
  font-size: 0.8rem;
  color: var(--muted);
}
.topline .spot-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
  line-height: 1.25;
}
.topline .warn { color: var(--down); }
.muted { color: var(--muted); }

/* ---------- prognosbanner ---------- */

.rec-banner {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 2rem;
  background: linear-gradient(135deg, var(--gold-soft) 0%, var(--card) 42%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.6rem 1.85rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-card);
}
.rec-banner::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
}

.rec-verdict {
  flex: none;
  align-self: center;
  display: flex;
  flex-direction: column;
  min-width: 12rem;
  padding-right: 2rem;
  border-right: 1px solid var(--border);
}
.rec-arrow {
  font-size: 1.1rem;
  line-height: 1;
  color: var(--gold);
  margin-bottom: 0.3rem;
}
.rec-word {
  font-family: var(--serif);
  font-size: 2.1rem;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.rec-sub {
  margin-top: 0.4rem;
  font-size: 0.66rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.rec-stats {
  flex: 1;
  align-self: center;
  display: flex;
  align-items: center;
  gap: 2.25rem;
  flex-wrap: wrap;
  min-width: 0;
}
.rec-stat { display: flex; flex-direction: column; }
.rec-stat-label {
  font-size: 0.66rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.rec-stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.rec-stat-arrow { margin-right: 0.3rem; font-size: 0.85rem; }
.rec-stat-arrow.dir-up { color: var(--fresh); }
.rec-stat-arrow.dir-down { color: var(--down); }
.rec-stat-arrow.dir-side { color: var(--stale); }

.rec-details { width: 100%; margin: 0.5rem 0 0; max-width: none; }
.rec-details p.legend { max-width: 46rem; margin-bottom: 0.4rem; }

.rec-fineprint {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

@media (max-width: 680px) {
  .rec-banner { flex-direction: column; gap: 1rem; padding: 1.15rem 1.25rem; }
  .rec-verdict {
    border-right: none;
    border-bottom: 1px solid var(--hair);
    padding: 0 0 0.9rem;
    min-width: 0;
  }
  .rec-stats { gap: 1.25rem; }
  .topline { text-align: left; }
}

/* ---------- flikar ---------- */

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs [role="tab"] {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.42rem 1rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s ease, background-color 0.12s ease;
}
.tabs [role="tab"]:hover { color: var(--fg); background: var(--hair); }
.tabs [role="tab"][aria-selected="true"] {
  color: var(--gold-deep);
  background: var(--gold-soft);
  border-color: color-mix(in srgb, var(--gold) 25%, transparent);
}

/* ---------- paneler ---------- */

main { padding-top: 1.75rem; padding-bottom: 2rem; }

section[role="tabpanel"] { outline: none; }

.intro {
  margin: 0 0 1.5rem;
  max-width: 46rem;
  color: var(--fg);
  font-size: 0.92rem;
}
.intro strong { color: var(--gold-deep); }

h3 {
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  margin: 2.25rem 0 0.6rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hair);
}
h3:first-child, .intro + h3 { border-top: none; padding-top: 0; margin-top: 1.5rem; }

.hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: 0.35rem;
}

.layer-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 650;
  color: var(--gold-deep);
  background: var(--gold-soft);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  letter-spacing: 0.04em;
  vertical-align: middle;
  margin-right: 0.4rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0 0 0.9rem;
  flex-wrap: wrap;
}

button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(58, 46, 20, 0.06);
  transition: border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
button:hover {
  border-color: var(--gold);
  color: var(--gold-deep);
  box-shadow: 0 2px 8px rgba(168, 121, 15, 0.18);
}
button:disabled { opacity: 0.5; cursor: wait; box-shadow: none; }

.legend { color: var(--muted); font-size: 0.82rem; margin: 0.25rem 0 0.9rem; max-width: 60rem; }
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin: 0 0.3rem 0 0.9rem;
}
.dot:first-child { margin-left: 0; }
.dot.fresh { background: var(--fresh); }
.dot.stale { background: var(--stale); }
.dot.unknown { background: var(--unknown); }

details.help {
  margin: 0.75rem 0 1rem;
  max-width: 46rem;
}
details.help > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  list-style: none;
  user-select: none;
}
details.help > summary::-webkit-details-marker { display: none; }
details.help.wide { max-width: none; }
details.help > summary::before { content: "ⓘ "; color: var(--gold); }
details.help > summary:hover { color: var(--gold-deep); }
details.help[open] > summary { color: var(--gold-deep); }
details.help p { margin-top: 0.35rem; }

/* ---------- tabeller ---------- */

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
}

table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }

th, td {
  text-align: left;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--hair);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
th {
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

td.value { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
td.date { white-space: nowrap; }
td.lag { color: var(--muted); font-size: 0.82rem; max-width: 24rem; }
.extra { display: block; color: var(--muted); font-weight: 400; font-size: 0.78rem; white-space: normal; }
.err { display: block; color: var(--down); font-size: 0.78rem; }

tr.status-stale td.value, tr.status-stale td.date { color: var(--stale); }
tr.status-unknown td { color: var(--unknown); }
tr.status-unknown td.value { font-style: italic; font-weight: 400; }

a { color: var(--gold-deep); text-decoration-color: color-mix(in srgb, var(--gold) 40%, transparent); }
a:hover { color: var(--gold); }

/* ---------- prisspektrum (fan chart) ---------- */

.fanchart {
  margin: 0 0 1.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.25rem 0.6rem;
  box-shadow: var(--shadow-card);
}
.fanchart-title {
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 0.5rem;
}
.fanchart-scroll { overflow-x: auto; }
.fanchart-plot { position: relative; min-width: 640px; }
.fanchart-plot svg { display: block; width: 100%; height: auto; }
.fanchart .legend { max-width: none; margin-bottom: 0.5rem; }

.fanchart text {
  font-family: inherit;
  font-size: 12px;
  fill: var(--muted);
}
.fc-grid { stroke: var(--hair); stroke-width: 1; }
.fc-today { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0.7; }
.fc-band { fill: var(--gold-bright); fill-opacity: 0.12; stroke: none; }
.fc-edge { fill: none; stroke: var(--gold); stroke-width: 1; opacity: 0.45; }
.fc-mid {
  fill: none;
  stroke: var(--gold-deep);
  stroke-width: 1.75;
  stroke-dasharray: 6 4;
  stroke-linejoin: round;
}
.fc-hist {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.fc-spot { fill: var(--gold); stroke: var(--card); stroke-width: 2; }
.fc-end-key { fill: var(--muted); }
.fc-end-val { fill: var(--fg); font-weight: 600; }
.fc-cross { stroke: var(--muted); stroke-width: 1; opacity: 0.6; pointer-events: none; }
.fc-overlay { fill: transparent; cursor: crosshair; }

.fc-tooltip {
  position: absolute;
  top: 0;
  pointer-events: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
  box-shadow: var(--shadow-pop);
  white-space: nowrap;
  z-index: 5;
}
.fc-tip-date { color: var(--muted); font-size: 0.7rem; margin-bottom: 0.1rem; }
.fc-tip-row .fc-tip-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.fc-tip-note { color: var(--muted); font-size: 0.7rem; margin-top: 0.1rem; }

/* ---------- kort ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.15rem 1.3rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow-card);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.card-horizon { font-weight: 700; font-size: 0.95rem; }
.dir-badge { font-weight: 700; font-size: 0.82rem; }
.dir-up .dir-badge { color: var(--fresh); }
.dir-down .dir-badge { color: var(--down); }
.dir-side .dir-badge { color: var(--stale); }

.card-interval {
  font-size: 1.4rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  margin: 0.3rem 0 0.35rem;
  letter-spacing: -0.015em;
}
.card-interval .unit { font-size: 0.82rem; font-weight: 600; color: var(--muted); }

.card-conf {
  color: var(--muted);
  font-size: 0.78rem;
  margin: 0 0 0.5rem;
}

.card-gate {
  color: var(--muted);
  font-size: 0.78rem;
  margin: -0.2rem 0 0.5rem;
}

details.card-more { margin: 0.5rem 0 0; }
details.card-more[open] { border-top: 1px solid var(--hair); padding-top: 0.5rem; }

.ibar {
  position: relative;
  height: 8px;
  background: var(--hair);
  border-radius: 999px;
  margin: 0.35rem 0 1rem;
  overflow: hidden;
}
.ibar-zero {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--muted);
  opacity: 0.55;
}
.ibar-range {
  position: absolute;
  top: 0; bottom: 0;
  border-radius: 999px;
  background: var(--unknown);
  opacity: 0.75;
}
.dir-up .ibar-range { background: var(--fresh); }
.dir-down .ibar-range { background: var(--down); }
.dir-side .ibar-range { background: var(--stale); }
.ibar-mid {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--card);
}

.card-row { margin: 0.55rem 0; }
.card-key {
  display: block;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.card-val { display: block; }
.unknown-note {
  color: var(--muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--hair);
  padding-top: 0.55rem;
}

.conf-badge, .sig-badge {
  display: inline-block;
  padding: 0 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.conf-high { color: var(--fresh); background: var(--up-soft); }
.conf-mid { color: var(--stale); background: var(--side-soft); }
.conf-low { color: var(--down); background: var(--down-soft); }
.sig-bullish { color: var(--fresh); background: var(--up-soft); }
.sig-bearish { color: var(--down); background: var(--down-soft); }
.sig-neutral { color: var(--unknown); background: var(--hair); }
.sig-unknown { color: var(--muted); background: var(--hair); font-style: italic; }

/* Faktorsignaler som chips: färg + pil ger riktningen direkt, detaljerna
   ligger hopfällda i tabellen under. */
.sig-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1rem;
}
.sig-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--hair);
  color: var(--muted);
  cursor: default;
}
.sig-chip.sig-bullish { background: var(--up-soft); color: var(--fresh); }
.sig-chip.sig-bearish { background: var(--down-soft); color: var(--down); }
.sig-chip.sig-neutral { background: var(--hair); color: var(--unknown); }
.sig-chip.sig-unknown { font-style: italic; font-weight: 400; }

/* ---------- regimvakter ---------- */
/* Trådvakter för regimbrott: kort med status-prick (grön/gul/röd), nuvärde
   och hopfälld tröskel/konsekvens – samma hårlinje-estetik som korten. */

.watch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.7rem;
  margin: 0 0 1rem;
}
.watch-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow-card);
  font-size: 0.85rem;
}
.watch-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.watch-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--unknown);
}
.watch-ok .watch-dot { background: var(--fresh); }
.watch-warn .watch-dot { background: var(--stale); }
.watch-hit .watch-dot { background: var(--down); }
.watch-label { font-weight: 650; }
.watch-status {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.watch-ok .watch-status { color: var(--fresh); }
.watch-warn .watch-status { color: var(--stale); }
.watch-hit .watch-status { color: var(--down); }
.watch-value {
  margin-top: 0.35rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.watch-unknown .watch-value { font-style: italic; }
.watch-more { margin-top: 0.4rem; }
.watch-more summary { font-size: 0.76rem; }

/* ---------- scenarier + red team ---------- */

.prob-badge {
  font-weight: 750;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.scenario-bull .prob-badge { color: var(--fresh); }
.scenario-base .prob-badge { color: var(--stale); }
.scenario-bear .prob-badge { color: var(--down); }

.consistency-warn {
  background: var(--side-soft);
  border: 1px solid color-mix(in srgb, var(--stale) 35%, transparent);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  margin: 0 0 0.9rem;
  font-size: 0.85rem;
}

.redteam {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
}
.rt-indicators { margin: 0.25rem 0 0; padding-left: 1.25rem; }
.rt-indicators li { margin: 0.3rem 0; }

.llm-block { border-left: 3px solid var(--gold); }

/* ---------- sidfot ---------- */

footer {
  color: var(--muted);
  font-size: 0.78rem;
  padding-top: 1.25rem;
  padding-bottom: 2.5rem;
  border-top: 1px solid var(--border);
}
