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

:root {
  --bg-deep:    #050507;
  --bg-surface: #0a0a0f;
  --bg-card:    #111118;
  --bg-hover:   #16161f;
  --bg-input:   #0d0d14;
  --border:     #1a1a2e;
  --border-active: #0ea5e9;
  --morfo:      #0ea5e9;
  --morfo-dim:  #0ea5e933;
  --morfo-glow: #0ea5e944;
  --text:       #e4e4e7;
  --text-dim:   #71717a;
  --text-muted: #52525b;
  --danger:     #ef4444;
  --success:    #22c55e;
  --radius:     10px;
  --radius-sm:  6px;
  --sidebar-w:  260px;
  --font:       'Exo 2', system-ui, sans-serif;
  --mono:       'JetBrains Mono', monospace;
}

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.logo-icon {
  color: var(--morfo);
  font-size: 22px;
  filter: drop-shadow(0 0 8px var(--morfo-glow));
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.logo-text .accent {
  color: var(--morfo);
}

/* ── Agent buttons ── */
#agents {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.agent-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font);
  text-align: left;
  width: 100%;
}

.agent-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.agent-btn.active {
  background: var(--morfo-dim);
  border-color: var(--morfo);
  box-shadow: 0 0 20px var(--morfo-glow), inset 0 0 20px var(--morfo-dim);
}

.agent-btn .agent-icon {
  font-size: 18px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--bg-card);
  flex-shrink: 0;
}

.agent-btn.active .agent-icon {
  background: var(--morfo);
  color: #000;
}

.agent-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.agent-name {
  font-weight: 600;
  font-size: 14px;
}

.agent-desc {
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Sidebar footer ── */
.sidebar-footer {
  display: flex;
  gap: 6px;
}

.stats-btn, .clear-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  transition: all 0.15s ease;
}

.stats-btn:hover, .clear-btn:hover {
  border-color: var(--morfo);
  color: var(--text);
}

/* ── Main ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-deep);
}

/* ── Chat header ── */
#chat-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

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

.header-agent .agent-icon {
  font-size: 18px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--morfo);
  color: #000;
}

#header-title {
  font-size: 16px;
  font-weight: 600;
}

.header-model {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
}

.status {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
}

.status.loading {
  color: var(--morfo);
}

.status.error {
  color: var(--danger);
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Welcome screen ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  gap: 16px;
  padding: 40px 20px;
}

.welcome-icon {
  font-size: 48px;
  color: var(--morfo);
  filter: drop-shadow(0 0 24px var(--morfo-glow));
  margin-bottom: 8px;
}

.welcome h2 {
  font-size: 22px;
  font-weight: 600;
}

.welcome p {
  color: var(--text-dim);
  max-width: 400px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  max-width: 500px;
}

.quick-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  transition: all 0.15s ease;
}

.quick-btn:hover {
  border-color: var(--morfo);
  background: var(--morfo-dim);
}

/* ── Message bubbles ── */
.msg {
  max-width: 780px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeIn 0.2s ease;
}

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

.msg.user {
  align-self: flex-end;
}

.msg.assistant {
  align-self: flex-start;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.65;
  word-break: break-word;
}

.msg.user .msg-bubble {
  background: var(--morfo);
  color: #000;
  border-bottom-right-radius: 2px;
  font-weight: 450;
}

.msg.assistant .msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
  display: flex;
  gap: 12px;
}

.msg.user .msg-meta {
  align-self: flex-end;
}

/* ── Markdown in assistant messages ── */
.msg.assistant .msg-bubble h1,
.msg.assistant .msg-bubble h2,
.msg.assistant .msg-bubble h3 {
  margin: 12px 0 6px;
  font-weight: 600;
}

.msg.assistant .msg-bubble h1 { font-size: 18px; }
.msg.assistant .msg-bubble h2 { font-size: 16px; }
.msg.assistant .msg-bubble h3 { font-size: 14px; color: var(--morfo); }

.msg.assistant .msg-bubble p {
  margin: 6px 0;
}

.msg.assistant .msg-bubble ul,
.msg.assistant .msg-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.msg.assistant .msg-bubble li {
  margin: 4px 0;
}

.msg.assistant .msg-bubble code {
  font-family: var(--mono);
  background: var(--bg-deep);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.msg.assistant .msg-bubble pre {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.msg.assistant .msg-bubble pre code {
  background: none;
  padding: 0;
  font-size: 13px;
}

.msg.assistant .msg-bubble strong {
  color: var(--morfo);
  font-weight: 600;
}

.msg.assistant .msg-bubble blockquote {
  border-left: 3px solid var(--morfo);
  padding-left: 12px;
  color: var(--text-dim);
  margin: 8px 0;
}

.msg.assistant .msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* ── Typing indicator ── */
.typing {
  display: flex;
  gap: 4px;
  padding: 16px;
}

.typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--morfo);
  animation: bounce 1.2s ease infinite;
}

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

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

/* ── Context panel ── */
.context-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 12px 24px;
  max-height: 200px;
  overflow-y: auto;
}

.context-panel.hidden { display: none; }

.context-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.context-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}

.context-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.context-field input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

.context-field input:focus {
  border-color: var(--morfo);
}

.context-field input::placeholder {
  color: var(--text-muted);
}

/* ── Input area ── */
.input-area {
  padding: 16px 24px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

.context-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.context-toggle:hover {
  border-color: var(--morfo);
  color: var(--morfo);
}

.context-toggle.open {
  background: var(--morfo);
  border-color: var(--morfo);
  color: #000;
}

#input {
  flex: 1;
  resize: none;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  max-height: 150px;
  outline: none;
  transition: border-color 0.15s ease;
}

#input:focus {
  border-color: var(--morfo);
}

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

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--morfo);
  color: #000;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.send-btn:disabled {
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  filter: brightness(1.15);
  box-shadow: 0 0 16px var(--morfo-glow);
}

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  overflow: hidden;
}

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

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

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

.stats-body {
  padding: 20px;
}

.stats-loading {
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-card .stat-agent {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--morfo);
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--mono);
}

.stat-card .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-card .stat-latency {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
  margin-top: 6px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #chat-header::before {
    content: '\2630';
    font-size: 20px;
    cursor: pointer;
    margin-right: 12px;
    color: var(--text-dim);
  }

  .quick-actions {
    flex-direction: column;
  }

  .context-fields {
    grid-template-columns: 1fr;
  }
}
