/**
 * ADHD Budget Planner - Mobile-First Core Design System & Neurodivergent Styling
 * Engineered primarily for native-like mobile UX, responsive on desktop.
 */

/* --- 1. CSS Custom Properties & Palettes --- */
:root {
  /* Sage Calm (Default Theme) */
  --bg-app: #f4f7f5;
  --surface-card: #ffffff;
  --surface-hover: #eef3f0;
  --surface-active: #e2ece6;
  --border-subtle: #d6e2dc;
  --border-strong: #9ab4a7;
  
  --text-main: #192b23;
  --text-muted: #536b60;
  --text-dim: #7f978d;

  --accent-primary: #1b6a50;
  --accent-light: #e1f4ec;
  --accent-vivid: #10b981;
  --accent-gold: #d97706;
  --accent-warn: #e11d48;
  --accent-info: #0284c7;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(18, 38, 29, 0.05);
  --shadow-card: 0 4px 14px -2px rgba(18, 38, 29, 0.06), 0 2px 4px -1px rgba(18, 38, 29, 0.03);
  --shadow-modal: 0 20px 30px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.08);

  --nav-height: 60px;
}

/* Theme 2: OLED Dark */
[data-theme="oled-dark"] {
  --bg-app: #080d0b;
  --surface-card: #111a16;
  --surface-hover: #192520;
  --surface-active: #22322c;
  --border-subtle: #1c2e26;
  --border-strong: #2e4a3e;

  --text-main: #e2ece7;
  --text-muted: #8ba599;
  --text-dim: #556e62;

  --accent-primary: #34d399;
  --accent-light: #113628;
  --accent-vivid: #10b981;
  --accent-gold: #f59e0b;
  --accent-warn: #f43f5e;
  --accent-info: #38bdf8;

  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Theme 3: Warm Earth */
[data-theme="warm-earth"] {
  --bg-app: #fcf9f5;
  --surface-card: #ffffff;
  --surface-hover: #f5eee4;
  --surface-active: #ebdfd0;
  --border-subtle: #e4d8c8;
  --border-strong: #bda691;

  --text-main: #2b231d;
  --text-muted: #6e5e52;
  --text-dim: #998779;

  --accent-primary: #8c4a27;
  --accent-light: #f7ebe4;
  --accent-vivid: #c25e2e;
  --accent-gold: #b45309;
  --accent-warn: #be123c;
  --accent-info: #0369a1;
}

/* Theme 4: High Contrast */
[data-theme="high-contrast"] {
  --bg-app: #ffffff;
  --surface-card: #ffffff;
  --surface-hover: #f0f0f0;
  --surface-active: #e4e4e4;
  --border-subtle: #000000;
  --border-strong: #000000;

  --text-main: #000000;
  --text-muted: #222222;
  --text-dim: #444444;

  --accent-primary: #000000;
  --accent-light: #eeeeee;
  --accent-vivid: #0066cc;
  --accent-gold: #cc6600;
  --accent-warn: #cc0000;
  --accent-info: #0066cc;
}

/* --- 2. Base Reset & Mobile Typography --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 16px;
  min-height: 100%;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
  touch-action: manipulation;
}

/* --- 3. App Shell Layout (Mobile-First) --- */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  width: 100%;
}

/* Navigation: Mobile-First Bottom Dock (Fluid across all mobile resolutions from 320px to 1080x2400) */
.nav-dock {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  background: var(--surface-card);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  z-index: 50;
  padding: 2px 4px env(safe-area-inset-bottom, 0px) 4px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
}

.nav-dock::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-width: 44px;
  height: 50px;
  color: var(--text-muted);
  font-size: clamp(9.5px, 2.4vw, 12px);
  font-weight: 600;
  gap: 2px;
  padding: 2px 2px;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  text-align: center;
}

.nav-tab svg {
  width: clamp(18px, 4.5vw, 22px);
  height: clamp(18px, 4.5vw, 22px);
  stroke-width: 2;
  flex-shrink: 0;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-tab span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.1;
}

.nav-tab:active {
  transform: scale(0.92);
}

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

.nav-tab.active svg {
  transform: translateY(-1px);
}

/* Main Content Area (Mobile-First) */
.main-wrapper {
  flex: 1;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top, 0px)) 16px calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 24px) 16px;
  box-sizing: border-box;
}

/* Desktop Sidebar Expansion: Only activates on wide landscape displays (Laptops & Desktops) */
@media (min-width: 960px) and (orientation: landscape) {
  .app-container {
    flex-direction: row;
  }
  .nav-dock {
    position: sticky;
    top: 0;
    left: 0;
    width: 230px;
    height: 100vh;
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    border-top: none;
    border-right: 1px solid var(--border-subtle);
    padding: 24px 14px;
    gap: 6px;
    overflow-x: visible;
    overflow-y: auto;
    box-shadow: none;
  }
  .nav-tab {
    flex-direction: row;
    justify-content: flex-start;
    flex: none;
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border-radius: var(--radius-md);
    gap: 12px;
    font-size: 14px;
  }
  .nav-tab svg {
    width: 22px;
    height: 22px;
  }
  .nav-tab:hover {
    background: var(--surface-hover);
  }
  .nav-tab.active {
    background: var(--accent-light);
  }
  .main-wrapper {
    max-width: 760px;
    padding: 28px 28px 48px 28px;
  }
}

/* --- 4. Top Header & App Bar (Mobile-First) --- */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-app);
  padding: 6px 0 10px 0;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-main);
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-text-full {
  display: none;
}

.btn-text-short {
  display: inline;
}

@media (min-width: 640px) {
  .btn-text-full {
    display: inline;
  }
  .btn-text-short {
    display: none;
  }
  .brand-icon {
    width: 36px;
    height: 36px;
  }
  .brand-title {
    font-size: 20px;
  }
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  min-height: 36px;
  border-radius: var(--radius-full);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.btn-pill:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-pill:active {
  transform: scale(0.96);
}

.btn-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

/* Persona Demo Notification Banner */
.demo-banner {
  background: var(--accent-light);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-main);
}

.demo-banner-actions {
  display: flex;
  gap: 6px;
}

/* --- 5. Screen Containers & Transitions --- */
.screen {
  display: none;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- 6. The "Today" Hero Screen Components (Mobile-First) --- */
.hero-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  margin-bottom: 16px;
}

.hero-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.eyebrow-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  color: var(--text-dim);
}

.help-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--surface-hover);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.help-badge:hover {
  background: var(--accent-light);
  color: var(--accent-primary);
}

.hero-number-wrap {
  margin: 10px 0 14px 0;
}

.hero-number {
  font-size: clamp(38px, 11vw, 56px);
  font-weight: 800;
  letter-spacing: -1.2px;
  color: var(--text-main);
  line-height: 1.05;
}

.hero-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* Paycheck Runway Progress Bar */
.runway-wrapper {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--surface-hover);
  border-radius: var(--radius-md);
}

.runway-header {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 6px;
}

.runway-track {
  height: 8px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.runway-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-vivid), var(--accent-primary));
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* Hero Quick Stats (Mobile 3-Column Grid) */
.hero-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Quick Log Shortcuts (Mobile-First 4-Column Grid) */
.quick-log-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.btn-quick {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 4px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  -webkit-user-select: none;
}

.btn-quick:active {
  transform: scale(0.93);
}

.btn-quick:hover {
  background: var(--surface-hover);
  border-color: var(--accent-primary);
}

.btn-quick-icon {
  font-size: 20px;
  line-height: 1;
}

.btn-quick-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.btn-quick-price {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
}

/* --- 7. Three Small Quests (ADHD Daily Quest Checklist) --- */
.quests-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow-card);
  margin-bottom: 16px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.quest-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-hover);
  margin-bottom: 8px;
  min-height: 52px;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.quest-item.done {
  opacity: 0.65;
  background: transparent;
  border: 1px dashed var(--border-strong);
}

.quest-checkbox {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-card);
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.quest-checkbox.checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.quest-text-wrap {
  flex: 1;
  min-width: 0;
}

.quest-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
}

.quest-item.done .quest-title {
  text-decoration: line-through;
}

.quest-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* --- 8. 48-Hour Impulse Vault Feature --- */
.vault-teaser {
  background: linear-gradient(135deg, var(--surface-card) 0%, var(--surface-hover) 100%);
  border: 1px dashed var(--accent-gold);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.vault-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.vault-badge-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent-gold);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* --- 9. Zombie Mode Styling (Low Energy Override) --- */
body.zombie-mode-active .nav-dock,
body.zombie-mode-active .quests-card,
body.zombie-mode-active .vault-teaser,
body.zombie-mode-active .quick-log-grid,
body.zombie-mode-active .top-header .brand-title {
  display: none !important;
}

body.zombie-mode-active .hero-card {
  padding: 36px 20px;
  text-align: center;
  border-color: var(--accent-primary);
}

body.zombie-mode-active .hero-stats-row {
  display: none;
}

.zombie-widget {
  display: none;
  background: var(--surface-card);
  border: 2px solid var(--accent-primary);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 16px;
  text-align: center;
}

body.zombie-mode-active .zombie-widget {
  display: block;
}

/* --- 10. Forms, Modals & Native Mobile Bottom Sheets --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9500;
  display: flex;
  align-items: flex-end; /* Native bottom sheet on mobile! */
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-modal);
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom, 0px)) 20px;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Native Pull Bar Grab Indicator on Mobile */
.modal-dialog::before {
  content: '';
  display: block;
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: var(--border-strong);
  margin: 0 auto 16px auto;
  opacity: 0.6;
}

.modal-overlay.open .modal-dialog {
  transform: translateY(0);
}

/* Desktop Centered Modal Expansion: Only on wide landscape screens */
@media (min-width: 768px) and (orientation: landscape) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }
  .modal-dialog {
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border-subtle);
    max-width: 480px;
    max-height: 90vh;
    padding: 24px;
    transform: translateY(20px) scale(0.96);
  }
  .modal-dialog::before {
    display: none;
  }
  .modal-overlay.open .modal-dialog {
    transform: translateY(0) scale(1);
  }
}

.input-group {
  margin-bottom: 14px;
}

.input-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.input-field {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-app);
  color: var(--text-main);
  font-size: 16px; /* 16px prevents iOS Safari auto-zoom! */
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-field:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.btn-primary {
  width: 100%;
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--accent-primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.btn-primary:active {
  transform: scale(0.97);
}

/* Contextual Help Accordion */
.help-tier {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
}

.help-tier-title {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.help-tier-body {
  font-size: 13.5px;
  color: var(--text-main);
  line-height: 1.4;
}

/* Reduced Motion Override for Accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
