:root {
  --navy: #1b1e4b; --navy-2: #2a2e68; --ink: #1f2238; --muted: #62667f; --line: #e2e3ec; --bg: #f5f5f9; --card: #fff;
  --orange: #f2711c; --pink: #e6336f; --blue: #2a7de1; --teal: #11a59a;
  --ok: #0f8a5f; --ok-bg: #e3f6ee; --warn: #a85c00; --warn-bg: #fff2dc; --bad: #c0213c; --bad-bg: #fde8ec; --info-bg: #e7f0fd;
  --brand: linear-gradient(90deg, var(--orange), var(--pink) 38%, var(--blue) 70%, var(--teal));
  --shadow: 0 1px 2px #1b1e4b0a, 0 4px 14px #1b1e4b0d;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0; color: var(--navy); }
h2 { font-size: 16px; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--navy); }
p { margin: 0 0 10px; }
a { color: var(--blue); }
code { font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.mobile-only { display: none; }
.hidden { display: none !important; }

/* Estrutura */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #fff; padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-top: 4px solid transparent; border-image: var(--brand) 1; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 16px; }
.brand img { width: 40px; height: 40px; border-radius: 50%; background: #fff; }
.brand b { display: block; line-height: 1.15; }
.brand span { font-size: 12px; opacity: .75; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { color: #dfe0f2; text-decoration: none; padding: 9px 10px; border-radius: 7px; }
.nav a:hover { background: var(--navy-2); }
.nav a.on { background: #fff; color: var(--navy); font-weight: 600; }
.nav .sep { border-top: 1px solid #ffffff26; margin: 8px 0; }
.who { font-size: 13px; padding: 12px 6px 0; border-top: 1px solid #ffffff26; }
.who a { color: #dfe0f2; }
.who button { margin-top: 6px; background: none; color: #fff; border: 1px solid #ffffff55; width: 100%; }
.mnav { display: none; }
.main { padding: 22px; min-width: 0; max-width: 1180px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.head .sub { color: var(--muted); font-size: 14px; display: block; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.danger-zone { justify-content: flex-end; margin: -6px 0 14px; padding-top: 10px; border-top: 1px dashed var(--line); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.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)); }
.g32 { grid-template-columns: 3fr 2fr; }

/* Painel */
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.hero h1 { font-size: 26px; }
.hero .date { color: var(--muted); }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { display: flex; gap: 12px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-decoration: none; color: inherit; box-shadow: var(--shadow); transition: transform .12s; }
.tile:hover { transform: translateY(-1px); border-color: #c9cbd9; }
.tile .ico { flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--info-bg); }
.tile .ico.orange { background: #fdebdd; } .tile .ico.pink { background: #fbe1ea; } .tile .ico.teal { background: #dff5f2; } .tile .ico.red { background: var(--bad-bg); }
.tile b { display: block; font-size: 24px; line-height: 1.1; color: var(--navy); }
.tile b.bad { color: var(--bad); }
.tile span { font-size: 13px; color: var(--muted); }
.agenda-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); }
.agenda-item:last-child { border-bottom: 0; }
.agenda-item .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--blue); }
.agenda-item .dot.task { background: var(--orange); } .agenda-item .dot.visit { background: var(--teal); } .agenda-item .dot.late { background: var(--bad); } .agenda-item .dot.deliver { background: var(--pink); }
.agenda-item a { color: inherit; text-decoration: none; }
.agenda-item a:hover { text-decoration: underline; }
.chart { display: flex; gap: 8px; align-items: flex-end; height: 110px; padding-top: 10px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--muted); font-size: 12px; }
.chart .bar i { display: block; width: 100%; max-width: 38px; border-radius: 6px 6px 2px 2px; background: #cfd6f3; min-height: 4px; }
.chart .bar.today i { background: var(--navy); }
.chart .bar b { color: var(--navy); font-size: 13px; }
.chart .bar.today span { color: var(--navy); font-weight: 700; }
.empty { color: var(--muted); padding: 12px 0; text-align: center; }

/* Ícones */
.ic { width: 18px; height: 18px; vertical-align: -4px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button .ic, .btn .ic { margin-right: 5px; }
.tile .ico .ic { width: 22px; height: 22px; color: var(--navy); }
.badge .ic { width: 13px; height: 13px; vertical-align: -2px; stroke-width: 2.5; }
.checklist .mark .ic { width: 13px; height: 13px; stroke-width: 3; }
.task .ic { width: 16px; height: 16px; color: var(--ok); }
.ai-fab .ic, .ai-head .ic { margin-right: 6px; }
.mnav .ic { display: block; margin: 0 auto 2px; width: 20px; height: 20px; }

/* Controles */
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--navy); padding: 9px 14px; min-height: 42px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; line-height: 1.3; }
button:hover, .btn:hover { border-color: var(--navy); }
button.primary, .btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
button.danger { color: var(--bad); border-color: #efb9c3; }
button.big, .btn.big { width: 100%; padding: 15px; font-size: 17px; text-align: center; }
button.success { background: var(--ok); border-color: var(--ok); color: #fff; }
button.link { border: 0; background: none; color: var(--blue); padding: 0; min-height: 0; font-weight: 500; text-decoration: underline; display: inline; }
button:disabled { opacity: .55; cursor: default; }
body.busy button, body.busy .btn, body.busy input[type=checkbox] { pointer-events: none; }
body.busy button.primary, body.busy button.success, body.busy button.danger { opacity: .7; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
.help { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 3px; }
.req { color: var(--bad); }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); width: 100%; margin-top: 3px; padding: 10px 11px; border: 1px solid #c9cbd9; border-radius: 8px; background: #fff; min-height: 42px; }
input::placeholder, textarea::placeholder { color: #9a9db3; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; accent-color: var(--navy); }
label.check { display: flex; gap: 9px; align-items: flex-start; color: var(--ink); font-weight: 500; font-size: 14px; padding: 5px 0; cursor: pointer; }
label.check input { margin-top: 1px; }
label.check .help { margin: 0; }
.form { display: grid; gap: 12px; }
.span2 { grid-column: 1 / -1; }
.search { max-width: 320px; margin: 0; }
.tip { display: inline-flex; width: 17px; height: 17px; border-radius: 50%; background: #d9dbe8; color: var(--navy); font-size: 11px; font-weight: 700; align-items: center; justify-content: center; margin-left: 4px; cursor: help; vertical-align: middle; }
.seg { display: inline-flex; border: 1px solid #c9cbd9; border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg label { margin: 0; padding: 8px 12px; font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer; display: flex; gap: 6px; align-items: center; border-right: 1px solid #c9cbd9; }
.seg label:last-child { border-right: 0; }
.seg label:has(input:checked) { background: var(--navy); color: #fff; }
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.field-err input, .field-err select, .field-err textarea { border-color: var(--bad); background: #fff8f9; }
.field-msg { display: block; color: var(--bad); font-size: 12px; font-weight: 600; margin-top: 4px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { flex: 1; min-width: 140px; }
.inline-form button { height: 42px; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.link { cursor: pointer; }
tr.link:hover td { background: #fafafd; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eceef5; color: var(--navy); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: #1c5fb3; }
.badge.teal { background: #dff5f2; color: #0b7a71; }
.alert { padding: 11px 13px; border-radius: 8px; margin-bottom: 12px; background: var(--warn-bg); color: #6e3e00; }
.alert.bad { background: var(--bad-bg); color: #8f1229; }
.alert.ok { background: var(--ok-bg); color: #0a6545; }
.alert.info { background: var(--info-bg); color: #164d92; }
.alert p:last-child { margin: 0; }
.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; color: inherit; text-decoration: none; }
.list-row:last-child { border-bottom: 0; }
.list-row.done { opacity: .6; }
.list-row.done .t { text-decoration: line-through; }

/* Passos do orçamento */
.step { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px; }
.step .n { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 14px; }
.step h2 { margin: 3px 0 2px; }
.step .help { margin: 0; }
.item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fcfcfe; }
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.item-head b { color: var(--navy); }
.item-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.calc { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--info-bg); color: #164d92; font-size: 14px; line-height: 1.5; }
.calc.bad { background: var(--bad-bg); color: #8f1229; }
.calc b { font-size: 16px; }
.private { background: #f1f2f9; border: 1px dashed #b9bcd3; border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.private > b { display: block; font-size: 13px; color: var(--navy); margin-bottom: 4px; }
.grand { font-size: 20px; font-weight: 700; color: var(--navy); }
.sticky-bar { position: sticky; bottom: 0; z-index: 5; box-shadow: 0 -4px 14px #1b1e4b14; }

/* Etapas / OS */
.steps { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.steps .sep { color: var(--muted); }
.layout-img { max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.search-os { display: flex; gap: 8px; flex-wrap: wrap; }
.search-os input { margin: 0; flex: 1; min-width: 140px; }
video.scan { width: 100%; max-height: 60vh; border-radius: 8px; background: #000; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist .mark { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #c9cbd9; display: grid; place-items: center; font-size: 12px; }
.checklist li.done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.checklist li.done span.t { text-decoration: line-through; color: var(--muted); }
.guide { background: linear-gradient(135deg, #fff7ef, #eef3ff); border: 1px solid #e6d9f1; }
.guide ol { margin: 6px 0 0; padding-left: 20px; }
.guide li { margin-bottom: 4px; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task input[type=checkbox] { margin-top: 2px; }
.task.done .t { text-decoration: line-through; color: var(--muted); }
.visit { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fff; }
.visit .vh { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.date-nav { display: flex; gap: 6px; align-items: center; }
.date-nav input { margin: 0; width: auto; }

/* Permissões */
.perm-row { display: grid; grid-template-columns: 1.2fr 2fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: start; }
.perm-row:last-child { border-bottom: 0; }
.perm-row .opts { display: flex; gap: 14px; flex-wrap: wrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--navy); }
.login form { background: #fff; padding: 26px; border-radius: 12px; width: 100%; max-width: 360px; display: grid; gap: 12px; border-top: 5px solid transparent; border-image: var(--brand) 1; }
.login img { width: 130px; margin: 0 auto; display: block; }
.error { color: var(--bad); font-size: 14px; min-height: 1em; }

dialog { border: 0; border-radius: 12px; padding: 20px; width: min(540px, calc(100vw - 32px)); color: var(--ink); max-height: calc(100vh - 32px); overflow: auto; }
dialog::backdrop { background: #10122f88; }
dialog .form { margin-top: 8px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 40; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }

/* Assistente */
.ai-fab { position: fixed; right: 18px; bottom: 18px; z-index: 30; background: var(--navy); color: #fff; border: 0; border-radius: 99px; padding: 12px 16px; font-weight: 700; box-shadow: 0 6px 20px #1b1e4b55; }
.ai-panel { position: fixed; right: 18px; bottom: 18px; width: min(420px, calc(100vw - 36px)); height: min(600px, calc(100vh - 36px)); background: #fff; border-radius: 14px; box-shadow: 0 12px 40px #1b1e4b55; z-index: 31; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); }
.ai-head { background: var(--navy); color: #fff; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; }
.ai-head button { background: none; border: 0; color: #fff; font-size: 18px; padding: 0 4px; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.ai-msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.ai-msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 3px; }
.ai-msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.ai-msg.bot ul { margin: 4px 0; padding-left: 18px; }
.ai-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 0; background: var(--bg); }
.ai-chips button { font-size: 12px; padding: 5px 9px; border-radius: 99px; font-weight: 500; }
.ai-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: #fff; }
.ai-form input { margin: 0; }

/* Documento do cliente / folha da OS */
.doc { background: #fff; border: 1px solid var(--line); padding: 34px; max-width: 800px; margin: 0 auto; border-radius: 4px; }
.doc-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding-bottom: 14px; border-bottom: 4px solid transparent; border-image: var(--brand) 1; margin-bottom: 18px; }
.doc-head img { width: 88px; }
.doc td, .doc th { padding: 8px; }
.qr svg { width: 130px; height: 130px; display: block; }

@media (max-width: 900px) {
  .mobile-only { display: initial; }
  .desktop-only { display: none !important; }
  .shell { display: block; padding-bottom: 66px; }
  .side { display: none; }
  .mnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--navy); padding-bottom: env(safe-area-inset-bottom); }
  .mnav a, .mnav button { flex: 1; color: #dfe0f2; background: none; border: 0; border-radius: 0; text-decoration: none; padding: 10px 2px; font-size: 11px; text-align: center; font-weight: 600; line-height: 1.2; }
  .mnav a.on { background: var(--navy-2); color: #fff; box-shadow: inset 0 3px 0 var(--orange); }
  .main { padding: 14px; }
  .g2, .g3, .g32 { grid-template-columns: minmax(0, 1fr); }
  .g4, .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile { padding: 12px; }
  .tile b { font-size: 20px; }
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .doc { padding: 16px; }
  input, select, textarea { font-size: 16px; }
  .search { max-width: none; }
  table.cards thead { display: none; }
  table.cards tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.cards td { display: block; border: 0; padding: 2px 0; text-align: left; }
  table.cards td.right { text-align: left; }
  .sticky-bar { bottom: 66px; }
  /* toque: botões maiores, dois por linha, destrutivos em linha própria */
  .head .actions, .visit .actions, .list-row .actions, .danger-zone { gap: 10px; width: 100%; }
  .head .actions > *, .visit .actions > * { flex: 1 1 calc(50% - 5px); min-height: 46px; }
  .head .actions > .danger, .visit .actions > .danger, .danger-zone > .danger { flex-basis: 100%; margin-top: 4px; }
  .list-row .actions > button { min-height: 44px; min-width: 44px; }
  .perm-row { grid-template-columns: 1fr; }
  .ai-fab { display: none; }
  .ai-panel { right: 0; bottom: 0; width: 100vw; height: 100vh; border-radius: 0; }
  .hero h1 { font-size: 22px; }
}
@media print {
  body { background: #fff; }
  .side, .mnav, .no-print, #toast, .ai-fab, .ai-panel { display: none !important; }
  .shell { display: block; padding: 0; }
  .main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; max-width: none; box-shadow: none; }
}
