.page-quests {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: var(--page-bg, var(--canvas));
}

.page-quests .topbar { flex: 0 0 auto; }

.page-quests .quest-app {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  overflow: hidden;
  background-color: transparent;
}

.page-quests .quest-sidebar {
  width: 250px;
  flex: 0 0 250px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.page-quests .quest-sidebar-head {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.page-quests .quest-sidebar h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.page-quests #new-quest {
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.page-quests #history-note { margin: 0 0 8px; }

.page-quests #history-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.page-quests .quest-history-item {
  display: grid;
  gap: 2px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-align: left;
  border: 0;
  border-radius: 10px;
  background: transparent;
  padding: 8px 10px;
  margin: 0 0 2px;
  color: inherit;
  font: inherit;
}

.page-quests .quest-history-item:hover { background: var(--canvas); }

.page-quests .quest-history-item.is-selected,
.page-quests .quest-history-item.is-selected:hover { background: var(--accent-weak); }

.page-quests .quest-history-kind {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--muted);
}

.page-quests .quest-history-item.is-command .quest-history-kind { color: var(--amber); }

.page-quests .quest-history-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.page-quests .quest-stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  background-color: var(--surface);
}

.page-quests .quest-column {
  width: min(880px, 100%);
  max-width: 880px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 24px;
}

.page-quests .quest-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overflow-anchor: none;
  padding: 24px 0 12px;
}

.page-quests .quest-empty {
  margin: 28px 0;
  color: var(--body);
  font-size: 15px;
}

.page-quests #detail-status:empty,
.page-quests #detail-error:empty,
.page-quests #live-status:empty,
.page-quests #form-status:empty,
.page-quests #form-error:empty,
.page-quests .quest-alert:empty { display: none; }

.page-quests .quest-message {
  display: grid;
  gap: 4px;
  margin: 0 0 28px;
}

.page-quests .quest-message h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.page-quests .quest-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.page-quests .quest-meta time { font-variant-numeric: tabular-nums; }

.page-quests .quest-message.is-failed .quest-meta { color: var(--danger); }

.page-quests .quest-message.is-succeeded .quest-meta { color: var(--muted); }

.page-quests .quest-message-user { margin-left: 48px; justify-items: end; }
.page-quests .quest-message-user .quest-text { background: var(--canvas); max-width: 100%; }
.page-quests .quest-message-user h3 { font-size: 13px; }
.page-quests .quest-message-agent .quest-text { padding: 8px 0; }
.page-quests .quest-message-agent h3 { margin-bottom: 4px; }
.page-quests .context-note { margin-bottom: 24px; }
.page-quests .chat-prose { white-space: normal; min-width: 0; }
.page-quests .chat-prose > :first-child { margin-top: 0; }
.page-quests .chat-prose > :last-child { margin-bottom: 0; }
.page-quests .chat-prose p { margin: 0 0 12px; }
.page-quests .chat-prose pre { overflow: auto; max-width: 100%; background: var(--canvas); border: 1px solid var(--line); border-radius: 10px; padding: 16px; white-space: pre; font-size: 13px; }
.page-quests .chat-prose table { display: block; overflow: auto; border-collapse: collapse; }
.page-quests .chat-prose th, .page-quests .chat-prose td { border: 1px solid var(--line); padding: 8px 12px; }
.page-quests .chat-prose li { margin: 4px 0; }

.page-quests .quest-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--surface);
  border-radius: 14px;
  padding: 14px 16px;
}

.page-quests .quest-alert {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.page-quests #cancel-button { justify-self: start; margin-top: 4px; }

.page-quests .quest-details {
  margin: 4px 0 12px;
  color: var(--body);
  font-size: 13px;
}

.page-quests .quest-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--muted);
}

.page-quests .quest-details h4 {
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 700;
}

.page-quests .quest-live {
  flex: none;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.page-quests .quest-composer {
  flex: 0 0 auto;
  margin: 0 0 16px;
  padding: 12px 12px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.page-quests #engine-note {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.45;
}

.page-quests .mode-pills {
  display: flex;
  gap: 8px;
  border: 0;
  margin: 0 0 6px;
  padding: 0;
}

.page-quests .mode-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--body);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.page-quests .mode-pill input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  min-width: 1px;
  min-height: 1px;
  margin: 0;
  padding: 0;
}

.page-quests .mode-pill:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.page-quests .mode-question:has(input:checked) {
  border-color: var(--primary);
  background: var(--accent-weak);
  color: var(--ink);
}

.page-quests .mode-command:has(input:checked) {
  border-color: var(--amber-line);
  background: var(--amber-bg);
  color: var(--amber);
}

.page-quests .mode-pill:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

.page-quests .quest-mode-help,
.page-quests .quest-hint,
.page-quests #form-status {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.page-quests .quest-hint { margin: 10px 0 0; text-align: center; }
.page-quests #engine-note[hidden] { display: none; }
.page-quests .mode-pill[hidden] { display: none; }

.page-quests .composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.page-quests .quest-composer textarea {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  margin: 0;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  field-sizing: content;
  line-height: 1.5;
}

.page-quests #send-button { flex: none; }

.page-quests #form-error { margin: 0; }

.page-quests .quest-action {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.page-quests .quest-action p { margin: 0 0 4px; }
