:root {
  color-scheme: light;
  --blue-700: #215a82;
  --blue-100: #e9f2f8;
  --slate-900: #1e2933;
  --slate-700: #485866;
  --slate-500: #70808c;
  --slate-200: #dbe3e8;
  --slate-100: #f4f7f9;
  --white: #ffffff;
  --danger: #a23b3b;
  --danger-bg: #fff1f1;
  --warning-bg: #fff8e7;
  --warning-border: #d39b25;
  --focus: #1b74ad;
  --shadow: 0 12px 35px rgb(30 41 51 / 10%);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--slate-100);
  color: var(--slate-900);
  overflow-x: hidden;
}

button, input, textarea { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: .55; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

a { color: var(--blue-700); }

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 20;
  padding: .65rem .9rem;
  background: var(--white);
  border-radius: .5rem;
  box-shadow: var(--shadow);
}

.skip-link:focus { top: 1rem; }

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.25rem;
  padding: .75rem 1.25rem;
  background: var(--white);
  border-bottom: 1px solid var(--slate-200);
}

.brand-lockup, .account-actions, .chat-heading, .history-heading, .dialog-actions {
  display: flex;
  align-items: center;
}

.brand-lockup { gap: .75rem; }

.brand {
  color: var(--slate-900);
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: -.02em;
  text-decoration: none;
}

.account-actions { gap: 1rem; }

.account-name, .subtle-text, .eyebrow { color: var(--slate-500); }

.account-name { font-size: .875rem; }

.app-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 19rem) minmax(0, 1fr);
  height: calc(100vh - 4.25rem);
  min-height: calc(100vh - 4.25rem);
}

.history-drawer {
  min-width: 0;
  padding: 1rem;
  background: var(--white);
  border-right: 1px solid var(--slate-200);
}

.history-heading { align-items: flex-start; justify-content: space-between; gap: .75rem; }

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

h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2vw, 1.75rem); }

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

.history-heading h2 { padding-top: .5rem; }

.subtle-text { min-height: 1.3rem; margin: .85rem 0 .5rem; font-size: .85rem; }

.conversation-list {
  display: grid;
  gap: .35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.conversation-item { min-width: 0; }

.conversation-button {
  display: block;
  width: 100%;
  min-height: 2.8rem;
  padding: .65rem .75rem;
  color: var(--slate-700);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: .55rem;
  overflow-wrap: anywhere;
}

.conversation-button:hover, .conversation-button.is-current { color: var(--blue-700); background: var(--blue-100); }

.conversation-button.is-current { border-color: #c8dce9; font-weight: 650; }

.load-more { width: 100%; margin-top: .75rem; }

.chat-main {
  display: flex;
  flex-direction: column;
  width: min(100%, 60rem);
  min-width: 0;
  height: 100%;
  min-height: calc(100vh - 4.25rem);
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 1rem;
  overflow: hidden;
}

.chat-heading { justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }

.eyebrow { margin-bottom: .35rem; font-size: .75rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }

.context-warning {
  margin: 0 0 1rem;
  padding: .8rem 1rem;
  color: #694b0a;
  background: var(--warning-bg);
  border-left: 4px solid var(--warning-border);
  border-radius: .35rem;
}

.transcript {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: .9rem;
  min-height: 0;
  padding: .5rem 0 2rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.empty-state { align-self: center; max-width: 26rem; margin: auto; color: var(--slate-500); text-align: center; }

.message-row { display: flex; min-width: 0; }

.message-row.user { justify-content: flex-end; }

.message-bubble {
  max-width: min(85%, 45rem);
  padding: .8rem 1rem;
  border-radius: 1rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.sophia .message-bubble { background: var(--white); border: 1px solid var(--slate-200); border-bottom-left-radius: .25rem; }

.message-row.user .message-bubble { color: var(--white); background: var(--blue-700); border-bottom-right-radius: .25rem; }

.message-label { margin-bottom: .3rem; font-size: .75rem; font-weight: 700; }

.message-text { margin: 0; line-height: 1.55; }

.composer {
  flex: none;
  padding: .65rem;
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: .8rem;
  box-shadow: var(--shadow);
}

.login-form label { display: block; margin-bottom: .35rem; font-weight: 650; }

.login-form input {
  display: block;
  width: 100%;
  padding: .75rem .85rem;
  color: var(--slate-900);
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: .55rem;
}

.composer-shell { position: relative; min-width: 0; }

.composer textarea {
  display: block;
  width: 100%;
  height: 3.1rem;
  min-height: 3.1rem;
  max-height: 10rem;
  padding: .75rem 3.75rem .75rem .9rem;
  color: var(--slate-900);
  line-height: 1.45;
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: .55rem;
  resize: none;
  overflow-x: hidden;
  overflow-y: hidden;
}

.composer textarea.is-scrollable { overflow-y: auto; }
.composer textarea:focus::placeholder { color: transparent; }
.composer textarea:disabled { background: var(--slate-100); }

.composer-send {
  position: absolute;
  right: .45rem;
  bottom: .45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  min-width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  color: var(--white);
  font-size: 1.25rem;
  line-height: 1;
  background: var(--blue-700);
  border: 1px solid var(--blue-700);
  border-radius: .55rem;
}

.composer-send:hover { background: #18496b; }

.button {
  min-height: 2.75rem;
  padding: .55rem .85rem;
  border: 1px solid transparent;
  border-radius: .55rem;
  font-weight: 650;
}

.button-primary { color: var(--white); background: var(--blue-700); }
.button-primary:hover { background: #18496b; }
.button-secondary { color: var(--blue-700); background: var(--blue-100); border-color: #c8dce9; }
.button-quiet { color: var(--slate-700); background: transparent; border-color: var(--slate-200); }
.button-danger { color: var(--danger); background: var(--danger-bg); border-color: #edc6c6; }

.app-status { min-height: 2rem; padding: .5rem 0; color: var(--slate-700); }
.app-status.is-error { color: var(--danger); }
.app-status.is-warning { color: #694b0a; }
.status-action { margin-left: .5rem; }

.drawer-backdrop { display: none; }

.mobile-only { display: none; }

.login-page {
  width: min(100% - 2rem, 28rem);
  margin: 10vh auto;
  padding: clamp(1.25rem, 5vw, 2.25rem);
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}

.login-intro { color: var(--slate-500); }

.login-form { display: grid; gap: .65rem; }
.login-form input { margin-bottom: .4rem; }
.form-error { padding: .75rem; color: var(--danger); background: var(--danger-bg); border-radius: .45rem; }
.noscript-warning { margin: 1rem; padding: 1rem; color: var(--danger); background: var(--danger-bg); }

dialog { max-width: min(32rem, calc(100% - 2rem)); padding: 0; color: var(--slate-900); background: var(--white); border: 0; border-radius: .8rem; box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(30 41 51 / 45%); }
.dialog-card { padding: 1.5rem; }
.dialog-card p { color: var(--slate-700); line-height: 1.5; }
.dialog-actions { justify-content: flex-end; gap: .65rem; }

@media (max-width: 700px) {
  .app-header { padding-inline: .75rem; }
  .mobile-only { display: inline-flex; }
  .account-name { display: none; }
  .app-layout { display: block; }
  .history-drawer {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    width: min(86vw, 20rem);
    min-height: 100vh;
    min-height: 100dvh;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .history-drawer.is-open { transform: translateX(0); }
  .drawer-backdrop:not([hidden]) { position: fixed; inset: 0; z-index: 9; display: block; background: rgb(30 41 51 / 35%); }
  .app-layout { height: calc(100vh - 4.25rem); min-height: calc(100vh - 4.25rem); }
  .chat-main {
    height: 100%;
    min-height: calc(100vh - 4.25rem);
    min-height: calc(100dvh - 4.25rem);
    padding: 1rem .75rem calc(.75rem + env(safe-area-inset-bottom));
  }
  .chat-heading { align-items: flex-start; }
  .message-bubble { max-width: 92%; }
  .composer { padding-bottom: calc(.65rem + env(safe-area-inset-bottom)); }
}

@supports (height: 100dvh) {
  .app-layout { height: calc(100dvh - 4.25rem); }
  .chat-main { min-height: calc(100dvh - 4.25rem); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
