/**
 * ============================================================
 * SIS MIDAS BKF - SISTEMA FINANCEIRO
 * Estilo Visual - Tema Dark BKF
 * Versão 3.15 - Mobile Polido: Textos Maiores e Layout Preenchido
 * ============================================================
 */

/* ========== VARIABLES ========== */
:root {
  --bg: #0a0b0d;
  --bg-card: #111318;
  --bg-elevated: #1a1d24;
  --bg-input: #0d0e11;
  --ink: #edf1f7;
  --muted: #9ca3af;
  --accent: #e5e7eb;
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --success-border: rgba(16, 185, 129, 0.3);
  
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --warning-border: rgba(245, 158, 11, 0.3);
  
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --error-border: rgba(239, 68, 68, 0.3);
  
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.1);
  --info-border: rgba(59, 130, 246, 0.3);
  
  --primary: #4b5563;
  --primary-hover: #374151;
  
  --line: rgba(255,255,255,.08);
  --glass: rgba(255,255,255,.04);
  --glass-hover: rgba(255,255,255,.08);
  
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  
  --sidebar-width: 260px;
}

/* ========== RESET ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.6; font-size: 14px;
  overflow-x: hidden;
}

/* ========== LAYOUT ========== */
.app-container { display: flex; min-height: 100vh; }

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-width); background: var(--bg-card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-header { padding: 24px 20px; border-bottom: 1px solid var(--line); }
.sidebar-logo { display: flex; align-items: center; gap: 12px; }
.sidebar-logo img { height: 36px; width: auto; }
.sidebar-logo-text { display: flex; flex-direction: column; }
.sidebar-logo-title { font-size: 16px; font-weight: 700; color: var(--ink); }
.sidebar-logo-subtitle { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section { margin-bottom: 24px; }
.nav-section-title { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); padding: 0 12px; margin-bottom: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-weight: 500; transition: all 0.2s ease;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left; font-size: 14px; font-family: inherit;
}
.nav-item:hover { background: var(--glass-hover); color: var(--ink); }
.nav-item.active { background: var(--primary); color: white; }
.nav-item-icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--line); }
.sidebar-footer-text { font-size: 11px; color: var(--muted); text-align: center; }

/* ========== MAIN CONTENT ========== */
.main-content {
  flex: 1; margin-left: var(--sidebar-width); min-height: 100vh;
  display: flex; flex-direction: column; width: 100%;
}

/* ========== HEADER ========== */
.header {
  background: var(--bg-card); border-bottom: 1px solid var(--line); padding: 16px 24px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 50; gap: 16px; flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.header-title { font-size: 20px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.header-month-selector { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.header-month-selector select { background: transparent; border: none; color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; outline: none; font-family: inherit; padding-right: 8px; }
.header-month-selector option { background: var(--bg-card); }
.menu-toggle { display: none; background: none; border: none; color: var(--ink); font-size: 24px; cursor: pointer; padding: 8px; border-radius: var(--radius-sm); transition: background 0.2s ease; }
.menu-toggle:hover { background: var(--glass); }

/* ========== PAGE CONTENT ========== */
.page-content { flex: 1; padding: 24px; overflow-x: hidden; }
.page-section { display: none; }
.page-section.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ========== CARDS ========== */
.card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 24px; width: 100%; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 10px; }
.card-body { padding: 20px; }

/* ========== STATS GRID ========== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; align-items: flex-start; gap: 16px; transition: all 0.2s ease; min-width: 0; width: 100%; }
.stat-card:hover { border-color: rgba(255,255,255,0.15); transform: translateY(-2px); }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.stat-icon.receitas { background: var(--success-bg); border: 1px solid var(--success-border); }
.stat-icon.despesas { background: var(--error-bg); border: 1px solid var(--error-border); }
.stat-icon.lucro { background: var(--info-bg); border: 1px solid var(--info-border); }
.stat-icon.pendente { background: var(--warning-bg); border: 1px solid var(--warning-border); }
.stat-info { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; white-space: nowrap; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--ink); line-height: 1.2; word-break: break-word; }
.stat-value.positive { color: var(--success); } .stat-value.negative { color: var(--error); }
.stat-change { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.stat-change.positive { color: var(--success); } .stat-change.negative { color: var(--error); }

/* ========== CONFIG GRID ========== */
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; }
.aux-list { display: flex; flex-direction: column; gap: 8px; }
.aux-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); transition: all 0.2s ease; gap: 12px; }
.aux-item:hover { border-color: rgba(255, 255, 255, 0.15); background: var(--glass-hover); }
.aux-item-info { flex: 1; min-width: 0; }
.aux-item-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.aux-item-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.aux-item-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ========== TABLES ========== */
.table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -20px; padding: 0 20px; max-width: 100vw; }
.table { width: 100%; border-collapse: collapse; min-width: 600px; table-layout: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 600px; table-layout: fixed; }
.data-table th:nth-child(1), .data-table td:nth-child(1) { width: 35%; }
.data-table th:nth-child(2), .data-table td:nth-child(2) { width: 20%; }
.data-table th:nth-child(3), .data-table td:nth-child(3) { width: 20%; }
.data-table th:nth-child(4), .data-table td:nth-child(4) { width: 15%; }
.data-table th:nth-child(5), .data-table td:nth-child(5) { width: 10%; text-align: right; }
.table th, .data-table th { text-align: left; padding: 14px 16px; background: var(--glass); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td, .data-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table tr:last-child td, .data-table tr:last-child td { border-bottom: none; }
.table tr:hover td, .data-table tr:hover td { background: var(--glass); }
.table-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ========== BUTTONS ========== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 20px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; text-decoration: none; transition: all 0.2s ease; cursor: pointer; border: none; font-family: inherit; white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #0d9668; }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-secondary { background: var(--glass); color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--glass-hover); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--muted); padding: 8px; }
.btn-ghost:hover { background: var(--glass); color: var(--ink); }
.btn-sm { padding: 8px 16px; font-size: 12px; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--glass); border: 1px solid var(--line); color: var(--muted); cursor: pointer; transition: all 0.2s ease; font-size: 14px; }
.btn-icon:hover { background: var(--glass-hover); color: var(--ink); }
.btn-icon.btn-delete:hover { background: var(--error-bg); border-color: var(--error); color: var(--error); }

/* ========== BADGES & FORMS ========== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; }
.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-border); }
.badge-error { background: var(--error-bg); color: var(--error); border: 1px solid var(--error-border); }
.badge-secondary { background: var(--glass); color: var(--muted); border: 1px solid var(--line); }
.form-group { margin-bottom: 20px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 8px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 12px 16px; background: var(--bg-input); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink); font-size: 14px; font-family: inherit; transition: all 0.2s ease; }
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(75, 85, 99, 0.2); }
.form-select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }

/* ========== MODALS (SCROLL + FLEX) ========== */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7); z-index: 2000;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  width: 100%; max-width: 600px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  max-height: 85vh; /* Limite de altura */
  margin: 0 auto;
}

.modal-header { padding: 16px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-body { 
  padding: 24px; 
  flex: 1 1 auto; 
  min-height: 0; /* Permite scroll */
  overflow-y: auto; 
  -webkit-overflow-scrolling: touch; 
}
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 12px; flex-shrink: 0; background: var(--glass); }

/* ========== LANÇAMENTOS LIST (GRID LAYOUT) ========== */
.lancamento-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto; /* Check | Info | Valor | Actions */
  align-items: center; gap: 16px; padding: 16px;
  background: var(--bg-elevated); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 12px; transition: all 0.2s ease;
}
.lancamento-checkbox { width: 24px; height: 24px; border: 2px solid var(--muted); border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.lancamento-checkbox.checked { background: var(--success); border-color: var(--success); }
.lancamento-checkbox.checked::after { content: '✓'; color: white; font-weight: 700; font-size: 14px; }
.lancamento-info { min-width: 0; }
.lancamento-descricao { font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lancamento-meta { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.lancamento-valor { font-size: 18px; font-weight: 700; white-space: nowrap; text-align: right; }
.lancamento-valor.receita { color: var(--success); } .lancamento-valor.despesa { color: var(--error); }
.lancamento-actions { display: flex; gap: 8px; }

/* ========== OUTROS ========== */
.toast-container { position: fixed; top: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 12px; }
.toast { background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; display: flex; align-items: center; gap: 12px; min-width: 300px; box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { border-left: 4px solid var(--success); } .toast.error { border-left: 4px solid var(--error); }
.loading { display: flex; justify-content: center; align-items: center; padding: 40px; }
.loading-spinner { width: 40px; height: 40px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 32px; color: var(--muted); }
.text-success { color: var(--success) !important; } .text-error { color: var(--error) !important; } .text-muted { color: var(--muted) !important; }
.d-flex { display: flex !important; } .justify-between { justify-content: space-between !important; } .align-center { align-items: center !important; } .gap-2 { gap: 16px !important; } .mb-3 { margin-bottom: 24px !important; }

/* ========== RESPONSIVE ========== */
@media (max-width: 1023px) {
  :root { --sidebar-width: 0px; }
  .sidebar { transform: translateX(-100%); width: 280px; } .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; width: 100%; }
  .menu-toggle { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .config-grid { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  body { font-size: 15px; /* Aumenta fonte base */ }
  .header { padding: 12px 16px; } .header-title { font-size: 18px; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; gap: 16px; }
  
  /* Stat Card Expandido */
  .stat-card { padding: 16px; width: 100%; display: flex; flex-direction: row; justify-content: space-between; align-items: center; }
  .stat-info { flex: 1; }
  
  /* Textos Maiores Mobile */
  .stat-label { font-size: 12px; }
  .stat-value { font-size: 26px; }
  
  .form-row { grid-template-columns: 1fr; gap: 16px; }
  
  /* Modal Mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { 
    max-width: 100%; width: 100%; 
    max-height: 85vh; 
    border-bottom-left-radius: 0; border-bottom-right-radius: 0; 
    border-top-left-radius: 16px; border-top-right-radius: 16px;
    margin: 0;
  }
  .modal-body { padding: 20px; max-height: 70vh; }
  
  .table-container { margin: 0 -16px; padding: 0 16px; }
  .card-body { padding: 16px; }
  
  .d-flex.gap-2 { gap: 12px; flex-direction: column; } 
  .d-flex.gap-2 button { width: 100%; margin: 0; min-width: 100%; }
  
  /* Lançamento Mobile Grid Ajustado */
  .lancamento-item {
    grid-template-areas: "info valor" "meta actions";
    grid-template-columns: 1fr auto;
    gap: 12px;
  }
  .lancamento-checkbox { display: none; } /* Oculta check p/ limpar */
  .lancamento-info { grid-area: info; }
  .lancamento-descricao { font-size: 16px; white-space: normal; } /* Quebra texto */
  .lancamento-valor { grid-area: valor; align-self: start; font-size: 18px; }
  .lancamento-meta { grid-area: meta; flex-direction: column; gap: 4px; font-size: 13px; }
  .lancamento-actions { grid-area: actions; justify-self: end; align-self: end; }
}