.app-shell:has(.grounded-qa-workbench) {
  width: min(1980px, 98vw);
  height: calc(100dvh - 26px);
  min-height: 0;
  margin: 8px auto 18px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.app-shell:has(.grounded-qa-workbench) > .sidebar {
  display: none;
}

.app-shell:has(.grounded-qa-workbench) .content-pane {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.grounded-qa-workbench {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.grounded-qa-workbench.view-hidden {
  display: none;
}

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

.grounded-qa-card {
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

#search-section-ask {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  min-height: 0;
}

#search-section-ask .grounded-qa-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.grounded-qa-card {
  padding: 0;
  overflow: hidden;
  border-radius: 16px;
}

.grounded-qa-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  flex: 1;
  height: 100%;
  min-height: 0;
}

.qa-sidebar,
.qa-conversation {
  min-width: 0;
  min-height: 0;
}

.qa-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 8px;
  background: color-mix(in srgb, var(--ink) 3%, #fff);
  border-right: 1px solid var(--stroke-soft);
}

.qa-conversation {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0)),
    color-mix(in srgb, var(--ink) 3%, #f3f6f3);
}

.qa-panel-head {
  display: grid;
  gap: 2px;
}

.qa-panel-head {
  padding: 0 8px;
}

.qa-panel-head h2,
.chat-header-row h2 {
  margin: 0;
  font-size: 1rem;
}

.qa-eyebrow {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.qa-new-chat-btn {
  width: calc(100% - 16px);
  margin: 0 8px;
  justify-content: center;
}

.threads-search {
  position: relative;
  padding: 0 8px;
}

.threads-search span {
  position: absolute;
  left: 17px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.78rem;
  pointer-events: none;
}

.threads-search input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 7px 10px 7px 30px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
}

.thread-list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 2px 10px;
}

.thread-group {
  display: grid;
  gap: 2px;
}

.thread-group-label {
  margin: 10px 8px 4px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.thread-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  margin: 0 6px;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.thread-item:hover {
  background: var(--table-row-hover);
}

.thread-item.active {
  background: color-mix(in srgb, var(--accent) 11%, #fff);
  border-color: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.thread-button {
  min-width: 0;
  border: 0;
  padding: 8px 9px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 3px;
  font: inherit;
  text-align: left;
}

.thread-title {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-meta {
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.thread-action {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  opacity: 0;
  transition: background 120ms ease, color 120ms ease, opacity 120ms ease;
}

.thread-item:hover .thread-action,
.thread-item.active .thread-action {
  opacity: 1;
}

.thread-action:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--ink);
}

.thread-empty {
  margin: 8px 6px;
  border: 1px dashed var(--stroke);
  border-radius: 10px;
  padding: 10px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1.4;
}

.chat-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 22px 26px 16px;
  border-bottom: 1px solid var(--stroke-soft);
  background: rgba(255, 255, 255, 0.62);
}

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

.chat-header-actions-floating {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 2;
}

.chat-header-row h2 {
  max-width: min(760px, 52vw);
  overflow: hidden;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.42rem;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 5px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.chat-model-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

.qa-conversation-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.ask-hints {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 48px 24px 18px;
  text-align: center;
}

.ask-hints[hidden] {
  display: none;
}

.ask-hints-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 700;
  box-shadow: 0 18px 34px color-mix(in srgb, var(--accent) 24%, transparent);
}

.ask-hints h2 {
  max-width: 760px;
  margin: 18px 0 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 1.12;
}

.ask-hints p {
  max-width: 760px;
  margin: 0;
  color: var(--ink-soft);
  font-size: clamp(1rem, 1.6vw, 1.35rem);
  line-height: 1.5;
}

.ask-hint-cards {
  display: grid;
  gap: 10px;
  width: min(720px, 100%);
  margin-top: 22px;
}

.ask-hint-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  padding: 12px 16px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: left;
  box-shadow: 0 4px 12px rgba(31, 43, 39, 0.06);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.ask-hint-card:hover,
.ask-hint-card:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--stroke));
  box-shadow: 0 10px 24px rgba(31, 43, 39, 0.1);
  outline: none;
  transform: translateY(-1px);
}

.ask-hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 13%, #fff);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
}

.ask-hint-card strong,
.ask-hint-card small {
  display: block;
  min-width: 0;
}

.ask-hint-card strong {
  font-size: 1rem;
  line-height: 1.25;
}

.ask-hint-card small {
  margin-top: 3px;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ask-hint-arrow {
  color: var(--ink-soft);
  font-size: 1.5rem;
}

.ask-hint-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: min(760px, 100%);
  margin-top: 6px;
}

.ask-hint-chips button {
  min-height: 36px;
  border: 1px solid var(--stroke-soft);
  border-radius: 999px;
  padding: 7px 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  box-shadow: 0 3px 8px rgba(31, 43, 39, 0.05);
}

.ask-hint-chips button:hover,
.ask-hint-chips button:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--stroke));
  color: var(--accent);
  outline: none;
}

.chat-token-usage {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--stroke-soft);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-family: var(--mono);
  white-space: nowrap;
}

#section-search {
  display: flex;
  flex-direction: column;
  min-height: min(580px, 78dvh);
}

#section-search.grounded-qa-workbench {
  height: 100%;
  min-height: 0;
}

#section-search.view-hidden {
  display: none;
}

.chat-messages {
  display: grid;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 8px 24px 22px;
  align-content: start;
}

.chat-messages:empty {
  display: none;
}

.chat-message {
  display: grid;
  gap: 4px;
  max-width: 84%;
}

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

.chat-message-assistant {
  justify-self: start;
  max-width: 92%;
}

.chat-message-status {
  justify-self: stretch;
  max-width: 100%;
  gap: 3px;
}

.chat-message-role {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

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

.chat-role-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-family: var(--sans);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0;
}

.chat-message-user .chat-role-dot {
  order: 2;
  background: linear-gradient(135deg, #5b6f6a, #2e3a36);
}

.chat-message-body {
  border: 1px solid color-mix(in srgb, var(--stroke) 70%, transparent);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(31, 43, 39, 0.06);
  line-height: 1.65;
}

.markdown-output {
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: normal;
}

.markdown-output p,
.markdown-output ul,
.markdown-output ol,
.markdown-output blockquote,
.markdown-output table {
  margin: 0 0 10px 0;
}

.markdown-output h1,
.markdown-output h2 {
  margin: 0 0 8px 0;
  font-family: var(--serif);
  line-height: 1.25;
}

.markdown-output h3 {
  margin: 0 0 8px 0;
  line-height: 1.25;
  font-weight: 700;
}

.markdown-output h1 {
  font-size: 1.15rem;
}

.markdown-output h2 {
  font-size: 1.05rem;
}

.markdown-output h3 {
  font-size: 0.98rem;
}

.markdown-output ul,
.markdown-output ol {
  padding-left: 18px;
}

.markdown-output code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: color-mix(in srgb, var(--accent-soft) 38%, white);
  border-radius: 5px;
  padding: 1px 4px;
}

.markdown-output blockquote {
  border-left: 3px solid var(--stroke);
  padding-left: 10px;
  color: var(--ink-soft);
}

.markdown-output table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--stroke);
  background: var(--table-bg);
}

.markdown-output th,
.markdown-output td {
  border: 1px solid var(--stroke-soft);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.markdown-output th {
  background: var(--table-head-bg);
  color: var(--table-head-ink);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.chat-message-user .chat-message-body {
  background: color-mix(in srgb, var(--accent) 12%, #fff);
  border-color: color-mix(in srgb, var(--accent) 20%, transparent);
  border-bottom-right-radius: 4px;
}

.chat-message-assistant .chat-message-body {
  border-bottom-left-radius: 4px;
}

.chat-message-status .chat-message-body {
  padding: 6px 9px;
  border-style: dashed;
  background: rgba(255, 255, 255, 0.54);
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.chat-status-summary {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) 8px;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 28px;
  border: 0;
  border-radius: 6px;
  padding: 4px 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  text-align: left;
}

.chat-status-summary:hover {
  background: rgba(43, 91, 74, 0.06);
}

.chat-status-marker {
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.chat-status-summary-text {
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.35;
}

.chat-status-live {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.7;
}

.chat-status-detail {
  max-height: 220px;
  overflow: auto;
  margin: 0 0 0 22px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-citations {
  color: var(--ink-soft);
  font-size: 0.78rem;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--stroke-soft);
}

.chat-citations summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 6px;
  transition: background 120ms ease;
}

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

.chat-citations summary::before {
  content: "▶";
  font-size: 0.55rem;
  transition: transform 150ms ease;
  color: var(--ink-soft);
}

.chat-citations[open] summary::before {
  transform: rotate(90deg);
}

.chat-citations summary:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--ink);
}

.chat-citation-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chat-citation-source {
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.74rem;
  transition: border-color 120ms ease, background 120ms ease;
}

.chat-citation-source:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
}

.chat-composer {
  display: grid;
  gap: 6px;
  flex: 0 0 auto;
  position: relative;
  z-index: 3;
  border: 1.5px solid var(--stroke);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 18px 8px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(31, 43, 39, 0.08);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.chat-composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--stroke));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.chat-composer textarea {
  min-height: 52px;
  max-height: 200px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  resize: none;
  overflow-y: auto;
  line-height: 1.55;
}

.chat-composer textarea:focus {
  outline: none;
}

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

.chat-composer-hint {
  color: var(--ink-soft);
  font-size: 0.7rem;
  opacity: 0.7;
  user-select: none;
}

@media (max-width: 960px) {
  .grounded-qa-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .qa-sidebar {
    border: 0;
    border-bottom: 1px solid var(--stroke-soft);
  }

  .chat-messages {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .grounded-qa-card {
    margin-inline: -2px;
  }

  .chat-header-row,
  .chat-composer-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-header-row h2 {
    max-width: 100%;
  }

  .chat-messages {
    padding: 14px 12px;
  }

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

  .chat-composer {
    margin: 0 12px 8px;
  }
}
