/*
 * ============================================================
 * GRANCARTA - APP (puerta única)
 * Selector de ámbitos
 *
 * Mismo design system que admin.grancarta.com:
 *   - Azul Francia (#2563EB) protagonista
 *   - Modo oscuro permanente
 *   - Inter + JetBrains Mono
 * ============================================================
 */

/* ============================================================ */
/* DESIGN TOKENS                                                */
/* ============================================================ */
:root {
  /* Backgrounds */
  --bg: #0A0E14;
  --bg-elevated: #131820;
  --bg-card: #1A2230;
  --bg-card-hover: #232C3D;

  /* Text */
  --text: #F5F5F4;
  --text-soft: #B8B8B5;
  --text-muted: #888780;
  --text-faint: #5F5E5A;

  /* Brand */
  --primary: #2563EB;
  --primary-hover: #3B82F6;
  --primary-light: #60A5FA;
  --primary-soft: rgba(37, 99, 235, 0.12);
  --primary-glow: rgba(37, 99, 235, 0.25);

  --navy: #1B2B4A;

  /* States */
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;

  --success-soft: rgba(16, 185, 129, 0.12);
  --warning-soft: rgba(245, 158, 11, 0.12);
  --danger-soft: rgba(239, 68, 68, 0.12);

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.1);

  /* Typography */
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* Shadows */
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-primary: 0 4px 14px rgba(37, 99, 235, 0.25);

  /* Animation */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================================ */
/* RESET & BASE                                                 */
/* ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

input, button, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* ============================================================ */
/* SCREENS                                                      */
/* ============================================================ */
.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen.is-active {
  display: block;
  animation: screenIn 0.3s var(--ease);
}

/* ============================================================ */
/* BRAND                                                        */
/* ============================================================ */
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--primary) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.brand-mark-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 16px;
}

.brand-name {
  font-size: 1.625rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 1rem;
  color: var(--text);
}

.brand-tagline {
  font-size: 0.875rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 0.25rem;
}

.brand-icon-mail {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

/* ============================================================ */
/* BUTTONS                                                       */
/* ============================================================ */
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-soft);
  transition: all 0.15s var(--ease);
}
.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}
.btn-icon:active {
  transform: scale(0.94);
}

/* ============================================================ */
/* LOGIN SCREENS                                                */
/* ============================================================ */
.screen-login.is-active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background:
    radial-gradient(ellipse at top, rgba(37, 99, 235, 0.08) 0%, transparent 60%),
    var(--bg);
}

.login-container {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-brand {
  margin-bottom: 2.5rem;
  animation: fadeInUp 0.5s var(--ease);
}

.login-brand .brand-mark {
  margin: 0 auto;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  animation: fadeInUp 0.6s var(--ease);
}

.login-label {
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

.login-input {
  width: 100%;
  padding: 0.875rem 1.125rem;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  outline: none;
  transition: all 0.2s var(--ease);
}

.login-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.login-input-code {
  font-family: var(--font-mono);
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-align: center;
  text-indent: 0.5em;
  padding: 1rem;
}

.login-btn {
  padding: 1rem 1.25rem;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.9375rem;
  background: var(--primary);
  color: white;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-primary);
  transition: all 0.15s var(--ease);
}

.login-btn:hover:not(:disabled) { background: var(--primary-hover); }
.login-btn:active { transform: scale(0.98); }
.login-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.login-status {
  min-height: 1.5em;
  font-size: 0.8125rem;
  text-align: center;
  padding-top: 0.25rem;
  color: var(--text-muted);
}
.login-status.is-error { color: var(--danger); }
.login-status.is-success { color: var(--success); }

.login-back {
  margin-top: 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: var(--r-sm);
  transition: color 0.2s;
}
.login-back:hover { color: var(--text); }

.login-footer {
  margin-top: 2rem;
  color: var(--text-faint);
  font-size: 0.75rem;
}

/* ============================================================ */
/* SELECTOR DE ÁMBITOS                                          */
/* ============================================================ */
#screen-selector.is-active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  padding-top: calc(1rem + env(safe-area-inset-top, 0));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.sel-header-left {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-width: 0;
}

.sel-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.sel-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

.sel-main {
  flex: 1;
  padding: 3rem 1.5rem 4rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

.sel-intro {
  margin-bottom: 2.5rem;
  animation: fadeInUp 0.4s var(--ease);
}

.sel-heading {
  font-size: 2rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0.625rem;
  color: var(--text);
}

.sel-lead {
  font-size: 0.9375rem;
  color: var(--text-soft);
  max-width: 540px;
}

/* ============================================================ */
/* GRID DE ÁMBITOS                                              */
/* ============================================================ */
.ambitos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.ambito-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  padding: 1.5rem 1.5rem 1.25rem;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  transition: all 0.2s var(--ease);
  animation: cardIn 0.4s var(--ease) backwards;
  position: relative;
  overflow: hidden;
}

/* Color accent bar superior */
.ambito-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--navy) 0%, var(--primary) 100%);
  opacity: 0.8;
}

.ambito-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-card);
}

.ambito-card:active {
  transform: translateY(-1px);
}

/* Animación escalonada de las cards */
.ambito-card:nth-child(1) { animation-delay: 0.05s; }
.ambito-card:nth-child(2) { animation-delay: 0.10s; }
.ambito-card:nth-child(3) { animation-delay: 0.15s; }
.ambito-card:nth-child(4) { animation-delay: 0.20s; }
.ambito-card:nth-child(5) { animation-delay: 0.25s; }
.ambito-card:nth-child(6) { animation-delay: 0.30s; }
.ambito-card:nth-child(n+7) { animation-delay: 0.35s; }

/* Encabezado del card */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.card-empresa {
  flex: 1;
  min-width: 0;
}

.card-empresa-name {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
  line-height: 1.2;
}

.card-local-name {
  font-size: 0.8125rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.card-local-name-empty {
  color: var(--warning);
  font-style: italic;
}

/* Badge del rol */
.card-rol-badge {
  flex-shrink: 0;
  padding: 0.25rem 0.625rem;
  border-radius: 100px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.card-rol-badge.is-dueno {
  background: var(--primary-soft);
  color: var(--primary-light);
  border: 1px solid var(--primary-glow);
}

.card-rol-badge.is-encargado {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.card-rol-badge.is-mozo {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Stats */
.card-stats {
  display: flex;
  gap: 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-soft);
}

.card-stat {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.card-stat-icon {
  font-size: 0.875rem;
  opacity: 0.7;
}

.card-stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text);
}

.card-stat-label {
  color: var(--text-muted);
}

/* CTA */
.card-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.card-cta-action {
  color: var(--primary-light);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  transition: gap 0.2s var(--ease);
}

.ambito-card:hover .card-cta-action {
  gap: 0.625rem;
  color: var(--primary-hover);
}

/* ============================================================ */
/* EMPTY STATE                                                  */
/* ============================================================ */
.sel-empty {
  padding: 4rem 2rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  text-align: center;
  color: var(--text-muted);
  animation: fadeInUp 0.4s var(--ease);
}

.sel-empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.sel-empty-title {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-soft);
  margin-bottom: 0.625rem;
}

.sel-empty-detail {
  font-size: 0.9375rem;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ============================================================ */
/* TOAST                                                        */
/* ============================================================ */
.toast {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top, 0));
  left: 50%;
  transform: translateX(-50%) translateY(-200%);
  z-index: 200;
  background: var(--bg-card);
  border: 1.5px solid var(--primary);
  color: var(--text);
  padding: 0.875rem 1.5rem;
  border-radius: 100px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-card);
  transition: transform 0.4s var(--ease);
  white-space: nowrap;
  max-width: calc(100vw - 2rem);
}

.toast.is-visible {
  transform: translateX(-50%) translateY(0);
}

.toast.is-error { border-color: var(--danger); }
.toast.is-success { border-color: var(--success); }

/* ============================================================ */
/* LOADING OVERLAY                                              */
/* ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 20, 0.85);
  z-index: 300;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.loading-overlay.is-visible { display: flex; }

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================================ */
/* ANIMATIONS                                                   */
/* ============================================================ */
@keyframes screenIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* ============================================================ */
/* FOCUS                                                        */
/* ============================================================ */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================================ */
/* RESPONSIVE                                                   */
/* ============================================================ */
@media (max-width: 600px) {
  .sel-main { padding: 2rem 1.25rem 3rem; }
  .sel-heading { font-size: 1.625rem; }
  .ambitos-grid { grid-template-columns: 1fr; }
  .ambito-card { padding: 1.25rem; }
}

/* ============================================================ */
/* REDUCED MOTION                                               */
/* ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
