:root {
  --bg: oklch(0.985 0.005 85);
  --surface: oklch(1 0 0);
  --ink: oklch(0.18 0.01 85);
  --ink-2: oklch(0.32 0.01 85);
  --muted: oklch(0.55 0.005 85);
  --dim: oklch(0.7 0.005 85);
  --border: oklch(0.91 0.005 85);
  --border-strong: oklch(0.82 0.005 85);
  --accent: oklch(0.55 0.13 145);
  --pos: oklch(0.5 0.13 145);
  --loss: oklch(0.55 0.16 28);
  --shadow: 0 1px 0 oklch(0.93 0.005 85), 0 1px 3px oklch(0.85 0.005 85 / 0.4);

  --pad-card: 28px;
  --gap: 20px;
  --radius: 8px;

  font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  font-feature-settings: "ss01", "cv11", "tnum";
}

[data-density="compact"] {
  --pad-card: 18px;
  --gap: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  font-feature-settings: "tnum", "zero";
  letter-spacing: -0.005em;
}

.dim { color: var(--dim); }
.pos { color: var(--pos); }
.neg { color: var(--loss); }

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  margin-bottom: 4px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--accent);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  background: oklch(1 0 0 / 0.85);
  border-radius: 2px;
  clip-path: polygon(0 100%, 25% 60%, 50% 75%, 75% 30%, 100% 50%, 100% 100%);
}
.brand-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--ink-2);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
}
.status-dot[data-state="live"] { background: var(--pos); box-shadow: 0 0 0 3px oklch(0.5 0.13 145 / 0.18); }
.status-dot[data-state="closed"] { background: var(--muted); }
.divider {
  width: 1px;
  height: 14px;
  background: var(--border-strong);
}

/* Meta strip */
.meta-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.meta {
  padding: 18px 22px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.meta:last-child { border-right: none; }
.meta-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.meta-value {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}
.meta-small { font-size: 11px; color: var(--muted); font-weight: 400; }

/* KPI cards */
.kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--gap);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kpi-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kpi-value {
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.kpi-sub {
  font-size: 11px;
  color: var(--muted);
}
.kpi.pos .kpi-value { color: var(--pos); }
.kpi.neg .kpi-value { color: var(--loss); }

.pill {
  display: inline-block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}
.pill.live, .pill.deposit { background: oklch(0.94 0.04 145); color: oklch(0.4 0.12 145); }
.pill.closed, .pill.withdrawal { background: oklch(0.94 0.04 28); color: oklch(0.45 0.14 28); }

/* Grid */
.grid-two {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: var(--gap);
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad-card);
  position: relative;
}
.card-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 18px;
}
.card-head.row {
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-end;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.card-sub {
  font-size: 12px;
  color: var(--muted);
}

/* Chart */
.chart {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
}
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { font-size: 10px; fill: var(--muted); font-family: "IBM Plex Mono", monospace; }
.chart .hover-line { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .flow-line { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 1 3; }
.chart .flow-dot { fill: var(--surface); stroke-width: 2; }
.chart .flow-label {
  font-size: 10px;
  fill: var(--ink-2);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
}

.chart-card { position: relative; }
.tooltip {
  position: absolute;
  top: 60px;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--ink);
  color: oklch(0.98 0.005 85);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 11px;
  min-width: 140px;
  box-shadow: 0 4px 16px oklch(0 0 0 / 0.15);
  z-index: 10;
}
.tt-month {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid oklch(0.4 0.01 85);
}
.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}
.tt-row .pos { color: oklch(0.78 0.15 145); }
.tt-row .neg { color: oklch(0.78 0.15 28); }

/* Period (year) panel */
.period-card { display: flex; flex-direction: column; }
.year-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}
.year-row {
  display: grid;
  grid-template-columns: 48px 1fr auto 36px 90px;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}
.year-label { font-weight: 500; }
.year-bar-wrap {
  height: 10px;
  background: oklch(0.95 0.005 85);
  border-radius: 2px;
  overflow: hidden;
}
.year-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}
.year-profit { font-weight: 500; text-align: right; font-size: 13px; }
.year-meta { font-size: 12px; text-align: center; }
.year-flow { font-size: 12px; text-align: right; }
.period-head {
  display: grid;
  grid-template-columns: 48px 1fr auto 36px 90px;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.period-head span:nth-child(3),
.period-head span:nth-child(5) { text-align: right; }
.period-head span:nth-child(4) { text-align: center; }

/* Table */
.table-wrap {
  overflow-x: auto;
}
.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ledger th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: oklch(0.99 0.003 85);
  position: sticky;
  top: 0;
}
.ledger th.sortable {
  cursor: pointer;
  user-select: none;
}
.ledger th.sortable:hover { color: var(--ink); }
.ledger th.active { color: var(--ink); }
.ledger th .sort-arrow {
  margin-left: 6px;
  opacity: 0.4;
  font-size: 10px;
}
.ledger th.active .sort-arrow { opacity: 1; }
.ledger td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.ledger tr:last-child td { border-bottom: none; }
.ledger tr:hover td { background: oklch(0.98 0.005 85); }
.ta-right { text-align: right; }
.ta-left { text-align: left; }

.trend {
  width: 80px;
  height: 6px;
  background: oklch(0.95 0.005 85);
  border-radius: 1px;
  overflow: hidden;
}
.trend-bar {
  display: block;
  height: 100%;
  transition: width 0.3s ease;
}

[data-density="compact"] .ledger td { padding: 6px 12px; }
[data-density="compact"] .ledger th { padding: 8px 12px; }
[data-density="compact"] .kpi-value { font-size: 19px; }

/* Filters */
.filters {
  display: flex;
  gap: 10px;
  align-items: center;
}
.seg {
  display: flex;
  background: oklch(0.96 0.005 85);
  border-radius: 5px;
  padding: 2px;
  border: 1px solid var(--border);
}
.seg-btn {
  border: none;
  background: transparent;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 5px 12px;
  border-radius: 3px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  font-weight: 500;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.06);
}
.select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}

/* Bar chart */
.bar.pos { fill: var(--accent); }
.bar.neg { fill: var(--loss); }

/* Footer */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-two { grid-template-columns: 1fr; }
  .meta-strip { grid-template-columns: repeat(2, 1fr); }
  .meta:nth-child(odd) { border-right: 1px solid var(--border); }
  .meta { border-bottom: 1px solid var(--border); }
}

/* === Multi-fund additions === */

.kpis-4 { grid-template-columns: repeat(4, 1fr); }

/* Fund tabs */
.fund-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.fund-tab {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  position: relative;
}
.fund-tab:hover {
  border-color: var(--border-strong);
}
.fund-tab.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink) inset;
}
.fund-tab-mark {
  width: 10px;
  height: 36px;
  border-radius: 2px;
  flex-shrink: 0;
}
.fund-tab-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.fund-tab-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.fund-tab-hebrew {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}
.fund-tab-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-2);
  gap: 8px;
}

/* Fund comparison cards */
.fund-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}
.fund-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--pad-card);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.fund-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.fund-card-name {
  display: flex;
  align-items: center;
  gap: 12px;
}
.fund-mark {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  flex-shrink: 0;
}
.fund-card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.fund-card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.fund-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px 24px;
}
.fund-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fund-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.fund-stat-value {
  font-size: 17px;
  font-weight: 500;
}
.badge-best {
  font-size: 8px;
  letter-spacing: 0.08em;
  background: var(--ink);
  color: var(--bg);
  padding: 2px 5px;
  border-radius: 2px;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
}

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--ink-2);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Matrix */
.matrix-wrap { overflow-x: auto; }
.matrix {
  width: 100%;
  border-collapse: separate;
  border-spacing: 3px;
  font-size: 12px;
}
.matrix th {
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 10px;
  white-space: nowrap;
}
.matrix th:first-child { text-align: left; }
.matrix th:not(:first-child) { text-align: right; }
.matrix .matrix-month {
  font-size: 12px;
  color: var(--ink-2);
  padding: 8px 10px;
  white-space: nowrap;
  font-weight: 500;
}
.matrix .matrix-cell {
  padding: 9px 12px;
  text-align: right;
  border-radius: 4px;
  font-size: 12px;
  min-width: 110px;
}
.matrix .matrix-cell.dim { background: oklch(0.97 0.005 85); color: var(--dim); }

@media (max-width: 1100px) {
  .kpis-4 { grid-template-columns: repeat(2, 1fr); }
  .fund-tabs { grid-template-columns: repeat(2, 1fr); }
  .fund-cards { grid-template-columns: 1fr; }
}
