/* Portfolio design system — calm, precise, financial. Self-hosted, no CDN. */

:root {
  --bg: #0e1013;
  --surface: #15181d;
  --surface-raised: #1a1e25;
  --line: #262b33;
  --line-soft: #1d2129;
  --text: #eceef1;
  --text-muted: #8b909c;
  --text-faint: #5c626d;
  --accent: #c99a4a;
  --accent-ink: #1a1408;
  --pos: #55b083;
  --neg: #d97463;
  --focus: #d7ac66;

  --font-ui: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

button, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* --- login ------------------------------------------------------------ */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(360px, 100%);
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.login-mark {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--accent);
}

.login-card h1 {
  margin: 0 0 24px;
  font-size: 20px;
  font-weight: 600;
}

.login-card label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin: 14px 0 6px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
}

.login-card button {
  width: 100%;
  margin-top: 22px;
  padding: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}

.login-error {
  margin: 0 0 4px;
  padding: 10px 12px;
  border: 1px solid var(--neg);
  border-radius: 4px;
  color: var(--neg);
  font-size: 13px;
}

/* --- shell -------------------------------------------------------------- */

.app-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 24px 64px;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}

.brand {
  font-family: var(--font-mono);
  letter-spacing: 0.14em;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.freshness {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

.logout-form { margin-left: auto; }

.link-button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 0;
}
.link-button:hover { color: var(--text); }

/* --- filters -------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin-bottom: 22px;
}

.filter-modes { display: flex; gap: 6px; }

.mode-btn, .chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.mode-btn:hover, .chip:hover { border-color: var(--text-muted); color: var(--text); }

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.chip-active:hover { color: var(--accent-ink); }

/* --- sync status ------------------------------------------------------------ */

.sync-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
  margin-bottom: 18px;
  font-size: 11.5px;
}

.sync-status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
}

.sync-status-provider {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sync-status-never { color: var(--text-faint); font-style: italic; }

/* --- summary -------------------------------------------------------------- */

.summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 26px;
}

.summary-stat {
  padding: 16px 20px;
  border-left: 1px solid var(--line-soft);
}
.summary-stat:first-child { border-left: none; }

.stat-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.stat-value {
  display: block;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 19px;
  font-weight: 600;
}

.stat-sub {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

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

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-family: var(--font-ui);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  vertical-align: middle;
}
.badge-ok { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 40%, transparent); }
.badge-estimated { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.badge-missing { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 45%, transparent); }

/* --- charts -------------------------------------------------------------- */

.charts {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 24px;
  margin-bottom: 30px;
}

.chart-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px 20px 20px;
  background: var(--surface);
  min-width: 0;
}

.chart-panel h2, .evolution-head h2, .detail h2, .holdings h2 {
  margin: 0 0 14px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

svg[data-chart="donut"] { display: block; margin: 0 auto; width: 100%; max-width: 220px; height: auto; }

.legend {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
}
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.legend .amount { margin-left: auto; font-family: var(--font-mono); color: var(--text-muted); }

.treemap {
  display: grid;
  gap: 4px;
  grid-auto-rows: 46px;
}
.treemap .tm-cell {
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--accent-ink);
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tm-cell .tm-name { font-weight: 600; }
.tm-cell .tm-value { font-family: var(--font-mono); opacity: 0.85; }

/* --- evolution -------------------------------------------------------------- */

.evolution {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px 20px 12px;
  background: var(--surface);
  margin-bottom: 30px;
}

.evolution-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.evolution-head h2 { margin: 0; }

.period-switch { display: flex; gap: 4px; }

.period-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  padding: 4px 9px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
}
.period-btn:hover { color: var(--text); }
.period-active { color: var(--accent); border-color: var(--accent); }

svg[data-chart="evolution"] { display: block; width: 100%; height: 220px; margin-top: 12px; }

.chart-empty { color: var(--text-faint); font-size: 13px; margin: 12px 0 0; }

/* --- holdings table -------------------------------------------------------------- */

.holdings { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

td a { text-decoration: none; }
td a:hover { text-decoration: underline; }

.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }

.empty-row { color: var(--text-faint); text-align: center; padding: 24px 0; }

/* --- instrument detail -------------------------------------------------------------- */

.detail { padding-top: 4px; }
.detail h1 { font-size: 22px; margin: 0 0 20px; }

.detail-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 26px;
}
.detail-stats .summary-stat { border-left: 1px solid var(--line-soft); }
.detail-stats .summary-stat:first-child { border-left: none; }

/* --- responsive: mobile 390x844 -------------------------------------------------------------- */

@media (max-width: 780px) {
  .app-shell { padding: 14px 14px 48px; }
  .summary, .detail-stats { grid-template-columns: repeat(2, 1fr); }
  .summary-stat:nth-child(3), .detail-stats .summary-stat:nth-child(3) { border-left: none; }
  .summary-stat, .detail-stats .summary-stat { border-top: 1px solid var(--line-soft); }
  .summary-stat:first-child, .summary-stat:nth-child(2),
  .detail-stats .summary-stat:first-child, .detail-stats .summary-stat:nth-child(2) { border-top: none; }
  .charts { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  table { font-size: 12px; }
  .stat-value { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
