/* NZ Cobrança: tema claro (padrão) e escuro via [data-theme]. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --border: #e3e7ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d5bd8;
  --primary-hover: #1749b0;
  --primary-soft: #e7eefc;
  --accent: #f5a524;
  --success: #138a4c;
  --success-soft: #e3f5eb;
  --danger: #c8322b;
  --danger-soft: #fbe9e8;
  --warning: #b26a00;
  --warning-soft: #fdf1dc;
  --historico: #6d3fc0;
  --historico-soft: #efe7fb;
  --sidebar: #0e1a33;
  --sidebar-text: #b9c4dc;
  --sidebar-active: #1d5bd8;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 10px;
  --chart-line: #1d5bd8;
  --chart-fill: rgba(29, 91, 216, .12);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0a1020;
  --surface: #111a2d;
  --surface-2: #0e1627;
  --border: #22304b;
  --text: #e5ebf5;
  --muted: #8d9ab3;
  --primary: #4f86f7;
  --primary-hover: #6d9bff;
  --primary-soft: #18284a;
  --accent: #f7b543;
  --success: #3ccf7f;
  --success-soft: #11301f;
  --danger: #ff6b62;
  --danger-soft: #3a1716;
  --warning: #f2b04a;
  --warning-soft: #3a2a0f;
  --historico: #c4a6f5;
  --historico-soft: #2c1f45;
  --sidebar: #070c18;
  --sidebar-text: #93a0bb;
  --sidebar-active: #2f6be6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --chart-line: #6d9bff;
  --chart-fill: rgba(109, 155, 255, .16);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.hidden { display: none !important; }
svg.ic { width: 18px; height: 18px; flex: none; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: #fff; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #1e3a8a); border: 1px solid #93c5fd;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; font-style: italic;
}
.brand b { display: block; font-size: 15px; letter-spacing: .2px; }
.brand small { color: var(--sidebar-text); font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; padding: 14px 12px 6px; opacity: .6; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav a.ativo { background: var(--sidebar-active); color: #fff; }
.nav .badge { margin-left: auto; background: var(--accent); color: #111; border-radius: 99px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.sidebar-footer { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; font-weight: 650; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }

.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; z-index: 20;
}
.dropdown-menu button { width: 100%; text-align: left; justify-content: flex-start; }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-header h2 { font-size: 15px; font-weight: 650; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.kpi { padding: 16px 18px; }
.kpi .rotulo { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.kpi .valor { font-size: 22px; font-weight: 700; margin-top: 6px; }
.kpi .det { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.destaque { border-left: 4px solid var(--primary); }
.kpi.verde { border-left: 4px solid var(--success); }
.kpi.vermelho { border-left: 4px solid var(--danger); }
.kpi.amarelo { border-left: 4px solid var(--accent); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); background: var(--success); }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-icon { padding: 7px; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); padding: 3px; border-radius: 9px; }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer; }
.tabs button.ativo { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Formulários ---------- */
.campo { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
input[type="checkbox"], input[type="radio"] { width: auto; padding: 0; margin: 0; flex: none; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filtros .campo { min-width: 140px; }
.filtros .busca { flex: 1; min-width: 200px; }
.check { display: flex; align-items: center; justify-content: flex-start; text-align: left; gap: 8px; font-weight: 500; color: var(--text); font-size: 13px; }
.opcoes-parcela { display: flex; flex-direction: column; gap: 6px; }
.opcoes-parcela .check { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px; }
.opcoes-parcela .check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- Tabelas ---------- */
.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 650; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.acoes { text-align: right; white-space: nowrap; }
th.r, td.r { text-align: right; }
tfoot td { font-weight: 700; background: var(--surface-2); }
.vazio { padding: 40px 20px; text-align: center; color: var(--muted); }

.tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.tag.aberto, .tag.aberta, .tag.pendente { background: var(--primary-soft); color: var(--primary); }
.tag.pago, .tag.concluida, .tag.conciliado { background: var(--success-soft); color: var(--success); }
.tag.vencido { background: var(--danger-soft); color: var(--danger); }
.tag.hoje { background: var(--warning-soft); color: var(--warning); }
.tag.cancelado, .tag.cancelada, .tag.ignorado { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag.em_andamento { background: var(--warning-soft); color: var(--warning); }
.tag.em_cobranca { background: #f3e8ff; color: #7e22ce; }
:root[data-theme="dark"] .tag.em_cobranca { background: #2e1a47; color: #d8b4fe; }

/* ---------- Modal / avisos ---------- */
.modal-fundo { position: fixed; inset: 0; background: rgba(5, 10, 25, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal.largo { width: min(1120px, 100%); }
.modal-header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.avisos { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.aviso { background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 9px; box-shadow: var(--shadow); max-width: 380px; animation: entrar .2s ease-out; }
.aviso.erro { background: var(--danger); color: #fff; }
.aviso.ok { background: var(--success); color: #fff; }
@keyframes entrar { from { transform: translateY(8px); opacity: 0; } }
.alerta { padding: 12px 14px; border-radius: 9px; background: var(--warning-soft); color: var(--warning); font-weight: 500; }
.btn-historico { background: var(--historico-soft); border-color: var(--historico); color: var(--historico); white-space: normal; text-align: left; max-width: 520px; line-height: 1.35; }
.btn-historico:hover { filter: brightness(0.97); background: var(--historico-soft); }
.btn-historico b { color: inherit; }
.tag.historico { background: var(--historico); color: #fff; }
.alerta.historico { background: var(--historico-soft); color: var(--historico); }
.alerta.info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Login ---------- */
.login-pagina { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-lado {
  background: radial-gradient(circle at 20% 20%, #1d5bd8 0, transparent 50%), radial-gradient(circle at 80% 80%, #f5a524 0, transparent 45%), #0e1a33;
  color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-lado h2 { font-size: 34px; max-width: 460px; line-height: 1.15; }
.login-lado p { color: #c9d4ea; max-width: 440px; font-size: 15px; }
.login-form { display: grid; place-items: center; padding: 32px; background: var(--bg); position: relative; }
.login-form form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-form h1 { font-size: 24px; }
.login-form .tema { position: absolute; top: 18px; right: 18px; }

/* ---------- Gráfico ---------- */
.grafico { width: 100%; height: 260px; display: block; }
.grafico text { fill: var(--muted); font-size: 11px; }
.grafico .grade { stroke: var(--border); stroke-width: 1; }
.grafico .zero { stroke: var(--danger); stroke-dasharray: 4 4; opacity: .7; }
.grafico .linha { fill: none; stroke: var(--chart-line); stroke-width: 2.2; }
.grafico .area { fill: var(--chart-fill); }
.grafico .ponto { fill: var(--chart-line); }
.grafico-tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px; border-radius: 7px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); }

.os-itens td { padding: 6px 8px; }
.os-itens input { padding: 6px 8px; }
.resumo-os { display: flex; justify-content: flex-end; gap: 28px; padding: 10px 4px; font-size: 13px; }
.resumo-os b { font-size: 16px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-21 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .layout.menu-aberto .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px 16px 40px; }
  .grid-2, .form-grid { grid-template-columns: 1fr; }
  .login-pagina { grid-template-columns: 1fr; }
  .login-lado { display: none; }
  .user-chip .nome { display: none; }
}
@media (max-width: 520px) { .grid-4 { grid-template-columns: 1fr; } }

/* ---------- Log de alterações ---------- */
tr.clicavel { cursor: pointer; }
tr.clicavel:hover td { background: var(--surface-2); }
.log-campos { width: auto; margin: 4px 0; }
.log-campos th, .log-campos td { padding: 4px 12px 4px 0; border: 0; }

/* ---------- Ordenação das tabelas ---------- */
th.ordenavel { cursor: pointer; user-select: none; white-space: nowrap; }
th.ordenavel:hover { color: var(--text); }
th.ordenavel::after { content: '↕'; margin-left: 4px; opacity: .3; }
th.ordem-asc::after { content: '▲'; opacity: .9; }
th.ordem-desc::after { content: '▼'; opacity: .9; }

/* ---------- Previsão: valores que mostram os lançamentos ---------- */
td.detalhavel { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
td.detalhavel:hover, td.detalhavel.ativa { background: var(--surface-2); }
.item-estoque { display: flex; gap: 6px; margin-top: 4px; }
.item-estoque input { flex: 1; min-width: 0; font-size: 12px; }
.item-estoque select { width: auto; max-width: 150px; font-size: 12px; padding: 4px 6px; }
.item-saldo { font-size: 12px; margin-top: 2px; }
.item-saldo:empty { display: none; }
.item-servico { display: inline-flex; align-items: center; padding: 4px 10px; font-size: 12px; font-weight: 600; border-radius: 7px;
  border: 1px solid var(--historico); background: var(--historico-soft); color: var(--historico); white-space: nowrap; }
.item-servico[hidden] { display: none; }
.os-itens td.c, .os-itens th.c { text-align: center; }
.os-itens input[type=checkbox] { width: auto; }
.os-itens tr.fora-orcamento [data-subtotal] { text-decoration: line-through; color: var(--muted); }
.tag.material { background: var(--primary-soft); color: var(--primary); }
.tag.servico { background: var(--historico-soft); color: var(--historico); }

/* Documentos anexados aos títulos */
.btn.com-anexo { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); gap: 3px; }
.n-anexos { font-size: 11px; font-weight: 700; }
#anexos + .row .campo { flex: 1; min-width: 240px; }
input[type=file] { padding: 6px; }
.item-nf { font-size: 12px; color: var(--muted); margin-top: 2px; }
.item-novo-aviso, [data-aviso-novo] { font-size: 12px; color: var(--primary); margin-top: 2px; }
[data-aviso-novo][hidden], [data-criar-produto][hidden] { display: none; }
tr.item-novo td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
td.acoes.acoes-esq { text-align: left; }
td.acoes .tag-os { vertical-align: middle; margin-left: 2px; }

/* Botões pequenos nas colunas de ações: mesma altura e alinhados na linha, com ou sem ícone. */
td.acoes .btn-sm { height: 30px; padding-top: 0; padding-bottom: 0; vertical-align: middle; margin: 1px 0; }
td.acoes .btn-sm.btn-icon { width: 30px; padding: 0; }
td.acoes .btn-sm svg.ic { width: 16px; height: 16px; }
.tab-parcelas-os td, .tab-parcelas-os th { padding-left: 5px; padding-right: 5px; }
tr.dia-sep td { background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 600; padding-top: 7px; padding-bottom: 7px;
  border-top: 2px solid var(--border); }
tr.dia-sep td b { color: var(--text); font-size: 13.5px; }
tr.dia-sep td b.neg { color: var(--danger); }

/* ---------- NZ Cobrança ---------- */
.tag.orcamento { background: var(--warning-soft); color: var(--warning); }
.tag.boleto { background: #f3e8ff; color: #7e22ce; }
:root[data-theme="dark"] .tag.boleto { background: #2e1a47; color: #d8b4fe; }
.tag.faturada { background: var(--primary-soft); color: var(--primary); }
.tag.paga { background: var(--success-soft); color: var(--success); }
.etapas { display: flex; gap: 4px; flex-wrap: wrap; }
.etapa { font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.etapa.ok { border-color: transparent; background: var(--success-soft); color: var(--success); font-weight: 650; }
.itens-edit td { vertical-align: top; }
.itens-edit textarea { min-height: 54px; width: 100%; font: inherit; font-size: 13px; }
.itens-edit input { width: 100%; min-width: 60px; }
.pasta-box { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pasta-box code { background: var(--surface-2); padding: 3px 8px; border-radius: 6px; }
.arquivo-linha { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.img-previa { max-width: 260px; max-height: 90px; border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 4px; }
.itens-edit td:nth-child(2) { min-width: 320px; }
.itens-edit td:nth-child(3) input, .itens-edit td:nth-child(4) input, .itens-edit td:nth-child(5) input, .itens-edit td:nth-child(6) input { max-width: 96px; }
