/* ============================================================
   Zentek Loyalty — Design System
   Tokens de diseño compartidos por login, dashboard y widgets.
   Dark mode por defecto; light mode con [data-theme="light"].
   ============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; outline: none; }
:focus-visible { outline: 2px solid var(--accent-border); outline-offset: 2px; }
html { -webkit-text-size-adjust: 100%; }
img, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }

/* ── Tokens — Dark (default) ─────────────────────────────── */
:root {
  /* Fuente del sistema: SF Pro en Apple, Roboto/Google Sans en Android — nativa y sin descarga. */
  --font: -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', Roboto, sans-serif;

  /* Fondos */
  --bg:        #0A0A0A;
  --bg-2:      #0D0D0D;
  --bg-3:      #111111;

  /* Superficies glass */
  --glass-bg:      rgba(14,14,14,0.55);
  --glass-bg-2:    rgba(255,255,255,0.05);
  --glass-border:  rgba(255,255,255,0.10);
  --glass-border-2:rgba(255,255,255,0.16);
  --glass-blur:    20px;
  --glass-blur-sm: 12px;

  /* Texto — secundarios con contraste legible (antes 0.55/0.30 se perdían) */
  --text:   #FFFFFF;
  --text-2: rgba(255,255,255,0.72);
  --text-3: rgba(255,255,255,0.48);
  --text-4: rgba(255,255,255,0.18);

  /* Acento — monocromático blanco */
  --accent:        #FFFFFF;
  --accent-text:   #0A0A0A;
  --accent-dim:    rgba(255,255,255,0.08);
  --accent-border: rgba(255,255,255,0.22);
  --accent-glow:   0 0 36px rgba(255,255,255,0.32);
  --accent-hover:  #E8E8E8;

  /* Glows */
  --glow-sm: 0 0 20px rgba(255,255,255,0.11);
  --glow-md: 0 0 40px rgba(255,255,255,0.14);
  --glow-lg: 0 0 70px rgba(255,255,255,0.12);
  --card-glow: 0 0 0 1px rgba(255,255,255,0.10), 0 4px 36px rgba(255,255,255,0.09);

  /* Sombras */
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.6);

  /* Semánticos */
  --success:     #4ade80;
  --success-dim: rgba(74,222,128,0.10);
  --warning:     #fbbf24;
  --warning-dim: rgba(251,191,36,0.10);
  --danger:      #f87171;
  --danger-dim:  rgba(248,113,113,0.10);
  --info:        #60a5fa;
  --info-dim:    rgba(96,165,250,0.10);

  /* Radios */
  --r-sm:  8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 9999px;

  /* Superficie sólida para sheets y sidebar en móvil (sin backdrop-filter:
     iOS no compone bien blur + transform animado, y el blur cuesta GPU). */
  --sheet: #17171B;

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h:   58px;
  --transition: 0.18s ease;

  /* Curvas de animación (feel de app nativa) */
  --ease:      cubic-bezier(.22, 1, .36, 1);   /* salida suave, "premium" */
  --ease-out:  cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1); /* rebote sutil */
  --press: 0.97;                                /* escala al presionar */
}

/* Transición suave SOLO durante el cambio de tema: JS pone html.theme-anim un
   instante. (Antes era global en * y cada nodo insertado transicionaba: los
   modales y renders se sentían trabados, sobre todo en móvil.) */
html.theme-anim *, html.theme-anim *::before, html.theme-anim *::after {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.15s ease, box-shadow 0.3s ease !important;
}
.btn { transition: background-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease, opacity 0.18s ease; }
.nav-item, .bn-item { transition: color 0.18s ease, background-color 0.18s ease; }

/* ── Tokens — Light ──────────────────────────────────────── */
[data-theme="light"] {
  --sheet: #FFFFFF;
  --bg:   #F0F0F0;
  --bg-2: #E8E8E8;
  --bg-3: #DFDFDF;

  --glass-bg:      rgba(255,255,255,0.80);
  --glass-bg-2:    rgba(255,255,255,0.60);
  --glass-border:  rgba(0,0,0,0.08);
  --glass-border-2:rgba(0,0,0,0.13);

  --text:   #0A0A0A;
  --text-2: rgba(10,10,10,0.68);
  --text-3: rgba(10,10,10,0.48);
  --text-4: rgba(10,10,10,0.16);

  --accent:        #0A0A0A;
  --accent-text:   #FFFFFF;
  --accent-dim:    rgba(0,0,0,0.07);
  --accent-border: rgba(0,0,0,0.22);
  --accent-glow:   0 0 28px rgba(0,0,0,0.18);
  --accent-hover:  #1F1F1F;

  --glow-sm: 0 2px 8px  rgba(0,0,0,0.08);
  --glow-md: 0 4px 20px rgba(0,0,0,0.12);
  --glow-lg: 0 8px 40px rgba(0,0,0,0.18);
  --card-glow: 0 0 0 1px rgba(0,0,0,0.09), 0 4px 30px rgba(0,0,0,0.10);

  --shadow-sm: 0 1px 4px  rgba(0,0,0,0.10);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);

  --success:     #16a34a;
  --success-dim: rgba(22,163,74,0.10);
  --warning:     #d97706;
  --warning-dim: rgba(217,119,6,0.10);
  --danger:      #dc2626;
  --danger-dim:  rgba(220,38,38,0.10);
  --info:        #2563eb;
  --info-dim:    rgba(37,99,235,0.10);
}

/* ── Base ────────────────────────────────────────────────── */
html {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body { min-height: 100vh; -webkit-font-smoothing: antialiased; }

a { color: inherit; text-decoration: none; }

/* ── Dot grid background ─────────────────────────────────── */
.bg-dots {
  position: fixed; inset: -40px; z-index: 0; pointer-events: none;
  background-image: radial-gradient(circle, rgba(255,255,255,0.12) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: radial-gradient(ellipse 95% 95% at 50% 50%, black 0%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 95% 95% at 50% 50%, black 0%, transparent 70%);
  animation: dotsDrift 30s ease-in-out infinite;
}
[data-theme="light"] .bg-dots {
  background-image: radial-gradient(circle, rgba(0,0,0,0.10) 1px, transparent 1px);
}
@keyframes dotsDrift {
  0%,100% { transform: translate(0,0); }
  33%      { transform: translate(6px,-8px); }
  66%      { transform: translate(-5px,6px); }
}

/* ── Glass component ─────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border);
}
.glass-sm {
  background: var(--glass-bg-2);
  backdrop-filter: blur(var(--glass-blur-sm));
  -webkit-backdrop-filter: blur(var(--glass-blur-sm));
  border: 1px solid var(--glass-border);
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--glass-bg-2);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--card-glow);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card:hover { border-color: var(--glass-border-2); box-shadow: var(--glow-md); }
.card-sm { padding: 14px 16px; border-radius: var(--r-md); }

.stat-card {
  background: var(--glass-bg-2);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--card-glow);
  transition: box-shadow var(--transition);
}
.stat-card .label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text-2); margin-bottom: 8px;
}
.stat-card .value { font-size: 28px; font-weight: 700; line-height: 1; color: var(--text); }
.stat-card .sub   { font-size: 13px; color: var(--text-3); margin-top: 6px; }
.stat-card .sub.up   { color: var(--success); }
.stat-card .sub.down { color: var(--danger); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--r-md); font-size: 15px; font-weight: 700;
  border: none; cursor: pointer; transition: all var(--transition); white-space: nowrap;
  position: relative; overflow: hidden;
}
.btn-primary {
  background: var(--accent); color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--accent-glow);
}
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.45; cursor: default; }

.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--glass-border-2);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2);
  border: 1px solid var(--glass-border);
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--glass-bg-2); color: var(--text); border-color: var(--glass-border-2); }
.btn-icon svg { width: 18px; height: 18px; pointer-events: none; }

.btn-sm { padding: 8px 16px; font-size: 14px; border-radius: var(--r-sm); }
.btn-full { width: 100%; }

/* ── Inputs ──────────────────────────────────────────────── */
.input-wrap { display: flex; flex-direction: column; gap: 6px; }
.input-wrap label { font-size: 13px; font-weight: 700; color: var(--text-2); letter-spacing: 0.03em; }

.input {
  width: 100%; padding: 13px 16px; border-radius: var(--r-md);
  background: var(--glass-bg-2); border: 1px solid var(--glass-border);
  color: var(--text); font-size: 15px; outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder { color: var(--text-3); }
.input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
/* El <select> cerrado toma el tema vía --glass-bg-2 (semitransparente), pero
   la lista desplegada la pinta el propio SO/navegador (sobre todo Android) y
   ahí un fondo con alpha no compone bien — queda en blanco. Se le da un color
   sólido explícito a las opciones para que la lista también respete el tema. */
select.input option { background-color: var(--sheet); color: var(--text); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
}
.badge-accent  { background: var(--accent);      color: var(--accent-text); }
.badge-primary { background: var(--accent);      color: var(--accent-text); }
.badge-success { background: var(--success-dim); color: var(--success); border: 1px solid rgba(74,222,128,0.2); }
.badge-warning { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(251,191,36,0.2); }
.badge-danger  { background: var(--danger-dim);  color: var(--danger);  border: 1px solid rgba(248,113,113,0.2); }
.badge-info    { background: var(--info-dim);    color: var(--info);    border: 1px solid rgba(96,165,250,0.2); }
.badge-muted   { background: rgba(255,255,255,0.06); color: var(--text-2); border: 1px solid var(--glass-border); }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
  width: 34px; height: 34px; border-radius: var(--r-full);
  background: var(--accent-dim); border: 1px solid var(--accent-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

/* ── Divider ─────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--glass-border); margin: 0; }

/* ── Toast ───────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
@media (max-width: 640px) {
  #toast-container { left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); align-items: center; }
  .toast { max-width: 100%; }
}
.toast {
  padding: 12px 18px; border-radius: var(--r-md); font-size: 14px; font-weight: 500;
  backdrop-filter: blur(16px); border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md); pointer-events: all; max-width: 320px;
  animation: toastIn 0.25s ease; color: var(--text);
  background: var(--glass-bg);
}
.toast-success { border-color: rgba(74,222,128,0.3); }
.toast-danger  { border-color: rgba(248,113,113,0.3); }
.toast-warning { border-color: rgba(251,191,36,0.35); }

/* ── App layout ──────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative; z-index: 1;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  position: fixed; top: 0; left: 0;
  display: flex; flex-direction: column;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border-right: 1px solid var(--glass-border);
  box-shadow: 4px 0 40px rgba(255,255,255,0.03);
  z-index: 110;
  transition: transform var(--transition);
}
[data-theme="light"] .sidebar {
  box-shadow: 4px 0 40px rgba(0,0,0,0.08);
}
.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px; margin-bottom: 14px;
}
.logo-zentek {
  font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.01em;
}
.logo-loyalty-badge {
  font-size: 10px; font-weight: 800; letter-spacing: 0.08em;
  padding: 3px 7px; border-radius: 5px;
  background: var(--text); color: var(--bg);
  line-height: 1.5;
}
/* compatibilidad con referencias antiguas al logo-mark */
.logo-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0;
}
.logo-name { font-size: 15px; font-weight: 700; color: var(--text); }

.biz-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-md);
  background: var(--glass-bg-2); border: 1px solid var(--glass-border);
  cursor: pointer; transition: border-color var(--transition);
}
.biz-chip:hover { border-color: var(--glass-border-2); }
.biz-chip-info { min-width: 0; flex: 1; }
.biz-chip-name { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.biz-chip-plan { font-size: 12px; color: var(--text-3); }

.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: none;
  /* Al llegar al tope, no propagar el scroll a la página de atrás. */
  overscroll-behavior: contain;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--text-3);
  padding: 12px 10px 5px;
}

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; border-radius: var(--r-sm);
  font-size: 15px; font-weight: 500; color: var(--text-2);
  background: transparent; border: none; width: 100%; text-align: left;
  cursor: pointer; transition: all var(--transition);
  position: relative;
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }
.nav-item:hover { background: var(--glass-bg-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid var(--accent-border);
}
.nav-item.active svg { color: var(--accent); }
.nav-item .lock-icon {
  margin-left: auto; opacity: 0.4;
  width: 14px; height: 14px;
}
.nav-item.locked { opacity: 0.45; cursor: not-allowed; }
.nav-item.locked:hover { background: transparent; color: var(--text-2); }
.nav-item .coming-badge {
  margin-left: auto; font-size: 9px; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; letter-spacing: 0.05em;
  background: var(--info-dim); color: var(--info); border: 1px solid rgba(96,165,250,0.2);
}

.sidebar-footer {
  padding: 12px 8px; border-top: 1px solid var(--glass-border);
  padding-bottom: max(12px, calc(8px + env(safe-area-inset-bottom)));
  flex-shrink: 0; display: flex; flex-direction: column; gap: 2px;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  position: fixed; top: 0; right: 0;
  left: var(--sidebar-w);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border-bottom: 1px solid var(--glass-border);
  z-index: 99;
  transition: left var(--transition);
}
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ── Main content ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  padding-top: var(--topbar-h);
  min-height: 100vh;
  position: relative; z-index: 1;
}
.content-inner {
  padding: 28px 28px 60px;
  max-width: 1200px;
}

/* ── Grid helpers ────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ── Grupos de contenido (Estadísticas, Integración API) ─── */
.group-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: 12px;
}

/* ── Section header ──────────────────────────────────────── */
.section-label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 8px;
}
.section-title { font-size: clamp(20px, 3vw, 28px); font-weight: 700; line-height: 1.2; }
.section-sub   { font-size: 14px; color: var(--text-2); line-height: 1.65; margin-top: 6px; }

/* ── Bar chart (CSS only) ────────────────────────────────── */
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-key  { font-size: 12px; color: var(--text-2); width: 28px; text-align: center; flex-shrink: 0; }
.bar-track { flex: 1; height: 6px; background: var(--glass-bg-2); border-radius: 3px; overflow: hidden; }
.bar-fill  { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.6s cubic-bezier(.16,1,.3,1); }
.bar-val   { font-size: 12px; color: var(--text-3); width: 30px; text-align: right; flex-shrink: 0; }

/* ── Skeleton loading ────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--glass-bg-2) 25%, rgba(255,255,255,0.08) 50%, var(--glass-bg-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: shimmer 1.6s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Coming soon placeholder ─────────────────────────────── */
.coming-soon {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 340px; gap: 14px; text-align: center;
}
.coming-soon svg { width: 48px; height: 48px; color: var(--text-4); }
.coming-soon h3  { font-size: 17px; font-weight: 700; color: var(--text-2); }
.coming-soon p   { font-size: 14px; color: var(--text-3); max-width: 320px; line-height: 1.6; }

/* ── Mobile menu button ──────────────────────────────────── */
.menu-toggle {
  display: none; width: 36px; height: 36px; border: 1px solid var(--glass-border);
  border-radius: var(--r-sm); background: transparent; color: var(--text-2);
  align-items: center; justify-content: center; cursor: pointer;
}
.menu-toggle svg { width: 18px; height: 18px; }

/* ── Bottom nav (mobile) ─────────────────────────────────── */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--glass-border);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}
.bn-items { display: flex; justify-content: space-around; }
.bn-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--text-3);
  padding: 4px 14px; border-radius: var(--r-sm); cursor: pointer;
  transition: color var(--transition); border: none; background: transparent;
}
.bn-item svg { width: 22px; height: 22px; }
.bn-item.active { color: var(--accent); }
.bn-item:hover:not(.active) { color: var(--text-2); }

/* ── Overlay (mobile sidebar) ────────────────────────────── */
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 109;
  background: rgba(0,0,0,0.5);
  opacity: 0; visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
  /* Mata el scroll de fondo al tocar fuera de la sidebar (iOS ignora overflow:hidden en body). */
  touch-action: none;
}
.sidebar-overlay.active { opacity: 1; visibility: visible; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    /* ponytail: en móvil NO animamos el transform de este panel fijo. Esa capa
       compuesta la congela/corrompe iOS (velo pegado, página en blanco, saltos
       entre secciones). Solo animamos opacidad (iOS sí la compone bien), sin
       translate. */
    transform: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s var(--ease), visibility 0.2s;
    background: var(--sheet);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .sidebar.open {
    opacity: 1;
    visibility: visible;
    box-shadow: var(--shadow-lg);
  }
  .topbar { left: 0; }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .content-inner  { padding: 20px 16px 80px; }
  .bottom-nav     { display: block; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4          { grid-template-columns: repeat(2, 1fr); }
  .topbar          { padding: 0 16px; }
}

/* ── Animations ──────────────────────────────────────────── */
.section-enter {
  animation: sectionFadeIn 0.22s ease forwards;
}
@keyframes sectionFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.reveal {
  opacity: 0; transform: translateY(20px);
  transition: opacity 0.5s cubic-bezier(.16,1,.3,1), transform 0.5s cubic-bezier(.16,1,.3,1);
}
.reveal.visible { opacity: 1; transform: translateY(0); }

/* ── Theme toggle button ─────────────────────────────────── */
.theme-toggle {
  width: 36px; height: 36px; border-radius: var(--r-sm);
  background: transparent; border: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-2); transition: all var(--transition);
}
.theme-toggle:hover { background: var(--glass-bg-2); color: var(--text); border-color: var(--glass-border-2); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-light { display: none; }
.theme-toggle .icon-dark  { display: block; }
[data-theme="light"] .theme-toggle .icon-light { display: block; }
[data-theme="light"] .theme-toggle .icon-dark  { display: none; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
/* Mientras se desvanece, el overlay ya no debe capturar clics: si no, el primer
   toque tras cerrar un modal "muere" en el overlay invisible (~180 ms). */
.modal-overlay.closing { animation: ovOut 0.18s ease forwards; pointer-events: none; }
.modal-overlay.closing .modal { animation: modalOut 0.18s ease forwards; }
@keyframes ovOut   { to { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(18px) scale(0.98); } }
@keyframes sheetIn { from { transform: translateY(60%); } }
@keyframes modalOut{ to { opacity: 0; transform: translateY(16px); } }
.modal {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg), var(--card-glow);
  width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
  animation: modalIn 0.28s var(--ease-out);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 0;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: transparent; border: 1px solid var(--glass-border);
  color: var(--text-2); cursor: pointer; font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--glass-bg-2); color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 0 20px 20px;
  display: flex; gap: 10px; justify-content: flex-end;
}
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  /* Sheet sólido: sin blur (caro y con bugs en iOS) y entrada deslizando. */
  .modal {
    max-width: 100%; border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: none;
    max-height: 88dvh;
    background: var(--sheet);
    backdrop-filter: none; -webkit-backdrop-filter: none;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheetIn 0.32s var(--ease-out);
  }
}
/* prefers-reduced-motion: cubierto por el bloque global al final del archivo
   (transition/animation-duration ~0 para *) — no repetir la regla aquí. */

/* ── Stamp dots ──────────────────────────────────────────── */
.stamp-grid {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin: 8px 0;
}
.stamp-dot {
  width: 16px; height: 16px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; line-height: 1;
  transition: all 0.15s ease;
}
.stamp-dot.filled { background: var(--accent); color: var(--bg); }
.stamp-dot.empty  { border: 1.5px solid var(--glass-border-2); color: transparent; }

/* ── Wallet card preview ─────────────────────────────────── */
.wallet-preview {
  border-radius: 16px; padding: 20px 22px;
  min-height: 160px; position: relative; overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.wallet-preview-logo {
  width: 38px; height: 38px; border-radius: 8px; object-fit: contain;
  background: rgba(255,255,255,0.15);
}
.wallet-preview-name  { font-size: 16px; font-weight: 700; margin-top: 10px; }
.wallet-preview-sub   { font-size: 13px; opacity: 0.65; margin-top: 2px; }
.wallet-preview-footer{ margin-top: 16px; display: flex; align-items: center; justify-content: space-between; }
.wallet-preview-pts   { font-size: 22px; font-weight: 800; }
.wallet-preview-label { font-size: 12px; opacity: 0.65; }

/* ── Toggle switch ───────────────────────────────────────── */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--glass-border);
}
.switch-row:last-child { border-bottom: none; }
.switch-label { font-size: 15px; font-weight: 500; color: var(--text); }
.switch-sub   { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.switch {
  position: relative; width: 40px; height: 22px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; border-radius: 11px;
  background: var(--glass-bg-2); border: 1px solid var(--glass-border-2);
  cursor: pointer; transition: background var(--transition);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch-track::after {
  content: ''; position: absolute;
  top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--text-2);
  transition: transform var(--transition), background var(--transition);
}
.switch input:checked + .switch-track::after {
  transform: translateX(18px); background: var(--bg);
}

/* ── Form rows ───────────────────────────────────────────── */
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 13px; font-weight: 700; color: var(--text-2); letter-spacing: 0.03em; }
.form-hint { font-size: 12px; color: var(--text-3); }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-swatch {
  width: 36px; height: 36px; border-radius: var(--r-sm);
  border: 2px solid var(--glass-border); cursor: pointer;
  flex-shrink: 0; overflow: hidden; padding: 0; position: relative;
}

/* ── Customer card ───────────────────────────────────────── */
.customer-list { display: flex; flex-direction: column; gap: 8px; }
.customer-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: var(--r-md);
  background: var(--glass-bg-2); border: 1px solid var(--glass-border);
  box-shadow: var(--card-glow);
  transition: border-color var(--transition);
  cursor: pointer;
}
.customer-item:hover { border-color: var(--glass-border-2); }
.customer-info { flex: 1; min-width: 0; }
.customer-name { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-phone { font-size: 13px; color: var(--text-3); margin-top: 1px; }
.customer-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.progress-track { flex: 1; height: 4px; border-radius: 2px; background: var(--glass-border-2); overflow: hidden; }
.progress-fill  { width: 100%; height: 100%; border-radius: 2px; background: var(--accent); transform-origin: left; transition: transform 0.4s var(--ease-spring); }
.customer-actions { display: flex; gap: 6px; flex-shrink: 0; }
@media (max-width: 640px) {
  .customer-item { flex-wrap: wrap; }
  .customer-actions { width: 100%; justify-content: flex-end; margin-top: 4px; }
}

/* ============================================================
   Feel de app nativa — respuesta táctil, transiciones y modo instalado.
   Va al final para ganar por orden de cascada.
   ============================================================ */

/* Sin rebote/pull-to-refresh del navegador; scroll con inercia. */
html, body { overscroll-behavior-y: contain; }
/* iOS: mata el zoom por doble-tap; los gestos de scroll siguen normales. */
html { touch-action: manipulation; }
.sidebar-nav, .modal, .main-content { -webkit-overflow-scrolling: touch; }

/* El "chrome" (barras y controles) no se selecciona: se siente app, no web. */
.sidebar, .topbar, .bottom-nav, .nav-item, .bn-item, .btn, .btn-icon,
.menu-toggle, .theme-toggle, .badge, .biz-chip, .modal-header, .section-label {
  -webkit-user-select: none; user-select: none;
}

/* Respuesta táctil inmediata: todo lo presionable se hunde al tocarlo. */
.nav-item, .bn-item, .btn, .btn-icon, .theme-toggle, .menu-toggle,
.customer-item, .biz-chip, .modal-close, .color-swatch, .switch-track {
  transition: transform 0.12s var(--ease), background-color 0.18s var(--ease),
              border-color 0.18s var(--ease), color 0.14s var(--ease), box-shadow 0.2s var(--ease);
}
.btn:active:not(:disabled),
.btn-icon:active:not(:disabled),
.nav-item:active,
.bn-item:active,
.theme-toggle:active,
.menu-toggle:active,
.customer-item:active,
.biz-chip:active,
.color-swatch:active,
.modal-close:active { transform: scale(var(--press)); }
.stat-card:active, .card:active { transform: scale(0.992); }
/* El botón activo de la nav inferior "salta" un poco al tocarlo. */
.bn-item.active svg { transition: transform 0.2s var(--ease-spring); }
.bn-item.active:active svg { transform: translateY(-2px) scale(1.08); }

/* Transición de sección con curva premium (entra desde abajo, suave). */
.section-enter { animation: sectionEnter 0.34s var(--ease) both; }
@keyframes sectionEnter {
  from { opacity: 0; transform: translateY(12px) scale(0.995); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* Toasts: entran desde abajo con rebote y salen limpio. En móvil, centrados. */
.toast { animation: toastIn 0.32s var(--ease-spring) both; will-change: transform, opacity; }
.toast.toast-out { animation: toastOut 0.28s var(--ease) forwards; }
@keyframes toastIn  { from { transform: translateY(16px) scale(0.96); opacity: 0; }
                      to   { transform: translateY(0)     scale(1);    opacity: 1; } }
@keyframes toastOut { from { transform: translateY(0)     scale(1);    opacity: 1; }
                      to   { transform: translateY(10px)  scale(0.97); opacity: 0; } }
@media (max-width: 640px) {
  #toast-container { left: 16px; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom)); align-items: center; }
  .toast { max-width: 100%; text-align: center; }
}

/* Modo instalado (standalone): respeta la barra de estado del sistema (notch/reloj). */
@media (display-mode: standalone) {
  .topbar { height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  .main-content { padding-top: calc(var(--topbar-h) + env(safe-area-inset-top)); }
  .sidebar-header { padding-top: max(20px, env(safe-area-inset-top)); }
}

/* Con un modal abierto, el fondo no scrollea (CSS puro: funciona sin importar
   cómo se cierre el modal). */
body:has(.modal-overlay) { overflow: hidden; }

/* Visor in-app (iOS PWA): abre Mi sitio/agenda con botón para volver al panel. */
.inapp-viewer {
  position: fixed; inset: 0; z-index: 999; background: var(--bg);
  display: flex; flex-direction: column;
  animation: sectionEnter 0.24s var(--ease) both;
}
.inapp-bar {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: calc(env(safe-area-inset-top) + 8px) 14px 8px;
  border-bottom: 1px solid var(--glass-border); background: var(--sheet);
}
.inapp-close {
  border: 1px solid var(--glass-border); background: var(--glass-bg-2);
  color: var(--text); font-size: 14px; font-weight: 700;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
}
.inapp-close:active { transform: scale(var(--press)); }
.inapp-url { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inapp-frame { flex: 1; width: 100%; border: 0; }

/* View Transitions API (cambio de sección): cross-fade breve, tipo app nativa. */
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.18s; }

/* Accesibilidad: si el usuario pide menos movimiento, lo respetamos. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .bg-dots { animation: none; }
}
