/* ===== Colores (claro / oscuro) ===== */
:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --input: #ffffff;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06);
  color-scheme: light;
}
:root[data-theme="oscuro"] {
  --bg: #0b0f14; --card: #151b23; --text: #e5e7eb; --muted: #9ca3af;
  --border: #263040; --input: #0f141b; --shadow: none;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="claro"]) {
    --bg: #0b0f14; --card: #151b23; --text: #e5e7eb; --muted: #9ca3af;
    --border: #263040; --input: #0f141b; --shadow: none;
    --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444;
    color-scheme: dark;
  }
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  line-height: 1.4;
}
body.modal-open { overflow: hidden; }
button { font: inherit; }
.ic { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
h2, h3 { margin: 0; }

/* ===== Barra superior ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 8px; max-width: 720px; margin: 0 auto; }
.moto-switcher {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  background: none; border: 0; color: var(--text); cursor: pointer; padding: 4px; text-align: left;
}
.logo { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; flex: none; }
.logo.foto { border-radius: 50%; box-shadow: 0 0 0 2px var(--accent); }

/* Indicador de sincronización */
.sync {
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer; flex: none;
  display: grid; place-items: center; background: var(--card); color: var(--muted); position: relative;
}
.sync.ok { color: var(--ok); }
.sync.pendiente { color: var(--warn); }
.sync.error { color: var(--bad); }
.sync.sincronizando .ic { color: var(--accent); animation: latir 1s ease-in-out infinite; }
.sync.pendiente::after, .sync.error::after {
  content: ''; position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: currentColor;
}
@keyframes latir { 50% { opacity: .35; } }

/* Sin sesión: pantalla de acceso a pantalla completa */
body.sin-sesion .topbar, body.sin-sesion .tabbar { display: none; }
body.sin-sesion { padding-bottom: 0; }
.login { max-width: 400px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 32px) 0 32px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 10px 30px rgba(249, 115, 22, .35); }
.login h1 { margin: 16px 0 6px; font-size: 26px; }
.login p { margin: 0 0 20px; }
.login .lema { margin: -2px 0 10px; color: var(--accent); font-weight: 700; letter-spacing: .02em; }
.firma { text-align: center; color: var(--muted); font-size: 13px; margin: 22px 0 0 !important; }
.firma strong { color: var(--accent); }
.acerca { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 28px 0 8px; font-size: 14px; line-height: 1.5; }
.acerca img { width: 40px; height: 40px; border-radius: 10px; }
.acerca strong { color: var(--text); }
.acerca .muted strong { color: var(--accent); }
.login form { text-align: left; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--border); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.btn:disabled { opacity: .6; cursor: wait; }

.barra-historial { display: flex; justify-content: space-between; align-items: center; margin: 0 4px 12px; }

/* Fotos de los registros */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.thumb {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--bg); border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.thumb.sin-foto::after { content: 'Sin conexión'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.thumb-x {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; display: grid; place-items: center;
}
.thumb-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer;
  border-style: dashed; color: var(--muted); font-size: 12px;
}
.thumb-add:hover { color: var(--accent); border-color: var(--accent); }
.con-fotos { display: inline-flex; align-items: center; gap: 3px; }
.con-fotos .ic { width: 14px; height: 14px; }
.visor {
  position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .9);
  display: grid; place-items: center; padding: calc(env(safe-area-inset-top) + 16px) 16px 16px; cursor: zoom-out;
}
.visor img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.visor .icon-btn { position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 12px; background: rgba(255, 255, 255, .2); color: #fff; }

/* Fotos de la moto */
.avatar { width: 40px; height: 40px; border-radius: 11px; object-fit: cover; flex: none; }
.foto-edit { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.foto-preview {
  width: 110px; height: 82px; border-radius: 12px; flex: none; overflow: hidden;
  background: var(--bg); border: 1px dashed var(--border); display: grid; place-items: center; color: var(--muted);
}
.foto-preview img { width: 100%; height: 100%; object-fit: cover; }
.foto-btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hero { position: relative; }
.hero.con-foto {
  min-height: 210px; align-items: flex-end; background-size: cover; background-position: center;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .45);
}
.hero .hero-foto {
  position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: rgba(255, 255, 255, .2); color: #fff;
}
.hero .hero-foto .ic { width: 18px; height: 18px; }
.hero:not(.con-foto) { padding-right: 56px; }
.moto-text { display: flex; flex-direction: column; min-width: 0; }
.moto-text strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.moto-text small { color: var(--muted); font-size: 13px; }
.chevron { color: var(--muted); width: 18px; height: 18px; }

main { max-width: 720px; margin: 0 auto; padding: 16px; outline: none; }

/* ===== Barra de pestañas ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 130px; background: none; border: 0; cursor: pointer;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 500; padding: 6px 0;
}
.tab.active { color: var(--accent); }
.tab-add .ic {
  width: 52px; height: 52px; padding: 13px; margin-top: -22px;
  background: var(--accent); color: #fff; border-radius: 50%;
  box-shadow: 0 6px 16px rgba(249, 115, 22, .45);
}

/* ===== Tarjetas ===== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.pad { padding: 16px; }
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  margin: 24px 4px 8px; font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
}
.link { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-transform: none; letter-spacing: 0; font-size: 14px; padding: 0; }

.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 18px 20px; border: 0; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}
.hero .label { display: block; font-size: 13px; opacity: .85; }
.hero strong { font-size: 40px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.hero .unit { font-size: 16px; margin-left: 4px; opacity: .85; }
.hero .btn { background: rgba(255, 255, 255, .2); color: #fff; }
.hero .btn:hover { background: rgba(255, 255, 255, .3); }

.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 14px 0 0; }
.quick-btn {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 2px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 500;
}
.quick-btn:hover { border-color: var(--c); }
.quick-btn .ic { color: var(--c); width: 26px; height: 26px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.stats.two { grid-template-columns: repeat(2, 1fr); }
.stat { padding: 12px 14px; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.alerta .v { color: var(--bad); }

/* ===== Listas ===== */
.list { overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; background: none; border: 0; border-bottom: 1px solid var(--border);
  text-align: left; color: inherit; cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.item-ic {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: grid; place-items: center; color: var(--c);
  background: color-mix(in srgb, var(--c) 15%, transparent);
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 14px; flex: none; }
.item-side small { color: var(--muted); font-size: 12px; max-width: 130px; }
.empty { color: var(--muted); text-align: center; padding: 20px 16px; margin: 0; }
.group-head { display: flex; justify-content: space-between; margin: 18px 4px 6px; font-size: 13px; color: var(--muted); font-weight: 600; }

.bar { height: 6px; background: var(--border); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.aviso.pronto .bar i { background: var(--warn); }
.aviso.vencido .bar i { background: var(--bad); }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; background: var(--border); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.pronto { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.vencido { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.aviso.inactivo { opacity: .5; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ===== Gráficas ===== */
.chart { width: 100%; height: auto; display: block; }
.chart { max-height: 260px; }
.chart text { fill: var(--muted); font-size: 12px; }
.chart .grid { stroke: var(--border); }
.chart .line { stroke: var(--accent); fill: none; stroke-width: 2.5; stroke-linejoin: round; }
.chart .area { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.chart .avg { stroke: var(--muted); stroke-dasharray: 5 5; }
.chart circle { fill: var(--card); stroke: var(--accent); stroke-width: 2.5; }
.hbar { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 10px; padding: 8px 0; font-size: 14px; }
.hbar .track { height: 10px; border-radius: 5px; background: var(--border); overflow: hidden; }
.hbar .track i { display: block; height: 100%; border-radius: 5px; background: var(--c); }
.hbar strong { font-variant-numeric: tabular-nums; }
table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--border); }
.tabla th:first-child, .tabla td:first-child { text-align: left; }
.tabla th { color: var(--muted); font-weight: 600; font-size: 12px; }
.tabla tr:last-child td { border-bottom: 0; }

/* ===== Botones ===== */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer; font-weight: 600;
  background: var(--border); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn.sm { padding: 9px 14px; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid currentColor; }
.btn.block { width: 100%; }
.btn .ic { width: 18px; height: 18px; }
.btn-list { display: grid; gap: 8px; }
.icon-btn { background: var(--border); border: 0; color: var(--text); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }

/* ===== Modal / formularios ===== */
.modal {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(0, 0, 0, .5); align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 0 18px calc(18px + env(safe-area-inset-bottom));
  animation: subir .22s ease-out;
}
@keyframes subir { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  .modal { align-items: center; }
  .sheet { border-radius: 22px; padding-bottom: 18px; }
}
.sheet-head {
  position: sticky; top: 0; z-index: 1; background: var(--card);
  display: flex; justify-content: space-between; align-items: center; padding: 16px 0 12px;
}
.sheet-head h2 { font-size: 19px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); font-weight: 600; min-width: 0; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--input);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; padding: 0; }
.legend-small { font-weight: 500; font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.chk { position: relative; }
.chk input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chk span {
  display: inline-block; padding: 8px 13px; border: 1px solid var(--border); border-radius: 999px;
  font-size: 14px; cursor: pointer; color: var(--text); background: var(--input); user-select: none;
}
.chk input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chk input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; font-size: 15px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.switch small { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin: -6px 0 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-actions .primary { flex: 1; }
.form-error {
  background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad);
  padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; font-weight: 600;
}
[hidden] { display: none !important; }

.tipo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tipo-btn {
  display: flex; align-items: center; gap: 12px; padding: 14px; text-align: left;
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px; color: var(--text); cursor: pointer;
}
.tipo-btn:hover { border-color: var(--c); }
.tipo-btn .item-ic { width: 42px; height: 42px; }
.tipo-btn strong { display: block; font-size: 15px; }
.tipo-btn small { color: var(--muted); font-size: 12px; }

/* ===== Bienvenida ===== */
.welcome { text-align: center; padding: 40px 16px; }
.welcome img { width: 96px; height: 96px; border-radius: 24px; box-shadow: 0 10px 30px rgba(249, 115, 22, .35); }
.welcome h1 { margin: 20px 0 8px; font-size: 26px; }
.welcome p { color: var(--muted); max-width: 420px; margin: 0 auto 24px; }
.features { display: grid; gap: 10px; text-align: left; max-width: 420px; margin: 0 auto 28px; }
.features div { display: flex; gap: 12px; align-items: center; }

/* ===== Aviso flotante ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #111827; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: 14px;
  transition: opacity .2s, transform .2s; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .quick-btn { font-size: 11px; }
  .hero strong { font-size: 34px; }
  .row3 { grid-template-columns: 1fr 1fr; }
  .tipo-grid { grid-template-columns: 1fr; }
}
