/* Layout: menu escuro à esquerda (vira barra no celular) + área de trabalho clara; cartões só separam tarefas */
:root {
  --bg: #F3F5F8; --surface: #FFFFFF; --surface-2: #F7F9FB; --line: #E1E6ED; --line-2: #EDF0F4; --ctrl: #C9D1DC;
  --fg: #111A27; --muted: #556073; --accent: #1F4FD1; --accent-strong: #163BA3; --accent-soft: #EAF0FF; --accent-line: #BFD0F8; --on-accent: #FFFFFF;
  --ok: #0A7A45; --ok-soft: #E5F5EC; --ok-line: #B2DFC6;
  --warn: #9A4A00; --warn-soft: #FFF3E2; --warn-line: #F0CC93;
  --bad: #B42318; --bad-soft: #FDEEEC; --bad-line: #F3C2BC;
  --neu: #475467; --neu-soft: #EDF0F4; --track: #E6EAF0;
  --nav-bg: #0F1B2D; --nav-fg: #C9D3E0; --nav-strong: #FFFFFF; --nav-muted: #8A9BB3; --nav-hover: #1A2940; --nav-active: #22385F; --nav-card: #172741; --nav-track: #2A3B57; --nav-bar: #6E93FF;
  --font-ui: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C121B; --surface: #131B26; --surface-2: #17212E; --line: #253142; --line-2: #1D2735; --ctrl: #3A475B;
    --fg: #E5EAF1; --muted: #9BA7B8; --accent: #7B9CFF; --accent-strong: #A9BEFF; --accent-soft: #1A2747; --accent-line: #34497A; --on-accent: #0A1020;
    --ok: #53C892; --ok-soft: #10291C; --ok-line: #1F5139;
    --warn: #F2AA55; --warn-soft: #2E210F; --warn-line: #5C4219;
    --bad: #F48479; --bad-soft: #341614; --bad-line: #6A2A25;
    --neu: #B7C1CF; --neu-soft: #1F2936; --track: #253142;
    --nav-bg: #080D14; --nav-fg: #C3CDDA; --nav-muted: #8796AC; --nav-hover: #141F30; --nav-active: #1E3054; --nav-card: #111A28; --nav-track: #24324A; --nav-bar: #7B9CFF;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-ui); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent-line); outline-offset: 2px; }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sm { font-size: 12px; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.app { display: flex; min-height: 100vh; }
.side { flex: none; width: 252px; background: var(--nav-bg); color: var(--nav-fg); display: flex; flex-direction: column; padding: 18px 14px 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 10px 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--nav-strong); text-decoration: none; }
.logo { width: 32px; height: 32px; border-radius: 8px; background: #1F4FD1; color: #FFFFFF; display: grid; place-items: center; }
.menu-btn { display: none; min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--nav-track); background: transparent; color: var(--nav-strong); font-weight: 600; cursor: pointer; }
.nav-sec { margin: 14px 0 4px; padding: 0 12px; font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--nav-muted); }
.nav-link { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: 8px; color: var(--nav-fg); font-size: 14px; font-weight: 500; text-decoration: none; }
.nav-link:hover { background: var(--nav-hover); color: var(--nav-strong); }
.nav-link[aria-current="page"] { background: var(--nav-active); color: var(--nav-strong); font-weight: 600; }
.nav-link.off { opacity: .55; pointer-events: none; }
.nav-foot { margin-top: auto; padding-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.plan-card { background: var(--nav-card); border-radius: 10px; padding: 14px; font-size: 12px; color: var(--nav-muted); }
.plan-card b { display: block; font-size: 14px; color: var(--nav-strong); margin-top: 2px; }
.bar { height: 6px; border-radius: 3px; background: var(--nav-track); overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; background: var(--nav-bar); }
.nav-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px 0 12px; font-size: 13px; }
.nav-user button { min-height: 44px; border: 0; background: none; color: var(--nav-fg); text-decoration: underline; cursor: pointer; }

.main { flex: 1; min-width: 0; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 22px clamp(16px, 3vw, 36px) 64px; display: flex; flex-direction: column; gap: 20px; }
.banner { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 9px 14px; border-radius: 10px; font-size: 13px; line-height: 1.4; border: 1px solid var(--line); }
.banner.sim { background: var(--accent-soft); border-color: var(--accent-line); }
.banner.homolog { background: var(--warn-soft); border-color: var(--warn-line); }
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.head p { margin-top: 4px; color: var(--muted); font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-bottom: 14px; }
.card-h h2 { font-size: 17px; font-weight: 700; display: flex; align-items: center; }
.flush > .card-h { padding: 14px 20px 0; margin-bottom: 12px; }
.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 700; margin-right: 10px; flex: none; }
.sub-h { font-size: 13px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.c-main { flex: 999 1 540px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.c-side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { align-items: flex-end; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-size: 13px; font-weight: 600; }
.help { font-size: 12px; color: var(--muted); line-height: 1.4; }
.erro-campo { font-size: 12px; color: var(--bad); font-weight: 600; }
.inp { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--ctrl); border-radius: 10px; background: var(--surface); color: var(--fg); font-size: 15px; }
textarea.inp { padding: 10px 12px; min-height: 84px; resize: vertical; line-height: 1.45; }
.inp::placeholder { color: var(--muted); }
.inp[aria-invalid="true"] { border-color: var(--bad); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.check input { width: 20px; height: 20px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--ctrl); background: var(--surface); color: var(--fg); font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.pri:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.soft { color: var(--accent); border-color: var(--accent-line); }
.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.big { width: 100%; min-height: 52px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.lnk { display: inline-flex; align-items: center; min-height: 44px; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--ctrl); background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg input:checked + span { color: var(--on-accent); }
.seg label:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--accent-line); outline-offset: 2px; }
.seg.pills label { border-radius: 999px; font-size: 13px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neu { background: var(--neu-soft); color: var(--neu); }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--neu-soft); color: var(--neu); white-space: nowrap; }
.tag.acc { background: var(--accent-soft); color: var(--accent-strong); }
.code { font-family: var(--font-mono); font-size: 13px; font-weight: 600; padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap; }

.scroll { overflow-x: auto; position: relative; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 14px; background: var(--surface-2); white-space: nowrap; }
.t td { padding: 8px 14px; border-top: 1px solid var(--line-2); vertical-align: middle; }
.t .r { text-align: right; }
.t .nw { white-space: nowrap; }
.t a.rowlink { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--fg); font-weight: 600; text-decoration: none; }
.t a.rowlink:hover { text-decoration: underline; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 232px), 1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; min-width: 0; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; }
.kpi .v small { font-size: 15px; font-weight: 500; color: var(--muted); }
.kpi .v.bad { color: var(--bad); } .kpi .v.warn { color: var(--warn); }
.kpi .s { font-size: 13px; color: var(--muted); margin-top: 6px; }
.track { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; margin-top: 10px; }
.track > span { display: block; height: 100%; background: var(--accent); }
.acts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 16px; }
.act { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 18px 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); text-decoration: none; }
.act:hover { border-color: var(--accent-line); }
.act .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 4px; }
.act b { font-size: 17px; }
.act .d { font-size: 14px; color: var(--muted); line-height: 1.45; }
.act .go { font-size: 14px; font-weight: 600; color: var(--accent); margin-top: 4px; }
.act.off { opacity: .6; pointer-events: none; }

.alert { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); font-size: 14px; line-height: 1.5; }
.alert .tx { flex: 1 1 260px; min-width: 0; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.alert.bad { background: var(--bad-soft); border-color: var(--bad-line); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok-line); }
.alert.info { background: var(--accent-soft); border-color: var(--accent-line); }
.empty { padding: 22px; border: 1px dashed var(--ctrl); border-radius: 12px; text-align: center; color: var(--muted); font-size: 14px; }
.box { padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.note { padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; line-height: 1.5; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.checks li { display: flex; gap: 8px; align-items: flex-start; line-height: 1.4; }
.checks li::before { content: "✓"; font-weight: 700; color: var(--ok); flex: none; width: 14px; }
.checks li.no::before { content: "!"; color: var(--warn); }
.sum { display: flex; flex-direction: column; gap: 8px; font-size: 14px; margin: 0; }
.sum > div { display: flex; justify-content: space-between; gap: 12px; }
.sum dt { color: var(--muted); } .sum dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.total b { font-size: 24px; font-variant-numeric: tabular-nums; }
.chave { display: block; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-family: var(--font-mono); font-size: 14px; word-break: break-all; min-width: 0; }
.dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 14px; margin: 0; }
.dl dt { font-size: 13px; color: var(--muted); } .dl dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.cli-card { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 10px 24px; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.cli-card b { display: block; font-size: 16px; color: var(--fg); }
.qty { width: 92px; text-align: center; }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--bad); }
.ok-ic { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 28px; font-weight: 700; }
.ok-ic.ok { background: var(--ok-soft); color: var(--ok); }
.ok-ic.bad { background: var(--bad-soft); color: var(--bad); }
.ok-ic.neu { background: var(--neu-soft); color: var(--neu); }
.spin { width: 52px; height: 52px; border-radius: 50%; border: 5px solid var(--accent-soft); border-top-color: var(--accent); animation: gira .9s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
.pagina { display: flex; gap: 8px; flex-wrap: wrap; }
.pagina nav { width: 100%; }
.guest { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.guest .card { width: min(100%, 460px); }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .side { width: auto; height: auto; position: static; padding: 8px 16px; }
  .brand-row { padding: 4px 0; }
  .menu-btn { display: inline-flex; align-items: center; }
  .side nav, .side .nav-foot { display: none; }
  .side.open nav, .side.open .nav-foot { display: flex; flex-direction: column; }
  .head h1 { font-size: 23px; }
}

/* Opções em cartões (tipo de negócio): o cartão inteiro é clicável, com título e explicação curta */
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 10px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); cursor: pointer; min-width: 0; }
.opt:hover { border-color: var(--accent-line); }
.opt input { margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.opt > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.opt b { font-size: 14px; }
.opt small { font-size: 12px; color: var(--muted); line-height: 1.4; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.opt:has(input:focus-visible) { outline: 3px solid var(--accent-line); outline-offset: 2px; }

/* Caixa de busca com lista de resultados (clientes e produtos na emissão) */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14); max-height: 300px; overflow: auto; padding: 4px; }
.combo-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer; font: inherit; color: inherit; }
.combo-list button:hover, .combo-list button.on { background: var(--accent-soft); }
.combo-list small { display: block; color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; color: inherit; }
.chip:hover { border-color: var(--accent-line); background: var(--accent-soft); }
/* Blocos opcionais que abrem só quando a pessoa precisa */
details.more { border: 1px dashed var(--ctrl); border-radius: 10px; padding: 0 12px; }
details.more > summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 14px; color: var(--accent); list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: '+ '; }
details.more[open] > summary::before { content: '− '; }
details.more > .stack { padding-bottom: 12px; }
.subcard { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--surface-2); }
.t input.inp { padding: 6px 8px; font-size: 14px; }

/* Tela de NF-e no formato de ficha: colunas fixas no desktop, empilhadas no celular */
.fields.f4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.fields.f5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.fields.f6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.fields .span2 { grid-column: span 2; }
@media (max-width: 1100px) { .fields.f5, .fields.f6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { .fields.f4, .fields.f5, .fields.f6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .fields.f4, .fields.f5, .fields.f6 { grid-template-columns: minmax(0, 1fr); } .fields .span2 { grid-column: auto; } }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface); }
.item .cab { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; }
.item .cab b { font-size: 15px; }
.item .fields { gap: 8px 10px; }
.item .field > label { font-size: 12px; }
.item .inp { padding: 7px 9px; font-size: 14px; }
.item .tot { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; align-self: end; padding-bottom: 8px; }
.totais { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 10px 16px; }
.totais .l { display: block; font-size: 12px; color: var(--muted); }
.totais .v { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.totais .total-nota { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.totais .total-nota .l { font-size: 15px; font-weight: 600; color: var(--fg); }
.totais .total-nota .v { font-size: 22px; font-weight: 700; }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.neu { background: var(--neu-soft); color: var(--neu); }
