/* FinBase — Estilos globais */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --border: rgba(255,255,255,.08);
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --primary: #6366f1;
  --primary2: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --income: #10b981;
  --expense: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.3);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; min-height: 100vh; background: var(--bg2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
  transition: transform .3s;
}
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon { font-size: 24px; }
.sidebar-logo .logo-text { font-size: 18px; font-weight: 800; color: var(--primary); }
.sidebar-user { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.sidebar-user .user-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: 11px; color: var(--text2); }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section { padding: 6px 20px 2px; font-size: 10px; font-weight: 700; color: var(--text3); letter-spacing: .08em; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; font-size: 14px; font-weight: 500;
  color: var(--text2); cursor: pointer; transition: all .15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav-item.active { background: rgba(99,102,241,.12); color: var(--primary); border-left-color: var(--primary); }
.nav-item i { width: 18px; text-align: center; font-size: 14px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }

.main-content { margin-left: 240px; flex: 1; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; }
.page-body { padding: 24px; }
.page-content { padding: 24px; } /* alias */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-title { font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.page-title i { color: var(--primary); }

/* Cards */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
}
.stat-value { font-size: 26px; font-weight: 800; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: none; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary2); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text2); }
.form-control {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; color: var(--text); font-size: 14px; width: 100%;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-control::placeholder { color: var(--text3); }
select.form-control option { background: var(--bg2); }

/* Table */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead th {
  padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.data-table tbody tr:hover { background: rgba(255,255,255,.03); }
.data-table tbody td { padding: 12px 14px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: var(--bg2); border-radius: 16px; width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-header {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}
.modal-close {
  background: transparent; border: none; color: var(--text2);
  font-size: 20px; cursor: pointer; padding: 0; line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.badge-income { background: rgba(16,185,129,.15); color: var(--income); }
.badge-expense { background: rgba(239,68,68,.12); color: var(--expense); }
.badge-transfer { background: rgba(99,102,241,.12); color: var(--primary); }

/* Amount colors */
.amount-income { color: var(--income); font-weight: 700; }
.amount-expense { color: var(--expense); font-weight: 700; }

/* Progress bar */
.progress { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 4px; transition: width .4s; }

/* Toast — fica acima da bottom nav no mobile */
.toast-container { position: fixed; bottom: 80px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
@media (min-width: 769px) { .toast-container { bottom: 20px; right: 20px; } }
.toast {
  padding: 12px 18px; border-radius: 10px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow); animation: slideIn .3s ease; max-width: 320px;
}
.toast-success { background: #064e3b; color: #6ee7b7; border: 1px solid #065f46; }
.toast-error   { background: #7f1d1d; color: #fca5a5; border: 1px solid #991b1b; }
.toast-info    { background: #1e3a5f; color: #93c5fd; border: 1px solid #1d4ed8; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Login */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #1e1b4b 0%, #0f172a 60%);
}
.auth-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 20px;
  padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .icon { font-size: 48px; margin-bottom: 8px; }
.auth-logo h1 { font-size: 24px; font-weight: 800; color: var(--primary); }
.auth-logo p { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* OFX Drop Zone */
.ofx-dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; cursor: pointer;
  transition: all .2s;
}
.ofx-dropzone:hover, .ofx-dropzone.drag-over {
  border-color: var(--primary); background: rgba(99,102,241,.06);
}
.ofx-dropzone i { font-size: 36px; color: var(--text3); margin-bottom: 12px; }

/* Hamburger for mobile */
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; padding: 6px; }

/* Chips/filters */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); color: var(--text2);
  background: transparent; transition: all .15s;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ============================================================
   MOBILE — Navegação inferior + layout adaptado
   ============================================================ */

/* Barra de navegação inferior (aparece só no mobile) */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--bg2); border-top: 1px solid var(--border);
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
  box-shadow: 0 -4px 20px rgba(0,0,0,.3);
}
.bottom-nav-items {
  display: flex; justify-content: space-around; align-items: center;
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 10px; cursor: pointer; border-radius: 10px;
  color: var(--text3); transition: all .15s; flex: 1; min-width: 0;
  border: none; background: none;
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item i { font-size: 18px; }
.bottom-nav-item span { font-size: 10px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Botão flutuante de ação (FAB) — adicionar lançamento rápido */
.fab {
  display: none;
  position: fixed; bottom: 72px; right: 18px; z-index: 199;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 22px;
  border: none; cursor: pointer; box-shadow: 0 4px 16px rgba(99,102,241,.5);
  align-items: center; justify-content: center; transition: transform .2s;
}
.fab:active { transform: scale(.93); }

/* Overlay sidebar mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55);
  z-index: 99; backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
  /* Sidebar: drawer lateral */
  .sidebar {
    transform: translateX(-100%);
    z-index: 100;
    width: 260px;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; align-items: center; justify-content: center; }

  /* Topbar mais compacta */
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 16px; }

  /* Conteúdo com espaço para bottom nav */
  .page-body { padding: 12px 14px 80px; }

  /* Bottom nav visível */
  .bottom-nav { display: block; }

  /* FAB visível nas páginas de lançamentos */
  .fab { display: flex; }

  /* Grids */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .grid-single { grid-template-columns: 1fr !important; }

  /* Stat cards menores */
  .stat-card { padding: 14px; }
  .stat-value { font-size: 20px; }
  .stat-label { font-size: 11px; }

  /* Cards */
  .card { padding: 14px; border-radius: 12px; }
  .card-header { padding: 12px 14px; }
  .card-body { padding: 0 14px 14px; }

  /* Tabelas: scroll horizontal */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
  .data-table { min-width: 480px; }
  .data-table thead th { padding: 8px 10px; font-size: 10px; }
  .data-table tbody td { padding: 10px 10px; font-size: 12px; }

  /* Auth card mais compacto */
  .auth-card { padding: 24px 18px; margin: 12px; max-width: 100%; }

  /* Modais em tela cheia no mobile */
  .modal-box {
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    max-height: 92vh !important;
    margin: 0 !important;
  }
  .modal[style*="flex"] { align-items: flex-end !important; }

  /* Formulários com campos maiores para toque */
  .form-control { padding: 12px 14px; font-size: 16px; border-radius: 10px; }
  .form-label { font-size: 13px; }
  .btn { padding: 11px 16px; font-size: 14px; border-radius: 10px; }
  .btn-sm { padding: 7px 12px; font-size: 12px; }

  /* Chips com scroll horizontal */
  .chips-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .chips-scroll::-webkit-scrollbar { display: none; }

  /* Texto truncado */
  .text-truncate-mobile { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Ocultar colunas menos importantes em tabelas no mobile */
  .hide-mobile { display: none !important; }

  /* Badge maior para toque */
  .badge { padding: 4px 10px; font-size: 11px; }

  /* OFX dropzone */
  .ofx-drop { padding: 24px 14px; }
}

/* Telas muito pequenas (até 380px) */
@media (max-width: 380px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }
  .stat-value { font-size: 18px; }
  .bottom-nav-item span { display: none; }
  .bottom-nav-item { padding: 8px 6px; }
  .bottom-nav-item i { font-size: 20px; }
  .page-body { padding: 10px 10px 72px; }
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

/* Chart container */
.chart-container { position: relative; }

/* Account color dot */
.color-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* Loading spinner */
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 60px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-state i { font-size: 40px; margin-bottom: 12px; display: block; }

/* Utilitários responsivos */
.show-mobile-only { display: none; }
.hide-on-mobile { }

/* Auth page mobile */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px;
}
.auth-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 20px;
  padding: 32px 28px; width: 100%; max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
}
