:root {
  --bg: #080705;
  --surface: #14100b;
  --surface-soft: #20180e;
  --ink: #fff6dd;
  --muted: #bba779;
  --line: #46361f;
  --primary: #d7a83f;
  --primary-ink: #100b04;
  --accent: #f2cf78;
  --danger: #ff7468;
  --success: #6fcf97;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  color-scheme: dark;
}

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

body {
  background: linear-gradient(180deg, #0f0c08 0%, var(--bg) 60%, #050403 100%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.header {
  padding: 14px 20px;
  background: #050403;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.header-brand .logo {
  font-size: 1.5rem;
}

.header-brand h1 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
}

.header-brand p {
  font-size: 0.72rem;
  color: var(--muted);
}

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

/* ── Layout ── */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1;
  min-height: 0;
}

@media (max-width: 700px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .sidebar.open { display: flex; position: fixed; inset: 0; z-index: 20; overflow-y: auto; }
}

/* ── Sidebar ── */
.sidebar {
  background: #050403;
  border-left: 1px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.sidebar-title {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 6px 4px 4px;
  text-transform: uppercase;
}

.category-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: right;
  width: 100%;
  font-size: 0.9rem;
  transition: all 0.15s;
}

.category-btn:hover, .category-btn.active {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--accent);
}

.category-btn .icon { font-size: 1.2rem; flex-shrink: 0; }

.quick-problem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  text-align: right;
  width: 100%;
  font-size: 0.82rem;
  transition: all 0.15s;
}

.quick-problem:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 8px 0;
}

/* ── Chat area ── */
.chat-area {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 58px);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome {
  max-width: 600px;
  margin: auto;
  text-align: center;
  padding: 40px 20px;
}

.welcome .big-icon { font-size: 3.5rem; margin-bottom: 16px; }
.welcome h2 { font-size: 1.5rem; color: var(--accent); margin-bottom: 10px; }
.welcome p { color: var(--muted); line-height: 1.8; font-size: 0.95rem; }

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 24px;
}

.quick-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: right;
  transition: all 0.15s;
}

.quick-card:hover {
  border-color: var(--primary);
  background: var(--surface-soft);
}

.quick-card .qc-icon { font-size: 1.4rem; margin-bottom: 6px; }
.quick-card .qc-title { font-size: 0.88rem; font-weight: 700; color: var(--accent); }
.quick-card .qc-desc { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* ── Messages ── */
.msg {
  display: flex;
  gap: 10px;
  max-width: 760px;
}

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

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.msg.assistant .msg-avatar { background: var(--primary); color: var(--primary-ink); }

.msg-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.75;
  font-size: 0.92rem;
  max-width: 560px;
}

.msg.user .msg-bubble {
  background: var(--primary);
  color: var(--primary-ink);
  border-radius: 14px 14px 4px 14px;
  font-weight: 600;
}

.msg.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px;
}

.msg-bubble ol, .msg-bubble ul {
  padding-right: 20px;
  margin: 8px 0;
}

.msg-bubble li { margin: 4px 0; }
.msg-bubble strong { color: var(--accent); }
.msg-bubble code {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  direction: ltr;
  display: inline-block;
}

.msg-bubble pre {
  background: #0a0806;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  direction: ltr;
  margin: 8px 0;
  font-size: 0.82rem;
}

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

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
  30% { opacity: 1; transform: scale(1.2); }
}

/* ── Input bar ── */
.input-bar {
  padding: 14px 20px;
  background: #050403;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-wrap {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  align-items: flex-end;
  padding: 8px 12px;
  gap: 8px;
}

.input-wrap:focus-within { border-color: var(--primary); }

#msg-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  resize: none;
  min-height: 24px;
  max-height: 140px;
  outline: none;
  line-height: 1.5;
}

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

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: var(--primary-ink);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── API Key modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}

.modal h2 { font-size: 1.2rem; color: var(--accent); margin-bottom: 8px; }
.modal p { color: var(--muted); font-size: 0.88rem; line-height: 1.7; margin-bottom: 16px; }

.modal label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

.modal input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  direction: ltr;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

/* ── Buttons ── */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.88rem;
}

.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-secondary { background: var(--surface-soft); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
