/* Tema único: fondo negro y acentos en gris (igual en modo claro y oscuro del teléfono). */
:root {
  --bg: #000000;
  --surface: #121214;
  --surface-2: #1d1d20;
  --line: #2b2b2f;
  --text: #ededed;
  --muted: #9a9a9f;
  --accent: #4a4a50;        /* botones principales, tarjeta destacada, logo */
  --accent-ink: #ffffff;
  --accent-soft: #2a2a2e;
  --accent-text: #e4e4e7;   /* pestaña activa y textos resaltados */
  --ok: #4cc27f;
  --ok-soft: #173325;
  --warn: #e7b04a;
  --warn-soft: #3a2f16;
  --bad: #ff6b6b;
  --bad-soft: #3c1c1c;
  --info: #6aa8ff;
  --info-soft: #182a42;
  --shadow: 0 1px 2px rgba(0,0,0,.6);
  --radius: 14px;
  --nav-h: 66px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { flex: 1; min-width: 0; }
.topbar .brand b { display: block; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand small { color: var(--muted); font-size: 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.brand-mark svg.i { width: 20px; height: 20px; }

main {
  overflow-x: hidden;
  padding: 16px 16px calc(var(--nav-h) + 96px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.tabbar a.on { color: var(--accent-text); }
.tabbar a.on svg.i { stroke-width: 2.4; }

.fab {
  position: fixed; z-index: 15;
  right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  height: 56px; padding: 0 20px 0 16px; border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; gap: 8px;
  font: 700 16px system-ui, sans-serif;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .6);
}

/* ---------- Encabezados de página ---------- */
.page-head { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; }
.page-head h1 { font-size: 24px; letter-spacing: -.02em; flex: 1; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-weight: 600; margin: -4px 0 8px -4px; padding: 6px 4px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 2px 8px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- Tarjetas ---------- */
.card { display: block; background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row > :first-child { min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strong { font-weight: 700; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

.order-card .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.order-card .folio { color: var(--muted); font-weight: 700; font-size: 13px; }
.order-card .who { font-weight: 700; font-size: 16.5px; }
.order-card .veh { color: var(--muted); font-size: 14px; margin-top: 2px; }
.order-card .bottom { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; }

.badge { display: inline-block; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.b-recibido   { background: var(--surface-2); color: var(--text); }
.b-diagnostico{ background: var(--info-soft); color: var(--info); }
.b-espera     { background: var(--warn-soft); color: var(--warn); }
.b-en_proceso { background: var(--accent-soft); color: var(--accent-text); }
.b-listo      { background: var(--ok-soft); color: var(--ok); }
.b-entregado  { background: var(--surface-2); color: var(--muted); }
.b-cancelado  { background: var(--bad-soft); color: var(--bad); }
.debe { color: var(--bad); font-weight: 700; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }

/* ---------- Resumen ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat span { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat b { display: block; font-size: 22px; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stat.accent span { color: inherit; opacity: .85; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 700 15.5px system-ui, sans-serif; cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.sm { min-height: 40px; padding: 0 13px; font-size: 14px; border-radius: 10px; }
.btn.danger-ghost { color: var(--bad); background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.ok { background: #1f8a4c; border-color: #1f8a4c; color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 0; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; font-size: 20px; cursor: pointer; }

/* ---------- Chips / buscador ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; scrollbar-width: none; }
.chip { flex: none; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 14px; color: var(--text); cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.search { position: relative; margin-bottom: 12px; }
.search svg.i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 20px; height: 20px; }
.search input { padding-left: 44px; }

/* ---------- Formularios ---------- */
input, select, textarea {
  width: 100%; min-height: 48px; padding: 11px 13px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: 16px system-ui, sans-serif;
  appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8a8a90; outline-offset: -1px; border-color: transparent; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 6px; grid-column: 1 / -1; }
.field.half { grid-column: span 1; }
.field > span { font-size: 13.5px; font-weight: 700; color: var(--muted); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.with-btn { display: flex; gap: 8px; }
.with-btn > :first-child { flex: 1; min-width: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: grid; place-items: center; min-height: 42px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Hoja inferior (diálogos) ---------- */
dialog.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--bg); color: var(--text);
}
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgba(0,0,0,.45); }
dialog.sheet form { display: flex; flex-direction: column; max-height: 92vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 18px; }
.sheet-head h2 { font-size: 19px; }
.sheet-body { padding: 8px 18px 16px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.sheet-foot .btn.primary { flex: 1; }

/* ---------- Detalle ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.block-text { white-space: pre-wrap; }
.lines { display: grid; grid-template-columns: minmax(0, 1fr); }
.line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.line:last-child { border-bottom: 0; }
.tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.totals { display: grid; gap: 4px; padding-top: 10px; margin-top: 4px; border-top: 2px solid var(--line); }
.totals .row { font-size: 15px; }
.totals .grand { font-size: 19px; font-weight: 800; }
.estado-select { font-weight: 700; }
.contact { display: flex; gap: 8px; margin-top: 12px; }
.contact .btn { flex: 1; }

/* ---------- Caja ---------- */
.mov { display: flex; align-items: center; gap: 12px; }
.mov .arrow { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; font-weight: 800; }
.mov .arrow.in { background: var(--ok-soft); color: var(--ok); }
.mov .arrow.out { background: var(--bad-soft); color: var(--bad); }
.mov .txt { flex: 1; min-width: 0; }
.day { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 2px 6px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 5px; }
.bar i { display: block; height: 100%; background: var(--bad); border-radius: 4px; }

/* ---------- Inventario ---------- */
.stock { font-weight: 800; font-variant-numeric: tabular-nums; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); }
.stock.low { background: var(--bad-soft); color: var(--bad); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .box { width: 100%; max-width: 380px; }
.auth .logo { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin-bottom: 18px; }
.auth .logo svg.i { width: 34px; height: 34px; }
.auth h1 { font-size: 28px; letter-spacing: -.02em; margin-bottom: 4px; }
.auth p { color: var(--muted); margin: 0 0 22px; }
.auth form { display: grid; gap: 14px; }
.link-btn { background: none; border: 0; color: var(--muted); font: 600 14px system-ui, sans-serif; text-decoration: underline; padding: 10px; cursor: pointer; }

/* ---------- Avisos ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 86px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14.5px;
  transition: .2s ease; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); color: #fff; }
.skeleton { height: 76px; border-radius: var(--radius); background: var(--surface-2); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------- Fotos ---------- */
.file-oculto { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; pointer-events: none; }
.btn.busy { opacity: .55; pointer-events: none; }
.fotos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.fotos-grid:empty { display: none; }
.foto { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 0; padding: 0; cursor: pointer; }
.foto img { width: 100%; height: 100%; object-fit: cover; display: block; }
.foto .quitar { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 13px; display: grid; place-items: center; cursor: pointer; }

dialog.visor { width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; color: #fff; }
dialog.visor::backdrop { background: #000; }
.visor-wrap { display: flex; flex-direction: column; height: 100%; }
.visor-head { display: flex; align-items: center; justify-content: space-between; padding: calc(6px + env(safe-area-inset-top)) 6px 6px 16px; }
.visor-head .icon-btn { color: #fff; }
.visor-img { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; }
.visor-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.visor-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0; border-radius: 12px; background: rgba(0,0,0,.45); color: #fff; font-size: 32px; cursor: pointer; }
.visor-nav.prev { left: 8px; }
.visor-nav.next { right: 8px; }
.visor-nav[hidden] { display: none; }
.visor-foot { display: flex; gap: 8px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
.visor-foot .btn { flex: 1; }
