:root {
  --navy: #0b1f3f;
  --accent: #00c288;
  --ink: #0b1f3f;
  --muted: #5b6b82;
  --line: #e3e8ef;
  --bg: #f6f8fb;
  --card: #fff;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #027a48;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 31, 63, .06), 0 8px 24px rgba(11, 31, 63, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }

/* ---------- Disclaimer ---------- */
.disclaimer {
  background: #eef2f7;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
}
.disclaimer .wrap { padding-top: 10px; padding-bottom: 10px; }

/* ---------- Hero ---------- */
.hero { padding: 36px 0 24px; }
.eyebrow {
  margin: 0 0 8px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(1.65rem, 5vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: -.02em;
  font-weight: 650;
}
.lead { margin: 0; max-width: 56ch; color: var(--muted); font-size: 1rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
@media (min-width: 720px) { .card { padding: 28px; } }

.card-title {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -.01em;
}
.hint { margin: 0 0 20px; color: var(--muted); font-size: .88rem; }

/* ---------- Tabs ---------- */
.tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 28px 0 32px;
}
@media (min-width: 720px) { .tabs { grid-template-columns: repeat(3, 1fr); gap: 16px; } }

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 76px;
  padding: 16px 20px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  white-space: normal;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.tab-btn:hover { border-color: #b9c6d8; transform: translateY(-1px); }
.tab-btn-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
.tab-btn-hint { font-size: .8rem; color: var(--muted); }
.tab-btn[aria-selected="true"] {
  border-color: var(--accent);
  background: #e5f9f2;
  box-shadow: 0 2px 4px rgba(0, 194, 136, .12), 0 12px 28px rgba(0, 194, 136, .2);
}
.tab-btn[aria-selected="true"] .tab-btn-title { color: var(--accent); }
.tab-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Form ---------- */
.row-grid {
  display: grid;
  gap: 8px;
  align-items: center;
}
@media (min-width: 720px) { .row-grid { gap: 12px; } }

.row-grid-single { grid-template-columns: minmax(0, 1fr) 96px; }
.row-grid-portfolio { grid-template-columns: minmax(0, 1fr) 96px 104px 40px; }
.row-grid-compare { grid-template-columns: minmax(0, 1fr) 96px 40px; }
@media (min-width: 720px) {
  .row-grid-single { grid-template-columns: minmax(0, 1fr) 110px; }
  .row-grid-portfolio { grid-template-columns: minmax(0, 1fr) 110px 140px 44px; }
  .row-grid-compare { grid-template-columns: minmax(0, 1fr) 110px 44px; }
}

.type-select {
  width: 100%;
  min-height: 44px;
  padding: 10px 10px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
}

.row-head {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 6px;
}
.holding-row { margin-bottom: 10px; }

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
}
input.isin { text-transform: uppercase; letter-spacing: .02em; }
input::placeholder { color: #93a2b5; }
input:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}
.remove-row {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.remove-row:hover { border-color: #f2c7c2; color: var(--danger); background: #fff6f5; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* ---------- Period selector ---------- */
.period-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.period-label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.period-group { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: #eef2f7; border-radius: 8px; }
.period-btn {
  min-height: 32px;
  padding: 0 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  font-weight: 650;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.period-btn.is-active { background: var(--navy); color: #fff; }
.period-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.period-note { margin: 0 0 20px; color: var(--muted); font-size: .85rem; }
.period-note strong { color: var(--ink); font-weight: 650; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
.data-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
}
.data-table th, .data-table td { padding: 10px 12px; text-align: right; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; white-space: normal; }
.data-table thead th {
  font-size: .72rem;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.data-table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--line); }
.data-table td.positive { color: var(--ok); }
.data-table td.negative { color: var(--danger); }
.data-table .fund-name { font-weight: 650; color: var(--ink); }
.data-table .fund-meta { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }

.chart-box-small { height: 160px; }
@media (min-width: 720px) { .chart-box-small { height: 200px; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #00a874; }
.btn-secondary { background: #fff; border-color: #cfd8e3; color: var(--navy); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; border-color: #cfd8e3; color: var(--navy); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .65; cursor: progress; }
.btn-submit { width: 100%; }
@media (min-width: 720px) { .btn-submit { width: auto; min-width: 180px; } }

.btn-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.is-loading .spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---------- Weight pill ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid;
  font-size: .85rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill[data-state="off"] { color: var(--danger); background: #fef3f2; border-color: #fecdc9; }
.pill[data-state="near"] { color: var(--warn); background: #fffaeb; border-color: #fedf89; }
.pill[data-state="ok"] { color: var(--ok); background: #ecfdf3; border-color: #a6f4c5; }

/* ---------- Banners ---------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 20px 0;
  padding: 14px 16px;
  border: 1px solid;
  border-radius: var(--radius);
  font-size: .9rem;
}
.banner-icon { flex: none; width: 20px; height: 20px; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.banner-error { color: var(--danger); background: #fef3f2; border-color: #fecdc9; }
.banner-warning { color: var(--warn); background: #fffaeb; border-color: #fedf89; }

/* ---------- Results ---------- */
#results { margin-bottom: 48px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 28px 0;
}
.cards .card {
  padding: 18px 16px;
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
}
.cards .card[data-tone="risk"] { border-top-color: #b54708; }
.cards .card[data-tone="loss"] { border-top-color: var(--danger); }
.cards .card[data-tone="ratio"] { border-top-color: var(--navy); }
.metric-value {
  font-size: clamp(1.5rem, 4.5vw, 1.85rem);
  font-weight: 650;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.metric-label { margin-top: 4px; color: var(--muted); font-size: .8rem; font-weight: 500; }

.chart-card .card-title { margin-bottom: 16px; }
.chart-box { position: relative; height: 280px; }
@media (min-width: 720px) { .chart-box { height: 380px; } }

.results-actions { margin-top: 20px; }
.results-actions .btn { width: 100%; }
@media (min-width: 720px) { .results-actions .btn { width: auto; } }

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .hero { padding: 16px 0 12px; }
  .disclaimer { background: none; border-bottom: 1px solid #ccc; }
  #portfolio-form, .results-actions, .form-actions, .tabs { display: none !important; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .cards { margin: 16px 0; grid-template-columns: repeat(4, 1fr); }
  .chart-box { height: 300px; }
}
