:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --sidebar: #111827;
  --sidebar-soft: #1f2937;
  --sidebar-text: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #7c3aed;
  --accent-2: #22c55e;
  --user-bubble: #ede9fe;
  --ai-bubble: #ffffff;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

body.dark {
  --bg: #0b1020;
  --panel: #111827;
  --sidebar: #070b14;
  --sidebar-soft: #151c2d;
  --sidebar-text: #e5e7eb;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #263041;
  --accent: #8b5cf6;
  --accent-2: #34d399;
  --user-bubble: #2f2452;
  --ai-bubble: #111827;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { display: flex; height: 100vh; width: 100%; }

.sidebar {
  width: 280px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 16px;
  flex-shrink: 0;
  z-index: 30;
}
.sidebar-top { display: grid; gap: 18px; }
.brand-row { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.brand-text { font-weight: 800; letter-spacing: 0.14em; font-size: 15px; }
.brand-mark { width: 38px; height: 38px; position: relative; flex: 0 0 38px; }
.brand-mark.large { width: 66px; height: 66px; transform: scale(1.35); }
.node { position: absolute; width: 8px; height: 8px; background: #a78bfa; border-radius: 50%; box-shadow: 0 0 14px rgba(167,139,250,.65); z-index: 2; }
.n1 { left: 4px; top: 15px; }
.n2 { left: 16px; top: 4px; }
.n3 { right: 3px; top: 16px; }
.n4 { left: 16px; bottom: 3px; background: #34d399; }
.link { position: absolute; height: 2px; background: linear-gradient(90deg, #8b5cf6, #34d399); transform-origin: left center; opacity: .9; }
.l1 { width: 18px; left: 8px; top: 17px; transform: rotate(-38deg); }
.l2 { width: 18px; left: 20px; top: 9px; transform: rotate(38deg); }
.l3 { width: 21px; left: 18px; top: 22px; transform: rotate(88deg); }

.new-chat-btn {
  border: 1px solid rgba(255,255,255,.12);
  background: var(--sidebar-soft);
  color: white;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.new-chat-btn:hover { background: #2b3548; }

.history-section { flex: 1; min-height: 0; margin-top: 22px; display: flex; flex-direction: column; }
.section-label { color: #9ca3af; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin: 0 8px 10px; }
.chat-history { overflow-y: auto; display: grid; gap: 6px; padding-right: 4px; }
.history-item {
  width: 100%; border: 0; color: #d1d5db; background: transparent; text-align: left;
  padding: 10px 11px; border-radius: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item:hover, .history-item.active { background: var(--sidebar-soft); color: white; }
.empty-history { color: #6b7280; font-size: 13px; padding: 10px 8px; }

.sidebar-bottom { display: grid; gap: 6px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.sidebar-action { border: 0; background: transparent; color: #d1d5db; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; text-align: left; }
.sidebar-action:hover { background: var(--sidebar-soft); color: white; }
.sidebar-action.danger:hover { color: #fca5a5; }

.main-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar { height: 64px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 22px; background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px); }
.topbar-title { font-weight: 800; letter-spacing: .08em; }
.status-pill { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; border: 1px solid var(--border); padding: 6px 9px; border-radius: 999px; background: var(--panel); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 8px rgba(34,197,94,.5); }

.chat-area { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.welcome { min-height: 100%; max-width: 900px; margin: 0 auto; padding: 70px 24px 130px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.welcome-logo { margin-bottom: 22px; }
.welcome h1 { margin: 0; font-size: clamp(30px, 4vw, 46px); letter-spacing: -.04em; }
.welcome-subtitle { max-width: 670px; color: var(--muted); line-height: 1.7; margin: 16px 0 30px; }
.suggestions { width: 100%; max-width: 760px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.suggestion-card { text-align: left; border: 1px solid var(--border); background: var(--panel); color: var(--text); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); transition: .2s ease; }
.suggestion-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.suggestion-card strong { display: block; margin-bottom: 6px; }
.suggestion-card span { color: var(--muted); font-size: 13px; line-height: 1.45; }

.messages { max-width: 860px; margin: 0 auto; padding: 34px 24px 150px; display: none; }
.messages.active { display: block; }
.message-row { display: grid; grid-template-columns: 36px 1fr; gap: 12px; margin-bottom: 26px; }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.message-row.user .avatar { background: var(--accent); color: white; }
.message-row.ai .avatar { background: #111827; color: #a7f3d0; border: 1px solid #374151; }
.message-meta { font-size: 12px; color: var(--muted); margin: 1px 0 7px; font-weight: 700; }
.message-bubble { border: 1px solid var(--border); background: var(--ai-bubble); border-radius: 16px; padding: 14px 16px; line-height: 1.65; white-space: pre-wrap; box-shadow: 0 8px 24px rgba(15,23,42,.04); }
.message-row.user .message-bubble { background: var(--user-bubble); border-color: transparent; }
.message-actions { display: flex; gap: 8px; margin-top: 8px; min-height: 30px; }
.action-btn { border: 1px solid var(--border); background: var(--panel); color: var(--muted); border-radius: 9px; padding: 6px 9px; font-size: 12px; }
.action-btn:hover { color: var(--text); }

.composer-wrap { position: sticky; bottom: 0; padding: 12px 20px 18px; background: linear-gradient(180deg, transparent, var(--bg) 28%); }
.composer { max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 10px 10px 10px 16px; box-shadow: var(--shadow); }
#messageInput { flex: 1; resize: none; max-height: 180px; min-height: 26px; border: 0; outline: none; background: transparent; color: var(--text); line-height: 1.5; padding: 5px 0; }
#messageInput::placeholder { color: var(--muted); }
.send-btn { width: 42px; height: 42px; border-radius: 13px; border: 0; background: var(--accent); color: white; font-size: 18px; display: grid; place-items: center; transition: .2s ease; }
.send-btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.composer-note { max-width: 860px; margin: 7px auto 0; text-align: center; color: var(--muted); font-size: 11px; }

.icon-btn { border: 0; background: transparent; color: inherit; font-size: 22px; padding: 6px; border-radius: 8px; }
.mobile-only { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 820px) {
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-102%); transition: transform .22s ease; width: min(86vw, 300px); box-shadow: 22px 0 60px rgba(0,0,0,.24); }
  .sidebar.open { transform: translateX(0); }
  .brand-row .mobile-only { margin-left: auto; color: #d1d5db; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 20; }
  .sidebar-overlay.show { display: block; }
  .topbar { padding: 0 14px; }
  .welcome { padding-top: 42px; }
  .suggestions { grid-template-columns: 1fr; }
  .messages { padding-left: 14px; padding-right: 14px; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
}

@media (max-width: 480px) {
  .status-pill { display: none; }
  .welcome { justify-content: flex-start; padding-top: 70px; }
  .welcome h1 { font-size: 31px; }
  .message-row { grid-template-columns: 30px 1fr; gap: 9px; }
  .avatar { width: 30px; height: 30px; border-radius: 9px; }
  .message-bubble { padding: 12px 13px; }
}
