:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f4f1;
  color: #191a18;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

body {
  background: #f4f4f1;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
select {
  min-height: 44px;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

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

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

.login-card {
  width: min(100%, 420px);
  background: #fff;
  border: 1px solid #d8d9d3;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 14px 40px rgba(25, 26, 24, 0.08);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 1.35rem;
  line-height: 1.2;
  margin-bottom: 6px;
}

h2 {
  font-size: 1.35rem;
  margin-bottom: 8px;
}

h3 {
  font-size: 1rem;
  margin-bottom: 0;
}

.eyebrow {
  margin-bottom: 5px;
  color: #666a62;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted,
.helper {
  color: #696c65;
  line-height: 1.5;
}

.helper {
  font-size: 0.82rem;
}

label {
  display: block;
  margin: 16px 0 6px;
  font-size: 0.84rem;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c9cbc4;
  border-radius: 11px;
  background: #fff;
  color: #191a18;
  outline: none;
}

input,
select {
  min-height: 48px;
  padding: 0 13px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #444740;
  box-shadow: 0 0 0 3px rgba(68, 71, 64, 0.12);
}

.primary,
.secondary,
.text-button,
.icon-button,
.send-button {
  border-radius: 11px;
  font-weight: 700;
}

.primary {
  border: 1px solid #1c1e1a;
  background: #1c1e1a;
  color: #fff;
  padding: 0 16px;
}

.secondary {
  border: 1px solid #c9cbc4;
  background: #fff;
  color: #242621;
  padding: 0 16px;
}

.full {
  width: 100%;
  margin-top: 16px;
}

.form-error {
  min-height: 20px;
  margin: 8px 0 0;
  color: #8c2e27;
  font-size: 0.84rem;
}

.app-shell {
  width: min(100%, 780px);
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: #fff;
}

.app-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid #e4e5df;
}

.header-title h1,
.header-title p {
  margin-bottom: 0;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 1px solid #d5d7d0;
  background: #fff;
  color: #20221e;
  font-size: 1.25rem;
}

.context-bar {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  border-bottom: 1px solid #ecece8;
  color: #5a5d56;
  font-size: 0.82rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #9b9e96;
}

.status-dot.ready {
  background: #467348;
}

.messages {
  overflow-y: auto;
  padding: 18px 14px 28px;
}

.welcome {
  max-width: 520px;
  margin: min(14vh, 80px) auto 0;
  padding: 22px;
  border: 1px solid #dedfd9;
  border-radius: 16px;
  background: #f8f8f5;
}

.welcome p:not(.eyebrow) {
  color: #62655e;
  line-height: 1.55;
}

.message {
  width: fit-content;
  max-width: min(92%, 620px);
  margin-bottom: 16px;
}

.message.user {
  margin-left: auto;
  padding: 11px 14px;
  border-radius: 16px 16px 4px 16px;
  background: #ecece7;
}

.message.assistant {
  margin-right: auto;
}

.message-body {
  margin: 0;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.error .message-body {
  color: #8c2e27;
}

.trace {
  margin-top: 10px;
  border: 1px solid #dddeda;
  border-radius: 12px;
  background: #fafaf8;
}

.trace summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  color: #555851;
  font-size: 0.82rem;
  font-weight: 700;
}

.trace-list {
  margin: 0;
  padding: 0 12px 12px 30px;
  color: #5f625b;
  font-size: 0.8rem;
}

.trace pre {
  max-width: 100%;
  overflow-x: auto;
  margin: 6px 0 10px;
  padding: 10px;
  border-radius: 8px;
  background: #efefeb;
  font-size: 0.72rem;
  white-space: pre-wrap;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
  padding: 10px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid #e1e2dc;
  background: #fff;
}

.composer textarea {
  min-height: 48px;
  max-height: 144px;
  resize: none;
  padding: 12px 14px;
  line-height: 1.45;
}

.send-button {
  width: 48px;
  height: 48px;
  border: 1px solid #1c1e1a;
  background: #1c1e1a;
  color: #fff;
  font-size: 1.3rem;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.settings-dialog {
  width: min(100% - 24px, 560px);
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 0;
  border: 1px solid #d8d9d3;
  border-radius: 18px;
  background: #f8f8f5;
  color: #191a18;
  overflow-y: auto;
}

.settings-dialog::backdrop {
  background: rgba(20, 21, 19, 0.48);
}

.settings-dialog[data-mode="onboarding"] {
  width: min(100% - 24px, 480px);
}

.settings-dialog[data-mode="onboarding"] .dialog-header {
  position: static;
  padding: 20px 18px 16px;
}

.settings-dialog[data-mode="onboarding"] .settings-section {
  margin: 18px;
  padding: 18px;
}

.settings-dialog[data-mode="onboarding"] .text-button {
  color: #5f625b;
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid #dedfd9;
  background: #f8f8f5;
}

.dialog-header h2,
.dialog-header p {
  margin-bottom: 0;
}

.settings-section {
  margin: 14px;
  padding: 16px;
  border: 1px solid #dedfd9;
  border-radius: 14px;
  background: #fff;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: #ecece7;
  color: #565952;
  font-size: 0.72rem;
  font-weight: 700;
}

.status-pill.ready {
  background: #e2ece0;
  color: #315d35;
}

.device-auth {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  background: #f0f0ec;
}

.device-auth a {
  display: inline-flex;
  align-items: center;
  color: #243e62;
  font-weight: 700;
}

.device-auth p {
  margin: 8px 0 0;
}

.text-button {
  margin: 0 14px 18px;
  border: 0;
  background: transparent;
  color: #7f2c26;
  text-decoration: underline;
}

@media (min-width: 700px) {
  body {
    padding: 18px;
  }

  .app-shell {
    min-height: calc(100dvh - 36px);
    border: 1px solid #d8d9d3;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 18px 50px rgba(25, 26, 24, 0.08);
  }
}

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