/* ── Variables ─────────────────────────────────────────────── */
:root {
  --bg:           #0d1117;
  --bg-card:      #161b22;
  --bg-card-hover:#1c2330;
  --border:       #30363d;
  --text:         #e6edf3;
  --text-muted:   #7d8590;
  --accent:       #2ea043;
  --accent-light: #3fb950;
  --positive:     #3fb950;
  --negative:     #f85149;
  --warning-bg:   #2a1f00;
  --warning-text: #e3b341;
  --radius:       10px;
}

/* ── Reset / Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

h2 { margin-top: 0; font-weight: 700; }
h3 { font-weight: 600; color: var(--text); }

/* ── Layout wrapper ────────────────────────────────────────── */
.site-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

/* ── Header ────────────────────────────────────────────────── */
header {
  background: #010409;
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  margin-bottom: 2.5rem;
}

.header-top {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

header h1 { margin: 0; font-size: 1.2rem; }

header h1 a {
  color: var(--accent-light);
  font-weight: 700;
  letter-spacing: -0.02em;
}

header h1 a:hover { text-decoration: none; opacity: 0.85; }

header p {
  display: none; /* tagline hidden — looks cleaner in dark nav */
}

nav {
  display: flex;
  align-items: center;
  gap: 1.4rem;
  font-size: 0.9rem;
}

nav a {
  color: var(--text-muted);
  transition: color 0.15s;
}

nav a:hover {
  color: var(--text);
  text-decoration: none;
}

/* ── Flash messages ────────────────────────────────────────── */
.flash {
  max-width: 1100px;
  margin: -1rem auto 1.5rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--warning-bg);
  border: 1px solid #5a4000;
  color: var(--warning-text);
  font-size: 0.9rem;
}

/* ── Page header (title + action button) ───────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.8rem;
}

.page-header h2 { margin: 0; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--accent-light);
  text-decoration: none;
}

.btn-secondary {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}

.btn-secondary:hover {
  border-color: var(--accent-light);
  color: var(--accent-light);
}

.btn-delete {
  background: none;
  border: 1px solid #3d1c1c;
  color: #f85149;
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  transition: background 0.15s;
}

.btn-delete:hover { background: #1f0d0d; }

.btn-recalculate {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}

.btn-recalculate:hover {
  border-color: var(--accent-light);
  color: var(--accent-light);
}

/* ── Risk badge ────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge-low    { background: #0d2818; color: #3fb950; border: 1px solid #1a4028; }
.badge-medium { background: #1c1a00; color: #e3b341; border: 1px solid #3d3800; }
.badge-high   { background: #2a0d0d; color: #f85149; border: 1px solid #4d1a1a; }

/* ── Portfolio grid (cards) ────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

@media (max-width: 860px) {
  .portfolio-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .portfolio-grid { grid-template-columns: 1fr; }
}

.portfolio-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  cursor: pointer;
  color: inherit;
  animation: fadeUp 0.45s ease both;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.2s;
}

.portfolio-card.card-positive {
  border-left-color: var(--positive);
  box-shadow: -2px 0 16px rgba(63, 185, 80, 0.12);
}

.portfolio-card.card-negative {
  border-left-color: var(--negative);
  box-shadow: -2px 0 16px rgba(248, 81, 73, 0.1);
}

.portfolio-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.portfolio-card.card-positive:hover { box-shadow: 0 8px 28px rgba(63, 185, 80, 0.15); }
.portfolio-card.card-negative:hover { box-shadow: 0 8px 28px rgba(248, 81, 73, 0.12); }

.portfolio-card:nth-child(1)  { animation-delay: 0.04s; }
.portfolio-card:nth-child(2)  { animation-delay: 0.08s; }
.portfolio-card:nth-child(3)  { animation-delay: 0.12s; }
.portfolio-card:nth-child(4)  { animation-delay: 0.16s; }
.portfolio-card:nth-child(5)  { animation-delay: 0.20s; }
.portfolio-card:nth-child(6)  { animation-delay: 0.24s; }
.portfolio-card:nth-child(7)  { animation-delay: 0.28s; }
.portfolio-card:nth-child(8)  { animation-delay: 0.32s; }
.portfolio-card:nth-child(9)  { animation-delay: 0.36s; }
.portfolio-card:nth-child(10) { animation-delay: 0.40s; }
.portfolio-card:nth-child(11) { animation-delay: 0.44s; }
.portfolio-card:nth-child(12) { animation-delay: 0.48s; }

/* top row: rank + risk badge */
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-rank {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

/* body: info left, chart right */
.card-body {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.card-owner {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.card-owner a { color: var(--text-muted); }
.card-owner a:hover { color: var(--accent-light); text-decoration: none; }

.card-perf-row {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.card-perf {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.02em;
}

.card-perf-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.card-perf-secondary {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.63rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* chart — right side of body */
.card-chart-area {
  flex-shrink: 0;
  width: 90px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* meta strip */
.card-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.67rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 0.65rem;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  padding-top: 0.7rem;
  margin-top: auto;
}

/* ── Performance colours ────────────────────────────────────── */
.perf-positive { color: var(--positive); }
.perf-negative { color: var(--negative); }

/* ── Portfolio detail page ──────────────────────────────────── */
.back-link {
  display: inline-block;
  margin-bottom: 1.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.back-link:hover { color: var(--text); text-decoration: none; }

.portfolio-hero {
  margin-bottom: 1.5rem;
}

.portfolio-hero h2 { margin-bottom: 0.2rem; }

.subtext {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0;
}

.metrics {
  display: flex;
  gap: 1rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

.metric {
  flex: 1;
  min-width: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.4rem;
}

.metric-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-light);
}

.perf-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: -0.5rem 0 1.5rem;
  font-size: 0.82rem;
  flex-wrap: wrap;
  color: var(--text-muted);
}

.stale-warning {
  color: var(--warning-text);
  background: var(--warning-bg);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
}

.stale-dot {
  color: var(--warning-text);
  font-size: 0.8rem;
}

/* ── Detail layout: chart + table side by side ──────────────── */
.holdings-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  align-items: start;
  margin-top: 1rem;
}

.chart-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
}

.chart-wrap h3 { margin: 0 0 1rem; font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Tables ─────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 500;
}

td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid #1c2128;
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-card); }

/* ── Forms ───────────────────────────────────────────────────── */
.auth-form, .portfolio-form {
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.auth-form label, .portfolio-form label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.auth-form input,
.portfolio-form input,
.portfolio-form select,
.portfolio-form textarea {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.auth-form input:focus,
.portfolio-form input:focus,
.portfolio-form select:focus,
.portfolio-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-form button, .portfolio-form button[type="submit"] {
  margin-top: 0.6rem;
  padding: 0.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.auth-form button:hover, .portfolio-form button[type="submit"]:hover {
  background: var(--accent-light);
}

/* ── Holdings dynamic rows (create form) ────────────────────── */
.holdings-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.8rem;
}

.holdings-header h3 { margin: 0; font-size: 0.95rem; }

.holding-row {
  display: grid;
  grid-template-columns: 90px 1fr 90px 32px;
  gap: 0.4rem;
  align-items: center;
  margin-bottom: 0.4rem;
}

.holding-row--header {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.holding-row input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  font-family: inherit;
}

.holding-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.ticker-wrap { display: flex; align-items: center; gap: 0.3rem; }
.ticker-wrap input { width: 100%; }
.ticker-status { font-size: 0.9rem; flex-shrink: 0; }

.btn-remove {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
  transition: all 0.15s;
}

.btn-remove:hover { background: #1f0d0d; border-color: #f85149; color: #f85149; }

/* ── Weight badge ────────────────────────────────────────────── */
.weight-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 12px;
}

.badge-ok   { background: #0d2818; color: var(--positive); }
.badge-warn { background: var(--warning-bg); color: var(--warning-text); }

/* ── Dev override ────────────────────────────────────────────── */
.dev-override {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.dev-override summary { cursor: pointer; user-select: none; }
.dev-override label, .dev-override input { display: block; margin-top: 0.4rem; }

/* ── Home hero ───────────────────────────────────────────────── */
.home-hero {
  padding: 3.5rem 0 3rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}

.home-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(48,54,61,0.18) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(48,54,61,0.18) 40px);
  pointer-events: none;
}

.home-hero-eyebrow {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--accent-light);
  margin: 0 0 1rem;
  position: relative;
}

.home-hero-title {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(2rem, 3.8vw, 2.9rem);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text);
  margin: 0 0 1rem;
  max-width: 620px;
  position: relative;
}

.home-hero-sub {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 0 0 2rem;
  max-width: 460px;
  line-height: 1.7;
  position: relative;
}

.home-stats {
  display: flex;
  align-items: center;
  gap: 1.8rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
  position: relative;
}

.home-stat-value {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 1.55rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.home-stat-label {
  display: block;
  font-size: 0.67rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 0.3rem;
}

.home-stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
  flex-shrink: 0;
}

.home-hero-cta {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  position: relative;
}

/* ── Grid header ─────────────────────────────────────────────── */
.grid-header {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.grid-title {
  margin: 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.grid-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* ── About page ─────────────────────────────────────────────── */
.about-hero {
  text-align: center;
  padding: 3rem 1rem 2.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.about-tagline {
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
  max-width: 680px;
  margin: 0 auto 1.8rem;
}

.about-cta-row {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
}

.about-sections {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.about-section {
  display: flex;
  gap: 1.4rem;
  align-items: flex-start;
  padding: 1.8rem 0;
  border-bottom: 1px solid var(--border);
}

.about-section:last-child {
  border-bottom: none;
}

.about-section-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 2.4rem;
  text-align: center;
  margin-top: 0.1rem;
}

.about-section h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.about-section p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.65;
}

.about-bottom-cta {
  text-align: center;
  padding: 3rem 1rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.about-bottom-cta p {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 580px;
  margin: 0 auto 1.5rem;
  line-height: 1.6;
}

/* ── Auth pages ─────────────────────────────────────────────── */
.auth-wrap {
  max-width: 400px;
  margin: 2rem auto;
}

.auth-wrap h2 {
  margin-bottom: 1.5rem;
}

.form-error {
  background: rgba(255, 123, 114, 0.12);
  border: 1px solid rgba(255, 123, 114, 0.4);
  color: #ff7b72;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.form-errors {
  background: rgba(255, 123, 114, 0.12);
  border: 1px solid rgba(255, 123, 114, 0.4);
  color: #ff7b72;
  padding: 0.75rem 1rem 0.75rem 1.75rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.form-errors li + li {
  margin-top: 0.3rem;
}

.auth-switch {
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-align: center;
}

.auth-switch a {
  color: var(--accent);
}

/* ── Footer ──────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}
