/* ==========================================================================
   FID - FIDELIZACIÓN COMERCIO LOCAL
   Estilos CSS Móvil-First, Responsivos y PWA de Alto Rendimiento
   ========================================================================== */

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary: #0f172a;
  --accent: #10b981;
  --accent-hover: #059669;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-elevated: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  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-app);
  color: var(--text-main);
  line-height: 1.5;
  user-select: none;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Contenedor Principal de la App */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  background-color: var(--bg-card);
  position: relative;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.08);
}

/* ================= HEADER Y PESTAÑAS ================= */
.app-header {
  padding-top: calc(var(--safe-top) + 8px);
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: 8px;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
}

/* Pestañas Superiores de Navegación */
.top-tabs {
  display: flex;
  background-color: var(--bg-elevated);
  border-radius: var(--radius-full);
  padding: 4px;
  flex: 1;
}

.top-tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.top-tab-btn.active {
  background-color: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Avatar / Botón de Perfil en Header */
.header-avatar-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-img {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 2px solid var(--primary-light);
}

/* ================= ÁREA DE CONTENIDO ================= */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.view-section {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 16px;
}

.view-section.active {
  display: flex;
}

/* ================= PESTAÑA SELLER: QR ================= */
.qr-display-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.qr-box {
  background: #ffffff;
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: inline-block;
  min-width: 200px;
  min-height: 200px;
}

.commerce-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
}

/* ================= PESTAÑA SELLER: CLIENTES EN TIENDA ================= */
.shop-clients-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.filter-toggle-btn {
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-toggle-btn.active {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.client-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.client-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.client-card:active {
  transform: scale(0.98);
  background-color: var(--bg-elevated);
}

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

.client-avatar {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 2px solid var(--border);
}

.client-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-main);
}

.client-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.client-balance-tag {
  text-align: right;
}

.client-balance-tag .amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

.client-balance-tag .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ================= PANTALLA DE COBRO / CALCULADORA SELLER ================= */
.checkout-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 12px;
  gap: 10px;
}

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

.btn-back {
  border: none;
  background: var(--bg-elevated);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Cuadrícula 5x2 de Categorías (hasta 9 + 10ª porcentaje libre) */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
}

.category-chip {
  background: var(--bg-elevated);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 2px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  transition: all 0.15s ease;
}

.category-chip.active {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.category-chip .icon {
  font-size: 16px;
}

.category-chip .pct {
  font-size: 12px;
  font-weight: 700;
}

.category-chip .name {
  font-size: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90%;
  color: var(--text-muted);
}

/* 10ª casilla: porcentaje libre */
.free-pct-chip {
  background: #ffffff;
  border: 2px dashed var(--border);
}

.free-pct-chip.active {
  border-style: solid;
  border-color: var(--warning);
  background-color: #fef3c7;
}

.free-pct-chip input {
  width: 80%;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  outline: none;
  color: inherit;
}

/* Caja de Texto del Importe con Foco Permanente */
.amount-input-box {
  background: #ffffff;
  border: 2px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.amount-input-box label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.amount-display-input {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-main);
  text-align: right;
  border: none;
  outline: none;
  width: 60%;
  background: transparent;
  letter-spacing: -0.5px;
}

/* Calculadora Táctil Pantalla Completa */
.calculator-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
}

.calc-btn {
  border: 1px solid var(--border);
  background-color: #ffffff;
  border-radius: var(--radius-md);
  font-size: 24px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.1s ease, transform 0.1s ease;
}

.calc-btn:active {
  background-color: var(--bg-elevated);
  transform: scale(0.96);
}

.calc-btn.operator {
  background-color: var(--bg-elevated);
  color: var(--primary);
}

.calc-btn.clear {
  color: var(--danger);
  font-size: 20px;
}

.calc-btn.action-confirm {
  background-color: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  grid-column: span 2;
  font-size: 20px;
  font-weight: 700;
}

.calc-btn.action-confirm:active {
  background-color: var(--accent-hover);
}

/* Barra Inferior del Cliente en Cobro */
.checkout-client-footer {
  background-color: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ================= BUYER: COMERCIOS CERCANOS ================= */
.commerce-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}

.commerce-card:active {
  transform: scale(0.98);
}

.commerce-avatar {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.commerce-details {
  flex: 1;
  margin-left: 14px;
}

.commerce-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

.commerce-dist {
  font-size: 13px;
  color: var(--text-muted);
}

/* ================= BARRA INFERIOR BUYER ================= */
.buyer-footer-bar {
  background-color: #ffffff;
  border-top: 1px solid var(--border);
  padding: calc(var(--safe-bottom) + 10px) 16px 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  bottom: 0;
  z-index: 40;
}

.btn-scan-qr {
  flex: 1;
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  padding: 14px;
  border-radius: var(--radius-full);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

.global-wallet-pill {
  background-color: var(--bg-elevated);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  text-align: right;
  cursor: pointer;
}

.global-wallet-pill .label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.global-wallet-pill .amount {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
}

/* ================= MODALES Y TOASTS ================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

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

.modal-box {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.btn-close-modal {
  border: none;
  background: transparent;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

/* Formularios */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text-main);
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background-color: var(--secondary);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.25s ease;
  pointer-events: auto;
}

.toast.success {
  background-color: #065f46;
  border-left: 4px solid var(--accent);
}

.toast.error {
  background-color: #991b1b;
  border-left: 4px solid var(--danger);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Banner de Actualización PWA */
.update-banner {
  background: #1e3a8a;
  color: #ffffff;
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  display: none;
}

.update-banner.active {
  display: flex;
}
