.ka-root {
  --ka-border: #e2e8f0;
  --ka-muted: #64748b;
  --ka-blue: #2563eb;
  max-width: none;
  margin: 0 auto;
  padding: 12px 0 0;
}

/* The chat owns the fold: drop the site-wide bottom padding on this page
   so the panel can use it (fitApp() still measures any remainder). */
body:has(> .container > #ka-root) {
  padding-bottom: 0;
}

.container:has(> #ka-root) {
  padding-bottom: 0;
}

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

.ka-header,
.ka-header-actions,
.ka-dialog-header,
.ka-status-actions,
.ka-source-actions,
.ka-feedback,
.ka-feedback-dialog-header,
.ka-feedback-actions,
.ka-diagnostic-tags {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ka-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.ka-header-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.ka-header h2,
.ka-dialog-header h3,
.ka-empty-state h3,
.ka-conversation-group h3 {
  margin: 0;
}

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

.ka-status-button,
.ka-sidebar-toggle,
.ka-new-conversation,
.ka-composer button,
.ka-feedback button,
.ka-status-actions button,
.ka-dialog-header button,
.ka-feedback-dialog button,
.ka-source-actions button,
.ka-source-actions a,
.ka-audio-close,
.ka-example-chip,
.ka-conversation-actions button {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #1e293b;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.ka-app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: calc(100vh - 200px);
  min-height: 480px;
  overflow: hidden;
  border: 1px solid var(--ka-border);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 30px rgb(15 23 42 / 7%);
}

.ka-sidebar {
  min-width: 0;
  overflow-y: auto;
  padding: 14px 10px;
  border-right: 1px solid var(--ka-border);
  background: #f8fafc;
}

.ka-new-conversation {
  width: 100%;
  border-color: var(--ka-blue);
  color: var(--ka-blue);
  font-weight: 700;
}

.ka-conversation-list {
  margin-top: 16px;
}

.ka-conversation-group + .ka-conversation-group {
  margin-top: 18px;
}

.ka-conversation-group h3 {
  padding: 0 8px 6px;
  color: var(--ka-muted);
  font-size: 12px;
  font-weight: 700;
}

.ka-conversation-item {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  border-radius: 8px;
}

.ka-conversation-item.is-active {
  background: #dbeafe;
}

.ka-conversation-open {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  border: 0;
  background: transparent;
  padding: 9px 66px 9px 9px;
  color: #334155;
  cursor: pointer;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ka-conversation-actions {
  position: absolute;
  right: 4px;
  display: none;
  gap: 2px;
}

.ka-conversation-item:hover .ka-conversation-actions,
.ka-conversation-item:focus-within .ka-conversation-actions,
.ka-conversation-item.show-actions .ka-conversation-actions {
  display: flex;
}

.ka-conversation-actions button {
  border: 0;
  padding: 4px 5px;
  background: #fff;
  font-size: 13px;
}

.ka-conversation-rename {
  width: calc(100% - 12px);
  margin: 5px 6px;
  border: 1px solid #93c5fd;
  border-radius: 6px;
  padding: 6px 7px;
  font: inherit;
}

.ka-sidebar-backdrop {
  display: none;
}

.ka-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: #f8fafc;
}

.ka-message {
  min-height: 0;
  margin: 0;
  padding: 0 20px;
  background: #fff7ed;
  color: #b45309;
  line-height: 0;
  transition: padding .15s ease, line-height .15s ease;
}

.ka-message:not(:empty) {
  padding-top: 8px;
  padding-bottom: 8px;
  line-height: 1.4;
}

.ka-scope-banner {
  margin: 0 16px 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #f4f0ff;
  color: #4b327d;
  text-align: center;
}

.ka-scope-banner button,
.ka-widen {
  border: 0;
  background: none;
  color: #6542a5;
  cursor: pointer;
  text-decoration: underline;
}

.ka-widen.is-emphasized { font-weight: 700; }

.ka-conversation-scope { display: block; font-size: .75rem; color: #716b7a; padding: 0 10px 6px; }

.ka-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px clamp(18px, 5vw, 72px) 32px;
  scroll-behavior: smooth;
}

.ka-empty-state {
  max-width: 620px;
  margin: clamp(60px, 14vh, 130px) auto 0;
  color: #334155;
  text-align: center;
}

/* The greeting is the only text on an empty thread, so it carries the page.
   Scales down on narrow screens, where the display name can push it to a
   second line. */
.ka-empty-state h3 {
  font-size: clamp(22px, 3.4vw, 30px);
  line-height: 1.4;
}

.ka-placeholder {
  color: var(--ka-muted);
}

.ka-example-chips {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 32px;
}

.ka-example-chip {
  border-radius: 999px;
  color: #1d4ed8;
}

.ka-message-row {
  display: flex;
  margin-bottom: 22px;
}

.ka-message-row.is-user {
  justify-content: flex-end;
}

.ka-bubble {
  max-width: min(860px, 88%);
  border-radius: 14px;
  line-height: 1.7;
}

.ka-user-bubble {
  padding: 10px 15px;
  border-bottom-right-radius: 4px;
  background: var(--ka-blue);
  color: #fff;
  white-space: pre-wrap;
}

.ka-assistant-bubble {
  width: min(860px, 100%);
  padding: 16px 18px;
  border: 1px solid var(--ka-border);
  border-bottom-left-radius: 4px;
  background: #fff;
  box-shadow: 0 3px 12px rgb(15 23 42 / 5%);
}

.ka-answer {
  white-space: pre-wrap;
}

.ka-answer-heading {
  margin-top: 0.8em;
  font-size: 1.06em;
  font-weight: 700;
}

.ka-answer-bullet {
  padding-left: 1em;
}

.ka-answer a,
.ka-citation-link {
  color: #1d4ed8;
  font-weight: 700;
}

.ka-pending {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ka-muted);
}

.ka-spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ka-border);
  border-top-color: var(--ka-blue);
  border-radius: 50%;
  animation: ka-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .ka-spinner {
    animation-duration: 2.4s;
  }
}

.ka-standalone-question {
  margin: 0 0 12px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
}

.ka-support {
  display: inline-block;
  margin-top: 14px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.ka-support.is-high {
  background: #dcfce7;
  color: #166534;
}

.ka-support.is-low {
  background: #fef3c7;
  color: #92400e;
}

.ka-support.is-none,
.ka-support.is-unknown {
  background: #e2e8f0;
  color: #475569;
}

.ka-feedback {
  margin-top: 10px;
}

.ka-feedback button {
  padding: 5px 9px;
  font-size: 13px;
}

.ka-feedback button[aria-disabled="true"] {
  opacity: .58;
  cursor: default;
}

.ka-feedback button.is-selected {
  opacity: 1;
  background: #dbeafe;
  border-color: #93c5fd;
}

.ka-feedback-status {
  color: #166534;
  font-size: 13px;
}

.ka-feedback .ka-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 30px;
  padding: 0;
  color: #475569;
}

.ka-feedback .ka-copy.is-done {
  color: #166534;
}

.ka-sources {
  margin-top: 14px;
  border-top: 1px solid var(--ka-border);
  padding-top: 11px;
}

.ka-sources > summary,
.ka-diagnostics summary {
  cursor: pointer;
  color: #475569;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.ka-sources > summary::-webkit-details-marker,
.ka-diagnostics summary::-webkit-details-marker {
  display: none;
}

.ka-sources > summary::before,
.ka-diagnostics summary::before {
  content: '▸';
  display: inline-block;
  width: 14px;
  transition: transform .15s ease;
}

.ka-sources[open] > summary::before,
.ka-diagnostics[open] summary::before {
  transform: rotate(90deg);
}

.ka-sources[open] > summary {
  margin-bottom: 10px;
}

.ka-source-card + .ka-source-card {
  margin-top: 10px;
}

.ka-source-card {
  padding: 0;
  border: 1px solid #dbe3ee;
  border-radius: 10px;
  background: #f8fafc;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.ka-source-card.is-highlighted {
  border-color: var(--ka-blue);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 14%);
}

.ka-source-title,
.ka-diagnostic-title {
  font-weight: 700;
}

.ka-source-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 11px 13px;
  cursor: pointer;
  list-style: none;
}

.ka-source-title::-webkit-details-marker {
  display: none;
}

.ka-source-title::before {
  content: '▸';
  flex: none;
  color: var(--ka-muted);
  transition: transform .15s ease;
}

.ka-source-card[open] > .ka-source-title::before {
  transform: rotate(90deg);
}

.ka-source-meta {
  margin-top: 3px;
  color: var(--ka-muted);
  font-size: 13px;
  font-weight: 400;
}

.ka-source-excerpt {
  margin: 0 13px 9px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.ka-source-actions {
  flex-wrap: wrap;
  padding: 0 13px 12px;
}

.ka-source-actions button,
.ka-source-actions a {
  padding: 5px 9px;
  font-size: 13px;
}

.ka-diagnostics {
  margin-top: 14px;
  border-top: 1px solid var(--ka-border);
  padding-top: 11px;
  color: #475569;
  font-size: 13px;
}

.ka-diagnostic-summary {
  margin: 10px 0;
}

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

.ka-diagnostic-item {
  padding: 9px 10px;
  border-left: 3px solid #60a5fa;
  background: #f8fafc;
}

.ka-diagnostic-item.is-below-floor {
  border-left-color: #cbd5e1;
  opacity: .72;
}

.ka-diagnostic-tags {
  flex-wrap: wrap;
  margin-top: 5px;
}

.ka-diagnostic-tag {
  border-radius: 999px;
  padding: 2px 6px;
  background: #e2e8f0;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
}

.ka-composer {
  padding: 10px clamp(18px, 5vw, 72px) 12px;
  border-top: 1px solid var(--ka-border);
  background: #fff;
}

.ka-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 860px;
  margin: 0 auto;
  border: 1px solid #cbd5e1;
  border-radius: 18px;
  padding: 8px 8px 8px 16px;
  background: #fff;
  box-shadow: 0 2px 10px rgb(15 23 42 / 5%);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.ka-composer-box:focus-within {
  border-color: var(--ka-blue);
  box-shadow: 0 0 0 3px rgb(37 99 235 / 14%);
}

.ka-composer textarea {
  min-height: 24px;
  max-height: 180px;
  flex: 1;
  margin: 6px 0;
  resize: none;
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  line-height: 1.5;
}

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

.ka-composer button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  padding: 0;
}

.ka-composer button,
#ka-rebuild {
  border-color: var(--ka-blue);
  background: var(--ka-blue);
  color: #fff;
}

.ka-composer-hint {
  max-width: 860px;
  margin: 8px auto 0;
  color: #94a3b8;
  font-size: 12px;
  text-align: center;
}

.ka-depth-controls[hidden] { display: none; }
.ka-depth-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 860px;
  margin: 0 auto 8px;
  color: var(--ka-muted);
  font-size: 12px;
}
.ka-depth-controls button,
.ka-primary-hint button {
  width: auto;
  height: auto;
  padding: 4px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  font: inherit;
}
.ka-depth-controls button[hidden] { display: none; }
.ka-depth-controls button[aria-pressed="true"] {
  border-color: var(--ka-blue);
  background: #eff6ff;
  color: #1d4ed8;
}
.ka-answer-depth { display: block; margin-bottom: 6px; font-size: 12px; color: var(--ka-muted); }
.ka-primary-hint { margin-top: 12px; font-size: 13px; color: var(--ka-muted); }
.ka-primary-hint button { margin-left: 8px; }

/* An author display wins over the UA's [hidden] { display: none }, so the
   bar has to opt back out or it shows even while hidden. */
.ka-audio-bar[hidden] {
  display: none;
}

.ka-audio-bar {
  position: sticky;
  z-index: 4;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.ka-audio {
  flex: 1;
  min-width: 0;
}

/* Square so the × sits on the axis of the player's own round controls. */
.ka-audio-close {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.ka-feedback-dialog {
  width: min(520px, calc(100vw - 32px));
  box-sizing: border-box;
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 14px;
  color: #1e293b;
  box-shadow: 0 20px 60px rgb(15 23 42 / 28%);
}

.ka-feedback-dialog::backdrop {
  background: rgb(15 23 42 / 45%);
}

.ka-feedback-form {
  padding: 20px;
}

.ka-feedback-dialog-header {
  justify-content: space-between;
  margin-bottom: 16px;
}

.ka-feedback-dialog-header h3 {
  margin: 0;
}

.ka-feedback-dialog-header button {
  border: 0;
  padding: 2px 8px;
  font-size: 26px;
}

.ka-feedback-reasons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ka-feedback-reasons button {
  border-radius: 999px;
  padding: 7px 11px;
}

.ka-feedback-reasons button[aria-pressed="true"] {
  border-color: var(--ka-blue);
  background: #dbeafe;
  color: #1d4ed8;
}

.ka-feedback-note-label {
  display: block;
  margin: 16px 0 6px;
  color: #475569;
  font-size: 13px;
}

.ka-feedback-dialog textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 10px;
  font: inherit;
}

.ka-feedback-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.ka-feedback-actions button {
  border-color: var(--ka-blue);
  background: var(--ka-blue);
  color: #fff;
}

.mv-dialog-body {
  padding: 20px;
}

.mv-intro,
.mv-status {
  color: #475569;
}

.mv-form[hidden] {
  display: none;
}

.mv-form {
  display: grid;
  gap: 8px;
}

.mv-form label {
  margin-top: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

.mv-form input {
  box-sizing: border-box;
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 10px;
  font: inherit;
}

.ka-message-action {
  margin-left: 8px;
  border: 1px solid #93c5fd;
  border-radius: 7px;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
  font: inherit;
}

.ka-status-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: 82vh;
  padding: 20px;
  border: 0;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgb(15 23 42 / 28%);
}

.ka-status-dialog::backdrop {
  background: rgb(15 23 42 / 45%);
}

.ka-dialog-header {
  justify-content: space-between;
}

.ka-dialog-header button {
  border: 0;
  padding: 2px 8px;
  font-size: 26px;
}

.ka-status-summary {
  margin: 12px 0;
  color: #475569;
}

.ka-status-table-wrap {
  max-height: 55vh;
  overflow: auto;
  margin-top: 12px;
}

.ka-status-table-wrap h4 {
  margin: 0 0 6px;
}

.ka-status-table {
  width: 100%;
  border-collapse: collapse;
}

.ka-status-table th,
.ka-status-table td {
  padding: 9px;
  border-bottom: 1px solid var(--ka-border);
  text-align: left;
}

@media (max-width: 760px) {
  .ka-root {
    padding: 6px 0 0;
  }

  .ka-header {
    gap: 8px;
  }

  .ka-header-title {
    min-width: 0;
    flex: 1;
  }

  .ka-header h2 {
    overflow: hidden;
    font-size: 17px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ka-sidebar-toggle {
    display: inline-block;
    padding: 6px 9px;
  }

  .ka-status-button {
    flex: none;
    padding: 6px 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  .ka-app {
    position: relative;
    display: block;
    height: calc(100vh - 150px);
    min-height: 480px;
    border-radius: 10px;
  }

  .ka-sidebar {
    position: absolute;
    z-index: 12;
    inset: 0 auto 0 0;
    width: min(82vw, 300px);
    border-right: 1px solid var(--ka-border);
    box-shadow: 14px 0 30px rgb(15 23 42 / 18%);
    transform: translateX(-105%);
    transition: transform .18s ease;
  }

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

  .ka-sidebar-backdrop:not([hidden]) {
    position: absolute;
    z-index: 11;
    inset: 0;
    display: block;
    width: 100%;
    border: 0;
    background: rgb(15 23 42 / 38%);
  }

  .ka-main {
    height: 100%;
  }

  .ka-thread {
    padding: 18px 12px 22px;
  }

  .ka-bubble {
    max-width: 94%;
  }

  .ka-assistant-bubble {
    padding: 13px;
  }

  .ka-composer {
    padding: 8px 10px 10px;
  }

  .ka-composer-hint {
    display: none;
  }

  .ka-status-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .ka-feedback-dialog {
    width: calc(100vw - 32px);
    max-width: none;
  }
}
