:root {
  --paper:        #f4efe4;
  --paper-edge:   #ece6d5;
  --surface:      #fbf7ed;
  --ink:          #1c1a14;
  --ink-soft:     #3a362d;
  --ink-muted:    #807a6b;
  --hairline:     #d9d2bf;
  --hairline-soft:#e6dfcc;
  --gain:         #3f6b4d;
  --loss:         #a64a3a;
  --accent:       #b88a35;
  --shadow:       0 1px 0 rgba(28, 26, 20, 0.04);

  --font-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-body:    "Geist", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --font-mono:    "Geist Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}

/* Subtle paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.11 0 0 0 0 0.10 0 0 0 0 0.08 0 0 0 0.045 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.6;
  mix-blend-mode: multiply;
}

main, header, .modal-backdrop { position: relative; z-index: 1; }

.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.muted { color: var(--ink-muted); }

/* ---------- Masthead ---------- */
.masthead {
  border-bottom: 1px solid var(--hairline);
  background: var(--paper);
}
.masthead-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand-mark {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 28px;
  line-height: 1;
  color: var(--accent);
}
.brand-text {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.01em;
}
.masthead-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
}

/* ---------- Buttons ---------- */
.btn-primary, .btn-ghost, .btn-danger, .btn-icon {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.btn-primary {
  background: var(--ink);
  color: var(--paper);
}
.btn-primary:hover { background: var(--ink-soft); }
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--hairline);
}
.btn-ghost:hover {
  background: var(--surface);
  border-color: var(--ink-muted);
}
.btn-danger {
  background: transparent;
  color: var(--loss);
  border-color: var(--hairline);
}
.btn-danger:hover {
  background: rgba(166, 74, 58, 0.08);
  border-color: var(--loss);
}
.btn-icon {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 22px;
  padding: 0 8px;
  line-height: 1;
}
.btn-icon:hover { color: var(--ink); }

/* ---------- Page ---------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 32px 80px;
}

/* ---------- Hero ---------- */
.hero {
  padding: 24px 0 48px;
  border-bottom: 1px solid var(--hairline-soft);
  margin-bottom: 40px;
}
.hero-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-muted);
  margin-bottom: 14px;
}
.hero-value {
  font-family: var(--font-display);
  font-size: clamp(56px, 9vw, 104px);
  line-height: 1;
  letter-spacing: -0.02em;
  font-feature-settings: "lnum", "tnum";
  margin-bottom: 14px;
  color: var(--ink);
}
.hero-sub { font-size: 14px; }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 32px;
  align-items: start;
}
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .masthead-inner, .page { padding-left: 20px; padding-right: 20px; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.card-header h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.005em;
}

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex;
  background: var(--paper-edge);
  border-radius: 6px;
  padding: 2px;
  border: 1px solid var(--hairline);
}
.seg-btn {
  background: transparent;
  border: none;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--ink-muted);
  cursor: pointer;
  border-radius: 4px;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

/* ---------- Donut chart ---------- */
.chart-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 320px;
  margin: 0 auto;
}
.chart-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.chart-center-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-muted);
  margin-bottom: 4px;
}
.chart-center-value {
  font-family: var(--font-display);
  font-size: 28px;
}

/* ---------- Legend ---------- */
.legend {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline-soft);
  font-size: 13px;
}
.legend-row:last-child { border-bottom: none; }
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.legend-name { color: var(--ink-soft); }
.legend-pct { font-family: var(--font-mono); font-size: 12px; color: var(--ink); }
.legend-target { font-family: var(--font-mono); font-size: 11px; color: var(--ink-muted); }

/* ---------- Holdings table ---------- */
.table-scroll { overflow-x: auto; }
.holdings {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.holdings thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--hairline);
}
.holdings thead th.num { text-align: right; }
.holdings tbody td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--hairline-soft);
  vertical-align: middle;
}
.holdings tbody tr:last-child td { border-bottom: none; }
.holdings tbody tr:hover { background: var(--paper-edge); }
.holdings .num {
  text-align: right;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
}
.asset-name { font-weight: 500; color: var(--ink); }
.asset-meta {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
  display: flex;
  gap: 8px;
}
.asset-meta .symbol {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.asset-meta .dot {
  color: var(--hairline);
}

.actual-target {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
.actual-target .actual { color: var(--ink); }
.actual-target .target { font-size: 11px; color: var(--ink-muted); }

.drift-pos { color: var(--gain); }
.drift-neg { color: var(--loss); }
.drift-zero { color: var(--ink-muted); }

.row-action {
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
}
.row-action:hover {
  background: var(--paper);
  border-color: var(--ink-muted);
}

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-muted);
}
.empty-art {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 48px;
  color: var(--hairline);
  margin-bottom: 12px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 26, 20, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(28, 26, 20, 0.18);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--hairline-soft);
}
.modal-header h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 22px;
  margin: 0;
}
.form { padding: 20px 24px 24px; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.field > span {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.field > span em {
  font-style: normal;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-muted);
  margin-left: 4px;
}
.field input,
.field select,
.field textarea {
  font: inherit;
  font-family: var(--font-body);
  padding: 9px 12px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.field input[name="symbol"], .field input[name="quantity"],
.field input[name="manual_value"], .field input[name="target_pct"] {
  font-family: var(--font-mono);
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--ink-soft);
}
.field[hidden] { display: none; }

.form-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline-soft);
}
.form-footer .btn-danger { margin-right: auto; }
