:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --card-2: #f7f8fc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e3e8f1;
  --brand: #3557f5;
  --brand-ink: #ffffff;
  --brand-soft: #e8edff;
  --good: #12965a;
  --good-soft: #dcf5e8;
  --warn: #c27406;
  --warn-soft: #fdf0d9;
  --bad: #d23a3a;
  --bad-soft: #fde4e4;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 16px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --card: #141a2e;
    --card-2: #1a2139;
    --text: #e8ebf4;
    --muted: #8d96ad;
    --line: #252d48;
    --brand: #6f8bff;
    --brand-ink: #0b1020;
    --brand-soft: #1e2850;
    --good: #3ccf8e;
    --good-soft: #123828;
    --warn: #f0a63a;
    --warn-soft: #3a2a10;
    --bad: #ff6b6b;
    --bad-soft: #3d1a1d;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(72px + var(--bottom));
}
a { color: var(--brand); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- topo e navegação ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
.bot-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.bot-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.bot-status.ok::before { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.bot-status.late::before { background: var(--warn); }
.bot-status.off::before { background: var(--bad); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + var(--bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--brand); }

.view { max-width: 720px; margin: 0 auto; padding: 16px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- blocos ---------- */
h1 { font-size: 24px; letter-spacing: -.02em; margin: 4px 0 16px; }
h2 { font-size: 15px; margin: 24px 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { background: var(--brand-soft); color: var(--text); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.hint.warn { background: var(--warn-soft); }
.hint.bad { background: var(--bad-soft); }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer;
  min-height: 44px; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn svg { width: 18px; height: 18px; }
.fab-row { display: flex; gap: 10px; flex-wrap: wrap; }
.fab-row .btn { flex: 1 1 140px; }

/* ---------- cartões de rota ---------- */
.route-card { display: block; color: var(--text); }
.route-card .od { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.route-card .od .arrow { color: var(--muted); font-weight: 400; margin: 0 4px; }
.route-card .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.price-big { font-size: 28px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.price-big small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.paused { background: var(--card-2); color: var(--muted); }
.spark { width: 100%; height: 44px; margin-top: 10px; }
.error-line { margin-top: 10px; font-size: 13px; color: var(--warn); }

/* ---------- gráfico ---------- */
.chart { width: 100%; height: 200px; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); stroke: none; font-size: 10px; }
.chart .line { stroke: var(--brand); stroke-width: 2.4; }
.chart .area { fill: var(--brand); opacity: .1; stroke: none; }
.chart .normal { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1.4; }
.chart .dot { fill: var(--brand); stroke: var(--card); stroke-width: 2; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 0; border-top: 2.4px solid var(--brand); vertical-align: middle; margin-right: 5px; }
.legend i.dash { border-top: 1.4px dashed var(--muted); }

/* ---------- calendário do mês ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; padding-bottom: 2px; }
.cal .day {
  aspect-ratio: 1 / 1.05; border-radius: 10px; background: var(--card-2); border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 11px; padding: 2px; cursor: pointer; min-width: 0;
}
.cal .day .n { font-weight: 700; font-size: 13px; }
.cal .day .p { font-size: 10px; font-weight: 600; white-space: nowrap; overflow: hidden; max-width: 100%; }
.cal .day.none { opacity: .45; cursor: default; }
.cal .day.past { opacity: .25; cursor: default; }
.cal .day.lvl-good { background: var(--good-soft); color: var(--good); }
.cal .day.lvl-warn { background: var(--warn-soft); color: var(--warn); }
.cal .day.lvl-bad { background: var(--bad-soft); color: var(--bad); }
.cal .day.lvl-mid { background: var(--card-2); }
.cal .day.sel { border-color: var(--brand); }
.cal .day.best { box-shadow: inset 0 0 0 2px var(--good); }

/* ---------- listas ---------- */
.list { display: flex; flex-direction: column; }
.list .item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; padding-top: 0; }
.list .item:last-child { padding-bottom: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
pre.log { white-space: pre-wrap; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; margin: 6px 0 0; color: var(--muted); }

/* ---------- formulário ---------- */
.field { display: block; }
.field + .field, .field + .grid2, .grid2 + .field, .grid2 + .grid2 { margin-top: 14px; }
.field > span, .label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--card-2); border-radius: 12px;
  padding: 11px 12px; min-height: 46px; outline: none; font-size: 16px; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }
.seg { display: flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type=range] { flex: 1; accent-color: var(--brand); }
.range-row output { min-width: 48px; text-align: right; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card-2); }
.stepper button { width: 46px; height: 46px; border: 0; background: transparent; font-size: 20px; cursor: pointer; }
.stepper output { flex: 1; text-align: center; font-weight: 700; }
.ac { position: relative; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
  max-height: 280px; overflow-y: auto; padding: 4px;
}
.ac-list button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; border: 0; background: transparent; padding: 10px; border-radius: 8px; cursor: pointer; }
.ac-list button:hover, .ac-list button:focus { background: var(--card-2); outline: none; }
.ac-list .code { font-weight: 800; font-size: 13px; background: var(--brand-soft); color: var(--brand); border-radius: 6px; padding: 2px 6px; min-width: 44px; text-align: center; }
.chosen { margin-top: 6px; font-size: 13px; color: var(--good); }
.chosen:empty { display: none; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch + .switch { border-top: 1px solid var(--line); }
.switch input { width: 46px; height: 28px; appearance: none; -webkit-appearance: none; background: var(--line); border-radius: 999px; position: relative; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--good); }
.switch input:checked::after { transform: translateX(18px); }

/* ---------- avisos ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.login { max-width: 400px; margin: 8vh auto 0; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 12px; }
