@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg-base:    #0d0f12;
  --bg-surface: #14171c;
  --bg-card:    #1a1e25;
  --bg-hover:   #1f242d;
  --bg-input:   #11141a;
  --border:     #252b35;
  --border-focus: #3a8fff;

  --text-primary:   #e8eaf0;
  --text-secondary: #8b93a5;
  --text-muted:     #525c6e;

  --accent:       #3a8fff;
  --accent-dim:   #1a4a8a;
  --green:        #27c97a;
  --green-dim:    #0d3d24;
  --red:          #f05c5c;
  --red-dim:      #3d1a1a;
  --amber:        #f5a623;
  --amber-dim:    #3d2a08;
  --purple:       #a78bfa;
  --purple-dim:   #2e1f5e;
  --teal:         #2dd4bf;
  --teal-dim:     #0d3530;

  --sidebar-w: 220px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 4px 24px rgba(0,0,0,.5);

  --font: 'Inter', sans-serif;
  --mono: 'Inter', sans-serif;
}

html, body { height: 100%; background: var(--bg-base); color: var(--text-primary); font-family: var(--font); font-size: 16px; line-height: 1.6; }

/* === LAYOUT === */
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 20px 16px 16px;
  font-size: 15px; font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  letter-spacing: -.3px;
}
.sidebar-logo span { font-size: 22px; }
.sidebar-section { padding: 12px 0; }
.sidebar-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  color: var(--text-muted); text-transform: uppercase;
  padding: 0 16px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  color: var(--text-secondary);
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left; font-size: 15px;
  border-left: 3px solid transparent;
  transition: all .15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-hover); color: var(--accent); border-left-color: var(--accent); font-weight: 500; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

/* Main content */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

#topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-title { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.topbar-sub { font-size: 13px; color: var(--text-secondary); margin-top: 1px; }

#content { flex: 1; overflow-y: auto; padding: 24px; }

/* === CARDS === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* === KPI CARDS === */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.kpi-card.blue::before { background: var(--accent); }
.kpi-card.green::before { background: var(--green); }
.kpi-card.red::before { background: var(--red); }
.kpi-card.amber::before { background: var(--amber); }
.kpi-card.purple::before { background: var(--purple); }
.kpi-card.teal::before { background: var(--teal); }

.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .7px; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text-primary); letter-spacing: -.5px; line-height: 1.2; }
.kpi-sub { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* === TABELA === */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .6px;
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td { padding: 13px 14px; font-size: 17px; color: var(--text-primary); }
.td-mono { font-family: var(--mono); font-size: 17px; }
.td-muted { color: var(--text-secondary); }

/* === BADGES === */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-dim);  color: var(--green);  }
.badge-red    { background: var(--red-dim);    color: var(--red);    }
.badge-amber  { background: var(--amber-dim);  color: var(--amber);  }
.badge-blue   { background: var(--accent-dim); color: var(--accent); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-muted  { background: var(--bg-hover);   color: var(--text-secondary); }
.badge-teal   { background: var(--teal-dim);   color: var(--teal);   }

/* === BOTÕES === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer;
  border: none; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5ba0ff; }
.btn-success { background: var(--green-dim); color: var(--green); border: 1px solid var(--green); }
.btn-success:hover { background: var(--green); color: #000; }
.btn-danger  { background: var(--red-dim); color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover  { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* === FORMULÁRIOS === */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 140px; }
.form-group.w-auto { flex: 0 0 auto; }
label { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
input, select, textarea {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-primary);
  font-family: var(--font); font-size: 15px; padding: 9px 12px;
  outline: none; transition: border-color .15s; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--border-focus); }
input[type=checkbox] { width: auto; }
select option { background: var(--bg-card); }

/* === FILTROS === */
.filters {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px 18px;
  margin-bottom: 16px;
  display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end;
}

/* === FORMULÁRIO ADD CHEQUE === */
.cheque-form-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px;
}
.cheque-form-card .form-row { margin-bottom: 0; }

/* === MODAL === */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  z-index: 100; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  width: 480px; max-width: 95vw;
  transform: translateY(8px); transition: transform .2s;
  max-height: 90vh; overflow-y: auto;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 18px; color: var(--text-primary); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* === TOAST === */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  font-size: 13px; color: var(--text-primary);
  min-width: 260px; animation: slideIn .25s ease;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-lg);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red);   }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === CHARTS === */
.chart-container { position: relative; height: 220px; }

/* === MISC === */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--text-primary); letter-spacing: -.4px; }
.page-sub { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.mt-16 { margin-top: 16px; }
.mt-8 { margin-top: 8px; }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.text-amber { color: var(--amber); }
.text-blue  { color: var(--accent); }
.text-muted { color: var(--text-secondary); }
.text-right { text-align: right; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); font-size: 13px; }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.valor-negativo { color: var(--red); }
.valor-positivo { color: var(--green); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #353c49; }

/* === SUB-MENU CAIXA === */
.nav-parent { justify-content: space-between; }
.nav-arrow { font-size: 11px; margin-left: auto; transition: transform .2s; color: var(--text-muted); }
.nav-arrow.open { transform: rotate(180deg); }
#nav-caixa-sub { overflow: hidden; max-height: 0; transition: max-height .25s ease; }
#nav-caixa-sub.open { max-height: 300px; }
.nav-sub-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px 8px 36px;
  color: var(--text-muted);
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left; font-size: 14px;
  border-left: 3px solid transparent;
  transition: all .15s;
}
.nav-sub-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-sub-item.active { color: var(--accent); border-left-color: var(--accent); font-weight: 500; background: var(--bg-hover); }
.nav-sub-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; transition: background .15s; }
.nav-sub-item.active .nav-sub-dot { background: var(--accent); }
.nav-sub-saldo { margin-left: auto; font-size: 11px; font-family: var(--mono); color: var(--text-muted); }
.nav-sub-item.active .nav-sub-saldo { color: var(--accent); }


/* ================================================================
   RESPONSIVO MOBILE
   Adiciona suporte a telas <= 768px sem quebrar o layout desktop
   ================================================================ */

/* --- Botão hamburger (só aparece no mobile) --- */
#btn-menu {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  padding: 6px 10px;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  transition: all .15s;
}
#btn-menu:hover { background: var(--bg-hover); color: var(--text-primary); }

/* --- Overlay escuro por trás da sidebar aberta --- */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 49;
}
#sidebar-overlay.open { display: block; }


@media (max-width: 768px) {

  /* --- Topbar --- */
  #topbar { padding: 0 14px; gap: 10px; }
  #btn-menu { display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .topbar-title { font-size: 16px; }
  .topbar-sub { display: none; }

  /* --- Sidebar vira drawer lateral --- */
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 260px;
    /* Garante que aparece mesmo que o CSS base tenha display:none */
    display: flex !important;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* --- Conteúdo principal ocupa largura total --- */
  #content { padding: 14px; }

  /* --- Page header empilha em mobile --- */
  .page-header {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
  }
  .page-header .btn { width: 100%; justify-content: center; }

  /* --- KPI grid: 2 colunas em mobile --- */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .kpi-value { font-size: 19px; }
  .kpi-card { padding: 14px; }

  /* --- Grids de seção viram 1 coluna --- */
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }

  /* --- Gráfico menor em mobile --- */
  .chart-container { height: 180px; }

  /* --- Filtros empilham verticalmente --- */
  .filters {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
    gap: 10px;
  }
  .filters .form-group { min-width: unset; width: 100%; }
  .filters .btn { width: 100%; justify-content: center; }

  /* --- Formulário de cheque --- */
  .cheque-form-card .form-row { flex-direction: column; }
  .cheque-form-card .form-group { min-width: unset; width: 100%; }

  /* --- Botões de ação na tabela ficam menores --- */
  .btn-sm { padding: 4px 8px; font-size: 11px; }

  /* -------------------------------------------------------
     TABELAS RESPONSIVAS — viram cards empilhados
     Requer data-label="Nome da coluna" em cada <td>
     ------------------------------------------------------- */
  .table-wrap { overflow-x: unset; }

  .table-mobile thead { display: none; }
  .table-mobile tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
    padding: 4px 0;
  }
  .table-mobile tbody tr:hover { background: var(--bg-hover); }
  .table-mobile tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 14px;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
  }
  .table-mobile tbody td:last-child { border-bottom: none; }
  .table-mobile tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  /* Células sem label (ex: coluna de ações) — centraliza */
  .table-mobile tbody td[data-label=""] {
    justify-content: flex-end;
  }
  .table-mobile tbody td[data-label=""]::before { display: none; }

  /* --- Modal vira bottom sheet em mobile --- */
  .modal-backdrop {
    align-items: flex-end;
  }
  .modal {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px 16px 32px;
    max-height: 92vh;
  }

  /* --- Toast ocupa largura total --- */
  #toast-container {
    bottom: 16px;
    left: 12px;
    right: 12px;
  }
  .toast { min-width: unset; width: 100%; }

  /* --- Seção header empilha --- */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .section-header .btn { width: 100%; justify-content: center; }

  /* --- Modal footer empilha botões --- */
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; justify-content: center; }

  /* --- Sub-menu do caixa no drawer --- */
  .nav-sub-item { padding: 9px 16px 9px 36px; font-size: 15px; }

  /* --- Esconde saldo da conta no sub-menu (pouco espaço) --- */
  .nav-sub-saldo { display: none; }

  /* --- Tabs de conta caixa (alternativa ao sub-menu) --- */
  .caixa-tabs {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding: 0 0 10px;
    margin-bottom: 14px;
    scrollbar-width: none;
  }
  .caixa-tabs::-webkit-scrollbar { display: none; }
  .caixa-tab {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
  }
  .caixa-tab.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
  }
}

/* --- KPI grid: 1 coluna em telas muito pequenas --- */
@media (max-width: 400px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
}
