/* ── Fonts: Canela Light, lokalt (kvartil.se:s CDN är CORS-låst) ─────── */
@font-face {
  font-family: 'Canela';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/canela-light.woff2') format('woff2');
}
@font-face {
  font-family: 'Canela';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/canela-lightitalic.woff2') format('woff2');
}

/* ── Kvartil Design System ─────────────────────────────────────────── */
:root {
  --kv-navy:         #00003B;
  --kv-gray:         #646464;
  --kv-pink:         #E83F6F;
  --kv-bg:           #FAFAFA;
  --kv-blue:         #214BB7;
  --kv-blue-lt:      #91B8FF;
  --kv-gray-lt:      #E0E5EC;
  --kv-pink-lt:      #DC93B0;
  --kv-green:        #214BB7;  /* design-blå för "positivt" (semantik) */
  --kv-shadow-dark:  rgba(0,0,0,0.10);
  --kv-shadow-light: rgba(163,177,198,0.30);
  --kv-highlight:    #FFFFFF;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  background: var(--kv-gray-lt);
  color: var(--kv-navy);
  font-size: 1rem;
  line-height: 1.5;
}

.app { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ── Baseline-tabell (Multi-Asset utgångspunkt) ─────────────────────── */
.baseline-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  color: var(--kv-navy);
}
.baseline-table td {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--kv-gray-lt);
}
.baseline-table td:first-child { color: var(--kv-gray); padding-right: 1.5rem; }
.baseline-table td:last-child  { text-align: right; font-weight: 700; padding-left: 1.5rem; }
.baseline-table tr.sep td      { border-top: 2px solid var(--kv-navy); padding-top: 0.55rem; }
.baseline-table tr:last-child td { border-bottom: none; }

/* ── Intro-text under header (i kort som övriga paneler) ────────────── */
.intro-text {
  color: var(--kv-navy);
  font-size: 0.9rem;
  line-height: 1.55;
}
.intro-text p { margin-bottom: 0.75rem; }
.intro-text p:last-child { margin-bottom: 0; }
.intro-text .intro-lead {
  font-family: 'Roboto', sans-serif;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--kv-navy);
  margin-bottom: 0.9rem;
}
.intro-text.disclaimer {
  color: var(--kv-gray);
  font-size: 0.82rem;
  line-height: 1.55;
}
.intro-text.disclaimer h3 { color: var(--kv-navy); }

/* ── Header (logga + h1 + subtitle) — matchar stiftelse-kalkylatorn ──── */
.app-header {
  display: block;
  margin-bottom: 1.5rem;
}
.app-header .kv-logo { display: block; margin-bottom: 1rem; }
.app-header .kv-logo img { height: 80px; width: auto; display: block; }
.app-header h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 2.25rem;
  font-weight: 300;
  color: var(--kv-navy);
  letter-spacing: -0.02em;
  margin-bottom: 0.2rem;
}
.app-header .page-subtitle {
  font-family: 'Roboto', sans-serif;
  color: var(--kv-navy);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: normal;
  margin: 0;
  max-width: 720px;
}

.mode-toggle {
  display: inline-flex;
  border-radius: 10px;
  border: 2px solid var(--kv-navy);
  overflow: hidden;
  background: var(--kv-bg);
  flex-shrink: 0;
}
.mode-toggle button {
  background: transparent;
  border: none;
  padding: 0.55rem 1.1rem;
  font-size: 0.85rem;
  font-family: 'Roboto', sans-serif;
  color: var(--kv-gray);
  cursor: pointer;
  font-weight: 500;
  letter-spacing: 0.005em;
  transition: background 0.15s, color 0.15s;
}
.mode-toggle button.active {
  background: var(--kv-navy);
  color: #FFFFFF;
}
.mode-toggle button:hover:not(.active) {
  background: rgba(0, 0, 59, 0.05);
  color: var(--kv-navy);
}

.kv-logo {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.kv-logo img { width: auto; display: block; }

/* ── Mode-card (investerartyp) ─────────────────────────────────────── */
.mode-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.mode-card-header h3 { margin-bottom: 0; }

.mode-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 700px) {
  .mode-card-body { grid-template-columns: 1fr; }
}
.mode-option {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 1rem 1.1rem;
  border-radius: 10px;
  border: 1.5px solid var(--kv-gray-lt);
  background: transparent;
  transition: border-color 0.15s, background 0.15s;
}
.mode-option:hover {
  border-color: var(--kv-navy);
}
.mode-option:focus-visible {
  outline: 2px solid var(--kv-blue);
  outline-offset: 2px;
}
.mode-option.active {
  border-color: var(--kv-navy);
  background: rgba(0, 0, 59, 0.025);
}
.mode-option-label {
  font-family: 'Roboto', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--kv-pink);
  margin-bottom: 0.4rem;
}
.mode-option.active .mode-option-label {
  color: var(--kv-navy);
}
.mode-option p {
  font-family: 'Roboto', sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--kv-navy);
  margin: 0;
}


/* Mindre toggle (t.ex. Real/Nominell inom en panel) */
.mini-toggle {
  display: inline-flex;
  border-radius: 10px;
  border: 1.5px solid var(--kv-navy);
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.mini-toggle button {
  background: transparent;
  border: none;
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
  font-family: 'Roboto', sans-serif;
  color: var(--kv-gray);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.mini-toggle button.active {
  background: var(--kv-navy);
  color: #FFFFFF;
}
.mini-toggle button:hover:not(.active) {
  background: rgba(0, 0, 59, 0.05);
  color: var(--kv-navy);
}

/* ── Typography (Kvartil Design System) ─────────────────────────────── */
/* h1 / h2 / h3 = Canela Light (serif).  body = Roboto Regular.          */
h1 {
  font-family: 'Canela', Georgia, 'Times New Roman', serif;
  font-size: 3rem;
  font-weight: 400;
  color: var(--kv-navy);
  letter-spacing: 0.012em;
  line-height: 1.1;
  margin-bottom: 0.5rem;
}
.h2-serif {
  font-family: 'Canela', Georgia, 'Times New Roman', serif;
  font-size: 2rem;
  font-weight: 400;
  color: var(--kv-navy);
  letter-spacing: 0.012em;
  line-height: 1.2;
  margin-bottom: 1rem;
}
h3, .card h3 {
  font-family: 'Roboto', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--kv-navy);
  letter-spacing: -0.005em;
  line-height: 1.4;
  padding-bottom: 0.375rem;
  border-bottom: 2px solid var(--kv-blue-lt);
  margin-bottom: 1rem;
  display: block;
}
.subtitle {
  color: var(--kv-gray);
  font-family: 'Roboto', sans-serif;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  margin-bottom: 1.5rem;
}
.subtitle.lead {
  font-family: 'Canela', Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-size: 1.25rem;
  letter-spacing: 0.012em;
  color: var(--kv-navy);
  opacity: 0.8;
}

/* H1-underrubrik (samma stil som Kvartils sektionsubsubrubriker:
   Canela light, ej italic, navy, lite gles) */
.page-subtitle {
  font-family: 'Roboto', sans-serif;
  font-size: 1.125rem;
  font-weight: 400;
  color: var(--kv-navy);
  letter-spacing: 0.005em;
  line-height: 1.5;
  margin-top: 0.5rem;
  margin-bottom: 0;
  max-width: 720px;
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.viewer-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.viewer-grid > * { min-width: 0; }
@media (max-width: 900px) {
  .viewer-grid { grid-template-columns: 1fr; }
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  align-items: stretch;
}
.charts-grid > * { min-width: 0; }
.charts-grid > .card {
  display: flex;
  flex-direction: column;
}
.charts-grid > .card > .chart-wrap {
  margin-top: auto;
}
@media (max-width: 1000px) {
  .charts-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .charts-grid { grid-template-columns: 1fr; }
}

/* ── Cards (neumorphic base) ────────────────────────────────────────── */
.card {
  background: var(--kv-bg);
  border-radius: 10px;
  border: none;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 6px 6px 12px var(--kv-shadow-light), -4px -4px 10px var(--kv-highlight);
}
.card-result { }
.card-tight  { padding: 1rem; }

/* ── Slider rows ────────────────────────────────────────────────────── */
.slider-block { margin-bottom: 1.1rem; }
.slider-label-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 0.35rem;
}
.slider-label-row .label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--kv-navy);
}
.slider-label-row .value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--kv-blue);
  font-variant-numeric: tabular-nums;
}
.slider-label-row .value.neg { color: var(--kv-pink); }
.slider-label-row .value.zero { color: var(--kv-gray); }

input[type="range"] {
  width: 100%;
  accent-color: var(--kv-navy);
  height: 4px;
}
.slider-scale {
  position: relative;
  height: 1.85rem;
  font-size: 0.7rem;
  color: var(--kv-gray);
  margin-top: 0.2rem;
}
.slider-scale .scale-min  { position: absolute; left: 0; top: 0; }
.slider-scale .scale-max  { position: absolute; right: 0; top: 0; }
.slider-scale .scale-zero { position: absolute; transform: translateX(-50%); top: 0; }
.slider-scale .scale-default {
  position: absolute;
  transform: translateX(-50%);
  top: 1rem;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--kv-blue);
  font-variant-numeric: tabular-nums;
}
.slider-scale .scale-default::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 1px;
  width: 1px;
  height: 7px;
  background: var(--kv-blue);
}

/* ── Buttons (Kvartil Design System: border-radius 10) ──────────────── */
.btn-reset {
  background: transparent;
  color: var(--kv-navy);
  border: 2px solid var(--kv-navy);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 400;
  font-family: 'Roboto', sans-serif;
  cursor: pointer;
  width: 100%;
  margin-top: 0.75rem;
  transition: background 0.15s, color 0.15s;
}
.btn-reset:hover { background: var(--kv-navy); color: #FFFFFF; }

/* ── Metric tiles ───────────────────────────────────────────────────── */
/* Wrapper for wide tables that need to scroll horizontally on narrow viewports. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Summary-tabell (nyckeltal i kort) ──────────────────────────────── */
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  color: var(--kv-navy);
}
.summary-table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--kv-gray);
  font-weight: 500;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--kv-gray-lt);
  text-align: right;
  vertical-align: bottom;
}
.summary-table thead th:first-child {
  text-align: left;
  text-transform: none;
  letter-spacing: 0.012em;
  font-family: 'Canela', Georgia, 'Times New Roman', serif;
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--kv-navy);
}
.summary-table thead th:first-child .vs {
  display: block;
  margin-top: 0.1rem;
  color: var(--kv-gray);
  font-weight: 400;
  font-size: 0.85rem;
  font-style: italic;
  font-family: 'Roboto', sans-serif;
  letter-spacing: 0;
}
.summary-table tbody tr th {
  text-align: left;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.7rem 0.6rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--kv-gray-lt);
  color: var(--kv-navy);
}
.summary-table tbody td {
  text-align: right;
  padding: 0.7rem 0.6rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--kv-gray-lt);
}
.summary-table tbody td.accent {
  background: var(--kv-navy);
  color: #FFFFFF;
}
.summary-table tbody td.muted { color: var(--kv-gray); }
.summary-table tbody td.vol-cell { background: rgba(0, 0, 59, 0.03); }
.summary-table .cell-value {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.15;
}
.summary-table .cell-delta {
  font-size: 0.72rem;
  font-weight: 500;
  margin-top: 0.15rem;
}
.summary-table .cell-delta.pos { color: var(--kv-green); }
.summary-table .cell-delta.neg { color: var(--kv-pink); }
.summary-table tbody td.accent .cell-delta { color: rgba(255,255,255,0.85); }
.summary-table tbody tr:last-child th,
.summary-table tbody tr:last-child td { border-bottom: none; }
.metric-tile {
  background: var(--kv-bg);
  border-radius: 8px;
  padding: 0.85rem 0.75rem;
  text-align: center;
  box-shadow: inset 2px 2px 4px var(--kv-shadow-light), inset -2px -2px 4px var(--kv-highlight);
}
.metric-tile.accent {
  background: var(--kv-navy);
  box-shadow: 4px 4px 8px var(--kv-shadow-light);
}
.metric-tile .label {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--kv-gray);
  margin-bottom: 0.3rem;
}
.metric-tile.accent .label { color: rgba(255,255,255,0.7); }
.metric-tile .value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--kv-navy);
}
.metric-tile.accent .value { color: #FFFFFF; }
.metric-tile .delta {
  font-size: 0.7rem;
  font-weight: 500;
  margin-top: 0.15rem;
}
.delta.pos { color: var(--kv-green); }
.delta.neg { color: var(--kv-pink); }
@media (max-width: 700px) {
  .metrics-row { grid-template-columns: repeat(2, 1fr); }
}

/* ── Splash ─────────────────────────────────────────────────────────── */
#splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--kv-gray-lt);
  font-family: 'Roboto', sans-serif;
  color: var(--kv-gray);
  font-size: 0.95rem;
  z-index: 1000;
  transition: opacity 0.3s;
}
#splash.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid var(--kv-blue-lt);
  border-top-color: var(--kv-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 0.6rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── SVG chart helpers ──────────────────────────────────────────────── */
.chart-wrap { width: 100%; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.axis text { font-size: 10px; fill: var(--kv-gray); font-family: 'Roboto', sans-serif; }
.axis line, .axis path { stroke: var(--kv-gray-lt); }
.gridline { stroke: var(--kv-gray-lt); stroke-dasharray: 2,3; }
.tooltip-box {
  fill: var(--kv-navy);
  fill-opacity: 0.92;
}
.tooltip-text {
  fill: #FFFFFF;
  font-size: 11px;
  font-family: 'Roboto', sans-serif;
}

/* ── CAPE-panelens introtext ────────────────────────────────────────── */
.cape-intro {
  font-family: 'Roboto', sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--kv-navy);
  max-width: 880px;
  margin: 0 0 1rem;
}

/* ── Cost table ─────────────────────────────────────────────────────── */
.cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--kv-navy);
}
.cost-table th,
.cost-table td { padding: 0.34rem 0.55rem; }
.cost-table thead th {
  color: var(--kv-gray);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--kv-gray-lt);
}
.cost-table td.muted { color: var(--kv-gray); }
.cost-table th.ar,
.cost-table td.ar { text-align: right; }
.cost-table th.al,
.cost-table td.al { text-align: left; }
.cost-table tr.cost-table-group td {
  font-weight: 700;
  background: rgba(0, 0, 59, 0.04);
  border-top: 1px solid var(--kv-gray-lt);
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}
.cost-table tr.cost-table-row td.indent { padding-left: 1.4rem; }
.cost-table tr.cost-table-sum td {
  font-weight: 700;
  border-top: 2px solid var(--kv-navy);
  padding-top: 0.5rem;
}

/* ── Weights table ──────────────────────────────────────────────────── */
.weights-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--kv-navy);
}
.weights-table th,
.weights-table td { padding: 0.35rem 0.6rem; vertical-align: middle; }
.weights-table thead th {
  color: var(--kv-gray);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--kv-gray-lt);
  text-align: left;
}
.weights-table th.ar,
.weights-table td.ar { text-align: right; }
.weights-table th.al,
.weights-table td.al { text-align: left; }
.weights-table th.wt-bar { width: 232px; }
.weights-table tr.wt-group td {
  font-weight: 700;
  background: rgba(0, 0, 59, 0.04);
  border-top: 1px solid var(--kv-gray-lt);
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}
.weights-table tr.wt-row td.indent { padding-left: 1.4rem; }
.weights-table tr.wt-sum td {
  font-weight: 700;
  border-top: 2px solid var(--kv-navy);
  padding-top: 0.5rem;
}

/* ── Footer ─────────────────────────────────────────────────────────── */
.app-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--kv-gray-lt);
  font-size: 0.75rem;
  color: var(--kv-gray);
  text-align: center;
}
