:root {
  --bg: #F5F4EF;
  --card: #FFFFFF;
  --ink: #1A1A1A;
  --muted: #76756F;
  --line: #E6E4DD;
  --soft: #F0EFEA;
  --dark: #1A1A1A;
  --dark-2: #2A2A28;
  --on-dark: #FFFFFF;
  --on-dark-muted: #A3A29C;
  --yellow: #FFD21F;
  --yellow-ink: #1A1A1A;
  --red: #D93A2B;
  --red-bg: #FCE9E6;
  --amber: #B86E00;
  --amber-bg: #FFF2D6;
  --green: #1F8A47;
  --green-bg: #E3F4E8;
  --radius: 20px;
  --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111110;
    --card: #1D1D1B;
    --ink: #F2F1EC;
    --muted: #9A9993;
    --line: #2E2E2B;
    --soft: #262624;
    --dark: #000000;
    --dark-2: #1D1D1B;
    --red-bg: #3A1A16;
    --amber-bg: #3A2C10;
    --green-bg: #15301F;
    --red: #FF6B5C;
    --amber: #F0B23E;
    --green: #4CC27A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111110; --card: #1D1D1B; --ink: #F2F1EC; --muted: #9A9993; --line: #2E2E2B; --soft: #262624;
  --dark: #000000; --dark-2: #1D1D1B; --red-bg: #3A1A16; --amber-bg: #3A2C10; --green-bg: #15301F;
  --red: #FF6B5C; --amber: #F0B23E; --green: #4CC27A; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body.no-scroll { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; }
p { margin: 6px 0 12px; }
small { font-size: 13px; }
.muted { color: var(--muted); }
.muted-d { color: var(--on-dark-muted); }
.caps { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 600; }
.center { text-align: center; }
.small { font-size: 13px; }
.pad { padding: 4px 4px 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.ic { flex: none; }
.error { color: var(--red); font-weight: 600; }

#app { min-height: 100vh; }
main { padding-bottom: calc(var(--tabbar) + var(--safe-b) + 90px); }
.content { padding: 16px; max-width: 640px; margin: 0 auto; }

/* ---------- topo ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 16px) 16px 18px;
  background: var(--dark); color: var(--on-dark);
  border-radius: 0 0 26px 26px;
}
.tab-home .top { border-radius: 0; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 44px; height: 44px; flex: none; border-radius: 12px; }
.brand-text { min-width: 0; }
.brand h1 { font-size: 24px; font-weight: 800; }
.veh-chip { color: var(--on-dark-muted); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.pill-mini { border: 1px solid #555; border-radius: 99px; padding: 0 8px; font-size: 12px; color: var(--on-dark); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: #7C5CDB; color: #fff; font-weight: 700; font-size: 20px; display: grid; place-items: center;
}

/* ---------- herói (início) ---------- */
.hero { background: var(--dark); color: var(--on-dark); padding: 10px 16px 22px; border-radius: 0 0 26px 26px; }
.hero > * { max-width: 608px; margin-left: auto; margin-right: auto; }
.veh-row { display: flex; align-items: center; gap: 14px; }
.veh-photo { width: 84px; height: 84px; border-radius: 18px; background: var(--dark-2); display: grid; place-items: center; color: var(--on-dark-muted); overflow: hidden; flex: none; }
.veh-photo img { width: 100%; height: 100%; object-fit: cover; }
.veh-info { flex: 1; min-width: 0; }
.veh-info .caps { color: var(--on-dark-muted); }
.veh-info h2 { font-size: 34px; font-weight: 800; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ring {
  --p: 0; width: 84px; height: 84px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: conic-gradient(var(--yellow) calc(var(--p) * 1%), #3A3A37 0);
}
.ring > div { width: 70px; height: 70px; border-radius: 50%; background: var(--dark); display: grid; place-items: center; text-align: center; line-height: 1; }
.ring b { font-size: 22px; }
.ring small { font-size: 10px; letter-spacing: .1em; color: var(--on-dark-muted); font-weight: 700; }
.hero-link { display: flex; align-items: center; gap: 8px; width: 100%; padding: 14px 0; margin-top: 10px; border-bottom: 1px solid #333; }
.hero-link .ic:last-child { margin-left: auto; color: var(--on-dark-muted); }
.odo { margin-top: 18px; }
.odo-num { font-size: 44px; font-weight: 800; letter-spacing: -0.03em; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 99px; font-size: 14px; font-weight: 600; }
.pill.warn { background: #3D3214; color: var(--yellow); }
.pill.ok { background: #1E3326; color: #7BD69B; }
.stats { display: grid; grid-template-columns: 1fr 1fr; margin: 18px 0; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat + .stat { border-left: 1px solid #3A3A37; padding-left: 20px; }
.stat > span { display: flex; align-items: center; gap: 6px; }
.stat b { font-size: 20px; }
.stat small { color: var(--on-dark-muted); }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border-radius: 16px; font-weight: 700; font-size: 17px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
}
.btn.primary { background: var(--yellow); color: var(--yellow-ink); border-color: var(--yellow); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.danger-ghost { color: var(--red); border-color: transparent; background: none; font-weight: 600; font-size: 15px; }
.btn.small { min-height: 38px; padding: 0 16px; font-size: 15px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn-col { display: grid; gap: 10px; margin-top: 14px; }
.link { color: var(--ink); font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; gap: 4px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--yellow); text-decoration-thickness: 2px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; flex: none; }

/* ---------- cartões e linhas ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card h3 { font-size: 19px; }
.card-title { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; }
.card-title small { display: block; }
.sec { font-size: 16px; margin-bottom: 8px; }
.sec.out { margin: 18px 4px 10px; font-size: 18px; }
.sec.out::first-letter { text-transform: uppercase; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.25; }
.sec-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-right: 4px; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.split > div { flex: 1; min-width: 0; }
.split .right { text-align: right; }
.top-line { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 8px; align-items: flex-start; }
.top-line > div + div { border-left: 1px solid var(--line); padding-left: 12px; }
.top-line .caps { display: block; font-size: 11px; letter-spacing: .04em; }
.big { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.huge { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; }
.title { font-size: 24px; font-weight: 800; margin-top: 4px; }

.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 0; min-height: 56px; }
.row + .row { border-top: 1px solid var(--line); }
.card-row { background: var(--card); border-radius: 18px; padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--line); }
.card-row + .card-row { border-top: 1px solid var(--line); }
.card-row.selected { border-color: var(--yellow); border-width: 2px; }
.row-btn { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.row-ic { width: 46px; height: 46px; border-radius: 14px; background: var(--soft); border: 1px solid var(--line); display: grid; place-items: center; flex: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-main b { font-size: 17px; }
.row-main small { color: var(--muted); font-size: 14px; }
.row-side { text-align: right; font-weight: 700; font-size: 13px; max-width: 34%; flex: none; display: inline-flex; align-items: center; justify-content: flex-end; gap: 4px; line-height: 1.25; }
.row-side.money { max-width: 45%; }
.row-side.money { font-size: 16px; }
.row > .ic:last-child { color: var(--muted); }
.st-late { color: var(--red); }
.st-soon { color: var(--amber); }
.st-ok, .st-paid { color: var(--green); }
.st-uncal, .st-done { color: var(--muted); }
.st-bg-late { background: var(--red-bg); color: var(--red); border-color: transparent; }
.st-bg-soon { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.st-bg-ok { background: var(--green-bg); color: var(--green); border-color: transparent; }
.st-bg-uncal { background: var(--soft); color: var(--muted); }
.empty-line { display: flex; align-items: center; gap: 10px; color: var(--green); font-weight: 600; padding: 6px 0; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 4px -16px 0; padding: 0 16px 4px; scrollbar-width: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--line); border-radius: 99px; padding: 8px 14px; font-size: 15px; background: var(--card); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
.toggle-row small { display: block; }
.switch {
  appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 99px; flex: none;
  background: var(--line); position: relative; transition: background .2s; cursor: pointer; margin: 0;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch:checked { background: var(--yellow); }
.switch:checked::after { transform: translateX(20px); }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 18px; padding: 4px; margin-bottom: 14px; }
.seg button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; border-radius: 14px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.empty { text-align: center; padding: 30px 20px; }
.empty-ic { width: 72px; height: 72px; border-radius: 50%; background: var(--soft); display: inline-grid; place-items: center; margin-bottom: 10px; border: 1px solid var(--line); }

.chart-box { position: relative; height: 220px; margin-top: 12px; }
.chart-box.donut { height: 240px; }

.photo-box { width: 100%; aspect-ratio: 16 / 10; border-radius: 16px; background: var(--soft); display: grid; place-items: center; margin-top: 14px; overflow: hidden; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-box span { display: inline-flex; align-items: center; gap: 8px; }

.timeline .tl-year { display: flex; align-items: center; gap: 12px; margin: 4px 0 8px; }
.timeline .tl-year hr { flex: 1; border: 0; border-top: 1px solid var(--line); }
.tl-item { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 8px 0; }
.tl-dot { width: 32px; height: 32px; border-radius: 50%; background: var(--soft); display: grid; place-items: center; flex: none; border: 1px solid var(--line); }
.tl-dot.y { background: var(--yellow); color: var(--yellow-ink); border-color: var(--yellow); }

/* ---------- barra inferior e botão + ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 12px; font-weight: 600; position: relative; }
.tabbar button.on { color: var(--ink); }
.tabbar button.on::before { content: ""; position: absolute; top: 0; width: 36px; height: 4px; border-radius: 0 0 4px 4px; background: var(--yellow); }
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); z-index: 21;
  width: 64px; height: 64px; border-radius: 50%; background: var(--yellow); color: var(--yellow-ink);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(0,0,0,.18);
}
.fab-menu { position: fixed; inset: 0; z-index: 40; }
.fab-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); opacity: 0; transition: opacity .2s; }
.fab-menu.open .fab-backdrop { opacity: 1; }
.fab-list { position: absolute; right: 16px; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); display: flex; flex-direction: column; align-items: flex-end; gap: 12px; }
.fab-list button { display: flex; align-items: center; gap: 12px; transform: translateY(12px); opacity: 0; transition: .2s; }
.fab-menu.open .fab-list button { transform: none; opacity: 1; }
.fab-list button span { background: #fff; color: #1A1A1A; padding: 12px 20px; border-radius: 99px; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.fab-list button i { width: 56px; height: 56px; border-radius: 50%; background: #fff; color: #1A1A1A; display: grid; place-items: center; margin-right: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.fab-list .fab-close { width: 64px; height: 64px; border-radius: 50%; background: var(--yellow); color: var(--yellow-ink); justify-content: center; }

/* ---------- folha inferior ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); opacity: 0; transition: opacity .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; max-height: 92dvh;
  background: var(--card); border-radius: 26px 26px 0 0; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .25s ease-out; max-width: 640px; margin: 0 auto;
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-grip { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 10px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 18px 12px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 23px; font-weight: 800; }
.sheet-head p { margin: 4px 0 0; font-size: 15px; }
.sheet-body { overflow-y: auto; padding: 16px 18px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

/* ---------- formulários ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-weight: 600; font-size: 15px; }
.req { color: var(--red); font-style: normal; }
.hint { color: var(--muted); margin-top: -6px; font-size: 13px; }
.field .hint { margin-top: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%; min-height: 54px; padding: 12px 16px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-size: 17px; outline: none; -webkit-appearance: none; appearance: none;
}
input[type=date] { min-width: 0; display: block; }
input::-webkit-date-and-time-value { text-align: left; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2376756F' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); }
.affix { display: flex; align-items: center; border: 1.5px solid var(--line); border-radius: 16px; background: var(--card); padding: 0 14px; }
.affix:focus-within { border-color: var(--ink); }
.affix span { color: var(--muted); font-weight: 600; }
.affix input { border: 0 !important; padding-left: 8px !important; padding-right: 8px !important; min-width: 0; }
.affix.right input { padding-left: 2px !important; }
.upload { display: grid; justify-items: center; gap: 4px; padding: 20px; border: 1.5px dashed var(--line); border-radius: 16px; background: var(--soft); text-align: center; cursor: pointer; }
.up-ic { width: 46px; height: 46px; border-radius: 50%; background: var(--yellow); color: var(--yellow-ink); display: grid; place-items: center; }
.checks { display: grid; gap: 6px; max-height: 260px; overflow-y: auto; border: 1.5px solid var(--line); border-radius: 16px; padding: 8px 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 36px; cursor: pointer; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); flex: none; margin: 0; }
.cal-item { border: 1.5px solid var(--line); border-radius: 18px; padding: 14px; display: grid; gap: 10px; }
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-head small { width: 100%; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 16px 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; font-weight: 600; text-align: right; }
.detail h4 { margin: 8px 0; }
.mini-row { padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }

/* ---------- telas centrais ---------- */
.center-screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; max-width: 420px; margin: 0 auto; gap: 8px; }
.center-screen .logo { width: 84px; height: 84px; border-radius: 22px; margin-bottom: 8px; }
.center-screen h1 { font-size: 30px; font-weight: 800; }
.center-screen .form { width: 100%; text-align: left; margin-top: 12px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--yellow); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.offline { background: var(--amber-bg); color: var(--amber); text-align: center; font-size: 14px; font-weight: 600; padding: calc(var(--safe-t) + 6px) 12px 6px; }
.offline + main .top { padding-top: 16px; }

/* ---------- aviso rápido ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 14px); z-index: 99; transform: translate(-50%, -20px);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 14px; font-weight: 600; font-size: 15px;
  opacity: 0; transition: .25s; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--green); color: #fff; }
.toast.err { background: var(--red); color: #fff; }

/* ---------- laudo ---------- */
#report { position: fixed; inset: 0; z-index: 60; background: var(--bg); overflow-y: auto; }
.report-bar { position: sticky; top: 0; display: flex; justify-content: space-between; gap: 10px; padding: calc(var(--safe-t) + 10px) 16px 10px; background: var(--bg); }
.report-page { background: #fff; color: #1A1A1A; max-width: 800px; margin: 0 auto 40px; padding: 28px 22px; border-radius: 12px; }
.report-head { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.report-head .logo { width: 34px; height: 34px; border-radius: 9px; }
.report-head small { margin-left: auto; font-weight: 400; color: #76756F; }
.report-page h1 { font-size: 26px; margin: 22px 0 6px; }
.report-veh { display: flex; align-items: center; gap: 12px; font-size: 17px; flex-wrap: wrap; }
.plate { border: 1.5px solid #1A1A1A; border-radius: 4px; padding: 1px 8px; font-weight: 700; font-family: ui-monospace, monospace; }
.report-stats { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid #E6E4DD; border-bottom: 1px solid #E6E4DD; margin: 16px 0; padding: 12px 0; }
.report-stats div { display: grid; }
.report-stats b { font-size: 20px; }
.report-stats small { color: #76756F; text-transform: uppercase; font-size: 11px; letter-spacing: .06em; }
.report-page table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-page th { text-align: left; color: #76756F; font-weight: 600; border-bottom: 2px solid #1A1A1A; padding: 6px 4px; }
.report-page td { border-bottom: 1px solid #E6E4DD; padding: 8px 4px; vertical-align: top; }
@media print {
  body.printing > :not(#report) { display: none !important; }
  #report { position: static; overflow: visible; background: #fff; }
  .no-print { display: none !important; }
  .report-page { margin: 0; padding: 0; max-width: none; }
}

@media (min-width: 700px) {
  .tabbar { left: 50%; right: auto; width: 640px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; }
}
