/* Agente Mike — Chat UI styles */

:root {
  --bg: #0f1117;
  --bg-surface: #1a1d27;
  --bg-input: #20232f;
  --border: #2e3148;
  --text: #e2e5f0;
  --text-muted: #8b90a7;
  --primary: #5d6af1;
  --primary-hover: #4a56d8;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --user-bubble: #1e2340;
  --bot-bubble: #252a3d;
  --sidebar-width: 280px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

#sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

#sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.3px;
}

#sidebar-header p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

#status-bar {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.status-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.status-badge.ok { border-color: var(--success); color: var(--success); }
.status-badge.err { border-color: var(--danger); color: var(--danger); }

/* Boxes section */
#boxes-section {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

#boxes-section h2 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.box-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  gap: 8px;
  transition: background 0.15s;
}

.box-item:hover { background: rgba(93,106,241,0.12); }

.box-item .box-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(93,106,241,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.box-item .box-info { flex: 1; min-width: 0; }
.box-item .box-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box-item .box-id { font-size: 11px; color: var(--text-muted); }

.box-item .box-remove {
  opacity: 0;
  cursor: pointer;
  color: var(--danger);
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  transition: opacity 0.15s, background 0.15s;
}
.box-item:hover .box-remove { opacity: 1; }
.box-item .box-remove:hover { background: rgba(248,113,113,0.15); }

#no-boxes {
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  padding: 16px 8px;
  line-height: 1.5;
}

/* Add box form */
#add-box-form {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
}

#add-box-form input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

#add-box-form input:focus { border-color: var(--primary); }
#add-box-form input::placeholder { color: var(--text-muted); }

#add-box-btn {
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#add-box-btn:hover { background: var(--primary-hover); }

/* ── Chat area ────────────────────────────────────────────────────── */

#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

#chat-header .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

#chat-header .title { font-weight: 600; font-size: 15px; }
#chat-header .subtitle { font-size: 12px; color: var(--text-muted); }

#conn-indicator {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}
#conn-indicator.connected { background: var(--success); }
#conn-indicator.thinking { background: var(--warning); animation: pulse 1s infinite; }

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

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

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: fadeUp 0.2s ease-out;
}

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

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

.message .msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .msg-avatar {
  background: rgba(93,106,241,0.3);
}

.message.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
}

.message .bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--bot-bubble);
  border-bottom-left-radius: 4px;
}

/* Markdown-like formatting inside bubbles */
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; color: var(--text-muted); }
.bubble code {
  background: rgba(0,0,0,0.3);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 12px;
  color: #a5f3fc;
}
.bubble pre code {
  display: block;
  padding: 10px;
  margin-top: 4px;
  overflow-x: auto;
  background: rgba(0,0,0,0.4);
  border-radius: var(--radius-sm);
}
.bubble ul, .bubble ol { padding-left: 18px; margin: 4px 0; }
.bubble li { margin: 2px 0; }
.bubble blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 10px;
  color: var(--text-muted);
  margin: 4px 0;
}
.bubble a { color: var(--primary); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }

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

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: 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 bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Welcome message */
#welcome {
  text-align: center;
  padding: 40px 20px;
  max-width: 480px;
  margin: auto;
}

#welcome .icon { font-size: 48px; margin-bottom: 12px; }
#welcome h2 { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
#welcome p { color: var(--text-muted); font-size: 14px; line-height: 1.6; }

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  justify-content: center;
}

.chip {
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text-muted);
}

.chip:hover {
  border-color: var(--primary);
  color: var(--text);
  background: rgba(93,106,241,0.1);
}

/* ── Input area ───────────────────────────────────────────────────── */

#input-area {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}

#input-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#message-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.15s;
  font-family: inherit;
}

#message-input:focus { border-color: var(--primary); }
#message-input::placeholder { color: var(--text-muted); }

#send-btn {
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) { background: var(--primary-hover); transform: scale(1.05); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#send-btn svg { width: 18px; height: 18px; fill: white; }

#input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
}

/* ── Responsive ───────────────────────────────────────────────────── */

@media (max-width: 640px) {
  #sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.25s ease;
  }

  #sidebar.open { left: 0; }

  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  #sidebar.open ~ #sidebar-overlay { display: block; }

  #menu-btn { display: flex !important; }
  .message { max-width: 95%; }
}

#menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font-size: 22px;
  padding: 2px;
}
