:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0b0d12;
  --panel: #11151d;
  --panel-2: #171c26;
  --line: rgba(255, 255, 255, 0.1);
  --text: #edf3ff;
  --muted: #9ba8bc;
  --accent: #82b7ff;
  --danger: #ff8585;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 0%, rgba(130, 183, 255, 0.15), transparent 35rem);
}
.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}
.login-card h1 { margin: 0; font-size: 25px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-card input, .composer textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: var(--panel-2);
  color: var(--text);
}
.login-card input { height: 46px; padding: 0 12px; }
.login-card button, .primary-button, .composer button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #07101d;
  font-weight: 750;
}
.login-card button { height: 46px; }
.error-text { min-height: 20px; color: var(--danger); font-size: 13px; }

.app-shell { height: 100vh; display: grid; grid-template-columns: 280px 1fr; }
.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: #0e1118;
}
.sidebar-head, .chat-head {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.primary-button { min-height: 42px; }
.conversation-list {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.conversation {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px;
  align-items: center;
  padding: 4px;
  border-radius: 9px;
}
.conversation.active { background: rgba(130, 183, 255, 0.13); }
.conversation-title, .delete-button, .text-button, .icon-button {
  border: 0;
  background: transparent;
  color: var(--text);
}
.conversation-title {
  min-width: 0;
  padding: 8px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.delete-button { padding: 7px; color: var(--muted); }
.delete-button:hover { color: var(--danger); }
.text-button { margin-top: auto; padding: 10px; color: var(--muted); }

.chat-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr auto; }
.chat-head { padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head div { display: flex; flex-direction: column; gap: 2px; }
.chat-head span { color: var(--muted); font-size: 12px; }
.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 24px max(20px, calc((100% - 800px) / 2));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.message {
  max-width: min(760px, 92%);
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.user { align-self: flex-end; background: rgba(130, 183, 255, 0.15); }
.message.assistant { align-self: flex-start; background: var(--panel); }
.message.pending { color: var(--muted); }
.empty { margin: auto; color: var(--muted); text-align: center; }
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px max(20px, calc((100% - 800px) / 2));
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer textarea { min-height: 50px; max-height: 160px; resize: vertical; padding: 13px; }
.composer button { min-width: 82px; padding: 0 14px; }
.composer button:disabled { cursor: wait; opacity: 0.65; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  translate: -50% 20px;
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  transition: 180ms ease;
}
.toast.show { translate: -50% 0; opacity: 1; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .mobile-only { display: inline-block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    width: min(320px, 88vw);
    translate: -100% 0;
    transition: translate 180ms ease;
    box-shadow: 18px 0 45px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { translate: 0 0; }
  .chat-panel { height: 100vh; }
  .chat-head { padding: 8px 12px; justify-content: flex-start; }
  .messages { padding: 16px 12px; }
  .composer { padding: 10px; grid-template-columns: 1fr; }
  .composer button { min-height: 42px; }
  .message { max-width: 95%; }
}
