/* ==============================================================================
   SOURCE FINANÇAS - CLEAN EXECUTIVE LIGHT DESIGN SYSTEM
   Paleta: Azul Corporativo com Branco, Verde para Entradas, Vermelho para Saídas
   Desktop: Barra Lateral (Sidebar) + Largura Total (Full Width)
   Mobile: PWA Nativo com Barra Inferior (Bottom Navigation Bar)
   ============================================================================== */

:root {
  /* Operational Light Canvas (Always pure, high-contrast and clean) */
  --bg-app: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F1F5F9;
  --bg-subtle: #F8FAFC;
  --border-color: #E2E8F0;
  --border-focus: #00A887;

  /* Source Finanças Official Palette */
  --brand-navy: #0A1326;
  --brand-navy-dark: #070D1B;
  --brand-navy-card: #0F1D38;
  --brand-navy-border: rgba(212, 175, 55, 0.2);

  --brand-gold: #C5A059;
  --brand-gold-metallic: #D4AF37;
  --brand-gold-light: #E5C378;
  --brand-gold-subtle: rgba(212, 175, 55, 0.12);

  --brand-teal: #00A887;
  --brand-teal-dark: #0D9488;
  --brand-teal-light: #10B981;
  --brand-teal-subtle: rgba(0, 168, 135, 0.12);
  
  /* Azul Corporativo de Apoio */
  --blue-50: #EFF6FF;
  --blue-100: #DBEAFE;
  --blue-200: #BFDBFE;
  --blue-500: #3B82F6;
  --blue-600: #00A887;
  --blue-700: #0D9488;
  --blue-800: #0F1D38;
  --blue-900: #0A1326;

  /* Verde (Receitas / Positivos) */
  --green-50: #ECFDF5;
  --green-100: #D1FAE5;
  --green-500: #10B981;
  --green-600: #00A887;
  --green-700: #065F46;

  /* Vermelho (Despesas / Saídas) */
  --red-50: #FEF2F2;
  --red-100: #FEE2E2;
  --red-500: #EF4444;
  --red-600: #DC2626;
  --red-700: #B91C1C;

  /* Roxos e Amarelos de Apoio */
  --purple-50: #FAF5FF;
  --purple-600: #9333EA;
  --amber-50: #FFFBEB;
  --amber-600: #D97706;

  /* Tipografia */
  --text-title: #0F172A;
  --text-body: #334155;
  --text-muted: #64748B;
  --text-subtle: #94A3B8;

  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  --sidebar-width: 260px;
  --bottom-nav-height: 64px;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg-app);
  color: var(--text-body);
  font-family: var(--font-sans);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
  touch-action: pan-y pinch-zoom;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root {
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  position: relative;
}

/* Custom Scrollbar Clean */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-app);
}
::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

.font-mono {
  font-family: var(--font-mono);
}

/* Layout Geral: Desktop com Sidebar + Full Width */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Sidebar no Desktop (Executive Deep Navy) */
.desktop-sidebar {
  width: var(--sidebar-width);
  background: radial-gradient(circle at 10% 15%, #0F1D38 0%, #0A1326 70%, #070D1B 100%);
  border-right: 1px solid rgba(212, 175, 55, 0.2);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  color: #FFFFFF;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: #0A1326;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  color: #94A3B8;
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #FFFFFF;
}

.nav-link.active {
  background: linear-gradient(135deg, rgba(0, 168, 135, 0.9) 0%, rgba(13, 148, 136, 0.95) 100%);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(0, 168, 135, 0.35);
  border-left: 3px solid #D4AF37;
}

.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(7, 13, 27, 0.65);
}

/* Área Principal (Desktop: Full Width com margem esquerda para a sidebar) */
.main-content-pane {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-width));
  max-width: 100%;
  overflow-x: hidden;
}

/* Topbar Superior em Largura Total */
.top-header-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.page-container-full {
  flex: 1;
  padding: 28px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

/* Bottom Navigation Bar (Apenas no Mobile / PWA - Deep Navy Executive) */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: #0A1326;
  border-top: 1px solid rgba(212, 175, 55, 0.22);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.4);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  color: #94A3B8;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 6px 10px;
  flex: 1;
  cursor: pointer;
  height: 100%;
  transition: all 0.15s ease;
}

.mobile-nav-item.active {
  color: #D4AF37;
}

/* Month Navigator Clean */
.month-selector-clean {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px 6px;
  box-shadow: var(--shadow-sm);
}

.month-btn-clean {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.month-btn-clean:hover {
  background: var(--blue-50);
  color: var(--blue-600);
}

.month-text-clean {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-title);
  padding: 4px 12px;
  min-width: 140px;
  text-align: center;
}

/* Cards Clean */
.clean-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.clean-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #CBD5E1;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: linear-gradient(135deg, #00A887 0%, #0D9488 100%);
  color: #FFFFFF;
  box-shadow: 0 3px 8px rgba(0, 168, 135, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #0FA082 0%, #065F46 100%);
  box-shadow: 0 5px 14px rgba(0, 168, 135, 0.4);
}

.btn-gold {
  background: linear-gradient(135deg, #D4AF37 0%, #C5A059 100%);
  color: #0A1326;
  font-weight: 800;
  border: 1px solid #E5C378;
  box-shadow: 0 3px 8px rgba(212, 175, 55, 0.3);
}
.btn-gold:hover {
  background: linear-gradient(135deg, #E5C378 0%, #D4AF37 100%);
  box-shadow: 0 5px 14px rgba(212, 175, 55, 0.45);
}

.btn-secondary {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--text-body);
}
.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: #CBD5E1;
  color: var(--text-title);
}

.btn-emerald-clean {
  background: var(--green-50);
  border: 1px solid var(--green-100);
  color: var(--green-700);
}
.btn-emerald-clean:hover {
  background: #D1FAE5;
}

.btn-ruby-clean {
  background: var(--red-50);
  border: 1px solid var(--red-100);
  color: var(--red-700);
}
.btn-ruby-clean:hover {
  background: #FEE2E2;
}

/* Destaque Verde e Vermelho */
.text-income {
  color: var(--green-600) !important;
}

.text-expense {
  color: var(--red-600) !important;
}

.bg-income-subtle {
  background-color: var(--green-50);
  border: 1px solid var(--green-100);
}

.bg-expense-subtle {
  background-color: var(--red-50);
  border: 1px solid var(--red-100);
}

/* Badges */
.badge-status-clean {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 20px;
}

.badge-paid {
  background: var(--green-50);
  color: var(--green-700);
  border: 1px solid var(--green-100);
}

.badge-pending {
  background: var(--amber-50);
  color: var(--amber-600);
  border: 1px solid #FDE68A;
}

/* Tabela Clean */
.table-responsive-clean {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.clean-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.clean-table th {
  background: #F8FAFC;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border-color);
}

.clean-table td {
  padding: 14px 18px;
  border-bottom: 1px solid #F1F5F9;
  vertical-align: middle;
}

.clean-table tr:hover td {
  background: #F8FAFC;
}

/* Forms & Modals Clean */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-content-clean {
  background: #FFFFFF;
  border-radius: var(--radius-xl);
  max-width: 620px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border-color);
  animation: modalEnter 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalEnter {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header-clean {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body-clean {
  padding: 24px;
}

.modal-footer-clean {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: #F8FAFC;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.form-group-clean {
  margin-bottom: 16px;
}

.form-label-clean {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-title);
  margin-bottom: 6px;
}

.form-input-clean, .form-select-clean, .form-textarea-clean {
  width: 100%;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  color: var(--text-title);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-family: inherit;
  transition: all 0.15s ease;
}

.form-input-clean:focus, .form-select-clean:focus, .form-textarea-clean:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Utilities Desktop / Mobile Visibility */
.desktop-only {
  display: block;
}
.mobile-only {
  display: none;
}
.desktop-only-text {
  display: inline;
}
.mobile-only-btn {
  display: none;
}

/* Entity Tab Buttons */
.entity-tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 8px 14px;
  min-width: 0;
}
.entity-tab-btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Auth View Grid & Columns */
.auth-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth-banner-col {
  padding: 48px 36px;
}
.auth-form-col {
  padding: 48px 36px;
}

/* Modal Bottom Sheet Drag Handle */
.modal-drag-handle {
  display: none;
  width: 40px;
  height: 4px;
  background: #CBD5E1;
  border-radius: 99px;
  margin: 10px auto 4px auto;
}

/* Mobile Quick Drawer Menu */
.mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s ease-out;
}

.mobile-drawer-content {
  background: #FFFFFF;
  width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 16px) + 12px) 16px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  animation: slideUpDrawer 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpDrawer {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.drawer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.drawer-action-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-title);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  width: 100%;
}

.drawer-action-btn:active {
  background: var(--blue-50);
  border-color: var(--blue-200);
  transform: scale(0.98);
}

.drawer-action-btn .btn-title {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-title);
}

.drawer-action-btn .btn-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Mobile Transaction Card Layout */
.desktop-table-container {
  display: block;
}
.mobile-tx-list {
  display: none;
}

.mobile-tx-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.mobile-tx-card:active {
  background: #F8FAFC;
  transform: scale(0.99);
}

/* ==============================================================================
   RESPONSIVIDADE MOBILE & TABLET (Menor que 1024px)
   ============================================================================== */
@media (max-width: 1024px) {
  .desktop-sidebar {
    display: none;
  }

  .main-content-pane {
    margin-left: 0;
    width: 100%;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 24px);
  }

  .mobile-bottom-nav {
    display: flex;
  }

  .top-header-bar {
    padding: 10px 14px;
  }

  .page-container-full {
    padding: 14px 12px;
  }
}

/* ==============================================================================
   RESPONSIVIDADE TELEFONE / SMARTPHONE (Menor que 768px)
   ============================================================================== */
@media (max-width: 768px) {
  /* Prevent iOS Safari auto-zoom on inputs */
  .form-input-clean,
  .form-select-clean,
  .form-textarea-clean,
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .desktop-only {
    display: none !important;
  }
  .mobile-only {
    display: block !important;
  }
  .desktop-only-text {
    display: none !important;
  }
  .mobile-only-btn {
    display: inline-flex !important;
  }

  /* Compact Month Selector in Mobile Header */
  .month-selector-clean {
    padding: 2px 4px;
    gap: 2px;
  }

  .month-text-clean {
    min-width: 110px;
    font-size: 0.82rem;
    padding: 2px 6px;
  }

  .month-btn-clean {
    padding: 4px 6px;
  }

  .top-header-bar {
    padding: 8px 12px;
    gap: 8px;
  }

  /* Modals as Native Mobile Bottom Sheets */
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
    background: rgba(15, 23, 42, 0.6);
  }

  .modal-drag-handle {
    display: block;
  }

  .modal-content-clean {
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    width: 100% !important;
    max-width: 100% !important;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: calc(env(safe-area-inset-bottom, 16px) + 8px);
    animation: modalSlideUpMobile 0.22s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  @keyframes modalSlideUpMobile {
    from { transform: translateY(100%); opacity: 0.5; }
    to { transform: translateY(0); opacity: 1; }
  }

  .modal-header-clean {
    padding: 14px 18px 12px 18px;
  }

  .modal-body-clean {
    padding: 16px 18px;
  }

  .modal-footer-clean {
    padding: 12px 18px;
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-footer-clean .btn {
    width: 100%;
    padding: 12px;
  }

  /* Switch Table to Cards on Mobile */
  .desktop-table-container {
    display: none !important;
  }

  .mobile-tx-list {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
  }

  /* KPI Card adjustments on mobile */
  .clean-card {
    padding: 16px;
    border-radius: var(--radius-md);
  }

  /* Entity Tabs Segmented Control Mobile */
  /* Entity Tabs Segmented Control Mobile */
  .entity-tabs-group {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
    gap: 4px !important;
    box-sizing: border-box !important;
  }

  .entity-tab-btn {
    padding: 8px 3px !important;
    font-size: 0.76rem !important;
    justify-content: center !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
  }

  .entity-tab-btn span {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 0 !important;
  }

  /* Auth View Mobile */
  .auth-card-grid {
    grid-template-columns: 1fr !important;
    border-radius: 18px !important;
    margin: 8px !important;
    max-width: calc(100vw - 16px) !important;
  }

  .auth-banner-col {
    padding: 24px 18px !important;
  }

  .auth-form-col {
    padding: 24px 18px !important;
  }

  .report-sheet-card {
    padding: 18px 14px !important;
    border-radius: var(--radius-md) !important;
  }

  /* Admin Modal Mobile Optimization */
  .admin-modal-content {
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .admin-edit-submodal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .admin-edit-submodal-card {
    border-radius: 20px 20px 0 0 !important;
    max-height: 90vh !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 20px 16px !important;
  }
}

.report-sheet-card {
  padding: 36px;
}

.admin-modal-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

