:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --text-muted: #666c78;
  --accent: #2f5dff;
  --accent-dark: #1f3fc4;
  --danger: #c62839;
  --sidebar-bg: #171a21;
  --sidebar-text: #c7cad1;
  --sidebar-text-active: #ffffff;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* --- Layout de administracion: sidebar + contenido --- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar__brand {
  font-size: 16px;
  font-weight: 600;
  color: var(--sidebar-text-active);
}

.sidebar__brand span {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--sidebar-text);
  margin-top: 2px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav a {
  color: var(--sidebar-text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.sidebar nav a.active {
  background: var(--accent);
  color: #fff;
}

.sidebar__section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7a808d;
  margin: 0 0 6px 10px;
}

.main {
  flex: 1;
  padding: 32px 40px;
  max-width: 960px;
}

/* Paginas que aprovechan el hueco libre a la derecha en pantallas anchas
   (p. ej. la ficha de un pase, con la vista previa en vivo) -- max-width
   mayor solo aqui, el resto de paginas se quedan en el ancho normal de
   lectura (960px). */
.main--wide {
  max-width: 1400px;
}

.pass-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

.pass-detail-preview {
  position: sticky;
  top: 24px;
}

.pass-detail-preview__frame {
  width: 100%;
  height: 720px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f2f2f4;
}

.pass-detail-preview__label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.pass-detail-preview__empty {
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

@media (max-width: 1099px) {
  .pass-detail-layout {
    grid-template-columns: 1fr;
  }
  .pass-detail-preview {
    position: static;
    /* En movil/tablet, la vista previa iria antes de los formularios de
       gestion y ocuparia toda la pantalla sin aportar -- se oculta y se usa
       el enlace "Ver vista previa" (abre aparte) en su lugar. */
    display: none;
  }
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 8px;
}

.page-header h1 {
  margin: 0;
  font-size: 22px;
}

.page-header .breadcrumb {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 4px;
}

/* --- Tarjetas / superficies --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin-top: 0;
  font-size: 16px;
}

.empty-state {
  color: var(--text-muted);
  font-style: italic;
  padding: 12px 0;
}

/* --- Tablas --- */

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

th,
td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

/* --- Formularios --- */

form.stacked {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 420px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='date'],
textarea,
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 70px;
}

button,
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

button:hover,
.btn:hover {
  background: var(--accent-dark);
  text-decoration: none;
}

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

.btn-secondary:hover {
  background: var(--bg);
}

.inline-form {
  display: inline;
}

/* --- Mensajes flash --- */

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
}

.flash-success {
  background: #e5f6ec;
  color: #14663c;
  border: 1px solid #b7e4c7;
}

.flash-error {
  background: #fbe9ea;
  color: var(--danger);
  border: 1px solid #f3c1c6;
}

/* --- Vista publica del pase --- */
/*
 * Fiel a la estructura real de un pase Apple/Google Wallet, no a una
 * "tarjeta de credito" inventada: fondo solido (color de marca, sin
 * gradiente libre), logo+nombre arriba, campo primario grande, secundario
 * debajo, QR real al pie sobre blanco solido. El color de texto no es un
 * capricho de CSS -- viene calculado por contraste desde el servidor
 * (src/lib/passColors.js) a partir del color de fondo, igual que exige
 * Apple/Google para que ningun tenant pueda crear un pase ilegible.
 */

body.pass-preview-body {
  background: #f2f2f4;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 32px 20px;
}

.pass-preview-column {
  width: 100%;
  max-width: 340px;
}

.pass-preview-label {
  text-align: center;
  font-size: 12px;
  color: #6b6f76;
  margin: 0 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/*
 * Sistema del pase: cabecera de marca (color del tenant) + cuerpo tipo
 * "carne" en papel crema + divisor decorativo entre ambos. Serif (Playfair
 * Display) para el nombre del tenant y el valor principal -- da caracter e
 * intencion en vez de una tarjeta de credito generica; Inter para
 * etiquetas/metadatos, que deben leerse como datos, no como titular.
 * Estructura generica: funciona igual con cualquier logo/color de marca,
 * no esta pensada solo para un tenant.
 */

.wallet-pass {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  background: #fcfcfb;
}

.wallet-pass--expired .wallet-pass__band {
  filter: grayscale(0.85);
}

.wallet-pass--expired .wallet-pass__holder-block,
.wallet-pass--expired .wallet-pass__meta-row {
  opacity: 0.55;
}

.wallet-pass__value--expired {
  color: #8a3b2a;
}

.wallet-pass__renew {
  background: #fdf1ec;
  border: 1px solid #f0cfc0;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

.wallet-pass__renew-value {
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  font-weight: 700;
  color: #8a3b2a;
  margin: 0;
}

.wallet-pass__band {
  background: var(--brand);
  color: var(--brand-text);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 18px 20px;
}

.wallet-pass__logo-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.wallet-pass__logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wallet-pass__logo-badge--initials {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 700;
}

.wallet-pass__band-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
  font-family: 'Playfair Display', serif;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.3;
  padding-top: 3px;
}

/* Isotipo en blanco opcional en vez del nombre en texto (imagen de marca
   propia del negocio, ver brandMarkUrlForTenant en src/routes/public.js) --
   altura fija a ojo de texto normal, ancho libre segun proporcion real. */
.wallet-pass__band-mark {
  height: 22px;
  width: auto;
  align-self: center;
}

.wallet-pass__scallop {
  display: block;
  width: 100%;
  height: 10px;
  margin-top: -1px;
}

.wallet-pass__body {
  padding: 20px 18px 22px;
}

.wallet-pass__label {
  font-family: 'Inter', sans-serif;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #9a8f78;
  margin: 0 0 4px;
}

.wallet-pass__value {
  font-family: 'Playfair Display', serif;
  font-size: 30px;
  font-weight: 700;
  color: #2b2a22;
  margin: 0;
  line-height: 1.15;
}

.wallet-pass__primary {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e9e7e1;
}

.wallet-pass__primary-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.wallet-pass__header-field {
  text-align: right;
  flex-shrink: 0;
}

.wallet-pass__header-field-value {
  font-family: 'Playfair Display', serif;
  font-size: 30px;
  font-weight: 700;
  color: #2b2a22;
  margin: 0;
  line-height: 1.15;
}

.wallet-pass__meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
}

.wallet-pass__meta {
  flex: 1;
  min-width: 0;
}

.wallet-pass__meta-value {
  font-family: 'Inter', sans-serif;
  font-size: 14.5px;
  font-weight: 600;
  color: #3a3830;
  margin: 0;
  overflow-wrap: break-word;
}

.wallet-pass__holder-block {
  margin-bottom: 14px;
}

.wallet-pass__holder-value {
  font-family: 'Playfair Display', serif;
  font-size: 19px;
  font-weight: 600;
  color: #2b2a22;
  margin: 0;
  line-height: 1.25;
  overflow-wrap: break-word;
}

.wallet-pass__foot {
  height: 6px;
}

.pass-preview-warning {
  text-align: center;
  color: #9a5b00;
  background: #fff3e0;
  border: 1px solid #ffd699;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  margin: 14px 0 0;
}

/* --- Panel de simulacion (fuera de la tarjeta, deliberadamente distinto) --- */

.pass-preview-sim {
  margin-top: 24px;
  background: #ffffff;
  border: 1px dashed #c9ccd2;
  border-radius: 10px;
  padding: 14px 16px;
}

.pass-preview-sim__title {
  font-size: 12px;
  font-weight: 700;
  color: #55585f;
  margin: 0 0 6px;
}

.pass-preview-sim__note {
  font-size: 12px;
  color: #7a7d84;
  margin: 0 0 10px;
  line-height: 1.4;
}

.pass-preview-sim__empty {
  font-size: 13px;
  color: #9a9da3;
  font-style: italic;
  margin: 0;
}

.pass-preview-sim__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pass-preview-sim__list li {
  font-size: 13px;
  color: #33353a;
  padding: 6px 0;
  border-top: 1px solid #ececef;
}

.pass-preview-sim__list li:first-child {
  border-top: none;
}

.pass-preview-sim__list time {
  display: block;
  font-size: 11px;
  color: #9a9da3;
  margin-top: 2px;
}

/* --- Editor de marca (branding.ejs) --- */

.branding-mini-pass {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  padding: 14px 16px;
  max-width: 320px;
}

.branding-mini-pass__logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: #ffffff;
}

.branding-mini-pass__logo--placeholder {
  background: rgba(255, 255, 255, 0.35);
}

.branding-mini-pass__name {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 14px;
}

.branding-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.branding-palette__swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.branding-palette__swatch.is-selected {
  border-color: var(--text);
}

.branding-suggestion {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.branding-suggestion__swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid var(--border);
}

/* --- Paginas de autenticacion (login, invite) --- */

body.auth-body {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px;
}

.auth-card__title {
  margin: 0 0 2px;
  font-size: 18px;
}

.auth-card__subtitle {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
}

/* --- Sidebar: usuario/logout, clave de API --- */

.sidebar__user {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 12px;
  color: var(--sidebar-text);
}

.sidebar__user-email {
  display: block;
  color: var(--sidebar-text-active);
  margin-bottom: 6px;
  word-break: break-all;
}

.sidebar__user-link {
  display: block;
  color: var(--sidebar-text);
  margin-bottom: 8px;
  font-size: 12px;
}

.sidebar__user-link.active {
  color: var(--sidebar-text-active);
}

.sidebar__user form {
  margin: 0;
}

.sidebar__user button {
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 12px;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.invite-link-box {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 20px;
  font-size: 13px;
  word-break: break-all;
}

.api-key-box {
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  word-break: break-all;
  font-family: ui-monospace, monospace;
}

/* --- Punto de color de marca junto al nombre del negocio (reconocimiento
   rapido en el listado de superadmin y en la ficha, sin abrir "Marca") --- */

.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

.color-dot--lg {
  width: 14px;
  height: 14px;
  margin-right: 10px;
}

/* --- Resumen de uso total del motor (tenants.ejs, solo superadmin) --- */

.usage-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.usage-summary__stat {
  display: flex;
  flex-direction: column;
  min-width: 90px;
}

.usage-summary__value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.usage-summary__label {
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Resumen de estado de pases (tenant.ejs) --- */

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 14px;
}

.stat-pill {
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.stat-pill strong {
  font-variant-numeric: tabular-nums;
}

.stat-pill--active {
  background: #e5f6ec;
  border-color: #b7e4c7;
  color: #14663c;
}

.stat-pill--expired {
  background: #fdf1ec;
  border-color: #f0cfc0;
  color: #8a3b2a;
}

.stat-pill--neutral {
  color: var(--text-muted);
}

/* ==========================================================================
   Responsive: por debajo de 768px el sidebar deja de ser una columna fija
   a la izquierda y pasa a ser una barra horizontal arriba (nav con scroll
   lateral) para que el panel se use bien desde el movil de un
   tenant_admin sin JS de cliente -- coherente con el resto del proyecto
   (formularios planos, sin bundler de frontend).
   ========================================================================== */

@media (max-width: 768px) {
  .app-shell {
    flex-direction: column;
    min-height: auto;
  }

  .sidebar {
    width: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 20px;
    padding: 14px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .sidebar__brand {
    flex-shrink: 0;
  }

  .sidebar nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar nav a {
    white-space: nowrap;
  }

  .sidebar__section-title {
    display: none;
  }

  .sidebar__user {
    margin-top: 0;
    margin-left: auto;
    padding-top: 0;
    border-top: none;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .sidebar__user-email {
    margin-bottom: 0;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar__user-link {
    margin-bottom: 0;
    white-space: nowrap;
  }

  .main {
    padding: 20px 16px;
    max-width: 100%;
  }

  .page-header {
    align-items: flex-start;
  }

  form.stacked {
    max-width: 100%;
  }

  .branding-mini-pass {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  .card {
    padding: 16px;
  }

  .wallet-pass__value,
  .wallet-pass__header-field-value {
    font-size: 26px;
  }
}

/* Tablas anchas (pases, notificaciones): scroll horizontal propio en vez de
   desbordar la pagina entera -- el body nunca debe scrollear en horizontal. */
.table-scroll {
  overflow-x: auto;
}
