:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17211c;
  --muted: #5d6b64;
  --line: #dfe5e2;
  --brand: #c62828;
  --brand-dark: #8e1b1b;
  --brand-ink: #ffffff;
  --brand-soft: #fdebeb;
  --ok: #1b7f4b;
  --ok-soft: #e3f4ec;
  --warn: #b26b00;
  --warn-soft: #fff4de;
  --bad: #a3122a;
  --bad-soft: #fbe3e7;
  --info: #2459c7;
  --info-soft: #e8effd;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141011;
    --card: #1e1718;
    --text: #efe7e8;
    --muted: #ab9b9d;
    --line: #362a2c;
    --brand: #e53935;
    --brand-dark: #b71c1c;
    --brand-ink: #ffffff;
    --brand-soft: #3d1a1b;
    --ok: #4cc38a;
    --ok-soft: #17352a;
    --warn: #f0a93b;
    --warn-soft: #3a2c12;
    --bad: #ff7a85;
    --bad-soft: #42191f;
    --info: #7aa5ff;
    --info-soft: #1a2640;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 10px; }
a { color: var(--info); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; color: var(--brand-ink);
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
}
.topbar h1 { font-size: 18px; }
.topbar button { background: transparent; color: inherit; border: 1px solid currentColor; padding: 6px 12px; min-height: 0; font-size: 14px; width: auto; }

main { padding: 12px 16px 40px; max-width: 640px; margin: 0 auto; }
main.wide { max-width: 1200px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; width: 100%;
}
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.big { min-height: 60px; font-size: 18px; }
.link { background: none; border: 0; color: var(--info); min-height: 0; padding: 6px 0; width: auto; font-weight: 500; text-decoration: underline; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.codigo-input { font-size: 28px; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.b-pendente { background: var(--line); color: var(--text); }
.b-em_rota { background: var(--info-soft); color: var(--info); }
.b-chegou { background: var(--warn-soft); color: var(--warn); }
.b-entregue { background: var(--ok-soft); color: var(--ok); }
.b-nao_entregue { background: var(--bad-soft); color: var(--bad); }

.alerta { padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-size: 14px; }
.alerta.erro { background: var(--bad-soft); color: var(--bad); }
.alerta.aviso { background: var(--warn-soft); color: var(--warn); }
.alerta.ok { background: var(--ok-soft); color: var(--ok); }

.entrega-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.entrega-head strong { font-size: 17px; }
.endereco { font-size: 16px; margin: 6px 0; }
.meta { font-size: 14px; color: var(--muted); }
.acoes { display: grid; gap: 8px; margin-top: 12px; }

.preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; background: #000; }
.spinner { width: 20px; height: 20px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  font-weight: 600; max-width: calc(100% - 32px); z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

/* Painel */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 12px 0; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 13px; color: var(--muted); }
.filtros { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.filtros > div { flex: 1 1 160px; }
.filtros button { width: auto; }
.tabela-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr.clicavel { cursor: pointer; }
tr.clicavel:hover td { background: var(--bg); }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-ok { color: var(--ok); font-weight: 600; }
.t-medio { color: var(--warn); font-weight: 700; }
.t-ruim { color: var(--bad); font-weight: 700; }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100% - 24px)); background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .conteudo { padding: 16px; max-height: 80vh; overflow: auto; }
dialog dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
dialog dt { color: var(--muted); }
dialog dd { margin: 0; }
.linha-tempo { list-style: none; padding: 0; margin: 12px 0; }
.linha-tempo li { padding: 6px 0 6px 18px; border-left: 2px solid var(--line); position: relative; font-size: 14px; }
.linha-tempo li::before { content: ""; position: absolute; left: -6px; top: 11px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
