:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111318;
  color: #f4f5f7;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior-y: none; }
body { background: #111318; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }

.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell { width: min(100%, 360px); }
.login-shell h1 { margin: 22px 0 6px; font-size: 30px; line-height: 1.2; }
.login-shell > p { margin: 0 0 28px; color: #9ca3af; }
.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid #30343b;
  border-radius: 8px;
  background: #191c22;
}
.brand-mark span, .brand-dot {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: inset -5px -4px 0 #22a85a;
}
.brand-mark.small { width: 42px; height: 42px; margin: 0 auto; }
.brand-mark.small span { width: 14px; height: 14px; }

.login-form { display: grid; gap: 10px; }
.login-form label { font-size: 13px; color: #c8ccd2; }
.login-form input {
  width: 100%;
  height: 48px;
  border: 1px solid #363b44;
  border-radius: 6px;
  padding: 0 14px;
  background: #191c22;
  outline: none;
  font-size: 16px;
}
.login-form input:focus { border-color: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .12); }
.primary-button {
  height: 48px;
  margin-top: 8px;
  border: 0;
  border-radius: 6px;
  background: #4ade80;
  color: #0b2012;
  font-weight: 700;
  cursor: pointer;
}
.primary-button:disabled { opacity: .55; cursor: wait; }
.form-error { min-height: 20px; margin: 2px 0 0; color: #fb7185; font-size: 14px; }

#app { height: 100dvh; display: grid; grid-template-columns: 280px minmax(0, 1fr); overflow: hidden; }
#sidebar {
  min-width: 0;
  background: #16191f;
  border-right: 1px solid #292d34;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.sidebar-head, .topbar {
  height: 58px;
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #292d34;
}
.sidebar-head { justify-content: space-between; padding: 0 14px 0 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-dot { width: 10px; height: 10px; box-shadow: none; }
.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #d7d9dd;
  font-size: 22px;
  cursor: pointer;
}
.icon-button:hover { background: #23272f; border-color: #30353e; }
.icon-button.danger:hover { color: #fb7185; }
#conversation-list { min-height: 0; padding: 10px; overflow-y: auto; }
.conversation-item {
  width: 100%;
  height: 42px;
  margin-bottom: 4px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #aeb3bb;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.conversation-item:hover { background: #20242b; color: #eef0f2; }
.conversation-item.active { background: #242a28; border-color: #31513b; color: #f4f5f7; }

#scrim { display: none; }
#chat-panel { width: 100%; min-width: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: #111318; }
.topbar { padding: 0 14px; gap: 10px; }
.topbar h1 { min-width: 0; flex: 1; margin: 0; font-size: 15px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menu-button { visibility: hidden; }
#messages {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px max(20px, calc((100% - 780px) / 2));
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
#empty-state { margin: 22vh auto 0; text-align: center; color: #9ca3af; }
#empty-state[hidden] { display: none; }
#empty-state h2 { margin: 16px 0 0; font-size: 17px; font-weight: 500; }
.message-row { width: 100%; min-width: 0; max-width: 780px; margin: 0 auto 26px; }
.message-label { display: block; margin: 0 0 8px; color: #7f8791; font-size: 12px; font-weight: 700; }
.message-row.user { display: flex; flex-direction: column; align-items: flex-end; }
.message-row.user .message-label { margin-right: 4px; }
.message-bubble { min-width: 0; max-width: min(88%, 680px); line-height: 1.65; overflow-wrap: anywhere; }
.user .message-bubble { padding: 10px 14px; border-radius: 8px 8px 2px 8px; background: #27322b; color: #f0f7f2; white-space: pre-wrap; }
.assistant .message-bubble { width: 100%; max-width: 100%; color: #e4e6e9; }
.assistant .message-bubble > :first-child { margin-top: 0; }
.assistant .message-bubble > :last-child { margin-bottom: 0; }
.assistant p { margin: 0 0 14px; }
.assistant a { color: #6ee7a0; }
.assistant pre {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 14px 0;
  padding: 42px 16px 16px;
  overflow-x: auto;
  border: 1px solid #30353e;
  border-radius: 6px;
  background: #0b0d10;
  -webkit-overflow-scrolling: touch;
}
.assistant code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
.assistant :not(pre) > code { padding: 2px 5px; border-radius: 4px; background: #242830; }
.copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 52px;
  height: 26px;
  border: 1px solid #393f49;
  border-radius: 5px;
  background: #191d23;
  color: #bfc4cb;
  font-size: 12px;
  cursor: pointer;
}
.error-bubble { color: #fda4af; }

#composer {
  position: sticky;
  bottom: 0;
  flex: 0 0 auto;
  padding: 10px max(20px, calc((100% - 780px) / 2)) calc(12px + env(safe-area-inset-bottom));
  background: #111318;
}
.composer-box {
  min-height: 52px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 7px 7px 14px;
  border: 1px solid #363b44;
  border-radius: 8px;
  background: #191c22;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .22);
}
textarea {
  min-width: 0;
  flex: 1;
  resize: none;
  border: 0;
  padding: 7px 0;
  background: transparent;
  color: #f4f5f7;
  outline: none;
  font-size: 16px;
  line-height: 22px;
}
textarea::placeholder { color: #737b85; }
.send-button, .stop-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 0;
  border-radius: 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.send-button { background: #4ade80; color: #102316; font-size: 23px; font-weight: 700; }
.stop-button { background: #f4f5f7; color: #17191e; font-size: 13px; }
[hidden] { display: none !important; }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(84vw, 310px);
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: 18px 0 45px rgba(0, 0, 0, .4);
  }
  .sidebar-open #sidebar { transform: translateX(0); }
  #scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: block;
    border: 0;
    background: rgba(0, 0, 0, .55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .sidebar-open #scrim { opacity: 1; pointer-events: auto; }
  #menu-button { visibility: visible; }
  #messages { padding: 20px 16px; }
  #composer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .message-bubble { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
