:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-border: #d8deea;
  --text: #142033;
  --muted: #66758a;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #dbeafe;
  --danger: #b42318;
  --assistant: #f0f4f8;
  --user: #2563eb;
  --shadow: 0 20px 60px rgba(20, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  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 {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-panel {
  width: min(1040px, 100%);
  height: min(860px, calc(100vh - 48px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--panel-border);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.status-pill {
  min-width: 88px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-pill.error {
  background: #fee4e2;
  color: var(--danger);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: #fbfcff;
}

.toggle,
.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.field-inline input {
  width: 64px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.messages {
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 36px;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
  background: #172554;
}

.message.user .bubble {
  grid-column: 1;
  justify-self: end;
  background: var(--user);
  color: #fff;
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #475569;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.bubble {
  max-width: min(720px, 100%);
  padding: 13px 15px;
  border-radius: 8px;
  background: var(--assistant);
  color: var(--text);
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble p {
  margin: 0;
}

.meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.typing-cursor::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -2px;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--panel-border);
  background: #fff;
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  padding: 13px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  line-height: 1.5;
}

.composer textarea:focus,
.field-inline input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.composer-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.primary-button,
.secondary-button,
.ghost-button {
  height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.secondary-button,
.ghost-button {
  background: #fff;
  color: var(--text);
  border-color: var(--panel-border);
}

.secondary-button:hover:not(:disabled),
.ghost-button:hover:not(:disabled) {
  border-color: #a9b4c5;
}

.ghost-button {
  margin-left: auto;
  height: 34px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.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;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel {
    width: 100%;
    height: 100vh;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .chat-header,
  .toolbar,
  .messages {
    padding-left: 16px;
    padding-right: 16px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    justify-content: flex-end;
  }
}
