:root {
  --bg: #0a0a0f;
  --bg-card: #14141c;
  --bg-elevated: #1a1a24;
  --border: #23232f;
  --text: #e8e8ee;
  --text-dim: #9a9aab;
  --accent: #e63946;
  --accent-hover: #ff4d5a;
  --user-bg: #2a2a3a;
  --radius: 12px;
}

* { 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);
  line-height: 1.55;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.logo-sub { color: var(--text-dim); font-weight: 400; font-size: .9rem; }

.nav { display: flex; gap: 20px; align-items: center; }
.nav a { color: var(--text-dim); text-decoration: none; font-size: .95rem; }
.nav a:hover { color: var(--text); }

.avatar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  overflow: hidden;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.sidebar {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.new-chat-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 12px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s;
}
.new-chat-btn:hover { background: var(--accent-hover); }

.conv-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }

.conv-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-dim);
  transition: background .15s;
}
.conv-list li:hover { background: var(--bg-elevated); }
.conv-list li.active { background: var(--accent); color: #fff; }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del {
  background: none; border: none; color: inherit; cursor: pointer;
  opacity: 0; padding: 0 4px; font-size: .85rem;
}
.conv-list li:hover .conv-del { opacity: 1; }

.chat-main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.chat-header h1 { font-size: 1.2rem; }

.chat-mode { display: flex; gap: 6px; background: var(--bg-card); padding: 4px; border-radius: 8px; }
.mode-btn {
  background: none; border: none; color: var(--text-dim);
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
  font-size: .85rem; font-weight: 600; transition: all .15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--accent); color: #fff; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.welcome h2 { color: var(--text); margin-bottom: 12px; font-size: 1.6rem; }

.msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: .95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user { align-self: flex-end; background: var(--user-bg); border: 1px solid var(--border); }
.msg.assistant { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); }
.msg img { max-width: 100%; border-radius: 8px; margin-top: 8px; display: block; }
.msg .typing { display: inline-block; color: var(--text-dim); font-style: italic; }

.chat-input-wrap {
  display: flex;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#chatInput {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: .95rem;
  resize: none;
  max-height: 200px;
  min-height: 48px;
  line-height: 1.4;
}
#chatInput:focus { outline: none; border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background .15s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.5; cursor: wait; }

.footer {
  text-align: center;
  padding: 16px;
  color: var(--text-dim);
  font-size: .85rem;
  border-top: 1px solid var(--border);
}

.error-page { text-align: center; padding: 80px 20px; }
.error-page h1 { font-size: 3rem; margin-bottom: 12px; }
.error-page p { color: var(--text-dim); margin-bottom: 24px; }
.btn-primary {
  background: var(--accent); color: #fff; padding: 10px 20px;
  border-radius: 8px; text-decoration: none; font-weight: 600;
}

@media (max-width: 768px) {
  .chat-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .header { padding: 12px 16px; }
  .chat-messages { padding: 16px; }
  .chat-input-wrap { padding: 12px 16px; }
}
