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

:root {
  --bg-sidebar:   #0f0f0f;
  --bg-main:      #1a1a1a;
  --bg-input:     #2a2a2a;
  --bg-user-msg:  #2563eb;
  --bg-bot-msg:   #252525;
  --bg-card:      #202020;
  --bg-hover:     #2a2a2a;
  --border:       #333;
  --text-primary: #e8e8e8;
  --text-secondary:#999;
  --text-muted:   #666;
  --accent:       #5865F2;
  --accent-hover: #4752c4;
  --success:      #23a55a;
  --danger:       #f23f43;
  --warning:      #e8a838;
  --sidebar-w:    260px;
  --radius:       12px;
  --radius-sm:    8px;
  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg-main);
  color: var(--text-primary);
  display: flex;
}

/* ────────────────────────────────────────────
   Layout
   ──────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  height: 100vh;
  overflow: hidden;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ────────────────────────────────────────────
   Sidebar
   ──────────────────────────────────────────── */
.sidebar-header {
  padding: 18px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-title svg { color: var(--accent); }

.new-chat-btn {
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: #333; }

/* Guild selector */
.guild-section {
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.guild-select {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}
.guild-select:focus { border-color: var(--accent); }
.guild-select option { background: #1a1a1a; }

/* Mode toggle */
.mode-section {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 11px;
  transition: background 0.2s;
}
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--accent); }
.toggle-switch input:checked ~ .toggle-thumb { transform: translateX(18px); }

/* History */
.history-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

/* User info at bottom */
.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.logout-btn:hover { color: var(--danger); }

/* ────────────────────────────────────────────
   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-main);
  flex-shrink: 0;
}

.guild-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ────────────────────────────────────────────
   Messages
   ──────────────────────────────────────────── */
#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scrollbar-width: thin;
  scrollbar-color: #333 transparent;
}

.messages-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.2s ease;
}
.msg.user { flex-direction: row-reverse; }

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  background: var(--accent);
  object-fit: cover;
}
.msg.bot .msg-avatar { background: #5865F2; }

.msg-body { max-width: 72%; display: flex; flex-direction: column; gap: 4px; }
.msg.user .msg-body { align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

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

.msg.bot .msg-bubble {
  background: var(--bg-bot-msg);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

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

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.2s ease;
}
.typing-dots {
  background: var(--bg-bot-msg);
  padding: 14px 18px;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.typing-dots span {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* Approval card */
.approval-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 4px;
}
.approval-card .card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.approval-card .plan-list {
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
  margin-bottom: 14px;
}
.approval-card.critical .card-title { color: var(--warning); }
.approval-card.critical { border-color: var(--warning); }

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

.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-approve { background: var(--success); color: #fff; }
.btn-approve:hover { background: #1f9149; }
.btn-cancel  { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-cancel:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ────────────────────────────────────────────
   Input area
   ──────────────────────────────────────────── */
#input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-main);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }

#message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  max-height: 160px;
  min-height: 24px;
  line-height: 1.5;
}
#message-input::placeholder { color: var(--text-muted); }

#send-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
  color: #fff;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  max-width: 780px;
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* ────────────────────────────────────────────
   Login screen
   ──────────────────────────────────────────── */
#login-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 40px;
}

.login-logo {
  width: 72px;
  height: 72px;
  background: var(--accent);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
}

.login-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 400px;
  line-height: 1.6;
}

.login-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  background: #5865F2;
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
  transition: background 0.15s, transform 0.1s;
}
.login-btn:hover { background: #4752c4; transform: translateY(-1px); }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 480px;
  margin-top: 8px;
}

.feature-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ────────────────────────────────────────────
   Empty state
   ──────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
  padding: 40px;
}

.empty-state h2 { font-size: 22px; color: var(--text-secondary); }
.empty-state p  { font-size: 14px; text-align: center; max-width: 380px; line-height: 1.6; }

.example-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.example-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.example-chip:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--text-primary); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #444; }

/* Markdown-like in bot messages */
.msg-bubble strong { font-weight: 700; }
.msg-bubble em     { font-style: italic; }
.msg-bubble code   { background: rgba(255,255,255,0.1); padding: 1px 5px; border-radius: 4px; font-family: monospace; font-size: 0.9em; }

@media (max-width: 640px) {
  #sidebar { display: none; }
  .example-prompts { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
