/* Mi coche · estilos mobile-first */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --danger: #b91c1c;
  --warn: #b45309;
  --ok: #15803d;
  --chip: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --card: #131c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #1f2a40;
    --primary: #14b8a6;
    --primary-ink: #04221f;
    --danger: #f87171;
    --warn: #fbbf24;
    --ok: #4ade80;
    --chip: #1f2a40;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; margin-top: 1rem; }

/* ---- Barra superior ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 1rem .75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topkm { font-size: .85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

main { max-width: 640px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.loading { text-align: center; color: var(--muted); padding: 3rem 0; }

/* ---- Tarjetas ---- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 1rem;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.card.narrow { max-width: 380px; margin: 2rem auto; width: 100%; }
.card.empty { text-align: center; }
.hero-icon { font-size: 2.5rem; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.big { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.okline { margin: .25rem 0 .5rem; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.sec-head h2 { margin: 0; }
.sec-head p { margin: 0; }
section { display: grid; gap: .6rem; }
.ver { margin-top: 1rem; }

/* ---- Km ---- */
.km-card { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; }
.km-form { display: flex; gap: .5rem; }
.km-form input { width: 8.5rem; }

/* ---- Accesos rápidos ---- */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.qbtn {
  display: grid; justify-items: center; gap: .2rem; padding: .7rem .25rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--text); font-size: .75rem; box-shadow: var(--shadow);
}
.qbtn span { font-size: 1.4rem; }

/* ---- Avisos ---- */
.rem {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: var(--radius); padding: .8rem .9rem; display: grid; gap: .4rem; box-shadow: var(--shadow);
}
.rem.pronto { border-left-color: var(--warn); }
.rem.vencido { border-left-color: var(--danger); }
.rem.sin_datos, .rem.inactivo { border-left-color: var(--muted); }
.rem.inactivo { opacity: .6; }
.rem-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.rem-meta { font-size: .85rem; color: var(--muted); display: grid; gap: .1rem; }
.rem-actions { display: flex; gap: .5rem; }
.badge { font-size: .7rem; font-weight: 700; padding: .15rem .5rem; border-radius: 99px; white-space: nowrap; background: var(--chip); }
.badge.ok { color: var(--ok); }
.badge.pronto { color: var(--warn); }
.badge.vencido { color: #fff; background: var(--danger); }
.bar { height: 6px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ok); }
.rem.pronto .bar span { background: var(--warn); }
.rem.vencido .bar span { background: var(--danger); }

/* ---- Listas ---- */
.list { display: grid; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.item { display: flex; align-items: center; gap: .75rem; padding: .75rem .9rem; color: var(--text); text-decoration: none; }
.item + .item { border-top: 1px solid var(--line); }
.ico { font-size: 1.3rem; }
.item-main { flex: 1; min-width: 0; display: grid; }
.item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-cost { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.month { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; padding: 0 .25rem; }
.split { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .3rem; }
.split li { display: flex; justify-content: space-between; font-size: .9rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; }
.chip { padding: .35rem .8rem; border-radius: 99px; background: var(--chip); color: var(--text); text-decoration: none; font-size: .85rem; white-space: nowrap; }
.chip.on { background: var(--primary); color: var(--primary-ink); }

.dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: .5rem 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.notes { white-space: pre-wrap; margin: 0; }
.fact-img { width: 100%; border-radius: 10px; border: 1px solid var(--line); }

/* ---- Formularios ---- */
.form { display: grid; gap: .8rem; }
.form label { display: grid; gap: .3rem; font-size: .88rem; color: var(--muted); }
.form label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .92rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .65rem .75rem; min-height: 44px;
}
input[type=checkbox], input[type=radio] { width: 1.2rem; height: 1.2rem; min-height: 0; accent-color: var(--primary); flex: none; }
input[type=file] { padding: .5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem .75rem; margin: 0; display: grid; gap: .5rem; }
legend { font-size: .82rem; color: var(--muted); padding: 0 .3rem; }
.file-box { display: grid; gap: .4rem; font-size: .88rem; color: var(--muted); }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: .5rem .2rem; border-radius: 10px; font-size: .72rem;
  background: var(--chip); color: var(--text); cursor: pointer; line-height: 1.3;
}
.seg input:checked + span { background: var(--primary); color: var(--primary-ink); font-weight: 600; }

.form[data-tipo=repostaje] .not-rep { display: none; }
.form:not([data-tipo=repostaje]) .only-rep { display: none; }

/* ---- Botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 44px; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.small { min-height: 36px; padding: .35rem .8rem; font-size: .85rem; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .6; cursor: wait; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }

/* ---- Barra inferior ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar[hidden] { display: none; }
.tabbar a { display: grid; justify-items: center; gap: .1rem; padding: .45rem 0 .5rem; font-size: .68rem; color: var(--muted); text-decoration: none; }
.tabbar a span { font-size: 1.2rem; }
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tabbar a.add span { color: var(--primary); font-size: 1.5rem; line-height: 1.1; }

/* ---- Toast ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 2rem); z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

@media (min-width: 700px) {
  main { padding: 1.5rem 1rem; }
  .qbtn { font-size: .85rem; }
}
