*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* `display` set on a class beats the UA [hidden]{display:none}, so make hidden authoritative. */
[hidden] { display: none !important; }

body {
  font-family: 'Ubuntu', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #ffffff;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* ── Global app-bar ───────────────────────────────────── */

.app-bar {
  flex-shrink: 0;
  width: 100%;
  padding: 12px 24px;
  border-bottom: 1px solid #f3f4f6;
  background: #fff;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
}
.app-bar__brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  justify-self: start;
}
.app-bar__brand img {
  height: 28px;
  width: auto;
  display: block;
}
.app-bar__tabs {
  display: flex;
  gap: 4px;
  justify-self: center;
}
.app-bar__tab {
  font-size: 0.875rem;
  font-weight: 500;
  color: #6b7280;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}
.app-bar__tab:hover {
  color: #111827;
  background: #f9fafb;
}
.app-bar__tab--active {
  color: #0f6f7b;
  background: rgba(15, 111, 123, .08);
}
.app-bar__logout {
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  margin-left: 8px;
}
.app-bar__logout:hover {
  color: #b91c1c;
  background: #fef2f2;
}

.search__wrap {
  display: flex;
  align-items: center;
}

.search__field {
  position: relative;
  flex: 1;
  background: #fff;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  height: 52px;
  display: flex;
  align-items: center;
  transition: border-color .15s;
}
.search__field:focus-within { border-color: #0f6f7b; }

#chat-input {
  flex: 1;
  height: 100%;
  border: none;
  outline: none;
  padding: 0 58px 0 18px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: transparent;
  color: #111827;
}
#chat-input::placeholder { color: #9ca3af; }
#chat-input:disabled { opacity: .5; }

#send-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  height: calc(100% - 12px);
  width: 42px;
  border: none;
  background: #e0370f;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(224, 55, 15, .25);
  transition: background .15s, box-shadow .15s, transform .1s;
}
#send-btn:hover:not(:disabled) {
  filter: brightness(.9);
  box-shadow: 0 2px 6px rgba(224, 55, 15, .3);
}
#send-btn:active:not(:disabled) { transform: translateY(-50%) scale(.97); }
#send-btn:disabled {
  cursor: default;
  background: #e5e7eb;
  color: #9ca3af;
  box-shadow: none;
}
#send-btn svg { width: 18px; height: 18px; }

/* ── Chat page ────────────────────────────────────────── */

body:has(.chat-page) {
  background: #f9fafb;
  align-items: center;
}

.chat-page {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  padding: 24px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 20px;
}

.chat-card {
  flex: 1;
  min-height: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(17, 24, 39, .04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-card__header {
  flex-shrink: 0;
  padding: 20px 24px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(15, 111, 123, .04) 0%, #ffffff 100%);
}

.chat-card__title {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #111827;
  letter-spacing: -.01em;
}

.chat-card__title-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(15, 111, 123, .15) 0%, rgba(15, 111, 123, .22) 100%);
  color: #0f6f7b;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(15, 111, 123, .08), 0 1px 2px rgba(15, 111, 123, .06);
}
.chat-card__title-icon svg {
  width: 20px;
  height: 20px;
}

.chat-card__title-text {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}
.chat-card__title-main {
  font-size: 1.0625rem;
  font-weight: 600;
  color: #111827;
  letter-spacing: -.015em;
}
.chat-card__subtitle {
  font-size: 0.8125rem;
  font-weight: 400;
  color: #6b7280;
  margin-top: 3px;
  line-height: 1.45;
  letter-spacing: 0;
  max-width: 60ch;
}

#messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 20px;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb {
  background: #e5e7eb;
  border-radius: 4px;
}
#messages::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

.chat-empty {
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px;
}
.chat-empty__logo {
  height: 44px;
  width: auto;
  display: block;
}
.chat-empty__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
  letter-spacing: -.01em;
}
.chat-empty__hint {
  font-size: 0.875rem;
  color: #6b7280;
  margin-top: 6px;
  line-height: 1.55;
  max-width: 440px;
}
.chat-empty__hint strong {
  font-weight: 600;
  color: #0f6f7b;
  background: rgba(15, 111, 123, .08);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
}
.chat-empty__examples {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 440px;
}
.chat-empty__examples-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  margin-bottom: 4px;
}
.chat-empty__example {
  font-size: 0.875rem;
  font-style: italic;
  color: #0f6f7b;
  line-height: 1.5;
}

.chat-msg {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 0.9375rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: chat-msg-in .2s ease-out;
}

@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg--user {
  align-self: flex-end;
  background: #111827;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg--assistant {
  align-self: flex-start;
  background: rgba(15, 111, 123, .08);
  color: #1f2937;
  border-bottom-left-radius: 4px;
  white-space: normal;
}

.markdown-body > *:first-child { margin-top: 0; }
.markdown-body > *:last-child { margin-bottom: 0; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 600;
  line-height: 1.3;
  margin: 14px 0 6px;
  color: #111827;
}
.markdown-body h1 { font-size: 1.15rem; }
.markdown-body h2 { font-size: 1.075rem; }
.markdown-body h3 { font-size: 1rem; }
.markdown-body h4 { font-size: 0.95rem; }

.markdown-body p {
  margin: 0 0 8px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 6px 0 10px;
  padding-left: 22px;
}
.markdown-body li {
  margin: 2px 0;
}
.markdown-body li > p {
  margin: 0;
}

.markdown-body strong { font-weight: 600; color: #111827; }
.markdown-body em { font-style: italic; }

.markdown-body a {
  color: #0f6f7b;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.markdown-body a:hover { color: #0f6f7b; }

.markdown-body code {
  background: rgba(15, 111, 123, .15);
  color: #0f6f7b;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875em;
}
.markdown-body pre {
  background: #1f2937;
  color: #f9fafb;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.markdown-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.markdown-body blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid rgba(15, 111, 123, .4);
  color: #4b5563;
  background: rgba(15, 111, 123, .04);
  border-radius: 0 6px 6px 0;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid rgba(15, 111, 123, .2);
  margin: 12px 0;
}

.markdown-body table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
  font-size: 0.9em;
  display: block;
  overflow-x: auto;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid rgba(15, 111, 123, .2);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.markdown-body th {
  background: rgba(15, 111, 123, .15);
  font-weight: 600;
  color: #111827;
}
.markdown-body tr:nth-child(even) td {
  background: rgba(15, 111, 123, .04);
}

.chat-msg--error {
  align-self: flex-start;
  background: rgba(224, 55, 15, .06);
  color: #e0370f;
  border: 1px solid rgba(224, 55, 15, .25);
  border-bottom-left-radius: 4px;
}

.chat-msg--loading {
  align-self: flex-start;
  background: rgba(15, 111, 123, .08);
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
  border-bottom-left-radius: 4px;
}
.chat-msg--loading span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(15, 111, 123, .4);
  animation: bounce 1.2s infinite ease-in-out;
}
.chat-msg--loading span:nth-child(2) { animation-delay: .2s; }
.chat-msg--loading span:nth-child(3) { animation-delay: .4s; }

.chat-card__composer {
  flex-shrink: 0;
  padding: 14px 16px;
  border-top: 1px solid #f3f4f6;
  background: #fff;
}

.chat-card__composer .search__wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-select {
  height: 48px;
  padding: 0 30px 0 12px;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") no-repeat right 10px center / 12px;
  font-family: inherit;
  font-size: 0.875rem;
  color: #1f2937;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
}
.model-select:hover { border-color: #d1d5db; background-color: #fff; }
.model-select:focus { outline: none; border-color: #0f6f7b; background-color: #fff; }
.model-select:disabled { opacity: 0.6; cursor: not-allowed; }

.chat-card__composer .search__field {
  border-color: #e5e7eb;
  background: #f9fafb;
  height: 48px;
}
.chat-card__composer .search__field:focus-within {
  border-color: #0f6f7b;
  background: #fff;
}

/* ── Settings form ───────────────────────────────────── */

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 620px;
}

.settings-field {
  display: grid;
  grid-template-columns: 200px 1fr;
  align-items: center;
  column-gap: 20px;
  row-gap: 6px;
}

.settings-field__label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
}

.settings-field__help {
  grid-column: 2;
  font-size: 0.75rem;
  line-height: 1.35;
  color: #6b7280;
}

.settings-field__help:empty { display: none; }

.settings-form .model-select {
  width: 100%;
}

.settings-input {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  font-family: inherit;
  font-size: 0.875rem;
  color: #1f2937;
  appearance: textfield;
  -moz-appearance: textfield;
}
.settings-input:hover { border-color: #d1d5db; background-color: #fff; }
.settings-input:focus { outline: none; border-color: #0f6f7b; background-color: #fff; }
.settings-input:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Token-usage panel ───────────────────────────────── */

.token-panel {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(17, 24, 39, .04);
  overflow: hidden;
}

.token-panel__header {
  padding: 14px 16px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
}

.token-panel__header-label {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #0f6f7b;
  background: rgba(15, 111, 123, .15);
  border-radius: 999px;
  padding: 2px 8px;
}

.token-panel__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}
.token-panel__list::-webkit-scrollbar { width: 8px; }
.token-panel__list::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }
.token-panel__list::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

.token-panel__list:empty::after {
  content: 'No requests yet.';
  font-size: 0.8125rem;
  color: #9ca3af;
  font-style: italic;
  padding: 4px 4px;
}

.token-entry {
  background: rgba(15, 111, 123, .08);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.token-entry__head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.token-entry__label {
  flex: 1;
  min-width: 0;
  font-size: 0.8125rem;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.token-entry__model {
  flex-shrink: 0;
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: #0f6f7b;
  background: rgba(15, 111, 123, .15);
  border-radius: 999px;
  padding: 2px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

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

.token-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.token-stat__label {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #0f6f7b;
}

.token-stat__value {
  font-size: 0.875rem;
  font-weight: 600;
  color: #1f2937;
  font-variant-numeric: tabular-nums;
}

.token-entry--missing {
  background: #fff;
  border: 1px dashed #e5e7eb;
}

.token-entry__missing-text {
  font-size: 0.8125rem;
  font-style: italic;
  color: #9ca3af;
}

.token-panel__footer {
  padding: 14px 16px;
  border-top: 1px solid #f3f4f6;
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.token-panel__footer-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #0f6f7b;
}

.token-panel__footer-value {
  font-size: 1rem;
  font-weight: 600;
  color: #0f6f7b;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 960px) {
  .chat-page {
    flex-direction: column;
    max-width: 760px;
  }
  .token-panel {
    width: 100%;
    max-height: 240px;
  }
  .settings-field {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .settings-field__help {
    grid-column: auto;
  }
}

/* ── Knowledge base page ──────────────────────────────── */

.kb-page {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: stretch;
}
.kb-page .chat-card {
  flex: 1;
  max-width: 820px;
  min-height: 0;
}

.kb-card__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
}
.kb-card__body::-webkit-scrollbar { width: 8px; }
.kb-card__body::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }
.kb-card__body::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

.kb-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kb-section__head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kb-section__title {
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  letter-spacing: -.01em;
}

.kb-section__desc {
  font-size: 0.8125rem;
  color: #6b7280;
  line-height: 1.5;
  max-width: 70ch;
}
.kb-section__desc code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78125rem;
  background: rgba(15, 111, 123, .08);
  color: #0f6f7b;
  padding: 1px 5px;
  border-radius: 4px;
}

.kb-section__label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
}

.kb-section__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.kb-divider {
  border: 0;
  height: 1px;
  background: #f3f4f6;
  margin: 4px 0;
}

.kb-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 22px;
  border: none;
  border-radius: 24px;
  background: #111827;
  color: #fff;
  font-size: 0.9375rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
  min-width: 200px;
}
.kb-btn:hover:not(:disabled) { background: #1f2937; }
.kb-btn:active:not(:disabled) { transform: translateY(1px); }
.kb-btn:disabled { opacity: .55; cursor: default; }
.kb-btn--danger {
  background: #e0370f;
  box-shadow: 0 1px 2px rgba(224, 55, 15, .25);
}
.kb-btn--danger:hover:not(:disabled) { background: #c92e0a; }

.kb-btn__spinner {
  display: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  animation: kb-spin .8s linear infinite;
}
.kb-btn.is-loading .kb-btn__spinner { display: inline-block; }

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

.kb-hint {
  font-size: 0.8125rem;
  color: #6b7280;
}

.kb-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(15, 111, 123, .06);
  border: 1px solid rgba(15, 111, 123, .18);
  color: #0f6f7b;
  font-size: 0.875rem;
  font-weight: 500;
}
.kb-progress__phase { letter-spacing: -.005em; }
.kb-progress__elapsed {
  font-variant-numeric: tabular-nums;
  color: #0b5a64;
  font-size: 0.8125rem;
}

.kb-status {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  font-family: inherit;
}
.kb-status--success {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}
.kb-status--error {
  background: rgba(224, 55, 15, .06);
  color: #b3290c;
  border: 1px solid rgba(224, 55, 15, .25);
}
.kb-status__title {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  color: inherit;
}
.kb-status__row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.kb-status__row + .kb-status__row { margin-top: 2px; }
.kb-status__row-label { color: #4b5563; font-weight: 400; }
.kb-status__row-value { color: #111827; font-weight: 500; }
.kb-status--success .kb-status__row-value { color: #14532d; }

.seed-live {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 18px;
  border-radius: 12px;
  background: #fafafa;
  border: 1px solid #e5e7eb;
}

.seed-phases {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.seed-phase {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e5e7eb;
  transition: border-color .2s ease, background .2s ease;
}
.seed-phase__marker {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  position: relative;
  flex-shrink: 0;
}
.seed-phase__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.seed-phase__title {
  font-size: 0.875rem;
  font-weight: 500;
  color: #111827;
}
.seed-phase__meta {
  font-size: 0.75rem;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}
.seed-phase__count {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #0f6f7b;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.seed-phase[data-state="active"] {
  border-color: rgba(15, 111, 123, .35);
  background: rgba(15, 111, 123, .04);
}
.seed-phase[data-state="active"] .seed-phase__marker {
  border-color: #0f6f7b;
  border-top-color: transparent;
  animation: kb-spin .9s linear infinite;
}
.seed-phase[data-state="done"] .seed-phase__marker {
  background: #0f6f7b;
  border-color: #0f6f7b;
}
.seed-phase[data-state="done"] .seed-phase__marker::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.seed-phase[data-state="error"] .seed-phase__marker {
  background: #b3290c;
  border-color: #b3290c;
}
.seed-phase[data-state="error"] .seed-phase__marker::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 8px;
  height: 8px;
  background:
    linear-gradient(45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, #fff 45%, #fff 55%, transparent 55%);
}

.seed-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.seed-group__heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}
.seed-group__title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6b7280;
}
.seed-group__count {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: #9ca3af;
}

.seed-products {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px 12px;
  max-height: 240px;
  overflow-y: auto;
}
.seed-products::-webkit-scrollbar { width: 8px; }
.seed-products::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }
.seed-products::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

.seed-product {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  transition: background .15s ease;
}
.seed-product__marker {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  position: relative;
  flex-shrink: 0;
  box-sizing: border-box;
}
.seed-product__code {
  color: #374151;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.seed-product__detail {
  font-size: 0.6875rem;
  color: #9ca3af;
  letter-spacing: -.005em;
}
.seed-product[data-state="fetching"] .seed-product__marker {
  border-color: #0f6f7b;
  border-top-color: transparent;
  animation: kb-spin .9s linear infinite;
}
.seed-product[data-state="fetching"] .seed-product__detail {
  color: #0f6f7b;
}
.seed-product[data-state="done"] {
  background: rgba(15, 111, 123, .04);
}
.seed-product[data-state="done"] .seed-product__marker {
  background: #0f6f7b;
  border-color: #0f6f7b;
}
.seed-product[data-state="done"] .seed-product__marker::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 0;
  width: 3px;
  height: 6px;
  border: solid #fff;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}
.seed-product[data-state="done"] .seed-product__detail {
  color: #0f6f7b;
  font-weight: 500;
}
.seed-product[data-state="partial"] .seed-product__marker {
  background: #d97706;
  border-color: #d97706;
}
.seed-product[data-state="partial"] .seed-product__marker::after {
  content: "!";
  position: absolute;
  left: 3px;
  top: -2px;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  line-height: 12px;
}
.seed-product[data-state="partial"] .seed-product__detail {
  color: #b45309;
  font-weight: 500;
}

.seed-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  border-radius: 12px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
}
.seed-summary__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.seed-summary__title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #14532d;
}
.seed-summary__elapsed {
  font-size: 0.8125rem;
  color: #166534;
  font-variant-numeric: tabular-nums;
}
.seed-summary__stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.seed-summary__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
}
.seed-summary__stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: #14532d;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.015em;
}
.seed-summary__stat-label {
  font-size: 0.6875rem;
  color: #166534;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.seed-summary__stat-value--warn { color: #b45309; }

/* Seed breakdowns (products per category, rows per index) */
.seed-breakdown { display: flex; flex-direction: column; }
.seed-breakdown__label,
.seed-breakdown__summary {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #166534;
}
.seed-breakdown__label { margin-bottom: 2px; }
.seed-breakdown--collapsible { border-top: 1px solid #bbf7d0; padding-top: 10px; }
.seed-breakdown__summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.seed-breakdown__summary::-webkit-details-marker { display: none; }
.seed-breakdown__summary::after {
  content: '▸';
  color: #16a34a;
  margin-left: auto;
  transition: transform .15s;
}
.seed-breakdown--collapsible[open] > .seed-breakdown__summary::after { transform: rotate(90deg); }
.seed-breakdown--collapsible[open] > .seed-breakdown__summary { margin-bottom: 6px; }
.seed-breakdown__count { color: #16a34a; font-weight: 500; }

.kv-rows { display: flex; flex-direction: column; }
.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 2px;
  font-size: 0.8125rem;
  color: #14532d;
  border-bottom: 1px solid rgba(187, 247, 208, .7);
}
.kv-row:last-child { border-bottom: 0; }
.kv-row__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv-row__value { flex: 0 0 auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv-row--zero { color: #6b9e7a; }
.kv-row--zero .kv-row__value { font-weight: 500; }
.kv-row--warn { color: #b45309; }
.kv-row--warn .kv-row__value { color: #b45309; }
.kv-row__flag { font-size: 0.6875rem; font-weight: 500; color: #b45309; }

/* ── Usage page ──────────────────────────────────────── */

.usage-page {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  flex: 1;
  min-height: 0;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: stretch;
}
.usage-page .chat-card {
  flex: 1;
  max-width: 820px;
  min-height: 0;
}

.usage-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.usage-stat {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.usage-stat__label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: #6b7280;
  text-transform: uppercase;
}

.usage-stat__value {
  font-size: 1.5rem;
  font-weight: 600;
  color: #111827;
  font-variant-numeric: tabular-nums;
}

.usage-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.875rem;
}
.usage-table th {
  text-align: left;
  padding: 10px 12px;
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  border-bottom: 1px solid #e5e7eb;
}
.usage-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  color: #1f2937;
  font-variant-numeric: tabular-nums;
}
.usage-table tbody tr:last-child td {
  border-bottom: none;
}
.usage-table th:not(:first-child),
.usage-table td:not(:first-child) {
  text-align: right;
}
.usage-table__empty {
  padding: 24px;
  text-align: center;
  color: #6b7280;
}

.widget-demo-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 96px 24px 48px;
  text-align: center;
}
.widget-demo-page__title {
  font-size: 2.25rem;
  font-weight: 600;
  color: #111827;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}
.widget-demo-page__subtitle {
  font-size: 1.125rem;
  line-height: 1.6;
  color: #4b5563;
  max-width: 600px;
  margin: 0 auto 32px;
}
.widget-demo-page__hint {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: rgba(15, 111, 123, .08);
  color: #0f6f7b;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
}
.widget-demo-page__hint svg {
  width: 16px;
  height: 16px;
}

/* ── Conversations (master-detail) ────────────────────── */

.conv-page .chat-card {
  max-width: 1100px;
}
.conv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 16px;
}
@media (max-width: 800px) {
  .conv-layout { grid-template-columns: 1fr; }
}
.conv-list tbody tr {
  cursor: pointer;
}
.conv-list tbody tr:hover {
  background: #f9fafb;
}
.conv-list tbody tr.is-selected {
  background: #e6f4f5;
}
.conv-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}
.conv-thread::-webkit-scrollbar { width: 8px; }
.conv-thread::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }
.conv-thread::-webkit-scrollbar-thumb:hover { background: #d1d5db; }
.conv-thread__empty {
  padding: 24px;
  text-align: center;
  color: #6b7280;
  font-size: 0.875rem;
}
.conv-msg {
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.875rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.conv-msg--user {
  background: #e6f4f5;
  align-self: flex-end;
  max-width: 85%;
}
.conv-msg--assistant {
  background: #f3f4f6;
  align-self: flex-start;
  max-width: 85%;
}
.conv-msg--assistant.markdown-body { white-space: normal; }
.conv-msg--system {
  background: #fff7ed;
  border: 1px solid #fed7aa;
}
.conv-msg--system summary {
  cursor: pointer;
  color: #6b7280;
  font-weight: 600;
}
.conv-msg--system__body {
  margin-top: 8px;
  color: #374151;
}

.prompt-field__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 6px;
}
.prompt-field__help {
  margin: 6px 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: #6b7280;
}
.system-prompt-textarea {
  width: 100%;
  min-height: 360px;
  padding: 14px 16px;
  border: 1.5px solid #e5e7eb;
  border-radius: 12px;
  background: #f9fafb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #1f2937;
  resize: vertical;
  box-sizing: border-box;
}
.system-prompt-textarea:hover { border-color: #d1d5db; background-color: #fff; }
.system-prompt-textarea:focus { outline: none; border-color: #0f6f7b; background-color: #fff; }

.prompt-history__heading {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 12px;
}
.prompt-history {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
}
.prompt-history__item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "meta restore" "preview restore";
  align-items: center;
  gap: 4px 16px;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
}
.prompt-history__meta { grid-area: meta; font-size: 0.75rem; color: #6b7280; }
.prompt-history__preview { grid-area: preview; font-size: 0.8125rem; color: #374151; white-space: pre-wrap; }
.prompt-history__restore {
  grid-area: restore;
  padding: 6px 14px;
  font-size: 0.8125rem;
  border-radius: 10px;
  background: transparent;
  color: #0f6f7b;
  border: 0;
  box-shadow: inset 0 0 0 1px rgba(15, 111, 123, .4);
  cursor: pointer;
}

/* ---- Data page ---------------------------------------------------------- */
.seed-categories { border: 0; padding: 0; margin: 0; }
.seed-categories__list { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 8px; }
.seed-category { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: #374151; cursor: pointer; }
.seed-category input { width: 16px; height: 16px; accent-color: #0f6f7b; cursor: pointer; }

.kb-btn--secondary { background: transparent; color: #0f6f7b; box-shadow: inset 0 0 0 1px rgba(15,111,123,.4); }
.kb-btn--secondary:hover { background: rgba(15,111,123,.06); }

/* Overview strip */
.kb-overview { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 4px; }
.kb-overview .usage-stat { flex: 1 1 0; min-width: 120px; }

/* Build steps */
.kb-step { display: flex; gap: 14px; padding: 14px 0; }
.kb-step + .kb-step { border-top: 1px solid #f0f1f3; }
.kb-step__marker { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; background: #0f6f7b; color: #fff; font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.kb-step__body { flex: 1; min-width: 0; }
.kb-step__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.kb-step__head .kb-btn { flex: 0 0 auto; }

/* Stored-data tabs */
.kb-stored__controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kb-tabs { display: inline-flex; background: #f3f4f6; border-radius: 8px; padding: 3px; gap: 2px; }
.kb-tabs__tab { border: 0; background: transparent; padding: 6px 14px; font: inherit; font-size: 0.85rem; color: #6b7280; border-radius: 6px; cursor: pointer; }
.kb-tabs__tab.is-selected { background: #fff; color: #0f6f7b; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Datasheet progress bar */
.kb-progress-bar { margin-top: 10px; height: 8px; background: #eef0f2; border-radius: 999px; overflow: hidden; }
.kb-progress-bar__fill { height: 100%; width: 0; background: #0f6f7b; border-radius: 999px; transition: width .2s ease; }

/* Stored groups (relocated from data.html inline <style>) */
.products-empty { margin-top: 10px; color: #6b7280; font-size: 0.875rem; }
.products-group { border: 1px solid #e5e7eb; border-radius: 10px; margin-top: 10px; overflow: hidden; }
.products-group > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; align-items: center; gap: 10px; font-weight: 600; color: #111827; background: #f9fafb; }
.products-group > summary::-webkit-details-marker { display: none; }
.products-group__name { flex: 1; }
.products-group__count { color: #6b7280; font-weight: 500; font-size: 0.8125rem; }
.products-group > summary::after { content: '▸'; color: #6b7280; transition: transform .15s; }
.products-group[open] > summary::after { transform: rotate(90deg); }
.products-group__body { max-height: 360px; overflow: auto; padding: 0 4px 4px; }
.products-group .usage-table { width: 100%; }
.products-group .usage-table a { color: #0f6f7b; text-decoration: none; white-space: nowrap; }
.products-group .usage-table a:hover { text-decoration: underline; }

/* Danger zone */
.kb-danger-zone { border: 1px solid rgba(220,38,38,.25); background: rgba(220,38,38,.03); border-radius: 12px; padding: 16px 18px; margin-top: 4px; }
.kb-danger-zone .kb-section__title { color: #b91c1c; }
.prompt-history__restore:hover { background: rgba(15, 111, 123, .06); }

/* ===== Data provenance overview ===== */

/* Fourth headline tile fits alongside the existing three */
.kb-overview .usage-stat { flex: 1 1 0; min-width: 120px; }

.prov-controls { justify-content: space-between; margin-top: 4px; }

/* Provenance table: data set · source tag · live count · usage */
.prov-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.875rem; }
.prov-table th {
  text-align: left; padding: 10px 12px; background: #f9fafb; font-weight: 600;
  color: #374151; border-bottom: 1px solid #e5e7eb; white-space: nowrap;
}
.prov-table td { padding: 10px 12px; border-bottom: 1px solid #f3f4f6; color: #1f2937; vertical-align: middle; }
.prov-table tbody tr:last-child td { border-bottom: none; }
.prov-table th.prov-num, .prov-table td.prov-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.prov-name { font-weight: 600; color: #111827; }
.prov-use { color: #6b7280; }
.prov-row--empty td { color: #9aa4b2; }
.prov-row--empty .prov-name { color: #6b7280; }

.prov-tag {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.74rem;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.prov-tag--catalog { color: #0f6f7b; background: rgba(15,111,123,.09); }
.prov-tag--web { color: #92400e; background: rgba(180,83,9,.10); }
.prov-tag--derived { color: #6b7280; background: #f3f4f6; }

/* Operator-controls divider heading */
.ops-heading { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.ops-heading .kb-section__title { font-size: 1.0625rem; }

@media (max-width: 720px) {
  .prov-controls { flex-direction: column; align-items: flex-start; gap: 8px; }
}
