:root {
  --bg-main: #0b0f14;
  --bg-sidebar: #0f141c;
  --bg-card: #151b24;
  --bg-card-hover: #1c2430;
  --bg-input: #121822;
  --border-subtle: #232d3d;
  --border-focus: #10b981;
  
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.2);
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* SIDEBAR */
.sidebar {
  width: 320px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-logo {
  font-size: 24px;
  background: var(--bg-card);
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--accent-emerald);
  box-shadow: 0 0 12px var(--accent-emerald-glow);
}

.brand h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.subbrand {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.close-sidebar-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.sidebar-section-title {
  padding: 16px 20px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.agent-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.agent-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background-color: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.agent-item:hover {
  background-color: var(--bg-card-hover);
}

.agent-item.active {
  background-color: var(--bg-card);
  border-color: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald-glow);
}

.agent-avatar {
  font-size: 20px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background-color: var(--bg-main);
  border: 1px solid var(--border-subtle);
}

.agent-info {
  flex: 1;
  min-width: 0;
}

.agent-top-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.agent-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.agent-level {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: var(--bg-main);
  color: var(--accent-emerald);
  font-family: var(--font-mono);
}

.agent-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ente-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-card);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #d97706;
}

.ente-icon {
  font-size: 18px;
}

.ente-name {
  font-size: 12px;
  font-weight: 600;
  color: #fbbf24;
  display: block;
}

.ente-level {
  font-size: 10px;
  color: var(--text-dim);
}

.telemetry-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.telemetry-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--text-dim);
}

/* CHAT VIEWPORT */
.chat-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: var(--bg-main);
  position: relative;
}

.chat-header {
  padding: 14px 24px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-main);
  font-size: 22px;
  cursor: pointer;
}

.current-agent-avatar {
  font-size: 24px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--accent-emerald);
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-row h1 {
  font-size: 18px;
  font-weight: 700;
}

.badge-role {
  font-size: 11px;
  background-color: var(--bg-card);
  color: var(--accent-emerald);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.status-indicator {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.status-indicator.online {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid var(--accent-emerald);
}

.current-job {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.toggle-voice {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
}

.toggle-voice input {
  display: none;
}

.toggle-voice .slider {
  width: 34px;
  height: 18px;
  background-color: var(--bg-card);
  border-radius: 20px;
  position: relative;
  border: 1px solid var(--border-subtle);
  transition: 0.3s;
}

.toggle-voice .slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background-color: var(--text-dim);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle-voice input:checked + .slider {
  background-color: var(--accent-emerald);
}

.toggle-voice input:checked + .slider::after {
  transform: translateX(16px);
  background-color: white;
}

.identity-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: 0.2s;
}

.identity-btn:hover {
  border-color: var(--accent-emerald);
}

/* MESSAGES CONTAINER */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg-wrapper {
  display: flex;
  gap: 12px;
  max-width: 820px;
}

.msg-wrapper.david {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-wrapper.agent {
  align-self: flex-start;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.msg-bubble {
  background-color: var(--bg-card);
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}

.msg-wrapper.david .msg-bubble {
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-color: #334155;
  color: #f8fafc;
}

.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 11px;
}

.msg-sender {
  font-weight: 600;
  color: var(--accent-emerald);
}

.msg-wrapper.david .msg-sender {
  color: #fbbf24;
}

.msg-time {
  color: var(--text-dim);
  font-size: 10px;
}

.msg-content p {
  margin-bottom: 8px;
}

.msg-content p:last-child {
  margin-bottom: 0;
}

.msg-content ul {
  padding-left: 20px;
  margin-bottom: 8px;
}

.msg-actions {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-voice-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: 0.2s;
}

.play-voice-btn:hover {
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

/* INPUT BAR */
.chat-input-bar {
  padding: 16px 24px;
  background-color: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-prompts {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.quick-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  transition: 0.2s;
}

.quick-chip:hover {
  color: var(--accent-emerald);
  border-color: var(--accent-emerald);
}

.input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.mic-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 18px;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.mic-btn.recording {
  background-color: var(--accent-red);
  border-color: #dc2626;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.4);
}

.mic-pulse {
  display: none;
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--accent-red);
  animation: pulse-ring 1.25s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

.mic-btn.recording .mic-pulse {
  display: block;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

.textarea-wrapper {
  flex: 1;
  position: relative;
}

#messageInput {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-main);
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  transition: border-color 0.2s;
}

#messageInput:focus {
  border-color: var(--accent-emerald);
}

.voice-feedback {
  display: none;
  position: absolute;
  bottom: -22px;
  left: 12px;
  font-size: 11px;
  color: var(--accent-emerald);
  font-style: italic;
}

.voice-feedback.active {
  display: block;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background-color: var(--accent-emerald);
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  background-color: #059669;
}

/* IDENTITY DRAWER */
.identity-drawer {
  position: fixed;
  top: 0;
  right: -420px;
  width: 420px;
  height: 100vh;
  background-color: var(--bg-sidebar);
  border-left: 1px solid var(--border-subtle);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}

.identity-drawer.open {
  right: 0;
}

.drawer-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.close-drawer-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 14px;
}

.module-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-emerald);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.module-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.module-summary {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-box {
  background: var(--bg-card);
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.stat-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-emerald);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* RESPONSIVE MOBILE */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    height: 100vh;
  }
  .sidebar.open {
    transform: translateX(320px);
  }
  .menu-btn {
    display: block;
  }
  .close-sidebar-btn {
    display: block;
  }
  .identity-drawer {
    width: 100vw;
    right: -100vw;
  }
  .chat-header {
    padding: 12px 16px;
  }
  .messages-container {
    padding: 16px;
  }
  .chat-input-bar {
    padding: 12px 16px;
  }
}
