/* ── Variables ────────────────────────────────────────────── */
:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --border: #2a3347;
  --text: #e8edf5;
  --text-muted: #7a8ba8;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-glow: rgba(59,130,246,.18);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #a855f7;
  --font: 'Sora', sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
  --sidebar-w: 220px;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: inherit; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ── Shell ──────────────────────────────────────────────── */
.shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-icon { font-size: 22px; }
.brand-name { font-size: 13px; font-weight: 700; line-height: 1.3; color: var(--text); }
.brand-name small { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: all .15s;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--primary-glow); color: var(--primary); }
.nav-icon { font-size: 16px; }
.sidebar-footer { padding: 14px 20px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border); }

/* ── Main wrap ──────────────────────────────────────────── */
.main-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 14px 28px; flex-shrink: 0;
}
.content { flex: 1; overflow-y: auto; padding: 28px; }

/* ── Page header ────────────────────────────────────────── */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── KPI Cards ──────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.kpi-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: transform .15s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-icon { font-size: 28px; }
.kpi-info { display: flex; flex-direction: column; }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-blue { border-left: 3px solid var(--primary); }
.kpi-blue .kpi-value { color: var(--primary); }
.kpi-green { border-left: 3px solid var(--success); }
.kpi-green .kpi-value { color: var(--success); }
.kpi-red { border-left: 3px solid var(--danger); }
.kpi-red .kpi-value { color: var(--danger); }
.kpi-purple { border-left: 3px solid var(--purple); }
.kpi-purple .kpi-value { color: var(--purple); }

/* ── Card ───────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.form-card { padding: 28px; }

/* ── Toolbar ────────────────────────────────────────────── */
.toolbar { display: flex; gap: 12px; margin-bottom: 14px; }
.search-input, .select-filter {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; color: var(--text);
  outline: none; transition: border-color .15s;
}
.search-input { flex: 1; }
.search-input:focus, .select-filter:focus { border-color: var(--primary); }
.select-filter option { background: var(--bg2); }

/* ── Table ──────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 11px 16px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
.table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg3); }
.table tbody tr:last-child td { border-bottom: none; }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: 12px; }
.col-actions { width: 110px; text-align: center; }
.empty { text-align: center; color: var(--text-muted); padding: 40px !important; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 20px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
}
.badge-ativo { background: rgba(34,197,94,.15); color: var(--success); }
.badge-inativo { background: rgba(122,139,168,.15); color: var(--text-muted); }
.badge-bloqueado { background: rgba(239,68,68,.15); color: var(--danger); }

/* ── Tags (módulos) ─────────────────────────────────────── */
.modulos-wrap { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  background: rgba(59,130,246,.12); color: var(--primary);
  border: 1px solid rgba(59,130,246,.25);
  border-radius: 5px; padding: 2px 7px;
  font-size: 10px; font-weight: 600; font-family: var(--mono);
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: 8px;
  font-weight: 600; font-size: 13px; cursor: pointer;
  border: none; transition: all .15s; line-height: 1;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost {
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 16px; padding: 4px 6px; border-radius: 6px;
  transition: background .12s; display: inline-flex;
}
.btn-icon:hover { background: var(--bg3); }
.btn-icon.danger:hover { background: rgba(239,68,68,.12); }

/* ── Forms ──────────────────────────────────────────────── */
.form-section { margin-bottom: 28px; }
.section-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-muted);
  margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.span-2 { grid-column: span 2; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.form-control {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 13px; color: var(--text);
  outline: none; transition: border-color .15s; width: 100%;
}
.form-control:focus { border-color: var(--primary); }
.form-control:disabled { opacity: .5; cursor: not-allowed; }
.form-control[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .5; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control option { background: var(--bg2); }
.validation-message { color: var(--danger); font-size: 11px; }

/* ── Módulos Toggles ────────────────────────────────────── */
.modulos-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.modulo-toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); cursor: pointer;
  font-size: 12px; font-weight: 600; font-family: var(--mono);
  color: var(--text-muted); transition: all .15s;
  user-select: none;
}
.modulo-toggle input { display: none; }
.modulo-toggle:hover { border-color: var(--primary); color: var(--text); }
.modulo-toggle.active {
  background: var(--primary-glow); border-color: var(--primary);
  color: var(--primary);
}

/* ── Form actions ───────────────────────────────────────── */
.form-actions {
  display: flex; justify-content: flex-end; gap: 12px;
  padding-top: 20px; border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Alerts ─────────────────────────────────────────────── */
.alert { border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }
.alert-error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; }

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  min-width: 380px; max-width: 480px; box-shadow: var(--shadow);
}
.modal h3 { font-size: 16px; margin-bottom: 12px; }
.modal p { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.modal .form-group { margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── Spinner ────────────────────────────────────────────── */
.loading-wrap { display: flex; justify-content: center; padding: 60px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .7s linear infinite;
}
.spinner-sm {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Colors ─────────────────────────────────────────────── */
.text-danger { color: var(--danger) !important; font-weight: 600; }
.text-warning { color: var(--warning) !important; font-weight: 600; }
.text-success { color: var(--success) !important; }

/* ── 404 ────────────────────────────────────────────────── */
.not-found { text-align: center; padding: 60px; color: var(--text-muted); }
.not-found a { color: var(--primary); text-decoration: underline; margin-top: 12px; display: inline-block; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.span-2 { grid-column: span 1; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Modal Large ─────────────────────────────────────────── */
.modal-lg {
  min-width: 700px;
  max-width: 900px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.modal-header h3 { margin-bottom: 2px; }
.modal-sub { color: var(--text-muted); font-size: 12px; }

/* ── Cobranças ───────────────────────────────────────────── */
.cobrancas-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg3);
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-muted);
}
.total-pendente {
  font-weight: 700;
  font-size: 15px;
  color: var(--danger);
  font-family: var(--mono);
}
.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.empty-state span { font-size: 40px; display: block; margin-bottom: 12px; }
.btn-link {
  color: var(--primary);
  font-size: 12px;
  text-decoration: underline;
}
.btn-link:hover { opacity: .8; }
.text-muted { color: var(--text-muted); }
.alert-warning {
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.3);
  color: #fcd34d;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
}

/* ── Login ───────────────────────────────────────────────── */
.login-body { background: var(--bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-icon { font-size: 36px; display: block; margin-bottom: 8px; }
.login-brand h1 { font-size: 20px; font-weight: 700; }
.login-brand p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.input-password { position: relative; }
.input-password .form-control { padding-right: 44px; }
.btn-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px;
}
.btn-full { width: 100%; justify-content: center; margin-top: 8px; padding: 11px; font-size: 14px; }

/* ── Sidebar footer com logout ───────────────────────────── */
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; padding: 14px; border-top: 1px solid var(--border); }
.user-nome { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.btn-logout {
  background: none; border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-muted); font-size: 12px; padding: 6px 10px;
  cursor: pointer; transition: all .15s; text-align: left;
}
.btn-logout:hover { background: rgba(239,68,68,.1); color: var(--danger); border-color: var(--danger); }

/* ── Auth checking ───────────────────────────────────────── */
.auth-checking {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-body {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Totais por Status ───────────────────────────────────── */
.status-totais {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 4px;
}
.status-total-card {
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--border);
}
.status-total-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.status-total-qtd {
  font-size: 12px;
  color: var(--text-muted);
}
.status-total-valor {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--mono);
}
.card-overdue {
  background: rgba(239,68,68,.08);
  border-color: rgba(239,68,68,.25);
}
.card-overdue .status-total-label { color: var(--danger); }
.card-overdue .status-total-valor  { color: var(--danger); }

.card-pending {
  background: rgba(245,158,11,.08);
  border-color: rgba(245,158,11,.25);
}
.card-pending .status-total-label { color: var(--warning); }
.card-pending .status-total-valor  { color: var(--warning); }

.card-other {
  background: rgba(34,197,94,.08);
  border-color: rgba(34,197,94,.25);
}
.card-other .status-total-label { color: var(--success); }
.card-other .status-total-valor  { color: var(--success); }

.card-total-geral {
  background: var(--bg3);
  border-color: var(--primary);
}
.card-total-geral .status-total-label { color: var(--primary); }
.card-total-geral .status-total-valor  { color: var(--text); font-size: 18px; }

/* ── CNPJ Search ─────────────────────────────────────────── */
.cnpj-search-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.alert-success {
  background: rgba(34,197,94,.1);
  border: 1px solid rgba(34,197,94,.3);
  color: #86efac;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
}

/* ── Sync Page ───────────────────────────────────────────── */
.sync-loading {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px; gap: 16px; text-align: center;
  color: var(--text-muted);
}
.sync-loading p { font-size: 15px; color: var(--text); }
.sync-loading small { font-size: 12px; }
.sync-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px; gap: 12px; text-align: center;
  color: var(--text-muted);
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.sync-empty span { font-size: 48px; }
.sync-empty p { font-size: 14px; color: var(--text); }
.sync-empty small { font-size: 12px; line-height: 1.8; }
.badge-warning {
  background: rgba(245,158,11,.15);
  color: var(--warning);
}
