/* ══════════════════════════════════════════════════════
   Node.js Event Loop Visualizer — styles.css
   Aesthetic: Dark Industrial Terminal · Neon Queues
══════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ──────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:      #080B12;
  --bg2:     #0D1120;
  --bg3:     #111827;
  --bg4:     #161E2E;

  /* Borders */
  --border:  rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);

  /* Typography */
  --text:    #CBD5E1;
  --text-2:  #94A3B8;
  --text-3:  #4B5B72;

  /* Queue Colors */
  --c-green:  #00E676;
  --c-cyan:   #00E5FF;
  --c-blue:   #448AFF;
  --c-purple: #D05EFF;
  --c-orange: #FF6D00;
  --c-yellow: #FFD600;
  --c-red:    #FF5252;

  /* Glows */
  --glow-green:  0 0 20px rgba(0,230,118,0.35);
  --glow-cyan:   0 0 20px rgba(0,229,255,0.35);
  --glow-blue:   0 0 20px rgba(68,138,255,0.35);
  --glow-purple: 0 0 20px rgba(208,94,255,0.35);
  --glow-orange: 0 0 20px rgba(255,109,0,0.35);

  /* Dimmed backgrounds */
  --dim-green:  rgba(0,230,118,0.08);
  --dim-cyan:   rgba(0,229,255,0.08);
  --dim-blue:   rgba(68,138,255,0.08);
  --dim-purple: rgba(208,94,255,0.08);
  --dim-orange: rgba(255,109,0,0.08);
  --dim-yellow: rgba(255,214,0,0.08);

  /* Fonts */
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --font-ui:   'Syne', sans-serif;
  --font-ar:   'Cairo', sans-serif;

  /* Layout */
  --header-h:  58px;
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
}

/* ── RESET ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ar);
  min-height: 100vh;
  overflow: hidden;
  /* subtle grid texture */
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 32px 32px;
}

/* ── SCROLLBARS ─────────────────────────────────────── */
::-webkit-scrollbar { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ══════════════════════════════════════════════════════
   HEADER
══════════════════════════════════════════════════════ */
.app-header {
  height: var(--header-h);
  background: rgba(13,17,32,0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--c-green), var(--c-blue));
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: #080B12;
  flex-shrink: 0;
  box-shadow: var(--glow-green);
}

.brand-title {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 800;
  color: #F1F5F9;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-3);
  margin-top: 1px;
  direction: ltr;
}

.header-badges {
  display: flex;
  gap: 6px;
  align-items: center;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge--node   { color: var(--c-green);  border-color: rgba(0,230,118,0.35); background: var(--dim-green); }
.badge--libuv  { color: var(--c-yellow); border-color: rgba(255,214,0,0.35); background: var(--dim-yellow); }
.badge--neutral{ color: var(--text-2);   border-color: var(--border2);       background: var(--bg4); }

/* ══════════════════════════════════════════════════════
   APP LAYOUT
══════════════════════════════════════════════════════ */
.app {
  display: grid;
  grid-template-columns: 38% 62%;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════
   LEFT PANEL
══════════════════════════════════════════════════════ */
.panel-left {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  overflow: hidden;
}

/* ── Section Header ── */
.section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--green  { background: var(--c-green); box-shadow: 0 0 6px var(--c-green); }
.dot--cyan   { background: var(--c-cyan); }
.dot--blue   { background: var(--c-blue); }
.dot--orange { background: var(--c-orange); }

/* ── Example Select ── */
.example-select {
  background: var(--bg4);
  border: 1px solid var(--border2);
  color: var(--text);
  font-family: var(--font-ar);
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  direction: rtl;
  transition: border-color 0.15s;
}
.example-select:focus { border-color: var(--c-green); }

/* ── Code Editor ── */
.editor-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.line-nums {
  flex-shrink: 0;
  width: 38px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  padding: 14px 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.75;
  color: var(--text-3);
  text-align: center;
  overflow: hidden;
  user-select: none;
}

.editor-inner {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#code-editor {
  position: absolute;
  inset: 0;
  background: var(--bg);
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.75;
  padding: 14px 14px 14px 10px;
  resize: none;
  outline: none;
  tab-size: 2;
  direction: ltr;
  text-align: left;
  caret-color: var(--c-green);
}

.line-hl {
  position: absolute;
  left: 0; right: 0;
  background: rgba(0,230,118,0.08);
  border-right: 2px solid var(--c-green);
  pointer-events: none;
  display: none;
  transition: top 0.18s ease;
}

/* ── Controls Bar ── */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-ar);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn--run {
  background: var(--c-green);
  color: #080B12;
}
.btn--run:not(:disabled):hover {
  background: #5affb2;
  box-shadow: var(--glow-green);
}
.btn--run.is-running {
  animation: runPulse 1.2s infinite;
}

.btn--step {
  background: var(--dim-blue);
  color: var(--c-blue);
  border: 1px solid rgba(68,138,255,0.3);
}
.btn--step:not(:disabled):hover {
  background: var(--c-blue);
  color: #080B12;
  box-shadow: var(--glow-blue);
}

.btn--reset {
  background: var(--bg4);
  color: var(--text-2);
  border: 1px solid var(--border2);
}
.btn--reset:hover {
  border-color: var(--c-red);
  color: var(--c-red);
}

@keyframes runPulse {
  0%,100% { box-shadow: none; }
  50%      { box-shadow: var(--glow-green); }
}

.speed-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: auto;
}
.speed-lbl {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#speed-slider {
  -webkit-appearance: none;
  width: 64px;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--c-green);
  cursor: pointer;
  box-shadow: 0 0 6px var(--c-green);
}

.step-badge {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-3);
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* ── Console ── */
.console-section {
  flex-shrink: 0;
  height: 155px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.console-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.85;
  direction: ltr;
  text-align: left;
}

.console-ph {
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.log-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  opacity: 0;
  animation: fadeUp 0.22s ease forwards;
}
.log-chevron { color: var(--c-green); flex-shrink: 0; }
.log-text    { color: var(--c-green); }

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

/* ── Step Description Bar ── */
.step-desc-bar {
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  min-height: 38px;
  display: flex;
  align-items: center;
}
.step-desc {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--c-yellow);
  direction: rtl;
  line-height: 1.5;
}

/* ══════════════════════════════════════════════════════
   RIGHT PANEL
══════════════════════════════════════════════════════ */
.panel-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Viz Rows ── */
.viz-row {
  display: grid;
  overflow: hidden;
}

.viz-row--top {
  grid-template-columns: 1fr 1fr;
  flex: 42;
  border-bottom: 1px solid var(--border);
}

.viz-row--queues {
  grid-template-columns: 1fr 1fr 1fr;
  flex: 30;
  border-bottom: 1px solid var(--border);
}

/* ── Viz Card ── */
.viz-card {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg2);
  overflow: hidden;
  position: relative;
  transition: box-shadow 0.3s, background 0.3s;
}

.viz-card + .viz-card {
  border-left: 1px solid var(--border);
}

/* Card Active States */
.viz-card.card--green  { box-shadow: inset 0 0 0 1px rgba(0,230,118,0.4), var(--glow-green);  background: rgba(0,230,118,0.03); }
.viz-card.card--cyan   { box-shadow: inset 0 0 0 1px rgba(0,229,255,0.4), var(--glow-cyan);   background: rgba(0,229,255,0.03); }
.viz-card.card--blue   { box-shadow: inset 0 0 0 1px rgba(68,138,255,0.4), var(--glow-blue);  background: rgba(68,138,255,0.03); }
.viz-card.card--purple { box-shadow: inset 0 0 0 1px rgba(208,94,255,0.4), var(--glow-purple);background: rgba(208,94,255,0.03); }
.viz-card.card--orange { box-shadow: inset 0 0 0 1px rgba(255,109,0,0.4), var(--glow-orange); background: rgba(255,109,0,0.03); }

/* ── Card Header ── */
.card-hd {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.card-badge-id {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.badge--green-id  { color: var(--c-green);  background: var(--dim-green);  border: 1px solid rgba(0,230,118,0.2); }
.badge--purple-id { color: var(--c-purple); background: var(--dim-purple); border: 1px solid rgba(208,94,255,0.2); }
.badge--cyan-id   { color: var(--c-cyan);   background: var(--dim-cyan);   border: 1px solid rgba(0,229,255,0.2); }
.badge--blue-id   { color: var(--c-blue);   background: var(--dim-blue);   border: 1px solid rgba(68,138,255,0.2); }
.badge--orange-id { color: var(--c-orange); background: var(--dim-orange); border: 1px solid rgba(255,109,0,0.2); }

.card-meta { flex: 1; min-width: 0; }
.card-name {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub {
  font-family: var(--font-mono);
  font-size: 0.57rem;
  color: var(--text-3);
  margin-top: 1px;
  direction: ltr;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-count {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-3);
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  flex-shrink: 0;
}

/* ── Card Body ── */
.card-body {
  flex: 1;
  padding: 7px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Call Stack: newest on top (LIFO visual) */
.stack-lifo { flex-direction: column-reverse; }

/* ── Empty Message ── */
.empty-msg {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-3);
  text-align: center;
  padding: 10px 8px;
  border: 1px dashed var(--border2);
  border-radius: var(--radius-sm);
  margin: auto;
  width: 100%;
}

/* ── Queue Items ── */
.q-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  animation: slideIn 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.q-item .q-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.q-item--green  { background: var(--dim-green);  color: var(--c-green);  border: 1px solid rgba(0,230,118,0.18); }
.q-item--green  .q-dot { background: var(--c-green); }
.q-item--cyan   { background: var(--dim-cyan);   color: var(--c-cyan);   border: 1px solid rgba(0,229,255,0.18); }
.q-item--cyan   .q-dot { background: var(--c-cyan); }
.q-item--blue   { background: var(--dim-blue);   color: var(--c-blue);   border: 1px solid rgba(68,138,255,0.18); }
.q-item--blue   .q-dot { background: var(--c-blue); }
.q-item--purple { background: var(--dim-purple); color: var(--c-purple); border: 1px solid rgba(208,94,255,0.18); }
.q-item--purple .q-dot { background: var(--c-purple); }
.q-item--orange { background: var(--dim-orange); color: var(--c-orange); border: 1px solid rgba(255,109,0,0.18); }
.q-item--orange .q-dot { background: var(--c-orange); }
.q-item--yellow { background: var(--dim-yellow); color: var(--c-yellow); border: 1px solid rgba(255,214,0,0.18); }
.q-item--yellow .q-dot { background: var(--c-yellow); }

/* Web API special layout */
.api-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
}
.api-timer {
  font-size: 0.55rem;
  color: var(--text-3);
}

/* ══════════════════════════════════════════════════════
   LIBUV STRIP
══════════════════════════════════════════════════════ */
.libuv-strip {
  flex: 28;
  display: flex;
  flex-direction: column;
  background: rgba(255,214,0,0.02);
  border-top: 1px solid rgba(255,214,0,0.15);
  overflow: hidden;
}

.libuv-hd {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-bottom: 1px solid rgba(255,214,0,0.12);
  flex-shrink: 0;
}

.libuv-pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--c-yellow);
  box-shadow: 0 0 8px var(--c-yellow);
  animation: pulseBeat 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulseBeat {
  0%,100% { box-shadow: 0 0 4px var(--c-yellow); opacity: 0.7; }
  50%      { box-shadow: 0 0 14px 3px var(--c-yellow); opacity: 1; }
}

.libuv-label {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--c-yellow);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  direction: ltr;
}

.libuv-status {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-3);
  margin-right: auto;
  direction: ltr;
}

/* ── Pipeline ── */
.libuv-pipeline {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 0;
  overflow-x: auto;
  direction: ltr;
}

/* ── Phase Node ── */
.phase-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border2);
  background: var(--bg4);
  cursor: default;
  transition: all 0.3s ease;
  flex-shrink: 0;
  min-width: 84px;
  text-align: center;
}

.phase-node.phase--active {
  border-color: var(--c-yellow);
  background: var(--dim-yellow);
  box-shadow: 0 0 16px rgba(255,214,0,0.3);
  transform: translateY(-2px);
}

.phase-glyph {
  font-size: 0.95rem;
  line-height: 1;
}

.phase-nm {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text);
}

.phase-node.phase--active .phase-nm {
  color: var(--c-yellow);
}

.phase-hint {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  max-width: 80px;
  text-overflow: ellipsis;
}

/* ── Phase Connector ── */
.phase-connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  padding: 0 3px;
}

.connector-line {
  width: 26px;
  height: 1px;
  background: linear-gradient(90deg, var(--border2), rgba(255,214,0,0.4), var(--border2));
  position: relative;
}

.connector-line::after {
  content: '';
  position: absolute;
  right: -4px;
  top: -3px;
  border-left: 5px solid rgba(255,214,0,0.5);
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
}

.connector-badge {
  font-family: var(--font-mono);
  font-size: 0.48rem;
  color: rgba(255,214,0,0.5);
  white-space: nowrap;
  letter-spacing: 0.04em;
}

/* ── Loop Back Arrow ── */
.phase-loop-back {
  display: flex;
  align-items: center;
  padding-right: 6px;
}
.loop-arrow {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: rgba(255,214,0,0.4);
  white-space: nowrap;
  padding: 4px 8px;
  border: 1px dashed rgba(255,214,0,0.2);
  border-radius: 4px;
}

/* ══════════════════════════════════════════════════════
   TOOLTIP
══════════════════════════════════════════════════════ */
.tooltip {
  position: fixed;
  background: var(--bg3);
  border: 1px solid rgba(255,214,0,0.4);
  color: var(--c-yellow);
  font-family: var(--font-ar);
  font-size: 0.72rem;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  max-width: 260px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s;
  direction: rtl;
  line-height: 1.55;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5), 0 0 16px rgba(255,214,0,0.15);
}
.tooltip.is-visible { opacity: 1; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .panel-left { height: 480px; }
  .panel-right {
    height: 700px;
    overflow: visible;
  }
  .viz-row--top    { flex: 0 0 260px; }
  .viz-row--queues { flex: 0 0 220px; }
  .libuv-strip     { flex: 0 0 190px; }
}

@media (max-width: 600px) {
  .viz-row--top    { grid-template-columns: 1fr; }
  .viz-row--queues { grid-template-columns: 1fr; }
  .header-badges   { display: none; }
}
