/* ==========================================================================
   VIVAGYM — Componentes compartidos ( Landing / Admin / PWA )
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, .display { font-family: var(--font-display); letter-spacing: .01em; margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
code, pre, .mono { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace; }

/* ---------- Layout ---------- */
.container { width: min(100% - 32px, var(--max-width)); margin-inline: auto; }
.section { padding: 64px 0; }
.section-sm { padding: 36px 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.muted { color: var(--muted); }
.dim { color: var(--text-dim); }
.tiny { font-size: 11px; }
.small { font-size: 12px; }
.upper { text-transform: uppercase; letter-spacing: .12em; font-weight: 700; }
.center { text-align: center; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.logo { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: .06em; }
.logo-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.nav { display: flex; align-items: center; gap: 22px; }
.nav a { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.nav a:hover, .nav a.active { color: var(--accent); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  transition: background .15s, border-color .15s, transform .15s, opacity .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: rgba(239,68,68,.5); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 7px 11px; font-size: 11px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }

/* ---------- Superficies ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card-hover { transition: border-color .15s, transform .15s; }
.card-hover:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-flat { background: var(--surface-2); }
.divider { height: 1px; background: var(--border); margin: 20px 0; border: 0; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface-2);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--success); border-color: rgba(34,197,94,.4); background: var(--success-soft); }
.badge.warn { color: var(--warning); border-color: rgba(245,158,11,.4); background: var(--warning-soft); }
.badge.bad { color: var(--danger); border-color: rgba(239,68,68,.4); background: var(--danger-soft); }
.badge.brand { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; outline: none; transition: border-color .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-dim); }
.textarea { resize: vertical; min-height: 80px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Tabla ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--text-dim); background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 10px 16px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); border-bottom: 2px solid transparent; background: none; border-top: 0; border-left: 0; border-right: 0;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { padding-top: 24px; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px); display: none; align-items: center; justify-content: center; padding: 16px;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px;
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.modal-close { background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); border-radius: 8px; width: 30px; height: 30px; }

/* ---------- Admin ---------- */
.admin-shell { display: grid; grid-template-columns: 250px 1fr; min-height: calc(100vh - 66px); }
.admin-side { border-right: 1px solid var(--border); padding: 24px 16px; background: var(--surface); }
.admin-side .side-item {
  display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px;
  background: transparent; border: 0; color: var(--muted); font-size: 13px; font-weight: 600;
}
.admin-side .side-item:hover, .admin-side .side-item.active { background: var(--accent-soft); color: var(--accent); }
.admin-main { padding: 28px; min-width: 0; }
.page-title { font-size: 26px; text-transform: uppercase; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- PWA / Teléfono ---------- */
.phone-stage { min-height: calc(100vh - 66px); display: grid; place-items: center; padding: 24px 12px 90px; }
.phone {
  width: min(100%, 430px); min-height: 720px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 28px;
  display: flex; flex-direction: column; overflow: hidden; position: relative;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.phone-header { padding: 20px 18px 12px; border-bottom: 1px solid var(--border); }
.phone-body { flex: 1; overflow-y: auto; padding: 18px; padding-bottom: 20px; }
.phone-view { display: none; }
.phone-view.active { display: block; }

.bottom-tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
  width: min(100%, 430px); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); z-index: 50;
}
.bottom-tabs button {
  background: none; border: 0; color: var(--text-dim); font-size: 8px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
}
.bottom-tabs button.active { color: var(--accent); }
.bottom-tabs .ico { font-size: 18px; line-height: 1; }

/* Historial del socio */
.history-item { padding: 14px; }
.history-item h4 { font-family: var(--font-display); text-transform: uppercase; }

/* Tarjeta de máquina */
.machine-card { border: 1px solid var(--accent); background: var(--surface); border-radius: var(--radius-lg); padding: 18px; }
.machine-name { font-family: var(--font-display); font-size: 24px; text-transform: uppercase; line-height: 1.1; margin-top: 6px; }
.strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.strip::-webkit-scrollbar { display: none; }
.strip button {
  flex: 0 0 128px; text-align: left; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; color: var(--text);
}
.strip button.active { border-color: var(--accent); background: var(--accent-soft); }
.strip img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; margin-bottom: 8px; background: var(--surface-3); }
.strip .strip-name { font-size: 11px; font-weight: 700; line-height: 1.25; }

.level-tabs { display: flex; gap: 6px; margin: 16px 0 12px; }
.level-tabs button {
  flex: 1; padding: 8px 4px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase;
}
.level-tabs button.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.preset-line { display: flex; gap: 8px; margin-bottom: 14px; }
.preset-line > div { flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.preset-line span { display: block; font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .1em; }
.preset-line strong { font-family: var(--font-display); font-size: 18px; color: var(--accent); }
.steps { counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; gap: 10px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.steps li::before {
  counter-increment: step; content: counter(step); flex: 0 0 20px; height: 20px; border-radius: 50%;
  background: var(--surface-3); color: var(--accent); display: grid; place-items: center; font-size: 10px; font-weight: 800;
}

/* Cronómetro fijo */
.timer-bar {
  position: sticky; bottom: 0; margin-top: 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; z-index: 5;
}
.timer-value { font-family: var(--font-display); font-size: 28px; color: var(--accent); font-variant-numeric: tabular-nums; }
.block-screen { text-align: center; padding: 40px 12px; }
.block-icon { font-size: 44px; margin-bottom: 12px; }

/* Visor de animación a pantalla completa */
.viewer {
  position: fixed; inset: 0; z-index: 120;
  background: #FFFFFF; color: #1E242B;
  display: none; flex-direction: column;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
.viewer.open { display: flex; }
.viewer-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.viewer-close { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 18px; font-weight: 700; }
.viewer-title-wrap { min-width: 0; flex: 1; }
.viewer-title { font-family: var(--font-display); font-size: 20px; text-transform: uppercase; line-height: 1.05; margin-top: 2px; }
.viewer-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 10px; overflow: hidden; }
.viewer-stage img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; }
.viewer-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: rgba(255,255,255,.92); color: var(--text); font-size: 28px; line-height: 1; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.viewer-nav.prev { left: 10px; }
.viewer-nav.next { right: 10px; }
.viewer-foot { max-height: 34vh; overflow-y: auto; padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.viewer-foot .preset-line { margin-bottom: 12px; }
.viewer-foot .preset-line > div { background: var(--surface); }
.viewer-foot .steps { margin: 0; }
.strip-media { position: relative; display: block; }
.strip-media::after {
  content: '▶'; position: absolute; right: 6px; top: 6px;
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--on-accent);
  font-size: 9px; display: grid; place-items: center; padding-left: 1px;
}

/* Sticker */
.sticker { background: #fff; color: #111; border-radius: 12px; padding: 18px; text-align: center; }
.sticker svg { width: 190px; height: 190px; margin: 0 auto 10px; }
.sticker .sticker-code { font-family: var(--font-display); font-size: 18px; letter-spacing: .08em; }
.sticker .sticker-sub { font-size: 11px; color: #555; }

/* Responsive */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-shell { grid-template-columns: 1fr; }
  .admin-side { border-right: 0; border-bottom: 1px solid var(--border); display: flex; gap: 6px; overflow-x: auto; padding: 12px; }
  .admin-side .side-item { width: auto; white-space: nowrap; }
  .admin-main { padding: 18px 14px; }
}
@media (max-width: 640px) {
  .nav { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .section { padding: 44px 0; }
  .phone-stage { padding: 0; }
  .phone { border: 0; border-radius: 0; min-height: 100vh; box-shadow: none; }
  .topbar-inner { height: 58px; }
}
