:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #111111;
  --muted: #6f7177;
  --accent: #9ca3af;
  --accent-dark: #6b7280;
  --danger: #b42318;
  --shadow: 0 3px 12px rgb(15 23 42 / 8%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.brand {
  font-weight: 700;
  text-decoration: none;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}

.icon-button:hover {
  border-color: var(--border);
  background: #f2f4f7;
}

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

.link-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.messages {
  max-width: 960px;
  margin: 16px auto 0;
  padding: 0 16px;
}

.message {
  margin: 0 0 8px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.message.error {
  border-color: #fecdca;
  color: var(--danger);
  background: #fffbfa;
}

.login-panel {
  width: min(420px, calc(100% - 32px));
  margin: 12vh auto;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 1.75rem;
}

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

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

.app-rail {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  height: 100vh;
  padding: 32px 0 22px;
  border-right: 1px solid #f2f3f5;
  background: #ffffff;
}

.rail-form {
  display: contents;
}

.rail-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #111111;
  cursor: pointer;
  text-decoration: none;
}

.rail-button:hover {
  background: #f4f4f5;
}

.rail-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.rail-menu {
  position: relative;
}

.rail-menu summary {
  list-style: none;
}

.rail-menu summary::-webkit-details-marker {
  display: none;
}

.rail-menu .conversation-list {
  position: absolute;
  left: 44px;
  top: -8px;
  z-index: 20;
  width: 260px;
  max-height: 420px;
  padding: 10px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.rail-bottom {
  margin-top: auto;
}

.sidebar {
  display: none;
  padding: 16px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
}

.conversation-list {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.conversation-link {
  display: block;
  padding: 10px 12px;
  overflow: hidden;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-link:hover,
.conversation-link.active {
  background: #f4f4f5;
  color: #111111;
}

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

.chat-transcript {
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 48px 32px 24px;
  overflow-y: auto;
}

.chat-transcript:has(.chat-message) {
  align-content: start;
}

.welcome-state {
  align-self: center;
  justify-self: center;
  margin-bottom: 28px;
  text-align: center;
}

.welcome-state h1 {
  margin: 0 0 8px;
  color: #111111;
  font-size: clamp(1.7rem, 2vw, 2rem);
  line-height: 1.1;
}

.welcome-state p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.chat-message {
  width: min(820px, 100%);
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-message.user {
  justify-self: end;
  background: #f4f4f5;
}

.chat-message strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.875rem;
  color: var(--muted);
}

.chat-message p {
  margin: 0;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}

.composer {
  display: grid;
  width: min(770px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 28px;
  background: transparent;
}

.composer label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font: inherit;
}

.composer-box {
  min-height: 120px;
  padding: 14px;
  border: 1px solid #e6e7eb;
  border-radius: 22px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.composer-box textarea {
  display: block;
  min-height: 54px;
  max-height: 220px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 0 8px;
  color: #111111;
  font-size: 1rem;
  line-height: 1.5;
}

.composer-box textarea::placeholder {
  color: #737373;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  margin-top: 8px;
}

.composer-tool-button,
.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.composer-tool-button {
  background: #ffffff;
  color: #111111;
  box-shadow: 0 1px 5px rgb(15 23 42 / 12%);
}

.composer-tool-button:hover {
  background: #f4f4f5;
}

.composer-tool-button svg,
.send-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.send-button {
  background: #9ca3af;
  color: #ffffff;
}

.send-button:hover {
  background: #6b7280;
}

.send-button:disabled,
.composer.is-sending .send-button {
  cursor: wait;
  background: #9ca3af;
}

.button-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgb(255 255 255 / 45%);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.composer.is-sending .send-icon {
  display: none;
}

.composer.is-sending .button-spinner {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
}

.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-decoration: none;
}

.secondary-action:hover {
  background: #f2f4f7;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.primary-action:disabled {
  background: #98a2b3;
  cursor: wait;
}

.primary-action:disabled:hover {
  background: #98a2b3;
}

.full-width {
  width: 100%;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.memory-panel {
  width: min(980px, calc(100% - 32px));
  margin: 32px auto;
}

.memory-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.memory-header h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.memory-header p {
  margin: 0;
  color: var(--muted);
}

.memory-form {
  display: grid;
  gap: 10px;
}

.memory-form label {
  font-weight: 700;
}

.memory-form textarea {
  min-height: 58vh;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  line-height: 1.5;
}

.memory-actions {
  display: flex;
  justify-content: flex-end;
}

.danger-zone {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.danger-action {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fffbfa;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.danger-action:hover {
  background: #fef3f2;
}

@media (max-width: 760px) {
  .chat-shell {
    grid-template-columns: 52px minmax(0, 1fr);
    min-height: 100vh;
  }

  .app-rail {
    gap: 14px;
    padding-top: 20px;
  }

  .sidebar {
    display: none;
  }

  .rail-menu .conversation-list {
    width: min(260px, calc(100vw - 76px));
  }

  .chat-panel {
    min-height: 100vh;
  }

  .chat-transcript {
    padding: 32px 16px 20px;
  }

  .composer {
    width: calc(100% - 20px);
    padding-bottom: 16px;
  }

  .memory-header {
    align-items: stretch;
    flex-direction: column;
  }
}
