.kr-root {
  --kr-border: #e2e8f0;
  --kr-muted: #64748b;
  --kr-blue: #2563eb;
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 0 40px;
  color: #1e293b;
}

.kr-header,
.kr-filter-bar,
.kr-turn-meta,
.kr-detail-meta,
.kr-source summary,
.kr-drawer-header {
  display: flex;
  align-items: center;
}

.kr-header {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.kr-header h2,
.kr-header p,
.kr-stats-section h3,
.kr-filter-bar h3,
.kr-drawer-header h3,
.kr-detail-section h4,
.kr-thread-context h4,
.kr-triage h4 {
  margin: 0;
}

.kr-header p {
  margin-top: 5px;
  color: var(--kr-muted);
}

.kr-header a,
.kr-retry,
.kr-play,
.kr-save,
.kr-drawer-header button {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #1e293b;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
}

.kr-message {
  margin: 0;
  color: #b45309;
}

.kr-message:not(:empty) {
  margin-bottom: 10px;
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff7ed;
}

.kr-retry {
  margin-bottom: 12px;
  border-color: var(--kr-blue);
  color: var(--kr-blue);
}

.kr-stats-section,
.kr-review-section {
  border: 1px solid var(--kr-border);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(15 23 42 / 5%);
}

.kr-stats-section {
  margin-bottom: 18px;
  padding: 18px;
}

.kr-stats-section > h3 {
  margin-bottom: 12px;
}

.kr-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
}

.kr-stat {
  min-width: 0;
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 11px 12px;
  background: #f8fafc;
}

.kr-stat-label,
.kr-stat strong {
  display: block;
}

.kr-stat-label {
  margin-bottom: 5px;
  color: var(--kr-muted);
  font-size: 12px;
}

.kr-stat strong {
  font-size: 15px;
  line-height: 1.35;
}

.kr-table-wrap {
  overflow-x: auto;
  margin-top: 16px;
}

.kr-user-table {
  width: 100%;
  border-collapse: collapse;
}

.kr-user-table th,
.kr-user-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--kr-border);
  text-align: left;
}

.kr-user-table th {
  color: var(--kr-muted);
  font-size: 12px;
}

.kr-filter-bar {
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--kr-border);
}

.kr-filter-bar h3 {
  margin-right: auto;
}

.kr-filter-bar label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #475569;
  font-size: 13px;
}

.kr-filter-bar select {
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  padding: 6px 8px;
  background: #fff;
  font: inherit;
}

.kr-list {
  min-height: 170px;
}

.kr-turn-row {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--kr-border);
  padding: 14px 16px;
  background: #fff;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: background .15s ease;
}

.kr-turn-row:last-child {
  border-bottom: 0;
  border-radius: 0 0 14px 14px;
}

.kr-turn-row:hover,
.kr-turn-row:focus-visible {
  background: #f8fafc;
  outline: none;
}

.kr-turn-meta,
.kr-detail-meta {
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 7px;
  color: var(--kr-muted);
  font-size: 12px;
}

.kr-question,
.kr-rewrite,
.kr-rewrite-failed {
  display: block;
}

.kr-question {
  color: #0f172a;
  font-size: 15px;
}

.kr-rewrite {
  margin-top: 5px;
  color: #475569;
  font-size: 13px;
}

.kr-rewrite-failed {
  margin-top: 4px;
  color: #b45309;
  font-size: 12px;
}

.kr-support,
.kr-admin-tag,
.kr-feedback-reason,
.kr-error-marker,
.kr-retrieval-tags span {
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
}

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

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

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

.kr-admin-tag {
  background: #dbeafe;
  color: #1d4ed8;
}

.kr-feedback-reason {
  background: #fee2e2;
  color: #b91c1c;
}

.kr-error-marker {
  background: #fee2e2;
  color: #b91c1c;
}

.kr-empty {
  margin: 0;
  padding: 42px 20px;
  color: var(--kr-muted);
  text-align: center;
}

.kr-drawer-backdrop:not([hidden]) {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: block;
  width: 100%;
  border: 0;
  background: rgb(15 23 42 / 38%);
}

.kr-drawer {
  position: fixed;
  z-index: 41;
  top: 0;
  right: 0;
  width: min(680px, 92vw);
  height: 100vh;
  overflow: hidden;
  background: #fff;
  box-shadow: -18px 0 48px rgb(15 23 42 / 22%);
  transform: translateX(105%);
  transition: transform .2s ease;
}

.kr-drawer.is-open {
  transform: translateX(0);
}

body.kr-drawer-open {
  overflow: hidden;
}

.kr-drawer-header {
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--kr-border);
}

.kr-drawer-header > div {
  min-width: 0;
}

.kr-drawer-header h3 {
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kr-eyebrow {
  color: var(--kr-muted);
  font-size: 11px;
  font-weight: 700;
}

.kr-drawer-header button {
  flex: none;
  border: 0;
  padding: 2px 8px;
  font-size: 28px;
}

.kr-drawer-body {
  height: calc(100vh - 72px);
  overflow-y: auto;
  padding: 18px;
}

.kr-thread-context,
.kr-detail-section,
.kr-triage {
  margin-bottom: 18px;
  border: 1px solid var(--kr-border);
  border-radius: 11px;
  padding: 14px;
}

.kr-thread-context h4,
.kr-detail-section h4,
.kr-triage h4 {
  margin-bottom: 10px;
  font-size: 14px;
}

.kr-thread-turns {
  display: grid;
  gap: 7px;
}

.kr-thread-turns button {
  display: grid;
  gap: 3px;
  border: 1px solid var(--kr-border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #f8fafc;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.kr-thread-turns button.is-selected {
  border-color: #60a5fa;
  background: #eff6ff;
}

.kr-thread-turns span {
  color: var(--kr-muted);
  font-size: 11px;
}

.kr-detail-rewrite {
  margin: 0 0 16px;
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff7ed;
  color: #9a3412;
}

.kr-answer {
  line-height: 1.7;
  white-space: pre-wrap;
}

.kr-citation-link {
  color: #1d4ed8;
  font-weight: 700;
}

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

.kr-source + .kr-source {
  margin-top: 8px;
}

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

.kr-source summary {
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.kr-source summary strong,
.kr-source summary span {
  display: block;
}

.kr-source blockquote {
  margin: 12px 0;
  line-height: 1.65;
  white-space: pre-wrap;
}

.kr-play {
  padding: 5px 9px;
  font-size: 13px;
}

.kr-retrieved {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border-left: 3px solid #60a5fa;
  background: #f8fafc;
}

.kr-retrieved + .kr-retrieved {
  margin-top: 7px;
}

.kr-muted {
  color: var(--kr-muted);
  font-size: 12px;
}

.kr-retrieval-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.kr-retrieval-tags span {
  background: #e2e8f0;
  color: #475569;
}

.kr-feedback-note {
  margin-bottom: 0;
  color: #475569;
  white-space: pre-wrap;
}

.kr-feedback-reason-line {
  margin-bottom: 8px;
  color: #b91c1c;
  font-weight: 700;
}

.kr-triage-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.kr-triage-options label,
.kr-note-label {
  color: #334155;
  font-size: 13px;
}

.kr-triage-options label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.kr-note-label {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.kr-note-label textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 9px;
  font: inherit;
}

.kr-save {
  margin-top: 10px;
  border-color: var(--kr-blue);
  background: var(--kr-blue);
  color: #fff;
}

.kr-save:disabled,
.kr-play:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.kr-audio {
  position: fixed;
  z-index: 42;
  right: 20px;
  bottom: 14px;
  width: min(620px, calc(92vw - 40px));
}

@media (max-width: 900px) {
  .kr-stats {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
}

@media (max-width: 640px) {
  .kr-root {
    padding-top: 8px;
  }

  .kr-header {
    align-items: flex-start;
  }

  .kr-header h2 {
    font-size: 19px;
  }

  .kr-header p {
    font-size: 13px;
  }

  .kr-header a {
    flex: none;
    padding: 6px 8px;
    font-size: 12px;
  }

  .kr-stats-section {
    padding: 12px;
  }

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

  .kr-filter-bar {
    align-items: stretch;
  }

  .kr-filter-bar h3 {
    width: 100%;
  }

  .kr-filter-bar label:not(.kr-checkbox) {
    justify-content: space-between;
    width: calc(50% - 6px);
  }

  .kr-filter-bar select {
    min-width: 0;
    max-width: 110px;
  }

  .kr-drawer {
    width: 100vw;
  }

  .kr-drawer-body {
    padding: 12px;
  }

  .kr-triage-options {
    grid-template-columns: 1fr;
  }

  .kr-audio {
    right: 10px;
    width: calc(100vw - 20px);
  }
}
