:root {
  color-scheme: dark;
  --bg: #212121;
  --panel: #2f2f2f;
  --panel-soft: #262626;
  --sidebar: #171717;
  --line: #3a3a3a;
  --text: #f4f4f5;
  --muted: #b4b4b4;
  --button: #ffffff;
  --button-text: #171717;
  --accent: #10a37f;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; }

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
}

.brand, .user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand strong { display: block; }
.brand span { color: var(--muted); font-size: 0.88rem; line-height: 1.4; }
.mark, .avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}

.new-chat, .user-row button, .prompt-grid button, .thread-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
}

.new-chat:hover, .user-row button:hover, .prompt-grid button:hover, .thread-button:hover {
  background: var(--panel-soft);
}

.thread-list {
  display: grid;
  gap: 4px;
  min-height: 0;
  overflow: auto;
}

.thread-button {
  width: 100%;
  min-height: 38px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-button.active {
  background: var(--panel);
  border-color: #555;
}

.thread-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 10px 2px;
}

.spacer { flex: 1; }
.user-row {
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.user-row button { padding: 8px 10px; }

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  min-width: 0;
}

.chat-header {
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(33,33,33,0.86);
}
.chat-header h1 { margin: 0; font-size: 1.1rem; }
.chat-header p { margin: 3px 0 0; color: var(--muted); font-size: 0.92rem; }

.messages {
  overflow: auto;
  padding: 26px;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 760px);
  gap: 14px;
  max-width: 860px;
  margin: 0 auto 24px;
}
.message.user .avatar { background: #10a37f; }
.bubble { line-height: 1.55; }
.label {
  font-weight: 700;
  margin-bottom: 5px;
}
.content { white-space: normal; overflow-wrap: anywhere; }
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.message-attachments span {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message-attachments em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.82rem;
}

.empty-state {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 24px;
  text-align: center;
}
.empty-state h2 { font-size: clamp(1.8rem, 4vw, 2.7rem); margin: 0; font-weight: 650; }
.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
  width: min(520px, 100%);
}
.prompt-grid button {
  text-align: left;
  min-height: 58px;
  color: var(--muted);
  background: var(--panel-soft);
}

.composer {
  display: grid;
  gap: 8px;
  width: min(860px, calc(100% - 40px));
  margin: 0 auto;
  padding: 18px 0 24px;
}
.composer-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: end;
}
.composer textarea {
  resize: none;
  min-height: 52px;
  max-height: 180px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  box-shadow: 0 2px 18px rgba(0,0,0,0.28);
}
.composer button {
  align-self: end;
  height: 52px;
  border: 0;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 650;
}
.composer #sendButton { min-width: 78px; }
.attach-button {
  width: 52px;
  min-width: 52px;
  font-size: 1.35rem;
  line-height: 1;
}
.composer button:disabled { opacity: 0.5; cursor: wait; }
.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(280px, 100%);
  height: 34px !important;
  min-width: 0;
  padding: 0 10px !important;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
  background: var(--panel-soft) !important;
  color: var(--text) !important;
  font-weight: 500 !important;
}
.attachment-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.8rem;
  white-space: nowrap;
}

.login-body {
  display: grid;
  place-items: center;
  background: var(--bg);
}
.login-shell {
  width: min(420px, calc(100% - 32px));
}
.login-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 32px;
  background: var(--panel-soft);
  box-shadow: 0 16px 60px rgba(0,0,0,0.36);
}
.login-card .mark { margin-bottom: 18px; }
.login-card h1 { margin: 0; font-size: 2rem; }
.login-card p { color: var(--muted); margin: 8px 0 22px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 7px; font-size: 0.9rem; font-weight: 650; }
.login-card input {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
}
.login-card button {
  height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 700;
}
.error {
  color: #ff8a80;
  margin-bottom: 0;
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .thread-list { max-height: 160px; }
  .chat-main { height: calc(100vh - 132px); }
  .message { grid-template-columns: 32px minmax(0, 1fr); }
  .prompt-grid { grid-template-columns: 1fr; }
  .composer { width: calc(100% - 24px); }
  .composer-row { grid-template-columns: auto 1fr; }
  .composer #sendButton { grid-column: 1 / -1; width: 100%; }
}
