:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f2;
  --text: #1a2233;
  --muted: #6b7789;
  --primary: #002255;
  --primary-dark: #001a44;
  --primary-soft: #e4eaf1;
  --green: #4fba25;
  --green-dark: #3f9a1d;
  --green-soft: #eaf7e1;
  --red: #dc2626;
  --red-soft: #fdecec;
  --amber: #d97706;
  --amber-soft: #fdf3e3;
  --sidebar: #002255;
  --sidebar-muted: #8fa0bd;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.16);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
a { text-decoration: none; color: inherit; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px; background: var(--sidebar); color: #cdd7e6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; flex-direction: column; gap: 6px; padding: 22px 20px 18px; }
.brand-img { width: 100%; max-width: 172px; height: auto; display: block; }
.brand-tag { color: var(--sidebar-muted); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; padding-left: 2px; }
.nav { display: flex; flex-direction: column; padding: 8px 12px; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-radius: 9px; color: var(--sidebar-muted); font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item .ico { font-size: 16px; width: 18px; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #eef3fb; }
.nav-item.active { background: var(--green); color: #002255; font-weight: 700; }
.nav-item.active .ico { color: #002255; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.link-danger { background: none; border: none; color: #ff8f8f; font-size: 13px; padding: 0; }
.link-danger:hover { color: #ffb3b3; }
.version { color: var(--sidebar-muted); font-size: 11px; margin-top: 10px; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 22px 32px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar p { font-size: 13px; margin-top: 2px; }
.view { padding: 28px 32px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 9px; font-size: 14px; font-weight: 600;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.95); }
.btn-ghost { background: none; border: none; color: var(--muted); padding: 6px 8px; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Cards / KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--muted); }
.kpi.k-total::before { background: var(--primary); }
.kpi.k-vencida::before { background: var(--red); }
.kpi.k-vence::before { background: var(--amber); }
.kpi.k-paga::before { background: var(--green); }
.kpi .kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.kpi .kpi-value { font-size: 25px; font-weight: 700; margin-top: 8px; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.k-vencida .kpi-value { color: var(--red); }
.kpi.k-vence .kpi-value { color: var(--amber); }
.kpi.k-paga .kpi-value { color: var(--green); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.card-head h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; font-size: 13.5px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
td { border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-vencida td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; opacity: .5; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge::before { content:""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-aberto { background: var(--primary-soft); color: var(--primary-dark); }
.badge-pago { background: var(--green-soft); color: var(--green); }
.badge-vencida { background: var(--red-soft); color: var(--red); }
.badge-aprovada { background: #ede9fe; color: #6d28d9; }
.tag { display:inline-block; padding: 2px 9px; border-radius: 6px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* ---------- Filters ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.field-inline { display: flex; flex-direction: column; gap: 4px; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px;
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search { min-width: 240px; }
select.compact, input.compact { padding: 8px 10px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-field .hint { font-size: 12px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-chip { border: 1px solid var(--border); border-radius: 9px; padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface); }
.radio-chip.active { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }
#novo-forn-box { display: flex; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,27,45,.5); backdrop-filter: blur(2px);
  display: grid; place-items: center; z-index: 50; padding: 24px;
}
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 18px; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--sidebar); color: #fff; padding: 13px 22px; border-radius: 10px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); z-index: 100;
  animation: rise .2s ease-out;
}
.toast.err { background: var(--red); }
@keyframes rise { from { transform: translate(-50%, 12px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- Misc ---------- */
.list-line { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-line:last-child { border-bottom: none; }
.list-line .ll-main { font-weight: 600; }
.list-line .ll-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.bar-row { margin-bottom: 14px; }
.bar-row .bar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.bar-track { height: 9px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.actions-cell { display: flex; gap: 4px; justify-content: flex-end; }
.icon-btn { background: none; border: 1px solid transparent; width: 30px; height: 30px; border-radius: 8px; color: var(--muted); font-size: 15px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn.danger:hover { color: var(--red); background: var(--red-soft); }
.pill-filter { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.pill-filter button { background: none; border: none; padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.pill-filter button.active { background: var(--surface); color: var(--primary-dark); box-shadow: var(--shadow); }
.mini-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.mini-cards.mc4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1024px) { .mini-cards.mc4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .mini-cards.mc4 { grid-template-columns: 1fr; } }
.mini-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.mini-card .mc-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.mini-card .mc-value { font-size: 19px; font-weight: 700; margin-top: 4px; }
.overdue-txt { color: var(--red); font-weight: 600; }
.soon-txt { color: var(--amber); font-weight: 600; }

/* Barra de ações (Pagamentos do Dia) */
.day-actionbar { border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.day-actionbar:empty { display: none; }
.day-actionbar-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; flex-wrap: wrap; }

/* ---------- Login ---------- */
#login-screen {
  position: fixed; inset: 0; z-index: 200; overflow: auto;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #0a3170 0%, var(--sidebar) 60%);
}
.login-card {
  background: var(--surface); width: 100%; max-width: 400px; border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 36px 32px; text-align: center;
}
.login-logo { width: 210px; max-width: 70%; height: auto; margin: 0 auto 10px; display: block; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.login-card .form-field { text-align: left; margin-bottom: 16px; }
.login-card .btn-block { margin-top: 6px; }
.login-error {
  background: var(--red-soft); color: var(--red); border: 1px solid #f5c2c2;
  border-radius: 9px; padding: 10px 12px; font-size: 13px; font-weight: 500; margin-bottom: 16px; text-align: left;
}

/* ---------- Caixa de usuário (sidebar) ---------- */
.user-box { margin-bottom: 12px; }
.user-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: #002255;
  font-weight: 700; display: grid; place-items: center; flex-shrink: 0; font-size: 15px;
}
.user-meta { min-width: 0; }
.user-email { color: #eef3fb; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--sidebar-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.user-actions { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.link-btn { background: none; border: none; color: var(--sidebar-muted); font-size: 12.5px; padding: 2px 0; }
.link-btn:hover { color: #eef3fb; }
.link-btn.danger { color: #ff8f8f; }
.link-btn.danger:hover { color: #ffb3b3; }

/* ---------- Impressão de relatórios ---------- */
#print-area { display: none; }
.rep-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--primary); padding-bottom: 10px; margin-bottom: 16px; }
.rep-logo { height: 44px; width: auto; display: block; }
.rep-title { font-size: 15px; color: var(--primary); font-weight: 700; margin-top: 8px; }
.rep-meta { font-size: 12px; color: #555; text-align: right; }
.rep-sec { font-size: 14px; margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 1px solid #ccc; }
.rep-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.rep-table th, .rep-table td { border: 1px solid #ccc; padding: 5px 8px; font-size: 12px; text-align: left; }
.rep-table th { background: #f0f0f0; }
.rep-table .num { text-align: right; }
.rep-total td { font-weight: 700; background: #f7f7f7; }
.rep-grand { text-align: right; font-size: 15px; margin-top: 14px; padding-top: 10px; border-top: 2px solid #222; }

@media print {
  #app, #modal-backdrop, #toast, #sidebar-overlay, #login-screen { display: none !important; }
  #print-area { display: block !important; padding: 0; color: #000; }
  @page { margin: 16mm; }
  body { background: #fff; }
}

/* Topbar left + menu button */
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.menu-btn {
  display: none; background: none; border: 1px solid var(--border); color: var(--text);
  width: 42px; height: 42px; border-radius: 10px; font-size: 20px; flex-shrink: 0;
}
.menu-btn:hover { background: var(--surface-2); }
.btn-mini { display: none; }

/* Sidebar overlay (mobile) */
.sidebar-overlay { position: fixed; inset: 0; background: rgba(15,27,45,.5); z-index: 30; }

/* Paginação */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager-info { font-size: 13px; color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Responsivo: tablet ---------- */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .mini-cards { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Responsivo: mobile ---------- */
@media (max-width: 760px) {
  .menu-btn { display: grid; place-items: center; }
  /* Sidebar vira drawer deslizante */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 264px; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .brand-text, .nav-item span, .sidebar-footer { display: flex; }
  .nav-item { font-size: 15px; padding: 13px 14px; }

  .topbar { padding: 14px 16px; }
  .topbar h1 { font-size: 18px; }
  #page-subtitle { display: none; }
  .view { padding: 16px; }

  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .kpi-value { font-size: 20px; }
  .mini-cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }

  /* Botão "Nova conta" compacto */
  .btn-full { display: none; }
  .btn-mini { display: inline; font-size: 20px; line-height: 1; }
  #btn-nova-conta { padding: 10px 15px; }

  /* Tabelas: oculta categoria, reduz espaçamento */
  .col-cat { display: none; }
  th, td { padding: 10px 10px; font-size: 13px; }
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { width: 100% !important; }
  .search { min-width: 0; }
  .pill-filter { width: 100%; overflow-x: auto; }

  /* Modal ocupa quase a tela toda */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 94vh; border-radius: 18px 18px 0 0; }
  .modal-body { padding: 18px; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
}

@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
