/* ============================================
   FIDELIX - CSS Completo + Responsive
   Mobile / Tablet / Desktop — iOS & Android
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&display=swap');

/* ---- VARIABLES ---- */
:root {
  --gold: #D4AF37;
  --gold-light: #F0D060;
  --gold-dark: #A8861A;
  --gold-muted: rgba(212, 175, 55, 0.15);
  --dark: #0d0d1a;
  --dark-2: #13132a;
  --dark-3: #1a1a35;
  --dark-4: #22223d;
  --sidebar-bg: #0f0f20;
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --text-primary: #f0f0f5;
  --text-secondary: #9090b0;
  --text-muted: #5a5a7a;
  --border: rgba(212, 175, 55, 0.15);
  --card-bg: rgba(26, 26, 53, 0.8);
  --success: #2ecc71;
  --danger: #e74c3c;
  --warning: #f39c12;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-gold: 0 4px 24px rgba(212,175,55,0.15);
  --transition: all 0.2s ease;
  --content-pad: 28px 32px;
  --content-pad-mobile: 16px;
}

/* ---- RESET ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--dark);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  -webkit-overflow-scrolling: touch;
}

.sidebar-logo {
  padding: 24px 20px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1px;
  line-height: 1;
}

.sidebar-logo .logo-sub {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: 3px;
}

.sidebar-nav {
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  position: relative;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.nav-item:hover, .nav-item:active {
  color: var(--text-primary);
  background: rgba(212,175,55,0.06);
}

.nav-item.active {
  color: var(--gold);
  background: var(--gold-muted);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--gold);
  border-radius: 0 3px 3px 0;
}

.nav-item .nav-icon {
  font-size: 15px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item .nav-arrow {
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.nav-item.open .nav-arrow { transform: rotate(90deg); }

.nav-submenu { display: none; background: rgba(0,0,0,0.15); }
.nav-submenu.open { display: block; }

.nav-submenu a {
  display: block;
  padding: 9px 18px 9px 46px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.nav-submenu a:hover, .nav-submenu a.active { color: var(--gold); }

.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.user-avatar {
  width: 34px; height: 34px;
  background: var(--gold);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--dark);
  flex-shrink: 0;
}

.user-info .user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.user-info .user-email {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.user-info a {
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
}

.user-info a:hover { color: var(--gold); }

/* Overlay para móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 199;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.open { display: block; }

/* ============================================
   TOPBAR MÓVIL
   ============================================ */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--dark-2);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.burger-btn {
  width: 40px; height: 40px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.burger-btn:active { background: var(--gold-muted); }

.mobile-logo {
  font-family: 'Playfair Display', serif;
  font-size: 20px;
  color: var(--gold);
  font-weight: 700;
  flex: 1;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  background: var(--dark);
  min-width: 0;
}

.topbar {
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--dark-2);
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.content {
  padding: var(--content-pad);
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(10px);
}

.card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

.metric-value {
  font-size: 40px;
  font-weight: 300;
  color: var(--gold);
  line-height: 1;
  font-family: 'Playfair Display', serif;
}

.metric-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.metric-sub { font-size: 15px; color: var(--text-secondary); margin-top: 8px; }

/* ---- FILTROS TIEMPO ---- */
.time-filters { display: flex; gap: 4px; flex-wrap: wrap; }

.time-btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.time-btn:hover { color: var(--text-primary); border-color: var(--gold); }

.time-btn.active {
  background: var(--gold);
  color: var(--dark);
  border-color: var(--gold);
  font-weight: 600;
}

/* ============================================
   GRIDS
   ============================================ */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ============================================
   GRÁFICA
   ============================================ */
.chart-container { position: relative; height: 160px; }

/* ============================================
   TABLA
   ============================================ */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 500px; }

thead th {
  padding: 12px 14px;
  text-align: left;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid rgba(212,175,55,0.06);
  color: var(--text-primary);
}

tbody tr:hover { background: rgba(212,175,55,0.04); }

.avatar-circle {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--dark);
  flex-shrink: 0;
}

.avatar-name { display: flex; align-items: center; gap: 10px; }

/* ============================================
   BADGES
   ============================================ */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-gold { background: var(--gold-muted); color: var(--gold); border: 1px solid rgba(212,175,55,0.3); }
.badge-green { background: rgba(46,204,113,0.15); color: var(--success); }
.badge-red { background: rgba(231,76,60,0.15); color: var(--danger); }

/* ============================================
   BOTONES
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.btn-primary { background: var(--gold); color: var(--dark); }
.btn-primary:hover, .btn-primary:active { background: var(--gold-light); box-shadow: var(--shadow-gold); }

.btn-outline { background: transparent; color: var(--gold); border: 1px solid var(--gold); }
.btn-outline:hover, .btn-outline:active { background: var(--gold-muted); }

.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-xs { padding: 5px 10px; font-size: 12px; }

/* ============================================
   INPUTS
   ============================================ */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--dark-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px; /* Evita zoom en iOS */
  font-family: inherit;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,175,55,0.1);
}

.form-control::placeholder { color: var(--text-muted); }
.form-control[type="color"] { padding: 6px; height: 44px; cursor: pointer; }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235a5a7a' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ---- SEARCH ---- */
.search-bar { position: relative; flex: 1; min-width: 200px; }

.search-bar input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  background: var(--dark-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  -webkit-appearance: none;
}

.search-bar input:focus { outline: none; border-color: var(--gold); }
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
}

/* ============================================
   TARJETAS DIGITALES (cliente)
   ============================================ */
.loyalty-card {
  border-radius: 18px;
  padding: 22px;
  position: relative;
  overflow: hidden;
  color: white;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  width: 100%;
  max-width: 340px;
}

.loyalty-card::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  pointer-events: none;
}

.loyalty-card .card-logo {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 700;
}

.loyalty-card .card-stats {
  display: flex;
  justify-content: space-between;
  margin: 14px 0;
}

.loyalty-card .stat-label { font-size: 11px; opacity: 0.7; }
.loyalty-card .stat-value { font-size: 22px; font-weight: 700; }

.loyalty-card .card-qr {
  display: flex;
  justify-content: center;
  margin: 14px 0;
}

.loyalty-card .card-qr img {
  width: 100px; height: 100px;
  border-radius: 8px;
  background: white;
  padding: 4px;
}

.loyalty-card .card-sellos {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.sello {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
}

.sello.activo { background: rgba(255,255,255,0.9); }
.sello.inactivo { background: rgba(255,255,255,0.1); }

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  z-index: 1000;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

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

.modal {
  background: var(--dark-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s cubic-bezier(0.4,0,0.2,1);
}

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

.modal-title {
  font-size: 17px;
  font-weight: 600;
  font-family: 'Playfair Display', serif;
  color: var(--gold);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover { color: var(--text-primary); }

/* ============================================
   FLASH
   ============================================ */
.flash {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.flash-success { background: rgba(46,204,113,0.15); border: 1px solid rgba(46,204,113,0.3); color: var(--success); }
.flash-error { background: rgba(231,76,60,0.15); border: 1px solid rgba(231,76,60,0.3); color: var(--danger); }

/* ============================================
   LOGIN
   ============================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dark);
  position: relative;
  overflow: hidden;
  padding: 20px;
}

.login-page::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212,175,55,0.08) 0%, transparent 70%);
  top: -200px; right: -150px;
}

.login-page::after {
  content: '';
  position: absolute;
  width: 350px; height: 350px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212,175,55,0.05) 0%, transparent 70%);
  bottom: -100px; left: -100px;
}

.login-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  backdrop-filter: blur(20px);
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow);
}

.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-mark {
  font-family: 'Playfair Display', serif;
  font-size: 38px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 2px;
}

.login-logo .logo-tagline {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* ============================================
   ACCIONES / ICONOS
   ============================================ */
.action-btns { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.icon-btn:hover, .icon-btn:active { color: var(--gold); border-color: var(--gold); }
.icon-btn.danger:hover, .icon-btn.danger:active { color: var(--danger); border-color: var(--danger); }

/* ============================================
   SEGMENTOS
   ============================================ */
.segment-card {
  background: var(--dark-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.segment-name { font-weight: 600; font-size: 14px; }
.segment-conditions { font-size: 12px; color: var(--text-muted); margin-top: 5px; line-height: 1.6; }

.segment-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--gold-muted);
  color: var(--gold);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 4px;
}

/* ============================================
   UBICACIONES
   ============================================ */
.location-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.location-name { font-weight: 500; font-size: 14px; }
.location-address { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--dark-2); }
::-webkit-scrollbar-thumb { background: var(--dark-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }

/* ============================================
   ANIMACIONES
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease; }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   TARJETA CLIENTE PÚBLICA
   ============================================ */
.client-card {
  border-radius: 20px;
  padding: 22px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.client-card::before {
  content: '';
  position: absolute;
  top: -50px; right: -50px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  pointer-events: none;
}

.sello-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.sello-item {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  border: 2px solid rgba(255,255,255,0.3);
}

.sello-item.lleno { background: rgba(255,255,255,0.9); }
.sello-item.vacio { background: rgba(255,255,255,0.1); }

/* ============================================
   SCANNER
   ============================================ */
.scanner-page { max-width: 500px; margin: 0 auto; padding: 20px; }

.tipo-selector { display: flex; gap: 8px; padding: 12px 16px; flex-wrap: wrap; }

.tipo-btn {
  flex: 1;
  min-width: 120px;
  padding: 11px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--dark-3);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tipo-btn.active { border-color: var(--gold); color: var(--gold); background: var(--gold-muted); }

/* ============================================
   UTILIDADES
   ============================================ */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.text-muted { color: var(--text-muted); }
.text-gold { color: var(--gold); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.fw-600 { font-weight: 600; }
.text-center { text-align: center; }
.w-full { width: 100%; }

/* ============================================
   RESPONSIVE — TABLET (≤ 1024px)
   ============================================ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 210px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 20px 24px; }
  .topbar { padding: 16px 24px; }
}

/* ============================================
   RESPONSIVE — TABLET PEQUEÑA (≤ 768px)
   ============================================ */
@media (max-width: 768px) {
  /* Sidebar oculto por defecto */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  .sidebar.open { transform: translateX(0); }

  /* Main ocupa todo */
  .main { margin-left: 0; padding-top: var(--topbar-h); }

  /* Topbar móvil visible */
  .mobile-topbar { display: flex; }

  /* Topbar de página */
  .topbar {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .topbar-actions { width: 100%; justify-content: flex-start; }
  .time-filters { width: 100%; }
  .time-btn { flex: 1; text-align: center; }

  .content { padding: var(--content-pad-mobile); }

  /* Grids a 1 columna */
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }

  /* Dashboard chart más pequeño */
  .chart-container { height: 130px; }

  /* Métricas */
  .metric-value { font-size: 32px; }

  /* Tabla */
  table { font-size: 13px; }
  thead th, tbody td { padding: 10px 10px; }

  /* Tarjeta digital */
  .loyalty-card { max-width: 100%; }

  /* Login */
  .login-box { padding: 28px 20px; }
  .login-logo .logo-mark { font-size: 32px; }

  /* Segmentos */
  .segment-card { flex-direction: column; gap: 10px; }

  /* Modal — bottom sheet en móvil */
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 88vh; }
  .modal-overlay { align-items: flex-end; }
}

/* ============================================
   RESPONSIVE — MÓVIL (≤ 480px)
   ============================================ */
@media (max-width: 480px) {
  .page-title { font-size: 18px; }

  /* Botones más grandes para touch */
  .btn { padding: 12px 16px; font-size: 14px; min-height: 44px; }
  .btn-sm { padding: 9px 13px; font-size: 13px; min-height: 38px; }

  /* Inputs más altos para touch */
  .form-control { min-height: 44px; }

  .metric-value { font-size: 28px; }

  /* Scanner */
  .scanner-page { padding: 12px; }
  .tipo-btn { min-height: 50px; font-size: 13px; }

  /* Tarjeta cliente */
  .client-card { padding: 18px; }
  .sello-item { width: 30px; height: 30px; font-size: 13px; }

  /* Acciones */
  .icon-btn { width: 38px; height: 38px; }

  /* Login */
  .login-box { padding: 24px 16px; border-radius: 16px; }

  /* Tabla scroll horizontal más explícita */
  .table-wrapper { margin: 0 -16px; padding: 0 16px; }
}

/* ============================================
   iOS SAFE AREAS (iPhone X+)
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
  .modal { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .mobile-topbar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .main { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .sidebar { padding-bottom: env(safe-area-inset-bottom); }
}

@media (max-width: 768px) {
  @supports (padding: env(safe-area-inset-bottom)) {
    .main { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  }
}

/* ============================================
   DARK MODE NATIVO (ya es dark por defecto)
   ============================================ */
@media (prefers-color-scheme: light) {
  /* Fidelix es siempre dark — no cambiamos */
}

/* ============================================
   PRINT (básico)
   ============================================ */
@media print {
  .sidebar, .mobile-topbar, .topbar-actions { display: none !important; }
  .main { margin-left: 0; }
  body { background: white; color: black; }
}
