/* ============================================================
   WEALTH DASHBOARD — STYLES
   Clean, flat, professional. Works light + dark.
   ============================================================ */

:root {
  --bg-page:        #F7F6F2;
  --bg-primary:     #FFFFFF;
  --bg-secondary:   #F1EFE8;
  --bg-tertiary:    #FAFAF7;

  --text-primary:   #1A1A19;
  --text-secondary: #5F5E5A;
  --text-tertiary:  #888780;

  --border-light:   rgba(0,0,0,0.08);
  --border-mid:     rgba(0,0,0,0.15);

  --success:        #1D9E75;
  --success-bg:     #E1F5EE;
  --success-text:   #0F6E56;

  --danger:         #E24B4A;
  --danger-bg:      #FCEBEB;
  --danger-text:    #A32D2D;

  --info:           #185FA5;
  --info-bg:        #E6F1FB;

  --purple:         #534AB7;
  --teal:           #1D9E75;
  --blue:           #185FA5;
  --amber:          #BA7517;
  --gray:           #888780;
  --coral:          #D85A30;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page:        #1A1A18;
    --bg-primary:     #232220;
    --bg-secondary:   #2C2B28;
    --bg-tertiary:    #1F1E1C;

    --text-primary:   #F1EFE8;
    --text-secondary: #B4B2A9;
    --text-tertiary:  #888780;

    --border-light:   rgba(255,255,255,0.08);
    --border-mid:     rgba(255,255,255,0.15);

    --success-bg:     rgba(29, 158, 117, 0.15);
    --success-text:   #5DCAA5;

    --danger-bg:      rgba(226, 75, 74, 0.15);
    --danger-text:    #F09595;

    --info-bg:        rgba(24, 95, 165, 0.18);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.page {
  min-height: 100vh;
  /* Respect notch / status-bar safe areas when running full-screen in a WebView */
  padding:
    calc(1.25rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right))
    calc(3rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left));
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* TOP NAV */
.navbar {
  position: sticky;
  top: 0.75rem;
  z-index: 50;
  display: flex;
  align-items: center;
  flex-wrap: wrap;        /* if actions don't fit, they drop to a tidy 2nd row */
  gap: 14px;
  row-gap: 10px;
  padding: 10px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 19px;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: nowrap;      /* keep the page links together — never orphan one onto a 2nd line */
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 11px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link i { font-size: 17px; }
.nav-link:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-link.active { background: var(--info-bg); color: var(--info); }
.nav-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
/* Hamburger toggle — shown only on small screens (see media queries) */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px; height: 42px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 20px;
  flex-shrink: 0;
}
.nav-toggle:hover { background: var(--bg-secondary); }

/* HERO */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  padding: 28px 30px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-light);
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(83,74,183,0.10), transparent 55%),
    linear-gradient(135deg, rgba(24,95,165,0.05), rgba(83,74,183,0.02));
  box-shadow: var(--shadow-sm);
}
.hero-label {
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}
.hero-main h1 {
  font-size: 46px;
  margin: 8px 0 4px;
}
.hero-change { text-align: right; }
.hero-change .metric-value { font-size: 26px; }

/* STOCK PORTFOLIO HERO — value + P&L + allocation as one unit */
.stock-hero { display: flex; flex-direction: column; gap: 8px; }
.stock-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.market-filter { font-size: 12px; flex-shrink: 0; }
.stock-hero-value {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin-top: 2px;
}
.stock-hero-pl {
  align-self: flex-start;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  margin-top: 2px;
}
.stock-hero-pl.success { color: var(--success-text); background: var(--success-bg); }
.stock-hero-pl.danger  { color: var(--danger-text);  background: var(--danger-bg); }
.hero-pl-pct { font-size: 13px; opacity: 0.9; }
.alloc-bar {
  display: flex;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-secondary);
  margin: 8px 0 2px;
}
.alloc-seg { height: 100%; }
.alloc-seg + .alloc-seg { box-shadow: inset 1.5px 0 0 var(--bg-primary); }
.stock-hero-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border-light);
}
.hero-stat { display: flex; flex-direction: column; gap: 3px; }
.hero-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
}
.hero-stat-val { font-size: 15px; font-weight: 600; }

/* PAGE HEADER (sub-pages) */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  padding: 4px 2px;
}
.page-head h1 { font-size: 32px; margin: 6px 0 0; }
.page-head .hero-label { color: var(--text-secondary); }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* GOAL ROWS (goals management) */
.goal-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.goal-row:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.goal-row-icon {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: var(--info-bg);
  color: var(--info);
}
.goal-row-main { flex: 1; min-width: 0; }
.goal-row-title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.goal-row-sub { font-size: 12px; color: var(--text-secondary); margin-top: 3px; }
.goal-row-target { text-align: right; }
.goal-row-target-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); }
.goal-row-target-value { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.goal-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* HOLDINGS POLISH */
.cat-subhead-bar {
  background: linear-gradient(90deg, var(--bg-secondary), transparent);
  border-left: 3px solid var(--border-mid);
  padding: 11px 14px;
}
.holdings td { padding: 13px 10px; }
.holdings tbody tr { transition: background 0.1s ease; }
.holdings th.sortable { cursor: pointer; user-select: none; white-space: nowrap; transition: color 0.1s ease; }
.holdings th.sortable:hover { color: var(--accent, var(--text-primary)); }
.holdings th.sorted { color: var(--accent, var(--text-primary)); }
.holdings th .sort-ind { font-size: 11px; opacity: 0.9; }
.mobile-sort { display: none; }
.set-divider { border: none; border-top: 1px solid var(--border-light); margin: 16px 0 6px; }
.rules-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.rule-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--bg-secondary); border-radius: 9px; font-size: 13px; }
.rule-add { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; }
.rule-add > input { width: 100%; }
.rule-add-row { display: flex; gap: 8px; align-items: stretch; }
.rule-add-row select, .rule-add-row input { flex: 1 1 auto; min-width: 0; }
.rule-add-row .btn { flex: 0 0 auto; white-space: nowrap; }
.check-inline { display: flex; align-items: center; gap: 8px; flex-direction: row !important; }
.check-inline input { width: auto; }
.cc-chart-wrap { position: relative; height: 280px; width: 100%; }
.bank-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border-radius: 9px; cursor: pointer; transition: background 0.1s ease; }
.bank-row:hover { background: var(--bg-secondary); }
.bank-row + .bank-row { border-top: 1px solid var(--border-light); }
.bank-row .bank-name { font-weight: 500; }
.bank-row .bank-bal { font-weight: 700; }
.bank-reconcile { margin-top: 10px; }
.txn-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 2px 12px; }
.txn-toolbar-title { font-size: 18px; font-weight: 700; margin-right: auto; }
.txn-toolbar select { flex: 0 1 auto; }
@media (max-width: 600px) {
  .txn-toolbar-title { flex: 1 0 100%; margin-right: 0; }
  .txn-toolbar select { flex: 1 1 auto; }
}
.reconcile { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border-radius: 10px; flex-wrap: wrap; }
.reconcile.ok { background: var(--success-bg, #e8f6ef); }
.reconcile.off { background: var(--danger-bg, #fdecec); }
.reconcile-hint { padding: 6px 12px 0; }
.seg-toggle { display: inline-flex; border: 1px solid var(--border-mid); border-radius: 9px; overflow: hidden; flex-shrink: 0; }
.seg-btn { padding: 7px 14px; background: var(--bg-secondary); border: none; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border-mid); }
.seg-btn.active { background: var(--accent, #534AB7); color: #fff; }
.cat-donut-view { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; padding: 6px 2px; }
.cc-donut-wrap { position: relative; width: 240px; height: 240px; flex: 0 0 auto; }
.cat-legend { flex: 1 1 280px; min-width: 240px; }
.cat-legend-head { display: flex; justify-content: space-between; font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-tertiary); padding-bottom: 7px; border-bottom: 1px solid var(--border-mid); }
.cat-legend-row { display: flex; align-items: center; gap: 11px; padding: 10px 0; border-bottom: 1px solid var(--border-light); }
.cat-legend-row .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.cat-legend-row .name { flex: 1; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-legend-row .pct { font-weight: 700; font-size: 14px; padding: 3px 9px; border-radius: 7px; }

/* BULK SELECT + DELETE */
.check-col { width: 38px; text-align: center !important; padding-left: 14px !important; padding-right: 4px !important; }
.holdings input.holding-check,
.holdings input.group-check {
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--info);
  vertical-align: middle;
  margin: 0;
}
.holdings tbody tr.row-selected td { background: var(--info-bg); }
.holdings tbody tr.row-selected:hover td { background: var(--info-bg); }
.holdings-head-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }

/* BUDGET: done / actual tracking */
.sum-bar {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.sum-bar .bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.holdings input.entry-check {
  width: 15px; height: 15px;
  cursor: pointer;
  accent-color: var(--success);
  vertical-align: middle;
  margin: 0;
}
.holdings tr.entry-done td { opacity: 0.6; }
.holdings tr.entry-done td:first-child,
.holdings tr.entry-done .entry-done-badge { opacity: 1; }
.entry-done-badge { font-size: 10px; }
.form label.check-row {
  flex-direction: row;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: 500;
}
.form input[type="checkbox"] {
  width: 16px; height: 16px;
  padding: 0;
  flex: none;
  accent-color: var(--info);
  cursor: pointer;
}

/* CLONE MONTH DROPDOWN */
.clone-menu { position: relative; }
.clone-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 60;
  min-width: 220px;
}
.clone-dropdown.open { display: block; }
.clone-dropdown button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}
.clone-dropdown button:hover { background: var(--bg-secondary); }
.clone-dropdown button i { font-size: 16px; color: var(--text-secondary); }
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}
#bulkCount { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); opacity: 0.9; }
.modal-confirm { max-width: 400px; }
.modal-import { max-width: 540px; }
#importPreview { max-height: 280px; overflow-y: auto; margin-top: 2px; }
.import-preview { font-size: 12px; }
.import-preview th, .import-preview td { padding: 8px 8px; }
.form input[type="file"] { padding: 8px 10px; font-size: 13px; }
.import-debug {
  max-height: 220px;
  overflow: auto;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
  margin-top: 2px;
}
.confirm-msg { margin: 0 0 1.4rem; color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
h1 {
  font-size: 36px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
.muted { color: var(--text-secondary); font-size: 13px; }
.tiny  { font-size: 12px; }
.bold  { font-weight: 600; }
.success { color: var(--success-text); }
.danger  { color: var(--danger-text); }
.right   { text-align: right; }
.center  { text-align: center; }
.left    { text-align: left; }

.pill {
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.pill-success { background: var(--success-bg); color: var(--success-text); }
.pill-danger  { background: var(--danger-bg);  color: var(--danger-text); }

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

/* BUTTONS */
.btn, .btn-sm {
  background: var(--bg-primary);
  border: 1px solid var(--border-mid);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.btn:hover, .btn-sm:hover {
  background: var(--bg-secondary);
  border-color: var(--text-secondary);
}
.btn:active { transform: scale(0.98); }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; display: inline-block; }
/* loader glyphs spin automatically wherever they appear (buttons, loading states) */
.ti-loader, .ti-loader-2, .ti-loader-3 { display: inline-block; animation: spin 0.8s linear infinite; }
/* password show/hide eye toggle */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { width: 100%; padding-right: 42px; box-sizing: border-box; }
.pw-eye { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0; background: none; border: none; border-radius: 7px; color: var(--text-secondary); cursor: pointer; }
.pw-eye:hover { color: var(--text-secondary); background: var(--bg-secondary); }
.pw-eye i { font-size: 17px; }
.btn-sm { font-size: 12px; padding: 6px 12px; }
.btn-primary {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}
.btn-primary:hover { opacity: 0.9; background: var(--text-primary); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* NAV LINK */
a.btn { text-decoration: none; color: var(--text-primary); }
.page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.page-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.page-nav a:hover { color: var(--text-primary); }

/* METRIC GRID */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.metric {
  position: relative;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.metric:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.metric-icon {
  position: absolute;
  top: 16px; right: 16px;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.metric-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }
.metric-value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.metric-value.success { color: var(--success-text); }
.metric-sub { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.metric-sub.success { color: var(--success-text); }
.metric-sub.danger  { color: var(--danger-text); }
.metric-value.danger { color: var(--danger-text); }
.metric-value.muted { color: var(--text-tertiary); }

/* CARDS */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.card-sub   { font-size: 12px; color: var(--text-secondary); margin-bottom: 14px; }
.card-head  { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
/* Budget income/expense cards size to their own content (no tall empty card) */
#categoryBreakdown { align-items: start; }

/* Labeled filter fields (e.g. Cards page) — clarify each control */
.filter-bar { align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); font-weight: 600; padding-left: 3px; }

/* CHART WRAP */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 200px;
}

/* LEGEND */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.legend b { color: var(--text-primary); font-weight: 500; margin-left: 2px; }
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
}

/* BARS */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-item .bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
  font-weight: 500;
}
.bar-name { color: var(--text-primary); }
.bar-track {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 4px; }
.bar-foot { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.bar-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border-light);
  font-size: 13px;
}

/* STOCK CARDS */
.stocks-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.kse-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 1fr;
  gap: 32px;
  align-items: start;
}
.kse-layout .chart-wrap {
  height: 360px;
}
.kse-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.kse-legend span { display: flex; align-items: center; gap: 6px; }
.kse-legend b { color: var(--text-primary); font-weight: 500; margin-left: 2px; }
.stock-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stock-name { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.stock-card .bold { font-size: 14px; margin-top: 4px; }
.stock-card .tiny { margin-top: 2px; }

/* HOLDINGS TABLE */
.holdings {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.holdings {
  margin-top: 8px;
}
.holdings th {
  text-align: center;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 10px 10px;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.holdings th.left { text-align: left; }
.holdings td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}
.holdings tbody tr:last-child td { border-bottom: none; }
.holdings tbody tr:hover { background: var(--bg-tertiary); }
.subtotal-row td {
  border-top: 2px solid var(--border-mid);
  border-bottom: none !important;
  background: var(--bg-tertiary);
  padding: 10px 10px;
  font-size: 13px;
}
.holdings tbody tr.subtotal-row:hover { background: var(--bg-tertiary); }

.cat-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: middle;
}
.cat-subhead-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  letter-spacing: 0.01em;
}
.cat-subhead-bar:first-child { margin-top: 0; }
.cat-subhead-total {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 12px;
}
.row-edit, .row-del {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.holdings tr:hover .row-edit,
.holdings tr:hover .row-del { opacity: 1; }
.row-edit:hover { color: var(--info); background: var(--info-bg); }
.row-del:hover { color: var(--danger); background: var(--danger-bg); }

/* INSIGHTS */
.insight ul { margin: 0; padding-left: 0; list-style: none; }
.insight li {
  padding: 6px 0;
  font-size: 13px;
  line-height: 1.6;
}
.insight li b { font-weight: 600; }
.insight-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}
.insight-head i { font-size: 18px; }
.insight-danger { background: var(--danger-bg); border-color: transparent; }
.insight-danger .insight-head, .insight-danger li { color: var(--danger-text); }
.insight-success { background: var(--success-bg); border-color: transparent; }
.insight-success .insight-head, .insight-success li { color: var(--success-text); }

/* MODAL */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  box-shadow: var(--shadow-md);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 600; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-secondary);
  gap: 6px;
  font-weight: 500;
}
.form input, .form select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: inherit;
}
.form input:focus, .form select:focus {
  outline: none;
  border-color: var(--text-primary);
  box-shadow: 0 0 0 3px var(--border-light);
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* GOAL TRACKER */
.goal-primary {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.goal-primary-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.goal-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-secondary);
}
.goal-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.goal-status-on { background: var(--success-bg); color: var(--success-text); }
.goal-status-behind { background: var(--danger-bg); color: var(--danger-text); }
.goal-status-risk { background: #FEF3CD; color: #856404; }
.goal-title { font-size: 18px; font-weight: 600; margin: 4px 0 2px; }
.goal-subtitle { font-size: 12px; color: var(--text-secondary); }
.goal-pct-big {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}
.goal-pct-label {
  font-size: 12px;
  color: var(--text-secondary);
}
.goal-progress-bar {
  height: 10px;
  background: var(--bg-secondary);
  border-radius: 5px;
  overflow: hidden;
  margin: 14px 0 8px;
}
.goal-progress-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s ease;
}
.goal-progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}
.goal-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 16px;
}
.goal-metric-label { font-size: 11px; color: var(--text-secondary); }
.goal-metric-value { font-size: 16px; font-weight: 600; margin-top: 2px; }

.goal-secondary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}
.goal-secondary {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.goal-secondary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.goal-secondary-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}
.goal-secondary-title i { font-size: 18px; color: var(--text-secondary); }
.goal-secondary-sub { font-size: 11px; color: var(--text-secondary); margin-bottom: 10px; }
.goal-secondary-value { font-size: 22px; font-weight: 600; }
.goal-secondary-value span { font-size: 14px; font-weight: 400; color: var(--text-secondary); }
.goal-secondary-bar {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.goal-secondary-fill {
  height: 100%;
  border-radius: 3px;
}
.goal-secondary-foot { font-size: 11px; color: var(--text-secondary); }
.goal-arrow { color: var(--text-tertiary); margin: 0 4px; }

/* Milestones */
.milestones {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.25rem 1rem;
  margin-top: 16px;
}
.milestones-title { font-size: 14px; font-weight: 600; margin-bottom: 20px; }
.milestones-track {
  display: flex;
  align-items: flex-start;
}
.milestone-line {
  flex: 1;
  height: 4px;
  background: var(--bg-secondary);
  margin-top: 10px;
}
.milestone-line.done { background: var(--success); }
.milestone-line.active { background: linear-gradient(to right, var(--success), var(--bg-secondary)); }
.milestone-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 60px;
}
.milestone-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-mid);
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.milestone-dot.done { background: var(--success); border-color: var(--success); color: #fff; }
.milestone-dot.active { border-color: var(--success); background: var(--bg-primary); }
.milestone-dot.future { border-color: var(--border-mid); color: var(--text-tertiary); }
.milestone-label {
  margin-top: 8px;
  font-size: 10px;
  text-align: center;
  color: var(--text-secondary);
  line-height: 1.3;
}
.milestone-label b { display: block; font-size: 11px; color: var(--text-primary); }

/* NEWS */
.news-list {
  display: flex;
  flex-direction: column;
}
.news-item {
  display: block;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}
.news-item:last-child { border-bottom: none; }
.news-item:hover { background: var(--bg-tertiary); }
.news-item-body { padding: 0 4px; }
.news-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.5;
}
.news-item:hover .news-title { color: var(--info); }
.news-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 3px;
}
.news-tickers {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.news-ticker {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--info-bg);
  color: var(--info);
  letter-spacing: 0.02em;
}

/* TRANSACTION BADGES */
.txn-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.txn-success { background: var(--success-bg); color: var(--success-text); }
.txn-danger  { background: var(--danger-bg);  color: var(--danger-text); }
.txn-info    { background: var(--info-bg);    color: var(--info); }
.txn-accent  { background: rgba(83, 74, 183, 0.12); color: #534AB7; }
.info   { color: var(--info); }
.accent { color: #534AB7; }

/* BUDGET */
.budget-dash-grid,
.budget-summary-grid {
  margin-bottom: 0;
}
.budget-dash-cats {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}
.budget-top-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.budget-top-chip {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
}
.budget-top-chip b { font-weight: 600; color: var(--text-primary); }
input[type="month"].btn {
  font-family: inherit;
  min-width: 140px;
}

/* LOGIN */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.login-wrap {
  width: 100%;
  max-width: 400px;
}
.login-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  padding: 2rem 2rem 1.75rem;
  box-shadow: var(--shadow-md);
}
.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-brand i {
  font-size: 40px;
  color: var(--purple);
  display: block;
  margin-bottom: 0.75rem;
}
.login-brand h1 {
  font-size: 24px;
  margin: 0 0 0.35rem;
}
.login-brand p { margin: 0; }
.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 1rem;
  border-radius: var(--radius-md);
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 13px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.login-form input {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
}
.login-form input:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px var(--info-bg);
}
.login-submit {
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
  padding: 11px 14px;
}
.login-or { display: flex; align-items: center; gap: 10px; color: var(--text-tertiary); font-size: 12px; margin: 16px 0; }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--border-light); }
.login-google { width: 100%; justify-content: center; gap: 8px; }
.login-toggle { text-align: center; font-size: 13px; color: var(--text-secondary); margin: 16px 0 0; }
.login-toggle a { color: var(--info); font-weight: 600; text-decoration: none; cursor: pointer; }
.login-error.is-ok { background: var(--success-bg, #e8f6ef); color: var(--success-text, #1D9E75); border-color: var(--success-text, #1D9E75); }

/* Data tables scroll horizontally inside their card instead of stretching the page */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* RESPONSIVE */
@media (max-width: 980px) {
  .navbar { flex-wrap: wrap; gap: 10px; }
  .nav-actions { width: 100%; margin-left: 0; justify-content: flex-start; }
}
@media (max-width: 900px) {
  .two-col     { grid-template-columns: 1fr; }
  .stocks-grid { grid-template-columns: repeat(2, 1fr); }
  .kse-layout { grid-template-columns: 1fr; }
  .goal-secondary-grid { grid-template-columns: 1fr; }
  .goal-metrics { grid-template-columns: repeat(2, 1fr); }
  .hero { align-items: flex-start; }
  .hero-change { text-align: left; }
  .hero-main h1 { font-size: 36px; }
}
@media (max-width: 768px) {
  /* Collapse the nav links into a hamburger menu */
  .nav-toggle { display: inline-flex; order: 2; margin-left: auto; }
  .nav-actions { order: 3; }
  .nav-links {
    order: 4;
    width: 100%;
    display: none;            /* hidden until the hamburger is tapped */
    flex-direction: column;
    gap: 2px;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
  }
  .navbar.nav-open .nav-links { display: flex; }
  .nav-link { width: 100%; padding: 12px 14px; }

  /* Page header tools wrap and fill width so filters stay tappable */
  .page-head { align-items: stretch; }
  .toolbar { width: 100%; }
  .toolbar > select, .toolbar > input { flex: 1 1 auto; min-width: 0; }
  .goal-metrics { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  /* Touch-friendly hit targets (>= ~44px) */
  .btn, .btn-sm { min-height: 42px; padding-top: 9px; padding-bottom: 9px; }
  .icon-btn { width: 42px; height: 42px; }
  .nav-link { padding: 10px 12px; }
  .row-edit, .row-del { padding: 8px 9px; }
  /* Goal rows stack so the target/actions don't squeeze */
  .goal-row { flex-wrap: wrap; }
  .goal-row-target { text-align: left; }
  .hero { padding: 22px; }
  .hero-main h1 { font-size: 32px; }
}
/* Holdings table -> cards on phones (the wide table can't fit; this keeps
   value/P&L visible and readable, with a sort dropdown since headers hide) */
@media (max-width: 600px) {
  .mobile-sort { display: inline-flex; }
  .holdings thead { display: none; }
  .holdings, .holdings tbody { display: block; width: 100%; }
  .holdings tbody tr {
    display: block; position: relative;
    border: 1px solid var(--border-light); border-radius: 14px;
    background: var(--bg-secondary);
    padding: 14px 16px; margin-bottom: 12px;
  }
  .holdings tbody tr:hover,
  .holdings tbody tr.subtotal-row:hover { background: var(--bg-secondary); }
  .holdings tbody tr.row-selected td { background: transparent; }
  .holdings tbody tr.row-selected { border-color: var(--accent, var(--border-mid)); background: var(--info-bg); }
  .holdings tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none !important; padding: 5px 0 !important; text-align: right !important;
    white-space: normal;
  }
  .holdings tbody td::before {
    content: attr(data-label);
    color: var(--text-tertiary); font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em; text-align: left;
  }
  .holdings tbody td:empty { display: none; }
  .holdings tbody td.cell-stock {
    font-size: 17px; font-weight: 700; justify-content: flex-start;
    padding: 0 36px 9px 0 !important; margin-bottom: 7px;
    border-bottom: 1px solid var(--border-light) !important;
  }
  .holdings tbody td.cell-stock::before { display: none; }
  .holdings tbody td.check-col {
    position: absolute; top: 12px; right: 12px; width: auto; padding: 0 !important;
  }
  .holdings tbody td.check-col::before { display: none; }
  .holdings tbody td.cell-edit::before { content: 'Edit'; }
  .holdings tbody tr.subtotal-row { background: var(--bg-tertiary); }
}

@media (max-width: 480px) {
  .stocks-grid { grid-template-columns: 1fr; }
  .goal-metrics { grid-template-columns: 1fr 1fr; }
  .page { padding: calc(0.75rem + env(safe-area-inset-top)) calc(0.75rem + env(safe-area-inset-right)) calc(2rem + env(safe-area-inset-bottom)) calc(0.75rem + env(safe-area-inset-left)); }
  .card { padding: 1.1rem 1.2rem; }
  .hero { padding: 20px; }
  .hero-main h1 { font-size: 28px; }
  .modal { max-width: 100%; }
  h1 { font-size: 26px; }
}
