/*
 * ============================================================
 * GRANCARTA - PANEL DE CAJA
 * Sistema de diseño: Alerta operativa profesional
 *
 * Filosofía: tablet en bar con luces bajas. Necesita ser
 * legible a la distancia, con contrastes fuertes y urgencias
 * que llamen la atención sin ser molestas.
 *
 * Tipografías:
 *   - JetBrains Mono (cronómetros, números)
 *   - Inter (UI general)
 *
 * Color: oscuro con acentos ámbar (warm) + alertas
 * ============================================================
 */

/* ====================================================== */
/* CSS VARIABLES - Modo oscuro permanente                 */
/* ====================================================== */
:root {
  /* Fondo */
  --bg: #0A0E14;
  --bg-elevated: #131820;
  --bg-card: #1A2230;
  --bg-card-hover: #232C3D;

  /* Texto */
  --text: #F5F5F4;
  --text-soft: #B8B8B5;
  --text-muted: #6B7280;

  /* Acentos */
  --accent: #F59E0B;          /* ámbar - acción principal */
  --accent-soft: #422F16;
  --accent-glow: rgba(245, 158, 11, 0.3);

  /* Estados */
  --color-pending: #3B82F6;   /* azul - pendiente normal */
  --color-warning: #F59E0B;   /* ámbar - urgente */
  --color-urgent: #EF4444;    /* rojo - muy urgente */
  --color-success: #10B981;   /* verde - atendido */

  --color-pending-glow: rgba(59, 130, 246, 0.15);
  --color-warning-glow: rgba(245, 158, 11, 0.20);
  --color-urgent-glow: rgba(239, 68, 68, 0.25);

  /* Bordes */
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);

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

  /* Radii */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;

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

/* ====================================================== */
/* RESET Y 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.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  overflow-x: hidden;
}

input, button {
  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;
}

/* ====================================================== */
/* PANTALLA: LOGIN                                        */
/* ====================================================== */
.screen-login {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top, rgba(245, 158, 11, 0.08) 0%, transparent 60%),
    var(--bg);
}

.screen-login.is-active {
  display: flex;
}

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

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

.login-logo {
  font-size: 3rem;
  margin-bottom: 1rem;
  animation: pulse 2s ease-in-out infinite;
}

.login-title {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.03em;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9375rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

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

.login-input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-family: var(--font-ui);
  font-size: 1.0625rem;
  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: border-color 0.2s var(--ease-out), background 0.2s var(--ease-out);
}

.login-input:focus {
  border-color: var(--accent);
  background: var(--bg-card);
}

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

.login-btn {
  padding: 1.125rem 1.25rem;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 1rem;
  background: var(--accent);
  color: #0A0E14;
  border-radius: var(--r-md);
  letter-spacing: 0.01em;
  transition: transform 0.15s var(--ease-out),
              box-shadow 0.15s var(--ease-out),
              background 0.15s var(--ease-out);
}

.login-btn:hover {
  background: #FCD34D;
  box-shadow: 0 0 24px var(--accent-glow);
}

.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.875rem;
  text-align: center;
  padding-top: 0.5rem;
}

.login-status.is-error {
  color: var(--color-urgent);
}

.login-status.is-success {
  color: var(--color-success);
}

.login-back {
  margin-top: 1.5rem;
  font-size: 0.875rem;
  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-muted);
  font-size: 0.75rem;
}

/* ====================================================== */
/* PANTALLA: SELECCIÓN DE LOCAL                           */
/* ====================================================== */
#screen-select-local.is-active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.select-container {
  width: 100%;
  max-width: 600px;
}

.select-header {
  text-align: center;
  margin-bottom: 2rem;
}

.select-title {
  font-size: 1.625rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.select-subtitle {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.locales-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 600px) {
  .locales-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.local-card {
  padding: 1.5rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-lg);
  text-align: left;
  transition: all 0.2s var(--ease-out);
}

.local-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.local-card-name {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.local-card-address {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ====================================================== */
/* PANTALLA PRINCIPAL: PANEL OPERATIVO                    */
/* ====================================================== */
#screen-panel.is-active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.panel-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;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.panel-header-left {
  flex: 1;
  min-width: 0;
}

.panel-local-name {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-local-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.panel-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.meta-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-urgent);
  display: inline-block;
}

.meta-dot-online {
  background: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
}

.panel-header-right {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: background 0.15s var(--ease-out);
}

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

.btn-icon:active {
  transform: scale(0.95);
}

/* ====================================================== */
/* MAIN: LISTA DE EVENTOS                                 */
/* ====================================================== */
.panel-main {
  flex: 1;
  padding: 1rem 1.5rem 2rem;
  position: relative;
}

.eventos-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* ====================================================== */
/* CARD DE EVENTO                                         */
/* ====================================================== */
.evento-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.25rem;
  align-items: center;
  padding: 1.25rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-lg);
  transition: all 0.3s var(--ease-out);
  position: relative;
  overflow: hidden;
  animation: slideIn 0.4s var(--ease-out);
}

/* Estados visuales por urgencia */
.evento-card.is-urgent {
  border-color: var(--color-warning);
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--color-warning-glow) 100%);
}

.evento-card.is-very-urgent {
  border-color: var(--color-urgent);
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--color-urgent-glow) 100%);
  animation: pulseUrgent 1.5s ease-in-out infinite;
}

.evento-card.is-attended {
  opacity: 0.4;
  filter: grayscale(0.7);
  animation: fadeOut 0.5s var(--ease-out) forwards;
  animation-delay: 1s;
}

/* Indicador de mesa (lateral izquierdo grande) */
.evento-mesa {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-md);
  flex-shrink: 0;
}

.evento-mesa-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.evento-mesa-num {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-top: 0.125rem;
}

/* Contenido central */
.evento-content {
  min-width: 0;
}

.evento-tipo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.evento-icono {
  font-size: 1.5rem;
}

.evento-etiqueta {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
}

.evento-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.evento-tiempo {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

.evento-id {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.evento-tag-urgent {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  background: var(--color-urgent);
  color: white;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 100px;
}

/* Botón de atender (derecha) */
.evento-action {
  display: flex;
  align-items: center;
}

.btn-atender {
  padding: 1rem 1.75rem;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.9375rem;
  background: var(--color-success);
  color: white;
  border-radius: var(--r-md);
  letter-spacing: 0.02em;
  white-space: nowrap;
  transition: all 0.15s var(--ease-out);
  box-shadow: 0 0 0 var(--color-success);
}

.btn-atender:hover {
  background: #34D399;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.4);
}

.btn-atender:active {
  transform: scale(0.97);
}

.btn-atender:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ====================================================== */
/* EMPTY STATE                                            */
/* ====================================================== */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  text-align: center;
  min-height: 400px;
}

.empty-state.is-visible {
  display: flex;
}

.empty-icon {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 0.5rem;
}

.empty-detail {
  color: var(--text-muted);
  font-size: 0.9375rem;
}

/* ====================================================== */
/* FOOTER                                                 */
/* ====================================================== */
.panel-footer {
  padding: 1rem 1.5rem calc(1rem + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  margin-top: auto;
}

.footer-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.footer-stats code {
  background: var(--bg-card);
  padding: 0.125rem 0.4rem;
  border-radius: var(--r-sm);
}

/* ====================================================== */
/* 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(--accent);
  color: var(--text);
  padding: 0.875rem 1.5rem;
  border-radius: 100px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  transition: transform 0.4s var(--ease-out);
  white-space: nowrap;
  max-width: calc(100vw - 2rem);
}

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

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

.toast.is-success {
  border-color: var(--color-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);
}

.loading-overlay.is-visible {
  display: flex;
}

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

/* ====================================================== */
/* ANIMACIONES                                            */
/* ====================================================== */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.95); }
}

@keyframes pulseUrgent {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
}

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

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(8px);
    height: 0;
    margin: 0;
    padding: 0;
  }
}

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

/* ====================================================== */
/* RESPONSIVE                                             */
/* ====================================================== */
@media (max-width: 600px) {
  .evento-card {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .evento-mesa {
    width: 100%;
    height: 60px;
    flex-direction: row;
    justify-content: center;
    gap: 0.5rem;
  }

  .evento-mesa-num {
    font-size: 1.5rem;
  }

  .evento-action {
    width: 100%;
  }

  .btn-atender {
    width: 100%;
  }
}

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

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