:root {
  --ink:        #11161D;
  --ink-2:      #171E27;
  --paper:      #F4EFE4;
  --paper-2:    #EAE3D2;
  --ink-text:   #1A1F26;
  --muted:      #746C5C;
  --muted-2:    #9A9384;
  --green:      #1F9C6B;
  --green-dim:  #17714D;
  --red:        #C23B32;
  --line:       #D9D0BC;

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 18px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font-family: inherit; }

.hidden { display: none !important; }

/* ── Lock screen ─────────────────────────────────────────── */

.lock {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink);
  padding: 24px;
  z-index: 50;
}
.lock-card {
  width: 100%; max-width: 360px;
  background: var(--paper);
  color: var(--ink-text);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
}
.lock-stamp {
  width: 56px; height: 56px; margin: 0 auto 16px;
  border: 3px solid var(--green);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 600; color: var(--green-dim);
  transform: rotate(-8deg);
}
.lock-card h1 { font-size: 1.25rem; margin: 0 0 8px; }
.lock-card .muted { font-size: 0.85rem; color: var(--muted); margin: 0 0 20px; }
.lock-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-text);
  font-size: 1rem; margin-bottom: 12px;
}
.lock-card input:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.lock-card button {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--ink); color: var(--paper); font-weight: 500; font-size: 1rem;
  cursor: pointer;
}
.lock-card button:active { transform: scale(0.98); }
.error { color: var(--red); font-size: 0.85rem; margin-top: 10px; }

/* ── App shell ───────────────────────────────────────────── */

.app {
  display: flex; flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: env(safe-area-inset-top, 14px) 18px 14px;
  background: var(--ink);
  border-bottom: 1px solid #232B36;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--green);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600; color: var(--green);
}
.brand-name { font-weight: 500; letter-spacing: 0.01em; }

.status-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--ink-2); border: 1px solid #262E39;
  color: var(--muted-2); font-size: 0.75rem;
  padding: 6px 10px; border-radius: 999px;
  cursor: pointer;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); }
.dot.ok { background: var(--green); }
.dot.bad { background: var(--red); }

.view {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px calc(90px + env(safe-area-inset-bottom));
  background: var(--ink);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--ink-2);
  border-top: 1px solid #232B36;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: none; color: var(--muted-2);
  padding: 6px 0; border-radius: 12px; cursor: pointer; font-size: 0.72rem;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.tab.active { color: var(--paper); background: #1E2733; }
.tab.active svg { stroke: var(--green); }

/* ── Secciones genéricas ─────────────────────────────────── */

.section-title {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted-2); margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ── Tarjeta "recibo" ────────────────────────────────────── */

.receipt {
  position: relative;
  background: var(--paper);
  color: var(--ink-text);
  border-radius: 14px;
  padding: 18px 18px 16px;
  margin-bottom: var(--gap);
}
.receipt::before, .receipt::after {
  content: "";
  position: absolute; left: 0; right: 0; height: 10px;
  background:
    radial-gradient(circle 6px at 12px 0, transparent 6px, var(--ink) 6.5px) top left / 24px 10px repeat-x;
}
.receipt::before { top: -1px; transform: rotate(180deg); }
.receipt::after { bottom: -1px; }

.receipt-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
}
.receipt-row + .receipt-row { margin-top: 6px; }
.receipt-label { color: var(--muted); font-size: 0.8rem; }
.receipt-value { font-family: var(--font-mono); font-size: 0.9rem; text-align: right; }
.receipt-total { font-size: 1.15rem; font-weight: 600; }

.receipt-dash {
  border: none; border-top: 1.5px dashed var(--line);
  margin: 12px 0;
}

.receipt-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}
.receipt-name { font-weight: 600; font-size: 1rem; }
.receipt-meta { color: var(--muted); font-size: 0.75rem; }

/* ── Sello de validación ─────────────────────────────────── */

.stamp {
  position: absolute; top: 14px; right: 14px;
  width: 68px; height: 68px; border-radius: 50%;
  border: 2.5px solid var(--green);
  color: var(--green-dim);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 0.62rem;
  text-align: center; line-height: 1.05; letter-spacing: 0.03em;
  transform: rotate(-11deg) scale(0);
  animation: stampDown 420ms cubic-bezier(.2,1.4,.4,1) 120ms forwards;
}
.stamp.pending { border-color: var(--muted-2); color: var(--muted); }
.stamp.error { border-color: var(--red); color: var(--red); }

@keyframes stampDown {
  0%   { transform: rotate(-11deg) scale(2.2); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: rotate(-11deg) scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .stamp { animation: none; transform: rotate(-11deg) scale(1); }
}

/* ── Formularios ─────────────────────────────────────────── */

.card {
  background: var(--ink-2);
  border: 1px solid #232B36;
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--gap);
}

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 0.78rem; color: var(--muted-2); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1.5px solid #2A3341; background: #0E1319; color: var(--paper);
  font-size: 0.95rem;
}
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: 2px solid var(--green); outline-offset: 1px;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.item-row {
  display: grid; grid-template-columns: 1fr 56px 84px 64px 28px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.item-row input { padding: 9px 8px; font-size: 0.85rem; }
.item-remove {
  background: none; border: none; color: var(--muted-2); font-size: 1.2rem;
  cursor: pointer; line-height: 1;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; padding: 13px 18px;
  font-size: 0.95rem; font-weight: 500; cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--green); color: #0B1712; }
.btn-primary:active { background: var(--green-dim); }
.btn-ghost { background: #1E2733; color: var(--paper); }
.btn-add {
  background: none; border: 1.5px dashed #333E4C; color: var(--muted-2);
  padding: 10px; border-radius: 10px; width: 100%; cursor: pointer; font-size: 0.85rem;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.customer-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.customer-toggle button {
  flex: 1; padding: 9px; border-radius: 10px; border: 1.5px solid #2A3341;
  background: none; color: var(--muted-2); font-size: 0.85rem; cursor: pointer;
}
.customer-toggle button.active { background: #1E2733; color: var(--paper); border-color: var(--green); }

.pick-list { max-height: 220px; overflow-y: auto; border-radius: 10px; }
.pick-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 0.9rem;
  display: flex; justify-content: space-between;
}
.pick-item:hover, .pick-item:focus-visible { background: #1E2733; }
.pick-item .muted { color: var(--muted-2); font-size: 0.78rem; }

/* ── Estados vacíos ──────────────────────────────────────── */

.empty {
  text-align: center; padding: 48px 20px; color: var(--muted-2);
}
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: 0.6; }

/* ── Badges de estado ────────────────────────────────────── */

.badge {
  display: inline-block; font-size: 0.7rem; padding: 3px 9px; border-radius: 999px;
  font-family: var(--font-mono);
}
.badge-issued { background: rgba(31,156,107,0.15); color: var(--green); }
.badge-error { background: rgba(194,59,50,0.15); color: var(--red); }
.badge-pending { background: rgba(154,147,132,0.15); color: var(--muted-2); }

/* ── Toast ───────────────────────────────────────────────── */

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--paper); color: var(--ink-text);
  padding: 13px 16px; border-radius: 12px; font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  z-index: 60;
  animation: toastIn 200ms ease-out;
}
.toast.error { background: var(--red); color: #fff; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Detalle expandible ──────────────────────────────────── */

.details-panel {
  margin-top: 10px; padding-top: 12px; border-top: 1.5px dashed var(--line);
  font-size: 0.85rem;
}
.details-panel a { color: var(--green-dim); font-weight: 600; }

@media (min-width: 640px) {
  .app { max-width: 480px; margin: 0 auto; box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  .tabbar, .topbar { max-width: 480px; margin: 0 auto; }
}
