:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --text: #17212b;
  --muted: #5f6b77;
  --border: #dde3e8;
  --primary: #0f5f73;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1f4;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --whats: #1a8f4c;
  --st-rascunho: #6b7480;
  --st-enviado: #b26a00;
  --st-aprovado: #1a7f45;
  --st-recusado: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #1e2830;
    --text: #e6edf3;
    --muted: #93a1ae;
    --border: #2b3741;
    --primary: #3fb0c9;
    --primary-ink: #06222a;
    --primary-soft: #143542;
    --danger: #f97066;
    --danger-soft: #3a1d1b;
    --whats: #34c46f;
    --st-rascunho: #93a1ae;
    --st-enviado: #f0a83a;
    --st-aprovado: #47c37b;
    --st-recusado: #f97066;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
h1 { font-size: 1.3rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }
.hint { margin: -6px 0 10px; font-size: .88rem; }
[hidden] { display: none !important; }

/* barra superior / navegação */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--primary); color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0b3d4a; } }
.brand-link { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 650; font-size: 1.05rem; }
.brand-link img { border-radius: 7px; background: #fff; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .78rem; font-weight: 550;
}
.bottomnav a span { font-size: 1.25rem; line-height: 1; }
.bottomnav a.active { color: var(--primary); }
.bottomnav .nav-new span {
  display: grid; place-items: center; width: 40px; height: 32px; border-radius: 16px;
  background: var(--primary); color: var(--primary-ink); font-size: 1.2rem;
}

main { outline: none; }
.page { max-width: 860px; margin: 0 auto; padding: 16px; }

/* componentes */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; font-weight: 550; color: var(--muted); margin-bottom: 10px; min-width: 0; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: var(--surface); }
input[type=color] { padding: 2px; height: 42px; }
textarea { resize: vertical; }
.row2, .row3 { display: grid; gap: 0 10px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .row2 { grid-template-columns: 1fr 1fr; } .row3 { grid-template-columns: repeat(3, 1fr); } }
.item .row3 { grid-template-columns: 1fr 1fr 70px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: 10px 14px; border-radius: 10px; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  min-height: 42px;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.whats { background: var(--whats); color: #fff; border-color: var(--whats); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; padding-left: 4px; }
.btn.light { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.35); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.dashed { border-style: dashed; color: var(--primary); background: transparent; }
.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 1rem; cursor: pointer;
}
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.saved { font-size: .8rem; color: var(--st-aprovado); }
.saved.pending { color: var(--muted); }

/* lista */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat span { font-size: .78rem; color: var(--muted); font-weight: 550; }
.stat strong { font-size: 1.2rem; color: var(--st-enviado); font-variant-numeric: tabular-nums; }
.stat.ok strong { color: var(--st-aprovado); }
.stat small { color: var(--muted); }
.search input { background: var(--surface); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.chip {
  flex: none; font: inherit; font-size: .85rem; cursor: pointer;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.chip b { color: var(--muted); font-weight: 600; margin-left: 2px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip.on b { color: inherit; opacity: .8; }
.list { display: flex; flex-direction: column; gap: 8px; }
.qcard {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; color: inherit; text-decoration: none; box-shadow: var(--shadow);
}
.qcard:hover { border-color: var(--primary); }
.qcard-main { min-width: 0; }
.qcard-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qcard-sub { font-size: .82rem; color: var(--muted); }
.qcard-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.qcard-side strong { font-variant-numeric: tabular-nums; }
.qnum { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.badge { font-size: .72rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; color: #fff; }
.st-rascunho { --st: var(--st-rascunho); }
.st-enviado { --st: var(--st-enviado); }
.st-aprovado { --st: var(--st-aprovado); }
.st-recusado { --st: var(--st-recusado); }
.badge { background: var(--st); }
.chip[class*="st-"]:not(.on) b { color: var(--st); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty img { opacity: .8; }

/* editor */
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.title-row h1 { margin: 0; }
.status-select { width: auto; font-weight: 650; color: var(--st); border-color: var(--st); background: var(--surface); }
.section-title { margin: 18px 4px 10px; }
.item { padding: 12px; }
.item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.item-head input { font-weight: 600; }
.idx {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .85rem;
}
.item-body { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 560px) { .item-body { grid-template-columns: 150px 1fr; } }
.sketch-box { display: grid; place-items: center; background: var(--surface-2); border-radius: 10px; color: var(--muted); padding: 4px; }
.sk { width: 100%; max-width: 180px; height: auto; display: block; }
@media (min-width: 560px) { .sketch-box { align-self: start; } }
.item-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.manual { margin: 0; max-width: 170px; }
.item-price { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.item-total { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.item-unit { color: var(--muted); font-size: .78rem; }
.breakdown summary { cursor: pointer; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.bd-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 6px; }
.bd-table td { padding: 4px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.bd-table td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding-left: 10px; }
.bd-table small { display: block; color: var(--muted); font-size: .75rem; }
.bd-table tr.sub td { font-weight: 650; }
.bd-table tr.warn td { color: var(--st-enviado); font-weight: 650; }

.totals .tot-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; }
.totals .tot-line b { font-variant-numeric: tabular-nums; }
.totals .inline { display: flex; gap: 6px; width: 170px; }
.totals .inline select { width: 64px; flex: none; }
.totals .grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; font-size: 1.15rem; }
.totals .grand b { font-size: 1.45rem; color: var(--primary); }
.margin { font-size: .78rem; margin-top: 4px; }

/* ajustes */
.logo-row { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.logo-prev { width: 96px; height: 64px; border: 1px dashed var(--border); border-radius: 10px; display: grid; place-items: center; overflow: hidden; background: #fff; font-size: .75rem; }
.logo-prev img { max-width: 100%; max-height: 100%; }
.logo-row label.btn { display: inline-flex; flex-direction: row; color: var(--text); margin: 0; }
.actions label.btn { margin: 0; color: var(--text); flex-direction: row; }
.tlist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.trow { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 10px; background: var(--surface-2); border-radius: 10px; }
.trow label { margin: 0; }
.trow label span { font-size: .72rem; }
.trow .grow { flex: 1 1 180px; }
.trow .money { flex: 0 1 110px; }
.trow .small { flex: 0 1 90px; }
.trow .mid { flex: 0 1 120px; }
.trow .color { flex: 0 0 56px; }
.trow input, .trow select { background: var(--surface); }
.formula { font-size: .82rem; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: #1d2733; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  max-width: calc(100% - 32px); z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- documento ---------- */
.doc-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; max-width: 860px; margin: 0 auto; padding: 12px 16px; }
.doc-toolbar .grow { flex: 1; }
.doc {
  --text: #17212b; --muted: #5f6b77; --border: #dde3e8; --primary: #0f5f73; --surface-2: #f4f6f8;
  color: var(--text); background: #fff;
  max-width: 820px; margin: 0 auto 24px; padding: 32px; border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,.12); font-size: 13px;
}
.doc .muted { color: var(--muted); }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid var(--primary); padding-bottom: 14px; }
.doc-brand { display: flex; gap: 14px; align-items: center; color: var(--muted); }
.doc-logo { max-width: 110px; max-height: 70px; }
.doc-company { font-size: 18px; font-weight: 700; color: var(--text); }
.doc-num { text-align: right; color: var(--muted); white-space: nowrap; }
.doc-n { font-size: 20px; font-weight: 700; color: var(--primary); }
.doc-label { display: block; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.doc-client { display: flex; flex-wrap: wrap; gap: 8px 32px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.doc-items { width: 100%; border-collapse: collapse; margin: 14px 0; }
.doc-items th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--border); padding: 6px; }
.doc-items td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.doc-items .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-items .col-sk { width: 96px; color: #444; }
.doc-items .sk { max-width: 92px; }
.doc-items tr { break-inside: avoid; }
.doc-bottom { display: grid; grid-template-columns: 1fr 260px; gap: 24px; break-inside: avoid; }
.doc-cond p { margin: 0 0 10px; }
.doc-totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.doc-totals div:first-child { color: var(--muted); font-size: 11px; }
.doc-totals .grand { border-top: 2px solid var(--primary); margin-top: 6px; padding-top: 8px; font-size: 17px; }
.doc-totals .grand b { color: var(--primary); }
.doc-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 48px; text-align: center; color: var(--muted); font-size: 11px; break-inside: avoid; }
.doc-sign .line { border-top: 1px solid #555; margin-bottom: 4px; }

@media (max-width: 600px) {
  .doc { padding: 16px; border-radius: 0; font-size: 12px; }
  .doc-head { flex-direction: column; }
  .doc-num { text-align: left; }
  .doc-bottom { grid-template-columns: 1fr; }
  .doc-items .col-sk { display: none; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; padding: 0; }
  .no-print, .doc-toolbar, .topbar, .bottomnav, .toast { display: none !important; }
  .doc { box-shadow: none; padding: 0; max-width: none; margin: 0; font-size: 11.5px; }
  .doc-head { flex-direction: row; }
  .doc-num { text-align: right; }
  .doc-bottom { grid-template-columns: 1fr 240px; }
  .doc-items .col-sk { display: table-cell; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
