/* ==========================================================================
   ZeroChat Composer Omnibox - Entrada Flotante estilo ChatGPT & Gemini
   ========================================================================== */

.chat-input-wrapper {
  flex-shrink: 0;
  width: 100%;
  padding: 0.75rem 1rem max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  background: linear-gradient(180deg, rgba(var(--primary-rgb), 0) 0%, var(--bg-app) 28px);
  position: relative;
  z-index: 10;
}

/* Contenedor de chips de archivos adjuntos */
.attachments-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  max-width: var(--max-content-width, 68rem);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  box-shadow: var(--shadow-xs);
  animation: fadeIn 0.15s ease-out;
}

.file-chip-icon {
  color: var(--primary);
  display: flex;
  align-items: center;
}

.file-chip-name {
  font-weight: 500;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip-size {
  color: var(--text-muted);
  font-size: 0.725rem;
}

.file-chip-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  width: 16px;
  height: 16px;
  transition: all 0.15s ease;
}

.file-chip-remove:hover {
  background-color: var(--danger);
  color: white;
}

/* Formulario Omnibox Flotante */
.chat-input-container {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 1.25rem;
  padding: 0.6rem 0.75rem 0.55rem 0.75rem;
  box-shadow: var(--shadow-composer);
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
  max-width: var(--max-content-width, 68rem);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.chat-input-container:focus-within {
  border-color: var(--input-border-focus);
  box-shadow: var(--shadow-composer), 0 0 0 1px var(--input-border-focus);
}

.chat-input-container.drag-over {
  border-color: var(--primary);
  background-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

/* Fila Superior: Área de Prompt a ancho completo */
.composer-top-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  position: relative;
}

/* Fila Inferior: Barra de herramientas, estado y acciones */
.composer-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

.composer-controls-left {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.composer-actions-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

/* Controles compactos del composer */
.btn-composer-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  width: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 9px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
  height: 36px;
  user-select: none;
}

.btn-composer-chip > .ui-icon,
.btn-composer-icon-btn > .ui-icon {
  width: 20px;
  height: 20px;
}

.btn-composer-chip:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-hover, var(--primary));
}

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

.btn-composer-chip.active,
.btn-composer-chip.btn-rag-mini.active {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

.composer-visually-hidden,
.btn-reasoning .reasoning-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.btn-composer-chip:focus-visible,
.btn-composer-icon-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Botón de icono circular compacto (ej. adjuntar) */
.btn-composer-icon-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-composer-icon-btn:hover {
  background-color: var(--bg-hover);
  color: var(--primary);
}

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

/* Botón para Adjuntar Archivos */
.btn-attach {
  margin-bottom: 0;
}

/* Control de Nivel de Razonamiento */
.reasoning-control-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-bottom: 0;
}

.btn-reasoning {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-color);
  padding: 0;
  border-radius: 9px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  height: 36px;
  width: 36px;
  justify-content: center;
}

.reasoning-gauge {
  overflow: visible;
}

.reasoning-gauge path:first-child {
  opacity: 0.5;
}

.btn-reasoning:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--primary);
}

.btn-reasoning.active-on {
  border-color: #818cf8;
  background-color: #eef2ff;
  color: #4338ca;
}

.btn-reasoning.active-low {
  border-color: #86efac;
  background-color: #f0fdf4;
  color: #166534;
}

.btn-reasoning.active-medium {
  border-color: #86efac;
  background-color: #f0fdf4;
  color: #166534;
}

.btn-reasoning.active-high {
  border-color: #fde047;
  background-color: #fefce8;
  color: #854d0e;
}

.btn-reasoning.active-xhigh {
  border-color: #c084fc;
  background-color: #faf5ff;
  color: #6b21a8;
}

/* Menú desplegable de niveles de razonamiento */
.reasoning-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: var(--z-modal, 210);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 250px;
  max-width: 320px;
  overflow: hidden;
  /* Se abre con display:flex desde ui-reasoning.js. */
  flex-direction: column;
}

.reasoning-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.7rem 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-surface-subtle);
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-main);
}

.btn-reasoning-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-reasoning-close:hover {
  color: var(--text-main);
  background: var(--bg-hover);
  border-color: var(--border-color);
}

.btn-reasoning-close:focus-visible,
.reasoning-intensity-slider:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.reasoning-menu-title-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.reasoning-model-badge {
  flex: 0 1 auto;
  max-width: 112px;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reasoning-options {
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reasoning-intensity-control {
  padding: 1rem 1rem 0.85rem;
}

.reasoning-intensity-heading,
.reasoning-intensity-scale {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.reasoning-intensity-heading {
  margin-bottom: 0.85rem;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
}

.reasoning-intensity-heading output {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
}

.reasoning-intensity-slider {
  --reasoning-intensity: 0%;
  width: 100%;
  height: 8px;
  margin: 0;
  appearance: none;
  border-radius: var(--radius-full);
  background: linear-gradient(to right, var(--primary) 0 var(--reasoning-intensity), var(--border-color) var(--reasoning-intensity) 100%);
  cursor: pointer;
}

.reasoning-intensity-slider::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  appearance: none;
  border: 3px solid var(--bg-surface);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 1px 5px rgba(var(--primary-rgb), 0.4);
}

.reasoning-intensity-slider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border: 3px solid var(--bg-surface);
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 1px 5px rgba(var(--primary-rgb), 0.4);
}

.reasoning-intensity-scale {
  margin-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.68rem;
}

.reasoning-transport-heading {
  margin: 0.5rem 0 0.15rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.reasoning-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.825rem;
  color: var(--text-main);
  transition: background-color 0.12s ease, color 0.12s ease;
  width: 100%;
  text-align: left;
  outline: none;
  box-sizing: border-box;
}

.reasoning-option:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

.reasoning-option:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.reasoning-option.active {
  background-color: var(--bg-surface-subtle);
  color: var(--text-main);
  border: none;
}

.reasoning-option .option-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  width: 1.25rem;
  flex-shrink: 0;
  line-height: 1;
}

.reasoning-option .option-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  gap: 1px;
}

.reasoning-option .option-text strong,
.reasoning-option .option-text .option-title {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-main);
  line-height: 1.25;
}

.reasoning-option.active .option-text strong,
.reasoning-option.active .option-text .option-title {
  font-weight: 600;
  color: var(--primary);
}

.reasoning-option .option-text small,
.reasoning-option .option-text .option-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.25;
}

.reasoning-option .option-check {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: var(--primary);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
}

.reasoning-option.active .option-check {
  opacity: 1;
  visibility: visible;
}

.reasoning-option.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reasoning-option.recommended::after {
  content: "★";
  font-size: 0.75rem;
  color: #f59e0b;
}

.reasoning-menu-footer {
  padding: 0.5rem 0.85rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-surface-subtle);
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.reasoning-agent-toggle-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.reasoning-agent-toggle-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1 1 auto;
}

.reasoning-agent-toggle-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
}

.reasoning-agent-toggle-title svg {
  color: var(--primary);
  flex-shrink: 0;
}

.reasoning-agent-toggle-desc {
  font-size: 0.675rem;
  color: var(--text-muted);
  line-height: 1.25;
}

@media (max-width: 640px) {
  .reasoning-menu {
    min-width: min(290px, calc(100vw - 16px));
  }

  .reasoning-intensity-control {
    padding: 1rem;
  }
}

.chat-textarea,
.chat-textarea:focus,
.chat-textarea:focus-visible {
  width: 100%;
  flex: 1 1 100%;
  box-sizing: border-box;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent;
  font-family: inherit;
  font-size: 0.975rem;
  color: var(--text-main);
  resize: none;
  /* field-sizing: content — CSS nativo auto-height sin JS (Baseline 2024) */
  field-sizing: content;
  max-height: 180px;
  min-height: 28px;
  line-height: 1.5;
  padding: 0.2rem 0.25rem;
  align-self: stretch;
}

@media (max-width: 640px) {
  .chat-textarea {
    font-size: 1rem; /* Evita auto-zoom forzado en iOS Safari (>= 16px) */
    max-height: 30dvh; /* Evita colapso en pantallas pequeñas */
  }
}

.chat-textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

/* Acciones del Composer (Send / Stop) */
.input-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-bottom: 0;
}

.generation-status {
  position: absolute;
  right: 0.2rem;
  bottom: 0.15rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  max-width: min(220px, calc(100% - 0.4rem));
  padding: 0.2rem 0.35rem;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--bg-surface) 88%, transparent);
  color: var(--text-muted);
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
}

.generation-status[hidden] { display: none; }

.generation-status-icon { flex: 0 0 auto; animation: generationStatusSpin 1s linear infinite; }
.generation-status-text { overflow: hidden; text-overflow: ellipsis; }
.generation-status-progress { width: 46px; height: 3px; accent-color: var(--primary); }
@keyframes generationStatusSpin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .generation-status { max-width: 108px; }
  .generation-status-progress { display: none; }
}

/* Botones Circulares de Acción del Composer */
.btn-send,
.btn-stop-stream {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send .ui-icon,
.btn-stop-stream .ui-icon {
  width: 20px;
  height: 20px;
}

@media (max-width: 640px) {
  .btn-composer-chip,
  .btn-composer-icon-btn,
  .btn-reasoning,
  .btn-send,
  .btn-stop-stream {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }
}

/* Botón Circular de Envío */
.btn-send {
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-xs);
}

.btn-send:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: scale(1.05);
  box-shadow: var(--shadow-sm);
}

.btn-send:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-send:disabled {
  background-color: var(--bg-surface-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

/* Botón Circular de Detención de Streaming */
.btn-stop-stream {
  gap: 0.35rem;
  background-color: var(--danger);
  color: #ffffff;
  border: none;
  padding: 0;
  transition: all 0.15s ease;
  animation: pulseStop 1.5s infinite;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

.btn-stop-stream:hover {
  background-color: var(--danger-hover);
  transform: scale(1.05);
}

@keyframes pulseStop {
  0%, 100% { box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2); }
  50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.4); }
}

/* Metamorfosis: cuando stop está activo, oculta el botón de send */
.btn-stop-stream:not([style*="none"]) ~ .btn-send {
  display: none !important;
}

/* ==========================================================================
   Telemetría de Contexto en el Composer (Texto sutil, pequeño y sin remarcar)
   ========================================================================== */
.input-actions .context-hub-wrapper {
  display: inline-flex;
  align-items: center;
}

.composer-telemetry-btn {
  background: transparent;
  border: none;
  padding: 0.25rem 0.4rem;
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
  line-height: 1.2;
  user-select: none;
  box-shadow: none;
  outline: none;
  flex-wrap: nowrap;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .composer-telemetry-btn {
    min-height: 32px;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }
}

.composer-telemetry-btn:hover {
  color: var(--text-main);
}

.composer-telemetry-btn:focus-visible {
  outline: 1px solid var(--primary);
  outline-offset: 1px;
}

.composer-tokens-text {
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.composer-tokens-cache {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  color: #0284c7;
  font-size: 0.65rem;
}

[data-theme="dark"] .composer-tokens-cache {
  color: #38bdf8;
}

/* Indicadores de advertencia o crítico (sutil cambio de tono sin remarcar ni alterar fondo) */
.composer-telemetry-btn.status-warning .composer-tokens-text {
  color: #d97706;
}

.composer-telemetry-btn.status-critical .composer-tokens-text {
  color: #dc2626;
  font-weight: 600;
}

/* Popover Flotante desplegado hacia arriba desde el Composer */
.input-actions .context-hub-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  left: auto;
  top: auto;
  width: 310px;
  max-width: min(320px, calc(100vw - 32px));
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  z-index: var(--z-modal, 1000);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: contextPopoverFadeUp 0.15s ease-out;
  text-align: left;
}

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

.context-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

.context-popover-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.775rem;
  font-weight: 700;
  color: var(--text-main);
}

.btn-close-popover {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast);
}

.btn-close-popover:hover {
  color: var(--text-main);
}

.context-popover-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.context-limit-control {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.65rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.context-limit-source {
  font-size: 0.68rem;
}

.context-limit-control-row {
  display: flex;
  gap: 0.35rem;
}

.context-limit-control input {
  min-width: 0;
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.8rem;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.context-limit-control input:hover {
  border-color: var(--input-border-hover);
}

.context-limit-control input:focus,
.context-limit-control input:focus-visible {
  border-color: var(--input-border-focus);
  box-shadow: var(--input-focus-ring);
  outline: none;
}

.context-section-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.context-progress-bar-container {
  width: 100%;
  height: 6px;
  background-color: var(--bg-surface-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.context-progress-bar {
  height: 100%;
  background-color: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease, background-color 0.3s ease;
}

.context-progress-bar.warning {
  background-color: #f59e0b;
}

.context-progress-bar.critical {
  background-color: #ef4444;
}

.context-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
}

.context-metric-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.context-metric-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.context-metric-val {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.context-metric-val.accent {
  color: #0284c7;
}

[data-theme="dark"] .context-metric-val.accent {
  color: #38bdf8;
}

.context-metric-val.status-ok {
  color: #10b981;
}

.context-metric-val.status-warning {
  color: #f59e0b;
}

.context-metric-val.status-critical {
  color: #ef4444;
}

/* ==========================================================================
   Selector de Perfiles en Header Superior
   ========================================================================== */
.header-profile-menu {
  position: relative;
  width: clamp(8.5rem, 18vw, 13.75rem);
  min-width: 8.5rem;
}

.header-profile-trigger {
  display: inline-flex;
  align-items: center;
  width: 100%;
  height: 32px;
  min-width: 0;
  box-sizing: border-box;
  padding: 0 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  background-color: var(--bg-hover);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.header-profile-trigger .profile-icon .ui-icon,
.header-profile-trigger .profile-chevron .ui-icon {
  width: 13px;
  height: 13px;
}

@media (max-width: 640px) {
  .header-profile-trigger {
    height: 36px;
    padding: 0 0.7rem;
    font-size: 0.8125rem;
  }

  .header-profile-trigger .profile-icon .ui-icon,
  .header-profile-trigger .profile-chevron .ui-icon {
    width: 14px;
    height: 14px;
  }
}

.header-profile-trigger:hover,
.header-profile-trigger:focus-visible,
.header-profile-trigger[aria-expanded="true"] {
  background-color: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-main);
  outline: none;
}

.header-profile-trigger .profile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.header-profile-name {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 0.45rem;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-profile-trigger .profile-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.header-profile-trigger:hover .profile-chevron,
.header-profile-trigger:focus-visible .profile-chevron,
.header-profile-trigger[aria-expanded="true"] .profile-chevron {
  color: var(--text-main);
}

.header-profile-popover {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  width: min(340px, calc(100vw - 2rem));
  padding: 0.45rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.18);
}

.header-profile-popover[hidden] {
  display: none;
}

.header-profile-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.45rem 0.45rem;
  color: var(--text-muted);
}

.header-profile-popover-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.header-profile-header-actions {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.btn-profile-header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.btn-profile-header-icon:hover,
.btn-profile-header-icon:focus-visible {
  background: var(--bg-hover);
  border-color: var(--border-color);
  color: var(--text-main);
  outline: none;
}

.header-profile-list {
  display: grid;
  gap: 0.2rem;
  max-height: 240px;
  overflow-y: auto;
}

.header-profile-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.header-profile-item:hover {
  background: var(--bg-hover);
}

.header-profile-item.active {
  border-color: color-mix(in srgb, var(--primary) 45%, transparent);
  background: color-mix(in srgb, var(--primary) 12%, var(--bg-surface));
}

.header-profile-option {
  display: grid;
  gap: 0.12rem;
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.45rem;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-main);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.header-profile-option:hover,
.header-profile-option:focus-visible {
  outline: none;
}

.header-profile-option-name {
  overflow: hidden;
  font-size: 0.8rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-profile-option-description {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-profile-item-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding-right: 0.25rem;
  flex-shrink: 0;
}

.btn-profile-item-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.btn-profile-item-action:hover,
.btn-profile-item-action:focus-visible {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-main);
  outline: none;
}

.btn-profile-item-action.btn-profile-item-delete:hover,
.btn-profile-item-action.btn-profile-item-delete:focus-visible {
  background: color-mix(in srgb, var(--danger, #ef4444) 15%, transparent);
  border-color: color-mix(in srgb, var(--danger, #ef4444) 30%, transparent);
  color: var(--danger, #ef4444);
}
}

@media (max-width: 640px) {
  .header-profile-popover {
    width: min(300px, calc(100vw - 1.5rem));
  }
}
