/* ============================================================
   components.css — Biblioteca de componentes de SPECTRA OS.
   Responsabilidad: paneles glassmorphism, botones, toggles,
   sliders, badges, medidores, chat, listas y modales.
   El granulado y las scanlines viven SOLO aquí (cromería),
   nunca sobre el video de la cámara (regla LENTE PURA).
   ============================================================ */

/* ---------- Panel ---------- */
.panel {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s4);
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}
/* Scanlines + granulado: cromería de panel */
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.028) 0 1px,
    transparent 1px 3px
  );
  opacity: 0.7;
  mix-blend-mode: overlay;
}
.panel--tight { padding: var(--s3); }
.panel--flat { background: var(--bg-inset); box-shadow: none; }

.panel-title {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--fs-nano);
  letter-spacing: var(--track-xwide);
  text-transform: uppercase;
  color: var(--txt-ghost);
  margin-bottom: var(--s3);
}
.panel-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
}

/* Esquinas de captura */
.corners::after {
  content: "";
  position: absolute;
  inset: 5px;
  pointer-events: none;
  border-radius: var(--r-md);
  background:
    linear-gradient(var(--line-hard), var(--line-hard)) left top / 12px 1px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) left top / 1px 12px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) right top / 12px 1px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) right top / 1px 12px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) left bottom / 12px 1px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) left bottom / 1px 12px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) right bottom / 12px 1px no-repeat,
    linear-gradient(var(--line-hard), var(--line-hard)) right bottom / 1px 12px no-repeat;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: 11px var(--s4);
  border: 1px solid var(--line-hard);
  border-radius: var(--r-md);
  background: var(--accent-dim);
  color: var(--txt-hi);
  font-size: var(--fs-xs);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  transition: all var(--t-fast) var(--ease);
  position: relative;
  overflow: hidden;
  min-height: 42px;
}
.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.38; pointer-events: none; }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

.btn--primary {
  background: linear-gradient(180deg, var(--accent-dim), rgba(0, 0, 0, 0.3));
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-accent), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  font-weight: 600;
}
.btn--hero { padding: 16px var(--s5); font-size: var(--fs-sm); min-height: 54px; }
.btn--ghost {
  background: transparent;
  border-color: var(--line-soft);
  color: var(--txt-lo);
}
.btn--ghost:hover { color: var(--txt); border-color: var(--line); }
.btn--danger {
  border-color: rgba(255, 51, 85, 0.5);
  background: rgba(255, 51, 85, 0.1);
  color: var(--neon-red);
}
.btn--block { width: 100%; }
.btn--sm { padding: 7px var(--s3); min-height: 32px; font-size: var(--fs-nano); }
.btn--icon { padding: 0; width: 42px; min-height: 42px; border-radius: var(--r-md); }

.btn--primary::after {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.13), transparent);
  animation: btn-sweep 3.4s linear infinite;
}
@keyframes btn-sweep {
  0% { left: -60%; }
  55%, 100% { left: 130%; }
}

/* ---------- Toggle ---------- */
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: 10px 0;
  width: 100%;
  text-align: left;
}
.toggle-label {
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--txt);
}
.toggle-hint {
  display: block;
  font-size: var(--fs-nano);
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--txt-ghost);
  margin-top: 2px;
  line-height: 1.4;
}
.switch {
  flex: 0 0 auto;
  position: relative;
  width: 44px;
  height: 23px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-soft);
  background: var(--bg-inset);
  transition: all var(--t-mid) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--txt-ghost);
  transition: all var(--t-mid) var(--ease);
}
.switch[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.switch[aria-checked="true"]::after {
  left: 23px;
  background: var(--accent);
  box-shadow: var(--glow-accent);
}

/* ---------- Slider ---------- */
.slider-wrap { padding: var(--s2) 0; }
.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--fs-nano);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--txt-ghost);
  margin-bottom: 7px;
}
.slider-val { color: var(--accent); font-size: var(--fs-xs); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(to right, var(--accent), var(--line-soft));
  border-radius: var(--r-pill);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--bg-void);
  border: 2px solid var(--accent);
  box-shadow: var(--glow-accent);
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line-soft);
  border-radius: var(--r-pill);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-void);
  border: 2px solid var(--accent);
}

/* ---------- Campos ---------- */
.field { display: block; margin-bottom: var(--s3); }
.field-label {
  display: block;
  font-size: var(--fs-nano);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--txt-ghost);
  margin-bottom: 6px;
}
.input,
.textarea,
.select {
  width: 100%;
  padding: 11px var(--s3);
  background: var(--bg-inset);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  color: var(--txt-hi);
  font-size: var(--fs-sm);
  transition: border-color var(--t-fast) var(--ease);
  outline: none;
}
.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.textarea { resize: vertical; min-height: 72px; line-height: 1.55; }
.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--txt-lo) 50%),
    linear-gradient(135deg, var(--txt-lo) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: var(--s6);
}
.input::placeholder, .textarea::placeholder { color: var(--txt-ghost); }

/* ---------- Badge / chip ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--bg-inset);
  font-size: var(--fs-nano);
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--txt-lo);
  white-space: nowrap;
}
.badge--on { color: var(--neon-green); border-color: rgba(36, 255, 165, 0.4); }
.badge--off { color: var(--txt-ghost); }
.badge--warn { color: var(--neon-amber); border-color: rgba(255, 176, 32, 0.4); }
.badge--err { color: var(--neon-red); border-color: rgba(255, 51, 85, 0.4); }
.badge--accent { color: var(--accent); border-color: var(--line-hard); }
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  flex: 0 0 auto;
}
.dot--pulse { animation: pulse-dot 1.5s ease-in-out infinite; }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.78); }
}

.chip-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.chip {
  padding: 7px var(--s3);
  border-radius: var(--r-pill);
  border: 1px solid var(--line-soft);
  background: var(--bg-inset);
  color: var(--txt-lo);
  font-size: var(--fs-nano);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all var(--t-fast) var(--ease);
}
.chip.is-active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
  box-shadow: var(--glow-accent);
}

/* ---------- Lecturas / métricas ---------- */
.readout {
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.readout-val {
  font-size: var(--fs-xl);
  font-weight: 600;
  color: var(--txt-hi);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1;
}
.readout-unit {
  font-size: var(--fs-nano);
  color: var(--txt-ghost);
  letter-spacing: 0.1em;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: var(--s2);
}
.metric {
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--bg-inset);
}
.metric-k {
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--txt-ghost);
  display: block;
  margin-bottom: 3px;
}
.metric-v {
  font-size: var(--fs-md);
  color: var(--txt-hi);
  font-variant-numeric: tabular-nums;
}

/* ---------- Barra de progreso / presencia ---------- */
.bar {
  height: 5px;
  border-radius: var(--r-pill);
  background: var(--bg-inset);
  overflow: hidden;
  border: 1px solid var(--line-soft);
}
.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--neon-cyan), var(--accent));
  box-shadow: 0 0 10px var(--accent-dim);
  transition: width var(--t-mid) var(--ease);
}

/* ---------- Lista de items ---------- */
.list { display: flex; flex-direction: column; gap: var(--s2); }
.item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s3);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--bg-inset);
  text-align: left;
  transition: all var(--t-fast) var(--ease);
}
.item:active { transform: scale(0.99); }
.item:hover { border-color: var(--line); }
.item-main { flex: 1 1 auto; min-width: 0; }
.item-title {
  font-size: var(--fs-xs);
  color: var(--txt-hi);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-sub {
  font-size: var(--fs-nano);
  color: var(--txt-ghost);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-glyph {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--accent-dim);
  color: var(--accent);
}
.item-glyph svg { width: 16px; height: 16px; }

/* ---------- Estado vacío ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: var(--s7) var(--s4);
  text-align: center;
  color: var(--txt-ghost);
}
.empty-glyph {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px dashed var(--line);
  color: var(--txt-ghost);
  animation: empty-breathe 4s ease-in-out infinite;
}
.empty-glyph svg { width: 24px; height: 24px; }
@keyframes empty-breathe {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}
.empty-title {
  font-size: var(--fs-xs);
  letter-spacing: var(--track-wide);
  text-transform: uppercase;
  color: var(--txt-lo);
}
.empty-text {
  font-size: var(--fs-nano);
  max-width: 260px;
  line-height: 1.6;
}

/* ---------- Chat ---------- */
.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
  padding: var(--s3) var(--s1);
}
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 4px; }
.msg-meta {
  font-size: 8px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--txt-ghost);
}
.msg-body {
  padding: 10px var(--s3);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  line-height: 1.55;
  border: 1px solid;
  word-break: break-word;
}
.msg--op { align-self: flex-end; align-items: flex-end; }
.msg--op .msg-body {
  background: rgba(0, 240, 255, 0.09);
  border-color: rgba(0, 240, 255, 0.35);
  color: #cdf6ff;
  border-bottom-right-radius: 2px;
}
.msg--ent { align-self: flex-start; }
.msg--ent .msg-body {
  background: rgba(168, 85, 247, 0.11);
  border-color: rgba(168, 85, 247, 0.42);
  color: #eddcff;
  border-bottom-left-radius: 2px;
  box-shadow: 0 0 22px rgba(168, 85, 247, 0.18);
  animation: msg-arrive var(--t-slow) var(--ease);
}
.msg--sys { align-self: center; max-width: 96%; }
.msg--sys .msg-body {
  background: transparent;
  border-color: var(--line-soft);
  border-style: dashed;
  color: var(--txt-ghost);
  font-size: var(--fs-nano);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
}
@keyframes msg-arrive {
  from { opacity: 0; transform: translateY(10px) scale(0.97); filter: blur(3px); }
  to { opacity: 1; transform: none; filter: none; }
}
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--neon-violet);
  animation: typing-b 1.1s ease-in-out infinite;
}
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes typing-b {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}

.composer {
  flex: 0 0 auto;
  display: flex;
  gap: var(--s2);
  padding-top: var(--s3);
  border-top: 1px solid var(--line-soft);
  align-items: flex-end;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  background: rgba(3, 3, 6, 0.86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal.is-open { display: flex; animation: screen-in var(--t-mid) var(--ease); }
.modal-card {
  width: 100%;
  max-width: 400px;
  max-height: 88vh;
  overflow-y: auto;
}

/* ---------- Toast ---------- */
#toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + var(--s3));
  transform: translateX(-50%);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  pointer-events: none;
  width: min(92vw, 400px);
}
.toast {
  padding: 10px var(--s3);
  border-radius: var(--r-md);
  border: 1px solid var(--line-hard);
  background: rgba(8, 10, 18, 0.94);
  color: var(--txt-hi);
  font-size: var(--fs-xs);
  letter-spacing: 0.05em;
  box-shadow: var(--shadow-panel);
  animation: toast-in var(--t-mid) var(--ease);
  display: flex;
  gap: var(--s2);
  align-items: center;
}
.toast--warn { border-color: rgba(255, 176, 32, 0.5); color: #ffe0ad; }
.toast--err { border-color: rgba(255, 51, 85, 0.5); color: #ffc2cd; }
.toast.is-out { animation: toast-out var(--t-mid) var(--ease) forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-8px); }
}

/* ---------- Gráficas ---------- */
.chart-box {
  position: relative;
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  background: var(--bg-inset);
  overflow: hidden;
}
.chart-box canvas { display: block; width: 100%; }
.chart-label {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 8px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--txt-ghost);
  pointer-events: none;
}

/* ---------- Divisor / kv ---------- */
.hr { height: 1px; background: var(--line-soft); margin: var(--s3) 0; border: 0; }
.kv {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  padding: 6px 0;
  font-size: var(--fs-xs);
  border-bottom: 1px dashed rgba(140, 170, 200, 0.08);
}
.kv:last-child { border-bottom: 0; }
.kv-k { color: var(--txt-ghost); letter-spacing: 0.08em; text-transform: uppercase; font-size: var(--fs-nano); }
.kv-v { color: var(--txt-hi); text-align: right; font-variant-numeric: tabular-nums; }
