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

/* Prevent any element from making the page wider than the viewport.
   This stops the browser from auto-zooming and going off-center on mobile. */
html { overflow-x: hidden; }
body { overflow-x: hidden; max-width: 100%; }

/* ── Theme tokens ───────────────────────────────────────────────────────────── */
:root {
  --bg:       #131009;
  --surface:  #1d1710;
  --surface2: #261e14;
  --border:   #3c2d1e;
  --text:     #ede3d4;
  --muted:    #9a8468;
  --accent:   #c8853a;
  --green:    #5aad6f;
  --yellow:   #d4a030;
  --red:      #c85c50;
  --radius:   10px;
}

/* ── Base ───────────────────────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Outfit', -apple-system, sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: 58px; /* compensate for fixed header */
}

/* ── Header / Nav ───────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  padding: 0 28px;
  height: 58px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface) 0%, #17120a 100%);
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 201; /* above sidebar (200) and sidebar overlay (199) */
}

.nav-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -.2px;
  font-family: 'Lora', serif;
  margin-right: 24px;
}
.nav-brand span { color: var(--accent); }

.nav-link {
  display: flex;
  align-items: center;
  height: 58px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color .15s;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--text); border-bottom-color: var(--accent); }

.nav-spacer { flex: 1; }

/* ── Sidebar (fixed, always visible) ───────────────────────────────────────── */
.sidebar {
  position: fixed;
  left: 0;
  top: 58px;
  width: 216px;
  height: calc(100vh - 58px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 200;
  box-shadow: 4px 0 20px rgba(0,0,0,.3);
}

/* Push content past the fixed sidebar, fill remaining width */
.sidebar ~ main,
.sidebar ~ footer.site-footer,
.sidebar ~ #save-bar {
  margin-left: 216px;
  margin-right: 0;
  max-width: none;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-radius: 7px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: color .15s, background .15s;
  white-space: nowrap;
}
.sidebar-link:hover { color: var(--text); background: rgba(255,255,255,.02); }
.sidebar-link.active { color: var(--accent); background: rgba(200,133,58,.11); font-weight: 600; }
.sidebar-link.sub { padding: 7px 12px 7px 20px; font-size: 12.5px; font-weight: 400; }
.sidebar-link.sub.active { font-weight: 500; }

.sidebar-divider { height: 1px; background: var(--border); margin: 5px 2px; flex-shrink: 0; }

.sidebar-section { display: flex; flex-direction: column; gap: 1px; }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--muted);
  opacity: .55;
  padding: 2px 12px 4px;
  pointer-events: none;
}

/* ── Nav ticker search ──────────────────────────────────────────────────────── */
.nav-search {
  position: relative;
  display: flex;
  align-items: center;
  margin-right: 10px;
}
.nav-search input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  font-family: 'Outfit', sans-serif;
  padding: 6px 32px 6px 12px;
  width: 170px;
  outline: none;
  transition: border-color .15s, width .2s;
}
.nav-search input::placeholder { color: var(--muted); }
.nav-search input:focus { border-color: var(--accent); width: 210px; }
.nav-search button {
  position: absolute;
  right: 6px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
  transition: color .15s;
}
.nav-search button:hover { color: var(--accent); }

.nav-search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 260px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  z-index: 200;
  overflow: hidden;
}
.nav-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .1s;
  text-decoration: none;
}
.nav-search-item:hover,
.nav-search-item.active { background: rgba(200,133,58,.1); }
.nav-search-symbol {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  min-width: 54px;
  flex-shrink: 0;
}
.nav-search-name {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticker-logo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: contain;
  background: var(--surface2);
  flex-shrink: 0;
}
.ticker-logo-hero {
  width: 40px;
  height: 40px;
}
.nav-search-type {
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}
.nav-search-empty {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ── User menu ──────────────────────────────────────────────────────────────── */
.user-menu-wrap {
  position: relative;
  margin-left: 12px;
}
.user-avatar-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s, background .15s;
}
.user-avatar-btn:hover { border-color: var(--accent); background: rgba(200,133,58,.1); }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  z-index: 300;
  overflow: hidden;
}
.user-dropdown.open { display: block; }

.user-dropdown-email {
  padding: 13px 16px 11px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: 'Outfit', sans-serif;
  text-decoration: none;
  transition: background .1s;
}
.user-dropdown-item:hover { background: rgba(200,133,58,.08); color: var(--accent); }
.user-dropdown-item svg { opacity: .6; flex-shrink: 0; }
.user-dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }
.user-dropdown-item.danger { color: var(--muted); }
.user-dropdown-item.danger:hover { background: rgba(200,92,80,.08); color: var(--red); }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
footer.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  margin-top: auto;
}
footer.site-footer a { color: var(--muted); text-decoration: none; transition: color .15s; }
footer.site-footer a:hover { color: var(--accent); }
footer.site-footer .footer-links { display: flex; gap: 18px; }

/* ── Value state classes ────────────────────────────────────────────────────── */
.val-good { color: var(--green); }
.val-warn { color: var(--yellow); }
.val-na   { color: var(--muted); }

/* ── Skeleton loader ────────────────────────────────────────────────────────── */
.skeleton { background: var(--border); border-radius: 4px; animation: shimmer 1.5s infinite; }
@keyframes shimmer {
  0%, 100% { opacity: .5; }
  50%       { opacity: 1; }
}

/* ── Status bar — smooth expand/collapse, no layout jump ────────────────────── */
/* body #status has specificity (1,0,1) — beats per-page #status at (1,0,0)     */
body #status {
  display: block;         /* always in flow; use max-height instead of display:none */
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 16px;
  padding-right: 16px;
  margin: 0;
  border-radius: var(--radius);
  font-size: 13px;
  transition:
    max-height .3s ease,
    opacity    .22s ease,
    padding-top    .3s ease,
    padding-bottom .3s ease;
}
body #status.error {
  max-height: 48px;
  opacity: 1;
  padding-top: 10px;
  padding-bottom: 10px;
  background: rgba(248,81,73,.12);
  color: var(--red);
}

/* ── Toast notification ─────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  z-index: 999;
}
#toast.show      { opacity: 1; }
#toast.toast-ok  { border-color: var(--green); color: var(--green); }
#toast.toast-err { border-color: var(--red);   color: var(--red); }

/* ── Mobile hamburger button ────────────────────────────────────────────────── */
.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  padding: 7px 9px;
  flex-shrink: 0;
  transition: border-color .15s;
  order: -1;
  margin-right: 8px;
}
.menu-toggle:hover { border-color: var(--muted); }
.menu-toggle span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: var(--muted);
  transition: background .15s;
}
.menu-toggle:hover span { background: var(--text); }

/* ── Sidebar overlay (mobile) ───────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 199;
  cursor: pointer;
}
body.sidebar-open .sidebar-overlay { display: block; }

/* ── Mobile breakpoint (≤ 768px) ────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header */
  header { padding: 0 12px; gap: 6px; }
  .nav-brand { font-size: 16px; margin-right: 0; }
  .nav-search { display: none; }
  .menu-toggle { display: flex; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 200;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* Remove the sidebar content offset */
  .sidebar ~ main,
  .sidebar ~ footer.site-footer,
  .sidebar ~ #save-bar { margin-left: 0; }

  /* Main content padding — !important needed to override per-page inline styles */
  main { padding: 14px 14px 28px !important; }

  /* Table horizontal scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Toolbar layout */
  .toolbar { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 16px; }
  .toolbar-right { width: 100%; flex-wrap: wrap; gap: 8px; }
  #dash-search { width: 100%; max-width: 100%; }

  /* Column panel anchors to left on mobile */
  .col-panel { right: auto; left: 0; }

  /* Footer */
  footer.site-footer { padding: 16px 14px; flex-direction: column; align-items: flex-start; }
}

/* ── Small phones (≤ 480px) ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .card { padding: 14px 16px; }
  .card .value { font-size: 20px; }
  .chart-card { padding: 16px; }
  .toolbar-right { gap: 6px; }
}

/* ── iOS auto-zoom prevention ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

/* ── Tap-target enforcement (≤ 768px) ───────────────────────────────────────── */
@media (max-width: 768px) {
  .filter-btn, .period-btn, .pag-btn, .tab-btn, .btn-action {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .menu-toggle {
    width: 44px;
    height: 44px;
    padding: 9px 11px;
  }
  .user-avatar-btn {
    width: 44px;
    height: 44px;
  }
}

/* ── Page entrance animations ───────────────────────────────────────────────── */
@keyframes enterUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes enterLeft {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes enterFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes bodyReveal {
  from { opacity: 0; }
  to   { opacity: 1; }
}

body.page-animate {
  animation: bodyReveal 0.35s ease both;
}

body.page-animate header {
  animation: enterFade 0.4s ease both;
}
/* Only animate sidebar entrance on desktop — on mobile, the sidebar is a
   slide-in drawer and the animation would permanently override translateX(-100%) */
@media (min-width: 769px) {
  body.page-animate .sidebar {
    animation: enterLeft 0.4s ease both;
  }
}

/* Stagger metric cards on page load */
body.page-animate .card:nth-child(1) { animation: enterUp 0.5s 0.06s ease both; }
body.page-animate .card:nth-child(2) { animation: enterUp 0.5s 0.12s ease both; }
body.page-animate .card:nth-child(3) { animation: enterUp 0.5s 0.18s ease both; }
body.page-animate .card:nth-child(4) { animation: enterUp 0.5s 0.24s ease both; }
body.page-animate .card:nth-child(5) { animation: enterUp 0.5s 0.30s ease both; }
body.page-animate .card:nth-child(6) { animation: enterUp 0.5s 0.36s ease both; }
body.page-animate .card:nth-child(7) { animation: enterUp 0.5s 0.42s ease both; }
body.page-animate .card:nth-child(8) { animation: enterUp 0.5s 0.48s ease both; }

/* Charts, table, AI card animate in later */
body.page-animate .charts-row     { animation: enterUp 0.55s 0.38s ease both; }
body.page-animate .table-card     { animation: enterUp 0.55s 0.48s ease both; }
body.page-animate #ai-portfolio-card { animation: enterUp 0.55s 0.54s ease both; }
body.page-animate #nw-chart-card  { animation: enterUp 0.55s 0.60s ease both; }

/* Generic section entrance for other pages */
body.page-animate .page-section-1 { animation: enterUp 0.5s 0.06s ease both; }
body.page-animate .page-section-2 { animation: enterUp 0.5s 0.16s ease both; }
body.page-animate .page-section-3 { animation: enterUp 0.5s 0.26s ease both; }
body.page-animate .page-section-4 { animation: enterUp 0.5s 0.36s ease both; }
body.page-animate .page-section-5 { animation: enterUp 0.5s 0.46s ease both; }

/* ── Improved skeleton shimmer ──────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface2) 25%,
    rgba(200,133,58,.07) 50%,
    var(--surface2) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-sweep 1.6s infinite;
}
@keyframes skeleton-sweep {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── Mobile nav search (visible on mobile) ──────────────────────────────────── */
@media (max-width: 768px) {
  /* Collapse the spacer so search can take the center */
  .nav-spacer { display: none; }

  /* Show the search and let it flex-fill the center */
  .nav-search {
    display: flex;
    flex: 1;
    margin: 0 8px;
    min-width: 0;
  }
  .nav-search input {
    width: 100% !important;
    min-width: 0;
    font-size: 16px !important; /* prevent iOS zoom */
  }
  .nav-search input:focus {
    width: 100% !important;
  }

  /* Remove sync button entirely on mobile — it crowds the search bar */
  #sync-btn { display: none !important; }
  #synced-at { display: none; }
}

/* ── Mobile chart sizing ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chart-wrap {
    height: 220px !important;
    width: 100% !important;
    box-sizing: border-box;
  }
  .chart-wrap canvas {
    display: block !important;
    max-width: 100% !important;
  }
  .chart-card {
    padding: 16px !important;
  }
  .chart-card h2 {
    font-size: 13px !important;
    margin-bottom: 12px !important;
  }
}

/* ── Mobile metric cards — 2 columns ────────────────────────────────────────── */
@media (max-width: 768px) {
  .cards {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .card {
    padding: 14px !important;
  }
  .card .value {
    font-size: 20px !important;
  }
  .card .label {
    font-size: 10px !important;
  }
  .card .sub {
    font-size: 11px !important;
  }
}

/* ── Mobile table improvements ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .table-card table {
    font-size: 12px;
  }
  .table-card thead th,
  .table-card tbody td {
    padding: 9px 10px;
  }
}

/* ── Global overflow guard for all pages ────────────────────────────────────── */
/* Prevents any page from being wider than the screen, which causes mobile
   browsers to zoom out and render off-center. */
@media (max-width: 768px) {
  main, header, .sidebar, footer.site-footer {
    max-width: 100vw;
  }
  /* Cards and chart cards must never exceed viewport */
  .card, .chart-card, .table-card {
    max-width: 100%;
    overflow: hidden;
  }
  /* Grids that could overflow on small screens */
  .charts-row {
    grid-template-columns: 1fr !important;
  }
  /* Net worth period bar: hide less-used periods so row doesn't wrap */
  #nw-period-bar [data-period="2y"],
  #nw-period-bar [data-period="3y"] {
    display: none;
  }
}

/* ── Hover glow on interactive cards ────────────────────────────────────────── */
.card {
  transition: box-shadow .25s ease, transform .25s ease;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,.5), 0 0 24px rgba(200,133,58,.07);
}
.chart-card {
  transition: box-shadow .25s ease;
}
.chart-card:hover {
  box-shadow: 0 6px 28px rgba(0,0,0,.4), 0 0 20px rgba(200,133,58,.05);
}

/* ── Button ripple wave ──────────────────────────────────────────────────────── */
@keyframes ripple-out {
  from { transform: scale(0); opacity: .4; }
  to   { transform: scale(3); opacity: 0; }
}
.ripple-wave {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  pointer-events: none;
  animation: ripple-out .52s ease-out forwards;
}

/* ── Table row entrance ──────────────────────────────────────────────────────── */
@keyframes rowSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.row-enter {
  animation: rowSlideIn .22s ease both;
}

/* ── Value flash when data updates ──────────────────────────────────────────── */
@keyframes valPop {
  0%   { opacity: 0; transform: translateY(5px) scale(.95); }
  60%  { opacity: 1; transform: translateY(-1px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.val-flash { animation: valPop .32s ease both; }

/* ── Active filter / period / pag buttons — subtle glow ─────────────────────── */
.filter-btn.active,
.tab-btn.active,
.period-btn.active,
.pag-btn.active,
.nw-period-btn.active {
  box-shadow: 0 0 14px rgba(200,133,58,.3), inset 0 1px rgba(255,255,255,.06);
}

/* ── Input / select focus ring ───────────────────────────────────────────────── */
input:focus,
select:focus,
textarea:focus {
  box-shadow: 0 0 0 2.5px rgba(200,133,58,.2);
}

/* ── Table row hover — warm tint ─────────────────────────────────────────────── */
.table-card tbody tr {
  transition: background .12s ease;
}
.table-card tbody tr:hover {
  background: rgba(200,133,58,.045) !important;
}

/* ── Screener pill active glow ───────────────────────────────────────────────── */
.sc-pill.active {
  box-shadow: 0 0 0 1px rgba(200,133,58,.4) inset, 0 0 14px rgba(200,133,58,.15);
}
.sc-preset.selected {
  box-shadow: 0 0 0 1px rgba(200,133,58,.35) inset;
}

/* ── Sidebar active link accent bar ──────────────────────────────────────────── */
.sidebar-link {
  position: relative;
}
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 2.5px;
  height: 55%;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(200,133,58,.55);
}

/* ── Chart card heading accent dot ───────────────────────────────────────────── */
.chart-card h2::before,
.chart-card h3::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 8px;
  opacity: .75;
  flex-shrink: 0;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ── Card redesign ───────────────────────────────────────────────────────────────
   Uses body-prefixed selectors (specificity 0,1,1) to beat per-page <style>
   blocks (specificity 0,1,0), so we don't have to edit every template.
   Goals: replace flat ambient glow with directional layered shadows;
          add subtle warm gradient so cards feel lit from above;
          kill the generic 3px-left-accent-border pattern.
─────────────────────────────────────────────────────────────────────────────── */

/* Chart cards and table cards — all pages */
body .chart-card,
body .table-card {
  background: linear-gradient(170deg, rgba(255,255,255,.02) 0%, transparent 45%), var(--surface);
  border-top-color: rgba(92,70,44,.6);
}

/* Metric cards — replace 3px left accent with gradient + top-edge emphasis */
body .card {
  background: linear-gradient(155deg, rgba(255,255,255,.02) 0%, transparent 45%), var(--surface);
  border-left-width: 1px;
  border-left-color: var(--border);
  border-top-color: rgba(92,70,44,.6);
}

/* Backtest stat cards */
body .stat-card {
  background: linear-gradient(158deg, rgba(255,255,255,.02) 0%, transparent 45%), var(--surface2);
  border-top-color: rgba(80,62,40,.6);
}

/* Sidebar — restore original shadow */
.sidebar {
  box-shadow: 4px 0 20px rgba(0,0,0,.3);
}
