/* ParkControl */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111114;
  --muted: #6b6b73;
  --line: #e1e1e6;
  --primary: #007aff;
  --primary-ink: #ffffff;
  --ok: #1e9e4a;
  --ok-bg: #e3f6e9;
  --warn: #b26a00;
  --warn-bg: #fff1d6;
  --bad: #d32f2f;
  --bad-bg: #fde7e7;
  --radius: 14px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #9a9aa2;
    --line: #2c2c2e;
    --ok: #4cd37b;
    --ok-bg: #12301e;
    --warn: #ffb340;
    --warn-bg: #3a2b0c;
    --bad: #ff6b6b;
    --bad-bg: #3d1717;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-top: var(--safe-t);
}
body.noscroll { overflow: hidden; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.25em; height: 1.25em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Estructura */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 24px); }
.section-title { margin: 22px 0 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-between .section-title { margin-top: 18px; }
.hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }
.hint.center { text-align: center; margin-top: 20px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; margin: 0; }
.warn { color: var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 10px 0 0; }

/* Tabs */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab .icon { width: 24px; height: 24px; }
.tab[aria-selected="true"] { color: var(--primary); }

/* Estadisticas */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 8px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.stat-n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12px; color: var(--muted); }

/* Botones y campos */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { width: 100%; min-height: 64px; margin: 14px 0 10px; font-size: 19px; border-radius: 16px; }
.icon-btn { background: none; border: 0; color: #fff; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; }
.icon-spacer { width: 44px; }

input, select {
  width: 100%; min-height: 44px; padding: 0 12px; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; padding: 0; flex: none; accent-color: var(--primary); }
.plate-input { text-transform: uppercase; letter-spacing: .12em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label > input, label > select { margin-top: 4px; color: var(--text); font-weight: 400; }
label > .plate-input { font-weight: 700; }
.manual { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.search { position: relative; display: block; margin: 8px 0 4px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; margin: 0; }
.switch-row { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 400; color: var(--text); }

/* Tarjetas y listas */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 10px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: var(--radius); padding: 12px 14px; color: inherit; font: inherit;
}
button.item { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button.item:active { background: color-mix(in srgb, var(--card) 85%, var(--primary)); }
.item-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.item-plate { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; font-size: 19px; letter-spacing: .08em; }
.item-sub { font-size: 13px; color: var(--muted); }
.item-end { text-align: right; display: grid; gap: 4px; justify-items: end; font-variant-numeric: tabular-nums; }
.item-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.item.col { flex-direction: column; align-items: stretch; }
.item.col .top { display: flex; align-items: center; gap: 12px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* Dialogos */
dialog {
  width: min(92vw, 460px); border: 0; border-radius: 20px; padding: 18px;
  background: var(--card); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 12px; font-size: 19px; }
dialog form { display: grid; gap: 12px; }
.actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; margin-top: 4px; }
.actions .btn { white-space: nowrap; }
.info { display: grid; gap: 6px; font-size: 14px; }
.info .line { display: flex; justify-content: space-between; gap: 12px; }
.info .line b { font-variant-numeric: tabular-nums; }
.info .big-amount { font-size: 26px; font-weight: 800; text-align: center; padding: 6px 0; }
.info .note { padding: 8px 12px; border-radius: 10px; background: var(--line); color: var(--text); }
.info .note.ok { background: var(--ok-bg); color: var(--ok); }
.info .note.warn { background: var(--warn-bg); color: var(--warn); }
.info .note.bad { background: var(--bad-bg); color: var(--bad); }

/* Avisos */
.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + var(--safe-b) + 12px); z-index: 80; display: grid; gap: 8px; pointer-events: none; justify-items: center; }
.toast { pointer-events: auto; max-width: 520px; padding: 11px 16px; border-radius: 14px; background: #1c1c1e; color: #fff; font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); }
.toast.error { background: var(--bad); }
.toast.success { background: var(--ok); color: #fff; }

/* Escaner */
.scanner { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; background: #000; color: #fff; }
.scan-top { display: flex; align-items: center; justify-content: space-between; padding: calc(8px + var(--safe-t)) 8px 8px; background: rgba(0, 0, 0, .75); }
.scan-title { font-weight: 600; }
.scan-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; }
.scan-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.guide { position: absolute; border: 3px dashed rgba(255, 255, 255, .8); border-radius: 12px; pointer-events: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
.scanner[data-state="success"] .guide { border-color: #4cd37b; border-style: solid; }
.scan-status {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  max-width: 92%; text-align: center; padding: 10px 18px; border-radius: 999px;
  background: rgba(0, 0, 0, .78); font-size: 14px; font-weight: 500;
}
.scan-status[data-kind="success"] { background: #1e9e4a; }
.scan-status[data-kind="reading"] { background: #0a5fcc; }
.scan-controls { display: flex; justify-content: center; align-items: center; gap: 28px; padding: 14px 16px calc(14px + var(--safe-b)); background: rgba(0, 0, 0, .85); }
.round { width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .2); color: #fff; display: grid; place-items: center; cursor: pointer; }
.round[aria-pressed="true"] { background: #ffd60a; color: #000; }
.round.shutter { width: 68px; height: 68px; background: #fff; color: #000; }
.round .icon { width: 24px; height: 24px; }
.debug-panel { position: absolute; top: 8px; left: 8px; right: 8px; padding: 8px; background: rgba(0, 0, 0, .72); border-radius: 10px; display: grid; gap: 6px; pointer-events: none; }
.debug-canvas { width: 100%; max-height: 90px; object-fit: contain; background: #fff; border-radius: 6px; }
.debug-text { margin: 0; font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; color: inherit; }
dialog .debug-canvas { max-height: 140px; border: 1px solid var(--line); }

@media (min-width: 720px) {
  .tabbar { max-width: 720px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) { .btn:active { transform: none; } }
