:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #141920;
  --muted: #5c6672;
  --border: #dde2e8;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d5efeb;
  --danger: #c62828;
  --danger-soft: #fde5e5;
  --warn: #a35f00;
  --warn-soft: #fff0d4;
  --ok: #2e7d32;
  --ok-soft: #e1f2e2;
  --shadow: 0 1px 2px rgba(16, 24, 32, .05), 0 4px 14px rgba(16, 24, 32, .06);
  --backdrop: rgba(10, 14, 20, .45);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1317;
    --surface: #181d23;
    --surface-2: #222830;
    --text: #e9edf1;
    --muted: #9aa5b1;
    --border: #2c333c;
    --accent: #2bb3a6;
    --accent-ink: #04201d;
    --accent-soft: #123a36;
    --danger: #ff6b6b;
    --danger-soft: #3a1c1e;
    --warn: #f2b14c;
    --warn-soft: #3a2c14;
    --ok: #6fcf75;
    --ok-soft: #173020;
    --shadow: none;
    --backdrop: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0 auto;
  max-width: 560px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.sheet-open { overflow: hidden; }

button, input, textarea { font: inherit; color: inherit; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barra superior y pestañas ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
}
.topbar h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn[hidden] { display: none; }

main {
  padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
body.no-tabs main { padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }

.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 10;
  width: 100%; max-width: 560px;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
body.no-tabs .tabbar { display: none; }
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer;
}
.tabbar button.active { color: var(--accent); font-weight: 600; }

/* ---------- Bloques ---------- */

/* Superficie común de tarjetas, cifras, listas y tarjetas de mantenimiento */
.card, .stat, .list, .mcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card { padding: 16px; margin-bottom: 12px; }
.grow { flex: 1; }
.section-title { margin: 22px 4px 8px; font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.small { font-size: 14px; }
.hint { margin: 6px 2px 0; font-size: 14px; color: var(--muted); min-height: 1em; }
.sub { margin-top: -8px; }            /* subtítulo pegado al título de una hoja */
.note { margin: -4px 2px 10px; }      /* aclaración pegada a los campos que siguen */
.hint.warn { color: var(--warn); }

.hero { text-align: center; padding: 18px 0 20px; }
.hero .eyebrow { color: var(--muted); font-size: 14px; }
.odo { font-size: 46px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.odo span { font-size: 20px; font-weight: 600; color: var(--muted); }

.stat-grid, .btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { padding: 14px; }
.stat-v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 13px; color: var(--muted); margin-top: 2px; }
.stat-s { font-size: 12px; color: var(--muted); margin-top: 4px; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; border: 1px dashed var(--border); border-radius: var(--radius); }

.banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius); margin-bottom: 12px; background: var(--warn-soft); color: var(--text); }
.banner .grow { font-size: 14px; }
.banner.info { background: var(--accent-soft); }
.banner .icon-btn { width: 32px; height: 32px; flex: none; }
.steps { padding-left: 22px; margin: 0 0 14px; }
.steps li { margin-bottom: 8px; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-stop { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-big { width: 100%; min-height: 64px; font-size: 20px; border-radius: 18px; margin-bottom: 12px; }
.btn-block { width: 100%; }
a.btn, a.link { text-decoration: none; }
.btn-block + .btn-block { margin-top: 10px; }
.btn-row .btn { padding: 0 10px; white-space: nowrap; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 0; cursor: pointer; }

.trip-live { display: flex; gap: 12px; align-items: center; border-color: var(--danger); }
.live-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); flex: none; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- Listas ---------- */

.list { overflow: hidden; margin-bottom: 12px; }
.item {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 12px 14px;
  border: 0; border-bottom: 1px solid var(--border); background: none; text-align: left; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.item-main { flex: 1; min-width: 0; }
.item-main > * { overflow: hidden; text-overflow: ellipsis; }
.item-side { text-align: right; flex: none; }
.item .muted { font-size: 14px; }
.group-head { display: flex; justify-content: space-between; margin: 18px 4px 6px; font-size: 14px; font-weight: 600; color: var(--muted); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.work { background: var(--accent-soft); color: var(--accent); }

/* ---------- Mantenimiento ---------- */

.mcard {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 14px;
  margin-bottom: 8px; text-align: left; cursor: pointer;
}
.micon { font-size: 26px; width: 34px; text-align: center; flex: none; }
.mbody { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.mname { font-weight: 600; }
.mtext { font-size: 14px; color: var(--muted); }
.mstate { flex: none; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.state-overdue { border-color: var(--danger); }
.state-overdue .mstate { background: var(--danger-soft); color: var(--danger); }
.state-overdue .progress span { background: var(--danger); }
.state-soon .mstate { background: var(--warn-soft); color: var(--warn); }
.state-soon .progress span { background: var(--warn); }
.state-ok .mstate { background: var(--ok-soft); color: var(--ok); }
.state-none .mstate { background: var(--surface-2); color: var(--muted); }
.progress { display: block; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 4px; }
.progress span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

/* ---------- Formularios y hojas ---------- */

#sheet-root .backdrop {
  position: fixed; inset: 0; z-index: 20; background: var(--backdrop);
  opacity: 0; transition: opacity .2s;
}
#sheet-root .sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 21;
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 20px);
  background: var(--surface); border-radius: 22px 22px 0 0;
  transform: translate(-50%, 100%); transition: transform .22s ease-out;
}
#sheet-root.open .backdrop { opacity: 1; }
#sheet-root.open .sheet { transform: translate(-50%, 0); }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 8px; }
.sheet h2 { margin: 6px 40px 16px 0; font-size: 21px; }
.sheet-x { position: absolute; top: 12px; right: 12px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; font-weight: 600; color: var(--muted); margin: 0 2px 6px; }
.field input, .field textarea {
  width: 100%; min-height: 50px; padding: 10px 14px;
  font-size: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg);
}
.field textarea { min-height: 80px; font-size: 16px; resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field input.big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: center; }
.field input.calc { background: var(--accent-soft); }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 .field input { font-size: 17px; padding: 10px; }
.form-error { color: var(--danger); font-weight: 600; margin: 0 0 10px; }
.form-error:empty { display: none; }
.result { text-align: center; font-size: 18px; margin: -4px 0 14px; min-height: 1.4em; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 9px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); font-size: 15px;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }

.onboard { padding-top: 24px; }
.onboard .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 16px; }
.onboard h2 { text-align: center; margin: 0 0 6px; font-size: 26px; }
.onboard p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; }

/* ---------- Avisos flotantes: mensajes (abajo) y versión nueva (arriba) ---------- */

#toast, #update {
  position: fixed; left: 50%; z-index: 30;
  display: flex; gap: 12px; align-items: center; width: calc(100% - 32px); max-width: 528px;
  padding: 12px 16px; border-radius: 14px; font-weight: 600;
}
#toast {
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s;
  background: var(--text); color: var(--bg);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { border: 0; background: none; color: var(--accent-soft); font-weight: 700; cursor: pointer; padding: 4px; }
#update { top: calc(env(safe-area-inset-top) + 8px); transform: translateX(-50%); background: var(--accent); color: var(--accent-ink); }
#update[hidden] { display: none; }
#update button { border: 0; border-radius: 10px; padding: 6px 12px; background: var(--accent-ink); color: var(--accent); font-weight: 700; cursor: pointer; }
