:root {
  color-scheme: dark;
  --bg: #101010;
  --sidebar: #171717;
  --surface: #202020;
  --surface-hover: #2a2a2a;
  --border: #303030;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #c4a7ff;
  --green: #7dd3a7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-height: 100vh;
  padding: 24px 16px 16px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; color: var(--text); }
.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, #d7c5ff, #9572e7);
  color: #211a32;
  font-weight: 800;
}
.brand h1 { margin: 0; font-size: 1.12rem; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: .78rem; }
.new-chat, .primary-button {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.new-chat:hover, .conversation-item:hover { background: var(--surface-hover); }
.conversation-section { flex: 1; min-height: 0; }
.conversation-section h2 { padding: 0 10px; color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; }
.conversation-list { display: grid; gap: 4px; max-height: calc(100vh - 300px); overflow-y: auto; }
.conversation-item {
  overflow: hidden;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ddd;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.conversation-item.active { background: var(--surface-hover); color: white; }
.sidebar-bottom { display: grid; gap: 14px; }
.model-card { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: #1c1c1c; }
.model-card strong, .model-card small { display: block; }
.model-card strong { font-size: .84rem; }
.model-card small { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.status-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--green); }
.status-dot.offline { background: #fbbf24; }
.account-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; }
.avatar { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; background: #46375e; color: white; font-size: .8rem; }
.account-name { flex: 1; overflow: hidden; font-size: .88rem; text-overflow: ellipsis; }
.logout-button { border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.chat-panel { display: flex; min-width: 0; min-height: 100vh; flex-direction: column; }
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 34px; border-bottom: 1px solid #242424; }
.chat-header h2 { margin: 3px 0 0; font-size: 1.05rem; font-weight: 550; }
.eyebrow { margin: 0; color: var(--muted); font-size: .66rem; font-weight: 700; letter-spacing: .17em; }
.privacy-label { padding: 7px 10px; border: 1px solid var(--border); border-radius: 20px; color: var(--muted); font-size: .73rem; }
.chat-messages { display: flex; width: min(820px, 100%); flex: 1; flex-direction: column; gap: 24px; margin: 0 auto; padding: 36px 30px; }
.welcome-card { max-width: 490px; margin: auto; text-align: center; }
.welcome-orb { display: grid; width: 54px; height: 54px; place-items: center; margin: 0 auto 20px; border: 1px solid #4c3f64; border-radius: 18px; background: radial-gradient(circle at 30% 20%, #54427a, #241e30 70%); color: #e1d4ff; font-size: 1.55rem; }
.welcome-card h3 { margin: 12px 0 8px; font-size: 1.6rem; font-weight: 550; letter-spacing: -.03em; }
.welcome-card p:last-child { max-width: 380px; margin: 0 auto; color: var(--muted); line-height: 1.65; }
.message-row { display: grid; gap: 8px; }
.message-row.user { align-self: flex-end; width: min(88%, 620px); }
.message-row.assistant { align-self: flex-start; width: min(100%, 720px); }
.message-label { color: var(--muted); font-size: .64rem; font-weight: 700; letter-spacing: .12em; }
.message-row.user .message-label { text-align: right; }
.message-bubble { padding: 14px 17px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.user .message-bubble { border-color: #45385b; background: #282332; }
.composer-wrap { width: min(820px, 100%); margin: 0 auto; padding: 0 30px 24px; }
.composer { display: flex; align-items: flex-end; gap: 12px; padding: 12px; border: 1px solid #414141; border-radius: 16px; background: #1b1b1b; box-shadow: 0 12px 40px #0004; }
.composer:focus-within { border-color: #62527e; }
#message-input { width: 100%; min-height: 42px; max-height: 180px; resize: vertical; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
#message-input::placeholder { color: #858585; }
#send-button { width: 38px; height: 38px; flex: none; border: 0; border-radius: 11px; background: #e6ddf6; color: #1d1727; font-size: 1.45rem; cursor: pointer; }
#send-button:disabled { opacity: .45; cursor: wait; }
.disclaimer { margin: 10px 0 0; color: #777; font-size: .68rem; text-align: center; }
.error-message { min-height: 0; margin: 0 0 8px; color: #fca5a5; font-size: .85rem; }
.error-message:empty { display: none; }

.auth-layout { display: grid; min-height: 100vh; grid-template-columns: 1fr 1fr; }
.auth-brand-panel { position: relative; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; padding: 34px; background: #16131d; }
.auth-brand { position: relative; z-index: 1; }
.auth-message { position: relative; z-index: 1; max-width: 460px; margin: auto; }
.auth-message h2 { margin: 18px 0; font-size: clamp(2.7rem, 5vw, 4.5rem); font-weight: 550; letter-spacing: -.06em; line-height: 1.05; }
.auth-message > p:last-child { max-width: 360px; color: #bbb5c6; line-height: 1.7; }
.auth-glow { position: absolute; right: -20%; bottom: -25%; width: 75%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, #674b9345, transparent 67%); }
.auth-form-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-form-wrap { width: min(390px, 100%); }
.auth-form-wrap h2 { margin: 10px 0 8px; font-size: 1.8rem; font-weight: 570; letter-spacing: -.04em; }
.auth-subtitle { margin: 0 0 28px; color: var(--muted); font-size: .94rem; }
.auth-form { display: grid; gap: 9px; }
.auth-form label { margin-top: 8px; color: #ddd; font-size: .83rem; }
.auth-form input { width: 100%; height: 45px; padding: 0 12px; border: 1px solid #3b3b3b; border-radius: 9px; outline: none; background: #1a1a1a; color: var(--text); }
.auth-form input:focus { border-color: #9276c2; }
.field-hint { color: var(--muted); }
.primary-button { margin-top: 18px; border: 0; background: #d8caf4; color: #20192c; font-weight: 650; }
.primary-button:hover { background: #e5dcf5; }
.auth-switch { margin-top: 22px; color: var(--muted); font-size: .86rem; text-align: center; }
.auth-switch a { margin-left: 4px; }
.flash { margin: 12px 0; padding: 11px 12px; border: 1px solid #793d43; border-radius: 8px; background: #381e22; color: #fecaca; font-size: .85rem; }

@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; gap: 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .conversation-section { display: none; }
  .sidebar-bottom { grid-template-columns: 1fr auto; align-items: center; }
  .chat-panel { min-height: calc(100vh - 250px); }
  .chat-header { padding: 18px 20px; }
  .privacy-label { display: none; }
  .chat-messages { padding: 24px 18px; }
  .composer-wrap { padding: 0 16px 18px; }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-brand-panel { display: none; }
}
