/* ── components.css: Estética de Interfaz y UI ── */

/* ── HEADER ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 12, 0.9);
  backdrop-filter: blur(20px);
  flex-shrink: 0;
  z-index: 10;
}

.h-left {
  display: flex;
  align-items: center;
  gap: 14px
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--indigo), var(--cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 11px;
  color: #fff;
  flex-shrink: 0;
}

.h-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.5px
}

.h-title span {
  color: var(--cyan)
}

.hstats {
  display: flex;
  gap: 8px;
  align-items: center
}

.stat-chip {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  background: var(--glass);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 4px;
}

.stat-chip b {
  color: var(--cyan)
}

.o2-badge {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  background: rgba(255, 0, 85, 0.1);
  color: var(--rose);
  border: 1px solid rgba(255, 0, 85, 0.25);
  padding: 3px 9px;
  border-radius: 4px;
}

.h-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.array-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 16px;
}

#array-input {
  width: 140px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--txt);
  font-family: 'Space Mono', monospace;
  font-size: 11px;
}

#array-input:focus {
  outline: none;
  border-color: var(--indigo);
  background: rgba(99, 102, 241, 0.05);
}

#array-input::placeholder {
  color: var(--muted);
  opacity: 0.5;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

.algo-selector {
  background: rgba(10, 10, 12, 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--cyan);
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  cursor: pointer;
}

.algo-selector:focus {
  outline: none;
  border-color: var(--indigo);
}

.algo-selector option {
  background: var(--bg2);
  color: var(--txt);
}

.prog {
  height: 2px;
  background: var(--bg3);
  flex-shrink: 0
}

.prog-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--indigo), var(--cyan));
  transition: width .3s
}

/* ── VISUALIZATION CARDS ── */
.viz-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 0;
}

#cards-box {
  position: relative
}

#idx-row {
  position: relative;
  height: 20px
}

/* ── CARDS GLASSMORPHISM ── */
.card {
  position: absolute;
  top: 0;
  width: 76px;
  height: 86px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .22s, border-color .22s, box-shadow .22s;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, transparent 60%);
  pointer-events: none;
}

.card-val {
  font-family: 'Space Mono', monospace;
  font-size: 24px;
  font-weight: 700;
  color: var(--txt);
  transition: color .22s;
  user-select: none;
  position: relative;
  z-index: 1;
}

.card.is-min {
  background: rgba(255, 0, 85, 0.12);
  border-color: rgba(255, 0, 85, 0.7);
  box-shadow: 0 0 24px rgba(255, 0, 85, 0.4), 0 0 48px rgba(255, 0, 85, 0.1), inset 0 0 24px rgba(255, 0, 85, 0.05);
}

.card.is-min .card-val {
  color: #ff6699
}

.card.is-cand {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.7);
  box-shadow: 0 0 24px rgba(99, 102, 241, 0.4), 0 0 48px rgba(99, 102, 241, 0.1), inset 0 0 24px rgba(99, 102, 241, 0.05);
}

.card.is-cand .card-val {
  color: #a5b4fc
}

.card.is-done {
  background: rgba(0, 242, 255, 0.08);
  border-color: rgba(0, 242, 255, 0.5);
  box-shadow: 0 0 16px rgba(0, 242, 255, 0.2), inset 0 0 16px rgba(0, 242, 255, 0.03);
}

.card.is-done .card-val {
  color: var(--cyan)
}

.idx-lbl {
  position: absolute;
  top: 0;
  width: 76px;
  text-align: center;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--muted);
}

.status-bar {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.65;
  min-height: 42px;
  font-family: 'Space Mono', monospace;
}

.status-bar code {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  background: rgba(0, 242, 255, 0.1);
  color: var(--cyan);
  padding: 1px 5px;
  border-radius: 3px;
}

.status-bar b {
  color: var(--txt);
  font-weight: 700
}

/* ── CONTROLS ── */
.controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap
}

.btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: var(--glass);
  color: var(--txt);
  font-family: 'Space Mono', monospace;
  font-size: 11.5px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.15)
}

.btn:active {
  transform: scale(.97)
}

.btn-play {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(0, 242, 255, 0.1));
  border-color: rgba(99, 102, 241, 0.5);
  color: var(--indigo);
}

.btn-play:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(0, 242, 255, 0.2));
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.2)
}

.btn-reset {
  border-color: rgba(255, 0, 85, 0.2)
}

.btn-reset:hover {
  background: rgba(255, 0, 85, 0.07);
  border-color: rgba(255, 0, 85, 0.4)
}

.btn-explain {
  background: linear-gradient(135deg, rgba(0, 242, 255, 0.1), rgba(99, 102, 241, 0.1));
  border-color: rgba(0, 242, 255, 0.3);
  color: var(--cyan);
  font-size: 11px;
}

.btn-explain:hover {
  box-shadow: 0 0 20px rgba(0, 242, 255, 0.15)
}

.btn-tutorial {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: #f59e0b;
}

.btn-tutorial:hover {
  background: rgba(245, 158, 11, 0.2);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.15);
}

.btn-tutorial.active {
  background: rgba(245, 158, 11, 0.3);
  border-color: #f59e0b;
}

/* ── COMPLEXITY PANEL ── */
.complexity-panel {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
}

.complexity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

.complexity-header small {
  color: var(--cyan);
  font-weight: 700;
}

.complexity-chart {
  width: 100%;
  height: 60px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  overflow: hidden;
}

#complexity-canvas {
  width: 100%;
  height: 100%;
}

.complexity-stats {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.c-stat {
  display: flex;
  gap: 6px;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
}

.c-label {
  color: var(--muted);
}

.c-value {
  color: var(--txt);
  font-weight: 700;
}

.spd {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px
}

.spd-lbl {
  font-size: 10.5px;
  color: var(--muted);
  font-family: 'Space Mono', monospace
}

input[type=range] {
  -webkit-appearance: none;
  width: 90px;
  height: 3px;
  background: var(--bg3);
  border-radius: 2px;
  outline: none;
  cursor: pointer
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--indigo);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.7)
}

.spd-val {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--indigo);
  min-width: 24px
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap
}

.leg {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  color: var(--muted);
  font-family: 'Space Mono', monospace
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0
}

.d-min {
  background: var(--rose);
  box-shadow: 0 0 5px rgba(255, 0, 85, 0.8)
}

.d-cand {
  background: var(--indigo);
  box-shadow: 0 0 5px rgba(99, 102, 241, 0.8)
}

.d-done {
  background: var(--cyan);
  box-shadow: 0 0 5px rgba(0, 242, 255, 0.7)
}

.d-def {
  background: var(--bg3);
  border: 1px solid var(--border)
}

/* ── CODE PANEL ── */
.code-panel {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  overflow: hidden
}

.phead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 12, 0.6);
  flex-shrink: 0;
}

.ptitle {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .4px;
  font-family: 'Space Mono', monospace
}

.lang-badge {
  font-family: 'Space Mono', monospace;
  font-size: 9.5px;
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.25);
  padding: 2px 8px;
  border-radius: 3px;
}

#code-view {
  overflow-y: auto;
  flex: 1;
  padding: 4px 0;
  font-family: 'Space Mono', monospace;
  font-size: 11.5px;
  line-height: 1.8;
  scrollbar-width: thin;
  scrollbar-color: var(--bg3) transparent;
}

#code-view::-webkit-scrollbar {
  width: 3px
}

#code-view::-webkit-scrollbar-thumb {
  background: var(--bg3);
  border-radius: 2px
}

.cl {
  display: flex;
  align-items: baseline;
  padding: 0 12px;
  border-left: 2px solid transparent;
  transition: all .2s
}

.cl.hi-default {
  background: rgba(99, 102, 241, 0.07);
  border-left-color: var(--indigo)
}

.cl.hi-rose {
  background: rgba(255, 0, 85, 0.1);
  border-left-color: var(--rose);
  box-shadow: inset 0 0 20px rgba(255, 0, 85, 0.05)
}

.ln {
  min-width: 24px;
  color: #2a2a3a;
  font-size: 10px;
  text-align: right;
  margin-right: 12px;
  user-select: none;
  transition: color .2s
}

.cl.hi-default .ln,
.cl.hi-rose .ln {
  color: var(--cyan)
}

.cl.hi-rose .ln {
  color: var(--rose)
}

.lc {
  color: #8892b0
}

.kw {
  color: #c084fc
}

.tp {
  color: #67e8f9
}

.nl {
  color: #fb923c
}

.cm {
  color: #3a3a55;
  font-style: italic
}

.hi-rose .kw,
.hi-rose .tp,
.hi-rose .nl,
.hi-rose .lc {
  color: #ff6699 !important;
  text-shadow: 0 0 8px rgba(255, 0, 85, 0.5)
}

/* ── CHAT PANEL ── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0
}

.chat-head {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10, 10, 12, 0.6);
  flex-shrink: 0;
}

.ai-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rose);
  box-shadow: 0 0 6px var(--rose);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1)
  }

  50% {
    opacity: .4;
    transform: scale(0.8)
  }
}

#chat-msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg3) transparent;
  scroll-behavior: smooth;
}

#chat-msgs::-webkit-scrollbar {
  width: 3px
}

#chat-msgs::-webkit-scrollbar-thumb {
  background: var(--bg3);
  border-radius: 2px
}

.bubble {
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.6;
  word-break: break-word;
  font-family: 'Space Mono', monospace
}

.b-user {
  align-self: flex-end;
  border-bottom-right-radius: 3px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(0, 242, 255, 0.1));
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: var(--txt);
}

.b-ai {
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--muted);
}

.b-ai code {
  font-family: 'Space Mono', monospace;
  font-size: 10.5px;
  background: rgba(0, 242, 255, 0.018);
  color: var(--cyan);
  padding: 1px 5px;
  border-radius: 3px;
}

.b-ai table, .ai-table {
  font-size: 10px;
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  background: rgba(10, 10, 12, 0.8);
  border-radius: 4px;
  overflow: hidden;
}

.b-ai th,
.b-ai td,
.ai-table th,
.ai-table td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}

.b-ai th,
.ai-table th {
  background: rgba(99, 102, 241, 0.2);
  color: var(--cyan);
  font-weight: 700;
}

.b-ai pre {
  background: rgba(0, 0, 0, 0.5);
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border);
}

.b-ai code {
  background: rgba(0, 242, 255, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 10px;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--cyan);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(10, 10, 12, 0.6);
  border-top: 1px solid var(--border);
}

.suggestion-chip {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(99, 102, 241, 0.3);
  background: rgba(99, 102, 241, 0.1);
  color: var(--cyan);
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion-chip:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--indigo);
}

.btn-clear-chat {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.btn-clear-chat:hover {
  opacity: 1;
  color: var(--rose);
}

.typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 2px 0
}

.td {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: tk 1.3s ease-in-out infinite
}

.td:nth-child(2) {
  animation-delay: .2s
}

.td:nth-child(3) {
  animation-delay: .4s
}

@keyframes tk {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: .3
  }

  30% {
    transform: translateY(-5px);
    opacity: 1
  }
}

.chat-in {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 7px;
  align-items: center;
  flex-shrink: 0;
}

#cinput {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1.5px solid var(--border);
  border-radius: 7px;
  padding: 8px 12px;
  color: var(--txt);
  font-family: 'Space Mono', monospace;
  font-size: 11.5px;
  outline: none;
  transition: border-color .15s;
}

#cinput:focus {
  border-color: rgba(99, 102, 241, 0.5);
  background: rgba(99, 102, 241, 0.04)
}

#cinput::placeholder {
  color: var(--muted);
  opacity: .5
}

.csend {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 7px;
  border: none;
  background: linear-gradient(135deg, var(--indigo2), var(--cyan2));
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, transform .1s;
}

.csend:hover {
  opacity: .8
}

.csend:active {
  transform: scale(.93)
}

/* ── QUICK EXPLAIN OVERLAY ── */
#explain-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

.explain-arrow {
  position: absolute;
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--rose);
  background: rgba(255, 0, 85, 0.1);
  border: 1px solid rgba(255, 0, 85, 0.4);
  padding: 6px 12px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 0 20px rgba(255, 0, 85, 0.2);
  opacity: 0;
}

.highlight-pulse {
  position: absolute;
  border-radius: 12px;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 20px rgba(0, 242, 255, 0.4);
  pointer-events: none;
  opacity: 0;
}