/* ═══════════════════════════════════════════════════════════════
   RiggsHQ — Stylesheet
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ── */
:root {
  --bg:           #0f1117;
  --bg-card:      #1a1d27;
  --bg-card-alt:  #1e2130;
  --border:       #2a2e3f;
  --border-light: #353a50;

  --text:         #e8eaf0;
  --text-muted:   #7a80a0;
  --text-dim:     #4a5070;

  --accent:       #4f8ef7;
  --accent-glow:  rgba(79, 142, 247, 0.15);

  --gain:         #2ecc71;
  --gain-bg:      rgba(46, 204, 113, 0.10);
  --loss:         #e74c3c;
  --loss-bg:      rgba(231, 76, 60, 0.10);

  --vanguard:     #C41E3A;
  --fidelity:     #007a3d;
  --schwab:       #00a0b0;

  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.3);

  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono:    'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════════════════════ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
  flex-wrap: wrap;
}

.site-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg-card-alt); color: var(--text); border: 1px solid var(--border-light); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-light); opacity: 1; }
.btn-danger   { background: var(--loss); color: #fff; }
.btn-sm       { padding: 4px 10px; font-size: 0.78rem; }
.btn-icon     { padding: 4px 8px; font-size: 0.8rem; background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-icon:hover { color: var(--text); border-color: var(--border-light); opacity: 1; }

/* Refresh spinning animation */
.refresh-icon { display: inline-block; }
.fetching .refresh-icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════════
   BANNERS
   ═══════════════════════════════════════════════════════════════ */
.cors-note {
  background: rgba(255, 193, 7, 0.10);
  border-bottom: 1px solid rgba(255, 193, 7, 0.25);
  color: #ffd54f;
  font-size: 0.82rem;
  padding: 10px 32px;
  text-align: center;
}

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--loss-bg);
  border-bottom: 1px solid rgba(231, 76, 60, 0.3);
  color: #ff8a80;
  font-size: 0.85rem;
  padding: 10px 32px;
}
.error-banner button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
  opacity: 0.7;
}
.error-banner button:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════
   SUMMARY SECTION
   ═══════════════════════════════════════════════════════════════ */
.summary-section {
  padding: 24px 32px 0;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  transition: border-color 0.2s;
}
.summary-card:hover { border-color: var(--border-light); }

.card-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.card-value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.card-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   GAIN / LOSS UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════ */
.gain  { color: var(--gain); }
.loss  { color: var(--loss); }
.neutral { color: var(--text-muted); }

.gain-badge { background: var(--gain-bg); color: var(--gain); }
.loss-badge { background: var(--loss-bg); color: var(--loss); }

/* ═══════════════════════════════════════════════════════════════
   SECTION HEADERS
   ═══════════════════════════════════════════════════════════════ */
.accounts-section,
.projection-section {
  padding: 32px 32px 0;
}

.section-header {
  margin-bottom: 20px;
}

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.section-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════════
   ACCOUNTS GRID
   ═══════════════════════════════════════════════════════════════ */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

/* ── Account Card ── */
.account-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.account-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-sm);
}

.account-card-accent {
  height: 3px;
  width: 100%;
}

.account-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 20px 12px;
  gap: 12px;
}

.account-card-title {
  flex: 1;
}

.account-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 4px;
}

.account-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge-vanguard  { background: rgba(196,30,58,0.15); color: #e74c3c; }
.badge-fidelity  { background: rgba(0,122,61,0.15); color: #2ecc71; }
.badge-schwab    { background: rgba(0,160,176,0.15); color: #1abc9c; }
.badge-other     { background: rgba(79,142,247,0.15); color: var(--accent); }
.badge-type      { background: var(--bg-card-alt); color: var(--text-muted); border: 1px solid var(--border); }
.badge-placeholder { background: var(--bg-card-alt); color: var(--text-dim); }

.account-card-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Account Value ── */
.account-total {
  padding: 0 20px 16px;
}

.account-total-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.account-total-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Sub-account summary ── */
.sub-account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  background: var(--bg-card-alt);
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.sub-account-row .sub-label {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sub-tag {
  background: rgba(79,142,247,0.15);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sub-account-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── Holdings Table ── */
.holdings-section {
  border-top: 1px solid var(--border);
}

.holdings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.holdings-table th {
  padding: 8px 20px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--bg-card-alt);
  border-bottom: 1px solid var(--border);
}

.holdings-table th:last-child,
.holdings-table td:last-child { text-align: center; }
.holdings-table th:nth-child(3),
.holdings-table td:nth-child(3),
.holdings-table th:nth-child(4),
.holdings-table td:nth-child(4),
.holdings-table th:nth-child(5),
.holdings-table td:nth-child(5) {
  text-align: right;
}

.holdings-table td {
  padding: 9px 20px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}

.holdings-table tr:last-child td { border-bottom: none; }
.holdings-table tr:hover td { background: rgba(255,255,255,0.02); }

.ticker-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--accent);
}

.holding-name {
  color: var(--text-muted);
  font-size: 0.76rem;
  margin-top: 1px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Inline shares input */
.shares-input {
  width: 90px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px;
  text-align: right;
  transition: border-color 0.15s;
  font-family: var(--font-mono);
}
.shares-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(79,142,247,0.05);
}

.price-cell {
  font-family: var(--font-mono);
}

.price-arrow {
  font-size: 0.7rem;
  margin-left: 3px;
}

.value-cell {
  font-weight: 600;
  font-family: var(--font-mono);
}

/* Sub-account tag badge in table */
.holding-tag {
  display: inline-block;
  background: rgba(79,142,247,0.12);
  color: var(--accent);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Placeholder state */
.placeholder-message {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-style: italic;
  border-top: 1px solid var(--border);
}

/* ── Account Card Footer ── */
.account-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card-alt);
  gap: 12px;
  flex-wrap: wrap;
}

.return-rate-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.return-rate-input {
  width: 58px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  text-align: right;
}
.return-rate-input:focus {
  outline: none;
  border-color: var(--accent);
}

.return-rate-unit {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   PROJECTION CHART
   ═══════════════════════════════════════════════════════════════ */
.chart-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 0;
}

.chart-container {
  position: relative;
  height: 350px;
}

.chart-empty {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-style: italic;
}

/* Callout boxes */
.chart-callouts {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-top: 20px;
}

.callout-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: center;
  transition: border-color 0.2s;
}
.callout-box:hover { border-color: var(--border-light); }

.callout-year {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.callout-value {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ═══════════════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════════════ */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  margin-top: 40px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.site-footer p {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.footer-actions {
  display: flex;
  gap: 8px;
}

/* ═══════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 440px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--bg-card-alt); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.modal-body input[type="text"],
.modal-body input[type="number"],
.modal-body select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  padding: 8px 12px;
  width: 100%;
  transition: border-color 0.15s;
}
.modal-body input:focus,
.modal-body select:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(79,142,247,0.05);
}

.modal-body input[type="color"] {
  padding: 3px;
  height: 38px;
  cursor: pointer;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.modal-body .required { color: var(--loss); margin-left: 2px; }
.modal-body .optional { color: var(--text-dim); font-weight: 400; }

.modal-account-name {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 8px 12px;
  background: var(--bg-card-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 4px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  gap: 8px;
}

.modal-footer-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

  .chart-callouts {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .site-header {
    padding: 16px 20px;
  }

  .summary-section,
  .accounts-section,
  .projection-section {
    padding-left: 20px;
    padding-right: 20px;
  }

  .summary-cards {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .card-value {
    font-size: 1.3rem;
  }

  .chart-callouts {
    grid-template-columns: 1fr 1fr;
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px 20px;
  }
}

@media (max-width: 400px) {
  .summary-cards {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MISC UTILITIES
   ═══════════════════════════════════════════════════════════════ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

select option {
  background: var(--bg-card);
  color: var(--text);
}

/* Scrollbar styling (Webkit) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ═══════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ═══════════════════════════════════════════════════════════════ */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 6px;
}

.login-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.login-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 4px;
}

.login-input-wrap {
  position: relative;
}

.login-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 44px 12px 16px;
  transition: border-color 0.15s;
  letter-spacing: 0.08em;
}
.login-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(79,142,247,0.04);
}

.login-eye {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.5;
  transition: opacity 0.15s;
  padding: 4px;
}
.login-eye:hover { opacity: 1; }

.login-error {
  background: var(--loss-bg);
  border: 1px solid rgba(231,76,60,0.3);
  color: #ff8a80;
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.login-btn {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  justify-content: center;
  margin-top: 4px;
}

@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-8px); }
  40%       { transform: translateX(8px); }
  60%       { transform: translateX(-6px); }
  80%       { transform: translateX(6px); }
}
.login-card.shake { animation: loginShake 0.4s ease; }

/* ═══════════════════════════════════════════════════════════════
   CHAT PANEL
   ═══════════════════════════════════════════════════════════════ */

/* Floating toggle button */
.chat-toggle-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 450;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(79,142,247,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.chat-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(79,142,247,0.6);
}
.chat-toggle-icon { font-size: 1.4rem; line-height: 1; }

/* Slide-in panel */
.chat-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  z-index: 450;
  width: 380px;
  height: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp 0.25s ease;
}

@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.chat-panel-icon {
  color: var(--accent);
  font-size: 1rem;
}

.chat-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.chat-panel-close:hover { color: var(--text); background: var(--bg-card-alt); }

.chat-panel-sub {
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 6px 18px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
}

.chat-msg-user { align-items: flex-end; }
.chat-msg-assistant { align-items: flex-start; }

.chat-bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.83rem;
  line-height: 1.55;
}

.chat-msg-user .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-msg-assistant .chat-bubble {
  background: var(--bg-card-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.chat-bubble em {
  font-style: italic;
  color: var(--text-muted);
}

.chat-bubble.success {
  background: var(--gain-bg);
  border-color: rgba(46,204,113,0.25);
  color: var(--gain);
}

.chat-bubble.error-bubble {
  background: var(--loss-bg);
  border-color: rgba(231,76,60,0.25);
  color: #ff8a80;
}

.chat-thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
  width: fit-content;
}

.chat-thinking span {
  width: 6px;
  height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: thinkingDot 1.2s ease-in-out infinite;
}
.chat-thinking span:nth-child(2) { animation-delay: 0.2s; }
.chat-thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkingDot {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.4; }
  40%           { transform: scale(1.2); opacity: 1; }
}

/* Input area */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  padding: 8px 12px;
  resize: none;
  line-height: 1.4;
  font-family: var(--font);
  transition: border-color 0.15s;
  max-height: 80px;
}
.chat-input:focus {
  outline: none;
  border-color: var(--accent);
}

.chat-send-btn {
  padding: 8px 16px;
  flex-shrink: 0;
  align-self: flex-end;
}

.chat-panel-footer {
  font-size: 0.67rem;
  color: var(--text-dim);
  text-align: center;
  padding: 6px 12px 10px;
  flex-shrink: 0;
}

/* Mobile: full-width panel */
@media (max-width: 480px) {
  .chat-panel {
    right: 0;
    bottom: 80px;
    width: 100%;
    border-radius: 16px 16px 0 0;
  }
  .chat-toggle-btn {
    right: 16px;
    bottom: 16px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   HOLDINGS BREAKDOWN + GEOGRAPHIC EXPOSURE SECTION
   ═══════════════════════════════════════════════════════════════ */

.breakdown-section {
  padding: 32px 32px 0;
}

.breakdown-subsection {
  margin-bottom: 40px;
}

/* ── Holdings / Geo detail table ── */
.breakdown-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.breakdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.breakdown-table thead {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.breakdown-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}

.breakdown-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.breakdown-table tbody tr:last-child td {
  border-bottom: none;
}

.breakdown-table tbody tr:hover {
  background: var(--bg-hover, rgba(255,255,255,0.03));
}

.breakdown-table .num-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.breakdown-table .holding-name-col {
  color: var(--text-muted);
  max-width: 220px;
}

.breakdown-table .pct-col {
  font-weight: 600;
  color: var(--accent);
}

.geo-pct {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.geo-detail-table .ticker-cell {
  font-size: 0.8rem;
}

/* ── Geographic exposure summary cards ── */
.geo-cards {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.geo-card {
  flex: 1;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.geo-card-domestic {
  border-top: 3px solid var(--accent);
}

.geo-card-intl {
  border-top: 3px solid #2eb87e;
}

.geo-card-flag {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

/* ── Domestic / international stacked bar ── */
.geo-bar-track {
  display: flex;
  height: 10px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--border);
  margin-bottom: 24px;
}

.geo-bar-fill-domestic {
  background: var(--accent);
  height: 100%;
  transition: width 0.4s ease;
}

.geo-bar-fill-intl {
  background: #2eb87e;
  height: 100%;
  transition: width 0.4s ease;
}

.geo-row-excluded td {
  opacity: 0.45;
  font-style: italic;
}

.geo-excluded-label {
  color: var(--text-muted);
  font-size: 0.75rem;
}

@media (max-width: 600px) {
  .breakdown-section {
    padding: 24px 16px 0;
  }
  .geo-card {
    min-width: 140px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   SAVINGS GOALS SECTION
   ═══════════════════════════════════════════════════════════════ */

.savings-section {
  padding: 32px 32px 0;
}

/* ── Pool Stats Bar ── */
.savings-pool-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.savings-pool-stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.savings-pool-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.savings-pool-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.savings-pool-warning {
  color: #e67e22;
}

.savings-pool-divider {
  color: var(--border-light);
  font-size: 1.3rem;
  align-self: center;
}

/* ── Goal Grid ── */
.goal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

/* ── Goal Card ── */
.goal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  transition: box-shadow 0.2s;
}

.goal-card:hover {
  box-shadow: var(--shadow-sm);
}

.goal-card-emergency {
  background: rgba(239, 68, 68, 0.04);
}

.goal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.goal-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.goal-shield {
  font-size: 1rem;
  flex-shrink: 0;
}

.goal-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.goal-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.goal-amount-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.goal-amount-value {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
}

/* ── Progress Bar ── */
.goal-progress-track {
  height: 8px;
  background: var(--bg-card-alt);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}

.goal-progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}

.goal-progress-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.goal-progress-text strong {
  color: var(--text);
}

/* ── Monthly Planner ── */
.goal-planner-section {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.goal-planner-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 2px 0;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s;
}

.goal-planner-toggle:hover {
  color: var(--text);
}

.goal-planner-chevron {
  font-size: 0.65rem;
}

.goal-planner-body {
  padding-top: 12px;
}

.goal-planner-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.goal-planner-input-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.goal-monthly-input {
  width: 110px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  padding: 5px 8px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s;
}

.goal-monthly-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(79,142,247,0.05);
}

.goal-planner-result {
  font-size: 0.82rem;
  line-height: 1.5;
}

.goal-funded-text {
  color: var(--gain);
  font-weight: 600;
}

.goal-planner-projection {
  color: var(--text);
}

.goal-planner-date {
  color: var(--text-muted);
}

.goal-planner-hint {
  color: var(--text-dim);
  font-style: italic;
}

/* ── Add Goal Button Row ── */
.goal-add-row {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

/* ── Color Swatches (modal) ── */
.goal-color-swatches {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 0;
}

.goal-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.goal-color-swatch:hover {
  transform: scale(1.15);
}

.goal-color-swatch.selected {
  border-color: var(--text);
  transform: scale(1.1);
}

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

@media (max-width: 640px) {
  .savings-section {
    padding: 24px 16px 0;
  }
}

/* ── Account holdings table — horizontal scroll on mobile ── */
.holdings-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
