:root {
  --primary: #0e8dd0;
  --primary-dark: #0039aa;
  --primary-light: #e0f2fe;
  --bg-gradient: linear-gradient(135deg, #0039aa 0%, #0e8dd0 100%);
  --bg-app: #f8fafc;
  --surface: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Banner de conectividad */
#network-banner {
  display: none;
  padding: 8px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  transition: all 0.3s ease;
}

#network-banner.offline {
  display: block;
  background-color: #ef4444;
  color: #ffffff;
}

#network-banner.online {
  display: block;
  background-color: #10b981;
  color: #ffffff;
}

/* Toast de notificaciones */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  left: 20px;
  max-width: 400px;
  margin: 0 auto;
  z-index: 2000020 !important;
  pointer-events: none;
}

.toast {
  background: white;
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  animation: slideDown 0.3s ease-out;
  border-left: 4px solid var(--primary);
  pointer-events: auto;
}

.toast.error { border-left-color: var(--danger); color: #991b1b; }
.toast.success { border-left-color: var(--success); color: #065f46; }
.toast.warning { border-left-color: var(--warning); color: #92400e; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Contenedor principal de pantallas */
.app-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

/* ============================================================
   PANTALLA DE LOGIN
   ============================================================ */
.login-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
  background: radial-gradient(circle at top right, #e0f2fe 0%, #f8fafc 60%);
}


/* Alerta visual en Login */
.login-alert-error {
  display: none;
  background-color: #fef2f2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  border-left: 5px solid #ef4444;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 20px;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 4px rgba(239, 68, 68, 0.12);
  animation: slideDown 0.25s ease-out;
}

.login-alert-error .login-error-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  padding: 36px 28px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(226, 232, 240, 0.8);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: var(--bg-gradient);
}

.login-header {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo {
  max-width: 220px;
  height: auto;
  margin-bottom: 18px;
  display: inline-block;
}

.login-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.login-header p {
  font-size: 13px;
  color: var(--text-muted);
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 6px;
}

.input-container {
  position: relative;
  display: flex;
  align-items: center;
}

.input-container .input-icon {
  position: absolute;
  left: 14px;
  color: #94a3b8;
  font-size: 16px;
  pointer-events: none;
}

.form-control {
  width: 100%;
  padding: 13px 14px 13px 42px;
  background-color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  color: var(--text-main);
  transition: all 0.2s ease;
  outline: none;
}

.form-control:focus {
  background-color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 141, 208, 0.15);
}

.toggle-password-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 6px;
  font-size: 16px;
  border-radius: 6px;
}

.toggle-password-btn:hover {
  color: var(--primary);
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  font-size: 13px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  padding: 14px 20px;
  background: var(--bg-gradient);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 12px rgba(14, 141, 208, 0.25);
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.95;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(14, 141, 208, 0.35);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Spinner animado */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

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

.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: #94a3b8;
}

/* ============================================================
   PANTALLA DE DASHBOARD (POST-LOGIN)
   ============================================================ */
.dashboard-wrapper {
  padding-bottom: 70px; /* espacio para bottom nav en móviles */
}

/* Top Navigation Bar */
.top-navbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-brand img {
  height: 32px;
  width: auto;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  text-align: right;
  line-height: 1.2;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  display: block;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-logout {
  background: #f1f5f9;
  border: 1px solid var(--border);
  color: #475569;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-logout:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

/* Banner de instalación PWA */
.install-banner {
  background: linear-gradient(135deg, #0284c7 0%, #0e8dd0 100%);
  color: white;
  padding: 14px 18px;
  margin: 14px;
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  animation: slideDown 0.3s ease;
}

.install-text {
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}

.install-actions {
  display: flex;
  gap: 8px;
}

.btn-install {
  background: white;
  color: var(--primary);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-install-close {
  background: transparent;
  color: white;
  border: none;
  padding: 6px;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.8;
}

/* Contenido Principal Dashboard */
.main-content {
  padding: 18px 16px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.welcome-card {
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.welcome-card::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -20px;
  width: 100px;
  height: 100px;
  background: rgba(14, 141, 208, 0.05);
  border-radius: 50%;
}

.welcome-info h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-main);
}

.welcome-info p {
  font-size: 13px;
  color: var(--text-muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #ecfdf5;
  color: #065f46;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

/* Grid de Módulos Operativos */
.section-title {
  font-size: 15px;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0;
}

.modules-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.btn-refresh {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-refresh:hover {
  background: var(--bg-body);
  border-color: var(--primary);
  transform: rotate(45deg);
}

.modules-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  width: 100%;
}

.modules-loading {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px;
  background: white;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
}

.modules-empty {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 32px 16px;
  background: white;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.modules-empty p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.modules-empty small {
  font-size: 12px;
  color: var(--text-muted);
}

/* Tarjeta rectangular apilada verticalmente */
.module-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  text-align: left;
  text-decoration: none;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 16px;
  width: 100%;
  position: relative;
}

.module-card:hover, .module-card:active {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  background: #fbfdff;
}

.module-icon {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: var(--primary-light);
  color: var(--primary);
}

.module-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.module-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
  line-height: 1.2;
}

.module-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

.module-arrow {
  color: var(--text-muted);
  font-size: 18px;
  opacity: 0.6;
  margin-left: 4px;
}

/* Bottom Navigation Bar para Móviles */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 99;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #64748b;
  text-decoration: none;
  cursor: pointer;
  padding: 6px;
  flex: 1;
  min-width: 0;
}

.bottom-nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

.bottom-nav-item .nav-icon {
  font-size: 18px;
}

/* ============================================================
   3. MÓDULO DE IA (AURELIO VOICE & AGENT) - COPIADO DE APP.MESANA.CL
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap');

.view-asistente-wrapper {
  max-width: 500px;
  margin: 0 auto;
  padding: 16px;
  text-align: center;
  padding-bottom: 80px;
}

.asistente-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.asistente-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.btn-back {
  background-color: #64748b;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.2s;
}

.btn-back:hover {
  background-color: #475569;
}

.asistente-greeting {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 15px;
}

/* Tarjeta Contenedora del Agente IA */
.ia-agent-card {
  background: linear-gradient(145deg, #0d0f1b, #171b30);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 20px;
  padding: 24px 18px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35), inset 0 0 20px rgba(0, 240, 255, 0.05);
  margin: 10px auto;
  max-width: 480px;
  color: #ffffff;
  font-family: 'Outfit', sans-serif;
}

.ia-voice-container {
  position: relative;
  margin: 15px auto 20px auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Orbe Base */
.voice-orb {
  width: 85px;
  height: 85px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 10%, #1a1a2e 90%);
  box-shadow:
    0 0 25px 6px rgba(0, 240, 255, 0.45),
    0 0 45px 12px rgba(208, 0, 255, 0.35),
    inset 0 0 12px rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: all 0.4s ease;
  position: relative;
}

.voice-orb:hover {
  transform: scale(1.08);
  box-shadow:
    0 0 35px 10px rgba(0, 240, 255, 0.6),
    0 0 55px 15px rgba(208, 0, 255, 0.5);
}

/* Estados y Animaciones del Orbe */
@keyframes orb-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 20px 5px rgba(0, 240, 255, 0.4), 0 0 40px 10px rgba(208, 0, 255, 0.3);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 30px 10px rgba(0, 240, 255, 0.5), 0 0 60px 15px rgba(208, 0, 255, 0.4);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 20px 5px rgba(0, 240, 255, 0.4), 0 0 40px 10px rgba(208, 0, 255, 0.3);
  }
}

@keyframes orb-listening {
  0% {
    transform: scale(1.05);
    box-shadow: 0 0 25px 8px rgba(0, 240, 255, 0.7), 0 0 50px 12px rgba(208, 0, 255, 0.2);
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 35px 12px rgba(0, 240, 255, 0.9), 0 0 70px 20px rgba(208, 0, 255, 0.4);
  }
  100% {
    transform: scale(1.05);
    box-shadow: 0 0 25px 8px rgba(0, 240, 255, 0.7), 0 0 50px 12px rgba(208, 0, 255, 0.2);
  }
}

@keyframes orb-thinking {
  0% {
    transform: rotate(0deg) scale(1.05);
    border-radius: 45% 55% 50% 50% / 50% 50% 50% 50%;
  }
  50% {
    border-radius: 55% 45% 50% 50% / 50% 50% 50% 50%;
  }
  100% {
    transform: rotate(360deg) scale(1.05);
    border-radius: 45% 55% 50% 50% / 50% 50% 50% 50%;
  }
}

.voice-orb.idle {
  animation: orb-pulse 3s infinite ease-in-out;
}

.voice-orb.listening {
  animation: orb-listening 1.2s infinite ease-in-out;
  background: radial-gradient(circle, #00f0ff 10%, #0d0f1b 90%);
}

.voice-orb.thinking {
  animation: orb-thinking 2s infinite linear;
  background: linear-gradient(45deg, #00f0ff, #d000ff);
  box-shadow: 0 0 35px 12px rgba(208, 0, 255, 0.6);
}

/* Etiqueta de Estado */
.voice-status {
  margin-top: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #00f0ff;
  background: rgba(13, 15, 27, 0.85);
  backdrop-filter: blur(8px);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.voice-status.listening {
  color: #ff3333;
  border-color: rgba(255, 51, 51, 0.3);
}

.voice-status.thinking {
  color: #d000ff;
}

/* Badge de Métricas Móvil */
.voice-metrics {
  margin-top: 6px;
  font-size: 0.70rem;
  font-weight: 600;
  color: #00f0ff;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 240, 255, 0.4);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
  pointer-events: auto;
}

.voice-metrics:active {
  transform: scale(0.93);
  background: rgba(0, 240, 255, 0.2);
}

/* Caja de Chat / Respuesta */
.ia-chat-box {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 15px;
  text-align: left;
  min-height: 70px;
}

.ia-query-text {
  font-size: 0.80rem;
  color: #00f0ff;
  font-weight: 600;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ia-response-text {
  font-size: 0.90rem;
  line-height: 1.45;
  color: #e6edf8;
  font-style: italic;
}

/* Grupo de Entrada de Texto */
.ia-input-group {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.ia-text-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 10px;
  padding: 10px 14px;
  color: #ffffff;
  font-size: 0.88rem;
  outline: none;
  transition: all 0.3s;
}

.ia-text-input:focus {
  border-color: #00f0ff;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.3);
}

.ia-send-btn {
  width: auto !important;
  margin: 0 !important;
  background: linear-gradient(135deg, #00f0ff, #7928ca) !important;
  color: #ffffff !important;
  font-weight: 600;
  border: none !important;
  border-radius: 10px !important;
  padding: 10px 18px !important;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Modal de Métricas Móvil */
.metrics-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}

.metrics-modal.hidden {
  display: none !important;
}

.metrics-modal-content {
  background: #121526;
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  max-height: 85vh;
  overflow-y: auto;
  color: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  font-family: 'Outfit', sans-serif;
  padding: 18px;
}

.metrics-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 10px;
  margin-bottom: 15px;
}

.metrics-modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: #00f0ff;
}

.metrics-modal-close {
  background: transparent;
  border: none;
  color: #aaaaaa;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0 5px;
  line-height: 1;
}

.metric-card {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.metric-card.highlight {
  background: rgba(0, 240, 255, 0.1);
  border-color: rgba(0, 240, 255, 0.3);
  text-align: center;
}

.metric-card.highlight .metric-value {
  font-size: 1.6rem;
  color: #00f0ff;
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-label {
  display: block;
  font-size: 0.72rem;
  color: #aaaaaa;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: #ffffff;
}

.metric-query-text {
  font-size: 0.85rem;
  color: #e0e0e0;
  font-style: italic;
  word-break: break-word;
}

.metric-history {
  margin-top: 15px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 10px;
}

.metric-history h4 {
  margin: 0 0 8px 0;
  font-size: 0.85rem;
  color: #d000ff;
}

.metric-history ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.78rem;
}

.metric-history li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
}

.metric-history li.empty {
  color: #777777;
  text-align: center;
  font-style: italic;
  justify-content: center;
}

/* ============================================================
   4. VISOR DE MÓDULOS IN-APP (PWA INTERNAL FRAME)
   ============================================================ */
.module-frame-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}

.module-frame-header {
  height: 54px;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.module-frame-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-frame-nav {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-frame-nav:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.module-frame-body {
  flex: 1;
  position: relative;
  width: 100%;
  height: calc(100% - 54px);
  overflow: hidden;
  background: white;
}

.module-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.frame-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
}

/* ============================================================
   ESTILOS NATIVOS: MÓDULO TRABAJOS ASIGNADOS (PWA)
   ============================================================ */

.view-trabajos-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 80px;
  background: var(--bg-app);
}

.trabajos-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.trabajos-header h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.btn-refresh-trabajos {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-refresh-trabajos:active {
  transform: scale(0.92);
  background: var(--primary-light);
}

/* KPIs de resumen */
.trabajos-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px 16px 8px 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 8px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.kpi-card:hover, .kpi-card.active {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
}

.kpi-num {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.1;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Toolbar: Barra de búsqueda y chips */
.trabajos-toolbar {
  padding: 6px 16px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-box {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  outline: none;
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 141, 208, 0.15);
}

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.chip.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(14, 141, 208, 0.25);
}

/* Lista y Tarjetas */
.trabajos-content {
  padding: 0 16px 20px 16px;
}

.trabajos-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.trabajos-loading, .trabajos-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

.trabajos-empty h4 {
  margin: 10px 0 4px 0;
  color: var(--text-main);
  font-size: 16px;
}

.trabajos-empty p {
  font-size: 13px;
  margin: 0;
}

.trabajo-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: all 0.2s ease;
}

.trabajo-card:hover {
  box-shadow: var(--shadow-md);
}

.trabajo-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}

.trabajo-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ot-badge {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary-dark);
}

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}

.badge-asignado {
  background: #dbeafe;
  color: #1e40af;
}

.badge-proceso {
  background: #fef3c7;
  color: #92400e;
}

.badge-terminado {
  background: #dcfce7;
  color: #166534;
}

.trabajo-date {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.trabajo-card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edificio-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.servicio-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 3px 8px;
  border-radius: 6px;
}

.trabajo-meta {
  font-size: 13px;
  color: var(--text-main);
  line-height: 1.4;
  margin: 0;
}

.meta-empty {
  color: var(--text-muted);
  font-style: italic;
}

/* Botones de acción rápida: GPS y Teléfono */
.trabajo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.btn-geo {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-maps {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

.btn-waze {
  background: #eef2ff;
  color: #4338ca;
  border-color: #c7d2fe;
}

.btn-call {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}

.btn-wa {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

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

/* Lista de tareas */
.trabajo-tareas {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-top: 4px;
}

.trabajo-tareas ul {
  list-style: none;
  margin: 4px 0 0 0;
  padding: 0;
}

.trabajo-tareas li {
  line-height: 1.4;
  color: #334155;
  margin-bottom: 3px;
}

.tarea-periodo {
  font-size: 11px;
  color: var(--text-muted);
}

/* Observaciones / Notas de terreno */
.trabajo-obs {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  color: #78350f;
  margin-top: 4px;
}

.trabajo-obs p {
  margin: 3px 0 0 0;
  line-height: 1.4;
}

/* Footer de tarjeta */
.trabajo-card-footer {
  padding: 10px 14px;
  background: #fafafa;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-update-status {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-update-status:hover, .btn-update-status:active {
  background: var(--primary);
  color: #ffffff;
}

/* ============================================================
   ESTILOS NATIVOS: MÓDULO DE GASTOS (PWA - app.mesana.cl)
   ============================================================ */

.view-gastos-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-bottom: 85px;
  background: var(--bg-app);
}

.gastos-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.gastos-header-titles {
  text-align: center;
}

.gastos-header-titles h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.gastos-header-sub {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

.btn-refresh-gastos {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-refresh-gastos:active {
  transform: scale(0.92);
  background: var(--primary-light);
}

.gastos-scroll-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Tarjeta Formulario de Gastos */
.gastos-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group-gasto {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.label-gasto {
  font-size: 12px;
  font-weight: 700;
  color: #3b3a88;
}

.form-control-gasto {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 15px;
  background-color: #ffffff;
  color: var(--text-main);
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.form-control-gasto:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 141, 208, 0.15);
}

.select-gasto {
  appearance: auto;
}

.btn-foto-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  padding: 11px 16px;
  background-color: #198754;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  transition: background-color 0.2s;
  text-align: center;
}

.btn-foto-upload:hover, .btn-foto-upload:active {
  background-color: #146c43;
}

.foto-preview-container {
  text-align: center;
  margin-top: 10px;
  position: relative;
  display: block;
  width: 100%;
}

.foto-preview-container img,
#pwa-pago-foto-preview-img,
#pwa-gasto-foto-preview-img {
  max-width: 100%;
  max-height: 180px;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  object-fit: contain;
  background-color: #f8fafc;
  display: block;
  margin: 0 auto;
  transition: transform 0.2s ease;
}

.foto-preview-container img:active {
  transform: scale(0.98);
}

.btn-quitar-foto {
  display: block;
  margin: 6px auto 0 auto;
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.gasto-msg {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.error-msg {
  background-color: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.success-msg {
  background-color: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.btn-guardar-gasto {
  width: 100%;
  background: #3b3a88;
  color: #ffffff;
  border: none;
  padding: 13px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  box-shadow: 0 2px 4px rgba(59, 58, 136, 0.2);
}

.btn-guardar-gasto:hover {
  background: #2f2e6e;
}

.btn-guardar-gasto:active {
  transform: scale(0.98);
}

.btn-guardar-gasto:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Sección Historial de Gastos */
.gastos-historial-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.historial-title {
  color: #3b3a88;
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gastos-filtros-row {
  display: flex;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.select-filtro-gasto {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background-color: #ffffff;
  color: var(--text-main);
  box-sizing: border-box;
}

#pwa-filtro-mes {
  flex: 1.3;
}

#pwa-filtro-anio {
  flex: 1;
}

.mis-gastos-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gasto-card-item {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.gasto-card-item:active {
  transform: scale(0.99);
}

.btn-back-gastos-bottom {
  background: #64748b;
  color: #ffffff;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
  text-align: center;
}

.btn-back-gastos-bottom:active {
  background: #475569;
}

/* Lightbox Modal Adaptativo Móvil / Desktop */
.pwa-lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 2000005 !important;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 12px 10px;
  box-sizing: border-box;
  overflow: hidden;
}

.lightbox-header {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 4px 6px;
  z-index: 10001;
  flex-shrink: 0;
}

.lightbox-close {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  user-select: none;
  transition: all 0.2s ease;
  padding: 0;
}

.lightbox-close:hover, .lightbox-close:active {
  background: rgba(239, 68, 68, 0.85);
  border-color: #ef4444;
}

.lightbox-img-wrapper {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0;
}

#lightbox-img {
  max-width: 94vw;
  max-height: 72dvh;
  max-height: 72vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.7);
  transition: transform 0.25s ease-in-out;
  cursor: zoom-in;
  margin: auto;
  display: block;
}

#lightbox-img.zoomed {
  max-width: none;
  max-height: none;
  transform: scale(1.6);
  cursor: zoom-out;
}

.lightbox-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 6px;
  z-index: 10001;
  flex-shrink: 0;
}

#lightbox-caption {
  color: #f8fafc;
  font-size: 13px;
  text-align: center;
  padding: 6px 16px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  font-weight: 600;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-hint {
  font-size: 11px;
  color: #94a3b8;
  text-align: center;
}

/* Tarjetas de contenido y secciones en vistas móviles (Checklist / Mantenciones) */
.card-gasto {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

/* Garantizar que diálogos de confirmación SweetAlert2 siempre se muestren sobre cualquier modal */
.swal2-container {
  z-index: 2000010 !important;
}
