:root {
  --primary: #6366F1;
  --primary-hover: #818CF8;
  --primary-glow: rgba(99, 102, 241, 0.15);
  --bg: #09090B;
  --bg-card: rgba(24, 24, 27, 0.8);
  --bg-panel: rgba(14, 14, 16, 0.9);
  --surface-alt: #27272A;
  --text: #FAFAFA;
  --text-secondary: #A1A1AA;
  --text-muted: #71717A;
  --border: rgba(63, 63, 70, 0.5);
  --border-glow: rgba(99, 102, 241, 0.25);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Animated Grid Background (Aceternity-inspired) ===== */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-size: 48px 48px;
  background-image:
    linear-gradient(to right, rgba(63, 63, 70, 0.15) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(63, 63, 70, 0.15) 1px, transparent 1px);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 30%, black 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 30%, black 20%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  top: -40%;
  left: 30%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: ambientDrift 20s ease-in-out infinite alternate;
}
@keyframes ambientDrift {
  0% { transform: translate(0, 0); }
  100% { transform: translate(-15%, 10%); }
}

/* ===== Top Bar ===== */
.topbar {
  position: relative;
  z-index: 1;
  background: rgba(14, 14, 16, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.topbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--primary) 50%, transparent 100%);
  opacity: 0.4;
}
.topbar h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(135deg, #fff 0%, #a1a1aa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.topbar .badge {
  font-size: 10px;
  padding: 3px 10px;
  border-radius: 99px;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: white;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  box-shadow: 0 0 12px var(--primary-glow);
}
.topbar .hint {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Main Layout ===== */
.main {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Panel Header (shared) ===== */
.panel-header {
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ===== Left: Chat Panel ===== */
.chat-panel {
  width: 340px;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Chat bubbles */
.chat-msg {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.6;
  max-width: 88%;
  word-break: break-word;
  animation: msgSlide 0.3s ease;
}
@keyframes msgSlide {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.user {
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px var(--primary-glow);
}
.chat-msg.agent {
  background: var(--surface-alt);
  color: var(--text-secondary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  font-size: 12px;
  position: relative;
}
.chat-msg.agent::before {
  content: '🤖';
  position: absolute;
  left: -28px;
  top: 6px;
  font-size: 16px;
}
.chat-msg.action {
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.2);
  color: #86EFAC;
  align-self: flex-start;
  font-size: 11px;
  font-family: var(--mono);
  border-bottom-left-radius: 4px;
}

/* Chat input */
.chat-input-bar {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: rgba(14, 14, 16, 0.5);
}
.chat-input-bar input {
  flex: 1;
  padding: 10px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(39, 39, 42, 0.6);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: all 0.25s;
}
.chat-input-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: rgba(39, 39, 42, 0.9);
}
.chat-input-bar input:disabled {
  opacity: 0.5;
}
.chat-input-bar button {
  padding: 10px 20px;
  border-radius: 20px;
  border: none;
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: white;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.25s;
  box-shadow: 0 2px 12px var(--primary-glow);
}
.chat-input-bar button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--primary-glow);
}
.chat-input-bar button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Center: Rendered UI ===== */
.render-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(9, 9, 11, 0.5);
}
.render-panel .panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.render-panel .panel-header .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
#render-container {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ===== Right: JSON Panel ===== */
.json-panel {
  width: 380px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
#json-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
}
.json-entry {
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  animation: msgSlide 0.3s ease;
}
.json-entry-header {
  padding: 6px 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-family: var(--mono);
}
.json-entry-header.server {
  background: rgba(59, 130, 246, 0.1);
  color: #60A5FA;
  border-bottom: 1px solid rgba(59, 130, 246, 0.15);
}
.json-entry-header.client {
  background: rgba(34, 197, 94, 0.08);
  color: #86EFAC;
  border-bottom: 1px solid rgba(34, 197, 94, 0.12);
}
.json-entry pre {
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.3);
  color: #A1A1AA;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 280px;
  overflow-y: auto;
}

/* ===== A2UI Components (Client Theme) ===== */
.a2ui-surface {
  animation: surfaceIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes surfaceIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.a2ui-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.a2ui-row {
  display: flex;
  flex-direction: row;
  gap: 14px;
  flex-wrap: wrap;
}
.a2ui-row > * { flex: 1; min-width: 0; }

.a2ui-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.3s ease;
}
.a2ui-card:hover {
  border-color: var(--border-glow);
  box-shadow: 0 4px 32px rgba(0,0,0,0.3), 0 0 0 1px var(--border-glow);
}

/* Text */
.a2ui-text--h1 { font-size: 28px; font-weight: 800; line-height: 1.15; margin: 0; color: var(--text); letter-spacing: -0.5px; }
.a2ui-text--h2 { font-size: 22px; font-weight: 700; line-height: 1.25; margin: 0; color: var(--text); letter-spacing: -0.3px; }
.a2ui-text--h3 { font-size: 17px; font-weight: 600; line-height: 1.35; margin: 0; color: var(--text); }
.a2ui-text--h4 { font-size: 15px; font-weight: 600; margin: 0; color: var(--text); }
.a2ui-text--h5 { font-size: 14px; font-weight: 600; margin: 0; color: var(--text); }
.a2ui-text--body { font-size: 14px; line-height: 1.65; margin: 0; color: var(--text-secondary); }
.a2ui-text--caption { font-size: 12px; line-height: 1.5; margin: 0; color: var(--text-muted); }

/* Button */
.a2ui-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--font);
  gap: 6px;
  position: relative;
  overflow: hidden;
}
.a2ui-button > * { margin: 0; color: inherit; }
.a2ui-button--primary {
  background: linear-gradient(135deg, var(--primary), #8B5CF6);
  color: white;
  box-shadow: 0 2px 12px var(--primary-glow);
}
.a2ui-button--primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.3);
}
.a2ui-button--primary:active { transform: translateY(0); }
.a2ui-button--secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.a2ui-button--secondary:hover {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border-glow);
}
.a2ui-button--tertiary {
  background: transparent;
  color: var(--text-muted);
  border: none;
}
.a2ui-button--tertiary:hover { color: var(--text); }

/* TextField */
.a2ui-textfield {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.a2ui-textfield label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.a2ui-textfield input,
.a2ui-textfield textarea {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.6);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: all 0.25s;
  resize: vertical;
}
.a2ui-textfield input:focus,
.a2ui-textfield textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Checkbox */
.a2ui-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: color 0.2s;
}
.a2ui-checkbox:hover { color: var(--text); }
.a2ui-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Divider */
.a2ui-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* List */
.a2ui-list {
  display: flex;
  gap: 10px;
}
.a2ui-list--vertical { flex-direction: column; }
.a2ui-list--horizontal { flex-direction: row; overflow-x: auto; }
.a2ui-list--horizontal > * { flex-shrink: 0; }

/* Image */
.a2ui-image {
  border-radius: var(--radius-sm);
  object-fit: cover;
  max-width: 100%;
}
.a2ui-image--icon { width: 24px; height: 24px; border-radius: 4px; }
.a2ui-image--avatar { width: 40px; height: 40px; border-radius: 50%; }
.a2ui-image--smallFeature { width: 80px; height: 80px; }
.a2ui-image--mediumFeature { width: 160px; height: 120px; }
.a2ui-image--largeFeature { width: 100%; max-height: 240px; }

.a2ui-icon { font-size: 20px; }

/* Choice Picker */
.a2ui-choice-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.a2ui-choice-picker__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.a2ui-choice-picker__option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  transition: all 0.2s;
  border: 1px solid transparent;
}
.a2ui-choice-picker__option:hover {
  background: rgba(99, 102, 241, 0.06);
  border-color: var(--border);
  color: var(--text);
}
.a2ui-choice-picker__option input[type="radio"] {
  accent-color: var(--primary);
  cursor: pointer;
}

/* Slider */
.a2ui-slider {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.a2ui-slider label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.a2ui-slider input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}
.a2ui-slider__value {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  align-self: flex-end;
  font-family: var(--mono);
}

/* Modal */
.a2ui-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.a2ui-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 16px 64px rgba(0,0,0,0.5);
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(113, 113, 122, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(113, 113, 122, 0.5); }
