:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --text: #17212b;
  --muted: #66727f;
  --line: #d9e0e7;
  --accent: #12645a;
  --accent-strong: #0a4e47;
  --accent-soft: #e2f3ef;
  --warn: #9b5b10;
  --danger: #b33434;
  --shadow: 0 18px 45px rgba(24, 36, 48, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(420px, 1fr) 320px;
  height: 100vh;
  min-height: 680px;
}

.sidebar,
.inspector {
  background: var(--panel);
  border-color: var(--line);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  border-right: 1px solid var(--line);
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #15232e;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 750;
}

.brand-subtitle,
.chat-meta,
.section-label,
.field span {
  color: var(--muted);
  font-size: 12px;
}

.primary-action,
.secondary-action,
.ghost-button,
.composer button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.primary-action,
.composer button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}

.primary-action:hover,
.composer button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.secondary-action,
.ghost-button {
  background: var(--panel-soft);
  color: var(--text);
  border-color: var(--line);
}

.secondary-action:hover,
.ghost-button:hover {
  border-color: #a9bac8;
  background: #eef3f6;
}

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

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

.section-label {
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.search-box {
  display: grid;
  gap: 6px;
}

.search-box span {
  color: var(--muted);
  font-size: 12px;
}

.search-box input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 100, 90, 0.12);
}

.conversation-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 2px;
}

.conversation-item {
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.conversation-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.conversation-item-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

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

.chat-pane {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-width: 0;
  background: #eef2f5;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
}

.chat-header h1 {
  margin: 0;
  max-width: min(62vw, 760px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-strip {
  min-height: 38px;
  padding: 10px 24px;
  color: #32505b;
  background: #e8f2f5;
  border-bottom: 1px solid #cfe0e6;
  font-size: 13px;
}

.status-strip.error {
  color: #7d2e2e;
  background: #fff1ef;
  border-color: #f0c7bf;
}

.status-strip.ok {
  color: #14564d;
  background: #e8f5f1;
  border-color: #c9e3dc;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  margin: auto;
  max-width: 640px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
}

.empty-state h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

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

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

.suggestions button {
  min-height: 50px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 780px);
  gap: 12px;
  align-items: start;
}

.message.user {
  justify-content: end;
  grid-template-columns: minmax(0, 760px) 42px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #dce6eb;
  color: #263945;
  font-size: 13px;
  font-weight: 800;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
  background: #d6eee8;
  color: var(--accent-strong);
}

.bubble {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 24px rgba(30, 44, 58, 0.06);
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.inline-source-details {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: #40515f;
  overflow: hidden;
}

.inline-source-details summary {
  min-height: 40px;
  padding: 9px 12px;
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 750;
  user-select: none;
}

.inline-source-details pre {
  max-height: 260px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-top: 1px solid var(--line);
  color: #3c4c59;
  background: #fff;
  font: inherit;
  font-size: 13px;
  line-height: 1.62;
  white-space: pre-wrap;
}

.message.pending .bubble {
  border-color: #c8d7dd;
  background: #f7fbfc;
  color: #385260;
}

.message.error .bubble {
  border-color: #f0c7bf;
  background: #fff1ef;
  color: #7d2e2e;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  margin-top: 10px;
  vertical-align: middle;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.35;
  animation: typing-pulse 1.1s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typing-pulse {
  0%,
  80%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }

  40% {
    opacity: 0.95;
    transform: translateY(-3px);
  }
}

.message-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.message-rating {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.message-rating-label,
.message-rating-status {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.message-rating-button,
.message-improve-button {
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #38505e;
  font-size: 12px;
  font-weight: 700;
}

.message-rating-button:hover,
.message-improve-button:hover {
  border-color: #a7bbc8;
  background: #f7fbfc;
}

.message-rating-button.selected {
  border-color: var(--accent);
  background: #e8f5f1;
  color: var(--accent-strong);
}

.message-rating-button:disabled,
.message-improve-button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.message-improve-button {
  border-color: #c8d7dd;
  color: var(--accent-strong);
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #edf2f5;
  color: #38505e;
  font-size: 12px;
  line-height: 1.4;
}

.chip.warn {
  background: #fff0d7;
  color: var(--warn);
}

.composer {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 10px;
  padding: 16px 24px 22px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  min-height: 48px;
  resize: none;
  padding: 13px 14px;
  border: 1px solid #bfd0dc;
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
  line-height: 1.5;
}

.composer textarea:focus,
.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 100, 90, 0.12);
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.panel-title {
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 750;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-title-row .panel-title {
  margin-bottom: 0;
}

.mini-button {
  min-height: 28px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.mini-button:hover {
  border-color: #a9bac8;
  color: var(--text);
}

.health-state {
  display: grid;
  gap: 8px;
}

.health-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.health-item {
  min-height: 50px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.health-label {
  color: var(--muted);
  font-size: 11px;
}

.health-value {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 750;
}

.health-note {
  padding: 9px;
  border-radius: 8px;
  background: #e8f5f1;
  color: #14564d;
  font-size: 12px;
  line-height: 1.5;
}

.health-note.warn {
  background: #fff0d7;
  color: var(--warn);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.field textarea {
  resize: vertical;
  min-height: 74px;
  line-height: 1.5;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.answer-state {
  min-height: 72px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.feedback-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sources-list {
  display: grid;
  gap: 10px;
}

.source-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.source-title {
  font-size: 13px;
  font-weight: 750;
}

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

.source-excerpt {
  color: #394956;
  font-size: 12px;
  line-height: 1.55;
}

.loading {
  opacity: 0.75;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .inspector {
    display: none;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    height: auto;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list {
    max-height: 170px;
  }

  .chat-pane {
    min-height: 70vh;
  }

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

  .status-strip,
  .messages,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .message,
  .message.user {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .message.user .avatar {
    grid-column: 1;
  }

  .avatar {
    width: 34px;
    height: 34px;
  }

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

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