:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface2: #f1f2f9;
  --surface3: #e9ebf5;
  --border: #e3e5f0;
  --accent: #5b52f0;
  --accent2: #0d9488;
  --accent3: #ff6b6b;
  --accent4: #f59e0b;
  --text: #20232e;
  --text2: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
  --shadow-sm: 0 1px 2px rgba(30,35,60,.04), 0 1px 3px rgba(30,35,60,.06);
  --shadow-md: 0 4px 16px rgba(30,35,60,.08);
  --shadow-lg: 0 20px 60px rgba(30,35,60,.18);
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --surface3: #2a2f47;
  --border: #2d3148;
  --accent: #6c63ff;
  --accent2: #00d4aa;
  --text: #e8eaf0;
  --text2: #9ca3b8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.55);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; line-height: 1.5; }

/* Layout */
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 24px 16px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.main { padding: 32px; overflow-x: hidden; position: relative; }
.page.active { position: relative; z-index: 1; }
.app-watermark { position: absolute; inset: 0; z-index: 0; pointer-events: none; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.app-watermark img { width: 60%; max-width: 480px; opacity: 0.05; object-fit: contain; }

/* Sidebar */
.logo { font-size: 17px; font-weight: 800; color: var(--accent); margin-bottom: 4px; }
.logo span { color: var(--accent2); }
.logo-sub { font-size: 10px; color: var(--text2); font-weight: 400; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.nav-section { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text2); margin: 14px 0 6px; }
.nav-btn { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; cursor: pointer; color: var(--text2); transition: all 0.15s; border: none; background: none; width: 100%; text-align: left; font-size: 13px; }
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--surface2); color: var(--accent); font-weight: 600; }
.nav-btn .icon { font-size: 16px; width: 20px; }
.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.theme-toggle { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface2); color: var(--text2); cursor: pointer; font-size: 12px; font-weight: 600; transition: all .15s; }
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }

/* Headers */
h1 { font-size: 26px; font-weight: 800; margin-bottom: 6px; letter-spacing: -0.3px; }
h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; color: var(--text); }
h3 { font-size: 13px; font-weight: 700; margin-bottom: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.8px; }
.subtitle { color: var(--text2); margin-bottom: 32px; }
.section-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-sm); }
.card-grid { display: grid; gap: 16px; }
.card-grid-2 { grid-template-columns: 1fr 1fr; }
.card-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.card-grid-4 { grid-template-columns: repeat(4, 1fr); }
/* Sem isso, um card com conteúdo largo (ex: tabela) força o item de grid
   inteiro a estourar a coluna — o padrão min-width:auto do grid deixa o
   item crescer até o conteúdo caber, empurrando os outros junto. */
.card-grid > * { min-width: 0; }

/* KPI Cards */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text2); margin-bottom: 8px; font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 800; letter-spacing: -0.3px; }
.kpi-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.kpi-green { border-top: 3px solid var(--green); }
.kpi-red { border-top: 3px solid var(--red); }
.kpi-yellow { border-top: 3px solid var(--yellow); }
.kpi-accent { border-top: 3px solid var(--accent); }

/* Tags */
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.tag-green { background: rgba(22,163,74,0.12); color: var(--green); }
.tag-red { background: rgba(220,38,38,0.12); color: var(--red); }
.tag-yellow { background: rgba(217,119,6,0.12); color: var(--yellow); }
.tag-accent { background: rgba(91,82,240,0.12); color: var(--accent); }
.tag-cyan { background: rgba(13,148,136,0.12); color: var(--accent2); }

.section-num { background: var(--accent); color: white; width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
th { background: var(--surface2); padding: 10px 14px; text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text2); white-space: nowrap; font-weight: 700; }
th:first-child { text-align: left; }
td { padding: 10px 14px; border-top: 1px solid var(--border); text-align: right; font-size: 13px; white-space: nowrap; }
td:first-child { text-align: left; font-weight: 500; }
tr:hover td { background: var(--surface2); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.neutral { color: var(--text2); }

/* Form */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid > * { min-width: 0; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 0; }
.form-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text2); font-weight: 700; }
input[type="number"], input[type="text"], input[type="date"], input[type="email"], input[type="tel"], input[type="time"], select, textarea {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 13px; width: 100%;
  outline: none; transition: border 0.15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,82,240,.12); }
textarea { resize: vertical; min-height: 80px; font-family: inherit; font-size: 13px; }
.mini-input { padding: 5px 8px; font-size: 12px; width: 70px; text-align: center; }
.mini-select { padding: 5px 8px; font-size: 11px; width: auto; }

/* Buttons */
.btn { padding: 10px 20px; border-radius: 9px; font-size: 13px; font-weight: 700; cursor: pointer; border: none; transition: all 0.15s; }
.btn-primary { background: var(--accent); color: white; box-shadow: 0 2px 8px rgba(91,82,240,.3); }
.btn-primary:hover { background: #4a41e0; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; padding: 5px 7px; border-radius: 7px; }
.btn-icon:hover { background: var(--surface2); }

/* One-click status toggle (pago/pendente, recebido/a receber) */
.status-toggle { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; border: 1px solid transparent; cursor: pointer; transition: all .15s; }
.status-toggle:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.status-ok { background: rgba(22,163,74,0.12); color: var(--green); border-color: rgba(22,163,74,0.25); }
.status-pending { background: rgba(217,119,6,0.12); color: var(--yellow); border-color: rgba(217,119,6,0.25); }
.status-overdue { background: rgba(220,38,38,0.14); color: var(--red); border-color: rgba(220,38,38,0.3); }

/* Bar chart */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 0 8px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bar { width: 100%; border-radius: 5px 5px 0 0; transition: height 0.4s ease; min-height: 2px; }
.bar-label { font-size: 9px; color: var(--text2); white-space: pre-line; text-align: center; }
.bar-val { font-size: 9px; font-weight: 700; }

/* Constraint box */
.constraint-box { background: linear-gradient(135deg, rgba(91,82,240,0.07), rgba(13,148,136,0.05)); border: 1px solid var(--accent); border-radius: 14px; padding: 20px; }
.constraint-title { font-size: 16px; font-weight: 800; color: var(--accent); margin-bottom: 8px; }
.constraint-desc { color: var(--text2); font-size: 13px; line-height: 1.7; }
.constraint-impact { margin-top: 12px; padding: 12px; background: rgba(220,38,38,0.06); border-radius: 8px; border-left: 3px solid var(--red); }
.constraint-impact-title { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--red); margin-bottom: 4px; }

/* Scenario cards */
.scenario-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; cursor: pointer; transition: all 0.15s; box-shadow: var(--shadow-sm); }
.scenario-card:hover, .scenario-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.scenario-card.best { border-color: var(--green); box-shadow: 0 0 0 1px var(--green); }
.scenario-name { font-weight: 700; margin-bottom: 4px; }
.scenario-num { font-size: 22px; font-weight: 800; margin: 12px 0 4px; }

/* Range slider */
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-val { font-size: 13px; font-weight: 700; color: var(--accent); min-width: 50px; text-align: right; }

/* Progress */
.progress-bar { height: 6px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.4s; }

/* Executive summary */
.exec-box { background: linear-gradient(135deg, var(--surface2), var(--surface)); border: 1px solid var(--border); border-radius: 14px; padding: 24px; }
.exec-item { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.exec-item:last-child { border-bottom: none; }
.exec-q { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--accent2); min-width: 200px; }
.exec-a { color: var(--text); font-size: 13px; line-height: 1.6; }

/* Alert */
.alert { padding: 14px 18px; border-radius: 12px; font-size: 13px; margin-bottom: 16px; }
.alert-warning { background: rgba(217,119,6,0.1); border: 1px solid rgba(217,119,6,0.25); color: var(--yellow); }
.alert-danger { background: rgba(220,38,38,0.08); border: 1px solid rgba(220,38,38,0.22); color: var(--red); }
.alert-success { background: rgba(22,163,74,0.08); border: 1px solid rgba(22,163,74,0.22); color: var(--green); }
.alert-info { background: rgba(91,82,240,0.08); border: 1px solid rgba(91,82,240,0.22); color: var(--accent); }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--surface2); padding: 4px; border-radius: 12px; flex-wrap: wrap; }
.tab { flex: 1; padding: 8px; border-radius: 9px; border: none; background: none; color: var(--text2); cursor: pointer; font-size: 12px; font-weight: 600; transition: all 0.15s; white-space: nowrap; }
.tab.active { background: var(--surface); color: var(--accent); font-weight: 700; box-shadow: var(--shadow-sm); }

/* Page visibility */
.page { display: none; }
.page.active { display: block; }
.sim-page { display: none; }
.sim-page.active { display: block; }

/* Divider */
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* Input table */
.input-table { width: 100%; border-collapse: collapse; }
.input-table th { background: var(--surface2); padding: 8px 12px; text-align: center; font-size: 11px; color: var(--text2); }
.input-table th:first-child { text-align: left; }
.input-table td { padding: 4px 6px; border-top: 1px solid var(--border); }
.input-table td:first-child { padding-left: 12px; font-size: 12px; color: var(--text2); }
.input-table input { background: transparent; border: none; color: var(--text); padding: 6px 8px; width: 100%; text-align: right; font-size: 12px; border-radius: 4px; }
.input-table input:focus { background: var(--surface2); outline: 1px solid var(--accent); box-shadow: none; }

/* Projection chart */
.proj-chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding: 0 4px; position: relative; }
.proj-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 2px; }
.proj-bar { width: 100%; border-radius: 3px 3px 0 0; min-height: 2px; }
.proj-label { font-size: 8px; color: var(--text2); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,22,35,0.45); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; backdrop-filter: blur(2px); }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-close { background: none; border: none; color: var(--text2); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-body { padding: 24px; }

/* Avatar / initials circle */
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface3); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0; }

/* Tela de login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }

/* Barra superior mobile + gaveta de navegação (escondidas no desktop) */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }
.hamburger-btn { background: none; border: none; font-size: 22px; color: var(--text); cursor: pointer; padding: 6px 10px; border-radius: 8px; }
.hamburger-btn:hover { background: var(--surface2); }

@media (max-width: 900px) {
  .card-grid-4, .card-grid-3 { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .exec-item { flex-direction: column; }
}

/* ---------------- Celular: menu em gaveta, cards no lugar de tabelas ---------------- */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; display: block; }

  .mobile-topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 900;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 14px;
  }

  .sidebar {
    position: fixed; top: 0; left: -300px; width: 280px; height: 100vh; z-index: 1001;
    transition: left .25s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(20,22,35,.45); z-index: 1000;
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .main { padding: 16px; }

  h1 { font-size: 21px; }
  .card-grid-4, .card-grid-3, .card-grid-2 { grid-template-columns: 1fr; }

  /* Modais ocupam a tela inteira */
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal-box { max-width: 100%; max-height: 100vh; height: 100%; border-radius: 0; }

  /* Alvos de toque maiores */
  .btn, .btn-icon, .status-toggle, .nav-btn, .tab { min-height: 42px; }
  .btn-icon { min-width: 42px; }

  /* Tabelas viram cards empilhados (aplicado a .table-responsive-cards) */
  .table-responsive-cards table, .table-responsive-cards thead, .table-responsive-cards tbody,
  .table-responsive-cards th, .table-responsive-cards td, .table-responsive-cards tr { display: block; }
  .table-responsive-cards thead { display: none; }
  .table-responsive-cards tr {
    margin-bottom: 12px; border: 1px solid var(--border); border-radius: 12px;
    padding: 6px 12px; background: var(--surface); box-shadow: var(--shadow-sm);
  }
  .table-responsive-cards tr:last-child { margin-bottom: 0; }
  .table-responsive-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    text-align: right; padding: 8px 0; border-top: 1px solid var(--border); white-space: normal;
  }
  .table-responsive-cards td:first-child { border-top: none; padding-top: 10px; }
  .table-responsive-cards td:last-child { padding-bottom: 10px; }
  .table-responsive-cards td::before {
    content: attr(data-label); font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text2); text-align: left; margin-right: auto;
  }
  .table-responsive-cards td:first-child::before { content: none; }
}

@media (max-width: 480px) {
  .kpi-value { font-size: 20px; }
  .modal-body { padding: 16px; }
  .simulacao-row { flex-direction: column; align-items: flex-start !important; gap: 4px; }
  .simulacao-row span:last-child { text-align: left !important; }
}
