/* ===================================================
   JENTRAX — MAIN STYLES
   Layout, CSS variables, responsive grid, navigation
   =================================================== */

/* ── CSS Custom Properties ── */
:root {
  /* Brand */
  --color-primary:        #6C63FF;
  --color-primary-dark:   #5750d4;
  --color-primary-light:  #ede9ff;

  /* Semantic */
  --color-income:         #22c55e;
  --color-income-bg:      #f0fdf4;
  --color-expense:        #ef4444;
  --color-expense-bg:     #fef2f2;
  --color-warning:        #f59e0b;
  --color-warning-bg:     #fffbeb;
  --color-danger:         #dc2626;
  --color-danger-dark:    #b91c1c;
  --color-success:        #16a34a;

  /* Neutrals */
  --color-bg:             #f1f5f9;
  --color-surface:        #ffffff;
  --color-border:         #e2e8f0;
  --color-text:           #0f172a;
  --color-text-muted:     #64748b;
  --color-text-faint:     #94a3b8;

  /* Typography */
  --font-sans: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Courier New', monospace;

  /* Spacing */
  --space-xs:   4px;
  --space-sm:   8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;
  --space-2xl: 48px;

  /* Radii */
  --radius-sm:   6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.10), 0 4px 12px rgba(0,0,0,.06);

  /* Header */
  --header-height: 64px;
}

/* ── Dark Mode ── */
[data-theme="dark"] {
  --color-primary-light:  #2d2a5e;

  --color-income-bg:      #0a2e1a;
  --color-expense-bg:     #2e0a0a;
  --color-warning-bg:     #2e2505;

  --color-bg:             #0f172a;
  --color-surface:        #1e293b;
  --color-border:         #334155;
  --color-text:           #f1f5f9;
  --color-text-muted:     #94a3b8;
  --color-text-faint:     #64748b;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.15);
  --shadow-md:  0 4px 12px rgba(0,0,0,.3), 0 2px 6px rgba(0,0,0,.2);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.25);
}

[data-theme="dark"] .modal::backdrop {
  background: rgba(0,0,0,.6);
}

[data-theme="dark"] .warning-banner--warning {
  color: #fbbf24;
}

[data-theme="dark"] .warning-banner--danger {
  color: #fca5a5;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  line-height: 1.25;
  font-weight: 600;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

img, svg {
  display: block;
  max-width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ── App Header (Premium) ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: none;
  box-shadow: var(--shadow-md);
}

.app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #6C63FF, #3b82f6, #22c55e, #f59e0b, #ec4899);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  height: 100%;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  overflow: hidden;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-text);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Navigation ── */
.app-nav {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex: 1;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

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

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.nav-link.active {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

/* ── App Layout (side panel + main) ── */
.app-layout {
  display: flex;
  min-height: calc(100vh - var(--header-height));
  overflow-x: hidden;
  max-width: 100vw;
}

.app-layout .app-main {
  flex: 1;
  min-width: 0;
  transition: margin-left 0.3s cubic-bezier(.4,0,.2,1);
}

/* ── Side Panel ── */
.side-panel {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: 380px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 90;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
}

.side-panel.open {
  transform: translateX(0);
}

.app-layout.panel-open .app-main {
  margin-left: 380px;
}

.side-panel__inner {
  padding: var(--space-xl);
}

.side-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--color-primary);
}

.side-panel__title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
}

.side-panel__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

/* ── Main Content ── */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

/* ── Sections ── */
.section {
  animation: fadeIn 0.2s ease;
  max-width: 100%;
  overflow-x: hidden;
}

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

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.section-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-text);
}

/* ── Month Navigation ── */
.month-nav {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-xs) var(--space-sm);
  box-shadow: var(--shadow-sm);
}

.month-label {
  font-weight: 600;
  font-size: 0.875rem;
  min-width: 7rem;
  text-align: center;
}

/* ── Stats Grid (Dashboard) ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

/* ── Charts Grid ── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.chart-card--full {
  margin-bottom: var(--space-lg);
  max-width: 100%;
}

/* ── Filter Bar (Transactions) ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-bottom: var(--space-lg);
}

.filter-group {
  display: flex;
  gap: var(--space-xs);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 3px;
}

.filter-select-wrap {
  flex-shrink: 0;
}

/* ── Categories Grid ── */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: var(--space-lg);
}

/* ── Settings Layout ── */
.settings-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

/* ── Budget Warnings ── */
.budget-warnings {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

/* ── Empty States ── */
.empty-state {
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  font-size: 0.9375rem;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .settings-layout {
    grid-template-columns: 1fr;
  }
  /* Side panel overlays instead of pushing on tablets */
  .app-layout.panel-open .app-main {
    margin-left: 0;
  }
  .side-panel.open + .app-main::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.35);
    backdrop-filter: blur(2px);
    z-index: 80;
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 52px;
  }

  .app-main {
    padding: var(--space-lg) var(--space-md);
    padding-bottom: 80px; /* space for bottom nav */
  }

  .header-inner {
    padding: 0 var(--space-md);
    gap: var(--space-sm);
  }

  .app-logo span {
    display: none;
  }

  /* ── Bottom Tab Bar Navigation ── */
  .app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 12px rgba(0,0,0,.08);
    display: flex;
    justify-content: flex-start;
    align-items: stretch;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: none;
    scrollbar-width: none;
    padding: var(--space-xs) var(--space-xs);
    padding-bottom: calc(var(--space-xs) + env(safe-area-inset-bottom, 0px));
    flex: none;
  }

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

  .nav-link {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xs) var(--space-sm);
    min-width: 64px;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    text-align: center;
    line-height: 1.2;
    gap: 2px;
  }

  .nav-link.active {
    background: var(--color-primary);
    color: #fff;
  }

  /* ── Add Transaction button compact ── */
  #btn-add-transaction span {
    display: none;
  }

  #btn-add-transaction {
    padding: 6px 10px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .section-header {
    margin-bottom: var(--space-lg);
  }

  .section-title {
    font-size: 1.25rem;
  }

  .side-panel {
    width: 100%;
    padding-bottom: 72px; /* space for bottom nav */
  }

  /* ── Filter bar stacking ── */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-wrap {
    max-width: 100%;
    min-width: 0;
  }

  .filter-group {
    width: 100%;
    justify-content: center;
  }

  .filter-select-wrap {
    width: 100%;
  }

  .filter-select-wrap .select {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .app-main {
    padding: var(--space-md) var(--space-sm);
    padding-bottom: 80px;
  }

  .header-inner {
    padding: 0 var(--space-sm);
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
  }

  .filter-bar {
    gap: var(--space-sm);
  }

  .categories-grid {
    grid-template-columns: 1fr;
  }

  /* Section header stacks vertically */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .section-title {
    font-size: 1.125rem;
  }

  .month-nav {
    align-self: stretch;
    justify-content: center;
  }
}
