:root {
  --bg-main: #0b0f19;
  --bg-sidebar: #0f172a;
  --bg-card: rgba(18, 24, 38, 0.75);
  --bg-bubble-user: #4f46e5;
  --bg-bubble-bot: rgba(30, 41, 59, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --accent-cyan: #06b6d4;
  --accent-indigo: #6366f1;
  --accent-green: #10b981;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --sidebar-width: 280px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

/* Sidebar Overlay */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 40;
}

#sidebar-overlay.active {
  display: block;
}

/* Sidebar Layout */
#sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    transform: translateX(-100%);
  }
  #sidebar.open {
    transform: translateX(0);
  }
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.btn-new-chat {
  width: 100%;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(6, 182, 212, 0.2));
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-new-chat:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.35), rgba(6, 182, 212, 0.35));
  border-color: var(--accent-cyan);
}

.conversations-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}

.sidebar-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 8px 8px 4px 8px;
  font-weight: 600;
}

#conversations-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #cbd5e1;
  transition: background 0.15s ease;
  position: relative;
}

.conv-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: white;
}

.conv-item.active {
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: white;
  font-weight: 500;
}

.conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-right: 6px;
}

.btn-del-conv {
  opacity: 0;
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: opacity 0.2s ease;
}

.conv-item:hover .btn-del-conv {
  opacity: 1;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

.server-status-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
}

.server-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.server-info {
  display: flex;
  flex-direction: column;
}

.server-name {
  font-size: 12px;
  font-weight: 600;
}

.server-model {
  font-size: 10px;
  color: var(--accent-cyan);
}

/* Main Chat Wrapper */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Header */
header {
  height: 60px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
}

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

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.brand-info h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--accent-green);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 16px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--accent-cyan);
}

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

.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

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

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

.bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--bg-bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.bot .bubble {
  background: var(--bg-bubble-bot);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* Tools Accordion */
.tool-box {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  font-size: 13px;
}

.tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--accent-cyan);
  font-weight: 500;
  cursor: pointer;
}

.tool-content {
  margin-top: 6px;
  color: var(--text-muted);
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
  display: none;
}

.tool-content.open {
  display: block;
}

.msg-image {
  max-width: 100%;
  border-radius: 10px;
  margin-top: 8px;
  border: 1px solid var(--border-color);
}

/* Attachment Preview */
.attachment-preview {
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: 8px;
  padding: 6px 12px;
  margin: 0 16px 8px 16px;
  font-size: 13px;
  animation: fadeIn 0.2s ease;
}

.attachment-preview.active {
  display: flex;
}

.attachment-name {
  flex: 1;
  color: var(--accent-cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.btn-remove-attachment {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-remove-attachment:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* Input Bar */
#input-bar {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 12px 18px;
  color: var(--text-main);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease;
}

#chat-input:focus {
  border-color: var(--accent-indigo);
}

.btn-action, .btn-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}

.btn-action {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

.btn-action:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-action.recording {
  background: #ef4444;
  animation: pulse 1s infinite;
}

.btn-send {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  color: white;
}

.btn-send:active, .btn-action:active {
  transform: scale(0.92);
}

/* Typing Indicator */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 8px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--accent-cyan);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-card {
  background: #131b2e;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-card h3 {
  margin-bottom: 12px;
  color: var(--accent-cyan);
}

.metric-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

/* Logout Button */
.btn-logout {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
  color: #f87171;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
}

/* Auth / Lock Modal */
.auth-card {
  text-align: center;
  max-width: 380px;
  padding: 28px 24px;
  background: #0f172a;
  border: 1px solid rgba(99, 102, 241, 0.4);
  box-shadow: 0 0 50px rgba(99, 102, 241, 0.2);
}

.auth-header h3 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-main);
  margin-bottom: 4px;
}

.auth-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.auth-input-group {
  margin-bottom: 16px;
}

.auth-input-group input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: white;
  font-size: 14px;
  outline: none;
  text-align: center;
  letter-spacing: 1px;
  transition: border-color 0.2s ease;
}

.auth-input-group input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.btn-login-submit {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.btn-login-submit:active {
  transform: scale(0.98);
}

.auth-error-msg {
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  color: #fca5a5;
  font-size: 12px;
  margin-bottom: 14px;
  animation: fadeIn 0.2s ease;
}
