:root {
  --bg: #fdf2f2;
  --surface: #ffffff;
  --surface2: #C8102E;
  --surface2-dark: #a00d25;
  --border: #f0c3c8;
  --border-focus: #C8102E;
  --strong-text: #1a0808;
  --text: #4a2020;
  --text-muted: #8b5b5b;
  --red-dark: #8a0c20;
  --red-darkest: #4a040e;
  --accent: #C8102E;
  --user-bubble: linear-gradient(135deg, #C8102E 0%, #9e0c24 100%);
  --user-text: #ffffff;
  --btn-bg: #ffffff;
  --btn-border: #C8102E;
  --btn-text: #C8102E;
  
  --warn-bg: #fffbeb;
  --warn-border: #f59e0b;
  --warn-text: #92400e;
  --warn-btn: #d97706;

  --success-bg: #ecfdf5;
  --success-border: #10b981;
  --success-text: #065f46;
  --success-btn: #059669;

  --radius-sm: 8px;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 4px rgba(200, 16, 46, 0.05);
  --shadow-md: 0 6px 16px rgba(200, 16, 46, 0.10);
  --shadow-lg: 0 12px 32px rgba(200, 16, 46, 0.16);
  --shadow-alarm: 0 0 50px rgba(200, 16, 46, 0.6);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  padding-bottom: 80px;
  user-select: none;
}

/* APP SHELL & TOP BAR */
.top-bar {
  background: var(--surface2);
  color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.user-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.active-role-btn {
  background: #ffffff;
  color: var(--surface2);
  border: none;
  font-weight: 800;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.active-role-btn:active {
  transform: scale(0.96);
}

/* MAIN CONTAINER */
.app-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
}

/* BOTTOM NAVIGATION TABS */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 68px;
  background: var(--surface);
  border-top: 2px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

.nav-tab.active {
  color: var(--surface2);
}

.nav-tab.active::after {
  content: "";
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 4px;
  background: var(--surface2);
  border-radius: 0 0 4px 4px;
}

.nav-tab svg {
  width: 22px;
  height: 22px;
  margin-bottom: 2px;
}

/* VIEW SCREENS */
.screen-view {
  display: none;
  animation: fadeIn 0.15s ease;
}

.screen-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* COMMON UTILITIES */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--strong-text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ==========================================================================
   PANTALLA 1: DESPACHO (MOBILE FIRST ULTRA RÁPIDO)
   ========================================================================== */
.dispatch-screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.quick-stats-bar {
  display: flex;
  gap: 8px;
}

.mini-stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}

.mini-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
}

.mini-stat-val {
  font-size: 16px;
  font-weight: 800;
  color: var(--strong-text);
}

.folio-input-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.folio-input-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.folio-input-wrapper {
  position: relative;
  margin-bottom: 12px;
}

.input-huge {
  width: 100%;
  font-size: 38px;
  font-weight: 900;
  text-align: center;
  color: var(--strong-text);
  background: #fffafa;
  border: 2.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  letter-spacing: 2px;
  outline: none;
  transition: border-color 0.15s ease;
}

.input-huge:focus {
  border-color: var(--surface2);
  background: #ffffff;
}

.input-clear-btn {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: #f0f0f0;
  color: #666;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}

/* BOTÓN DE ACCIÓN GIGANTE */
.btn-massive-primary {
  width: 90%;
  margin: 0 auto;
  display: block;
  background: var(--user-bubble);
  color: var(--user-text);
  font-size: 20px;
  font-weight: 800;
  padding: 18px 24px;
  border-radius: var(--radius-lg);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  letter-spacing: 0.5px;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.btn-massive-primary:active {
  transform: scale(0.97);
  filter: brightness(0.95);
}

.btn-massive-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* VIRTUAL NUMERIC KEYPAD PARA DEDOS CON GRASA */
.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.numpad-btn {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 24px;
  font-weight: 700;
  color: var(--strong-text);
  padding: 14px 0;
  cursor: pointer;
  transition: background 0.1s ease;
}

.numpad-btn:active {
  background: #fce8e8;
  border-color: var(--surface2);
}

.numpad-btn.btn-backspace {
  font-size: 18px;
  color: var(--surface2);
}

/* FEEDBACK OVERLAYS Y MODALES INMEDIATOS */
.feedback-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  padding: 20px;
  justify-content: center;
  align-items: center;
}

.feedback-overlay.active {
  display: flex;
}

/* ESCENARIO A: TICKET VÁLIDO PENDIENTE */
.modal-valid {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 3px solid var(--success-border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  text-align: center;
}

.badge-tag {
  display: inline-block;
  padding: 6px 16px;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.badge-tag.paid {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.badge-tag.unpaid {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

.valid-folio-title {
  font-size: 32px;
  font-weight: 900;
  color: var(--strong-text);
  margin-bottom: 4px;
}

.valid-seller-info {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.pedido-type-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.type-option-btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.type-option-btn.selected {
  border-color: var(--surface2);
  background: #fdf2f2;
  color: var(--surface2);
}

.btn-confirm-delivery {
  width: 100%;
  background: var(--success-btn);
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  padding: 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
  margin-bottom: 12px;
}

.btn-confirm-delivery:active {
  transform: scale(0.98);
}

.btn-cancel-modal {
  width: 100%;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
}

/* ESCENARIO B: ALERTA FRAUDE (PANTALLA ENTERA CARMESÍ) */
.overlay-fraud {
  background: var(--red-dark);
  animation: pulseAlarm 0.4s infinite alternate;
}

@keyframes pulseAlarm {
  from { background-color: #8a0c20; }
  to { background-color: #5a0412; }
}

.fraud-card {
  color: #ffffff;
  text-align: center;
  max-width: 440px;
  width: 100%;
}

.fraud-icon-siren {
  font-size: 64px;
  margin-bottom: 10px;
  animation: shake 0.3s infinite;
}

@keyframes shake {
  0% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
  100% { transform: rotate(-5deg); }
}

.fraud-title {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -1px;
  text-transform: uppercase;
  line-height: 1.1;
  margin-bottom: 14px;
  color: #ffffff;
  text-shadow: 0 3px 10px rgba(0,0,0,0.5);
}

.fraud-details {
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 24px;
  font-size: 17px;
  line-height: 1.5;
}

.fraud-details strong {
  color: #ffd2d6;
  font-size: 19px;
  display: block;
}

.btn-fraud-dismiss {
  width: 100%;
  background: #ffffff;
  color: var(--red-dark);
  font-size: 20px;
  font-weight: 900;
  padding: 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

/* ESCENARIO C: ALERTA DEUDA / NO PAGADO */
.overlay-debt {
  background: rgba(40, 20, 0, 0.85);
}

.debt-card {
  background: var(--warn-bg);
  border: 3px solid var(--warn-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.debt-title {
  font-size: 28px;
  font-weight: 900;
  color: var(--warn-text);
  margin-bottom: 10px;
}

.debt-message {
  font-size: 16px;
  color: #78350f;
  margin-bottom: 20px;
  font-weight: 600;
}

.btn-debt-caja {
  width: 100%;
  background: var(--warn-btn);
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  margin-bottom: 10px;
}

/* ==========================================================================
   PANTALLA 2: CAJA / COBRANZA RÁPIDA
   ========================================================================== */
.cashier-search-bar {
  margin-bottom: 14px;
}

.search-input {
  width: 100%;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: #ffffff;
  outline: none;
}

.search-input:focus {
  border-color: var(--surface2);
}

.cashier-filter-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.filter-pill {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--surface2);
  color: #ffffff;
  border-color: var(--surface2);
}

.tickets-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ticket-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ticket-card.is-paid {
  border-color: #a7f3d0;
  background: #fafffc;
}

.ticket-card.is-debt {
  border-color: #fed7aa;
  background: #fffdf9;
}

.ticket-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ticket-folio {
  font-size: 20px;
  font-weight: 900;
  color: var(--strong-text);
}

.ticket-seller {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.ticket-price {
  font-size: 17px;
  font-weight: 800;
  color: var(--surface2);
}

.payment-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn-pay-cash {
  background: var(--btn-bg);
  border: 2px solid var(--btn-border);
  color: var(--btn-text);
  font-size: 15px;
  font-weight: 800;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.1s ease;
}

.btn-pay-cash:active {
  background: #fee2e2;
}

.btn-pay-yape {
  background: #73138b;
  border: 2px solid #73138b;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.1s ease;
}

.btn-pay-yape:active {
  background: #560a6a;
}

.btn-revert-pay {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  color: #4b5563;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  align-self: flex-start;
}

/* ==========================================================================
   PANTALLA 3: DASHBOARD DE ARQUEO (ADMIN)
   ========================================================================== */
.admin-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.kpi-card.full-width {
  grid-column: span 2;
}

.kpi-title {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-number {
  font-size: 24px;
  font-weight: 900;
  color: var(--strong-text);
}

.kpi-number.alert {
  color: var(--red-dark);
}

.kpi-number.success {
  color: #047857;
}

/* PROGRESS BAR DE POLLOS */
.progress-container {
  width: 100%;
  height: 16px;
  background: #f0e0e2;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 8px;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
  border-radius: var(--radius-full);
}

/* TABLA DE MOROSOS */
.debtors-table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.debtors-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.debtors-table th {
  background: #f8e8ea;
  padding: 10px 12px;
  font-weight: 800;
  color: var(--strong-text);
  border-bottom: 1px solid var(--border);
}

.debtors-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.debtors-table tr:last-child td {
  border-bottom: none;
}

.debtors-table .debt-amount {
  font-weight: 900;
  color: var(--red-dark);
  font-size: 14px;
}

.phone-link {
  color: var(--surface2);
  text-decoration: none;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* FORMULARIO DE CARGA MASIVA DE TALONARIOS */
.bulk-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--strong-text);
}

.form-input, .form-select {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 14px;
  outline: none;
  background: #ffffff;
}

.form-input:focus, .form-select:focus {
  border-color: var(--surface2);
}

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

.btn-admin-action {
  background: var(--surface2);
  color: #ffffff;
  border: none;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}

.btn-admin-action:active {
  background: var(--surface2-dark);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
}

/* DIALOGO DE PIN DE SEGURIDAD */
.pin-dialog {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
  padding: 20px;
  align-items: center;
  justify-content: center;
}

.pin-dialog.active {
  display: flex;
}

.pin-modal {
  background: #ffffff;
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 16px 0;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--surface2);
  background: transparent;
}

.pin-dot.filled {
  background: var(--surface2);
}

.pin-numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.pin-key {
  padding: 14px 0;
  font-size: 20px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: 10px;
  cursor: pointer;
}

.pin-key:active {
  background: #fce8e8;
}

/* TOAST NOTIFICACIONES */
.toast-msg {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 8, 8, 0.95);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 700;
  z-index: 400;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.toast-msg.show {
  opacity: 1;
}
