:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #64717f;
  --line: #d9ded6;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warn: #9a3412;
  --soft: #e7f3ef;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

.app-loading {
  display: flex;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--ink);
}

.app-loading p {
  color: var(--muted);
  font-size: 13px;
}

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

.auth-card {
  display: grid;
  width: min(420px, 100%);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf7;
  padding: 24px;
  box-shadow: 0 16px 45px rgb(24 32 42 / 0.08);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand p {
  color: var(--muted);
  font-size: 13px;
}

.auth-card .segmented {
  width: 100%;
}

.auth-card .primary {
  width: 100%;
  min-height: 48px;
}

.auth-secondary-actions {
  display: grid;
  gap: 10px;
}

.provider-button {
  min-height: 46px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}

.provider-button:hover {
  background: #f1f5f3;
}

.link-button {
  justify-self: center;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 700;
  padding: 4px 8px;
}

.link-button:hover {
  text-decoration: underline;
}

.workspace-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
}

.workspace-shell.sidebar-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.workspace-shell.sidebar-collapsed .sidebar {
  display: none;
}

.workspace-shell:not(.sidebar-collapsed) .sidebar-toggle-open {
  display: none;
}

.sidebar-overlay {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfaf7;
  padding: 24px;
}

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

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-block h1,
.brand-block p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.2;
}

h2 {
  font-size: 22px;
  line-height: 1.2;
}

.brand-block p,
.status-line,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.auth-panel,
.workspace-settings,
.conversation-panel {
  display: grid;
  gap: 14px;
}

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

.panel-heading h2 {
  font-size: 14px;
  letter-spacing: 0;
}

.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
}

.icon-button:hover {
  background: #f1f5f3;
  color: var(--ink);
}

.conversation-list {
  display: grid;
  gap: 8px;
}

#load-more-conversations {
  width: 100%;
}

.load-older-messages {
  width: min(220px, 100%);
  margin: 0 auto 8px;
}

.conversation-item {
  position: relative;
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 112px 10px 10px;
  text-align: left;
}

.conversation-item:hover,
.conversation-item.active,
.conversation-item:focus-visible {
  border-color: #a7d8c6;
  background: var(--soft);
}

.conversation-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-action {
  position: absolute;
  top: 8px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}

.conversation-rename {
  right: 84px;
  font-size: 14px;
}

.conversation-export-md {
  right: 58px;
  font-size: 14px;
}

.conversation-export-json {
  right: 32px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
}

.conversation-delete {
  right: 8px;
}

.conversation-rename:hover,
.conversation-export-md:hover,
.conversation-export-json:hover,
.conversation-rename:focus-visible,
.conversation-export-md:focus-visible,
.conversation-export-json:focus-visible {
  background: #dbeafe;
  color: #1d4ed8;
}

.conversation-delete:hover,
.conversation-delete:focus-visible {
  background: #fee2e2;
  color: #991b1b;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #efede7;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  cursor: pointer;
}

.segmented button.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(15 118 110 / 0.15);
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, opacity 120ms ease;
}

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

.primary,
.send-button {
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  padding: 11px 14px;
}

.primary:hover,
.send-button:hover {
  background: var(--accent-strong);
}

.ghost {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
}

.ghost:hover {
  background: #f1f5f3;
}

.hidden {
  display: none !important;
}

.toggle-row {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.thinking-settings {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.thinking-heading {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.thinking-row {
  display: grid;
  gap: 8px;
}

.thinking-row.two-columns {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.thinking-readonly {
  border: 1px solid #a7d8c6;
  border-radius: 8px;
  background: var(--soft);
  color: #0f513c;
  font-size: 13px;
  padding: 9px 10px;
}

.chat-surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  min-height: 0;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  padding: 22px 28px;
}

.chat-title-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.connection-state {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  padding: 7px 11px;
  white-space: nowrap;
}

.connection-state.ready {
  border-color: #a7d8c6;
  background: var(--soft);
  color: #0f513c;
}

.connection-state.error {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--warn);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 28px;
}

.message {
  display: grid;
  gap: 8px;
  max-width: 820px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.message.user {
  align-self: flex-end;
  background: #eef7ff;
  border-color: #cce3ff;
}

.message.assistant {
  align-self: flex-start;
}

.message.system {
  align-self: center;
  background: #fff7ed;
  border-color: #fed7aa;
}

.message-role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.message-content {
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.message-content > * {
  margin: 0;
}

.message-content > * + * {
  margin-top: 12px;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  color: var(--ink);
  font-weight: 800;
  line-height: 1.28;
}

.message-content h1 {
  font-size: 24px;
}

.message-content h2 {
  font-size: 21px;
}

.message-content h3 {
  font-size: 18px;
}

.message-content h4,
.message-content h5,
.message-content h6 {
  font-size: 16px;
}

.message-content ul,
.message-content ol {
  padding-left: 1.35rem;
}

.message-content li + li {
  margin-top: 6px;
}

.message-content blockquote {
  border-left: 3px solid var(--line);
  color: var(--muted);
  padding-left: 12px;
}

.message-content pre {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  white-space: pre;
}

.message-content code {
  border-radius: 5px;
  background: #eef2f7;
  color: #0f172a;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  padding: 2px 5px;
}

.message-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.message-content a {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.message.user .message-content {
  white-space: pre-wrap;
}

.thinking {
  color: var(--muted);
  font-size: 13px;
}

.thinking pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.citations a {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 12px;
  padding: 5px 8px;
  text-decoration: none;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: #ffffff;
  padding: 18px 28px;
}

.composer-main {
  display: grid;
  gap: 10px;
}

.composer textarea {
  min-height: 48px;
  max-height: 180px;
  resize: none;
}

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

.attach-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.attach-button:hover {
  background: #f1f5f3;
}

.attach-button input {
  display: none;
}

.attach-button span {
  font-size: 24px;
  line-height: 1;
}

.send-button {
  align-self: end;
  min-width: 88px;
  min-height: 48px;
}

.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-chip {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  max-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 5px 7px 5px 5px;
}

.attachment-chip img {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  object-fit: cover;
}

.attachment-chip em {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 6px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 9px;
  font-style: normal;
  font-weight: 800;
}

.attachment-chip span {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip strong {
  color: var(--muted);
  font-size: 16px;
}

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.message-attachments img {
  width: 128px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.message-file {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 9px;
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .auth-screen {
    min-height: 100svh;
    overflow: auto;
    place-items: start center;
    padding: max(18px, env(safe-area-inset-top)) 18px 18px;
  }

  .auth-card {
    width: 100%;
    gap: 16px;
    margin-top: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 12px 30px rgb(24 32 42 / 0.08);
  }

  .auth-brand {
    align-items: flex-start;
  }

  .auth-brand .brand-mark {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  .auth-brand h1 {
    font-size: 20px;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }

  .workspace-shell {
    grid-template-columns: 1fr;
    height: 100dvh;
    min-height: 0;
  }

  .workspace-shell:not(.sidebar-collapsed) .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10;
    border: 0;
    background: rgb(24 32 42 / 0.22);
    cursor: default;
    padding: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(88vw, 360px);
    max-height: none;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 18px 0 40px rgb(24 32 42 / 0.18);
    padding: 18px;
  }

  .chat-surface {
    height: 100dvh;
  }

  .chat-header,
  .messages,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-header {
    align-items: center;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .chat-header h2 {
    font-size: 19px;
  }

  .eyebrow {
    display: none;
  }

  .connection-state {
    font-size: 12px;
    padding: 6px 9px;
  }

  .messages {
    gap: 10px;
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .message {
    max-width: 92%;
    padding: 12px;
  }

  .composer {
    grid-template-columns: 44px minmax(0, 1fr) 72px;
    gap: 8px;
    align-items: end;
    border-top: 1px solid var(--line);
    padding-top: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .composer-main,
  .composer-actions {
    display: contents;
  }

  .attachment-preview {
    grid-column: 1 / -1;
  }

  .composer textarea {
    grid-column: 2;
    grid-row: 2;
    min-height: 44px;
    max-height: 132px;
    padding: 10px 12px;
  }

  .attach-button {
    grid-column: 1;
    grid-row: 2;
    width: 44px;
    height: 44px;
  }

  .send-button {
    grid-column: 3;
    grid-row: 2;
    min-width: 72px;
    min-height: 44px;
    padding: 10px 12px;
  }
}
