/* ADoong Chat Window — Figma "ADoong Web Agent" */

:root {
  /* Purple accent (from Figma) */
  --accent: #7C3AED;
  --accent-light: #A78BFA;
  --accent-dark: #5B21B6;
  --accent-bg: #EDE9FE;
  --accent-subtle: #F5F3FF;

  /* Chat */
  --chat-bg: #FAFAFA;
  --chat-header-bg: #FFFFFF;
  --msg-user-bg: #7C3AED;
  --msg-user-text: #FFFFFF;
  --msg-bot-bg: #FFFFFF;
  --msg-bot-text: #1F2937;

  /* Sidebar */
  --sidebar-bg: #1A1625;
  --sidebar-header: #231E30;
  --sidebar-text: #E0DFE4;
  --sidebar-muted: #9CA3AF;
  --sidebar-border: #2D2640;
  --sidebar-card: #2D2640;

  /* General */
  --text: #1F2937;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--chat-bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-app-region: no-drag;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ===== CHAT PANEL ===== */

#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--chat-bg);
}

/* Header */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--chat-header-bg);
  border-bottom: 1px solid var(--border);
  -webkit-app-region: drag;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  -webkit-app-region: no-drag;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.agent-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
}
.agent-name:hover {
  background: var(--accent-bg);
}
.chevron-down {
  opacity: 0.5;
  transition: transform 0.2s;
}
.agent-name.open .chevron-down {
  transform: rotate(180deg);
}

/* Agent Dropdown */
.agent-dropdown {
  position: absolute;
  top: 100%;
  left: 12px;
  width: 260px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 100;
  overflow: hidden;
  animation: dropdownIn 0.15s ease-out;
}
.agent-dropdown.hidden { display: none; }
@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.agent-dropdown-header {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.agent-list {
  max-height: 280px;
  overflow-y: auto;
  padding-bottom: 6px;
}
.agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.12s;
}
.agent-item:hover {
  background: var(--accent-subtle);
}
.agent-item.active {
  background: var(--accent-bg);
}
.agent-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.agent-item-info {
  flex: 1;
  min-width: 0;
}
.agent-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-item-id {
  font-size: 11px;
  color: var(--text-muted);
}
.agent-item .active-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s infinite;
}
@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.status-dot {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.connected::before { background: #10B981; }
.status-dot.disconnected::before { background: #9CA3AF; }
.status-dot.connecting::before { background: #F59E0B; animation: pulse-dot 1s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.header-right {
  display: flex;
  gap: 8px;
  -webkit-app-region: no-drag;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--accent-bg); color: var(--accent); }
.icon-btn-light { color: var(--sidebar-muted); }
.icon-btn-light:hover { background: var(--sidebar-card); color: white; }

/* Messages Area */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar { width: 6px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
#chat-messages::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* Welcome */
#welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0.9;
}

#welcome-screen h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.welcome-sub {
  color: var(--text-muted);
  font-size: 14px;
}

.welcome-bunny { width: 120px; height: 140px; }
.bunny-img { width: 100%; height: 100%; }

/* Message Bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: msg-in 0.2s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.bot { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.message.bot .msg-avatar { background: var(--accent-bg); }
.message.user .msg-avatar { background: var(--accent); color: white; font-size: 13px; font-weight: 600; }

.msg-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.bot .msg-content {
  background: var(--msg-bot-bg);
  color: var(--msg-bot-text);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
}

.message.user .msg-content {
  background: var(--msg-user-bg);
  color: var(--msg-user-text);
  border-top-right-radius: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message.user .msg-time { text-align: right; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-items: center;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-light);
  animation: typing-bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Skill execution card inside chat */
.msg-skill-card {
  background: var(--accent-subtle);
  border: 1px solid var(--accent-bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.skill-card-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.skill-card-info { flex: 1; }
.skill-card-name { font-weight: 600; color: var(--accent-dark); }
.skill-card-status { color: var(--text-muted); font-size: 12px; }

/* ===== INPUT AREA ===== */

#chat-input-area {
  padding: 12px 20px 16px;
  background: var(--chat-header-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #F3F4F6;
  border-radius: 20px;
  padding: 6px 6px 6px 16px;
  border: 2px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  background: white;
}

#chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 6px 0;
  font-family: inherit;
  color: var(--text);
}

#chat-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.send-btn:hover { background: var(--accent-dark); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn:disabled:hover { background: var(--accent); }

/* ===== SIDEBAR ===== */

#sidebar {
  width: 320px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--sidebar-border);
  transition: width 0.25s ease, opacity 0.2s;
  overflow: hidden;
  flex-shrink: 0;
}

#sidebar:not(.sidebar-open) {
  width: 0;
  opacity: 0;
  border: none;
}

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

.sidebar-title {
  font-weight: 600;
  font-size: 15px;
  color: white;
}

/* Tabs */
#sidebar-tabs {
  display: flex;
  padding: 8px 16px 0;
  gap: 4px;
  border-bottom: 1px solid var(--sidebar-border);
}

.tab-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--sidebar-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.tab-btn:hover { color: var(--sidebar-text); }
.tab-btn.active { color: var(--accent-light); border-bottom-color: var(--accent-light); }

/* Sidebar Content */
#sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

#sidebar-content::-webkit-scrollbar { width: 4px; }
#sidebar-content::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Skill Cards */
.sidebar-skill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.sidebar-skill:hover { background: var(--sidebar-card); }

.sidebar-skill-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

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

.sidebar-skill-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.sidebar-skill-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 500;
  flex-shrink: 0;
}

.sidebar-skill-badge.idle { background: var(--sidebar-card); color: var(--sidebar-muted); }

/* Empty state */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--sidebar-muted);
  font-size: 13px;
}

/* ===== Sidebar Footer (Gateway) ===== */

#sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 12px 16px;
  flex-shrink: 0;
}

#gateway-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.gw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6B7280;
  flex-shrink: 0;
}

.gw-dot.connected { background: #10B981; }
.gw-dot.connecting { background: #F59E0B; animation: pulse-dot 1s infinite; }

#gw-label {
  font-size: 12px;
  color: var(--sidebar-muted);
}

.connect-btn {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent-light);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}

.connect-btn:hover { background: var(--accent); color: white; }
.connect-btn.connected { border-color: #10B981; color: #10B981; }
.connect-btn.connected:hover { background: #10B981; color: white; }

/* ===== Markdown in messages ===== */

.msg-content strong { font-weight: 600; }
.msg-content em { font-style: italic; }

.msg-content .inline-code {
  background: #F3F4F6;
  color: #D946EF;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
}

.message.user .msg-content .inline-code {
  background: rgba(255,255,255,0.2);
  color: #FDE68A;
}

.msg-content .code-block {
  background: #1E1E2E;
  border-radius: 8px;
  margin: 8px 0 4px;
  overflow: hidden;
  position: relative;
}

.msg-content .code-block .code-lang {
  display: block;
  padding: 6px 12px;
  font-size: 11px;
  color: #9CA3AF;
  background: #161622;
  border-bottom: 1px solid #2D2D44;
  font-family: inherit;
}

.msg-content .code-block pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
}

.msg-content .code-block code {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #E0DEF4;
  white-space: pre;
}

.msg-content .msg-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

.msg-content .msg-link:hover { border-bottom-color: var(--accent); }
.message.user .msg-content .msg-link { color: #C4B5FD; }
.message.user .msg-content .msg-link:hover { border-bottom-color: #C4B5FD; }

.msg-content ul {
  margin: 6px 0;
  padding-left: 20px;
}

.msg-content li {
  margin: 2px 0;
}

/* ===== Image messages ===== */

.msg-image {
  margin-top: 8px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 360px;
}

.msg-image img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.2s;
}

.msg-image img.msg-image-expanded {
  max-width: none;
  width: auto;
  max-height: 80vh;
}

/* ===== Responsive ===== */

@media (max-width: 700px) {
  #sidebar { position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; }
  #sidebar:not(.sidebar-open) { width: 0; }
}
