:root {
  --teal: #3dbab3;
  --teal-dark: #28625d;
  --bg: #f4f7f7;
  --text: #1f2d2c;
  --muted: #5f7170;
  --border: #d5e3e2;
  --white: #fff;
  --danger: #c0392b;
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.muted { color: var(--muted); font-size: 0.9rem; }

.app-body {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-filter {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item:hover { background: #eef6f5; }
.chat-item.active { background: #dff0ee; font-weight: 600; }
.chat-item.archived { opacity: 0.65; font-style: italic; }

.sidebar-foot {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.link-admin { font-size: 0.85rem; color: var(--teal-dark); }

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(90deg, var(--teal-dark), var(--teal));
  color: var(--white);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--white);
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.welcome-msg { color: var(--muted); line-height: 1.5; }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
  word-break: break-word;
}

.bubble h2, .bubble h3, .bubble h4 {
  margin: 0.6rem 0 0.35rem;
  font-size: 1rem;
}

.bubble ul, .bubble ol {
  margin: 0.35rem 0;
  padding-left: 1.25rem;
}

.bubble p { margin: 0.35rem 0; }

.msg.user .bubble {
  background: var(--teal);
  color: var(--white);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg.assistant .bubble {
  background: var(--white);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: end;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--white);
}

.llm-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  padding: 0.55rem 1.25rem 0;
  background: var(--white);
  border-top: 1px solid var(--border);
}

.llm-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 160px;
}

.llm-field select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--white);
}

.llm-field select:disabled {
  opacity: 0.55;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 52px;
  max-height: 160px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.btn-primary {
  background: var(--teal);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost-sm, .btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.5);
  color: inherit;
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.sidebar-foot .btn-ghost-sm {
  border-color: var(--border);
  color: var(--text);
  align-self: flex-start;
}

.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--white);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.typing { color: var(--muted); font-style: italic; }

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
}

.login-card {
  width: min(420px, 92vw);
  background: var(--white);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.login-card h1 { margin: 0.4rem 0 0.2rem; font-size: 1.35rem; }
.login-card label { display: block; margin: 0.6rem 0 0.25rem; font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.error { color: var(--danger); margin-top: 0.75rem; font-size: 0.9rem; }

.admin-page {
  justify-content: center;
  align-items: flex-start;
  padding: 2rem;
}

.admin-card {
  background: var(--white);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 720px;
  width: 100%;
  border: 1px solid var(--border);
}

.admin-form {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
  max-width: 360px;
}

.admin-form input {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.user-table th, .user-table td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

.back-link {
  color: var(--teal-dark);
  text-decoration: none;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .app-body { flex-direction: column; }
  .sidebar { width: 100%; max-height: 180px; }
  .composer { grid-template-columns: 1fr; }
}
