/* ---------- Tokens ---------- */
:root {
  color-scheme: light dark;

  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f7f7f5;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;

  --brand: #2a78d6;
  --brand-ink: #ffffff;
  --series-1: #2a78d6;  /* combustível */
  --series-2: #eb6834;  /* outros gastos */

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 6px 20px rgba(11, 11, 11, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    --bg: #0d0e11;
    --surface: #16181d;
    --surface-2: #1d2027;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #8d8c86;
    --line: #2a2d34;
    --line-strong: #3a3e46;

    --brand: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0e11;
  --surface: #16181d;
  --surface-2: #1d2027;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #8d8c86;
  --line: #2a2d34;
  --line-strong: #3a3e46;
  --brand: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* hidden tem que vencer o display das classes (.btn-row é flex, .aviso-pendente é block) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px); }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

button { font: inherit; color: inherit; }

/* ---------- Topo ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px 12px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}

.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { font-size: 18px; }
.topbar .sub { color: var(--ink-muted); font-size: 12.5px; margin-top: 2px; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  cursor: pointer;
  font-size: 16px;
}

/* ---------- Layout ---------- */
main { padding: 16px; max-width: 720px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

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

.card h2 { font-size: 14px; color: var(--ink-2); font-weight: 600; margin-bottom: 12px; }

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-muted);
  margin: 22px 2px 8px;
  font-weight: 650;
}

/* ---------- Hero / stats ---------- */
.hero { text-align: left; }
.hero .label { font-size: 12.5px; color: var(--ink-muted); }
.hero .value { font-size: 40px; font-weight: 680; letter-spacing: -.03em; line-height: 1.05; margin-top: 4px; }
.hero .value small { font-size: 17px; font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.hero .delta { font-size: 13px; margin-top: 6px; color: var(--ink-2); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
}
.stat .k { font-size: 11.5px; color: var(--ink-muted); }
.stat .v { font-size: 21px; font-weight: 650; margin-top: 3px; letter-spacing: -.02em; }
.stat .v small { font-size: 12px; color: var(--ink-2); font-weight: 600; }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.item:active { background: var(--surface-2); }
.item .bullet {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--ink-2);
}
.item .bullet svg { width: 18px; height: 18px; }
.nav svg { width: 21px; height: 21px; display: block; }
.item .main { flex: 1; min-width: 0; }
.item .t { display: block; font-size: 14.5px; font-weight: 600; }
.item .s { display: block; font-size: 12.5px; color: var(--ink-muted); margin-top: 3px; line-height: 1.35; }
.item .r { text-align: right; font-size: 14.5px; font-weight: 650; white-space: nowrap; }
.item .s b { color: var(--ink-2); font-weight: 650; }
.pedente { color: #8a5a00; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .pedente { color: var(--warning); }
}
:root[data-theme="dark"] .pedente { color: var(--warning); }
.item .r small { display: block; font-size: 11.5px; font-weight: 500; color: var(--ink-muted); margin-top: 2px; }

.empty {
  text-align: center;
  color: var(--ink-muted);
  font-size: 13.5px;
  padding: 28px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

/* ---------- Lembretes ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.pill.ok { color: #006300; border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.pill.warn { color: #8a5a00; border-color: color-mix(in srgb, var(--warning) 55%, var(--line)); }
.pill.late { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, var(--line)); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .pill.ok { color: #4bd14b; }
  :root:where(:not([data-theme="light"])) .pill.warn { color: var(--warning); }
}
:root[data-theme="dark"] .pill.ok { color: #4bd14b; }
:root[data-theme="dark"] .pill.warn { color: var(--warning); }

/* ---------- Botões ---------- */
.btn {
  border: 0;
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--critical); border: 1px solid color-mix(in srgb, var(--critical) 40%, var(--line)); }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }

/* ---------- Formulários ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 11, 11, .45);
  z-index: 50;
  display: none;
}
.sheet-backdrop.open { display: block; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 51;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  max-height: 92vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform .22s ease;
  padding: 8px 16px calc(24px + var(--safe-b));
  max-width: 720px; margin: 0 auto;
}
.sheet.open { transform: none; }
.sheet .grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line-strong); margin: 8px auto 14px; }
.sheet h2 { font-size: 17px; margin-bottom: 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* evita zoom no iOS */
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.field .hint { font-size: 11.5px; color: var(--ink-muted); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 10px; }
.switch label { margin: 0; font-size: 14px; color: var(--ink); }
.switch input { width: 22px; height: 22px; accent-color: var(--brand); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- Gráficos ---------- */
.chart-wrap { position: relative; }
.chart { width: 100%; display: block; overflow: visible; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 2px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 12px;
  color: var(--ink);
  box-shadow: var(--shadow);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .12s;
  z-index: 5;
}
.tooltip.on { opacity: 1; }
.tooltip b { font-weight: 650; }
.tooltip .row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.tooltip .row i { width: 8px; height: 8px; border-radius: 2px; }

.aviso-pendente {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--warning) 55%, var(--line));
  background: color-mix(in srgb, var(--warning) 12%, var(--surface));
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 13.5px;
  line-height: 1.4;
  margin-bottom: 14px;
  cursor: pointer;
}
.aviso-pendente b { font-weight: 650; }
.aviso-pendente span { display: block; color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }

/* ---------- Rendimento por posto ---------- */
.posto { padding: 11px 0; border-bottom: 1px solid var(--line); }
.posto:last-of-type { border-bottom: 0; padding-bottom: 2px; }
.posto .topo { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.posto .nome { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.posto .kml { font-size: 15px; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.posto .kml small { font-size: 11.5px; font-weight: 600; color: var(--ink-2); }
.posto .barra { height: 8px; border-radius: 4px; background: var(--surface-2); margin: 7px 0 6px; overflow: hidden; }
.posto .barra i { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.posto .det { font-size: 12px; color: var(--ink-muted); }
.posto .det .aviso { color: #8a5a00; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .posto .det .aviso { color: var(--warning); }
}
:root[data-theme="dark"] .posto .det .aviso { color: var(--warning); }

.nota { font-size: 11.5px; color: var(--ink-muted); margin: 12px 0 0; line-height: 1.45; }

/* ---------- Status da nuvem ---------- */
.status-nuvem { display: flex; align-items: center; gap: 11px; }
.status-nuvem .t { font-size: 14px; font-weight: 600; }
.status-nuvem .s { font-size: 12.5px; color: var(--ink-muted); margin-top: 2px; word-break: break-all; }
.bolinha { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; background: var(--ink-muted); }
.bolinha.ok { background: var(--good); }
.bolinha.aguardando { background: var(--warning); }
.bolinha.erro { background: var(--critical); }

details.table-view { margin-top: 10px; }
details.table-view summary { font-size: 12.5px; color: var(--ink-muted); cursor: pointer; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-muted); font-weight: 600; }

/* ---------- Navegação ---------- */
.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.nav button {
  border: 0; background: none;
  padding: 9px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10.5px;
  color: var(--ink-muted);
  cursor: pointer;
}
.nav button .ico { font-size: 19px; line-height: 1; }
.nav button[aria-current="true"] { color: var(--brand); font-weight: 650; }

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  opacity: 0;
  transition: all .2s;
  z-index: 60;
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%); }
