*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #1d4ed8;   --blue-light: #dbeafe;
  --green: #15803d;  --green-light: #dcfce7;
  --amber: #92400e;  --amber-light: #fef3c7;
  --red: #991b1b;    --red-light: #fee2e2;
  --border: #e2e8f0; --bg: #f1f5f9; --muted: #64748b;
  --text: #0f172a;   --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}

/* ── Header ── */
.app-header {
  background: var(--blue); color: white; padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.app-header h1 { font-size: 17px; font-weight: 600; flex: 1; }
.header-action { background: none; border: none; color: white; cursor: pointer;
  font-size: 22px; padding: 4px; text-decoration: none; }
.back-btn { background: none; border: none; color: white; cursor: pointer;
  font-size: 22px; padding: 4px; line-height: 1; }

/* ── Cert alert banner ── */
.cert-alert {
  margin: 12px 16px 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}
.cert-alert--warning {
  background: var(--amber-light);
  color: var(--amber);
  border: 1px solid #f59e0b;
}
.cert-alert--expired {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #ef4444;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; background: white;
  border-top: 1px solid var(--border); display: flex; z-index: 20;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px;
  padding: 6px 0; border: none; background: none; cursor: pointer;
}
.nav-btn.active { color: var(--blue); }
.nav-icon { font-size: 22px; line-height: 1; }

/* ── Stats ── */
.stats { display: flex; gap: 8px; padding: 14px 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stat { background: white; border-radius: 10px; padding: 12px 14px; text-align: center;
  min-width: 80px; box-shadow: var(--shadow); flex-shrink: 0; }
.stat-n { font-size: 26px; font-weight: 700; line-height: 1; }
.stat-l { font-size: 11px; color: var(--muted); margin-top: 3px; }
.c-blue { color: var(--blue); } .c-amber { color: #b45309; }
.c-red  { color: var(--red); } .c-green { color: var(--green); }

/* ── Section title ── */
.section-title { padding: 6px 16px 5px; font-size: 12px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── Item card ── */
.item-link { display: block; text-decoration: none; color: inherit; margin: 0 16px 10px; }
.item-card { background: white; border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); border-left: 4px solid var(--border); }
.item-card.pending  { border-left-color: #f59e0b; }
.item-card.sold     { border-left-color: var(--blue); }
.item-card.expired  { border-left-color: var(--red); }
.item-name  { font-size: 15px; font-weight: 600; }
.item-serie { font-size: 12px; font-family: 'SF Mono', 'Courier New', monospace;
  color: var(--muted); margin-top: 2px; }
.item-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; flex-wrap: wrap; gap: 4px; }
.item-vendor { font-size: 12px; color: var(--muted); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; padding: 3px 8px;
  border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-sold     { background: var(--blue-light); color: var(--blue); }
.badge-ok       { background: var(--green-light); color: var(--green); }
.badge-expiring { background: #fef3c7; color: #92400e; }
.badge-expired  { background: var(--red-light); color: var(--red); }

/* ── Generic card ── */
.card { background: white; border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin: 0 16px 12px; }
.card-title { font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }

/* ── Info table ── */
.info-table { font-size: 14px; }
.info-row { display: flex; justify-content: space-between; align-items: flex-start;
  padding: 9px 0; border-bottom: 1px solid var(--border); gap: 12px; }
.info-row:last-child { border-bottom: none; }
.info-key { color: var(--muted); flex-shrink: 0; }
.info-val { font-weight: 500; text-align: right; word-break: break-word; max-width: 65%; }

/* ── Forms ── */
.form-section { padding: 0 16px 16px; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 5px; }
.form-label .req { color: var(--red); }
.form-input, .form-select {
  width: 100%; padding: 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 16px; background: white; -webkit-appearance: none; color: var(--text);
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-light);
}
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Upload ── */
.upload-area { border: 2px dashed var(--border); border-radius: 8px; padding: 22px 16px;
  text-align: center; cursor: pointer; background: #f8fafc; transition: all .2s; }
.upload-area:active { background: var(--blue-light); }
.upload-area.has-file { border-color: var(--green); background: var(--green-light); border-style: solid; }
.upload-icon { font-size: 34px; }
.upload-text { font-size: 14px; color: var(--muted); margin-top: 6px; }
.upload-name { font-size: 13px; font-weight: 600; color: var(--green); margin-top: 4px; }
.upload-area input[type=file] { display: none; }

/* ── Buttons ── */
.btn { display: block; width: 100%; padding: 14px; border: none; border-radius: 8px;
  font-size: 16px; font-weight: 600; cursor: pointer; text-align: center;
  text-decoration: none; transition: opacity .15s; -webkit-tap-highlight-color: transparent; }
.btn:active { opacity: .82; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary   { background: var(--blue); color: white; }
.btn-success   { background: var(--green); color: white; }
.btn-secondary { background: white; color: #334155; border: 1.5px solid var(--border); }
.btn-sm { padding: 9px 16px; font-size: 14px; width: auto; display: inline-block; }
.btn-group { display: flex; gap: 8px; }
.btn-group .btn { flex: 1; }

/* ── Items agregados (nueva compra) ── */
.added-list { }
.added-item { display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.added-item:last-child { border-bottom: none; }
.added-num { width: 22px; height: 22px; background: var(--blue); color: white;
  border-radius: 50%; font-size: 12px; font-weight: 700; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px; }
.added-info { flex: 1; }
.added-name { font-weight: 600; }
.added-serie { font-family: monospace; color: var(--muted); font-size: 12px; margin-top: 1px; }
.added-garantia { font-size: 12px; color: var(--green); margin-top: 2px; }

/* ── Step indicator ── */
.steps { display: flex; padding: 12px 16px; gap: 0; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; position: relative; }
.step:not(:last-child)::after { content: ''; position: absolute; top: 14px; left: 50%;
  width: 100%; height: 2px; background: var(--border); z-index: 0; }
.step.done::after { background: var(--blue); }
.step-circle { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
  background: white; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; position: relative; z-index: 1; color: var(--muted); }
.step.active .step-circle { border-color: var(--blue); background: var(--blue); color: white; }
.step.done .step-circle { border-color: var(--blue); background: var(--blue); color: white; }
.step-label { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: center; }
.step.active .step-label { color: var(--blue); font-weight: 600; }

/* ── Search ── */
.search-bar { padding: 10px 16px; background: white; border-bottom: 1px solid var(--border);
  position: sticky; top: 52px; z-index: 10; }
.search-input { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 16px; background: #f8fafc; -webkit-appearance: none; }
.search-input:focus { outline: none; border-color: var(--blue); background: white; }

/* ── File view link ── */
.file-link { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: var(--blue-light); color: var(--blue); border-radius: 8px;
  text-decoration: none; font-size: 13px; font-weight: 500; margin-top: 8px; }

/* ── Toast ── */
.toast { position: fixed; bottom: calc(78px + env(safe-area-inset-bottom)); left: 16px; right: 16px;
  padding: 13px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  z-index: 100; transform: translateY(16px); opacity: 0; transition: all .25s; pointer-events: none; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: #14532d; color: white; }
.toast-error   { background: #450a0a; color: white; }

/* ── Empty / loading ── */
.empty { text-align: center; padding: 52px 24px; color: var(--muted); }
.empty-icon { font-size: 52px; margin-bottom: 10px; }
.empty-msg  { font-size: 15px; }
.loading { text-align: center; padding: 32px; color: var(--muted); font-size: 14px; }

/* ── Divider ── */
.divider { height: 1px; background: var(--border); margin: 4px 0 12px; }

/* ── Botón escanear S/N ── */
.btn-scan {
  padding: 0 14px; border: 1.5px solid var(--blue); border-radius: 8px;
  background: var(--blue-light); color: var(--blue); font-size: 20px;
  cursor: pointer; flex-shrink: 0; line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.btn-scan:active { opacity: .75; }

/* ── Overlay de escaneo ── */
#scan-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.scan-header {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(16px + env(safe-area-inset-top)) 16px 16px;
  display: flex; justify-content: flex-end;
}
.scan-close {
  background: rgba(255,255,255,.15); border: none; color: white;
  padding: 8px 16px; border-radius: 20px; font-size: 15px; font-weight: 600;
  cursor: pointer;
}
#scan-video {
  width: 100%; max-width: 480px; height: auto; display: block;
}
.scan-frame {
  position: absolute; width: 240px; height: 160px;
  pointer-events: none;
}
.scan-corner {
  position: absolute; width: 24px; height: 24px; border-color: #fff; border-style: solid;
}
.scan-corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; }
.scan-corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; }
.scan-corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
.scan-corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; }
.scan-hint {
  position: absolute; bottom: calc(72px + env(safe-area-inset-bottom));
  color: rgba(255,255,255,.8); font-size: 14px; text-align: center; padding: 0 24px;
}

/* ── Resultados OCR ── */
.ocr-serial-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--border); gap: 10px;
}
.ocr-serial-row:last-child { border-bottom: none; }
.ocr-serial-val {
  font-family: 'SF Mono', 'Courier New', monospace; font-size: 13px;
  word-break: break-all; flex: 1;
}
.btn-use-serial {
  padding: 6px 14px; background: var(--blue); color: white; border: none;
  border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;
  flex-shrink: 0; white-space: nowrap;
}
.btn-use-serial:active { opacity: .8; }

/* ── Spinner ── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: white;
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Guarantee banner ── */
.guarantee-banner { margin: 0 16px 12px; border-radius: var(--radius); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; }
.guarantee-banner.ok       { background: var(--green-light); color: var(--green); }
.guarantee-banner.expiring { background: #fef3c7; color: #92400e; }
.guarantee-banner.expired  { background: var(--red-light); color: var(--red); }
.guarantee-icon { font-size: 24px; flex-shrink: 0; }
