/* Common header styles for all portal pages */
:root {
  --portal-header-offset: 58px;
}

#portal-content {
  padding-top: var(--portal-header-offset);
}

/* Estándar del portal: header gris claro (antes requería la clase .header-gray) */
.header {
  background: #d9dde4;
  min-height: 52px;
  padding: 5px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--navy);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 120;
  box-sizing: border-box;
  box-shadow: 0 2px 8px rgba(16, 32, 57, 0.08);
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid #d9dde4;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  overflow: visible;
}

.header-inner,
.header-row {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  gap: 10px;
  flex: 1 1 100%;
}

.header-top-end,
.header-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

/* Páginas sin .header-inner: empujar UF y cerrar sesión a la derecha */
.header > .header-actions {
  margin-left: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 120;
}

/* Styles for the brand/logo area */
.header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 1 280px;
  min-width: 0;
  max-width: min(28vw, 320px);
}

.header .brand-text {
  min-width: 0;
  overflow: hidden;
}

.header .brand-text h2,
.header .brand h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header .brand-text .header-sub,
.header .brand .header-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header .header-logo {
  height: 44px;
  width: auto;
  flex: 0 0 auto;
}

.header h2 {
  font-family: 'Playfair Display', serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin: 0;
  color: var(--navy);
}

.header-sub {
  color: var(--navy);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* UF y acciones derecha (fila superior) */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-left: 0;
}

/* Iconos de header: calendario (reuniones) + campana (sistema admin) */
.portal-agenda-alert,
.portal-system-alert {
  flex: 0 0 auto;
  max-width: min(34vw, 320px);
}

.portal-agenda-alert.hidden {
  display: none !important;
}

.portal-agenda-alert-wrap {
  position: relative;
}

.portal-agenda-alert-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e3a5f;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 9px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
  min-width: 36px;
  min-height: 32px;
}

.portal-agenda-alert-pill.has-today {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.portal-agenda-alert-pill.has-soon {
  border-color: #ef4444;
  background: #fef2f2;
  color: #991b1b;
}

.portal-agenda-calendar {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E") center / contain no-repeat;
}

.portal-agenda-notif-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  flex-shrink: 0;
}

.portal-agenda-alert-pill.has-soon .portal-agenda-notif-dot {
  background: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
}

.portal-agenda-kommo-badge {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.9;
}

.portal-agenda-kommo-badge.hidden {
  display: none;
}

.portal-agenda-kommo-badge.loading {
  color: #64748b;
}

.portal-agenda-kommo-badge.ready {
  color: #166534;
}

.portal-agenda-alert-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10080;
  width: min(400px, 92vw);
  max-height: min(70vh, 520px);
  overflow: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
  z-index: 10060;
  text-align: left;
}

.portal-agenda-alert-panel.hidden {
  display: none;
}

.portal-agenda-alert-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}

.portal-agenda-alert-panel-head .muted {
  font-size: 11px;
  color: #64748b;
  flex: 1 1 100%;
}

.portal-agenda-alert-close {
  margin-left: auto;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
}

.portal-agenda-alert-panel-body {
  padding: 10px 14px 14px;
}

.portal-agenda-alert-intro {
  margin: 0 0 10px;
  font-size: 12px;
  color: #475569;
  line-height: 1.4;
}

.portal-agenda-alert-empty {
  margin: 8px 0;
  font-size: 13px;
}

.portal-agenda-alert-item-titulo {
  font-weight: 700;
  font-size: 13px;
  color: var(--navy);
  line-height: 1.35;
  margin-bottom: 4px;
}

.portal-agenda-alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.portal-agenda-alert-item {
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.portal-agenda-alert-item:last-child {
  border-bottom: none;
}

.portal-agenda-alert-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.portal-agenda-alert-hora {
  font-weight: 700;
  font-size: 14px;
  color: var(--navy);
}

.portal-agenda-alert-tipo {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
}

.portal-agenda-alert-tipo.llamada {
  background: #dcfce7;
  color: #166534;
}

.portal-agenda-alert-nombre {
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}

.portal-agenda-alert-meta {
  font-size: 12px;
  color: #64748b;
}

.portal-agenda-alert-resp {
  font-size: 11px;
  margin-top: 4px;
  font-weight: 600;
}

.portal-agenda-alert-resp.aceptada { color: #166534; }
.portal-agenda-alert-resp.pendiente { color: #92400e; }
.portal-agenda-alert-resp.rechazada { color: #991b1b; }

.portal-agenda-alert-kommo {
  margin-top: 8px;
  font-size: 12px;
  color: #334155;
}

.portal-agenda-alert-kommo ul {
  margin: 6px 0 0;
  padding-left: 16px;
}

.portal-agenda-alert-kommo .kommo-fecha {
  color: #64748b;
  font-size: 11px;
}

.portal-agenda-alert-foot {
  margin-top: 12px;
  font-size: 12px;
}

.portal-agenda-alert-foot a {
  color: #1d4ed8;
}

.portal-agenda-alert-kommo-load {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 8px;
}

/* Campana de sistema (admin): dispositivos pendientes, etc. */
.portal-system-alert.hidden {
  display: none !important;
}

.portal-system-alert-wrap {
  position: relative;
}

.portal-system-alert-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e3a5f;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 9px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1;
  min-width: 36px;
  min-height: 32px;
}

.portal-system-alert-pill.has-pending {
  border-color: #7c3aed;
  background: #f5f3ff;
  color: #5b21b6;
}

.portal-system-bell {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9'/%3E%3Cpath d='M13.73 21a2 2 0 0 1-3.46 0'/%3E%3C/svg%3E") center / contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9'/%3E%3Cpath d='M13.73 21a2 2 0 0 1-3.46 0'/%3E%3C/svg%3E") center / contain no-repeat;
}

.portal-system-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #7c3aed;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.portal-system-alert-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10081;
  width: min(380px, 92vw);
  max-height: min(60vh, 420px);
  overflow: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.portal-system-alert-panel.hidden {
  display: none !important;
}

.portal-system-alert-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.portal-system-alert-panel-head .muted {
  font-size: 12px;
  font-weight: 500;
  margin-left: auto;
}

.portal-system-alert-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 0 4px;
}

.portal-system-alert-panel-body {
  padding: 12px 14px 14px;
}

.portal-system-alert-intro {
  font-size: 12px;
  color: #475569;
  margin: 0 0 10px;
  line-height: 1.45;
}

.portal-system-alert-empty {
  margin: 0;
  font-size: 13px;
}

.portal-system-alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.portal-system-alert-item {
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.portal-system-alert-item:last-child {
  border-bottom: none;
}

.portal-system-alert-item-title {
  font-weight: 600;
  font-size: 13px;
  color: #1e293b;
}

.portal-system-alert-meta {
  font-size: 12px;
  color: #64748b;
  margin-top: 2px;
}

.portal-system-alert-foot {
  margin-top: 12px;
  font-size: 12px;
}

.portal-system-alert-foot a {
  color: #6d28d9;
  font-weight: 600;
}

/* Indicador de salud del portal (Fase 1) — .user-info */
.portal-health-mount {
  display: inline-flex;
  align-items: center;
  margin-right: 10px;
  vertical-align: middle;
}

.portal-health-wrap {
  position: relative;
}

.portal-health-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e3a5f;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.2;
  max-width: min(160px, 28vw);
}

.portal-health-pill.level-ok {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.portal-health-pill.level-warn {
  border-color: #fdba74;
  background: #fff7ed;
  color: #9a3412;
}

.portal-health-pill.level-error {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #991b1b;
}

.portal-health-pill.level-checking,
.portal-health-pill.level-unknown {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #64748b;
}

.portal-health-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #94a3b8;
}

.level-ok .portal-health-led { background: #22c55e; }
.level-warn .portal-health-led { background: #f97316; }
.level-error .portal-health-led { background: #ef4444; }
.level-checking .portal-health-led,
.level-unknown .portal-health-led {
  background: #94a3b8;
  animation: portal-health-pulse 1.2s ease-in-out infinite;
}

@keyframes portal-health-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.portal-health-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.portal-health-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10082;
  width: min(360px, 92vw);
  max-height: min(65vh, 440px);
  overflow: auto;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}

.portal-health-panel.hidden {
  display: none !important;
}

.portal-health-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.portal-health-panel-head .muted {
  font-size: 12px;
  font-weight: 500;
  margin-left: auto;
}

.portal-health-close {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 0 4px;
}

.portal-health-panel-body {
  padding: 12px 14px 14px;
}

.portal-health-intro {
  margin: 0 0 10px;
  font-size: 12px;
  color: #64748b;
}

.portal-health-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.portal-health-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid #f1f5f9;
}

.portal-health-item:last-child {
  border-bottom: none;
}

.portal-health-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
  background: #94a3b8;
}

.portal-health-dot.is-ok { background: #22c55e; }
.portal-health-dot.is-warn { background: #f97316; }
.portal-health-dot.is-error { background: #ef4444; }
.portal-health-dot.is-skipped { background: #cbd5e1; }
.portal-health-dot.is-pending { background: #94a3b8; }

.portal-health-item-title {
  font-size: 13px;
  font-weight: 600;
  color: #1e293b;
}

.portal-health-item-msg {
  font-size: 12px;
  color: #475569;
  margin-top: 2px;
}

.portal-health-item-meta {
  font-size: 11px;
  margin-top: 2px;
}

.portal-health-empty {
  margin: 0;
  font-size: 12px;
}

.portal-health-rol {
  margin: 10px 0 0;
  font-size: 11px;
}

.portal-health-foot {
  margin: 12px 0 0;
  font-size: 12px;
}

.portal-health-refresh-btn {
  border: none;
  background: none;
  padding: 0;
  color: #1d4ed8;
  font-weight: 600;
  cursor: pointer;
  font-size: 12px;
}

.portal-health-foot a {
  color: #1d4ed8;
  font-weight: 600;
}

.portal-health-foot-admin {
  margin: 0 0 8px;
  font-size: 12px;
}

.portal-health-foot-admin a {
  color: #6d28d9;
  font-weight: 600;
}

@media (max-width: 720px) {
  .portal-health-label {
    display: none;
  }
  .portal-health-pill {
    padding: 7px 9px;
    max-width: none;
  }
}

.header-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  gap: 6px;
  position: static;
  left: auto;
  transform: none;
  white-space: nowrap;
  min-width: 0;
  overflow: visible;
  padding: 0 4px;
}

.header-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.header-menu-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 8px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}

.header-menu-toggle:hover,
.header-dropdown:focus-within .header-menu-toggle {
  background: rgba(26, 39, 68, 0.08);
}

.header-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  background: #fffdf7;
  border: 1px solid rgba(26, 39, 68, 0.16);
  box-shadow: 0 12px 28px rgba(16, 32, 57, 0.12);
  padding: 8px;
  display: none;
  z-index: 10070;
}

.header-dropdown:hover .header-dropdown-menu,
.header-dropdown:focus-within .header-dropdown-menu {
  display: grid;
  gap: 4px;
}

.header-dropdown-menu a {
  display: block;
  text-decoration: none;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  padding: 9px 10px;
  border-radius: 8px;
}

.header-dropdown-menu a:hover {
  background: rgba(201, 168, 76, 0.14);
}

.header-dropdown-menu hr.header-menu-divider {
  border: none;
  border-top: 1px solid rgba(26, 39, 68, 0.14);
  margin: 6px 4px;
  padding: 0;
  height: 0;
  width: auto;
}

.header-menu-subsection {
  display: contents;
}

.header-menu-group-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(26, 39, 68, 0.55);
  padding: 4px 10px 2px;
}

.header-dropdown-menu a:focus-visible,
.header-menu a:focus-visible,
.header-menu-toggle:focus-visible,
.header .header-back-link:focus-visible,
.header #logoutButton:focus-visible {
  outline: 2px solid rgba(26, 39, 68, 0.3);
  outline-offset: 2px;
}

.header-menu a {
  text-decoration: none;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 8px;
  border-radius: 999px;
}

.header-menu a:hover {
  background: rgba(26, 39, 68, 0.08);
}
.pill {
  border: 1px solid rgba(255,255,255,.18);
  color: #dce6f2;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255,255,255,.06);
}
.pill.gold { /* Specific pill style, can remain */
  background: var(--gold);
  color: var(--navy);
  border-color: var(--gold);
}

.header .header-back-link {
  color: var(--navy);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid rgba(26, 39, 68, 0.22);
  padding: 10px 14px;
  line-height: 1;
}

.header .header-back-link:hover {
  background: rgba(26, 39, 68, 0.08);
}

.header #ufValue {
  min-width: 120px;
  padding: 6px 10px;
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* User info styles, now global */
.header .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  text-align: right;
  flex: 0 0 auto;
  margin-left: 0;
  flex-wrap: nowrap;
}

.header + main {
  margin-top: 0;
}

.header #logoutButton {
  background: none !important;
  border: none !important;
  color: var(--navy);
  cursor: pointer;
  font-weight: 500;
  font-size: 12px;
  text-transform: none; /* Asegurar que no esté en mayúsculas */
  text-decoration: underline;
  letter-spacing: 0.2px;
  line-height: 1.2;
  padding: 0 !important;
  margin: 0;
  border-radius: 0 !important;
}

/* Portal clásico: conserva compatibilidad sin diferenciar visualmente el header. */
body.portal-classic .header-badge-classic {
  display: none;
}

body.portal-classic .portal-agenda-alert,
body.portal-classic .portal-system-alert {
  filter: none;
}

/* Variante opcional: header azul navy (páginas legacy o CSS de página que lo requieran) */
.header-navy,
.header.header-navy {
  background: var(--navy);
  border-bottom-color: rgba(26, 39, 68, 0.18);
  color: var(--white);
}

.header-navy h2,
.header.header-navy .header-sub,
.header.header-navy .header-menu a,
.header.header-navy .header-menu-toggle,
.header.header-navy .header-back-link,
.header.header-navy #logoutButton {
  color: var(--white);
}

.header.header-navy .header-sub {
  color: var(--gold);
}

.header.header-navy .header-menu a:hover,
.header.header-navy .header-menu-toggle:hover,
.header.header-navy .header-dropdown:focus-within .header-menu-toggle,
.header.header-navy .header-back-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Estilo para el loader sobre el header */
.header-loader {
  position: fixed;
  top: 8px; /* Ajusta la posición vertical */
  left: 50%;
  transform: translateX(-50%);
  background: #fffbe7;
  color: #1a2a4a;
  padding: 8px 16px;
  border-radius: 7px;
  border: 1px solid #e0d7b8;
  z-index: 130; /* Asegura que esté sobre el header */
}

@media (max-width: 1100px) {
  .portal-agenda-alert-pill {
    padding: 6px 8px;
    min-width: 32px;
    min-height: 28px;
  }

  .header-menu a,
  .header-menu-toggle {
    font-size: 11px;
    padding: 4px 6px;
  }
}

@media (max-width: 768px) {
  :root {
    --portal-header-offset: 50px;
  }

  .header {
    min-height: 44px;
    padding: 5px 10px;
  }

  .header-menu {
    display: none;
  }

  .header .brand {
    gap: 10px;
    flex: 1 1 auto;
    max-width: none;
  }

  .header .header-logo {
    height: 36px;
  }

  .header #ufValue {
    min-width: 96px;
    font-size: 11px;
  }
}