/* ==========================================================================
   Sistema Varieté Commerce Intelligence — hoja de estilos base
   Sin frameworks externos. Variables CSS para theming centralizado.
   ========================================================================== */

:root {
  /* Colores base */
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-surface-alt: #fafbfc;
  --color-border: #e3e6ea;
  --color-border-strong: #cbd0d8;

  /* Texto */
  --color-text: #1a1d23;
  --color-text-secondary: #5b6270;
  --color-text-muted: #9aa1ac;
  --color-text-inverse: #ffffff;

  /* Marca / acciones */
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-primary-light: #eaf1ff;

  /* Estados */
  --color-success: #16a34a;
  --color-success-bg: #eafbf0;
  --color-warning: #b45309;
  --color-warning-bg: #fff8e6;
  --color-danger: #dc2626;
  --color-danger-bg: #fdecec;
  --color-info: #2563eb;
  --color-info-bg: #eaf1ff;

  /* Geometría */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 16px rgba(16, 24, 40, 0.08);

  /* Layout */
  --header-height: 64px;
  --container-max: 1180px;
  --transition: 150ms ease;
}

/* ---------- Reset básico ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

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

h1, h2, h3, h4 { margin: 0 0 4px 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 8px 0; }

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

.text-muted { color: var(--color-text-secondary); font-size: 0.9rem; }

/* ==========================================================================
   Header / navegación
   ========================================================================== */

.app-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.app-header__inner {
  max-width: var(--container-max);
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
}

/* Marca: dos niveles tipográficos — "VARIETÉ" (principal) + "Commerce Intelligence" (sistema) */
.app-header__brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  white-space: nowrap;
}
.app-header__brand:hover { text-decoration: none; }

.app-header__brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: var(--color-text);
}

.app-header__brand-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.app-header__toggle {
  display: none;
  margin-left: auto;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  width: 40px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text);
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.app-nav__link {
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.app-nav__link:hover { background: var(--color-surface-alt); color: var(--color-text); text-decoration: none; }
.app-nav__link.is-active { color: var(--color-primary); background: var(--color-primary-light); }

.app-header__user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.app-header__username { font-weight: 600; font-size: 0.9rem; }

.app-header__logout-form { margin: 0; }

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge-role { background: var(--color-surface-alt); color: var(--color-text-secondary); border: 1px solid var(--color-border); text-transform: capitalize; }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-pending { background: var(--color-surface-alt); color: var(--color-text-muted); border: 1px dashed var(--color-border-strong); }

/* ==========================================================================
   Botones
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-alt); }

.btn-danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: transparent; }
.btn-danger:hover { background: #fbdede; }

.btn-success { background: var(--color-success-bg); color: var(--color-success); }
.btn-success:hover { background: #d9f6e3; }

.btn-ghost { background: transparent; color: var(--color-text-secondary); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-surface-alt); }

.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ==========================================================================
   Layout principal
   ========================================================================== */

.app-main { padding: 32px 20px 60px; }

.app-container {
  max-width: var(--container-max);
  margin: 0 auto;
}

.page-header { margin-bottom: 24px; }

.page-header--with-action {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* ==========================================================================
   Tarjetas / cards
   ========================================================================== */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.form-card { max-width: 480px; margin-bottom: 24px; }
.form-card--secondary { border-style: dashed; }

/* ==========================================================================
   Grid de módulos (dashboard)
   ========================================================================== */

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.module-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), transform var(--transition);
  color: var(--color-text);
}
a.module-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; color: var(--color-text); }

.module-card__title { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.module-card__desc { color: var(--color-text-secondary); font-size: 0.85rem; margin-bottom: 12px; }

.module-card--disabled {
  opacity: 0.65;
  cursor: default;
}

/* ==========================================================================
   Formularios
   ========================================================================== */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--color-text);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group select {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.92rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-hint { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 4px; }
.form-error { font-size: 0.8rem; color: var(--color-danger); margin-top: 4px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  cursor: pointer;
}
.checkbox-label input { width: auto; }

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.inline-form { display: inline; margin: 0; }

/* ==========================================================================
   Autenticación
   ========================================================================== */

.auth-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 40px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 24px;
}

.auth-brand__name {
  display: block;
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--color-text);
}

.auth-brand__sub {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
  letter-spacing: 0.03em;
  margin-top: 2px;
}

.auth-brand__descriptor {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--color-text-secondary);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px;
}

.auth-card__header { margin-bottom: 24px; text-align: center; }

/* ==========================================================================
   Páginas de error (403 / 404)
   ========================================================================== */

.error-page {
  text-align: center;
  padding: 56px 16px;
  max-width: 420px;
  margin: 0 auto;
}

.error-page__code {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: 12px;
}

.error-page__title { margin-bottom: 8px; }

.error-page__desc {
  color: var(--color-text-secondary);
  margin-bottom: 24px;
}

.error-page__actions {
  display: flex;
  justify-content: center;
}

/* ==========================================================================
   Tabla
   ========================================================================== */

.table-wrap {
  overflow-x: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.table { width: 100%; border-collapse: collapse; min-width: 560px; }

.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.table th {
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--color-surface-alt);
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--color-surface-alt); }

.table__actions { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.table__actions-col { width: 1%; }
.table__empty { text-align: center; color: var(--color-text-muted); padding: 32px 16px; }

/* ==========================================================================
   Alertas / flash messages
   ========================================================================== */

.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }

.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  border: 1px solid transparent;
}

.alert-success { background: var(--color-success-bg); color: var(--color-success); border-color: #bdedcd; }
.alert-danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: #f7c9c9; }
.alert-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: #f2debb; }
.alert-info { background: var(--color-info-bg); color: var(--color-info); border-color: #c9dcfb; }

.alert__close {
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
}
.alert__close:hover { opacity: 1; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
  .app-header__toggle { display: inline-flex; }

  .app-nav {
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-direction: column;
    align-items: stretch;
    padding: 8px;
    box-shadow: var(--shadow-md);
    display: none;
  }
  .app-nav.is-open { display: flex; }
  .app-nav__link { padding: 12px; }

  .app-header__user { margin-left: 0; }
  .app-header__username { display: none; }

  .app-main { padding: 20px 16px 48px; }

  .page-header--with-action { flex-direction: column; }

  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
}

/* Header muy angosto: ocultar la sub-etiqueta de marca para no chocar con el toggle */
@media (max-width: 480px) {
  .app-header__brand-sub { display: none; }
}