/* ══════════════════════════════════════════════════════════
   ClearWealth — Premium Design System v3
   Dark, sophisticated, mobile-first financial dashboard
   ══════════════════════════════════════════════════════════ */

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

/* ── Base ─────────────────────────────────────────────────── */
body {
  background: #050a14;
  color: #e2e8f0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  inset-block: 0;
  left: 0;
  z-index: 40;
  width: 15.5rem;
  background: linear-gradient(180deg, #080e1a 0%, #060c16 100%);
  border-right: 1px solid rgba(255,255,255,0.055);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
#sidebar.open { transform: translateX(0); }

@media (min-width: 1024px) {
  #sidebar            { transform: translateX(0); }
  #main-wrap          { margin-left: 15.5rem; }
  #hamburger-btn      { display: none !important; }
  #overlay            { display: none !important; }
  #sidebar-close-btn  { display: none !important; }
}

@media (max-width: 1023px) {
  #sidebar-close-btn { display: flex !important; }
}

/* ── Overlay ──────────────────────────────────────────────── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 30;
}
#overlay.show { display: block; }

/* ── Nav links ────────────────────────────────────────────── */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.875rem;
  border-radius: 0.75rem;
  font-size: 0.8375rem;
  color: #6b7a96;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  border: 1px solid transparent;
  margin-bottom: 1px;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.005em;
}
.nav-link:hover {
  color: #cbd5e1;
  background: rgba(255,255,255,0.04);
}
.nav-link.active {
  background: linear-gradient(105deg, rgba(20,184,166,0.14) 0%, rgba(6,182,212,0.07) 100%);
  color: #2dd4bf;
  border-color: rgba(20,184,166,0.22);
}
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 18%; bottom: 18%;
  width: 2.5px;
  background: linear-gradient(to bottom, #14b8a6, #06b6d4);
  border-radius: 0 3px 3px 0;
}
.nav-section-label {
  font-size: 0.625rem;
  font-weight: 700;
  color: #2d3a52;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding: 0.875rem 0.5rem 0.3rem;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: #0b1120;
  border: 1px solid rgba(255,255,255,0.065);
  border-radius: 1.125rem;
  padding: 1.25rem;
  transition: border-color 0.2s;
}
.card:hover { border-color: rgba(255,255,255,0.1); }

.metric-card {
  background: linear-gradient(145deg, #0c1221 0%, #0f1629 100%);
  border: 1px solid rgba(255,255,255,0.065);
  border-radius: 1.125rem;
  padding: 1.125rem;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.11);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
}
.metric-card .metric-label {
  font-size: 0.6rem;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 700;
  margin-bottom: 0.4rem;
}
.metric-card .metric-value {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.04em;
  line-height: 1.1;
}
.metric-card .metric-sub {
  font-size: 0.6875rem;
  color: #334155;
  margin: 0.3rem 0 0;
}

/* ── Net Worth Banner ────────────────────────────────────── */
.networth-card {
  background: linear-gradient(135deg, #042f2e 0%, #0c3554 40%, #0f2d5c 100%);
  border-radius: 1.375rem;
  padding: 1.625rem 1.5rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(20,184,166,0.15), 0 0 0 1px rgba(20,184,166,0.12);
}
.networth-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 10% 60%, rgba(20,184,166,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 90% 10%, rgba(6,182,212,0.09) 0%, transparent 55%),
    radial-gradient(ellipse at 60% 90%, rgba(99,102,241,0.07) 0%, transparent 50%);
  pointer-events: none;
}
.networth-card > * { position: relative; z-index: 1; }
.networth-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 0.375rem;
}
.networth-value {
  font-size: 2.625rem;
  font-weight: 800;
  margin: 0 0 0.25rem;
  letter-spacing: -0.05em;
  line-height: 1;
  color: #fff;
}
.networth-sub {
  font-size: 0.8125rem;
  color: rgba(255,255,255,0.4);
  margin: 0;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  background: linear-gradient(135deg, #14b8a6 0%, #06b6d4 100%);
  color: #fff;
  font-weight: 600;
  border-radius: 0.875rem;
  padding: 0.5rem 1.125rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  box-shadow: 0 3px 14px rgba(20,184,166,0.3);
  font-size: 0.8375rem;
  line-height: 1.5;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.005em;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #2dd4bf 0%, #22d3ee 100%);
  box-shadow: 0 5px 20px rgba(20,184,166,0.45);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(20,184,166,0.25); }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  background: rgba(255,255,255,0.055);
  color: #cbd5e1;
  font-weight: 500;
  border-radius: 0.875rem;
  padding: 0.5rem 1.125rem;
  border: 1px solid rgba(255,255,255,0.09);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  font-size: 0.8375rem;
  line-height: 1.5;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: -0.005em;
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.14);
  color: #e2e8f0;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  background: rgba(225,29,72,0.12);
  color: #fb7185;
  font-weight: 500;
  border-radius: 0.875rem;
  padding: 0.5rem 1.125rem;
  border: 1px solid rgba(225,29,72,0.25);
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
  font-size: 0.8375rem;
  line-height: 1.5;
}
.btn-danger:hover { background: rgba(225,29,72,0.22); border-color: rgba(225,29,72,0.4); }

/* ── Icon Badges ──────────────────────────────────────────── */
.icon-badge {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  flex-shrink: 0;
}
.icon-badge-sm {
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-input {
  width: 100%;
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(255,255,255,0.085);
  border-radius: 0.875rem;
  padding: 0.65rem 1rem;
  font-size: 0.875rem;
  color: #e2e8f0;
  outline: none;
  transition: all 0.2s;
  display: block;
  -webkit-appearance: none;
  font-family: inherit;
}
.form-input::placeholder { color: #3d4f69; }
.form-input:focus {
  border-color: transparent;
  box-shadow: 0 0 0 2px rgba(20,184,166,0.55);
  background: rgba(255,255,255,0.055);
}
select.form-input {
  appearance: auto;
  -webkit-appearance: auto;
  background: rgba(255,255,255,0.035);
}
.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.375rem;
  letter-spacing: 0.01em;
}

/* ── Progress bars ────────────────────────────────────────── */
.progress-bar {
  height: 0.3125rem;
  border-radius: 9999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.65s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Modals ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: linear-gradient(180deg, #0e1629 0%, #0b1120 100%);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 1.5rem 1.5rem 0 0;
  padding: 1.5rem;
  width: 100%;
  max-width: 100%;
  box-shadow: 0 -24px 64px rgba(0,0,0,0.65);
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 1rem; }
  .modal-box {
    border-radius: 1.5rem;
    max-width: 28rem;
    max-height: 88vh;
    border: 1px solid rgba(255,255,255,0.1);
  }
}

.modal-handle {
  width: 2.5rem;
  height: 0.25rem;
  background: rgba(255,255,255,0.12);
  border-radius: 9999px;
  margin: 0 auto 1.375rem;
}
@media (min-width: 640px) { .modal-handle { display: none; } }

.modal-title {
  font-size: 1.0625rem;
  font-weight: 700;
  margin: 0;
  color: #f1f5f9;
  letter-spacing: -0.02em;
}

/* ── Clerk auth modal ─────────────────────────────────────── */
#clerk-modal-container {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5,10,20,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Auth gate ────────────────────────────────────────────── */
#auth-gate {
  background: #050a14;
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Toast notifications ──────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: min(22rem, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: #0e1626;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 1rem;
  padding: 0.875rem 1rem;
  font-size: 0.8rem;
  box-shadow: 0 10px 35px rgba(0,0,0,0.55);
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
  line-height: 1.45;
}
.toast.success { border-color: rgba(20,184,166,0.3); background: rgba(4,42,38,0.95); }
.toast.error   { border-color: rgba(244,63,94,0.3);  background: rgba(50,8,20,0.95); }
.toast.info    { border-color: rgba(6,182,212,0.3);  background: rgba(4,30,44,0.95); }

@keyframes toastIn {
  from { transform: translateX(110%) scale(0.92); opacity: 0; }
  to   { transform: translateX(0)     scale(1);   opacity: 1; }
}

/* ── Account type borders ─────────────────────────────────── */
.acct-depository { border-left: 3px solid #14b8a6; }
.acct-credit     { border-left: 3px solid #f43f5e; }
.acct-investment { border-left: 3px solid #8b5cf6; }
.acct-loan       { border-left: 3px solid #f59e0b; }
.acct-savings    { border-left: 3px solid #06b6d4; }

/* ── Account card ─────────────────────────────────────────── */
.account-card {
  background: linear-gradient(145deg, #0b1120 0%, #0d1428 100%);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 1.125rem;
  padding: 1.25rem;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.account-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.12);
  box-shadow: 0 10px 28px rgba(0,0,0,0.4);
}

/* ── Debt card ────────────────────────────────────────────── */
.debt-card {
  background: linear-gradient(145deg, #0b1120 0%, #180a14 100%);
  border: 1px solid rgba(255,255,255,0.07);
  border-left: 3px solid #f43f5e;
  border-radius: 1.125rem;
  padding: 1.25rem;
}

/* ── Goal cards ───────────────────────────────────────────── */
.goal-card {
  background: linear-gradient(145deg, #0b1120 0%, #0d1428 100%);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 1.125rem;
  padding: 1.25rem;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.goal-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.12);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
}

/* ── Loading spinner ──────────────────────────────────────── */
.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Table rows ───────────────────────────────────────────── */
.txn-row { transition: background 0.12s; }
.txn-row:hover { background: rgba(255,255,255,0.025); }

/* ── Giving badges ────────────────────────────────────────── */
.giving-badge {
  font-size: 0.6375rem;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-weight: 700;
  display: inline-block;
  letter-spacing: 0.025em;
  text-transform: capitalize;
}
.giving-tithe   { background: rgba(139,92,246,0.15); color: #c4b5fd; border: 1px solid rgba(139,92,246,0.28); }
.giving-charity { background: rgba(20,184,166,0.15); color: #5eead4; border: 1px solid rgba(20,184,166,0.28); }
.giving-family  { background: rgba(245,158,11,0.15); color: #fcd34d; border: 1px solid rgba(245,158,11,0.28); }
.giving-friend  { background: rgba(6,182,212,0.15);  color: #67e8f9; border: 1px solid rgba(6,182,212,0.28); }
.giving-other   { background: rgba(100,116,139,0.15); color: #cbd5e1; border: 1px solid rgba(100,116,139,0.28); }

/* ── Status pills ─────────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pill-success { background: rgba(20,184,166,0.15); color: #2dd4bf; border: 1px solid rgba(20,184,166,0.25); }
.pill-warning { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.25); }
.pill-error   { background: rgba(244,63,94,0.15);  color: #fb7185; border: 1px solid rgba(244,63,94,0.25); }

/* ── Bill rows ────────────────────────────────────────────── */
.bill-row {
  display: flex;
  align-items: center;
  padding: 0.875rem 1.25rem;
  gap: 0.875rem;
  transition: background 0.12s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.bill-row:last-child { border-bottom: none; }
.bill-row:hover { background: rgba(255,255,255,0.022); }

/* ── Section headers ──────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #e2e8f0;
  margin: 0;
  letter-spacing: -0.015em;
}
.section-link {
  font-size: 0.75rem;
  color: #2dd4bf;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}
.section-link:hover { color: #5eead4; }

/* ── Empty states ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: #334155;
}
.empty-state i {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
  opacity: 0.2;
}
.empty-state p { font-size: 0.875rem; margin: 0; color: #475569; }
.empty-state p.sub { font-size: 0.8125rem; color: #2d3a52; margin-top: 0.25rem; }

/* ── Dividers ─────────────────────────────────────────────── */
.divide-row { border-bottom: 1px solid rgba(255,255,255,0.045); }
.divide-row:last-child { border-bottom: none; }

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 0.875rem;
}
.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  letter-spacing: -0.025em;
  color: #f1f5f9;
}
.page-subtitle {
  font-size: 0.8125rem;
  color: #475569;
  margin: 0;
}
.page-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  align-items: center;
}

/* ── Card table ───────────────────────────────────────────── */
.card-table {
  background: #0b1120;
  border: 1px solid rgba(255,255,255,0.065);
  border-radius: 1.125rem;
  overflow: hidden;
}
.card-table-header {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.055);
  background: rgba(255,255,255,0.02);
}

/* ── Transaction list items ───────────────────────────────── */
.txn-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.txn-item:last-child { border-bottom: none; }

/* ── Summary stat bar ─────────────────────────────────────── */
.stat-card {
  background: linear-gradient(145deg, #0c1221 0%, #0f1629 100%);
  border: 1px solid rgba(255,255,255,0.065);
  border-radius: 1rem;
  padding: 0.875rem 1rem;
  text-align: center;
}
.stat-label {
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #475569;
  margin-bottom: 0.3rem;
}
.stat-value {
  font-size: 1.1875rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* ── Safe area ────────────────────────────────────────────── */
@supports (padding: max(0px)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  #main-wrap > header { padding-top: max(0.75rem, env(safe-area-inset-top)); }
  #toast-container { bottom: max(1.5rem, env(safe-area-inset-bottom)); }
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden { display: none !important; }
.min-h-screen { min-height: 100vh; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Gradient text */
.gradient-text {
  background: linear-gradient(to right, #2dd4bf, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ── Mobile responsive overrides ─────────────────────────── */
@media (max-width: 639px) {
  .card, .metric-card { padding: 1rem; border-radius: 1rem; }
  .account-card, .goal-card { padding: 1rem; border-radius: 1rem; }
  .btn-primary, .btn-secondary { padding: 0.5rem 0.875rem; font-size: 0.8125rem; }
  .modal-box .btn-primary,
  .modal-box .btn-secondary { width: 100%; justify-content: center; }
  .page-title { font-size: 1.125rem; }
  .networth-value { font-size: 2.1rem; }
}
