/* ═══════════════════════════════════════════════════════════
   LAYOUT.CSS — My Financial Picture
   App shell · Sidebar · Main content area
   ═══════════════════════════════════════════════════════════ */

/* ── App root ─────────────────────────────────────────────── */
#app-root {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ── Sidebar (desktop) ────────────────────────────────────── */
#sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .25s;
}
#sidebar.collapsed { width: 60px; }

.sidebar-logo {
  padding: 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.sidebar-logo .logo-text {
  font-weight: 800; font-size: 14px;
  letter-spacing: -.3px;
  white-space: nowrap; overflow: hidden;
}
.collapse-btn {
  margin-left: auto;
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 14px; flex-shrink: 0; padding: 4px;
}

/* ── Nav list inside sidebar ──────────────────────────────── */
#sidebar nav {
  flex: 1;
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px;
  border: none; cursor: pointer; text-align: left;
  width: 100%; font-family: inherit; font-size: 13px; font-weight: 600;
  transition: all .15s;
  background: transparent; color: var(--muted);
  border-left: 2px solid transparent;
  white-space: nowrap; overflow: hidden;
  text-decoration: none; /* anchor fallback */
}
.nav-btn.active {
  background: rgba(0,212,170,.1);
  color: var(--accent);
  border-left-color: var(--accent);
}
.nav-btn:hover:not(.active) {
  background: rgba(255,255,255,.04);
  color: var(--text);
}
.nav-icon  { font-size: 18px; flex-shrink: 0; }
.nav-label { /* stays visible in expanded state */ }

/* ── Sidebar footer (user email + sign-out) ───────────────── */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}

/* ── Collapsed sidebar overrides ──────────────────────────── */
#sidebar.collapsed .logo-text,
#sidebar.collapsed .nav-label,
#sidebar.collapsed .sidebar-footer { display: none; }
#sidebar.collapsed .logo-icon       { display: none; }
#sidebar.collapsed .sidebar-logo   { justify-content: center; padding: 14px 8px; }
#sidebar.collapsed .collapse-btn   { margin-left: 0; }
#sidebar.collapsed .nav-btn        { justify-content: center; padding: 10px 0; }
#sidebar.collapsed .nav-icon       { font-size: 20px; }

/* ── Main content area ────────────────────────────────────── */
#main {
  flex: 1;
  padding: 28px 24px;
  overflow-y: auto;
  overflow-x: hidden;
}
.page-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Login screen ─────────────────────────────────────────── */
#login-screen {
  display: none;
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 9999;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 24px;
}
.login-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #00D4AA, #3B82F6);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; margin: 0 auto 16px;
}
.login-title { font-size: 26px; font-weight: 800; color: var(--text); }
.login-sub   { font-size: 14px; color: var(--muted); margin-top: 6px; }
.login-google-btn {
  display: flex; align-items: center; gap: 12px;
  background: #fff; color: #222;
  border: none; border-radius: 12px;
  padding: 14px 28px; font-size: 15px; font-weight: 600;
  cursor: pointer; box-shadow: 0 2px 12px rgba(0,0,0,.3);
}
#login-error { color: var(--neg); font-size: 13px; min-height: 20px; }
.local-mode-notice {
  background: rgba(245,158,11,.12);
  border: 1px solid rgba(245,158,11,.3);
  border-radius: 12px; padding: 14px 20px;
  text-align: center; max-width: 320px;
}
.local-mode-notice-title { font-size: 13px; font-weight: 700; color: var(--accent3); margin-bottom: 6px; }
.local-mode-notice-body  { font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ═══════════════════════════════════════════════════════════
   MOBILE — left icon sidebar (≤700px)
   ═══════════════════════════════════════════════════════════ */

#mobile-nav { display: none; }

@media (max-width: 1100px) {
  #dash-stats        { grid-template-columns: repeat(3, 1fr) !important; }
  #dash-credit-cards { grid-template-columns: repeat(3, 1fr) !important; }
}

@media (max-width: 700px) {
  /* Hide desktop sidebar entirely */
  #sidebar { display: none !important; }

  /* App root is a row: mobile-nav on left, main on right */
  #app-root { display: flex !important; flex-direction: row; min-height: 100vh; }

  /* Mobile left nav */
  #mobile-nav {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 54px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 9000;
    overflow-y: auto; overflow-x: hidden;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
    -webkit-overflow-scrolling: touch;
  }
  #mobile-nav::-webkit-scrollbar { display: none; }

  /* Main content pushed right of the mobile nav */
  #main {
    margin-left: 54px;
    padding: 14px 12px 24px;
    width: calc(100% - 54px);
    box-sizing: border-box;
    min-height: 100vh;
    overflow-y: auto;
  }

  /* Page title smaller */
  .page-title { font-size: 19px; }
  .page-sub   { font-size: 12px; }
  .page-header { gap: 8px; }
  .page-header .btn-row { width: 100%; justify-content: flex-start; }

  /* Stat grid: 2 cols on mobile */
  .stat-grid         { grid-template-columns: 1fr 1fr; gap: 10px; }
  #dash-stats        { grid-template-columns: 1fr 1fr !important; }
  #dash-credit-cards { grid-template-columns: 1fr 1fr !important; }
  #summary-expense-grid { grid-template-columns: 1fr 1fr !important; }
  .stat-card  { padding: 14px; }
  .stat-value { font-size: 17px; }
  .stat-label { font-size: 10px; }

  /* Cards */
  .card       { padding: 14px; border-radius: 12px; }
  .card-title { font-size: 14px; margin-bottom: 12px; }

  /* Forms: single column */
  .form-grid                    { grid-template-columns: 1fr; }
  .form-input, .form-select, .inp { font-size: 16px; padding: 10px 12px; } /* 16px stops iOS zoom */

  /* Buttons: larger tap targets */
  .btn    { padding: 9px 14px; font-size: 13px; }
  .btn-sm { padding: 7px 12px; font-size: 12px; }
  .btn-row { flex-wrap: wrap; gap: 6px; }

  /* Tables: horizontal scroll with momentum */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; min-width: 420px; }
  th { padding: 9px 10px; font-size: 10px; }
  td { padding: 8px 10px; }

  /* Charts */
  .chart-grid { grid-template-columns: 1fr; }
  .chart-wrap { height: 220px !important; }

  /* Modals: slide up from bottom */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box {
    max-width: 100% !important; width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    border-left: none; border-right: none; border-bottom: none;
  }
  .modal-body   { padding: 16px; }
  .modal-head   { padding: 14px 16px; }
  .modal-footer { padding: 0 16px 16px; margin-top: 12px; }

  /* Net worth banner: stack */
  #nw-total-breakdown { justify-content: flex-start; gap: 16px; }
  #nw-goals           { grid-template-columns: 1fr !important; }
  #nw-charts-row      { grid-template-columns: 1fr !important; }

  /* Cash flow: single col */
  #cf-two-col { grid-template-columns: 1fr !important; }

  /* Misc */
  .search-row { flex-wrap: wrap; }
  .calc-box   { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ── Mobile nav buttons ────────────────────────────────────── */
.m-nav-btn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; width: 100%;
  padding: 12px 4px;
  background: none; border: none;
  border-left: 2px solid transparent;
  cursor: pointer; color: var(--muted);
  font-family: inherit; font-size: 9px; font-weight: 600;
  transition: all .15s; white-space: nowrap;
  flex-shrink: 0; text-decoration: none;
}
.m-nav-btn.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(0,212,170,.08);
}
.m-nav-btn:hover:not(.active) {
  color: var(--text);
  background: rgba(255,255,255,.04);
}
.m-nav-icon { font-size: 20px; line-height: 1; display: block; }

.m-nav-logo {
  display: flex; align-items: center; justify-content: center;
  padding: 12px 0 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px; flex-shrink: 0;
}
.m-nav-signout {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 4px; flex-shrink: 0;
}
