:root {
  color-scheme: light;
  --page: #edf2f8;
  --surface: #ffffff;
  --surface-alt: #f5f8fc;
  --history: #eef3f9;
  --text: #1d2733;
  --muted: #5f6e7f;
  --line: #d3dbe6;
  --line-strong: #bcc8d6;
  --accent: #1f4f8f;
  --accent-hover: #183d6f;
  --accent-soft: #dce8f6;
  --danger: #a43333;
  --danger-soft: #f7e6e6;
  --focus: #8eb3df;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

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

button {
  border-radius: 4px;
}

.login-view {
  display: grid;
  width: 100%;
  min-height: 100%;
  place-items: center;
  padding: 24px;
  background: #e8eef5;
}

.login-form {
  display: grid;
  width: min(100%, 380px);
  gap: 10px;
  border: 1px solid var(--line-strong);
  border-top: 4px solid var(--accent);
  padding: 30px;
  background: var(--surface);
}

.login-brand {
  color: var(--accent);
  font-size: 15px;
  font-weight: 750;
}

.login-form h1 {
  margin: 4px 0 14px;
  font-size: 22px;
  line-height: 1.2;
}

.login-form label {
  margin-top: 5px;
  font-weight: 650;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
}

.login-button {
  width: 100%;
  margin-top: 12px;
}

.form-error {
  margin: 4px 0 0;
  color: var(--danger);
}

.app-shell {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
  width: 100%;
  height: 100vh;
}

.topbar {
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
  background: var(--surface);
}

.topbar-start,
.topbar-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.topbar-start {
  flex: 1 1 auto;
}

.brand {
  color: var(--accent);
  font-size: 16px;
  font-weight: 750;
}

.topbar-history-button {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.topbar-history-button:hover,
.topbar-history-button:focus-visible {
  background: #eef4fb;
  color: var(--accent);
}

.topbar-history-icon {
  font-size: 20px;
  line-height: 1;
}

.app-switcher {
  display: flex;
  min-width: 0;
  gap: 8px;
  margin-left: 8px;
}

.app-switcher-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  background: #f4f7fb;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.app-switcher-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.user-name {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.config-menu {
  position: relative;
}

.config-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}

.config-button::-webkit-details-marker {
  display: none;
}

.config-button:hover,
.config-button:focus-visible,
.logout-icon-button:hover,
.logout-icon-button:focus-visible {
  background: #eef4fb;
  color: var(--accent);
}

.config-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.contact-email {
  color: var(--accent);
  font-weight: 700;
  text-underline-offset: 2px;
}

.logout-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

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

.config-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 170px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  box-shadow: 0 16px 36px rgb(24 33 38 / 12%);
}

.config-title {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 14px;
}

.config-field {
  display: grid;
  gap: 8px;
}

.credit-summary {
  margin: 0;
}

.credit-summary .config-label {
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.config-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.config-select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.primary-button,
.new-question-button,
.danger-button {
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  color: #fff;
  font-weight: 650;
}

.primary-button,
.new-question-button {
  border-color: var(--accent);
  background: var(--accent);
}

.primary-button:hover,
.new-question-button:hover {
  background: var(--accent-hover);
}

.primary-button:disabled,
.new-question-button:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.text-button,
.danger-text-button,
.load-more-button,
.mobile-close-button {
  border: 0;
  padding: 6px 8px;
  cursor: pointer;
  background: transparent;
  color: var(--accent);
}

.sidebar-toggle-button {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 16;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  transition: left 180ms ease, transform 180ms ease;
}

.app-body:not(.is-sidebar-collapsed) .sidebar-toggle-button {
  left: 198px;
  transform: none;
}

.sidebar-toggle-icon {
  font-size: 18px;
  line-height: 1;
}

.text-button:hover,
.load-more-button:hover {
  text-decoration: underline;
}

.danger-text-button {
  color: var(--danger);
}

.danger-button {
  border-color: var(--danger);
  background: var(--danger);
}

.mobile-close-button {
  display: none;
}

.app-body {
  position: relative;
  display: grid;
  height: calc(100vh - 56px);
  min-height: 0;
  grid-template-columns: 260px minmax(0, 1fr);
  transition: grid-template-columns 180ms ease;
}

.app-body.is-sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.history-sidebar {
  z-index: 15;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border-right: 1px solid var(--line);
  background: var(--history);
  transition: transform 180ms ease, opacity 180ms ease;
  transform: translateX(0);
  opacity: 1;
}

.app-body.is-sidebar-collapsed .history-sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.history-header {
  display: grid;
  gap: 13px;
  border-bottom: 1px solid var(--line);
  padding: 18px 16px;
}

.history-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-heading-row h1 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
}

.history-subtitle {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.new-question-button {
  width: 100%;
}

.history-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: visible;
  scrollbar-gutter: stable;
}

.history-empty {
  margin: 0;
  padding: 22px 16px;
  color: var(--muted);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-bottom: 1px solid var(--line);
}

.history-open {
  min-width: 0;
  border: 0;
  border-radius: 0;
  padding: 12px 8px 12px 16px;
  cursor: pointer;
  background: transparent;
  color: inherit;
  text-align: left;
}

.history-item:hover,
.history-item.is-active {
  background: var(--surface);
}

.history-item.is-active {
  box-shadow: inset 4px 0 0 var(--accent);
}

.history-question {
  display: -webkit-box;
  overflow: hidden;
  font-weight: 650;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-date {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.history-model {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 12px;
}

.history-delete {
  align-self: stretch;
  border: 0;
  border-radius: 0;
  padding: 8px;
  cursor: pointer;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
}

.history-delete:hover {
  background: var(--danger-soft);
}

.history-delete svg {
  width: 16px;
  height: 16px;
  display: block;
  fill: currentColor;
}

.load-more-button {
  width: 100%;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 10px;
}

.history-footer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 12px 10px;
}

.history-download-button {
  flex: 0 1 auto;
}

.history-download-status {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.history-actions-menu {
  position: relative;
  margin-left: auto;
}

.history-actions-button {
  border: 0;
  padding: 2px 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.history-actions-button::-webkit-details-marker {
  display: none;
}

.history-actions-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: #fff;
  box-shadow: 0 14px 30px rgb(24 33 38 / 12%);
}

.history-action-item {
  width: 100%;
  padding: 4px 0;
  text-align: left;
}

.workspace {
  display: grid;
  height: calc(100vh - 56px);
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  background: var(--surface-alt);
}

.pane {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 26px 28px 34px;
  background: var(--surface-alt);
}

.workspace-view {
  height: 100%;
}

.pane-inner {
  display: grid;
  width: 100%;
  max-width: 1180px;
  height: 100%;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr);
  margin: 0 auto;
}

.pane-label {
  margin: 0 0 16px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 750;
  text-transform: uppercase;
}

.tabbed-box {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent);
  background: var(--surface);
}

.tab-list {
  display: flex;
  min-width: 0;
  align-items: stretch;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: #edf3f9;
}

.tab-button {
  flex: 0 1 auto;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 11px 15px;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  white-space: nowrap;
}

.tab-button[aria-selected="true"] {
  background: var(--surface);
  color: var(--accent);
  font-weight: 750;
}

.tab-run-spacer {
  flex: 1 0 28px;
  min-width: 28px;
}

.tab-run-button {
  align-self: center;
  flex: 0 0 auto;
  margin: 6px 8px 6px 0;
  padding: 7px 18px;
}

.tab-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px 0;
}

.model-picker-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.model-picker-options {
  display: flex;
  gap: 8px;
}

.model-option {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.model-option.is-selected {
  border-color: var(--accent);
  background: #e2ecf8;
  color: var(--accent);
}

.model-option:disabled {
  cursor: default;
  opacity: 0.6;
}

.rated-output {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
}

.query-input,
.output-text,
.process-view {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  border: 0;
  border-radius: 0;
  padding: 18px 20px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
}

.process-view {
  background: transparent;
}

.query-input::placeholder {
  color: #98a1a8;
  opacity: 1;
}

.query-input:focus-visible {
  outline-offset: -3px;
}

.rating-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  border-top: 1px solid var(--line);
  padding: 8px 20px;
  background: #fbfcfc;
}

.rating-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.rating-stars {
  display: flex;
  align-items: center;
  gap: 2px;
}

.rating-star {
  width: 24px;
  height: 24px;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: transparent;
  color: #aab2b8;
  font-size: 18px;
  line-height: 1;
}

.rating-star.is-selected,
.rating-star:hover,
.rating-star:hover ~ .rating-star {
  color: #b48718;
}

.rating-stars:hover .rating-star {
  color: #b48718;
}

.rating-stars .rating-star:hover ~ .rating-star {
  color: #aab2b8;
}

.rating-star:disabled {
  cursor: not-allowed;
}

.feedback-panel {
  position: relative;
}

.feedback-panel .query-input {
  padding-bottom: 42px;
}

.save-status {
  position: absolute;
  right: 28px;
  bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.output-section {
  margin: 0 0 24px;
}

.output-section:last-child {
  margin-bottom: 0;
}

.output-section-title {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 750;
}

.output-section-body,
.source-title,
.source-meta,
.source-relevance {
  margin: 0;
}

.output-section-list {
  margin: 0;
  padding-left: 20px;
}

.output-section-list-item + .output-section-list-item {
  margin-top: 6px;
}

.source-list {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.source-item {
  border-left: 3px solid var(--accent-soft);
  padding-left: 12px;
}

.source-title {
  margin-bottom: 4px;
  font-weight: 750;
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 12px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

.warning-list {
  margin: 0;
  padding-left: 20px;
}

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

.output-text a {
  color: var(--accent);
  font-weight: 650;
  text-underline-offset: 2px;
}

.process-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.process-metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 9px 10px;
  background: #fbfcfc;
}

.process-metric-label {
  display: block;
  overflow: hidden;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.process-metric strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.process-error {
  margin: 0 0 16px;
  border-left: 3px solid var(--danger);
  padding: 8px 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 650;
}

.process-timeline {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.process-event {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  border-left: 3px solid var(--accent-soft);
  padding-left: 12px;
}

.process-event-time {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  white-space: nowrap;
}

.process-event-title {
  margin: 0;
  font-weight: 750;
}

.process-details {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.process-details dt {
  font-weight: 650;
}

.process-details dd {
  margin: 0;
}

.process-details dd::after {
  content: "";
}

.chat-workspace .pane-inner {
  max-width: 1120px;
}

.chat-shell {
  position: relative;
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #f5f8fc;
}

.chat-header {
  display: none;
}

.chat-header-side {
  display: grid;
  justify-items: end;
  gap: 14px;
}

.chat-kicker {
  margin: 0 0 6px;
  color: #406c93;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.chat-summary {
  max-width: 360px;
  margin: 0;
  color: var(--muted);
  text-align: right;
}

.chat-model-picker {
  display: grid;
  gap: 8px;
}

.chat-model-picker-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: right;
  text-transform: uppercase;
}

.chat-model-picker-options {
  display: flex;
  gap: 8px;
}

.chat-model-option {
  border: 1px solid #bed0df;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgb(255 255 255 / 82%);
  color: #406c93;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.chat-model-option.is-selected {
  border-color: #406c93;
  background: #406c93;
  color: #fff;
}

.chat-thread {
  display: grid;
  align-content: start;
  gap: 28px;
  min-height: 0;
  overflow-y: auto;
  padding: 48px 24px 72px;
  scrollbar-gutter: stable;
  width: min(820px, calc(100% - 48px));
  margin: 0 auto;
}

.chat-empty {
  max-width: 620px;
  border: 1px dashed #d7e0e8;
  border-radius: 20px;
  padding: 24px 26px;
  background: rgb(255 255 255 / 78%);
}

.chat-empty h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.chat-empty p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.chat-message {
  display: grid;
  gap: 8px;
  max-width: min(82%, 760px);
}

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

.chat-message-assistant,
.chat-message-system {
  justify-self: start;
}

.chat-message-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.chat-bubble {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  background: rgb(255 255 255 / 88%);
  box-shadow: 0 10px 24px rgb(24 33 38 / 6%);
}

.chat-message-user .chat-bubble {
  border-color: #c9d8ea;
  background: linear-gradient(180deg, #eff5fc 0%, #e5eef9 100%);
}

.chat-message-assistant .chat-bubble {
  border-color: #c8d8e7;
  background: linear-gradient(180deg, #ffffff 0%, #f5f9fc 100%);
}

.chat-message-system .chat-bubble {
  border-style: dashed;
  background: rgb(255 255 255 / 55%);
}

.chat-bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.chat-next-step {
  margin: 0;
  color: inherit;
  font: inherit;
  line-height: inherit;
  white-space: pre-wrap;
}

.chat-progress-line {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #6f8193;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.chat-progress-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  color: var(--accent);
  border-radius: 50%;
  background: conic-gradient(from 0deg, color-mix(in srgb, currentColor 18%, transparent), currentColor);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 0);
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 0);
  animation: chat-progress-spin 1s linear infinite;
}

.chat-progress-label {
  line-height: 1.35;
}

@keyframes chat-progress-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-progress-icon {
    animation: none;
  }
}

.chat-message-stats-menu {
  position: relative;
  justify-self: start;
}

.chat-message-actions {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.chat-message-stats-trigger {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  font-size: 20px;
  line-height: 1;
}

.chat-message-stats-trigger::-webkit-details-marker,
.chat-stat-item-trigger::-webkit-details-marker {
  display: none;
}

.chat-message-stats-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 160px;
  border: 1px solid #d4dde6;
  border-radius: 12px;
  padding: 8px 10px;
  background: #fff;
  box-shadow: 0 14px 30px rgb(24 33 38 / 12%);
}

.chat-stat-item + .chat-stat-item {
  margin-top: 6px;
}

.chat-stat-item-trigger {
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-stat-item-value {
  margin-top: 4px;
  color: var(--text);
  font-size: 13px;
}

.chat-source-stack {
  display: grid;
  gap: 10px;
}

.chat-source-card {
  border: 1px solid #d6e0ea;
  border-radius: 14px;
  background: rgb(255 255 255 / 78%);
}

.chat-source-card[open] {
  background: #fff;
}

.chat-source-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
}

.chat-source-summary::-webkit-details-marker {
  display: none;
}

.chat-source-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid #c7d8e7;
  border-radius: 999px;
  padding: 3px 9px;
  color: #406c93;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-source-body {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.chat-source-title,
.chat-source-text,
.chat-source-meta {
  margin: 0;
}

.chat-source-title {
  font-weight: 750;
}

.chat-source-meta {
  color: var(--muted);
  font-size: 12px;
}

.chat-source-text {
  color: var(--text);
}

.chat-source-link {
  color: var(--accent);
  font-weight: 700;
  text-underline-offset: 2px;
}

.chat-consulted-button,
.chat-copy-button,
.chat-feedback-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.chat-consulted-button svg,
.chat-copy-button svg,
.chat-feedback-button svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;
}

.chat-consulted-button:hover,
.chat-consulted-button:focus-visible,
.chat-consulted-button[aria-expanded="true"],
.chat-copy-button:hover,
.chat-copy-button:focus-visible,
.chat-copy-button.is-copied,
.chat-feedback-button:hover,
.chat-feedback-button:focus-visible,
.chat-feedback-button.has-feedback {
  color: var(--accent);
}

.chat-feedback-button svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.chat-copy-button.is-copy-error {
  color: var(--danger);
}

.chat-consulted-scrim {
  position: absolute;
  inset: 0;
  background: rgb(24 33 38 / 18%);
  z-index: 19;
}

.chat-consulted-panel {
  position: absolute;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: min(420px, calc(100% - 36px));
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgb(255 255 255 / 97%);
  box-shadow: 0 22px 48px rgb(24 33 38 / 18%);
  z-index: 20;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.chat-consulted-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.chat-consulted-panel-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
}

.chat-consulted-panel-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.chat-consulted-panel-close {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

.chat-source-select-actions {
  margin-top: 12px;
}

.chat-consulted-panel-body {
  overflow-y: auto;
  padding: 18px 18px 20px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.chat-feedback-form {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px 20px 20px;
}

.chat-feedback-form label,
.chat-feedback-rating legend {
  font-size: 13px;
  font-weight: 700;
}

.chat-feedback-rating {
  margin: 0;
  padding: 0;
  border: 0;
}

.chat-feedback-stars {
  display: flex;
  gap: 4px;
  margin-top: 7px;
}

.chat-feedback-stars button {
  border: 0;
  padding: 2px;
  background: transparent;
  color: #aab5bf;
  cursor: pointer;
  font-size: 27px;
  line-height: 1;
}

.chat-feedback-stars button:hover,
.chat-feedback-stars button:focus-visible,
.chat-feedback-stars button.is-selected {
  color: #d69a2d;
}

.chat-feedback-form textarea {
  min-height: 130px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  color: var(--text);
  font: inherit;
}

.chat-feedback-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.chat-feedback-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.chat-consulted-section {
  display: grid;
  gap: 10px;
}

.chat-consulted-section-title {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chat-composer {
  display: grid;
  gap: 10px;
  width: min(860px, calc(100% - 48px));
  margin: 0 auto 28px;
  padding: 0;
  background: transparent;
}

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

.chat-landing-intro {
  display: none;
  margin: 0 0 18px;
  color: #1f1f1f;
  font-size: 26px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
}

.chat-disclaimer {
  margin: 28px 0 10px;
  color: #8a8f98;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
}

.chat-input {
  min-height: 58px;
  max-height: 240px;
  border: 0;
  border-radius: 30px;
  padding: 18px 126px 18px 114px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  box-shadow: none;
  overflow-y: hidden;
  width: 100%;
}

.chat-input:focus,
.chat-input:focus-visible {
  outline: none;
}

.chat-input:focus {
  overflow-y: auto;
  scrollbar-color: #aab8c4 transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.chat-input:focus::-webkit-scrollbar {
  width: 5px;
}

.chat-input:focus::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #aab8c4;
}

.chat-input-shell {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 58px;
  border: 1px solid #e1e1dc;
  border-radius: 30px;
  background: #fff;
  box-shadow: 0 2px 10px rgb(24 33 38 / 6%);
}

.chat-attach-button {
  position: absolute;
  left: clamp(8px, 1.2vw, 12px);
  bottom: clamp(7px, 1.2vw, 10px);
  width: clamp(34px, 5vw, 42px);
  height: clamp(34px, 5vw, 42px);
  border: 1px solid #cbd6e1;
  border-radius: 999px;
  padding: 0;
  background: #fff;
  color: #576878;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: clamp(22px, 3vw, 26px);
  line-height: 1;
}

.chat-source-select-button {
  position: absolute;
  left: clamp(44px, 6vw, 58px);
  bottom: clamp(7px, 1.2vw, 10px);
  width: clamp(34px, 5vw, 42px);
  height: clamp(34px, 5vw, 42px);
  border: 1px solid #cbd6e1;
  border-radius: 999px;
  padding: 0;
  background: #fff;
  color: #576878;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: clamp(22px, 3vw, 26px);
  line-height: 1;
}

.chat-source-select-button:hover,
.chat-source-select-button:focus-visible { background: #eef4fb; color: var(--accent); }

.chat-attach-button svg,
.chat-source-select-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.source-choice-list { display: grid; gap: 8px; margin: 14px 0; }
.source-tree { gap: 10px; }
.source-tree-branch { display: grid; gap: 8px; }
.source-tree-toggle { display: flex; align-items: center; width: 100%; min-height: 44px; gap: 9px; padding: 10px 12px; border: 1px solid #dbe2e8; border-radius: 9px; background: #fff; color: #263744; font: inherit; font-weight: 650; text-align: left; cursor: pointer; }
.source-tree-toggle:hover, .source-tree-toggle:focus-visible { border-color: #9ab5cf; background: #f6f9fc; outline: none; }
.source-tree-chevron { display: inline-grid; place-items: center; width: 16px; color: #50708d; font-size: 20px; line-height: 1; }
.source-tree-count { min-width: 20px; margin-left: auto; padding: 1px 6px; border-radius: 999px; background: #e8f1fa; color: #15598e; font-size: 12px; font-weight: 700; text-align: center; }
.source-tree-children { display: grid; gap: 8px; margin-left: 16px; padding-left: 12px; border-left: 1px solid #dbe2e8; }
.source-choice-item { display: flex; align-items: flex-start; gap: 9px; padding: 10px; border: 1px solid #dbe2e8; border-radius: 9px; color: #263744; font-size: 14px; line-height: 1.35; }
.source-tree-leaf { background: #fff; }
.source-choice-item input { margin-top: 3px; accent-color: var(--accent); }
.source-choice-error { margin: 8px 0; color: #a12c2c; font-size: 13px; }

.chat-record-button {
  position: absolute;
  right: clamp(50px, 6.6vw, 58px);
  bottom: clamp(7px, 1.2vw, 10px);
  width: clamp(34px, 5.2vw, 44px);
  height: clamp(34px, 5.2vw, 44px);
  border: 1px solid #cbd6e1;
  border-radius: 999px;
  padding: 0;
  background: #fff;
  color: #576878;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.chat-record-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.chat-record-button:hover,
.chat-record-button:focus-visible {
  background: #eef4fb;
  color: var(--accent);
}

.chat-record-button.is-recording {
  background: #fff0f0;
  color: #bc2f2f;
}

.chat-record-button.is-transcribing {
  color: #8a8f98;
  cursor: wait;
}

.chat-voice-status,
.chat-voice-notice {
  margin: -2px 8px 0;
  color: #667788;
  font-size: 12px;
  line-height: 1.35;
}

.chat-voice-status.is-error {
  color: #a12c2c;
}

.chat-attach-button:hover,
.chat-attach-button:focus-visible {
  background: #eef4fb;
  color: var(--accent);
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(860px, calc(100% - 48px));
  margin: 0 auto;
  padding: 0 4px;
}

.chat-submission-error {
  flex-basis: 100%;
  margin: 0;
  color: #a12c2c;
  font-size: 13px;
  line-height: 1.35;
}

.chat-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  border: 1px solid #d1dbe7;
  border-radius: 999px;
  padding: 7px 10px;
  background: #fff;
  color: #40607e;
  font-size: 13px;
}

.chat-attachment-chip.is-pending {
  border-style: dashed;
  color: #667788;
}

.chat-attachment-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-attachment-chip-remove {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.chat-starters {
  display: grid;
  justify-items: start;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  margin: 12px 0 0;
  padding-left: 22px;
}

.chat-starter-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #8a8f98;
  cursor: pointer;
  font-size: 15px;
  text-align: left;
}

.chat-starter-button:hover,
.chat-starter-button:focus-visible {
  color: #406c93;
  outline: none;
}

.chat-starter-icon {
  color: #98a4b0;
  font-size: 20px;
  line-height: 1;
}

.chat-starter-label {
  line-height: 1.35;
}

.chat-send-button {
  position: absolute;
  right: clamp(6px, 1.2vw, 10px);
  bottom: clamp(6px, 1.2vw, 10px);
  min-width: 0;
  width: clamp(34px, 5.2vw, 44px);
  height: clamp(34px, 5.2vw, 44px);
  padding: 0;
  border-radius: 999px;
  font-size: 0;
}

.chat-send-button::before {
  content: "↑";
  font-size: clamp(16px, 2.4vw, 20px);
  line-height: 1;
}

.chat-send-button:hover,
.chat-send-button:focus-visible {
  background: var(--accent-hover);
}

.chat-shell.is-landing .chat-thread {
  display: none;
}

.chat-shell.is-landing .chat-composer {
  align-self: center;
  margin-bottom: 0;
}

.chat-shell.is-landing .chat-landing-intro {
  display: block;
}

.chat-shell.is-landing .chat-input {
  min-height: 60px;
}

.chat-shell.is-landing #chat-consulted-panel,
.chat-shell.is-landing #chat-consulted-scrim,
.chat-shell.is-landing #chat-feedback-panel,
.chat-shell.is-landing #chat-feedback-scrim {
  display: none;
}

.confirm-dialog {
  width: min(92vw, 430px);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
}

.confirm-dialog::backdrop {
  background: rgb(24 30 34 / 45%);
}

.confirm-dialog form {
  padding: 22px;
}

.confirm-dialog h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

.confirm-dialog p {
  margin: 0 0 22px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.sidebar-scrim {
  display: none;
}

@media (max-width: 980px) {
  .app-body {
    height: calc(100vh - 56px);
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar-toggle-button,
  .mobile-close-button {
    display: inline-block;
  }

  .sidebar-toggle-button {
    position: fixed;
    top: auto;
    left: 16px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    z-index: 17;
    box-shadow: 0 8px 20px rgb(24 33 38 / 12%);
  }

  .app-body:not(.is-sidebar-collapsed) .sidebar-toggle-button {
    left: 16px;
    transform: none;
  }

  .history-sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    width: min(88vw, 320px);
    height: calc(100vh - 56px);
    max-height: calc(100vh - 56px);
    transform: translateX(-102%);
    transition: transform 160ms ease;
    box-shadow: 8px 0 22px rgb(29 37 41 / 18%);
  }

  .history-sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-scrim {
    position: fixed;
    z-index: 14;
    inset: 0;
    display: block;
    background: rgb(24 30 34 / 35%);
  }

  .process-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chat-header {
    align-items: start;
    flex-direction: column;
  }

  .chat-header-side {
    width: 100%;
    justify-items: start;
  }

  .chat-summary {
    max-width: none;
    text-align: left;
  }

  .chat-model-picker-label {
    text-align: left;
  }

  .chat-consulted-panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(100%, 440px);
    border-radius: 0;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .login-form input {
    font-size: 16px;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
  }

  .app-body,
  .workspace,
  .history-sidebar {
    height: auto;
    max-height: none;
  }

  .topbar {
    padding: 0 14px;
  }

  .topbar-start {
    gap: 10px;
  }

  .brand {
    display: none;
  }

  .topbar-history-button {
    display: inline-flex;
  }

  .app-switcher {
    overflow-x: auto;
    margin-left: 0;
    padding-bottom: 2px;
  }

  .user-name {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .pane {
    height: min(690px, calc(100dvh - 80px));
    min-height: 480px;
    padding: 22px 16px 28px;
  }

  .tab-button {
    flex: 1 0 auto;
    padding: 10px 11px;
  }

  .tab-run-spacer {
    flex-basis: 18px;
    min-width: 18px;
  }

  .tab-run-button {
    margin-right: 6px;
    padding: 7px 16px;
  }

  .process-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .process-event {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .chat-thread,
  .chat-header,
  .chat-composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chat-composer {
    width: 100%;
    margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  }

  .chat-attachments {
    width: 100%;
  }

  .chat-title {
    font-size: 24px;
  }

  .chat-message {
    max-width: 100%;
  }

  .chat-input-shell {
    min-height: 52px;
    border-radius: 24px;
    padding-right: clamp(42px, 14vw, 54px);
  }

  .chat-input {
    min-height: 52px;
    padding: 12px 100px 12px 94px;
    font-size: 16px;
  }

  .chat-input-shell {
    min-height: 94px;
    border-radius: 26px;
    padding-right: 0;
  }

  .chat-input {
    min-height: 94px;
    padding: 14px 16px 52px;
  }

  .chat-composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-model-picker-options,
  .chat-message-stats {
    flex-wrap: wrap;
  }

  .chat-send-button {
    right: clamp(6px, 2vw, 8px);
    bottom: clamp(6px, 2vw, 8px);
    width: clamp(34px, 10vw, 40px);
    height: clamp(34px, 10vw, 40px);
  }

  .chat-record-button {
    right: clamp(54px, 14vw, 62px);
    bottom: clamp(6px, 2vw, 8px);
    width: clamp(34px, 10vw, 40px);
    height: clamp(34px, 10vw, 40px);
  }

  .chat-send-button::before {
    font-size: 18px;
  }

  .chat-attach-button {
    left: 8px;
    bottom: 6px;
    width: clamp(32px, 9vw, 38px);
    height: clamp(32px, 9vw, 38px);
    font-size: 22px;
  }

  .chat-source-select-button {
    left: clamp(50px, 13vw, 58px);
    bottom: 6px;
  }

  .sidebar-toggle-button {
    top: 11px;
    bottom: auto;
    left: 14px;
    z-index: 21;
    width: 34px;
    height: 34px;
  }

  .app-body:not(.is-sidebar-collapsed) .sidebar-toggle-button {
    left: 14px;
  }

  .sidebar-toggle-button {
    display: none;
  }

  .sidebar-toggle-icon {
    font-size: 0;
  }

  .sidebar-toggle-icon::before {
    content: "☰";
    font-size: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .history-sidebar {
    transition: none;
  }
}
