:root {
  color-scheme: dark;
  --page: #12140f;
  --surface: #191c16;
  --surface-raised: #20241c;
  --surface-soft: #252a20;
  --line: rgba(239, 244, 230, 0.12);
  --line-strong: rgba(239, 244, 230, 0.22);
  --text: #f1f4eb;
  --muted: #9da595;
  --accent: #b7d46b;
  --accent-ink: #18200d;
  --danger: #e48d83;
  --radius-small: 10px;
  --radius-medium: 18px;
  font-family: "Geist", "Avenir Next", "SF Pro Text", -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
}

body {
  min-width: 320px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

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

button:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

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

.is-hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  min-height: 72px;
  padding: 12px clamp(18px, 3vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(18, 20, 15, 0.95);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--accent);
  background: var(--surface);
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0;
}

.connection-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  position: relative;
  display: inline-block;
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--accent);
}

.status-dot::after {
  position: absolute;
  inset: -4px;
  border: 1px solid rgba(183, 212, 107, 0.34);
  border-radius: inherit;
  content: "";
  animation: breathe 2.4s ease-in-out infinite;
}

.connection-state.is-working .status-dot::after {
  animation-duration: 0.9s;
}

.connection-state.is-offline .status-dot {
  background: var(--danger);
}

.connection-state.is-offline .status-dot::after {
  border-color: rgba(228, 141, 131, 0.4);
}

@keyframes breathe {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 0.85; transform: scale(1); }
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button,
.text-button,
.primary-button,
.send-button {
  border: 1px solid var(--line);
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), border-color 180ms ease, background 180ms ease, color 180ms ease;
  cursor: pointer;
}

.icon-button:active,
.text-button:active,
.primary-button:active,
.send-button:active {
  transform: translateY(1px) scale(0.98);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-raised);
}

.text-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 13px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.conversation-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  width: min(100%, 1080px);
  min-height: 0;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 42px) max(14px, env(safe-area-inset-bottom));
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(30px, 6vh, 70px) 0 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.empty-state {
  width: min(700px, 100%);
  padding-top: clamp(16px, 9vh, 110px);
}

.empty-state[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 15px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.empty-state h1,
.login-copy h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  font-weight: 560;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

.empty-state > p:not(.eyebrow),
.login-copy > p:not(.eyebrow) {
  max-width: 58ch;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 34px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font: 12px "Geist Mono", "SFMono-Regular", Consolas, monospace;
}

.message {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: clamp(20px, 4vw, 54px);
  padding: 28px 0 34px;
  border-top: 1px solid var(--line);
  animation: reveal-message 340ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.message:first-child {
  border-top: 0;
}

@keyframes reveal-message {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-meta {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  min-width: 0;
}

.message-meta > div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.message-meta strong {
  font-size: 13px;
  font-weight: 680;
}

.message-meta span:not(.message-badge) {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.message-badge {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--accent);
  background: var(--surface);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: 0.04em;
}

.message-user .message-badge {
  color: var(--text);
}

.message-content {
  min-width: 0;
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 15px/1.72 "Geist", "Avenir Next", "SF Pro Text", sans-serif;
}

.message-user .message-content {
  color: #d8ddcf;
}

.quick-replies {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: -14px;
}

.quick-replies-label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.quick-reply {
  max-width: min(100%, 360px);
  min-height: 34px;
  padding: 0 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: transparent;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), border-color 180ms ease, background 180ms ease;
}

.quick-reply:hover {
  border-color: rgba(183, 212, 107, 0.48);
  background: rgba(183, 212, 107, 0.08);
}

.quick-reply:active {
  transform: translateY(1px) scale(0.98);
}

.response-loading {
  display: grid;
  gap: 9px;
  width: min(420px, 80%);
  padding-top: 6px;
}

.response-loading span {
  display: block;
  height: 11px;
  border-radius: 999px;
  background: var(--surface-soft);
  animation: loading-line 1.2s ease-in-out infinite;
}

.response-loading span:nth-child(2) {
  width: 78%;
  animation-delay: 120ms;
}

.response-loading span:nth-child(3) {
  width: 54%;
  animation-delay: 240ms;
}

@keyframes loading-line {
  0%, 100% { opacity: 0.35; transform: scaleX(0.97); transform-origin: left; }
  50% { opacity: 0.9; transform: scaleX(1); transform-origin: left; }
}

.error-banner {
  margin: 0 0 10px;
  padding: 10px 13px;
  border: 1px solid rgba(228, 141, 131, 0.34);
  border-radius: var(--radius-small);
  color: #f1b5ad;
  background: rgba(228, 141, 131, 0.08);
  font-size: 12px;
  line-height: 1.45;
}

.composer {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-medium);
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(8, 10, 6, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.composer textarea {
  width: 100%;
  min-height: 46px;
  max-height: 220px;
  padding: 7px 4px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 16px;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: #7f8877;
}

.composer textarea:disabled {
  opacity: 0.72;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.composer-context {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
}

.composer-context span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-separator {
  width: 3px;
  height: 3px;
  flex: 0 0 3px;
  border-radius: 50%;
  background: var(--line-strong);
}

.send-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 16px;
  border-color: transparent;
  border-radius: 999px;
  color: var(--accent-ink);
  background: var(--accent);
  font-size: 12px;
  font-weight: 760;
}

.send-button:hover,
.primary-button:hover {
  background: #c0db7a;
  transform: translateY(-1px);
}

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

.send-button svg {
  width: 17px;
  height: 17px;
}

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

.login-shell {
  width: min(100%, 980px);
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  grid-template-areas:
    "brand brand"
    "copy form"
    "copy error";
  column-gap: clamp(42px, 9vw, 120px);
  row-gap: 24px;
  padding: clamp(28px, 6vw, 72px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 34px 90px rgba(7, 9, 6, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.025);
}

.login-panel > .brand-lockup {
  grid-area: brand;
  margin-bottom: clamp(24px, 5vh, 58px);
}

.login-copy {
  grid-area: copy;
  align-self: start;
}

.login-copy h1 {
  font-size: clamp(40px, 6vw, 70px);
}

.login-form {
  grid-area: form;
  display: grid;
  align-content: start;
  gap: 10px;
}

.login-form label {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.password-field {
  position: relative;
}

.password-field input {
  width: 100%;
  height: 50px;
  padding: 0 48px 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  color: var(--text);
  background: var(--page);
}

.field-key {
  position: absolute;
  top: 50%;
  right: 14px;
  display: grid;
  place-items: center;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.field-key svg {
  width: 18px;
  height: 18px;
}

.field-help {
  margin: 0 0 13px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}

.login-form .primary-button {
  width: 100%;
  min-height: 48px;
}

.login-error {
  grid-area: error;
  align-self: start;
  margin: -10px 0 0;
  color: #f1b5ad;
  font-size: 11px;
}

.login-error.is-empty {
  visibility: hidden;
}

.login-footnote {
  margin: 16px 8px 0;
  color: var(--muted);
  font: 10px "Geist Mono", "SFMono-Regular", Consolas, monospace;
  text-align: right;
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 64px;
    padding: 10px 14px;
  }

  .connection-state {
    position: absolute;
    top: 52px;
    left: 50%;
    z-index: 1;
    padding: 5px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--page);
    transform: translateX(-50%);
  }

  .brand-lockup {
    font-size: 10px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .text-button span {
    display: none;
  }

  .text-button {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .conversation-shell {
    padding: 0 12px max(10px, env(safe-area-inset-bottom));
  }

  .messages {
    padding: 44px 2px 20px;
  }

  .empty-state {
    padding-top: 8vh;
  }

  .message {
    grid-template-columns: 1fr;
    gap: 18px;
    padding: 24px 2px 28px;
  }

  .quick-replies {
    grid-column: 1;
    margin-top: -8px;
  }

  .quick-replies-label {
    flex-basis: 100%;
    margin-bottom: 2px;
  }

  .composer {
    gap: 12px;
    padding: 14px;
    border-radius: 16px;
  }

  .composer-footer {
    align-items: flex-end;
  }

  .composer-context span:last-child,
  .context-separator {
    display: none;
  }

  .send-button {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    padding: 0;
  }

  .send-button span {
    display: none;
  }

  .login-page {
    padding: 14px;
  }

  .login-panel {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "copy"
      "form"
      "error";
    gap: 24px;
    padding: 26px 20px;
    border-radius: 22px;
  }

  .login-panel > .brand-lockup {
    margin-bottom: 26px;
  }

  .login-copy h1 {
    font-size: clamp(40px, 14vw, 58px);
  }
}

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