:root {
  --bg: #f3f5f9; --card: #ffffff; --ink: #172033; --muted: #66728a; --line: #e3e8f0;
  --nav: #0e1d3a; --nav-ink: #b9c4dc; --accent: #0d9488; --accent-d: #0a7a70;
  --nfce: #0d9488; --nfe: #3b5bdb; --cte: #f08c00; --danger: #d6336c; --ok: #2f9e44;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--ink); background: var(--bg); }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0; } h3 { font-size: 14px; margin: 0; }
a { color: var(--accent-d); text-decoration: none; } a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .right { text-align: right; } .nowrap { white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--nav); color: var(--nav-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand i { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.side a.nav { display: flex; align-items: center; gap: 10px; color: var(--nav-ink); padding: 9px 12px; border-radius: 8px; font-weight: 500; text-decoration: none; }
.side a.nav:hover { background: rgba(255,255,255,.07); color: #fff; }
.side a.nav.on { background: rgba(13,148,136,.22); color: #fff; }
.side .sp { flex: 1; }
.side .who { font-size: 12px; padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.1); }
.side .who b { color: #fff; display: block; font-size: 13px; }
.side .btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #e6ecf8; }
.side .btn:hover { background: rgba(255,255,255,.16); }
.main { padding: 22px 28px 40px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.top .grow { flex: 1; }
.top p { margin: 2px 0 0; }

/* componentes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 16px 18px; }
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card > header small { color: var(--muted); }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); } .g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.mt { margin-top: 16px; }
.kpi { position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c, var(--accent)); }
.kpi .lb { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 24px; font-weight: 700; margin: 4px 0 2px; }
.kpi .s { color: var(--muted); font-size: 12.5px; }
.chip { white-space: nowrap; display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef2f7; color: #435069; }
.chip.NFCE { background: #d7f3ef; color: #0a6b62; } .chip.NFE { background: #e0e7ff; color: #2b44a8; } .chip.CTE { background: #ffe9c7; color: #9a5a00; }
.chip.ok { background: #dff5e3; color: #1f7a33; } .chip.off { background: #fde1ea; color: #a4204f; }
.chip.warn { background: #fff0cc; color: #8a5a00; }
code { background: #eef2f7; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.chip.cancelada { background: #fde1ea; color: #a4204f; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover td { background: #f7f9fc; }
.tscroll { overflow-x: auto; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

.btn { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { background: #f4f7fb; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: #fff; } .btn.pri:hover { background: var(--accent-d); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; } .btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .sel { border: 1px solid #cfd6e3; border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0; }
.field input:focus, .field select:focus, .field textarea:focus, .sel:focus { outline: 2px solid rgba(13,148,136,.35); border-color: var(--accent); }
.form { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.form .full { grid-column: 1 / -1; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.err { color: var(--danger); font-weight: 600; min-height: 18px; margin-top: 8px; }

/* modal e toast */
.overlay { position: fixed; inset: 0; background: rgba(14,29,58,.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: 92vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin-bottom: 14px; } .modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 80; }
.toast { background: #172033; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); }
.toast.bad { background: var(--danger); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #0e1d3a 0%, #12335c 55%, #0d6f68 100%); }
.login .box { width: min(400px, 100%); background: #fff; border-radius: 16px; padding: 32px 30px; box-shadow: 0 24px 70px rgba(0,0,0,.35); }
.login .brand { color: var(--ink); padding: 0 0 6px; font-size: 22px; }
.login .field { margin-top: 14px; } .login .btn { width: 100%; margin-top: 20px; padding: 11px; }

/* graficos */
.chart { width: 100%; position: relative; } .chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 90; pointer-events: none; background: #172033; color: #fff; border-radius: 8px; padding: 8px 11px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 260px; }
.tip b { display: block; margin-bottom: 3px; } .tip .r { display: flex; justify-content: space-between; gap: 14px; }
.tip .r i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.hbar { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,2fr) auto; align-items: center; gap: 10px; padding: 5px 0; }
.hbar .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .b { height: 10px; background: #edf1f7; border-radius: 99px; overflow: hidden; } .hbar .b i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.dl { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px 18px; }
.dl div span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; } .dl div b { font-weight: 500; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 0 10px 0 4px; } .side .sp, .side .who { display: none; }
  .main { padding: 16px 14px 30px; } .g2, .g4 { grid-template-columns: 1fr; } .form { grid-template-columns: 1fr; }
}

/* ---- Monitoramento de NFC-e: cartoes compactos por empresa */
.mn-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 13.5px; box-shadow: var(--shadow); }
.mn-bar i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px #2f9e4422; }
.mn-bar.off i { background: var(--danger); box-shadow: 0 0 0 3px #d6336c22; }
.mn-bar span { color: var(--muted); }
.mn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 430px), 1fr)); gap: 14px; align-items: start; }
.mn-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 13px 15px 12px; display: flex; flex-direction: column; gap: 10px; }
.mn-h { display: flex; flex-direction: column; gap: 6px; }
.mn-nome b { font-size: 15px; display: block; line-height: 1.25; }
.mn-nome span { color: var(--muted); font-size: 12.5px; }
.mn-ser { display: flex; flex-wrap: wrap; gap: 4px; }
.mn-src { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.mn-b { background: #f7f9fc; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0; }
.mn-l { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px; }
.mn-s { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; font-size: 12.5px; }
.mn-m { color: var(--muted); font-size: 12.5px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mn-n { display: flex; gap: 12px; margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.mn-n b { color: var(--ink); font-size: 14px; }
.mn-info { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 9px; }
.mn-info b { color: var(--ink); }
.mn-act { display: flex; flex-wrap: wrap; gap: 6px; }
.mn-vazio { background: #fbfcfe; gap: 6px; } .mn-vazio .mn-m { margin: 0; }

.acts-lote { display: flex; gap: 8px; flex-wrap: wrap; }
.btn:disabled { opacity: .6; cursor: wait; }
