/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --navy:          #0F172A;
  --navy-800:      #1E293B;
  --navy-700:      #334155;
  --emerald:       #10B981;
  --emerald-dark:  #059669;
  --emerald-light: #D1FAE5;
  --slate-50:      #F8FAFC;
  --slate-100:     #F1F5F9;
  --slate-200:     #E2E8F0;
  --slate-400:     #94A3B8;
  --slate-500:     #64748B;
  --slate-700:     #334155;
  --red-100:       #FEE2E2;
  --red-600:       #DC2626;
  --red-700:       #B91C1C;
  --amber-100:     #FEF3C7;
  --amber-700:     #B45309;
  --card-shadow:   0 2px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --card-shadow-hover: 0 8px 24px rgba(0,0,0,0.1), 0 2px 6px rgba(0,0,0,0.06);
  --muted:         #94A3B8;
  --radius-card:   20px;
  --radius-pill:   9999px;
  --text-primary:  var(--navy);
  --text-muted:    var(--slate-400);
}

/* ── Base ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, var(--navy) 0%, #1e3a5f 100%) center / cover no-repeat;
  min-height: 100vh;
  color: var(--navy);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  max-width: 100vw;
}
.hidden { display: none !important; }

/* ── Spinner ───────────────────────────────────────────────────────────── */
.spinner {
  border: 3px solid #E2E8F0; border-top-color: var(--emerald);
  border-radius: 50%; width: 18px; height: 18px;
  animation: spin 0.7s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--card-shadow);
  padding: 24px;
  border: 1px solid rgba(0,0,0,0.04);
  transition: box-shadow 0.2s;
}
/* Consistent 16 px gap between any two adjacent children of a page-body */
.page-body > * + * { margin-top: 16px; }
/* Tighter gap between sibling cards nested inside another card */
.card .card + .card { margin-top: 12px; }
.card:hover { box-shadow: var(--card-shadow-hover); }

/* ── Inputs ─────────────────────────────────────────────────────────────── */
.input-field {
  width: 100%;
  border: 1.5px solid var(--slate-200);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--navy);
  outline: none;
  background: var(--slate-50);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.input-field::placeholder { color: var(--slate-400); }
.input-field:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 4px rgba(16,185,129,0.12);
  background: #fff;
}
label.field-label {
  display: block; font-size: 0.78rem; font-weight: 600;
  color: var(--slate-500); margin-bottom: 6px; letter-spacing: 0.02em;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--emerald); color: #fff; font-family: inherit;
  font-size: 0.9rem; font-weight: 600; padding: 13px 24px;
  border-radius: var(--radius-pill);
  border: none; cursor: pointer; width: 100%;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 14px rgba(16,185,129,0.3);
}
.btn-primary:hover { background: var(--emerald-dark); box-shadow: 0 4px 20px rgba(16,185,129,0.4); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--slate-50); color: var(--slate-700); font-family: inherit;
  font-size: 0.875rem; font-weight: 500; padding: 10px 20px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--slate-200); cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.btn-secondary:hover { background: #fff; border-color: var(--slate-400); }

.btn-emerald {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--emerald); color: #fff; font-family: inherit;
  font-size: 0.875rem; font-weight: 600; padding: 10px 22px;
  border-radius: var(--radius-pill);
  border: none; cursor: pointer; transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 3px 10px rgba(16,185,129,0.25);
}
.btn-emerald:hover { background: var(--emerald-dark); box-shadow: 0 4px 14px rgba(16,185,129,0.35); }
.btn-emerald:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn-slate {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--navy-800); color: #fff; font-family: inherit;
  font-size: 0.875rem; font-weight: 600; padding: 10px 22px;
  border-radius: var(--radius-pill);
  border: none; cursor: pointer; transition: background 0.2s;
}
.btn-slate:hover { background: var(--navy-700); }
.btn-slate:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--red-600); color: #fff; font-family: inherit;
  font-size: 0.875rem; font-weight: 600; padding: 10px 22px;
  border-radius: var(--radius-pill);
  border: none; cursor: pointer; transition: background 0.2s;
}
.btn-danger:hover { background: #B91C1C; }

/* ── Tab toggle ─────────────────────────────────────────────────────────── */
.tab-wrap {
  display: flex; background: var(--slate-100); padding: 5px;
  border-radius: var(--radius-pill); gap: 3px;
}
.tab-btn {
  flex: 1; padding: 9px 14px; font-family: inherit; font-size: 0.85rem; font-weight: 500;
  border: none; cursor: pointer; border-radius: var(--radius-pill);
  background: transparent; color: var(--slate-500); transition: all 0.2s;
}
.tab-btn.active {
  background: #fff; color: var(--navy); font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ── Password strength ──────────────────────────────────────────────────── */
.strength-bars { display: flex; gap: 4px; margin-top: 8px; }
.strength-bar { flex: 1; height: 4px; border-radius: 99px; background: var(--slate-200); transition: background 0.3s; }
.strength-bar.s1 { background: #EF4444; }
.strength-bar.s2 { background: #F97316; }
.strength-bar.s3 { background: #EAB308; }
.strength-bar.s4 { background: var(--emerald); }
.strength-label { font-size: 0.72rem; margin-top: 4px; color: var(--slate-400); min-height: 14px; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.72rem; font-weight: 700; padding: 4px 10px;
  border-radius: var(--radius-pill); letter-spacing: 0.01em;
}
.badge-crash { background: var(--red-100); color: var(--red-700); }
.badge-normal { background: var(--emerald-light); color: #065F46; }
.badge-count { background: var(--emerald-light); color: #065F46; }

/* ── Price change pill badges ────────────────────────────────────────────── */
.pct-badge {
  display: inline-flex; align-items: center;
  font-size: 0.75rem; font-weight: 700; padding: 3px 9px;
  border-radius: var(--radius-pill);
}
.pct-badge.up   { background: rgba(16,185,129,0.12); color: #059669; }
.pct-badge.down { background: rgba(220,38,38,0.1);   color: #DC2626; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px; min-height: 100vh;
  background: var(--navy);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
}
.sidebar-logo { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.07); }
.nav-list { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border-radius: 12px;
  font-size: 0.875rem; font-weight: 500; color: var(--slate-400);
  cursor: pointer; border: none; background: transparent;
  font-family: inherit; text-align: left; width: 100%;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: rgba(16,185,129,0.15); color: var(--emerald); font-weight: 600; }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-footer { padding: 16px 12px; border-top: 1px solid rgba(255,255,255,0.07); }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: 12px; background: rgba(255,255,255,0.05); margin-bottom: 8px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--emerald);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-email-text { font-size: 0.72rem; color: var(--slate-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout {
  width: 100%; padding: 9px 14px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent; color: var(--slate-400); font-family: inherit;
  font-size: 0.8rem; font-weight: 500; cursor: pointer;
  transition: background 0.15s, color 0.15s; text-align: center;
}
.btn-logout:hover { background: rgba(255,255,255,0.07); color: #fff; }

/* ── App layout ─────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }
.main-content { margin-left: 240px; flex: 1; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: rgba(15,23,42,0.75); backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-size: 1rem; font-weight: 700; color: #fff; letter-spacing: -0.2px; }
.topbar-sub { font-size: 0.72rem; color: rgba(255,255,255,0.4); margin-top: 2px; }
.page-body { padding: 20px 32px; flex: 1; }

/* ── Stats grid ─────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 0; }
.stat-card {
  background: #fff; border-radius: var(--radius-card);
  box-shadow: var(--card-shadow); padding: 18px 20px;
  border: 1px solid rgba(0,0,0,0.04);
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-1px); box-shadow: var(--card-shadow-hover); }
.stat-label {
  font-size: 0.68rem; font-weight: 700; color: var(--slate-400);
  text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px;
}
.stat-value { font-size: 1.65rem; font-weight: 800; color: var(--navy); line-height: 1.1; letter-spacing: -0.5px; }
.stat-value.positive { color: #059669; }
.stat-value.negative { color: var(--red-600); }

/* ── Section heading ────────────────────────────────────────────────────── */
.section-heading {
  font-size: 0.95rem; font-weight: 700; color: var(--navy); margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between;
  letter-spacing: -0.1px;
}

/* ── Asset row (holdings) ───────────────────────────────────────────────── */
.asset-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--slate-100);
}
.asset-row:last-child { border-bottom: none; padding-bottom: 0; }
.asset-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--navy-800), var(--navy-700));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 800; color: #fff; flex-shrink: 0;
  letter-spacing: -0.5px;
}
.asset-info { flex: 1; min-width: 0; }
.asset-ticker { font-size: 0.9rem; font-weight: 700; color: var(--navy); }
.asset-name { font-size: 0.72rem; color: var(--slate-400); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-right { text-align: right; flex-shrink: 0; }
.asset-value { font-size: 0.9rem; font-weight: 700; color: var(--navy); }
.asset-shares { font-size: 0.72rem; color: var(--slate-400); margin-top: 1px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 480px; }
.data-table th {
  text-align: left; font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--slate-400); padding: 0 10px 12px;
  border-bottom: 1.5px solid var(--slate-100); white-space: nowrap;
}
.data-table th:first-child { padding-left: 0; }
.data-table th.r { text-align: right; }
.data-table td { padding: 12px 10px; border-bottom: 1px solid #F8FAFC; color: var(--navy-800); }
.data-table td:first-child { padding-left: 0; }
.data-table td.r { text-align: right; }
.data-table td.c { text-align: center; }
.data-table tbody tr:hover { background: #FAFBFD; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Plan card ──────────────────────────────────────────────────────────── */
.plan-card {
  border: 1.5px solid var(--slate-200); border-radius: 16px; padding: 20px;
  margin-bottom: 12px; transition: box-shadow 0.2s, border-color 0.2s;
  background: #fff;
}
.plan-card:last-child { margin-bottom: 0; }
.plan-card:hover { box-shadow: var(--card-shadow-hover); border-color: var(--slate-300); }
.plan-card-actions {
  display: flex; gap: 8px; margin-top: 14px; align-items: center; flex-wrap: wrap;
}
.plan-card-actions .btn-emerald,
.plan-card-actions .btn-secondary { font-size: 0.82rem; padding: 9px 18px; }

/* ── AI Advisor hero card ────────────────────────────────────────────────── */
.ai-advisor-card {
  background: linear-gradient(135deg, #0F172A 0%, #1e3a5f 100%);
  color: #fff; border: none; margin-bottom: 24px;
}
.ai-advisor-card .section-heading { color: rgba(255,255,255,0.9); border-bottom-color: rgba(255,255,255,0.1); }
.ai-advisor-reasoning {
  font-size: 0.88rem; line-height: 1.7; color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.07); border-radius: 12px; padding: 16px;
  white-space: pre-wrap;
}
.ai-advisor-card .plan-card-actions .btn-emerald { background: #10B981; }
.ai-advisor-card .plan-card-actions .btn-secondary {
  background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.2);
}

/* ── Tag input ──────────────────────────────────────────────────────────── */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--navy-800); color: #E2E8F0; font-size: 0.78rem; font-weight: 600;
  padding: 5px 12px; border-radius: var(--radius-pill);
}
.tag-remove {
  cursor: pointer; color: var(--slate-400); font-size: 0.9rem; line-height: 1;
  background: none; border: none; padding: 0; font-family: inherit;
  transition: color 0.15s;
}
.tag-remove:hover { color: #f87171; }
.tag-input-row { display: flex; gap: 8px; }
.tag-input-row .input-field { flex: 1; padding: 9px 14px; font-size: 0.85rem; }
.tag-input-row .btn-secondary { padding: 9px 16px; font-size: 0.82rem; white-space: nowrap; }

/* ── Slider ─────────────────────────────────────────────────────────────── */
.slider-row { display: flex; align-items: center; gap: 14px; }
input[type=range] { flex: 1; accent-color: var(--emerald); }
.slider-val { min-width: 52px; font-size: 0.875rem; font-weight: 700; color: var(--navy); text-align: right; }

/* ── Toggle ─────────────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 12px; }
.toggle { position: relative; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; background: var(--slate-200); border-radius: 12px;
  cursor: pointer; transition: background 0.3s;
}
.toggle input:checked + .toggle-track { background: var(--emerald); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  background: #fff; border-radius: 50%; transition: transform 0.3s;
  pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle input:checked ~ .toggle-thumb { transform: translateX(20px); }
.toggle-label { font-size: 0.875rem; font-weight: 500; color: var(--navy-800); }

/* ── Settings row ───────────────────────────────────────────────────────── */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0; border-bottom: 1px solid var(--slate-100);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 0.82rem; font-weight: 500; color: var(--slate-500); }
.settings-row-value { font-size: 0.875rem; font-weight: 700; color: var(--navy); }

/* ── Empty / loading ────────────────────────────────────────────────────── */
.empty-state { color: var(--slate-400); font-size: 0.875rem; padding: 20px 0; text-align: center; }
.loading-text { color: var(--slate-400); font-size: 0.875rem; font-style: italic; }

/* ── Alert ──────────────────────────────────────────────────────────────── */
.alert { border-radius: 12px; padding: 12px 16px; font-size: 0.875rem; margin-bottom: 16px; }
.alert-error { background: var(--red-100); color: var(--red-700); }
.alert-success { background: var(--emerald-light); color: #065F46; }
.alert-warning { background: var(--amber-100); color: var(--amber-700); }

/* ── Mobile top nav ─────────────────────────────────────────────────────── */
.mobile-topnav {
  display: none; background: var(--navy); color: #fff;
  padding: 14px 20px; align-items: center; justify-content: space-between;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.app-footer { text-align: center; font-size: 0.72rem; color: rgba(255,255,255,0.3); padding: 24px 32px; border-top: 1px solid rgba(255,255,255,0.07); }

/* ── Login page ─────────────────────────────────────────────────────────── */
#loginView {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto; padding: 24px;
}
#loginView.hidden { display: none; }
.login-box {
  background: #fff; border-radius: 24px; padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35), 0 4px 16px rgba(0,0,0,0.15);
}
.login-logo { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 28px; }
.brand-text { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; color: #fff; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--slate-500); margin-bottom: 6px; }
.password-wrap { position: relative; }
.eye-btn { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--slate-400); font-size: 1rem; padding: 0; }
.form-error { font-size: 0.78rem; color: var(--red-600); margin-top: 6px; min-height: 16px; }

/* ── View panels ────────────────────────────────────────────────────────── */
.view-panel { display: flex; flex-direction: column; min-height: 100vh; }
.view-panel.hidden { display: none !important; }

/* ── Google error banner ────────────────────────────────────────────────── */
.google-error-box {
  display: none; background: #FEF2F2; border: 1px solid #FECACA;
  border-radius: 10px; padding: 10px 14px; margin-top: 10px;
  font-size: 0.85rem; color: var(--red-600); text-align: center; line-height: 1.45;
}
.google-error-box.visible { display: block; }

/* ── Google button ──────────────────────────────────────────────────────── */
.btn-google {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #3C4043; font-family: inherit;
  font-size: 0.9rem; font-weight: 500; padding: 11px 20px;
  border-radius: var(--radius-pill);
  border: 1px solid #DADCE0; cursor: pointer; width: 100%;
  transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.btn-google:hover { background: #F8F9FA; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.btn-google:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--slate-400); font-size: 0.78rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--slate-200); }

/* ── Mobile bottom nav ──────────────────────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 10px;
  left: 12px;
  right: 12px;
  background: rgba(10,17,32,0.96);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 200;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.09);
  box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 2px 8px rgba(0,0,0,0.3);
  overflow: hidden;
}
/* Scrollable inner — supports any number of tabs without squishing */
.mobile-bottom-nav-inner {
  display: flex; align-items: stretch;
  overflow-x: auto; scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.mobile-bottom-nav-inner::-webkit-scrollbar { display: none; }
.mob-tab {
  flex: 0 0 auto;             /* don't shrink — each tab keeps its natural width */
  min-width: 60px;            /* minimum tap target per tab */
  width: calc(100vw / 6);     /* show ~6 at a time; scroll reveals the rest */
  max-width: 80px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px 4px 6px; color: rgba(255,255,255,0.38); background: none; border: none;
  font-family: inherit; font-size: 0.56rem; font-weight: 600; gap: 3px; cursor: pointer;
  transition: color 0.15s; letter-spacing: 0.01em;
  position: relative; overflow: hidden; scroll-snap-align: start;
}
.mob-tab svg {
  /* width/height set as SVG attributes; this ensures it won't grow */
  flex-shrink: 0;
  display: block;
}
.mob-tab span {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%; display: block;
}
.mob-tab.active { color: var(--emerald); }
.mob-tab.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 2.5px; background: var(--emerald);
  border-radius: 0 0 4px 4px;
}
.mob-tab:hover { color: rgba(255,255,255,0.75); }

/* ── Dashboard Alpaca banner ────────────────────────────────────────────── */
.dash-alpaca-banner {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, #FFF7ED, #FEF3C7);
  border: 1px solid #FED7AA; border-radius: var(--radius-card);
  padding: 18px 22px; margin-bottom: 20px;
}
.dash-alpaca-banner-icon { font-size: 1.8rem; flex-shrink: 0; }
.dash-alpaca-banner-text { flex: 1; min-width: 0; }
.dash-alpaca-banner-title { font-weight: 700; color: #92400E; margin-bottom: 2px; }
.dash-alpaca-banner-sub { font-size: 0.83rem; color: #B45309; }
.dash-alpaca-banner .btn-connect {
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; white-space: nowrap; width: auto;
  background: #D97706; color: #fff; font-family: inherit;
  font-size: 0.875rem; font-weight: 600; padding: 10px 20px;
  border-radius: var(--radius-pill); border: none; cursor: pointer;
  transition: background 0.2s;
}
.dash-alpaca-banner .btn-connect:hover { background: #B45309; }

/* ── Portfolio grid spacing ──────────────────────────────────────────────── */
#port-grid {
  display: grid;                        /* must live in CSS — JS clears inline display */
  grid-template-columns: 1fr 300px;     /* Holdings wide-left, Allocation fixed-right */
  align-items: start;
  margin-top: 28px;                     /* gap below the stats row */
  column-gap: 32px;                     /* gap between Holdings and Allocation (desktop) */
  row-gap: 32px;                        /* gap when stacked (tablet/mobile) */
}

/* ── Portfolio stacked layout for tablet ────────────────────────────────── */
@media (max-width: 900px) {
  #port-grid { grid-template-columns: 1fr !important; row-gap: 32px !important; margin-top: 20px; }
  .why-grid-3 { grid-template-columns: 1fr !important; }
}
@media (min-width: 901px) and (max-width: 1100px) {
  .why-grid-3 { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ── Inline result message boxes ────────────────────────────────────────── */
.msg-box {
  font-size: 0.85rem; padding: 11px 16px; border-radius: 12px;
  margin-top: 12px; line-height: 1.45; display: none;
}
.msg-box:not(:empty) { display: block; }
.msg-box.is-error   { background:#FEF2F2; border:1px solid #FECACA; color:#991B1B; }
.msg-box.is-success { background:#ECFDF5; border:1px solid #A7F3D0; color:#065F46; }
.msg-box.is-warning { background:#FFFBEB; border:1px solid #FDE68A; color:#92400E; }
.msg-box.is-info    { background:#EFF6FF; border:1px solid #BFDBFE; color:#1D4ED8; }

/* ── Settings page ──────────────────────────────────────────────────────── */
.settings-body { max-width: 100%; }
.alpaca-link-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1024px) { .stats-grid { grid-template-columns: repeat(2,1fr); } }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-topnav { display: flex; width: 100%; }
  .mobile-bottom-nav { display: block; }
  .app-layout { flex-direction: column; width: 100%; max-width: 100vw; overflow-x: hidden; }
  .main-content { margin-left: 0; width: 100%; max-width: 100vw; overflow-x: hidden; }
  .view-panel { width: 100%; max-width: 100vw; overflow-x: hidden; }
  .page-body { padding: 12px 14px 96px; width: 100%; box-sizing: border-box; }
  .topbar { padding: 12px 14px; gap: 8px; width: 100%; box-sizing: border-box; flex-wrap: wrap; }
  /* Hide the 4 market stat cards on mobile — replaced by compact text bar */
  .dash-market-stats { display: none !important; }
  .dash-market-bar { display: flex !important; }
  .topbar-title { font-size: 0.9rem; }
  .topbar-sub { display: none; }
  /* Stats become a horizontal swipe strip — no vertical stacking */
  .stats-grid {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 10px;
    margin-bottom: 10px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .stats-grid::-webkit-scrollbar { display: none; }
  .stat-card {
    min-width: 130px;
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: 12px 14px;
  }
  .stat-value { font-size: 1.3rem; }
  .card { padding: 16px; border-radius: 16px; }
  .section-heading { font-size: 0.88rem; }
  .data-table { font-size: 0.82rem; min-width: 0; }
  .data-table .col-shares,
  .data-table .col-alloc,
  .data-table .col-target { display: none; }
  .settings-body { max-width: 100%; }
  #s-budget { width: 100%; max-width: 100% !important; box-sizing: border-box; }
  .tag-input-row .btn-secondary { padding: 8px 10px; white-space: nowrap; }
  .dash-alpaca-banner { flex-wrap: wrap; }
  .dash-alpaca-banner .btn-connect { width: 100%; margin-top: 8px; }
  .plan-card-actions { flex-direction: column; gap: 10px; }
  .plan-card-actions .btn-emerald,
  .plan-card-actions .btn-secondary { width: 100%; text-align: center; padding: 12px 16px; font-size: 0.875rem; }
  .ai-advisor-reasoning { font-size: 0.83rem; padding: 12px; }

  /* ── AI Trades mobile fixes ─────────────────────────────────── */
  /* Signal card header: stack ticker + direction badge, score row below */
  .signal-header-row { flex-direction: column; align-items: flex-start !important; gap: 8px !important; }
  /* Options chain table: allow horizontal scroll inside the wrapper */
  .options-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  /* Topbar buttons: hide subtitle text, keep icon */
  .topbar .btn-secondary { font-size: 0.75rem; padding: 6px 10px; white-space: nowrap; }

  /* ── Flow page mobile fixes ─────────────────────────────────── */
  /* Search bar: stack vertically on very narrow screens */
  #flow-search-input { font-size: 0.83rem; }
  /* Flow table: always scrollable, never breaks out of screen */
  .flow-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
}

@media (max-width: 480px) {
  .page-body { padding: 12px 12px 96px; }
  #btn-save-settings { font-size: 0.78rem; padding: 7px 10px; }
  /* Settings Alpaca section — keep vertical grid, not horizontal scroll */
  #s-alpaca-connected .stats-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    overflow-x: visible;
  }
  #s-alpaca-connected .stat-card { min-width: 0; flex: unset; }
  .alpaca-actions { flex-direction: column; }
  .alpaca-actions button { width: 100%; }
  .alpaca-link-row { flex-direction: column; align-items: flex-start; }
  .toggle-wrap { flex-wrap: wrap; }
  .login-box { padding: 28px 20px; }
}
