:root {
  --brand: #0e9f6e;
  --brand-dark: #057a55;
  --brand-soft: #def7ec;
  --side: #0f1b2d;
  --side-2: #16263d;
  --side-text: #b6c2d3;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #dc2626;
  --danger-soft: #fde8e8;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --info: #1d4ed8;
  --info-soft: #e1effe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-dark); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding-bottom: 24px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-size: 18px; font-weight: 700; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-size: 10.5px; font-weight: 400; color: var(--side-text); letter-spacing: .3px; }
.nav-group { padding: 10px 0 2px; }
.nav-group > span { display: block; padding: 6px 18px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #6f819b; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 18px; color: var(--side-text); border-left: 3px solid transparent; }
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: var(--side-2); color: #fff; border-left-color: var(--brand); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 20; }
.topbar .empresa { font-weight: 600; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 22px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; }
.page-head .spacer { flex: 1; }
.trial { background: var(--warn-soft); color: var(--warn); padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mt { margin-top: 14px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.kpi { padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .valor { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.verde .valor { color: var(--brand-dark); }
.kpi.vermelho .valor { color: var(--danger); }
.kpi.amarelo .valor { color: var(--warn); }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f5c2c2; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: #374151; font-weight: 500; }
input, select, textarea { font: inherit; height: 36px; padding: 0 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; color: var(--text); width: 100%; min-width: 0; }
textarea { height: auto; min-height: 70px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14, 159, 110, .25); border-color: var(--brand); }
input[type=checkbox] { width: 16px; height: 16px; }
.senha { position: relative; display: block; }
.senha input { padding-right: 40px; }
.olho { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 34px; height: 32px; border: 0; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 6px; }
.olho:hover { color: var(--text); }
.olho svg { width: 18px; height: 18px; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .c1 { grid-column: span 1; } .form-grid .c2 { grid-column: span 2; } .form-grid .c3 { grid-column: span 3; }
.form-grid .c4 { grid-column: span 4; } .form-grid .c5 { grid-column: span 5; } .form-grid .c6 { grid-column: span 6; }
.form-grid .c7 { grid-column: span 7; } .form-grid .c8 { grid-column: span 8; } .form-grid .c9 { grid-column: span 9; }
.form-grid .c10 { grid-column: span 10; } .form-grid .c11 { grid-column: span 11; } .form-grid .c12 { grid-column: span 12; }
.form-section { grid-column: span 12; font-weight: 600; font-size: 13px; color: var(--brand-dark); border-bottom: 1px solid var(--line); padding: 8px 0 4px; margin-top: 4px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters input, .filters select { width: auto; }
.filters .busca { min-width: 240px; flex: 1; max-width: 380px; }

.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
table.t td { padding: 9px 12px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
table.t tbody tr.click { cursor: pointer; }
table.t tbody tr.click:hover { background: #f6fbf9; }
table.t tfoot td { font-weight: 700; background: #fafbfc; border-top: 1px solid var(--line); }
table.t td.num, table.t th.num { text-align: right; white-space: nowrap; }
.vazio { padding: 40px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef0f3; color: #4b5563; white-space: nowrap; }
.badge.verde { background: var(--brand-soft); color: var(--brand-dark); }
.badge.vermelho { background: var(--danger-soft); color: var(--danger); }
.badge.amarelo { background: var(--warn-soft); color: var(--warn); }
.badge.azul { background: var(--info-soft); color: var(--info); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs a.active { color: var(--brand-dark); border-bottom-color: var(--brand); }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.lg { max-width: 920px; } .modal.xl { max-width: 1180px; } .modal.sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 12px 12px; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: entra .2s; }
.toast.erro { background: var(--danger); }
.toast.ok { background: var(--brand-dark); }
@keyframes entra { from { transform: translateY(8px); opacity: 0; } }

/* Autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); z-index: 50; max-height: 280px; overflow-y: auto; }
.ac-list div { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.ac-list div:hover, .ac-list div.sel { background: #f0faf6; }

/* Itens de documentos */
.itens td input { height: 32px; }
.totais { display: flex; justify-content: flex-end; gap: 22px; padding: 12px 4px; flex-wrap: wrap; align-items: center; }
.totais .total { font-size: 20px; font-weight: 700; color: var(--brand-dark); }

/* Login */
.auth { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-hero { background: linear-gradient(135deg, #0f1b2d 0%, #0b3b35 60%, #0e9f6e 140%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; }
.auth-hero h1 { font-size: 36px; line-height: 1.15; margin: 22px 0 14px; }
.auth-hero p { color: #c8d3e0; font-size: 16px; max-width: 520px; line-height: 1.55; }
.auth-hero ul { list-style: none; padding: 0; margin: 22px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; max-width: 520px; }
.auth-hero li::before { content: "✓"; color: #34d399; font-weight: 700; margin-right: 8px; }
.auth-box { display: flex; align-items: center; justify-content: center; padding: 32px; }
.auth-box .card { width: 100%; max-width: 420px; padding: 28px; }
.auth-box h2 { font-size: 22px; margin-bottom: 4px; }
.auth-box form { display: grid; gap: 12px; margin-top: 18px; }
.auth-box .btn { height: 42px; justify-content: center; }

/* PDV */
.pdv { display: grid; grid-template-columns: 1fr 380px; gap: 14px; height: calc(100vh - 56px - 44px); }
.pdv-left { display: flex; flex-direction: column; min-height: 0; }
.pdv-busca input { height: 52px; font-size: 18px; }
.pdv-itens { flex: 1; overflow-y: auto; margin-top: 12px; }
.pdv-right { display: flex; flex-direction: column; gap: 12px; }
.pdv-total { background: var(--side); color: #fff; border-radius: var(--radius); padding: 18px; }
.pdv-total .v { font-size: 40px; font-weight: 700; }
.pdv-atalhos { font-size: 12px; color: var(--muted); }
.kbd { display: inline-block; border: 1px solid #cbd2dc; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; background: #fff; }
.offline { background: var(--warn-soft); color: var(--warn); padding: 6px 12px; border-radius: 8px; font-weight: 600; }

/* Gráfico */
.chart { width: 100%; height: 220px; }
.chart rect.bar { fill: var(--brand); }
.chart rect.bar:hover { fill: var(--brand-dark); }
.chart text { font-size: 10px; fill: var(--muted); }
.chart line { stroke: #eef0f3; }

/* DRE */
.dre td { padding: 7px 12px; }
.dre .grupo td { font-weight: 600; background: #fafbfc; }
.dre .resultado td { font-weight: 700; border-top: 2px solid var(--line); }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pdv { grid-template-columns: 1fr; height: auto; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -260px; width: 250px; z-index: 60; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .form-grid > * { grid-column: span 12 !important; }
  .auth { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 22px; }
  .auth-hero ul { grid-template-columns: 1fr; }
  .topbar .empresa { display: none; }
}

@media print {
  .sidebar, .topbar, .no-print, .filters, .page-head .btn { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; }
}
