/* MIT AI chat — ChatGPT-like layout */

:root,
[data-theme="light"] {
  --bg: #f9f9f9;
  --sidebar: #f3f3f3;
  --surface: #ffffff;
  --composer: #ffffff;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --text-dim: #5d5d5d;
  --muted: #8f8f8f;
  --hover: rgba(0, 0, 0, 0.05);
  --user-bubble: #f4f4f4;
  --accent: #ff5c00;
  --accent-text: #ffffff;
  --danger: #ef4444;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius: 24px;
  --sidebar-w: 268px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #212121;
  --sidebar: #171717;
  --surface: #2f2f2f;
  --composer: #2f2f2f;
  --border: #3d3d3d;
  --text: #ececec;
  --text-dim: #b4b4b4;
  --muted: #8f8f8f;
  --hover: rgba(255, 255, 255, 0.06);
  --user-bubble: #2f2f2f;
  --accent: #ff5c00;
  --accent-text: #ffffff;
  --danger: #f87171;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

.brand-mark { width: 40px; height: 40px; display: block; }
.brand-mark.sm { width: 28px; height: 28px; }
.brand-mark.lg { width: 56px; height: 56px; margin: 0 auto 1rem; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(800px 400px at 50% -10%, rgba(255, 92, 0, 0.16), transparent 55%),
    var(--bg);
}
.login-panel {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.75rem 1.6rem;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-panel .brand-mark { margin: 0 auto 1rem; }
.login-panel h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}
.login-lead { color: var(--text-dim); margin: 0.4rem 0 1.4rem; }
.login-panel form { text-align: left; }
.login-panel label {
  display: grid;
  gap: 0.35rem;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.85rem;
}
.login-panel input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.login-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 92, 0, 0.18);
}
.hint { color: var(--muted); font-size: 12px; margin: 0.8rem 0 0; }
.hint code { font-size: 11px; }
.alt-login { margin-top: 1rem; color: var(--text-dim); font-size: 13px; }
.alt-login summary { cursor: pointer; }
.error { color: var(--danger); font-size: 13px; margin: 0.75rem 0 0; }

.btn {
  border: 1px solid var(--border);
  background: var(--hover);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn.block { width: 100%; }
.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 600;
  padding: 10px 14px;
  margin-top: 0.2rem;
}
.btn.ghost { background: transparent; margin-top: 0.5rem; }
.btn.new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--surface);
  font-weight: 600;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-top { padding: 12px; display: grid; gap: 10px; }
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  padding: 4px;
}
.brand:hover { text-decoration: none; }
.chat-list {
  flex: 1;
  overflow: auto;
  padding: 4px 8px 12px;
}
.chat-group {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 10px 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 10px;
  padding: 8px 8px;
  cursor: pointer;
  color: var(--text);
}
.chat-item:hover, .chat-item.active { background: var(--hover); }
.chat-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.chat-item .del {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
}
.chat-item:hover .del, .chat-item.active .del { opacity: 1; }
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px 14px;
}
.foot-link {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.user-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  align-items: center;
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}
.user-meta { min-width: 0; }
.user-meta #user-name { font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
}
.model-pick select {
  background: transparent;
  border: 0;
  font-weight: 600;
  font-size: 15px;
  padding: 6px 4px;
  outline: none;
  cursor: pointer;
}
.theme-switcher { display: flex; gap: 4px; }
.theme-opt, .icon-btn {
  border: 0;
  background: transparent;
  width: 34px; height: 34px;
  border-radius: 8px;
  cursor: pointer;
}
.theme-opt.active, .icon-btn:hover, .theme-opt:hover { background: var(--hover); }

.thread { overflow: auto; }
.empty {
  max-width: 720px;
  margin: 12vh auto 0;
  text-align: center;
  padding: 0 1.25rem;
}
.empty h2 { font-size: 1.7rem; font-weight: 600; margin: 0 0 1.4rem; }
.chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: left;
}
.chips button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 14px;
}
.chips button:hover { border-color: var(--accent); }

.messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: grid;
  gap: 18px;
}
.msg { display: grid; gap: 8px; }
.msg.user .bubble {
  margin-left: auto;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  max-width: min(680px, 92%);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.assistant .bubble {
  font-size: 15.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.assistant .bubble.rich { white-space: normal; }
.msg.assistant .bubble.rich p { margin: 0 0 0.7em; }
.msg.assistant .bubble.rich p:last-child { margin-bottom: 0; }
.msg.assistant .bubble.rich pre {
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
  font-size: 13px;
}
.msg.assistant .bubble.rich code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.msg.assistant .bubble.rich :not(pre) > code {
  background: var(--hover);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg.err .bubble { color: var(--danger); }
.msg .meta { font-size: 12px; color: var(--muted); }

.composer-wrap {
  padding: 8px 16px 18px;
}
.composer {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  gap: 6px;
  background: var(--composer);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow);
}
.composer textarea {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  max-height: 200px;
  line-height: 1.45;
  padding: 6px 0;
}
.icon-btn.send, .icon-btn.stop {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
}
.icon-btn.send:disabled { opacity: 0.35; }
.icon-btn.stop { background: var(--danger); color: #fff; }
.disclaimer {
  max-width: 760px;
  margin: 8px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

.mobile-toggle { display: none; position: fixed; top: 10px; left: 10px; z-index: 30; }
.sidebar-overlay { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, var(--sidebar-w));
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }
  .sidebar-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 35;
  }
  .mobile-toggle { display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); }
  .chips { grid-template-columns: 1fr; }
  .topbar { padding-left: 52px; }
}
