/* ===== CSS VARIABLES & THEMES ===== */
:root {
  /* Brand Colors */
  --color-primary: #1565C0;
  --color-primary-dark: #0D47A1;
  --color-primary-light: #1976D2;
  --color-primary-pale: #E3F2FD;
  --color-secondary: #F57C00;
  --color-secondary-dark: #E65100;
  --color-secondary-light: #FF9800;
  --color-secondary-pale: #FFF3E0;

  /* Semantic Colors */
  --color-success: #2E7D32;
  --color-success-bg: #E8F5E9;
  --color-danger: #C62828;
  --color-danger-bg: #FFEBEE;
  --color-warning: #F57F17;
  --color-warning-bg: #FFFDE7;
  --color-info: #0277BD;
  --color-info-bg: #E1F5FE;

  /* Light Theme */
  --bg-main: #F5F7FA;
  --bg-surface: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-sidebar: #FFFFFF;
  --bg-header: #1565C0;
  --bg-overlay: rgba(0,0,0,0.5);
  --bg-input: #FFFFFF;
  --bg-muted: #F0F2F5;

  /* Text */
  --text-primary: #1A1A2E;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --text-on-primary: #FFFFFF;
  --text-on-secondary: #FFFFFF;
  --text-link: #1565C0;

  /* Borders */
  --border: #E2E8F0;
  --border-focus: #1565C0;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;
  --border-radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 16px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.06);
  --shadow-lg: 0 20px 40px rgba(0,0,0,0.1), 0 8px 16px rgba(0,0,0,0.06);
  --shadow-primary: 0 4px 14px rgba(21,101,192,0.3);
  --shadow-secondary: 0 4px 14px rgba(245,124,0,0.3);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-base: 14px;
  --font-size-md: 15px;
  --font-size-lg: 16px;
  --font-size-xl: 18px;
  --font-size-2xl: 22px;
  --font-size-3xl: 28px;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --line-height: 1.5;

  /* Transitions */
  --transition: 0.2s ease;
  --transition-slow: 0.3s ease;

  /* Layout */
  --header-height: 56px;
  --nav-height: 60px;
  --sidebar-width: 240px;
}

[data-theme="dark"] {
  --bg-main: #0F172A;
  --bg-surface: #1E293B;
  --bg-card: #1E293B;
  --bg-sidebar: #1E293B;
  --bg-header: #0D47A1;
  --bg-input: #263549;
  --bg-muted: #1A2944;

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --text-link: #60A5FA;

  --border: #334155;
  --border-focus: #60A5FA;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 4px 6px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 16px rgba(0,0,0,0.35);
  --shadow-lg: 0 20px 40px rgba(0,0,0,0.4);
  --shadow-primary: 0 4px 14px rgba(21,101,192,0.5);

  --color-primary-pale: #1E3A5F;
  --color-secondary-pale: #3D2B00;
  --color-success-bg: #1B3A1D;
  --color-danger-bg: #3D1515;
  --color-warning-bg: #3D2E00;
  --color-info-bg: #1A334D;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background: var(--bg-main);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition-slow), color var(--transition-slow);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text-link); text-decoration: none; }
img { max-width: 100%; height: auto; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ===== SVG ICONS ===== */
.icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  vertical-align: middle;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; }

/* ===== LAYOUT ===== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page { display: none; }
.page.active { display: flex; flex-direction: column; flex: 1; }

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-header);
  color: var(--text-on-primary);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.app-header .logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: white;
}

.app-header .logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
}

.header-title {
  flex: 1;
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  text-align: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.header-btn {
  background: transparent;
  border: none;
  color: white;
  padding: var(--space-2);
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background var(--transition);
}

.header-btn:hover, .header-btn:active {
  background: rgba(255,255,255,0.15);
}

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: var(--color-secondary);
  border-radius: 50%;
  border: 1.5px solid var(--bg-header);
}

/* ===== BOTTOM NAVIGATION ===== */
.app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: var(--font-weight-medium);
  padding: var(--space-1) var(--space-2);
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.nav-item.active {
  color: var(--color-primary);
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--color-primary);
  border-radius: 3px 3px 0 0;
}

.nav-item .icon { width: 22px; height: 22px; }

/* ===== MAIN CONTENT ===== */
.content-area {
  flex: 1;
  padding-top: calc(var(--header-height) + var(--space-4));
  padding-bottom: calc(var(--nav-height) + var(--space-4));
  padding-left: var(--space-4);
  padding-right: var(--space-4);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

/* ===== AUTH PAGES ===== */

/* Brand panel: oculto no mobile */
.auth-brand-panel { display: none; }

/* Form panel: tela cheia no mobile com gradiente */
.auth-form-panel {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 55%, #122d5c 100%);
}

.auth-screen { width: 100%; max-width: 420px; }

.auth-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(0,0,0,0.22);
}

.auth-logo { text-align: center; margin-bottom: 24px; }

.auth-logo img {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: 0 4px 16px rgba(21,101,192,0.3);
  margin-bottom: 12px;
}

.auth-logo h1 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary);
}

.auth-logo p { font-size: var(--font-size-sm); color: var(--text-secondary); margin-top: 2px; }

/* ===== DESKTOP AUTH: painel esquerdo fixo + formulário metade direita ===== */
@media (min-width: 1024px) {
  /* Painel de marca: position:fixed cobre metade esquerda — independe do display pai */
  .auth-brand-panel {
    display: flex;
    position: fixed;
    left: 0; top: 0;
    width: 50%;
    height: 100vh;
    background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 55%, #122d5c 100%);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 48px;
    z-index: 1;
    color: white;
    text-align: center;
  }

  .auth-brand-logo {
    width: 96px; height: 96px;
    border-radius: 24px;
    object-fit: cover;
    box-shadow: 0 8px 32px rgba(0,0,0,0.35);
    margin-bottom: 24px;
  }

  .auth-brand-title { font-size: 36px; font-weight: 800; color: white; margin-bottom: 12px; }

  .auth-brand-sub {
    font-size: 15px; opacity: 0.82; line-height: 1.7;
    margin-bottom: 40px; max-width: 300px;
  }

  .auth-brand-features { list-style: none; padding: 0; margin: 0; width: 100%; max-width: 280px; }

  .auth-brand-features li {
    padding: 11px 0;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    font-size: 14px; opacity: 0.88;
    display: flex; align-items: center; gap: 10px; text-align: left;
  }

  .auth-brand-features li::before {
    content: '';
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--color-secondary);
    flex-shrink: 0;
  }

  /* Painel de formulário: colado na metade direita */
  .auth-form-panel {
    margin-left: 50%;
    min-height: 100vh;
    background: var(--bg-main);
    padding: 64px 56px;
  }

  .auth-screen { max-width: 400px; }

  .auth-card {
    padding: 40px 36px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.07);
    background: var(--bg-surface);
  }
}

/* ===== SECTION TITLE ===== */
.section-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.section-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  background: var(--bg-muted);
  border-radius: var(--border-radius);
  padding: 3px;
  margin-bottom: var(--space-5);
}

.tab-btn {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: calc(var(--border-radius) - 3px);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  transition: all var(--transition);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
  font-weight: var(--font-weight-semibold);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-6);
}

.empty-state .icon-xl {
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.empty-state h3 {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* ===== LOADING ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  margin-top: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

/* ===== TOAST NOTIFICATIONS ===== */
#toast-container {
  position: fixed;
  bottom: calc(var(--nav-height) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  pointer-events: none;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  background: var(--bg-surface);
  border-radius: var(--border-radius);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  pointer-events: auto;
  animation: slideUp 0.3s ease;
  border-left: 4px solid var(--color-primary);
}

.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.warning { border-left-color: var(--color-warning); }

.toast .icon { flex-shrink: 0; }
.toast.success .icon { color: var(--color-success); }
.toast.error .icon { color: var(--color-danger); }
.toast.warning .icon { color: var(--color-warning); }
.toast.info .icon { color: var(--color-primary); }

.toast-text {
  flex: 1;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
}

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

/* ===== ALARM OVERLAY ===== */
.alarm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(21, 101, 192, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: var(--space-8);
  text-align: center;
  animation: fadeIn 0.4s ease;
}

.alarm-icon-pulse {
  width: 80px;
  height: 80px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-6);
  animation: pulse 1s ease-in-out infinite;
  color: white;
}

.alarm-overlay h2 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: white;
  margin-bottom: var(--space-3);
}

.alarm-overlay p {
  font-size: var(--font-size-md);
  color: rgba(255,255,255,0.85);
  margin-bottom: var(--space-8);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,255,255,0.4); }
  50% { transform: scale(1.08); box-shadow: 0 0 0 16px rgba(255,255,255,0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== PWA INSTALL OVERLAY ===== */
.install-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: var(--space-8);
  text-align: center;
  color: white;
}

.install-overlay img {
  width: 80px;
  height: 80px;
  border-radius: 18px;
  object-fit: cover;
  margin-bottom: var(--space-5);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.install-overlay h2 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-3);
}

.install-overlay p {
  font-size: var(--font-size-base);
  opacity: 0.85;
  margin-bottom: var(--space-8);
  line-height: 1.6;
  max-width: 300px;
}

.install-steps {
  background: rgba(255,255,255,0.12);
  border-radius: var(--border-radius);
  padding: var(--space-5);
  text-align: left;
  width: 100%;
  max-width: 320px;
  margin-bottom: var(--space-6);
}

.install-step {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.install-step:last-child { margin-bottom: 0; }

.step-num {
  width: 24px;
  height: 24px;
  background: var(--color-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  flex-shrink: 0;
  margin-top: 1px;
}

.install-step p {
  margin: 0;
  font-size: var(--font-size-sm);
  opacity: 0.9;
}

/* ===== PENDING PAGE ===== */
.pending-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
  background: var(--bg-main);
}

.pending-icon {
  width: 72px;
  height: 72px;
  background: var(--color-warning-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-5);
  color: var(--color-warning);
}

.pending-page h2 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-3);
  color: var(--text-primary);
}

.pending-page p {
  color: var(--text-secondary);
  font-size: var(--font-size-base);
  line-height: 1.6;
  max-width: 280px;
  margin: 0 auto var(--space-6);
}

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
  .content-area {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }
}

@media (min-width: 768px) {
  :root {
    --font-size-base: 14px;
  }
}

/* ===== DESKTOP LAYOUT (>= 1024px) — nav permanece embaixo ===== */
@media (min-width: 1024px) {
  /* Content area: ocupa largura maior na tela grande */
  .content-area {
    max-width: 1280px;
    padding-left: 40px;
    padding-right: 40px;
  }

  /* Charts grid sempre 2 colunas no desktop */
  .charts-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Dashboard: layout 2 colunas (gráficos esq, recentes dir) */
  #page-dashboard .content-area {
    display: grid;
    grid-template-columns: 1fr 300px;
    column-gap: 24px;
    align-items: start;
  }

  #page-dashboard .content-area .month-selector {
    grid-column: 1 / -1;
  }

  #page-dashboard .content-area .dashboard-recent {
    grid-column: 2;
    grid-row: 2 / span 4;
    position: sticky;
    top: calc(var(--header-height) + 16px);
  }

  #page-dashboard .content-area > .balance-card,
  #page-dashboard .content-area > .chart-container,
  #page-dashboard .content-area > .charts-grid {
    grid-column: 1;
  }
}
