:root {
  --bg: #f4f5f9;
  --surface: #fff;
  --line: #e4e7ef;
  --line-soft: #eef0f5;
  --text: #1f2740;
  --muted: #687189;
  --primary: #3559ce;
  --primary-strong: #2846ad;
  --primary-soft: #e8edff;
  --accent: #6f55bb;
  --danger: #b8435a;
  --danger-soft: #fbecef;
  --warn: #9a5b00;
  --warn-soft: #fff3dc;
  --ok: #1d7a52;
  --ok-soft: #e3f5ec;
  --radius: 14px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1 { font-size: 24px; letter-spacing: -.5px; margin: 0; line-height: 1.25; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Estrutura ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); height: 56px; padding: 0 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 800; font-size: 21px; letter-spacing: -1px; text-decoration: none; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }
.brand span { color: var(--accent); }
.brand-logo { display: block; height: 36px; max-width: 160px; object-fit: contain; object-position: left center; }
.logo-preview { display: flex; align-items: center; justify-content: center; min-height: 96px; padding: 14px; border: 1px dashed #cfd4e2; border-radius: 12px; background: #fff; margin-bottom: 12px; }
.logo-preview img { max-height: 90px; max-width: 100%; object-fit: contain; }
.public-logo { display: block; max-height: 72px; max-width: 240px; margin: 0 auto 8px; object-fit: contain; border-radius: 10px; }
.desk-nav { display: none; gap: 4px; margin-left: 12px; }
.desk-nav a { padding: 8px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 500; }
.desk-nav a.active { background: var(--primary-soft); color: var(--primary); }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.icon-btn { position: relative; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--text); text-decoration: none; }
.icon-btn:hover { background: var(--bg); }
.icon-btn svg { width: 22px; height: 22px; }
.dot { position: absolute; top: 4px; right: 3px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: #d9475f; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 14px; }

main { max-width: 1080px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); }
body.focus-mode main { padding-bottom: calc(96px + var(--safe-b)); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding: 4px 4px calc(4px + var(--safe-b)); height: calc(var(--tabbar-h) + var(--safe-b)); }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 500; border-radius: 12px; position: relative; }
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.active { color: var(--primary); }
.tabbar a.new-tab span.plus { width: 46px; height: 46px; border-radius: 15px; background: var(--primary); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px #3559ce40; margin-top: -2px; }
.tabbar a.new-tab span.plus svg { width: 26px; height: 26px; }
.tabbar .dot { top: 2px; right: calc(50% - 22px); }
body.focus-mode .tabbar { display: none; }

@media (min-width: 900px) {
  .desk-nav { display: flex; }
  .tabbar { display: none; }
  main { padding: 28px 24px 60px; }
  body.focus-mode main { padding-bottom: 110px; }
  .topbar { padding: 0 max(24px, calc((100vw - 1080px) / 2 + 24px)); height: 64px; }
  h1 { font-size: 28px; }
}

/* ---------- Cabeçalho de página ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head .eyebrow { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .6px; text-transform: uppercase; margin-bottom: 2px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); text-decoration: none; font-weight: 500; font-size: 15px; min-height: 44px; margin: -6px 0 2px; background: none; border: 0; padding: 0; cursor: pointer; }
.back svg { width: 20px; height: 20px; }

/* ---------- Botões ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 0; background: var(--primary); color: #fff; font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, transform .05s; }
.btn:hover { background: var(--primary-strong); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: default; transform: none; pointer-events: none; }
.btn svg { width: 19px; height: 19px; flex-shrink: 0; }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-secondary:hover { background: #dce4ff; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #f6dde2; }
.btn-whats { background: #1f9d55; }
.btn-whats:hover { background: #188547; }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }
:focus-visible { outline: 3px solid #9dabdf; outline-offset: 2px; }

/* ---------- Formulários ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.field > span em { color: var(--danger); font-style: normal; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
input, select, textarea { display: block; width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid #d7dbe7; border-radius: 11px; background: var(--surface); font-size: 16px; }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px #3559ce26; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--primary); flex-shrink: 0; margin: 0; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 6px 0 14px; cursor: pointer; }
.check b { display: block; font-weight: 500; }
.grid { display: grid; gap: 0 14px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: 1fr 1fr 1fr; } .span-2 { grid-column: span 2; } }
.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 42px; }
details.more { margin: 4px 0 14px; }
details.more summary { cursor: pointer; color: var(--primary); font-weight: 500; font-size: 15px; min-height: 40px; display: flex; align-items: center; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: '+'; display: inline-block; width: 20px; font-weight: 700; }
details.more[open] summary::before { content: '–'; }

/* ---------- Superfícies ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card > h2:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
@media (min-width: 640px) { .card { padding: 20px; } }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: inherit; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; cursor: pointer; min-height: 60px; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: #fafbff; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .sub { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .end { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.list-row .chev { width: 18px; height: 18px; color: #b3b9c9; flex-shrink: 0; }
.list .empty, .empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 15px; }
.list-title { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 10px; }
.list-title h2 { margin: 0; }

/* ---------- Badges e chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 8px; white-space: nowrap; background: #eef0f5; color: #545d74; }
.st-orcamento { background: #efebfc; color: #6a48b0; }
.st-aprovado { background: #e4ecff; color: #2c4fc0; }
.st-em-execucao { background: #fff1d9; color: #935800; }
.st-concluido { background: var(--ok-soft); color: var(--ok); }
.st-recusado { background: #f1f2f5; color: #6b7184; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 4px; margin: 12px -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; min-height: 38px; padding: 7px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.chip.warn-chip.active { background: var(--warn); border-color: var(--warn); }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, 1fr); gap: 14px; } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: inherit; display: block; min-width: 0; }
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat strong { display: block; font-size: 22px; letter-spacing: -.5px; margin: 4px 0 2px; overflow-wrap: anywhere; line-height: 1.2; }
.stat small { color: var(--muted); font-size: 12.5px; }
.alert-box { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-radius: var(--radius); background: var(--warn-soft); color: #5e3b00; text-decoration: none; margin-bottom: 10px; border: 1px solid #f6dfb3; }
.alert-box svg { width: 22px; height: 22px; flex-shrink: 0; color: var(--warn); }
.alert-box .grow { flex: 1; }
.alert-box b { display: block; }
.alert-box span { font-size: 14px; }
.alert-box.danger { background: var(--danger-soft); border-color: #f1ccd4; color: #6d2333; }
.alert-box.danger svg { color: var(--danger); }
.alert-box.ok { background: var(--ok-soft); border-color: #c4ead6; color: #12553a; }
.alert-box.ok svg { color: var(--ok); }
.cols { display: grid; gap: 14px; }
@media (min-width: 900px) { .cols { grid-template-columns: 1fr 1fr; } }
.stage { display: block; padding: 10px 0; text-decoration: none; color: inherit; }
.stage .row { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.bar { height: 7px; background: var(--line-soft); border-radius: 6px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; background: var(--primary); }

/* ---------- Ordem: detalhe ---------- */
.order-hero { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.total-big { font-size: 30px; font-weight: 750; letter-spacing: -1px; color: var(--primary); line-height: 1.1; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 15px; }
.kv span:first-child { color: var(--muted); }
.kv.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; font-weight: 700; font-size: 17px; }
.item-line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 15px; }
.item-line:last-child { border-bottom: 0; }
.item-line .grow { min-width: 0; flex: 1; }
.item-line .sub { color: var(--muted); font-size: 13.5px; }
.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.quick-actions a, .quick-actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 12px; background: var(--bg); color: var(--text); text-decoration: none; font-size: 13px; font-weight: 500; border: 0; cursor: pointer; min-height: 64px; justify-content: center; }
.quick-actions svg { width: 22px; height: 22px; color: var(--primary); }
.quick-actions .disabled { opacity: .4; pointer-events: none; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14.5px; }
.timeline li::before { content: ''; position: absolute; left: 4px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ''; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline small { display: block; color: var(--muted); }
.progress { display: flex; gap: 4px; margin: 14px 0 4px; }
.progress i { flex: 1; height: 5px; border-radius: 4px; background: var(--line); }
.progress i.on { background: var(--primary); }

/* ---------- Assistente de orçamento ---------- */
.steps { display: flex; gap: 6px; margin: 6px 0 18px; }
.steps button { flex: 1; border: 0; background: none; padding: 0; text-align: left; cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }
.steps button::before { content: ''; display: block; height: 5px; border-radius: 4px; background: var(--line); margin-bottom: 7px; }
.steps button.done::before, .steps button.current::before { background: var(--primary); }
.steps button.current { color: var(--primary); }
.steps button:disabled { cursor: default; }
.selected-client { display: flex; gap: 12px; align-items: center; }
.selected-client .avatar { width: 46px; height: 46px; font-size: 17px; }
.result-row .add { width: 36px; height: 36px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex-shrink: 0; }
.result-row .add svg { width: 20px; height: 20px; }
.result-row.added .add { background: var(--ok-soft); color: var(--ok); }
.type-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--accent); }
.cart-item { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.cart-item:last-child { border-bottom: 0; }
.cart-item .top { display: flex; gap: 10px; align-items: flex-start; }
.cart-item .top .grow { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.cart-item .controls { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.cart-item .line-total { margin-left: auto; font-weight: 700; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: var(--surface); }
.qty button { width: 42px; height: 42px; border: 0; background: var(--bg); font-size: 20px; cursor: pointer; color: var(--primary); }
.qty input { width: 62px; min-height: 42px; border: 0; border-radius: 0; text-align: center; padding: 4px; }
.qty input:focus { box-shadow: none; }
.price-input { width: 118px; min-height: 42px; padding: 6px 10px; }
.remove { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--danger); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.remove svg { width: 19px; height: 19px; }
.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 16px calc(10px + var(--safe-b)); box-shadow: 0 -6px 18px #1f27400d; }
.bottom-bar .inner { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bottom-bar .sum { flex: 1; min-width: 0; }
.bottom-bar .sum small { display: block; color: var(--muted); font-size: 12.5px; }
.bottom-bar .sum strong { font-size: 20px; letter-spacing: -.4px; }
.bottom-bar .btn { min-width: 140px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 11px; padding: 3px; margin-bottom: 12px; }
.segmented button { border: 0; background: transparent; min-height: 40px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px #1f274018; }

/* ---------- Paginação ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0; font-size: 14px; color: var(--muted); }
.pager .btn { min-width: 0; }

/* ---------- Folha (modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: #11172a73; z-index: 60; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--surface); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + var(--safe-b)); max-height: 92vh; overflow-y: auto; animation: up .2s ease-out; }
.sheet::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 4px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 19px; margin-bottom: 4px; }
.sheet .sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
@media (min-width: 640px) { .sheet-backdrop { align-items: center; padding: 20px; } .sheet { border-radius: 20px; padding: 20px 22px; } .sheet::before { display: none; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Toast, carregamento, login ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px); background: var(--text); color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 80; font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: #a2364d; }
body.focus-mode #toast { bottom: calc(96px + var(--safe-b)); }
body.sheet-open #toast { bottom: auto; top: calc(12px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); }
@media (min-width: 900px) { #toast { bottom: 28px; } }
.loading { display: grid; place-items: center; padding: 60px 0; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { display: block; font-size: 30px; text-align: center; margin-bottom: 6px; max-width: none; }
.auth-card .muted { text-align: center; margin-bottom: 22px; }
.notice { background: var(--primary-soft); color: #2c3f87; border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.hub { display: grid; gap: 10px; }
.hub .list-row svg.ico { width: 24px; height: 24px; color: var(--primary); flex-shrink: 0; }
