/* ═══════════════════════════════════════════════════════════
   Controle Financeiro — style.css
   Totalmente responsivo: mobile, tablet, desktop
   ═══════════════════════════════════════════════════════════ */

:root {
  --primary:      #2563eb;
  --primary-dark: #1d4ed8;
  --success:      #16a34a;
  --danger:       #dc2626;
  --warning:      #d97706;
  --bg:           #f1f5f9;
  --card:         #ffffff;
  --text:         #1e293b;
  --muted:        #64748b;
  --border:       #e2e8f0;
  --sidebar-w:    240px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── AUTH ─────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  padding: 16px;
}
.auth-card {
  background: var(--card);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
@media (max-width: 480px) {
  .auth-card { padding: 28px 20px; border-radius: 12px; }
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo h1 { font-size: 22px; font-weight: 700; color: var(--primary); }
.auth-logo p  { color: var(--muted); font-size: 13px; }

/* ── APP LAYOUT ───────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 300;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .25s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }

.sidebar-brand {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.sidebar-brand h2 { color: #fff; font-size: 15px; font-weight: 700; line-height: 1.3; }
.sidebar-brand p  { color: #94a3b8; font-size: 11px; margin-top: 2px; }

.sidebar-nav { padding: 8px 0; flex: 1; }
.nav-section {
  padding: 10px 16px 4px;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: #94a3b8;
  text-decoration: none;
  transition: all .15s;
  font-size: 13px;
  white-space: nowrap;
}
.nav-link:hover  { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .icon  { width: 20px; text-align: center; flex-shrink: 0; font-size: 15px; }

.sidebar-user {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: #94a3b8;
  font-size: 12px;
  flex-shrink: 0;
}
.sidebar-user strong { display: block; color: #fff; margin-bottom: 2px; font-size: 13px; }
.sidebar-user span   { font-size: 11px; word-break: break-all; }
.btn-logout {
  margin-top: 8px;
  width: 100%;
  padding: 7px;
  background: rgba(220,38,38,.2);
  border: 1px solid rgba(220,38,38,.4);
  color: #fca5a5;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s;
}
.btn-logout:hover { background: rgba(220,38,38,.35); }

/* Overlay escuro quando sidebar aberta no mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 299;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* ── MAIN CONTENT ─────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  min-width: 0;
}

/* ── TOPBAR ───────────────────────────────────────────────── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* Botão hambúrguer — só aparece no mobile */
.btn-menu {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  font-size: 22px;
  line-height: 1;
  color: var(--text);
  flex-shrink: 0;
}

.page-body { padding: 20px 24px; }

/* ── STATS GRID ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px 16px;
  border: 1px solid var(--border);
}
.stat-card .label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-card.green .value { color: var(--success); }
.stat-card.red   .value { color: var(--danger); }
.stat-card.blue  .value { color: var(--primary); }
.stat-card.amber .value { color: var(--warning); }

/* ── CHARTS ───────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.chart-card {
  background: var(--card);
  border-radius: 12px;
  padding: 18px;
  border: 1px solid var(--border);
}
.chart-card h3 { font-size: 13px; font-weight: 700; margin-bottom: 14px; color: var(--muted); }

/* ── CARD ─────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.card-header h3 { font-size: 14px; font-weight: 700; }
.card-body { padding: 18px; }

/* ── FORM ─────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--muted); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  background: var(--card);
  color: var(--text);
  width: 100%;
  -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); }

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }

/* ── TABLE ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 500px; /* evita colapso no mobile — scroll horizontal */
}
thead th {
  background: var(--bg);
  padding: 9px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ── BADGE ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ── UTILS ────────────────────────────────────────────────── */
.text-green { color: var(--success); }
.text-red   { color: var(--danger); }
.text-blue  { color: var(--primary); }
.text-muted { color: var(--muted); }
.fw-700     { font-weight: 700; }

.alert {
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state p { margin-top: 8px; font-size: 13px; }

.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 540px;
  padding: 28px 24px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  max-height: 90vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; padding: 16px; }
  .modal { border-radius: 16px; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.btn-close { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--muted); line-height: 1; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVO — BREAKPOINTS
   ═══════════════════════════════════════════════════════════ */

/* ── TABLET (≤ 1024px) ─────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
  .page-body { padding: 16px 18px; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
  .charts-grid { grid-template-columns: 1fr; }
  .stat-card .value { font-size: 20px; }
}

/* ── MOBILE (≤ 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {

  /* Sidebar vira drawer */
  .sidebar {
    transform: translateX(-100%);
    width: min(var(--sidebar-w), 85vw);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }

  /* Main ocupa tudo */
  .main-content { margin-left: 0; }

  /* Topbar */
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 15px; }
  .btn-menu { display: flex; }

  /* Page body */
  .page-body { padding: 12px 14px; }

  /* Stats: 2 colunas no mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }
  .stat-card { padding: 14px 12px; }
  .stat-card .value { font-size: 18px; }
  .stat-card .label { font-size: 10px; }

  /* Forms: 1 coluna */
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  /* Respeita span 2 mas reseta para 1 no mobile */
  .form-group[style*="grid-column:span 2"],
  .form-group[style*="grid-column: span 2"] { grid-column: span 1 !important; }

  .card-header { padding: 12px 14px; gap: 8px; }
  .card-body   { padding: 14px; }

  /* Botões menores no mobile */
  .btn { padding: 9px 14px; font-size: 13px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }

  /* Charts: altura menor */
  canvas { max-height: 220px; }

  /* Table: scroll horizontal sempre visível */
  .table-wrap {
    margin: 0 -14px;
    padding: 0 14px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Oculta colunas menos importantes nas tabelas */
  .hide-mobile { display: none !important; }
}

/* ── SMALL MOBILE (≤ 480px) ───────────────────────────────── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card .value { font-size: 16px; }

  /* Topbar compacta */
  .topbar { padding: 8px 12px; }
  .topbar h1 { font-size: 14px; }

  /* Page body */
  .page-body { padding: 10px 12px; }

  /* Buttons em linha: wrap */
  .btn-group { flex-wrap: wrap; }

  /* Esconde texto dos botões de ação na tabela, mostra só ícone */
  .btn-sm .btn-label { display: none; }
}

/* ── PRINT ────────────────────────────────────────────────── */
@media print {
  .sidebar, .sidebar-overlay, .topbar, .btn-menu,
  .btn-pdf, .btn-xls, .export-bar, .rel-tabs,
  .card-header .btn, button { display: none !important; }
  .main-content { margin: 0 !important; }
  .page-body { padding: 0 !important; }
  .card { border: 1px solid #ccc; margin-bottom: 12px; break-inside: avoid; }
  table { font-size: 11px; }
}
