:root {
  --bg: #f2f2ef;
  --surface: #ffffff;
  --sunken: #f7f7f4;
  --line: #e2e1dc;
  --line-strong: #cbc9c2;
  --text: #121417;
  --muted: #5c6067;
  --dim: #8a8e95;
  --accent: #123a73;
  --accent-soft: #e8eef8;
  --ok: #0f7a4f;
  --ok-bg: #e7f5ee;
  --warn: #8a5300;
  --warn-bg: #fdf3e1;
  --err: #b42318;
  --bubble: #e7f6dd;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
small { font-weight: 400; color: var(--dim); }

/* ---------- controles ---------- */
.input {
  width: 100%; height: 46px; padding: 0 13px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 8px; outline: none; font-size: 16px;
}
textarea.input { height: auto; min-height: 84px; padding: 11px 13px; resize: vertical; line-height: 1.4; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: block; margin-bottom: 14px; min-width: 0; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--sunken); }
.btn-primary { background: var(--text); border-color: var(--text); color: #fff; }
.btn-primary:hover { background: #2a2e34; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--err); }
.btn[disabled] { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; font-size: 13px; }
.msg { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: var(--err); }
.msg.ok { color: var(--ok); }
.msg:empty { min-height: 0; }
input[type=file].input { padding: 8px 10px; font-size: 14px; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; border: 1px solid var(--line-strong); background: var(--sunken); border-radius: 6px; padding: 4px 10px; margin-right: 10px; cursor: pointer; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 30px 26px; }
.login-card h1 { margin: 14px 0 4px; font-size: 22px; letter-spacing: -.4px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.login-foot { color: var(--dim); font-size: 12px; text-align: center; margin: 16px 0 0; }

/* ---------- topo ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: auto; }
.brand img { width: 34px; height: 34px; flex: none; }
.brand b { display: block; font-size: 16px; letter-spacing: -.2px; }
.brand span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 5px; box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 6px; font-size: 14px; }
.menu-pop button:hover { background: var(--sunken); }
.menu-pop .who { padding: 8px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

.tabs { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 11px 12px 10px; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); }
.tabs .dot::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--warn); vertical-align: 2px; }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 60px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 14px; letter-spacing: -.1px; }
.card h2 small { margin-left: 6px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.layout > div { min-width: 0; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--sunken); border: 1px solid var(--line); border-radius: 9px; padding: 3px; margin-bottom: 16px; }
.seg button { border: 0; background: none; border-radius: 7px; height: 38px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.hint { font-size: 13px; color: var(--muted); margin: -6px 0 14px; }
.hint.warn { color: var(--warn); }

/* crédito: - [select] + */
.stepper { display: grid; grid-template-columns: 46px 1fr 46px; gap: 6px; }
.stepper button { height: 46px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; font-size: 20px; font-weight: 600; }
.stepper button:hover { background: var(--sunken); }
.stepper select { font-weight: 700; text-align: center; text-align-last: center; }

/* resultado */
.result { padding: 0; overflow: hidden; }
.result-main { padding: 18px; }
.result-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.result-value { font-size: 36px; font-weight: 750; letter-spacing: -1px; line-height: 1.1; margin: 4px 0 2px; }
.result-value small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.result-sub { font-size: 14px; color: var(--muted); }
.result-sub b { color: var(--text); }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }
.facts div { padding: 11px 14px; border-right: 1px solid var(--line); min-width: 0; }
.facts div:last-child { border-right: 0; }
.facts b { display: block; font-size: 14px; }
.facts span { display: block; font-size: 11px; color: var(--muted); }
.near { border-top: 1px solid var(--line); padding: 12px 14px 14px; background: var(--sunken); }
.near-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.near-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.near-list button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 4px; text-align: center; min-width: 0; }
.near-list button:hover { border-color: var(--line-strong); }
.near-list b { display: block; font-size: 13px; }
.near-list span { display: block; font-size: 12px; color: var(--muted); }

/* mensagem */
.bubble { background: var(--bubble); border-radius: 10px 10px 10px 2px; padding: 12px 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px; line-height: 1.5; min-height: 120px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions.one { grid-template-columns: 1fr; }
.bubble + .actions { margin-top: 12px; }

/* reduzida x integral: valor da parcela dentro do botão */
.seg.plano { margin-bottom: 0; }
.seg.plano button { height: auto; padding: 7px 4px; line-height: 1.25; }
.seg.plano button b { display: block; font-size: 15px; color: var(--text); }
.seg.plano button.on[data-plano="reduzida"] { box-shadow: inset 0 0 0 2px var(--ok); }
.seg.plano button.on[data-plano="integral"] { box-shadow: inset 0 0 0 2px var(--accent); }
.seg.plano button[disabled] { cursor: default; opacity: .55; }
.seg.plano button[disabled] b { font-size: 12px; font-weight: 600; color: var(--dim); }
.result-label .tag { margin-left: 6px; text-transform: none; letter-spacing: 0; font-size: 12px; }
.tag.int { background: var(--accent-soft); color: var(--accent); }

/* foto do caminhão */
.foto { margin-bottom: 10px; }
.foto img { display: block; width: 100%; max-height: 300px; object-fit: contain; background: var(--sunken); border-radius: 10px; border: 1px solid var(--line); }
.foto-vazia { display: block; text-align: center; padding: 18px 12px; border: 1.5px dashed var(--line-strong); border-radius: 10px; background: var(--sunken); cursor: pointer; }
.foto-vazia:hover { border-color: var(--accent); background: var(--accent-soft); }
.foto-vazia b { display: block; font-size: 14px; color: var(--accent); }
.foto-vazia span { display: block; font-size: 12.5px; color: var(--muted); }
.foto-vazia.busy { opacity: .6; pointer-events: none; }
.foto-acts { display: flex; justify-content: space-between; gap: 10px; padding: 6px 2px 0; }
.foto-acts label.link { cursor: pointer; }
.thumb { width: 52px; height: 40px; flex: none; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--sunken); }
th.sel { color: var(--text); }
.thumb.ext { display: grid; place-items: center; font-size: 11px; font-weight: 800; color: var(--err); background: #fdecea; border-color: #f6cfcb; }
#fichaLink { margin-top: -6px; }
.phone-row { margin-top: 12px; }

.vars { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.vars button { border: 1px solid var(--line-strong); background: var(--sunken); border-radius: 6px; padding: 4px 8px; font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; }
.vars button:hover { background: var(--accent-soft); border-color: var(--accent); }
#tmPrev { min-height: 80px; font-size: 14px; }

/* listas */
.list { display: grid; gap: 0; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; padding-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .m { font-size: 12.5px; color: var(--muted); }
.list-item .acts { display: flex; gap: 6px; flex: none; }
.empty { color: var(--muted); font-size: 14px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--sunken); color: var(--muted); vertical-align: 1px; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

/* tabela */
.table-tools { display: flex; gap: 10px; align-items: end; margin-bottom: 12px; flex-wrap: wrap; }
.table-tools .field { margin: 0; flex: 1; min-width: 200px; max-width: 320px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
td.r, th.r { text-align: right; }
tr.fit td { background: var(--ok-bg); }
tr.fit.last td { font-weight: 700; }
tr.out td { color: var(--dim); }
tbody tr:hover td { background: var(--sunken); }

/* grupo */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stats div { padding: 12px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 0 -1px -1px 0; }
.stats b { display: block; font-size: 16px; }
.stats span { display: block; font-size: 12px; color: var(--muted); }

/* admin */
.banner { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; background: var(--warn-bg); color: var(--warn); }
.banner b { color: var(--text); }
.prazo-card { display: flex; align-items: center; gap: 16px; }
.prazo-card .grow { flex: 1; min-width: 0; }
.prazo-card h2 { margin-bottom: 4px; }
.prazo-card p { margin: 0; font-size: 14px; }
.cmp { width: 100%; margin: 4px 0 14px; font-size: 14px; }
.cmp td, .cmp th { padding: 7px 6px; }
.cmp td:last-child { font-weight: 700; }
.upload-grid { display: grid; grid-template-columns: 1fr 120px; gap: 10px; align-items: end; }
.or { text-align: center; font-size: 12px; color: var(--dim); margin: 2px 0 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 14px; }

/* modal e toast */
#layer:empty { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(15,17,20,.4); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 420px; background: var(--surface); border-radius: 12px; padding: 22px; }
.modal h3 { margin: 0 0 6px; font-size: 18px; }
.modal p, .modal .mtxt { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.modal .actions { margin-top: 6px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 11px 16px; border-radius: 9px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .brand span { display: none; }
  .card { padding: 15px; }
  .card.result { padding: 0; }
  .result-value { font-size: 32px; }
  .near-list { grid-template-columns: repeat(2, 1fr); }
  .facts div { padding: 10px; }
  .list-item { flex-wrap: wrap; }
  .list-item .acts { width: 100%; }
  .list-item .acts .btn { flex: 1; }
  .upload-grid { grid-template-columns: 1fr; }
  .prazo-card { flex-direction: column; align-items: stretch; }
}
