:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #ecebe7;
  --line: #dddcd6;
  --text: #121413;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #0f8a58;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0f8a58;
  --bad: #c93636;
  --warn: #b86e00;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121413;
    --surface: #1b1d1c;
    --surface-2: #262928;
    --line: #333634;
    --text: #f4f4f1;
    --text-2: #c3c2b7;
    --muted: #8d8c86;
    --accent: #3ecf8e;
    --accent-ink: #0b1a12;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good: #3ecf8e;
    --bad: #f07070;
    --warn: #e8a33a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121413; --surface: #1b1d1c; --surface-2: #262928; --line: #333634;
  --text: #f4f4f1; --text-2: #c3c2b7; --muted: #8d8c86;
  --accent: #3ecf8e; --accent-ink: #0b1a12; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --good: #3ecf8e; --bad: #f07070; --warn: #e8a33a;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .kpi b, .hero b, td.r { font-variant-numeric: tabular-nums; }

/* layout */
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
header.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line);
}
header.top h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top select { max-width: 50%; }
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
nav.tabs button {
  flex: 1; border: 0; background: none; padding: 9px 2px 8px; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
nav.tabs button svg { width: 22px; height: 22px; }
nav.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }

/* forms */
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; outline: none; min-height: 44px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent); }
input[type="date"], input[type="time"] { min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box; -webkit-appearance: none; appearance: none; display: block; }
input[type="date"]::-webkit-date-and-time-value, input[type="time"]::-webkit-date-and-time-value { text-align: left; }
.grid2 > *, .row > * { min-width: 0; }
.money { position: relative; }
.money::before { content: "R$"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.money input { padding-left: 38px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 8px; }
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.sec { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in oklab, var(--bad) 40%, transparent); }
.btn.full { width: 100%; }
button.link { background: none; border: 0; color: var(--accent); padding: 6px 0; cursor: pointer; font-weight: 600; }
button.icon { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; width: 44px; height: 44px; cursor: pointer; display: grid; place-items: center; flex: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
.chips button {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chips button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.err { color: var(--bad); font-size: 14px; min-height: 1em; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.logo { width: 48px; height: 48px; margin-bottom: 12px; }

/* painel */
.hero { padding: 18px; }
.hero .lbl { color: var(--text-2); font-size: 14px; }
.hero > b { display: block; font-size: 38px; line-height: 1.1; letter-spacing: -.02em; margin: 2px 0 6px; }
.hero2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 6px 0 8px; }
.hero2 span { display: block; font-size: 13px; color: var(--text-2); }
.hero2 b { display: block; font-size: clamp(20px, 6.2vw, 32px); line-height: 1.15; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: 0; }
.hero3 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 4px 0 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.hero3 span { display: block; font-size: 13px; color: var(--text-2); }
.hero3 b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.hero3 small { display: block; font-size: 12.5px; margin-top: 1px; }
.hero3 .dt { margin-top: 1px; }
.hero .sub { font-size: 14px; color: var(--text-2); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi span { display: block; font-size: 12.5px; color: var(--text-2); }
.kpi b { display: block; font-size: 21px; margin-top: 2px; letter-spacing: -.01em; }
.dt { display: inline-block; font-size: 12.5px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.dt.melhor { color: var(--good); } .dt.pior { color: var(--bad); } .dt.neutro { color: var(--muted); font-weight: 500; }
.kpi small .dt { margin-top: 0; font-size: 12px; }
.kpi small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.meter { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.empty { text-align: center; padding: 28px 16px; color: var(--text-2); }

/* charts */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--text-2); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .bar.s1 { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.comp { display: flex; gap: 2px; height: 14px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.comp i { display: block; height: 100%; }
.comp .s1, .dot.s1 { background: var(--series-1); }
.comp .s2, .dot.s2 { background: var(--series-2); }
.dot.s0 { background: transparent; box-shadow: inset 0 0 0 2px var(--text-2); }
.comp-leg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.comp-leg div { font-size: 12.5px; color: var(--text-2); }
.comp-leg b { display: block; font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; margin-top: 2px; }
.comp-leg small { color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart .bar.neg { fill: var(--bad); }
.chart .meta { stroke: var(--warn); stroke-width: 2; stroke-dasharray: 5 4; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .on { opacity: .75; }
.hbars { display: grid; gap: 10px; }
.hbar .t { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.hbar .t span:last-child { font-variant-numeric: tabular-nums; color: var(--text-2); }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 99px; margin-top: 4px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; background: var(--series-1); border-radius: 99px; }
.hbar .track i.s2 { background: var(--series-2); }
#tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--text); color: var(--bg);
  padding: 8px 10px; border-radius: 10px; font-size: 13px; line-height: 1.4; max-width: 220px;
  font-variant-numeric: tabular-nums; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
}

/* lançar */
.plat { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.plat:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.plat-nome { font-weight: 600; margin-bottom: 8px; }
.gasto { display: grid; grid-template-columns: 1.3fr 1fr 44px; gap: 8px; align-items: end; padding-bottom: 10px; border-bottom: 1px dashed var(--line); margin-bottom: 10px; }
.gasto .extra { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.sumbar {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); z-index: 4;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-top: 16px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 -6px 24px rgb(0 0 0 / .12);
}
.sumbar .grow div { font-size: 12.5px; color: var(--text-2); }
.sumbar .grow b { font-size: 20px; }
.datebar { display: flex; gap: 8px; align-items: center; }
.datebar input { flex: 1; text-align: center; font-weight: 600; }
.datebar .dow { text-align: center; font-size: 13px; color: var(--text-2); margin-top: 4px; }

/* histórico */
table.hist { width: 100%; border-collapse: collapse; font-size: 14px; }
table.hist th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 6px; border-bottom: 1px solid var(--line); }
table.hist td { padding: 11px 6px; border-bottom: 1px solid var(--line); }
table.hist tr.clk { cursor: pointer; }
table.hist tr.clk:active { background: var(--surface-2); }
table.hist .r, table.hist th.r { text-align: right; }
table.hist tfoot td { font-weight: 700; border-bottom: 0; }
.tbl { overflow-x: auto; }

/* usuários */
.user { display: flex; gap: 12px; align-items: center; }
.user .av { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; flex: none; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); margin-left: 6px; vertical-align: 1px; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.acts button { font-size: 13px; padding: 8px 12px; min-height: 38px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; z-index: 30; font-weight: 600;
  max-width: calc(100% - 32px);
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }

/* linha do tempo da jornada */
.tl { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.tl li { position: relative; padding: 4px 0 4px 10px; font-size: 14px; }
.tl li::before { content: ""; position: absolute; left: -20px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px var(--surface); }
.tl .ev-inicio::before, .tl .ev-retomada::before { background: var(--good); }
.tl .ev-pausa::before { background: var(--warn); }
.tl .ev-fim::before { background: var(--text); }
.tl .ev-descartada::before { background: var(--bad); }

/* mapa dia × hora (viagens) */
.mapa { display: grid; grid-template-columns: 30px repeat(24, 1fr); gap: 2px; align-items: center; }
.mapa .mh { font-size: 10px; color: var(--muted); text-align: center; }
.mapa .md { font-size: 11px; color: var(--text-2); }
.mapa .mc { aspect-ratio: 1; border: 0; border-radius: 3px; padding: 0; min-height: 10px; cursor: pointer; }

/* R$/km por categoria: marcador da média geral */
.hbar .ref { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text-2); border-radius: 1px; }
.chart .pt { cursor: pointer; }
/* janela de detalhe */
dialog.janela { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); padding: 18px; width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto; }
dialog.janela::backdrop { background: rgb(0 0 0 / .55); }

/* card principal do painel, enxuto */
.mini3, .mini2 { display: grid; gap: 10px; padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--line); }
.mini3 { grid-template-columns: repeat(3, 1fr); }
.mini2 { grid-template-columns: repeat(2, 1fr); border-top: 0; margin-top: 4px; padding-top: 4px; }
.mini3 span, .mini2 span { display: block; font-size: 12.5px; color: var(--muted); }
.mini3 b, .mini2 b { font-size: 18px; font-variant-numeric: tabular-nums; }
.mini3 small, .mini2 small { display: block; font-size: 12px; color: var(--muted); }
.mini3 small { display: inline; margin-left: 4px; }
.kv { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.kv .dt { margin: 0; font-size: 12px; }
.meta-hero { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.meta-hero .meter { margin-top: 0; }
.nota-hero { margin-top: 10px; font-size: 12.5px; color: var(--warn); }

.desl { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.rota { margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 12px; font-size: 14px; display: grid; gap: 6px; }
.rota b { margin-right: 4px; }
.mini2.tres { grid-template-columns: repeat(3, 1fr); }

/* nada vaza do card em tela estreita (iPhone 375px) */
.hero2 > *, .hero3 > *, .grid2 > *, .kpis > *, .mini2 > *, .mini3 > * { min-width: 0; }
.hero2 span, .hero3 span, .kpi span, .kpi small, .hero3 small { overflow-wrap: anywhere; }
@media (max-width: 420px) {
  table.hist { font-size: 12.5px; }
  table.hist th, table.hist td { padding-left: 3px; padding-right: 3px; }
  .hero3 b { font-size: 18px; }
  .kpi b { font-size: 19px; }
}

/* Viagens: uma linha por viagem, separador por dia */
table.viag td, table.viag th { white-space: nowrap; }
table.viag td { padding-top: 9px; padding-bottom: 9px; font-size: 13.5px; }
table.viag td.cat { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; }
table.viag tr.dia td { padding: 12px 6px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); }
