:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --ok: #047857;
  --ok-bg: #d1fae5;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #181b21; --ink: #e5e7eb; --muted: #9ca3af; --line: #2a2f38;
    --accent: #3b82f6; --ok: #34d399; --ok-bg: #064e3b; --warn: #fbbf24; --warn-bg: #451a03;
    --bad: #f87171; --bad-bg: #450a0a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .8rem; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* Barra superior */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 56px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-badge { background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 2px 7px; font-size: .8rem; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a { text-decoration: none; color: var(--muted); padding: 8px 11px; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.nav a.active, .nav a:hover { color: var(--ink); background: var(--bg); }
.user { display: flex; align-items: center; gap: 10px; font-size: .88rem; white-space: nowrap; margin-left: auto; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 80px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }

/* Formularios */
label { display: block; font-size: .83rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; min-height: 42px; }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; min-height: 0; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: .9rem; margin: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid .full { grid-column: 1 / -1; }
.field { min-width: 0; }
.origen-atajos { display: flex; gap: 8px; flex-wrap: wrap; }
.origen-atajos select { flex: 1 1 160px; width: auto; }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .92rem;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 9px 14px;
  min-height: 42px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.big { min-height: 54px; font-size: 1.02rem; width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.permisos td:not(:first-child), table.permisos th:not(:first-child) { text-align: center; width: 110px; }
table.permisos input[type=checkbox] { width: 20px; height: 20px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.chip.emitido { background: var(--ok-bg); color: var(--ok); }
.chip.finalizado { background: var(--line); color: var(--muted); }
.chip.anulado { background: var(--bad-bg); color: var(--bad); }

.alert { border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; font-size: .92rem; }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* Datos clave/valor */
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 20px; }
.kv div span { display: block; font-size: .78rem; color: var(--muted); }
.kv div b { font-weight: 600; word-break: break-word; }

/* Carga (vehículo transportado) */
.carga { border: 1px dashed var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.carga-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }

/* Tarjetas de lista para el conductor */
.list-cards { display: grid; gap: 10px; }
.deca-card { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; }
.deca-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

/* Elección auxilio / traslado */
.choice { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.choice button { text-align: left; font: inherit; color: inherit; background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--radius); padding: 18px; cursor: pointer; }
.choice button:hover { border-color: var(--accent); }
.choice b { display: block; font-size: 1.05rem; margin-bottom: 4px; }

/* Modo inspección */
.inspect { position: fixed; inset: 0; z-index: 50; background: #fff; color: #111; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; padding: 24px 16px; text-align: center; overflow-y: auto; }
.inspect img { width: min(78vw, 380px); height: auto; image-rendering: pixelated; }
.inspect .num { font-size: 1.4rem; font-weight: 800; letter-spacing: .02em; }
.inspect .plate { font-size: 1.1rem; }
.inspect .btn { min-width: 220px; }
.inspect .btn:not(.primary) { background: #fff; color: #111; border-color: #d1d5db; }
.inspect .anulado { background: #fee2e2; color: #b91c1c; font-weight: 800; padding: 6px 14px; border-radius: 6px; }

/* Login */
.login { max-width: 380px; margin: 10vh auto; padding: 0 16px; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; }
#toast.show { opacity: 1; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 6px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .user .who { display: none; }
  .hide-sm { display: none; }
  main { padding-top: 14px; }
  .card { padding: 14px; }
}
