/* ── Base ──────────────────────────────────────────────────── */
html, body {
  height: 100%;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app { display: none; }
#app.auth-ready { display: flex; flex-direction: column; min-height: 100vh; }

/* ── Header ─────────────────────────────────────────────────── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 200;
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ── Stats bar ──────────────────────────────────────────────── */
#stats-bar {
  position: sticky;
  top: 52px;
  z-index: 199;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 34px;
  display: flex;
  align-items: center;
}

#stats-bar #header-stats {
  display: flex;
  gap: 4px;
  align-items: center;
}

#stats-bar .stat-chip {
  padding: 3px 10px;
  font-size: 11px;
  background: var(--bg-surface);
}

#stats-bar .stat-chip-label {
  font-size: 10px;
}

#stats-bar .stat-chip-value {
  font-size: 11px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 32px;
  flex-shrink: 0;
}

.brand-link {
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
  white-space: nowrap;
}
.brand-dot { color: var(--text-faint); font-weight: 400; }

/* ── Top Nav ────────────────────────────────────────────────── */
#top-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nav-tab {
  padding: 6px 14px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.12s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}

.nav-tab:hover { background: var(--bg-elevated); color: var(--text-primary); }

.nav-tab.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

.nav-chevron {
  font-size: 10px;
  transition: transform 0.15s ease;
}

.nav-tab.open .nav-chevron { transform: rotate(180deg); }

/* ── Finances dropdown ──────────────────────────────────────── */
.nav-dropdown-wrap { position: relative; }

.nav-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.10);
  min-width: 180px;
  padding: 4px;
  display: none;
  z-index: 300;
}

.nav-dropdown.open { display: block; }

.nav-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.nav-dropdown-item:hover { background: var(--bg-elevated); color: var(--primary); }

/* ── Header stats (now in stats bar) ────────────────────────── */

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.stat-chip-label {
  font-size: 11px;
  color: var(--text-faint);
  font-weight: 500;
}

.stat-chip-value {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ── Header right ───────────────────────────────────────────── */
.header-right {
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.save-plan-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.save-plan-btn:hover { background: var(--primary-dark); }

/* ── Main content ───────────────────────────────────────────── */
#main-content {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px 48px;
  box-sizing: border-box;
}

/* ── Tab panels ─────────────────────────────────────────────── */
.tab-panel { display: block; }
.tab-panel.hidden { display: none !important; }

/* ── Finance sections ───────────────────────────────────────── */
.finance-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  overflow: hidden;
}

.finance-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.finance-section-header:hover { background: var(--bg-elevated); }
.finance-section.open .finance-section-header { background: var(--bg-elevated); }

.fs-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fs-icon { font-size: 13px; color: var(--text-faint); }

.fs-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.fs-summary {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}

.fs-chevron {
  font-size: 11px;
  color: var(--text-faint);
  transition: transform 0.18s;
}

.finance-section.open .fs-chevron { transform: rotate(180deg); }

.finance-section-body {
  border-top: 1px solid var(--border);
  padding: 20px;
}

.finance-section-body.collapsed { display: none; }

/* ── Ad slots ───────────────────────────────────────────────── */
.ad-slot-top {
  margin-bottom: 20px;
}

.ad-slot-content {
  margin: 24px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
}

.ad-label {
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-faint);
  text-align: center;
  padding: 4px 0;
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  padding: 36px 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  background: none; border: none;
  font-size: 16px; color: var(--text-faint);
  cursor: pointer; padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--bg-elevated); color: var(--text-primary); }

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.modal-form { display: flex; flex-direction: column; gap: 10px; }

.modal-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-surface);
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}
.modal-input:focus { border-color: var(--primary); }

.modal-submit-btn {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s;
}
.modal-submit-btn:hover { background: var(--primary-dark); }

.modal-disclaimer { font-size: 11px; color: var(--text-faint); margin-top: 10px; }
.modal-success.hidden { display: none; }
.modal-error.hidden   { display: none; }

/* ── Footer ─────────────────────────────────────────────────── */
#app-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  background: var(--bg-surface);
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-faint);
}

.footer-brand { font-weight: 700; color: var(--text-muted); }
.footer-sep { color: var(--border-mid); }
.footer-inner a { color: var(--text-muted); text-decoration: none; }
.footer-inner a:hover { color: var(--primary); }
.footer-disc { font-size: 11px; }

.footer-disclaimer {
  max-width: 960px;
  margin: 10px auto 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

/* ── Bottom nav stub (unused — keeps tab modules happy) ─────── */
--bottom-nav-height: 0px;
#bottom-nav { display: none; }
#app-main { margin-top: 0; padding: 0; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 14px;
}

/* ── Logo image ─────────────────────────────────────────────── */
.brand-logo-img {
  height: 36px;
  width: auto;
  display: block;
}

.brand-link {
  display: flex;
  align-items: center;
}

/* ── Export button ───────────────────────────────────────────── */
.btn-export {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.btn-export:hover { background: var(--border); color: var(--text-primary); }

.export-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.10);
  min-width: 160px;
  padding: 4px;
  z-index: 400;
}

.export-dropdown.hidden { display: none; }

.export-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.export-option:hover { background: var(--bg-elevated); color: var(--primary); }

/* ── Ghost header buttons ────────────────────────────────────── */
.header-ghost-btn {
  padding: 6px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}

.header-ghost-btn:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-mid); }

/* ── Dashboard grid utility ─────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
/* Cards inside a grid row don't need their own bottom margin — the grid handles spacing */
.grid-2 > .card {
  margin-bottom: 0;
}

/* ════════════════════════════════════════════════════════════
   MOBILE & TABLET RESPONSIVE — < 1024px
════════════════════════════════════════════════════════════ */

/* ── Bottom tab bar (mobile only) ───────────────────────────── */
#bottom-tab-bar {
  display: none; /* hidden on desktop */
}

@media (max-width: 1023px) {

  /* Hide desktop top nav links and action buttons */
  #top-nav { display: none; }
  .header-ghost-btn { display: none; }
  #export-slot-dashboard { display: none; }

  /* Slim header — just logo + save */
  #app-header {
    padding: 0 16px;
    height: 48px;
  }

  .header-left { gap: 0; }
  .brand-logo-img { height: 30px; }

  .save-plan-btn {
    padding: 6px 12px;
    font-size: 12px;
  }

  /* Stats bar — show only 2 key stats */
  #stats-bar {
    padding: 0 16px;
    height: 30px;
    top: 48px;
  }

  #stats-bar .stat-chip:nth-child(n+3) { display: none; }

  /* Main content — full width, bottom padding for tab bar */
  #main-content {
    padding: 16px 16px 80px;
    max-width: 100%;
  }

  /* Finance sections — full width */
  .finance-section { border-radius: 8px; }
  .finance-section-header { padding: 12px 16px; }
  .finance-section-body { padding: 16px; }

  /* Cards — tighter on mobile */
  .card { padding: 16px; }

  /* Modals go full-screen from bottom */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    width: 100%;
    padding: 28px 24px 40px;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Bottom sheets stay bottom sheets */
  .bottom-sheet {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(100%);
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
  }
  .bottom-sheet.visible { transform: translateY(0); }

  /* Bottom tab bar — show on mobile */
  #bottom-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
  }

  .bottom-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: none;
    font-family: var(--font-sans);
    color: var(--text-faint);
    cursor: pointer;
    padding: 6px 4px;
    transition: color 0.12s;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-tab.active { color: var(--primary); }

  .bottom-tab-icon {
    font-size: 18px;
    line-height: 1;
  }

  .bottom-tab-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.2px;
    white-space: nowrap;
  }

  /* Finances sub-menu sheet */
  #finances-sheet {
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    z-index: 299;
    padding: 12px 8px 8px;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.10);
    display: none;
  }

  #finances-sheet.open { display: block; }

  .finances-sheet-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 0 8px 8px;
  }

  .finances-sheet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .finances-sheet-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border: none;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .finances-sheet-item:active { background: var(--primary-light); color: var(--primary); }

  /* Wizard — single column on mobile */
  #wizard-box { max-width: 100%; border-radius: 16px 16px 0 0; }
  #wizard-overlay { align-items: flex-end; }

  /* Plan health checklist — tighter */
  #plan-health-card { padding: 16px; }

  /* Export slot in monte carlo tab */
  #export-slot-monte { display: flex; }

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

  /* Stat grid — 2 col on mobile */
  .grid-5 { grid-template-columns: 1fr 1fr !important; }
  .grid-2 { grid-template-columns: 1fr !important; }
}

/* ── Tablet adjustments 640–1023px ──────────────────────────── */
@media (min-width: 640px) and (max-width: 1023px) {
  #main-content { padding: 20px 24px 80px; }
  .finances-sheet-grid { grid-template-columns: repeat(3, 1fr); }
  #stats-bar .stat-chip:nth-child(n+3) { display: flex; }
  #stats-bar .stat-chip:nth-child(n+4) { display: none; }
}

/* ── Touch-friendly tap targets ─────────────────────────────── */
@media (max-width: 1023px) {
  button, select, input[type="checkbox"], input[type="radio"] {
    min-height: 40px;
  }
  .nav-dropdown-item, .bottom-tab, .finances-sheet-item {
    min-height: 44px;
  }

  /* Prevent iOS auto-zoom on input focus (triggers when font-size < 16px) */
  input, select, textarea {
    font-size: 16px !important;
  }
}
