/* ============================================================
   OpenClaw — SimCity for AI Agents
   "Diegetic UI" — everything feels part of the world
   ============================================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* === LOADING OVERLAY === */
#loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  background: radial-gradient(ellipse at 50% 40%, #1A0F2A 0%, #0B0612 50%, #050308 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}
#loading-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
}
.loader-content {
  text-align: center;
}
.loader-spinner {
  width: 40px; height: 40px;
  margin: 0 auto 16px;
  border: 3px solid rgba(139, 62, 255, 0.15);
  border-top-color: #8B3EFF;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text {
  font-family: var(--sans);
  color: #9B93B8;
  font-size: 14px;
  letter-spacing: 0.5px;
}

/* === PALETTE — locked down, no extras === */
:root {
  /* Void / Background */
  --void:          #050308;
  --deep:          #0B0612;
  --space:         #1A0F2A;
  /* ONE purple, ONE pink */
  --purple:        #8B3EFF;
  --pink:          #FF7EB6;
  /* Neutrals */
  --panel-bg:      rgba(16, 12, 28, 0.93);
  --panel-border:  rgba(139, 62, 255, 0.12);
  --panel-glow:    rgba(139, 62, 255, 0.15);
  /* Text — never pure white */
  --text-1:        #EDE9F5;
  --text-2:        #9B93B8;
  --text-3:        #6A6384;
  /* Functional */
  --green:         #3CFF6B;
  --red:           #E63946;
  --blue:          #3FA9F5;
  /* Fonts */
  --sans:          'Inter', -apple-system, sans-serif;
  --mono:          'JetBrains Mono', monospace;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--void);
  font-family: var(--sans);
  color: var(--text-1);
  cursor: default;
}
.hidden { display: none !important; }

/* ============================================================
   MAC CHROME
   ============================================================ */
#mac-chrome {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 38px;
  background: linear-gradient(180deg, #150E24 0%, #100C1C 100%);
  border-bottom: 1px solid rgba(139, 62, 255, 0.08);
  display: flex; align-items: center;
  padding: 0 16px;
}
.traffic-lights { display: flex; gap: 8px; align-items: center; }
.traffic-lights .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.red { background: #FF5F57; }
.dot.yellow { background: #FFBD2E; }
.dot.green { background: #28C840; }
.chrome-title {
  flex: 1; text-align: center;
  font-size: 13px; font-weight: 500;
  color: var(--text-3);
  letter-spacing: 0.5px;
}
.chrome-right { font-size: 12px; color: var(--text-3); font-family: var(--mono); }

/* ============================================================
   SCENE CONTAINER + DIMMING + VIGNETTE
   ============================================================ */
#scene-container {
  position: fixed;
  top: 38px; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at 50% 35%, #1A0F2A 0%, #0B0612 50%, #050308 100%);
}
#scene-container canvas {
  display: block; width: 100% !important; height: 100% !important;
}

/* Vignette — always on */
#scene-container::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 45%, rgba(5, 3, 8, 0.55) 100%);
  pointer-events: none;
  z-index: 1;
}

/* Scene dim — activates when panel opens */
#scene-container::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(5, 3, 8, 0.35);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.6s ease;
}
#scene-container.dimmed::before {
  opacity: 1;
}

/* Billboard — hidden, rendered in 3D */
#billboard { display: none !important; }

/* ============================================================
   SPEECH BUBBLES — diegetic, part of the world
   ============================================================ */
#bubbles-container {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none; z-index: 30;
}

.speech-bubble {
  position: absolute;
  background: rgba(16, 12, 28, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(139, 62, 255, 0.2);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 12px; font-weight: 500;
  color: var(--text-1);
  white-space: nowrap;
  transform: translate(-50%, -100%);
  animation: bubbleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 0 24px rgba(139, 62, 255, 0.12);
  pointer-events: none;
}
.speech-bubble::after {
  content: '';
  position: absolute; bottom: -7px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid rgba(139, 62, 255, 0.2);
}
.speech-bubble.error {
  border-color: rgba(230, 57, 70, 0.3);
  box-shadow: 0 0 24px rgba(230, 57, 70, 0.15);
  animation: bubbleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), shake 0.5s ease;
}
.speech-bubble.error::after { border-top-color: rgba(230, 57, 70, 0.3); }
.speech-bubble.success {
  border-color: rgba(60, 255, 107, 0.25);
  box-shadow: 0 0 24px rgba(60, 255, 107, 0.1);
}
.speech-bubble.success::after { border-top-color: rgba(60, 255, 107, 0.25); }
.bubble-exit { animation: bubbleOut 0.3s ease forwards; }

@keyframes bubbleIn {
  from { opacity: 0; transform: translate(-50%, -80%) scale(0.5); }
  to   { opacity: 1; transform: translate(-50%, -100%) scale(1); }
}
@keyframes bubbleOut {
  to { opacity: 0; transform: translate(-50%, -120%) scale(0.8); }
}
@keyframes shake {
  0%, 100% { transform: translate(-50%, -100%) rotate(0); }
  20% { transform: translate(-48%, -100%) rotate(-2deg); }
  40% { transform: translate(-52%, -100%) rotate(2deg); }
  60% { transform: translate(-49%, -100%) rotate(-1deg); }
  80% { transform: translate(-51%, -100%) rotate(1deg); }
}

/* ============================================================
   CONNECTION LINES
   ============================================================ */
#connections-svg {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 25;
}
#connections-svg line {
  stroke: var(--purple);
  stroke-width: 2;
  stroke-dasharray: 8 4;
  opacity: 0.4;
  animation: dashScroll 1s linear infinite;
}
@keyframes dashScroll { to { stroke-dashoffset: -12; } }

/* ============================================================
   PANELS — Diegetic, semi-transparent, part of the world
   ============================================================ */
.panel {
  position: fixed;
  top: 50%; right: 40px;
  transform: translateY(-50%);
  width: 380px;
  max-height: 80vh;
  /* KEY: semi-transparent, glassy, part of the world */
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  z-index: 50;
  overflow: hidden;
  /* Soft outer glow — not hard shadow */
  box-shadow: 0 0 40px var(--panel-glow), 0 0 80px rgba(5, 3, 8, 0.5);
  animation: panelSlideIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes panelSlideIn {
  from { opacity: 0; transform: translateY(-50%) translateX(40px) scale(0.97); }
  to   { opacity: 1; transform: translateY(-50%) translateX(0) scale(1); }
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(139, 62, 255, 0.08);
}
.panel-header h2 {
  font-size: 16px; font-weight: 700;
  color: var(--text-1);
  letter-spacing: 0.3px;
}
.panel-close {
  width: 28px; height: 28px;
  border: none; border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-3);
  font-size: 18px; cursor: pointer;
  transition: all 0.25s;
}
.panel-close:hover {
  background: rgba(139, 62, 255, 0.1);
  color: var(--pink);
}

/* Tabs */
.panel-tabs {
  display: flex;
  border-bottom: 1px solid rgba(139, 62, 255, 0.06);
}
.tab {
  flex: 1; padding: 10px 16px;
  border: none; background: none;
  color: var(--text-3);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all 0.25s;
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--pink);
  border-bottom-color: var(--pink);
  background: rgba(255, 126, 182, 0.03);
}
.tab:hover { color: var(--text-2); }

/* Search */
.panel-search { padding: 12px 16px; }
.panel-search input {
  width: 100%; padding: 10px 14px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(139, 62, 255, 0.1);
  border-radius: 12px;
  color: var(--text-1);
  font-size: 13px; font-family: var(--sans);
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.panel-search input:focus {
  border-color: rgba(139, 62, 255, 0.25);
  box-shadow: 0 0 16px rgba(139, 62, 255, 0.08);
}
.panel-search input::placeholder { color: var(--text-3); }

/* ============================================================
   AGENT CARDS — creatures in capsules, not dashboard rows
   ============================================================ */
.agent-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 16px;
  max-height: 320px;
  overflow-y: auto;
}

.agent-card {
  /* Capsule gradient */
  background: linear-gradient(180deg, rgba(40, 30, 60, 0.9), rgba(20, 15, 35, 0.9));
  border: 1px solid rgba(139, 62, 255, 0.1);
  border-radius: 16px;
  padding: 14px;
  cursor: pointer;
  text-align: center;
  /* Smooth transitions for everything */
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              border-color 0.3s ease,
              box-shadow 0.3s ease,
              background 0.3s ease;
}

.agent-card:hover {
  transform: translateY(-3px) scale(1.03);
  border-color: rgba(139, 62, 255, 0.25);
  box-shadow: 0 0 24px rgba(139, 62, 255, 0.12);
}

.agent-card.selected {
  border-color: var(--pink);
  box-shadow: 0 0 32px rgba(255, 126, 182, 0.15), 0 0 12px rgba(139, 62, 255, 0.1);
  animation: selectedFloat 2s ease-in-out infinite;
}

@keyframes selectedFloat {
  0%, 100% { transform: translateY(-3px); }
  50%      { transform: translateY(-6px); }
}

/* Avatar — circular with glow ring */
.agent-card .agent-avatar {
  width: 56px; height: 56px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  position: relative;
  /* Glow ring effect */
  box-shadow: 0 0 16px rgba(139, 62, 255, 0.15);
  transition: box-shadow 0.3s ease;
}
.agent-card:hover .agent-avatar {
  box-shadow: 0 0 24px rgba(139, 62, 255, 0.25);
}
.agent-card.selected .agent-avatar {
  box-shadow: 0 0 28px rgba(255, 126, 182, 0.3);
  animation: avatarRingPulse 1.5s ease-in-out infinite;
}

@keyframes avatarRingPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(255, 126, 182, 0.2); }
  50%      { box-shadow: 0 0 32px rgba(255, 126, 182, 0.35); }
}

.agent-card .agent-monitor {
  position: absolute;
  bottom: -3px; right: -3px;
  width: 18px; height: 18px;
  background: rgba(16, 12, 28, 0.9);
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  border: 1px solid rgba(139, 62, 255, 0.15);
}

.agent-card .agent-name {
  font-size: 13px; font-weight: 600;
  color: var(--text-1);
  margin-bottom: 3px;
}
.agent-card .agent-role {
  font-size: 11px;
  color: var(--text-3);
}

/* ============================================================
   PANEL FOOTER + BUTTONS
   ============================================================ */
.panel-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(139, 62, 255, 0.06);
  display: flex; gap: 10px;
}

.btn-recruit, .btn-save, .btn-test {
  flex: 1; padding: 11px 20px;
  border: none; border-radius: 12px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Recruit — premium command button */
.btn-recruit {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: var(--text-1);
  box-shadow: 0 0 20px rgba(255, 126, 182, 0.15);
  position: relative;
  overflow: hidden;
}
.btn-recruit::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity 0.25s;
}
.btn-recruit:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 0 32px rgba(255, 126, 182, 0.25), 0 4px 16px rgba(0,0,0,0.3);
}
.btn-recruit:not(:disabled):hover::before { opacity: 1; }
.btn-recruit:not(:disabled):active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 0 16px rgba(255, 126, 182, 0.1);
}
.btn-recruit:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-save {
  background: linear-gradient(135deg, var(--purple), #6D28D9);
  color: var(--text-1);
  box-shadow: 0 0 16px rgba(139, 62, 255, 0.12);
}
.btn-save:hover {
  box-shadow: 0 0 28px rgba(139, 62, 255, 0.2);
  transform: translateY(-1px);
}
.btn-save:active { transform: translateY(1px) scale(0.98); }

.btn-test {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(139, 62, 255, 0.12);
  color: var(--text-2);
}
.btn-test:hover {
  border-color: rgba(139, 62, 255, 0.25);
  color: var(--text-1);
  background: rgba(139, 62, 255, 0.04);
}

/* ============================================================
   SETTINGS PANEL
   ============================================================ */
.settings-content {
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}
.settings-avatar {
  width: 80px; height: 80px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: rgba(230, 57, 70, 0.08);
  border: 2px solid rgba(230, 57, 70, 0.3);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  box-shadow: 0 0 24px rgba(230, 57, 70, 0.1);
  animation: settingsAvatarPulse 2.5s ease-in-out infinite;
}
@keyframes settingsAvatarPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(230, 57, 70, 0.08); }
  50%      { box-shadow: 0 0 36px rgba(230, 57, 70, 0.18); }
}

.settings-fields label {
  display: block;
  font-size: 11px; font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin: 14px 0 6px;
}
.settings-fields label:first-child { margin-top: 0; }
.settings-fields input,
.settings-fields textarea {
  width: 100%; padding: 10px 12px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(139, 62, 255, 0.1);
  border-radius: 10px;
  color: var(--text-1);
  font-size: 13px; font-family: var(--sans);
  outline: none; resize: vertical;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.settings-fields input:focus,
.settings-fields textarea:focus {
  border-color: rgba(139, 62, 255, 0.2);
  box-shadow: 0 0 12px rgba(139, 62, 255, 0.06);
}
.code-field {
  font-family: var(--mono) !important;
  font-size: 12px !important;
  line-height: 1.5;
  background: rgba(0, 0, 0, 0.15) !important;
}
.skills-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.skill-tag {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px; font-weight: 500;
  background: rgba(139, 62, 255, 0.08);
  border: 1px solid rgba(139, 62, 255, 0.15);
  color: var(--purple);
}

/* ============================================================
   OVERLAY TEXT
   ============================================================ */
#overlay-text {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 40;
  pointer-events: none;
}
#overlay-text span {
  display: block;
  font-size: 28px; font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 4px;
  color: var(--text-1);
  text-shadow: 0 0 40px rgba(139, 62, 255, 0.4), 0 0 80px rgba(255, 126, 182, 0.2);
  animation: overlayFadeIn 0.8s ease;
  text-align: center;
}
@keyframes overlayFadeIn {
  from { opacity: 0; transform: scale(0.85) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ============================================================
   FINAL OVERLAY
   ============================================================ */
#final-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(5, 3, 8, 0.92);
  z-index: 80;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 1s ease;
  backdrop-filter: blur(8px);
}
.final-content {
  text-align: center;
  animation: finalSlideUp 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
.final-content h1 {
  font-size: 64px; font-weight: 800;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}
.final-content p {
  font-size: 20px;
  color: var(--text-2);
  margin-bottom: 32px;
}
.final-features {
  display: flex; gap: 14px; justify-content: center;
  flex-wrap: wrap; margin-bottom: 40px;
}
.final-features span {
  padding: 8px 20px;
  border-radius: 24px;
  font-size: 14px; font-weight: 500;
  background: rgba(139, 62, 255, 0.06);
  border: 1px solid rgba(139, 62, 255, 0.15);
  color: var(--purple);
}
.btn-replay {
  padding: 14px 40px;
  border: none; border-radius: 14px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: var(--text-1);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  box-shadow: 0 0 24px rgba(255, 126, 182, 0.15);
  transition: all 0.3s;
}
.btn-replay:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 40px rgba(255, 126, 182, 0.25);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes finalSlideUp {
  from { opacity: 0; transform: translateY(40px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   CONTROLS — minimal, game HUD feel
   ============================================================ */
#controls {
  position: fixed;
  bottom: 40px; left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex; align-items: center; gap: 12px;
  background: rgba(16, 12, 28, 0.8);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(139, 62, 255, 0.08);
  border-radius: 16px;
  padding: 10px 20px;
}
#btn-play-pause, #btn-manual-recruit {
  width: 36px; height: 36px;
  border: none; border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-1);
  font-size: 14px; cursor: pointer;
  transition: all 0.25s;
  display: flex; align-items: center; justify-content: center;
}
#btn-play-pause:hover, #btn-manual-recruit:hover {
  background: rgba(139, 62, 255, 0.08);
  color: var(--pink);
}
#btn-manual-recruit {
  width: auto; padding: 0 14px;
  font-size: 12px; font-weight: 600;
  font-family: var(--sans);
}
#timeline-bar {
  width: 200px; height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
}
#timeline-progress {
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear;
}
#timeline-time {
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--mono);
  min-width: 80px;
}

#btn-exit-immersive {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 75;
  border: 1px solid rgba(139, 62, 255, 0.22);
  background: rgba(16, 12, 28, 0.88);
  backdrop-filter: blur(10px);
  color: var(--text-1);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 0 20px rgba(139, 62, 255, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
#btn-exit-immersive:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 126, 182, 0.4);
  box-shadow: 0 0 28px rgba(255, 126, 182, 0.28);
}

/* ============================================================
   STATUS BAR
   ============================================================ */
#status-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 55;
  height: 28px;
  background: rgba(16, 12, 28, 0.85);
  border-top: 1px solid rgba(139, 62, 255, 0.05);
  display: flex; align-items: center;
  padding: 0 16px; gap: 24px;
}
.status-item { font-size: 11px; color: var(--text-3); }
.status-item strong { color: var(--pink); font-weight: 600; }

/* ============================================================
   AGENT LABELS — glowy pills, never pure white
   ============================================================ */
.agent-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-size: 11px; font-weight: 700;
  padding: 3px 12px;
  border-radius: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 29;
  letter-spacing: 0.6px;
}

/* Dev label — soft pink glow */
.agent-label.dev {
  background: rgba(255, 126, 182, 0.12);
  border: 1px solid rgba(255, 126, 182, 0.25);
  color: var(--pink);
  text-shadow: 0 0 10px rgba(255, 126, 182, 0.35);
}

/* Agent label — soft green glow */
.agent-label.lobster {
  background: rgba(60, 255, 107, 0.08);
  border: 1px solid rgba(60, 255, 107, 0.2);
  color: var(--green);
  text-shadow: 0 0 10px rgba(60, 255, 107, 0.3);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139, 62, 255, 0.15); border-radius: 3px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .panel { width: 320px; right: 10px; }
  #controls { padding: 8px 12px; }
  #timeline-bar { width: 120px; }
  #overlay-text span { font-size: 20px; }
}

/* ============================================================
   WALLET BAR
   ============================================================ */
#wallet-bar {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 8px;
}
#btn-connect-wallet {
  border: 1px solid rgba(171, 133, 255, 0.35);
  background: rgba(171, 133, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #ab85ff;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.25s;
}
#btn-connect-wallet:hover {
  background: rgba(171, 133, 255, 0.18);
  box-shadow: 0 0 20px rgba(171, 133, 255, 0.2);
}
#wallet-address {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-2);
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(139, 62, 255, 0.1);
}

/* ============================================================
   CREATE AGENT PANEL
   ============================================================ */
#btn-create-agent {
  position: fixed;
  top: 56px;
  left: 16px;
  z-index: 80;
  border: 1px solid rgba(255, 126, 182, 0.35);
  background: linear-gradient(135deg, rgba(255, 126, 182, 0.15), rgba(139, 62, 255, 0.15));
  backdrop-filter: blur(10px);
  color: var(--text-1);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  box-shadow: 0 0 24px rgba(255, 126, 182, 0.2);
  transition: all 0.25s;
}
#btn-create-agent:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 36px rgba(255, 126, 182, 0.3);
}

#create-agent-panel {
  position: fixed;
  top: 96px;
  left: 16px;
  width: 340px;
  max-height: calc(100vh - 140px);
  overflow: auto;
  z-index: 85;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  backdrop-filter: blur(14px);
  box-shadow: 0 0 40px rgba(139, 62, 255, 0.18);
  animation: panelSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.oc-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(139, 62, 255, 0.1);
}
.oc-panel-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
}

.oc-panel-body {
  padding: 14px 16px;
  display: grid;
  gap: 8px;
}

.oc-panel-body label {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.oc-panel-body input,
.oc-panel-body select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(139, 62, 255, 0.15);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-1);
  font-size: 12px;
  font-family: var(--sans);
  outline: none;
  transition: border-color 0.2s;
}
.oc-panel-body input:focus,
.oc-panel-body select:focus {
  border-color: rgba(139, 62, 255, 0.3);
}

.payment-badge {
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 126, 182, 0.08);
  border: 1px solid rgba(255, 126, 182, 0.2);
  color: var(--pink);
  margin-bottom: 8px;
}

.tier-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 6px;
}
.tier-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid rgba(139, 62, 255, 0.12);
  background: rgba(11, 6, 18, 0.6);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.tier-btn:hover {
  border-color: rgba(139, 62, 255, 0.3);
}
.tier-btn.active {
  border-color: var(--purple);
  background: rgba(139, 62, 255, 0.08);
}
.tier-label {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
}
.tier-desc {
  font-family: var(--sans);
  font-size: 9px;
  color: var(--text-3);
  text-align: center;
}
#ca-byok-fields {
  padding: 8px 0;
}
#ca-byok-fields.hidden {
  display: none;
}

.telegram-link-btn {
  display: block;
  text-align: center;
  padding: 12px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0088cc, #229ED9);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  font-family: var(--sans);
  margin-top: 8px;
  transition: all 0.2s;
}
.telegram-link-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 20px rgba(0, 136, 204, 0.3);
}

.field-hint {
  font-size: 9px;
  color: var(--text-3);
  line-height: 1.3;
}
.field-hint a {
  color: var(--purple);
  text-decoration: none;
}

#ca-log {
  margin-top: 8px;
  min-height: 70px;
  max-height: 160px;
  overflow: auto;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(139, 62, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
  color: #b0a8cc;
  font-size: 10px;
  font-family: var(--mono);
  line-height: 1.4;
  white-space: pre-wrap;
}

/* ============================================================
   AGENT DASHBOARD (CHAT + TERMINAL)
   ============================================================ */
#agent-dashboard {
  position: fixed;
  top: 38px;
  right: 0;
  width: 420px;
  height: calc(100vh - 38px);
  z-index: 90;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  animation: dashSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes dashSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.dash-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(139, 62, 255, 0.1);
}
.dash-header span:first-child {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
}
.dash-status {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 10px;
  background: rgba(106, 99, 132, 0.15);
  color: var(--text-3);
}
.dash-status.active {
  background: rgba(60, 255, 107, 0.1);
  color: var(--green);
}

.dash-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Chat Panel ──────────────────────────────────────────── */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid rgba(139, 62, 255, 0.08);
  min-height: 0;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--purple), rgba(139, 62, 255, 0.6));
  color: var(--text-1);
  border-bottom-right-radius: 4px;
}
.chat-msg.agent {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(139, 62, 255, 0.1);
  color: var(--text-1);
  border-bottom-left-radius: 4px;
}
.chat-msg.system {
  align-self: center;
  font-size: 10px;
  color: var(--text-3);
  font-style: italic;
}
.chat-role {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-3);
  margin-bottom: 3px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid rgba(139, 62, 255, 0.06);
}
.chat-input-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(139, 62, 255, 0.12);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text-1);
  font-size: 12px;
  font-family: var(--sans);
  outline: none;
}
.chat-input-row input:focus {
  border-color: rgba(139, 62, 255, 0.25);
}
.chat-input-row button {
  padding: 10px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: var(--text-1);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.2s;
}
.chat-input-row button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 16px rgba(255, 126, 182, 0.2);
}

/* ── Terminal Panel ──────────────────────────────────────── */
#terminal-panel {
  height: 260px;
  display: flex;
  flex-direction: column;
}
.terminal-header {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  border-bottom: 1px solid rgba(139, 62, 255, 0.06);
}
#terminal-iframe {
  flex: 1;
  border: none;
  width: 100%;
  background: #0a0a0a;
  border-radius: 0 0 0 0;
}

/* ── Typing Indicator ─────────────────────────────────────── */
.typing-dots {
  display: inline-flex;
  gap: 3px;
}
.typing-dots span {
  animation: typingBounce 1.2s infinite ease-in-out;
  font-size: 18px;
  line-height: 1;
  color: var(--purple);
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-4px); }
}

/* ── My Agents Button ──────────────────────────────────────── */
#btn-my-agents {
  position: fixed;
  top: 56px;
  left: 160px;
  z-index: 80;
  border: 1px solid rgba(60, 255, 107, 0.3);
  background: rgba(60, 255, 107, 0.08);
  backdrop-filter: blur(10px);
  color: var(--green);
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.25s;
}
#btn-my-agents:hover {
  background: rgba(60, 255, 107, 0.14);
  box-shadow: 0 0 20px rgba(60, 255, 107, 0.15);
}

/* ── Agent List ──────────────────────────────────────── */
#agent-list {
  padding: 12px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.agent-list-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(139, 62, 255, 0.12);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agent-list-item .agent-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.agent-list-item .agent-model {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}
.agent-list-item .agent-tier {
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
}
.agent-list-item .agent-status-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
}
.agent-status-badge.active {
  background: rgba(60, 255, 107, 0.1);
  color: var(--green);
}
.agent-status-badge.pending {
  background: rgba(255, 189, 46, 0.1);
  color: #FFBD2E;
}
.agent-status-badge.failed {
  background: rgba(230, 57, 70, 0.1);
  color: var(--red);
}
.agent-list-item .agent-actions {
  display: flex;
  gap: 8px;
}
.agent-list-item .btn-chat-agent {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: var(--text-1);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.2s;
}
.btn-chat-agent:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 16px rgba(255, 126, 182, 0.2);
}
.btn-chat-agent:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.agent-list-item .btn-tg-agent {
  padding: 8px 12px;
  border: 1px solid rgba(0, 136, 204, 0.3);
  border-radius: 10px;
  background: rgba(0, 136, 204, 0.08);
  color: #0088cc;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--sans);
  text-decoration: none;
  text-align: center;
}

/* ── Chat Panel (reworked) ──────────────────────────────────── */
#chat-panel {
  position: fixed;
  top: 38px;
  right: 0;
  width: 420px;
  height: calc(100vh - 38px);
  z-index: 95;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  animation: dashSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--purple), rgba(139, 62, 255, 0.6));
  color: var(--text-1);
  border-bottom-right-radius: 4px;
}
.chat-msg.agent {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(139, 62, 255, 0.1);
  color: var(--text-1);
  border-bottom-left-radius: 4px;
}
.chat-msg.system {
  align-self: center;
  font-size: 10px;
  color: var(--text-3);
  font-style: italic;
}
.chat-typing {
  align-self: flex-start;
  font-size: 11px;
  color: var(--text-3);
  padding: 8px 12px;
}

@media (max-width: 900px) {
  #agent-dashboard { width: 100%; }
  #chat-panel { width: 100%; }
}
