:root {
  --brand: #2e7d32;
  --brand-dark: #1b5e20;
  --bg: #f7f7f8;
  --sidebar-bg: #202123;
  --sidebar-text: #ececec;
  --border: #e5e5e5;
  --text: #1f1f1f;
  --muted: #6b6b6b;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
}
.login-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  width: 320px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-box h1 { margin: 0 0 6px; font-size: 22px; color: var(--brand-dark); }
.login-box p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.login-box input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; margin-bottom: 10px;
}
.login-box button {
  width: 100%; padding: 10px 12px; border: none; border-radius: 8px;
  background: var(--brand); color: white; font-size: 14px; cursor: pointer;
}
.login-box button:hover { background: var(--brand-dark); }
.login-error { color: #c0392b; font-size: 13px; margin-top: 8px; min-height: 16px; }

/* ---------- App layout ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 12px;
}
.new-chat-btn {
  background: transparent;
  border: 1px solid #565869;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  margin-bottom: 10px;
}
.new-chat-btn:hover { background: #2b2c2f; }

.conversation-list {
  flex: 1;
  overflow-y: auto;
}
.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.conversation-item:hover { background: #2b2c2f; }
.conversation-item.active { background: #343541; }
.conversation-item .del-btn {
  opacity: 0; color: #9b9b9b; cursor: pointer; font-size: 12px;
}
.conversation-item:hover .del-btn { opacity: 1; }

.sidebar-footer { border-top: 1px solid #3a3b3e; padding-top: 10px; margin-top: 8px; }
.usage-box { font-size: 12px; color: #cfcfcf; }
.usage-title { color: #9b9b9b; margin-bottom: 2px; }
.usage-value { font-size: 18px; font-weight: 600; color: white; }
.usage-sub { color: #9b9b9b; margin-top: 2px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: white;
}
#model-select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.session-cost { font-size: 13px; color: var(--muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.empty-state {
  max-width: 560px;
  margin: 60px auto;
  text-align: center;
  color: var(--muted);
}
.empty-state h2 { color: var(--text); }

.msg { display: flex; gap: 12px; max-width: 780px; width: 100%; margin: 0 auto; }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: white;
}
.msg.user .avatar { background: #6b6b6b; }
.msg.assistant .avatar { background: var(--brand); }
.msg .bubble { line-height: 1.55; font-size: 15px; padding-top: 3px; overflow-x: auto; }
.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble pre {
  background: #1e1e1e; color: #eaeaea; padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: 13px;
}
.msg .bubble code { font-family: "SFMono-Regular", Consolas, monospace; }
.msg .bubble :not(pre) > code {
  background: #eee; padding: 1px 5px; border-radius: 4px; font-size: 13px;
}
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }

.chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 20px 20px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}
#chat-input {
  flex: 1;
  resize: none;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  max-height: 160px;
}
#chat-input:focus { outline: none; border-color: var(--brand); }
#send-btn {
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: white;
  font-size: 14px;
  cursor: pointer;
}
#send-btn:hover { background: var(--brand-dark); }
#send-btn:disabled { background: #a5c9a7; cursor: not-allowed; }
