:root {
  color-scheme: light;
  --page: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef6f5;
  --text: #17202a;
  --muted: #667085;
  --border: #d9dee7;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 60px rgba(27, 39, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  line-height: 1.25;
}

.chat-app {
  width: min(1180px, calc(100vw - 32px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
  gap: 16px;
}

.chat-workspace,
.context-panel {
  min-width: 0;
}

.chat-workspace {
  display: grid;
  min-height: calc(100dvh - 48px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 750;
}

h2 {
  margin-bottom: 0;
  font-size: 15px;
}

.status-pill,
.count-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #fbfcfd;
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.top-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  border: 0;
  color: #ffffff;
  background: var(--accent);
}

.ghost-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: #fbfcfd;
}

.danger-button {
  border: 1px solid #f1b8b2;
  color: var(--danger);
  background: #fff4f2;
}

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button:not(:disabled),
.ghost-button:not(:disabled),
.danger-button:not(:disabled) {
  cursor: pointer;
}

.ghost-button:hover {
  border-color: var(--accent);
}

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

.conversation-panel,
.composer,
.context-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.conversation-panel {
  padding: 18px;
  overflow: auto;
  min-height: 0;
}

.message {
  width: fit-content;
  max-width: 760px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  overflow-wrap: anywhere;
}

.message + .message {
  margin-top: 12px;
}

.message-user {
  margin-left: auto;
  max-width: min(680px, 92%);
  background: var(--surface-soft);
  border-color: rgba(15, 118, 110, 0.25);
}

.message-answer {
  background: #fbfcfd;
}

.message-loading {
  color: var(--muted);
}

.message-refusal {
  border-color: rgba(180, 83, 9, 0.35);
  background: #fff8ed;
}

.message p {
  margin-bottom: 0;
  line-height: 1.55;
}

.message p + p {
  margin-top: 10px;
}

.answer-content,
.refusal-content {
  display: grid;
  gap: 10px;
}

.message-status {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
}

.status-success {
  color: #0f5132;
  background: #e9f7ef;
  border: 1px solid #b7e4c7;
}

.status-warning {
  color: var(--warning);
  background: #fff4df;
  border: 1px solid #f7d7a4;
}

.loading-block {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
}

.loading-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.14);
}

.refusal-original {
  padding-top: 2px;
}

.message-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.answer-region {
  margin-top: 14px;
}

.empty-state {
  padding: 18px 0 0;
}

.empty-title {
  margin-bottom: 10px;
  color: var(--muted);
}

.prompt-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-chip {
  max-width: 100%;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  white-space: normal;
}

.prompt-chip:hover {
  border-color: var(--accent);
}

.composer {
  padding: 14px;
}

textarea {
  width: 100%;
  min-height: 94px;
  max-height: 220px;
  resize: vertical;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfd;
  line-height: 1.5;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfd;
}

textarea:focus,
input:focus,
select:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

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

.trace-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.trace-toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

#submit-button {
  min-width: 104px;
  min-height: 40px;
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 750;
  cursor: pointer;
}

#submit-button:hover {
  background: var(--accent-strong);
}

#submit-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.validation-message {
  min-height: 20px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.context-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  align-self: start;
  position: sticky;
  top: 16px;
  max-height: calc(100dvh - 32px);
  overflow: auto;
}

.side-section {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.side-section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.citation-item {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
}

.citation-title {
  margin-bottom: 4px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.citation-meta {
  color: var(--muted);
  font-size: 13px;
}

.citation-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.citation-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f7;
  font-size: 12px;
  font-weight: 650;
}

.empty-citations {
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfd;
  font-size: 14px;
  line-height: 1.45;
}

.citation-item a {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.citation-item a:hover {
  text-decoration: underline;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

details {
  color: var(--muted);
}

.debug-panel[hidden] {
  display: none;
}

.debug-panel .section-heading {
  margin-bottom: 8px;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

pre {
  max-height: 300px;
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.admin-app {
  width: min(1280px, calc(100vw - 32px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
}

.admin-header,
.admin-toolbar,
.source-list-panel,
.source-detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
}

.admin-toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(180px, 220px) minmax(220px, 1fr);
  gap: 12px;
  padding: 14px;
}

.admin-toolbar label,
.source-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

.source-list-panel,
.source-detail-panel {
  min-width: 0;
  padding: 14px;
}

.source-list-panel {
  align-self: start;
  position: sticky;
  top: 16px;
  max-height: calc(100dvh - 32px);
  overflow: auto;
}

.source-list-empty {
  margin-top: 14px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fbfcfd;
}

.source-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.source-list-item {
  display: grid;
  width: 100%;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfd;
  cursor: pointer;
  text-align: left;
}

.source-list-item:hover,
.source-list-item-selected {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.source-list-item-title {
  font-weight: 750;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.source-list-item-meta,
.source-list-item-readiness {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.source-list-item-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.source-topic-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f7;
  font-size: 12px;
}

.source-form {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.full-width-field {
  display: grid;
}

.field-action {
  display: grid;
  align-content: end;
  gap: 6px;
}

.field-action span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.field-action .ghost-button {
  width: 100%;
}

.source-form textarea {
  min-height: 240px;
  max-height: 420px;
}

.readiness-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.readiness-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #eef2f7;
  font-size: 12px;
  font-weight: 700;
}

.readiness-ready {
  color: #0f5132;
  background: #e9f7ef;
  border-color: #b7e4c7;
}

.source-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.source-meta-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
}

.source-meta-grid dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.source-meta-grid dd {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.form-message {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.form-message[data-kind="success"] {
  color: #0f5132;
}

.form-message[data-kind="error"] {
  color: var(--danger);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

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

@media (max-width: 1080px) {
  .chat-app {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  }

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

@media (max-width: 880px) {
  .chat-app {
    width: min(100vw - 20px, 680px);
    min-height: auto;
    grid-template-columns: 1fr;
    padding: 10px 0;
  }

  .chat-workspace {
    min-height: auto;
  }

  .context-panel {
    position: static;
    max-height: none;
  }

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

  .admin-app {
    width: min(100vw - 20px, 760px);
    min-height: auto;
    padding: 10px 0;
  }

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

  .admin-toolbar,
  .admin-grid,
  .form-grid,
  .source-meta-grid {
    grid-template-columns: 1fr;
  }

  .source-list-panel {
    position: static;
    max-height: none;
  }

  .conversation-panel {
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  .chat-app {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  .admin-app {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  .chat-header,
  .conversation-panel,
  .composer,
  .context-panel,
  .admin-header,
  .admin-toolbar,
  .source-list-panel,
  .source-detail-panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-header,
  .admin-header {
    padding: 16px;
  }

  .admin-toolbar,
  .source-list-panel,
  .source-detail-panel {
    padding: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .conversation-panel {
    padding: 12px;
    min-height: 380px;
  }

  .message {
    width: 100%;
    padding: 12px;
  }

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

  .prompt-list {
    display: grid;
    grid-template-columns: 1fr;
  }

  .prompt-chip {
    width: 100%;
  }

  textarea {
    min-height: 112px;
  }

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

  .trace-toggle {
    min-height: 36px;
  }

  #submit-button {
    width: 100%;
  }

  .top-actions,
  .detail-actions,
  .primary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
  }
}
