/* ─── RESET & VARS ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #07090f;
  --bg2:        #0d1220;
  --surface:    #111827;
  --surface2:   #1a2235;
  --surface3:   #222d42;
  --border:     #243047;
  --border2:    #2e3d5c;
  --gold:       #f0b429;
  --gold-dim:   #b8872a;
  --gold-bg:    rgba(240,180,41,0.08);
  --green:      #22c55e;
  --green-bg:   rgba(34,197,94,0.1);
  --red:        #f43f5e;
  --red-bg:     rgba(244,63,94,0.1);
  --blue:       #38bdf8;
  --blue-bg:    rgba(56,189,248,0.1);
  --purple:     #a78bfa;
  --text:       #e2e8f0;
  --text-muted: #64748b;
  --text-dim:   #94a3b8;
  --font:       'Sora', sans-serif;
  --mono:       'JetBrains Mono', monospace;
  --sidebar-w:  220px;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);
  --transition: 0.18s ease;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── SCROLLBAR ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ─── LOGIN ─────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 20% 60%, rgba(240,180,41,0.07) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(56,189,248,0.06) 0%, transparent 50%),
              var(--bg);
}
.login-card {
  position: relative;
  width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; color: var(--gold);
  margin-bottom: 32px;
}
.login-card h1 { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.login-card > p { color: var(--text-muted); margin-bottom: 28px; }
.login-erro {
  background: var(--red-bg); border: 1px solid var(--red);
  color: var(--red); padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px;
}
.btn-full { width: 100%; justify-content: center; margin-top: 8px; }

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

/* ─── SIDEBAR ────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px; font-size: 15px; font-weight: 700;
  color: var(--gold); border-bottom: 1px solid var(--border);
}
#sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: var(--transition);
  margin-bottom: 2px;
}
.nav-item svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--gold-bg); color: var(--gold); border: 1px solid rgba(240,180,41,0.2); }
.nav-separator { height: 1px; background: var(--border); margin: 10px 0; }
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.user-info { display: flex; align-items: center; gap: 10px; overflow: hidden; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gold); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
#user-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px; border-radius: var(--radius-sm);
  display: flex; align-items: center; transition: var(--transition);
}
.btn-logout:hover { color: var(--red); background: var(--red-bg); }
.btn-logout svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ─── MAIN ───────────────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1; min-height: 100vh;
  background: var(--bg);
}
.page { display: none; padding: 32px; }
.page.active { display: block; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ─── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: 1px solid transparent;
  transition: var(--transition); line-height: 1;
  text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--gold); color: #080d16; border-color: var(--gold); }
.btn-primary:hover { background: #e0a820; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border2); }
.btn-outline:hover { background: var(--surface2); border-color: var(--border2); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-success { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-xs { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border: none; background: none; cursor: pointer; color: var(--text-muted); border-radius: var(--radius-sm); transition: var(--transition); }
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ─── FORMS ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; letter-spacing: 0.03em; text-transform: uppercase; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 13.5px;
  transition: var(--transition);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(240,180,41,0.12); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }
.full-input { width: 100%; padding: 9px 12px; }
.full-select { width: 100%; padding: 9px 12px; }
select option { background: var(--surface); }

/* ─── FILTERS ────────────────────────────────────────────────── */
.filters-bar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 18px;
}
.filter-input { padding: 8px 12px; border-radius: var(--radius-sm); min-width: 200px; }
.filter-select { padding: 8px 12px; border-radius: var(--radius-sm); }
.filter-num { min-width: 110px !important; }
.select-sm { padding: 6px 10px; border-radius: var(--radius-sm); font-size: 13px; }

/* ─── TABLES ─────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead tr { background: var(--surface); }
.data-table th {
  padding: 12px 14px; text-align: left;
  font-size: 11.5px; font-weight: 700; color: var(--text-muted);
  letter-spacing: 0.06em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-size: 13.5px; vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface2); }
.td-actions { display: flex; gap: 4px; }
.mono { font-family: var(--mono); }

/* ─── BADGES / STATUS ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-gold   { background: var(--gold-bg);   color: var(--gold); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-gray   { background: var(--surface3);  color: var(--text-dim); }
.badge-purple { background: rgba(167,139,250,0.12); color: var(--purple); }

/* ─── KPI CARDS ──────────────────────────────────────────────── */
.cards-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
}
.kpi-card.green::before { background: var(--green); }
.kpi-card.red::before   { background: var(--red); }
.kpi-card.gold::before  { background: var(--gold); }
.kpi-card.blue::before  { background: var(--blue); }
.kpi-label { display: block; font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.kpi-value { display: block; font-family: var(--mono); font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.kpi-card.green .kpi-value { color: var(--green); }
.kpi-card.red .kpi-value   { color: var(--red); }
.kpi-card.gold .kpi-value  { color: var(--gold); }
.kpi-card.blue .kpi-value  { color: var(--blue); }
.kpi-sub { font-size: 12px; color: var(--text-muted); }

/* ─── CHARTS ─────────────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px; }
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.chart-card.large { }
.chart-header { font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 16px; }
.chart-card canvas { max-height: 220px; }

/* ─── TOTAIS BAR ─────────────────────────────────────────────── */
.totais-bar {
  margin-top: 16px; padding: 14px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; gap: 24px; flex-wrap: wrap;
}
.totais-bar .t-item { display: flex; flex-direction: column; gap: 2px; }
.totais-bar .t-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.totais-bar .t-val { font-family: var(--mono); font-size: 15px; font-weight: 600; }

/* ─── MODAL ──────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 14px;
  width: 100%; max-width: 600px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; padding: 4px; border-radius: 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.modal-wide { max-width: 800px; }
.modal-xl { max-width: 1000px; }

/* ─── TOAST ──────────────────────────────────────────────────── */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent;
  min-width: 260px; max-width: 380px;
  animation: slideIn 0.2s ease;
  box-shadow: var(--shadow);
}
.toast-success { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.toast-error   { background: var(--red-bg);   border-color: var(--red);   color: var(--red); }
.toast-info    { background: var(--blue-bg);  border-color: var(--blue);  color: var(--blue); }
.toast-warn    { background: var(--gold-bg);  border-color: var(--gold);  color: var(--gold); }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }

/* ─── LOADING ────────────────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9990;
  background: rgba(7,9,15,0.8); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.spinner-wrap { text-align: center; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--border2); border-top-color: var(--gold);
  animation: spin 0.7s linear infinite; margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-wrap p { color: var(--text-dim); font-size: 14px; }

/* ─── DROP ZONE ──────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border2);
  border-radius: var(--radius);
  padding: 36px 20px; text-align: center;
  cursor: pointer; transition: var(--transition);
  position: relative; margin-bottom: 16px;
  color: var(--text-muted);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--gold); background: var(--gold-bg); color: var(--gold);
}
.drop-zone svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.5; margin-bottom: 10px; }
.drop-zone p { font-size: 13.5px; }
.drop-zone small { font-size: 12px; opacity: 0.7; }
.drop-zone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ─── CNAB PAGE ──────────────────────────────────────────────── */
.cnab-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cnab-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cnab-card.full-width { grid-column: 1 / -1; }
.cnab-card-header {
  padding: 14px 18px; display: flex; align-items: center; gap: 10px;
  font-size: 13.5px; font-weight: 700;
  background: var(--surface2); border-bottom: 1px solid var(--border);
}
.cnab-card-header svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.cnab-card-header.green { color: var(--green); }
.cnab-card-header.blue  { color: var(--blue); }
.cnab-card-header.gold  { color: var(--gold); }
.cnab-card-body { padding: 18px; }
.log-box {
  background: var(--bg2); border-radius: var(--radius-sm);
  border: 1px solid var(--border); padding: 14px;
  height: 180px; overflow-y: auto; font-family: var(--mono); font-size: 12px;
  color: var(--text-dim);
}
.log-placeholder { color: var(--text-muted); text-align: center; margin-top: 60px; }
.log-entry { margin-bottom: 4px; }
.log-entry.ok   { color: var(--green); }
.log-entry.err  { color: var(--red); }
.log-entry.info { color: var(--blue); }
.log-entry.warn { color: var(--gold); }

/* ─── TABS ───────────────────────────────────────────────────── */
.tabs-bar { display: flex; gap: 0; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none; border: none; cursor: pointer;
  font-family: var(--font); font-size: 13.5px; font-weight: 600;
  color: var(--text-muted); padding: 10px 18px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: var(--transition);
}
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── CONCILIAÇÃO ────────────────────────────────────────────── */
.conc-grid { display: grid; grid-template-columns: 380px 1fr; gap: 16px; }
.conc-upload-card, .conc-result-card, .conc-history-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
}
.conc-history-card.full-width { grid-column: 1 / -1; }
.conc-upload-card h3, .conc-result-card h3, .conc-history-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.text-muted { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; line-height: 1.6; }
.conc-status-placeholder { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.conc-status-placeholder svg { width: 36px; height: 36px; fill: none; stroke: currentColor; stroke-width: 1.5; margin-bottom: 12px; opacity: 0.4; }
.conc-result-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.conc-result-row:last-child { border-bottom: none; }
.conc-result-row .label { color: var(--text-muted); }
.conc-result-row .val { font-family: var(--mono); font-weight: 600; }
.conc-result-row.match .val { color: var(--green); }
.conc-result-row.diff .val { color: var(--red); }
.conc-alert { padding: 14px 18px; border-radius: var(--radius-sm); margin-top: 16px; font-weight: 600; font-size: 14px; }
.conc-alert.ok { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.conc-alert.err { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }

/* ─── GRUPOS DESPESAS ────────────────────────────────────────── */
.grupo-block { margin-bottom: 20px; }
.grupo-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
}
.grupo-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.grupo-dot { width: 10px; height: 10px; border-radius: 50%; }
.grupo-total { font-family: var(--mono); font-size: 13.5px; color: var(--red); }
.grupo-content { border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }

/* ─── CONFIG ─────────────────────────────────────────────────── */
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.config-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.config-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.usuarios-lista { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.user-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--surface2); border-radius: var(--radius-sm); }
.user-row-email { font-size: 13.5px; }
.user-row-role { font-size: 12px; color: var(--text-muted); }

/* ─── IA RESULT ──────────────────────────────────────────────── */
.ia-result {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-top: 16px;
}
.ia-result h4 { font-size: 13px; font-weight: 700; color: var(--gold); margin-bottom: 12px; }
.ia-field { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.ia-field:last-child { border-bottom: none; }
.ia-field .ia-label { color: var(--text-muted); }
.ia-field .ia-val { font-weight: 600; font-family: var(--mono); }

/* ─── MISC ───────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 1.5; margin-bottom: 12px; opacity: 0.4; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.color-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; cursor: pointer; border: 2px solid transparent; }
.color-dot.selected { border-color: var(--text); }
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 1100px) {
  .cards-row { grid-template-columns: repeat(2,1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .cnab-grid { grid-template-columns: 1fr; }
  .conc-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  #sidebar { transform: translateX(-100%); }
  #main { margin-left: 0; }
  .cards-row { grid-template-columns: 1fr; }
}
