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

body {
  font-family: system-ui, sans-serif;
  background: #0f0f0f;
  color: #e0e0e0;
  height: 100dvh;
  overflow: hidden;
}

/* ── Two-column layout ─────────────────────────────────────────────── */

#layout {
  display: flex;
  height: 100dvh;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */

#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #141414;
  border-right: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-header {
  padding: 0.75rem 0.75rem;
  border-bottom: 1px solid #2a2a2a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.logo { font-weight: 600; font-size: 1.05rem; }

#new-btn {
  background: none;
  border: 1px solid #2a2a2a;
  color: #aaa;
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
#new-btn:hover { background: #1e1e1e; color: #e0e0e0; border-color: #444; }

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.conv-item {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  border-radius: 6px;
  margin: 0 0.35rem 0.15rem;
  font-size: 0.85rem;
  line-height: 1.35;
  color: #aaa;
  transition: background 0.1s;
}
.conv-item:hover { background: #1e1e1e; color: #e0e0e0; }
.conv-item.active { background: #1a3a5c; color: #e0e0e0; }

.conv-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-date {
  font-size: 0.72rem;
  color: #555;
  margin-top: 0.15rem;
}
.conv-item.active .conv-item-date { color: #7aa; }

/* ── Main chat area ────────────────────────────────────────────────── */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 800px;
}

header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #2a2a2a;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#conv-title {
  font-size: 0.9rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.status { font-size: 0.8rem; color: #666; flex-shrink: 0; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 85%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user      { align-self: flex-end; background: #1a3a5c; }
.msg.assistant { align-self: flex-start; background: #1e1e1e; border: 1px solid #2a2a2a; }
.msg.error     { align-self: flex-start; background: #3a1a1a; color: #ff6b6b; }

.divider {
  align-self: center;
  font-size: 0.75rem;
  color: #444;
  padding: 0.25rem 0.75rem;
  border: 1px solid #2a2a2a;
  border-radius: 999px;
  user-select: none;
}

#chat-form {
  display: flex;
  padding: 0.75rem 1rem;
  border-top: 1px solid #2a2a2a;
  gap: 0.5rem;
}

#input {
  flex: 1;
  background: #1e1e1e;
  border: 1px solid #2a2a2a;
  color: #e0e0e0;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  outline: none;
}
#input:focus { border-color: #444; }

button[type="submit"] {
  background: #1a3a5c;
  color: #e0e0e0;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  font-size: 1rem;
}
button[type="submit"]:hover { background: #1e4a7a; }
button[type="submit"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Responsive: hide sidebar on narrow screens ────────────────────── */

@media (max-width: 540px) {
  #sidebar { display: none; }
}
