:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --success: #059669;
  --danger: #e11d48;
  --danger-soft: #fff1f2;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Cabecera */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo svg {
  width: 42px;
  height: 42px;
  display: block;
}

.app-title {
  margin: 0 0 3px;
  font-size: 1.06rem;
  font-weight: 700;
}

.center-selector {
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #475569;
  border-radius: 999px;
  padding: 4px 10px 4px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.center-pin,
.center-chevron {
  width: 13px;
  height: 13px;
}

.center-pin {
  color: var(--primary);
}

.app-main {
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Escáner */
.scanner-viewport {
  position: relative;
  height: 224px;
  border-radius: 18px;
  overflow: hidden;
  background: #0b1120;
  border: 1px solid #1e293b;
}

.scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scan-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 78%;
  height: 54%;
  transform: translate(-50%, -56%);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(9, 14, 26, 0.56);
  pointer-events: none;
  overflow: hidden;
}

.corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 0 solid #ffffff;
}

.corner-tl {
  top: 0;
  left: 0;
  border-top-width: 3.5px;
  border-left-width: 3.5px;
  border-top-left-radius: 10px;
}

.corner-tr {
  top: 0;
  right: 0;
  border-top-width: 3.5px;
  border-right-width: 3.5px;
  border-top-right-radius: 10px;
}

.corner-bl {
  bottom: 0;
  left: 0;
  border-bottom-width: 3.5px;
  border-left-width: 3.5px;
  border-bottom-left-radius: 10px;
}

.corner-br {
  bottom: 0;
  right: 0;
  border-bottom-width: 3.5px;
  border-right-width: 3.5px;
  border-bottom-right-radius: 10px;
}

.scan-laser {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2.5px;
  border-radius: 999px;
  background: #ef4444;
  box-shadow: 0 0 10px 2px rgba(239, 68, 68, 0.72);
  animation: laserSweep 2s ease-in-out infinite;
}

@keyframes laserSweep {
  0%, 100% {
    top: 10%;
  }
  50% {
    top: 86%;
  }
}

.scanner-hint {
  position: absolute;
  inset: auto 12px 10px;
  text-align: center;
  font-size: 0.76rem;
  color: rgba(248, 250, 252, 0.92);
  pointer-events: none;
}

.scanner-fallback {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #000000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  gap: 12px;
}

.fallback-msg {
  margin: 0;
  color: #e2e8f0;
  font-size: 0.85rem;
}

.fallback-actions {
  display: flex;
  gap: 8px;
}

.btn-chip {
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-chip-primary {
  background: var(--primary);
  border-color: var(--primary);
}

/* Botones principales */
.rescan-btn,
.add-batch-btn,
.save-all-btn {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.rescan-btn {
  border: 1.5px solid #bfdbfe;
  background: var(--surface);
  color: var(--primary);
}

.rescan-icon,
.add-batch-btn svg,
.save-all-btn svg {
  width: 20px;
  height: 20px;
}

.add-batch-btn {
  border: 1.5px dashed #93c5fd;
  background: var(--primary-soft);
  color: var(--primary);
}

.save-all-btn {
  border: 0;
  background: var(--success);
  color: #ffffff;
  font-size: 1rem;
  box-shadow: 0 8px 18px -6px rgba(5, 150, 105, 0.5);
}

/* Entrada manual */
.manual-section,
.product-section,
.batches-list,
.location-units-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manual-form {
  display: flex;
  gap: 8px;
}

.manual-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
}

.manual-input-wrap:focus-within,
.batch-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.manual-icon {
  width: 19px;
  height: 19px;
  margin-left: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.manual-input-wrap input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  padding: 13px 10px;
  font-size: 0.95rem;
  color: var(--ink);
}

.clear-input-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.clear-input-btn svg {
  width: 15px;
  height: 15px;
}

.manual-submit-btn {
  border: 0;
  background: var(--ink);
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0 18px;
  border-radius: 14px;
  cursor: pointer;
}

/* Producto y tarjetas */
.product-summary-card,
.batch-card,
.location-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.product-summary-card,
.batch-line-top,
.batch-line-bottom,
.location-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.product-identity {
  min-width: 0;
  flex: 1;
}

.product-name {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 700;
}

.product-code {
  margin: 4px 0 0;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  color: var(--muted);
}

.product-total-box {
  background: var(--primary-soft);
  border: 1px solid #dbeafe;
  border-radius: 12px;
  min-width: 76px;
  padding: 8px 12px;
  text-align: center;
}

.product-total-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary);
}

.product-total-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #3b82f6;
}

.batches-empty {
  background: var(--surface);
  border: 1.5px dashed #cbd5e1;
  border-radius: 14px;
  padding: 18px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.batch-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.batch-card.is-new {
  border-color: #93c5fd;
  background: #f8fbff;
}

.batch-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.batch-meta-right {
  text-align: right;
}

.meta-label,
.batch-field label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
}

.meta-value {
  font-size: 0.95rem;
  font-weight: 700;
}

.meta-value.is-expiring {
  color: #b45309;
}

.meta-value.is-expired {
  color: #be123c;
}

.batch-inputs-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.batch-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.batch-field input {
  width: 100%;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  outline: none;
}

.batch-field input.is-invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.field-error {
  font-size: 0.72rem;
  font-weight: 600;
  color: #be123c;
}

/* Cubo de basura y unidades */
.trash-btn {
  width: 44px;
  height: 44px;
  border: 1px solid #fecdd3;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.trash-btn:active {
  background: #ffe4e6;
  color: #be123c;
}

.trash-btn svg {
  width: 21px;
  height: 21px;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}

.qty-btn {
  width: 42px;
  height: 40px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  border-radius: 9px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.qty-btn:disabled {
  opacity: 0.4;
}

.qty-value,
.qty-input {
  min-width: 42px;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 800;
}

.qty-input {
  width: 52px;
  border: 0;
  background: transparent;
  outline: none;
  padding: 4px 2px;
  -moz-appearance: textfield;
}

.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/* Tienda y almacén */
.location-info {
  display: flex;
  align-items: center;
  gap: 11px;
}

.location-badge {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
}

.location-badge-warehouse {
  background: var(--bg);
  color: #334155;
}

.location-badge svg {
  width: 20px;
  height: 20px;
}

.location-labels {
  display: flex;
  flex-direction: column;
}

.location-title {
  font-size: 0.96rem;
  font-weight: 700;
}

.location-sub {
  font-size: 0.76rem;
  color: var(--muted);
}

/* Modal centros y toast */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-panel {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 12px 18px max(22px, env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: #cbd5e1;
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-title {
  margin: 0;
  font-size: 1.02rem;
}

.sheet-close {
  width: 36px;
  height: 36px;
  border: 0;
  background: #f8fafc;
  border-radius: 999px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.sheet-close svg,
.center-check {
  width: 18px;
  height: 18px;
}

.center-options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.center-option-btn {
  width: 100%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 13px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.center-option-btn.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  width: calc(100% - 32px);
  max-width: 400px;
  background: var(--ink);
  color: #f8fafc;
  padding: 13px 16px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toast.is-success {
  background: #065f46;
}

.toast.is-error {
  background: #991b1b;
}

.toast-action {
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
