:root {
  color-scheme: light dark;
  --page: #f4f5f7;
  --surface: #ffffff;
  --line: #dfe2e7;
  --ink: #17191d;
  --muted: #6f7682;
  --accent: #17191d;
  --accent-ink: #ffffff;
  --user: #e8ebef;
  --error: #b42318;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }

.shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  align-items: center;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(16, 24, 40, .06);
}

.login-panel {
  width: min(100%, 360px);
  padding: 28px;
  justify-self: center;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: 0;
}

.login-panel h1 { margin-bottom: 20px; }

form { display: grid; gap: 12px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

input { height: 44px; padding: 0 12px; }

input:focus, textarea:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(23, 25, 29, .12);
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.error {
  margin: 0;
  color: var(--error);
  font-size: 13px;
}

.chat-panel {
  height: min(760px, calc(100vh - 48px));
  min-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  overflow: hidden;
}

.chat-header {
  min-height: 60px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quiet-button {
  min-height: 34px;
  padding: 0 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.quiet-button:hover { color: var(--ink); background: var(--user); }

.messages {
  min-height: 0;
  padding: 20px 18px;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb {
  background: var(--muted);
  border: 2px solid transparent;
  border-radius: 8px;
  background-clip: padding-box;
}

.message.pending {
  color: var(--muted);
  font-style: italic;
}

.message.pending p::after {
  content: "...";
  display: inline-block;
  width: 1.25em;
  overflow: hidden;
  vertical-align: bottom;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0%, 20% { width: 0; }
  50% { width: .65em; }
  80%, 100% { width: 1.25em; }
}

.message {
  max-width: 84%;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message p { margin: 0; }

.message.user {
  align-self: flex-end;
  padding: 10px 13px;
  border-radius: 8px;
  background: var(--user);
}

.message.assistant { align-self: flex-start; padding: 2px 0; }

.chat-error { padding: 0 18px 8px; }

.composer {
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line);
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

textarea {
  min-height: 42px;
  max-height: 180px;
  resize: none;
  padding: 10px 12px;
  line-height: 1.4;
}

.composer button { min-width: 70px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

@media (max-width: 520px) {
  .shell { padding: 0; }
  .panel { min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; }
  .login-panel { width: 100%; min-height: auto; padding: 24px 16px; align-self: center; }
  .chat-panel { height: 100vh; min-height: 100vh; }
  @supports (height: 100dvh) {
    .chat-panel { height: 100dvh; min-height: 100dvh; }
  }
  .message { max-width: 92%; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .messages { padding-left: 12px; padding-right: 12px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #111315;
    --surface: #1a1d21;
    --line: #30353c;
    --ink: #f4f5f7;
    --muted: #a7afb9;
    --accent: #f4f5f7;
    --accent-ink: #17191d;
    --user: #2b3037;
    --error: #ff8b82;
  }
  .panel { box-shadow: none; }
}
