/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
textarea, input { font-family: inherit; }

/* ── Tokens ── */
:root {
  --c-primary:      #1a3c6e;
  --c-primary-dk:   #112952;
  --c-accent:       #2563eb;
  --c-accent-lt:    #eff4ff;
  --c-bg:           #f1f5fb;
  --c-surface:      #ffffff;
  --c-border:       #dde4f0;
  --c-text:         #1e293b;
  --c-muted:        #64748b;
  --c-success:      #16a34a;
  --c-warn:         #ca8a04;
  --c-danger:       #dc2626;
  --r:              10px;
  --ease:           cubic-bezier(.4,0,.2,1);
}

/* ── Layout ── */
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Main two-column wrapper ── */
.main-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.chat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Header ── */
.hdr {
  flex-shrink: 0;
  height: 58px;
  background: linear-gradient(135deg, var(--c-primary-dk) 0%, var(--c-primary) 55%, #2a5fac 100%);
  box-shadow: 0 2px 10px rgba(17,41,82,.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
  z-index: 10;
}

.hdr-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.hdr-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.hdr-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.hdr-title {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.hdr-sub {
  font-size: 11px;
  color: rgba(255,255,255,.6);
  line-height: 1.3;
  white-space: nowrap;
}

.hdr-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-hdr {
  height: 32px;
  padding: 0 13px;
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .18s var(--ease), transform .14s var(--ease);
}
.btn-hdr:hover { background: rgba(255,255,255,.22); transform: translateY(-1px); }
.btn-hdr:active { transform: none; }

/* ── Chat area ── */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 16px;
  display: flex;
  flex-direction: column;
}
#chat::-webkit-scrollbar { width: 4px; }
#chat::-webkit-scrollbar-thumb { background: #c8d3e8; border-radius: 4px; }

/* ── Scroll-to-bottom button ── */
#scroll-btn {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  color: var(--c-muted);
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s var(--ease), transform .2s var(--ease), background .15s var(--ease), color .15s var(--ease);
  z-index: 50;
}
#scroll-btn.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}
#scroll-btn:hover {
  background: var(--c-accent-lt);
  color: var(--c-accent);
  border-color: var(--c-accent);
}

/* ── Empty state ── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 24px;
  text-align: center;
  color: var(--c-muted);
}
.empty-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--c-accent-lt), #dbeafe);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(37,99,235,.1);
}
.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
}
.empty-desc {
  font-size: 13px;
  max-width: 320px;
  line-height: 1.6;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}
.chip {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--c-text);
  cursor: pointer;
  transition: background .16s var(--ease), border-color .16s var(--ease), transform .14s var(--ease);
}
.chip:hover {
  background: var(--c-accent-lt);
  border-color: var(--c-accent);
  transform: translateY(-1px);
}

/* ── Messages ── */
.msg-row {
  display: flex;
  flex-shrink: 0;
  padding: 4px 24px;
  animation: msgIn .2s var(--ease) both;
}
.msg-row.user      { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bubble {
  max-width: 68%;
  border-radius: var(--r);
  padding: 11px 15px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
/* pre-wrap only during streaming — needed for textContent newlines */
.bubble.streaming {
  white-space: pre-wrap;
}
.msg-row.user .bubble {
  background: linear-gradient(135deg, var(--c-accent), #1d4ed8);
  color: #fff;
  border-bottom-right-radius: 3px;
  box-shadow: 0 2px 10px rgba(37,99,235,.25);
}
.msg-row.assistant .bubble {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-accent);
  border-bottom-left-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* Streaming cursor */
.bubble.streaming::after {
  content: '▍';
  color: var(--c-accent);
  animation: blink .65s step-end infinite;
  display: inline;
}
@keyframes blink { 50% { opacity: 0; } }

/* Typing indicator */
.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  background: #a0aec0;
  border-radius: 50%;
  animation: tdot .9s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes tdot {
  0%, 80%, 100% { transform: scale(.7); opacity: .5; }
  40%           { transform: scale(1);  opacity: 1;  }
}

/* Queue indicator inside typing bubble */
.typing-queue {
  display: none;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--c-warn);
  margin-bottom: 6px;
  animation: fadeIn .3s var(--ease);
}
.typing-queue.show { display: flex; }
@keyframes fadeIn { from { opacity:0; transform:translateY(-4px); } to { opacity:1; transform:none; } }
.typing-queue-icon { font-size: 14px; }

/* ── Sources ── */
.src-divider {
  border: none;
  border-top: 1px solid var(--c-border);
  margin: 10px 0 8px;
}
.src-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-muted);
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 5px;
  user-select: none;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.src-toggle:hover { background: var(--c-accent-lt); color: var(--c-accent); }
.src-toggle svg   { transition: transform .2s var(--ease); }
.src-toggle.open svg { transform: rotate(90deg); }

.src-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height .35s var(--ease), opacity .25s var(--ease);
}
.src-list.open { max-height: 900px; opacity: 1; }

.src-card {
  background: var(--c-bg);
  border-radius: 8px;
  border-left: 3px solid var(--c-border);
  padding: 9px 12px;
  font-size: 12px;
}
.src-card.hi  { border-left-color: var(--c-success); }
.src-card.mid { border-left-color: var(--c-warn); }
.src-card.lo  { border-left-color: var(--c-danger); }

.src-title  { font-weight: 600; margin-bottom: 5px; }
.src-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 6px; }
.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}
.b-re { background: #fdf2f8; color: #9d174d; }
.b-se { background: var(--c-accent-lt); color: var(--c-accent); }

.src-body {
  color: var(--c-muted);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 60px;
  overflow: hidden;
  transition: max-height .3s var(--ease);
}
.src-body.expanded { max-height: 400px; }
.src-more {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--c-accent);
  cursor: pointer;
}
.src-more:hover { text-decoration: underline; }

/* ── Input area ── */
.input-area {
  flex-shrink: 0;
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  padding: 12px 24px 14px;
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
  position: relative;   /* нужно для абсолютного позиционирования dropdown */
}

/* ── Autocomplete dropdown ── */
.suggest-list {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 24px;
  right: 24px;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  box-shadow: 0 -6px 24px rgba(0,0,0,.10);
  overflow: hidden;
  display: none;
  z-index: 100;
}
.suggest-list.show { display: block; }
.suggest-item {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--c-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--c-border);
  transition: background .12s var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover,
.suggest-item.active { background: var(--c-accent-lt); color: var(--c-accent); }
.suggest-item svg { flex-shrink: 0; color: var(--c-muted); }
.suggest-item.active svg { color: var(--c-accent); }
.suggest-hl { font-weight: 700; }
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.input-box {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--c-bg);
  border: 1.5px solid var(--c-border);
  border-radius: var(--r);
  overflow: hidden;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.input-box:focus-within {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: 10px 13px;
  font-size: 14px;
  color: var(--c-text);
  resize: none;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}
.input-box textarea::placeholder { color: var(--c-muted); }

.send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--r);
  background: linear-gradient(135deg, var(--c-accent), #1d4ed8);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(37,99,235,.3);
  transition: opacity .16s var(--ease), transform .14s var(--ease), box-shadow .16s var(--ease);
  line-height: 0;
}
.send-btn:hover:not(:disabled) {
  opacity: .9;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,.38);
}
.send-btn:active:not(:disabled) { transform: none; }
.send-btn:disabled { opacity: .38; cursor: default; box-shadow: none; }

.input-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--c-muted);
  text-align: center;
}
.input-hint a {
  color: var(--c-accent);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.input-hint a:hover { text-decoration: underline; }
.input-hint kbd {
  display: inline-block;
  font-family: inherit;
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--c-border, #e5e7eb);
  border-radius: 4px;
  background: var(--c-surface2, #f1f5f9);
  color: var(--c-muted);
  line-height: 1.5;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  margin: 16px;
  background: var(--c-surface);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  transform: translateY(16px) scale(.97);
  opacity: 0;
  transition: transform .26s cubic-bezier(.34,1.4,.64,1), opacity .2s var(--ease);
  display: flex;
  flex-direction: column;
}
.modal-backdrop.open .modal { transform: none; opacity: 1; }

.modal-body {
  padding: 28px;
  overflow-y: auto;
  flex: 1;
}
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: #c8d3e8; border-radius: 4px; }

.modal-hdr {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--c-text); }
.modal-desc  { font-size: 12px; color: var(--c-muted); margin-top: 3px; }

.modal-close {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--c-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.modal-close:hover { background: var(--c-bg); color: var(--c-text); }

.field       { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-muted);
  margin-bottom: 5px;
}
.field-ctrl {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  border: 1.5px solid var(--c-border);
  border-radius: 8px;
  outline: none;
  resize: none;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.field-ctrl:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: var(--c-surface);
}

.field-error {
  font-size: 12px;
  color: var(--c-danger);
  margin-top: -8px;
  margin-bottom: 12px;
  display: none;
}
.field-error.show { display: block; }

.modal-ftr {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-cancel {
  height: 36px;
  padding: 0 16px;
  background: none;
  border: 1.5px solid var(--c-border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-muted);
  transition: background .16s var(--ease), color .16s var(--ease);
}
.btn-cancel:hover { background: var(--c-bg); color: var(--c-text); }

.btn-primary {
  height: 36px;
  padding: 0 20px;
  background: linear-gradient(135deg, var(--c-accent), #1d4ed8);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  box-shadow: 0 2px 8px rgba(37,99,235,.28);
  transition: opacity .16s var(--ease), transform .14s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: .45; cursor: default; }
.btn-secondary {
  height: 36px;
  padding: 0 16px;
  background: var(--c-surface);
  border: 1.5px solid var(--c-border);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text);
  transition: background .16s var(--ease), transform .14s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-secondary:hover:not(:disabled) { background: var(--c-hover); transform: translateY(-1px); }
.btn-secondary:disabled { opacity: .45; cursor: default; }

/* Success state */
.modal-success {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
}
.modal-success.show { display: flex; }

.success-circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: #dcfce7;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-success);
}
.success-title { font-size: 15px; font-weight: 700; color: var(--c-text); }
.success-sub   { font-size: 12px; color: var(--c-muted); }

/* ── Admin / KB modal ── */
.admin-section { margin-bottom: 20px; }
.admin-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c-muted);
  margin-bottom: 10px;
}

.kb-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.kb-stat {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 8px;
  padding: 10px 12px;
}
.kb-stat-label { font-size: 10px; color: var(--c-muted); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.kb-stat-value { font-size: 14px; font-weight: 600; color: var(--c-text); }

.kb-drop {
  border: 2px dashed var(--c-border);
  border-radius: 10px;
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s var(--ease), background .18s var(--ease);
  position: relative;
}
.kb-drop:hover, .kb-drop.drag-over {
  border-color: var(--c-accent);
  background: var(--c-accent-lt);
}
.kb-drop input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.kb-drop-icon { font-size: 24px; margin-bottom: 6px; }
.kb-drop-text { font-size: 13px; color: var(--c-muted); line-height: 1.4; }
.kb-drop-text strong { color: var(--c-accent); }
.kb-drop-name {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
  background: var(--c-accent-lt);
  border: 1px solid var(--c-accent);
  border-radius: 6px;
  padding: 4px 10px;
  display: inline-block;
}

.kb-progress {
  display: none;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  font-size: 12px;
  color: #1d4ed8;
  align-items: center;
  gap: 8px;
}
.kb-progress.show { display: flex; }
.kb-spinner {
  width: 14px; height: 14px;
  border: 2px solid #bfdbfe;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.kb-result {
  display: none;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
}
.kb-result.show { display: block; }
.kb-result.ok {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #15803d;
}
.kb-result.err {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
}

.admin-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ── Provider tabs (LLM switcher) ── */
.prov-tabs {
  display: flex;
  gap: 4px;
  background: var(--c-bg);
  border: 1.5px solid var(--c-border);
  border-radius: 9px;
  padding: 3px;
  margin-bottom: 12px;
}
.prov-tab {
  flex: 1;
  height: 30px;
  border: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-muted);
  background: transparent;
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
  white-space: nowrap;
}
.prov-tab:hover:not(.active) { background: rgba(0,0,0,.04); color: var(--c-text); }
.prov-tab.active {
  background: var(--c-surface);
  color: var(--c-accent);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ── Analytics modal ── */
.an-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.an-card {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
}
.an-card-val  { font-size: 22px; font-weight: 700; color: var(--c-text); line-height: 1; }
.an-card-lbl  { font-size: 11px; color: var(--c-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }
.an-card.green .an-card-val { color: var(--c-success); }
.an-card.blue  .an-card-val { color: var(--c-accent); }
.an-card.warn  .an-card-val { color: var(--c-warn); }
.an-card.red   .an-card-val { color: var(--c-danger); }

.an-section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--c-muted); margin: 16px 0 8px;
}
.an-bar-wrap { display: flex; gap: 4px; align-items: flex-end; height: 56px; margin-bottom: 4px; }
.an-bar-col  { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.an-bar      { width: 100%; border-radius: 4px 4px 0 0; min-height: 3px; background: var(--c-accent); transition: height .3s; }
.an-bar.red  { background: #fca5a5; }
.an-bar-lbl  { font-size: 9px; color: var(--c-muted); }

.an-export-item { display:block;width:100%;text-align:left;padding:7px 14px;font-size:13px;background:none;border:none;cursor:pointer;color:var(--c-text); }
.an-export-item:hover { background:rgba(0,0,0,.04); }
.an-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.an-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); padding: 0 0 6px; border-bottom: 1px solid var(--c-border); }
.an-table td { padding: 7px 0; border-bottom: 1px solid var(--c-border); vertical-align: top; }
.an-table td:last-child { text-align: right; color: var(--c-muted); white-space: nowrap; padding-left: 8px; }
.an-table tr:last-child td { border-bottom: none; }
.an-empty { color: var(--c-muted); font-size: 13px; text-align: center; padding: 16px 0; }
.an-loading { color: var(--c-muted); font-size: 13px; text-align: center; padding: 24px 0; }
.an-log-toggle {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none;
  padding: 8px 0; margin-top: 4px;
  border-top: 1px solid var(--c-border);
}
.an-log-toggle:hover { opacity: .8; }
.an-log-chevron { font-size: 10px; color: var(--c-muted); transition: transform .2s; }
.an-log-wrap.an-log-open .an-log-chevron { transform: rotate(90deg); }
.an-log-body { display: none; max-height: 320px; overflow-y: auto; }
.an-log-wrap.an-log-open .an-log-body { display: block; }
.an-log-body::-webkit-scrollbar { width: 4px; }
.an-log-body::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 4px; }
.an-log-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--c-border);
  font-size: 12px;
}
.an-log-row:last-child { border-bottom: none; }
.an-log-ts { color: var(--c-muted); white-space: nowrap; font-size: 11px; flex-shrink: 0; }
.an-log-q { flex: 1; color: var(--c-text); word-break: break-word; }
.an-log-badges { display: flex; gap: 4px; flex-shrink: 0; }
.an-log-badge {
  font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: var(--c-surface2, #f1f5f9); color: var(--c-muted);
}
.an-log-badge.found { background: #dcfce7; color: #16a34a; }
.an-log-badge.notfound { background: #fee2e2; color: #dc2626; }
.an-log-badge.cached { background: #dbeafe; color: #2563eb; }

/* ══════════════════════════════
   DEBUG PANEL (right column)
   ══════════════════════════════ */

/* Resize handle */
.debug-resizer {
  flex-shrink: 0;
  width: 5px;
  background: #1e2d45;
  cursor: col-resize;
  position: relative;
  transition: background .15s;
  z-index: 10;
}
.debug-resizer:hover,
.debug-resizer.dragging { background: #2563eb; }
.debug-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 32px;
  background: currentColor;
  opacity: .4;
  border-radius: 1px;
}

.debug-col {
  width: 420px;
  min-width: 260px;
  max-width: 720px;
  flex-shrink: 0;
  background: #0f1623;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
}

.debug-hdr {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #1e2d45;
  background: #0b1120;
  gap: 8px;
}
.debug-hdr-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.debug-hdr-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #334155;
  flex-shrink: 0;
  transition: background .3s;
}
.debug-hdr-dot.active { background: #22c55e; box-shadow: 0 0 7px #22c55e99; }
.debug-hdr-title {
  font-size: 13px;
  font-weight: 700;
  color: #e2e8f0;
  letter-spacing: .02em;
}
.debug-timings {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.debug-timing-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  background: #1e2d45;
  color: #64748b;
  transition: color .3s, background .3s;
  white-space: nowrap;
}
.debug-timing-chip.ready { color: #7dd3fc; background: #0c2340; }

/* Debug history navigation */
.dbg-nav {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.dbg-nav-btn {
  background: #1e2d45;
  border: 1px solid #263348;
  color: #64748b;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
  line-height: 1;
  padding: 0;
}
.dbg-nav-btn:hover:not(:disabled) {
  background: #263348;
  border-color: #2563eb55;
  color: #94a3b8;
}
.dbg-nav-btn:disabled { opacity: .3; cursor: default; }
.dbg-nav-label {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  min-width: 36px;
  text-align: center;
  user-select: none;
}
.dbg-nav-query {
  font-size: 10px;
  color: #334155;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.debug-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0 24px;
}
.debug-body::-webkit-scrollbar { width: 4px; }
.debug-body::-webkit-scrollbar-thumb { background: #263348; border-radius: 4px; }

/* Empty state */
.debug-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  text-align: center;
  padding: 24px;
}
.debug-empty-icon {
  font-size: 36px;
  opacity: .3;
}
.debug-empty-text {
  font-size: 13px;
  line-height: 1.7;
  max-width: 230px;
  color: #475569;
}

/* Section */
.dbg-section { margin-bottom: 2px; }
.dbg-section-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.dbg-section-hdr:hover { background: #ffffff0a; }
.dbg-section-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dbg-section-icon { font-size: 15px; }
.dbg-section-title {
  font-size: 12px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.dbg-section-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  background: #1e2d45;
  color: #94a3b8;
}
.dbg-chevron {
  color: #475569;
  transition: transform .2s;
  font-size: 11px;
}
.dbg-section.open .dbg-chevron { transform: rotate(90deg); }

.dbg-section-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .3s cubic-bezier(.4,0,.2,1);
}
.dbg-section.open .dbg-section-body { max-height: 1400px; }
.dbg-section-inner { padding: 4px 16px 12px; }

/* Divider */
.dbg-divider { height: 1px; background: #1a2640; margin: 2px 0; }

/* Tokens */
.dbg-tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.dbg-token {
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  background: #0c2340;
  color: #7dd3fc;
  border: 1px solid #1e3a5f;
  border-radius: 5px;
  padding: 4px 10px;
  font-weight: 500;
}

/* Rank list */
.dbg-rank-list { display: flex; flex-direction: column; gap: 5px; }
.dbg-rank-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 10px;
  background: #0b1120;
  border-radius: 7px;
  border: 1px solid #1e2d45;
  transition: border-color .15s;
}
.dbg-rank-item:hover { border-color: #2563eb55; }
.dbg-rank-num {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: #1e2d45;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.dbg-rank-title {
  flex: 1;
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.45;
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.dbg-rank-score {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  font-family: monospace;
  color: #64748b;
  background: #1a2536;
  padding: 3px 7px;
  border-radius: 4px;
  margin-top: 1px;
}
.dbg-rank-score.hi  { color: #4ade80; background: #052010; }
.dbg-rank-score.mid { color: #fbbf24; background: #1c1205; }

/* RRF formula */
.dbg-rrf-formula {
  font-size: 12px;
  color: #94a3b8;
  font-family: 'Consolas', monospace;
  background: #0b1120;
  border: 1px solid #1e2d45;
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 10px;
  line-height: 1.7;
}
.dbg-rrf-formula .hl { color: #c4b5fd; font-weight: 700; }

/* Score bars */
.dbg-result-list { display: flex; flex-direction: column; gap: 10px; }
.dbg-result-card {
  background: #0b1120;
  border: 1px solid #1e2d45;
  border-radius: 8px;
  padding: 10px 12px;
}
.dbg-result-title {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 9px;
  line-height: 1.45;
}
.dbg-bars { display: flex; flex-direction: column; gap: 5px; }
.dbg-bar-row { display: flex; align-items: center; gap: 8px; }
.dbg-bar-label {
  width: 68px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #64748b;
}
.dbg-bar-track {
  flex: 1;
  height: 6px;
  background: #1e2d45;
  border-radius: 3px;
  overflow: hidden;
}
.dbg-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
}
.dbg-bar-fill.reranker { background: linear-gradient(90deg, #7c3aed, #c4b5fd); }
.dbg-bar-fill.semantic  { background: linear-gradient(90deg, #0369a1, #7dd3fc); }
.dbg-bar-fill.bm25      { background: linear-gradient(90deg, #92400e, #fbbf24); }
.dbg-bar-fill.rrf       { background: linear-gradient(90deg, #065f46, #6ee7b7); }
.dbg-bar-val {
  width: 38px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  font-family: monospace;
  color: #94a3b8;
  text-align: right;
}

/* ── Markdown rendered inside bubbles ── */
.bubble ul, .bubble ol {
  margin: 6px 0 6px 20px;
  padding: 0;
}
.bubble li {
  margin-bottom: 3px;
}
.bubble strong { font-weight: 600; }
.bubble em     { font-style: italic; }
.bubble br + br { display: none; } /* collapse double blank lines */

/* ── Links inside answer bubbles ── */
.msg-row.assistant .bubble a {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  font-weight: 500;
  transition: opacity .15s;
}
.msg-row.assistant .bubble a:hover { opacity: .75; }

/* UNC path (\\server\...) */
.unc-path {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: 'Consolas', 'Fira Code', monospace;
  font-size: .88em;
  background: #f1f5fb;
  border: 1px solid #dde4f0;
  border-radius: 4px;
  padding: 1px 7px;
  cursor: pointer;
  color: #1e293b;
  transition: background .15s;
  word-break: break-all;
}
.unc-path:hover { background: #e0eaff; border-color: #93c5fd; }
.unc-path::before { content: '📁'; font-size: .85em; }

/* ── Rating buttons (👍 / 👎) ── */
.rating-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--c-border);
}
.rating-lbl {
  font-size: 11px;
  color: var(--c-muted);
  margin-right: 2px;
  white-space: nowrap;
}
.rating-btn {
  background: none;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 15px;
  line-height: 1;
  color: var(--c-muted);
  transition: background .15s, border-color .15s, transform .1s;
}
.rating-btn:hover { background: var(--c-bg); border-color: #a8b4c8; transform: scale(1.12); }
.rating-btn.chosen.up   { background: #dcfce7; border-color: var(--c-success); }
.rating-btn.chosen.down { background: #fee2e2; border-color: var(--c-danger);  }
.rating-btn.unchosen    { opacity: .3; pointer-events: none; }

/* Copied toast */
.copy-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: #1e293b;
  color: #f1f5fb;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 16px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 999;
}
.copy-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Links inside source body cards */
.src-body a {
  color: var(--c-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.src-body .unc-path {
  font-size: .82em;
}

/* ── Login overlay ── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--c-primary-dk) 0%, var(--c-primary) 55%, #2a5fac 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.login-card {
  background: var(--c-surface);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  margin: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.login-logo {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--c-accent-lt), #dbeafe);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 4px 14px rgba(37,99,235,.15);
}
.login-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--c-text);
  text-align: center;
  margin-bottom: 5px;
}
.login-sub {
  font-size: 13px;
  color: var(--c-muted);
  text-align: center;
  margin-bottom: 24px;
}
.login-field {
  width: 100%;
  margin-bottom: 10px;
}
.login-field input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-bg);
  border: 1.5px solid var(--c-border);
  border-radius: 9px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.login-field input:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: #fff;
}
.login-error {
  width: 100%;
  font-size: 12px;
  color: var(--c-danger);
  min-height: 18px;
  margin-bottom: 6px;
  text-align: center;
}
.login-btn {
  width: 100%;
  height: 40px;
  background: linear-gradient(135deg, var(--c-accent), #1d4ed8);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(37,99,235,.3);
  transition: opacity .16s, transform .14s;
  margin-top: 4px;
}
.login-btn:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.login-btn:disabled { opacity: .5; cursor: default; }

/* ── Suggestions admin modal ── */
.sugg-tabs {
  display: flex; gap: 4px; background: var(--c-bg);
  border: 1.5px solid var(--c-border); border-radius: 9px;
  padding: 3px; margin-bottom: 16px;
}
.sugg-tab {
  flex: 1; height: 30px; border: none; border-radius: 7px;
  font-size: 12px; font-weight: 600; color: var(--c-muted);
  background: transparent; cursor: pointer;
  transition: background .15s, color .15s;
}
.sugg-tab:hover:not(.active) { background: rgba(0,0,0,.04); color: var(--c-text); }
.sugg-tab.active { background: var(--c-surface); color: var(--c-accent); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.sugg-tab .badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--c-danger); color: #fff;
  font-size: 10px; font-weight: 700; min-width: 16px; height: 16px;
  border-radius: 8px; padding: 0 4px; margin-left: 5px;
}
.sugg-tab.active .badge-count { background: var(--c-accent); }

.sugg-list { display: flex; flex-direction: column; gap: 10px; }

.sugg-card {
  background: var(--c-bg); border: 1.5px solid var(--c-border);
  border-radius: 10px; padding: 13px 14px;
}
.sugg-card-hdr {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}
.sugg-status {
  font-size: 11px; font-weight: 700; padding: 2px 9px;
  border-radius: 20px; white-space: nowrap;
}
.sugg-status.pending       { background: #fef3c7; color: #92400e; }
.sugg-status.auto_approved { background: #dcfce7; color: #15803d; }
.sugg-status.auto_rejected { background: #fee2e2; color: #b91c1c; }
.sugg-status.approved      { background: #dcfce7; color: #15803d; }
.sugg-status.rejected      { background: #fee2e2; color: #b91c1c; }

.sugg-ts { font-size: 11px; color: var(--c-muted); }

.sugg-query {
  font-size: 12px; font-weight: 600; color: var(--c-muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px;
}
.sugg-query span { font-weight: 400; color: var(--c-text); text-transform: none; letter-spacing: 0; }

.sugg-text {
  font-size: 13px; color: var(--c-text); line-height: 1.5;
  margin-bottom: 8px; padding: 8px 10px;
  background: var(--c-surface); border-radius: 6px;
  border-left: 3px solid var(--c-accent);
}
.sugg-llm {
  font-size: 11px; color: var(--c-muted); margin-bottom: 10px;
  display: flex; align-items: flex-start; gap: 5px;
}
.sugg-llm-label { flex-shrink: 0; font-weight: 600; }

.sugg-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.btn-sugg-approve {
  height: 30px; padding: 0 13px; font-size: 12px; font-weight: 600;
  background: #dcfce7; color: #15803d; border: 1.5px solid #86efac;
  border-radius: 7px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-sugg-approve:hover { background: #bbf7d0; border-color: #4ade80; }
.btn-sugg-reject {
  height: 30px; padding: 0 13px; font-size: 12px; font-weight: 600;
  background: #fee2e2; color: #b91c1c; border: 1.5px solid #fca5a5;
  border-radius: 7px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-sugg-reject:hover { background: #fecaca; border-color: #f87171; }

.qa-card {
  background: var(--c-bg); border: 1.5px solid var(--c-border);
  border-radius: 10px; padding: 12px 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.qa-card-body { flex: 1; min-width: 0; }
.qa-card-query { font-size: 12px; font-weight: 600; color: var(--c-muted); margin-bottom: 4px; }
.qa-card-answer { font-size: 13px; color: var(--c-text); line-height: 1.5; }
.qa-card-source {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; background: var(--c-accent-lt);
  color: var(--c-accent); margin-top: 6px; display: inline-block;
}
.btn-qa-del {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 6px;
  background: none; border: 1.5px solid var(--c-border);
  color: var(--c-muted); font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-qa-del:hover { background: #fee2e2; border-color: #fca5a5; color: var(--c-danger); }

.sugg-empty { text-align: center; padding: 32px 0; color: var(--c-muted); font-size: 13px; }
.sugg-loading { text-align: center; padding: 24px 0; color: var(--c-muted); font-size: 13px; }

/* ── Suggest-answer button (появляется после 👎) ── */
.suggest-answer-btn {
  display: none;
  margin-left: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--c-accent);
  background: var(--c-accent-lt);
  border: 1px solid #bfdbfe;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  align-items: center;
  gap: 4px;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.suggest-answer-btn:hover { background: #dbeafe; border-color: var(--c-accent); }
.suggest-answer-btn.show  { display: inline-flex; }

/* Logout button */
.btn-logout {
  height: 32px;
  padding: 0 13px;
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.7);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .18s, color .18s;
}
.btn-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ══════════════════════════════════════════════════════════════════
   UTILITY — заменяют inline style= атрибуты (CSP: убираем unsafe-inline)
   ══════════════════════════════════════════════════════════════════ */

/* ── Display helpers ── */
.d-none { display: none !important; }

/* ── Modal widths ── */
#admin-modal { max-width: 500px; }
#sa-modal    { max-width: 620px; }
#an-modal    { max-width: 580px; }

/* ── Login overlay: initially hidden ── */
#login-overlay { display: none; }

/* ── Header: logout button initially hidden ── */
#btn-logout { display: none; }

/* ── Debug panel navigation: initially hidden ── */
#dbg-nav    { display: none; }
#dbg-content { display: none; }

/* ── LLM provider: active badge + panel initial state ── */
#prov-active-badge {
  display: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-success);
  margin-bottom: 10px;
}
#prov-panel-external { display: none; }

/* ── LLM provider: local panel controls ── */
.prov-local-ctrl { display: flex; gap: 8px; align-items: center; }
#model-select    { flex: 1; height: 36px; padding: 0 10px; cursor: pointer; }
#model-apply-btn { height: 36px; padding: 0 16px; white-space: nowrap; }
#model-status    { font-size: 12px; color: var(--c-muted); margin-top: 6px; }

/* ── External API profiles ── */
#ext-profiles-list { margin-bottom: 12px; }
#ext-add-details   { margin-bottom: 6px; }
#ext-add-details > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-primary);
  user-select: none;
}
.ext-form-body { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
#ext-name-input, #ext-url-input, #ext-key-input { height: 34px; padding: 0 10px; }
.ext-model-row { display: flex; gap: 6px; align-items: center; }
#ext-model-select { flex: 1; height: 34px; padding: 0 8px; }
[data-action="loadExtModels"] {
  flex-shrink: 0; height: 34px; padding: 0 10px;
  font-size: 12px; background: none;
  border: 1px solid var(--c-border); border-radius: 6px;
  cursor: pointer; white-space: nowrap;
}
#ext-model-status { font-size: 11px; color: var(--c-muted); margin-top: -2px; }
.ext-action-row   { display: flex; gap: 8px; align-items: center; }
[data-action="saveExtProfile"] { height: 32px; padding: 0 14px; font-size: 13px; }
[data-action="clearExtForm"] {
  height: 32px; padding: 0 10px;
  font-size: 12px; background: none;
  border: 1px solid var(--c-border); border-radius: 6px; cursor: pointer;
}
#ext-status { font-size: 12px; margin-top: 4px; }

/* ── KB stats ── */
#kbs-rebuilt  { font-size: 12px; }
#kbs-file-list { margin-top: 10px; }

/* ── Token limits ── */
.admin-section--mt16 { margin-top: 16px; }
.tok-form { display: flex; flex-direction: column; gap: 10px; }
.tok-label {
  font-size: 12px; font-weight: 500;
  color: var(--c-text); display: block; margin-bottom: 4px;
}
.tok-label-note { font-weight: 400; color: var(--c-muted); }
#tok-max-tokens, #tok-max-context { height: 34px; padding: 0 10px; width: 100%; }
.tok-action-row { display: flex; align-items: center; gap: 8px; }
[data-action="saveTokenLimits"] { height: 34px; padding: 0 16px; font-size: 13px; }
#tok-status { font-size: 12px; color: var(--c-muted); }

/* ── KB file drop ── */
#kb-chosen-name { display: none; }

/* ── Synonyms & stop-words ── */
.admin-section--mt24 { margin-top: 24px; }
.syn-hint { font-size: 12px; color: var(--c-muted); margin: 0 0 10px; }
.syn-label { font-size: 12px; font-weight: 600; display: block; margin-bottom: 4px; }
.syn-label--mt { margin: 10px 0 4px; }
.syn-label-note { font-weight: 400; color: var(--c-muted); }
#syn-synonyms, #syn-stopwords {
  width: 100%; box-sizing: border-box;
  font-family: monospace; font-size: 12px;
  padding: 8px; border: 1px solid var(--c-border);
  border-radius: 6px; resize: vertical;
}
.syn-action-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
[data-action="saveSynonyms"] { height: 34px; padding: 0 14px; }
#syn-status { font-size: 12px; }

/* ── Search thresholds ── */
.thresh-hint { font-size: 12px; color: var(--c-muted); margin: 0 0 12px; }
#thresh-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.field-label--sm { font-size: 11px; }
#th-reranker, #th-semantic, #th-qa-sim, #th-qa-reranker, #th-top-k {
  height: 32px; padding: 0 8px; font-size: 13px;
}
.thresh-action-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
[data-action="saveThresholds"] { height: 34px; padding: 0 14px; }
[data-action="loadThresholds"] {
  height: 34px; padding: 0 10px; font-size: 12px;
  background: none; border: 1px solid var(--c-border);
  border-radius: 6px; cursor: pointer;
}
#thresh-status { font-size: 12px; }

/* ── Widget section ── */
.admin-section--mt8  { margin-top: 8px; }
.retrieval-subsection { padding: 8px 0; }
.retrieval-sub-label  { font-size: 12px; font-weight: 600; color: #555; margin-bottom: 6px; }
.wgt-toggle-row   { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.wgt-toggle-label { font-size: 13px; color: var(--c-muted); flex: 1; }
.wgt-toggle-wrap  { position: relative; display: inline-block; width: 40px; height: 22px; }
.wgt-toggle-input { opacity: 0; width: 0; height: 0; }
#wgt-toggle-track {
  position: absolute; cursor: pointer; inset: 0;
  background: #ccc; border-radius: 22px; transition: .2s;
}
#wgt-toggle-knob {
  position: absolute; height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.field--mb10 { margin-bottom: 10px; }
.wgt-color-row { display: flex; gap: 8px; align-items: center; }
#wgt-color-picker {
  width: 38px; height: 34px;
  border: 1.5px solid var(--c-border);
  border-radius: 6px; cursor: pointer; padding: 2px;
}
#wgt-color-text { flex: 1; }
.wgt-snippet-wrap      { margin-bottom: 10px; }
.wgt-snippet-label     { margin-bottom: 4px; }
.wgt-snippet-container { position: relative; }
#wgt-snippet {
  width: 100%; font-family: monospace; font-size: 11px;
  background: #f4f6fb; border: 1.5px solid var(--c-border);
  border-radius: 6px; padding: 8px 36px 8px 10px;
  resize: none; color: var(--c-text); line-height: 1.5;
}
[data-action="wgtCopySnippet"] {
  position: absolute; top: 6px; right: 6px;
  border: none; background: none;
  cursor: pointer; color: var(--c-muted); padding: 2px;
}
#wgt-save-msg { font-size: 12px; color: #2ecc71; display: none; margin-left: 8px; }

/* ── Modal success button ── */
.modal-success .btn-primary { margin-top: 6px; }

/* ── Suggestions admin modal ── */
.sa-modal-hdr-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.sugg-tabs--flex  { flex: 1; margin-bottom: 0; }
#sa-count-pending { display: none; }
[data-action="loadSuggAdminTabCurrent"] {
  flex-shrink: 0; height: 30px; padding: 0 10px;
  font-size: 12px; background: none;
  border: 1.5px solid var(--c-border); border-radius: 7px;
  cursor: pointer; color: var(--c-muted);
}

/* ── Suggestion question display ── */
#sg-question-display {
  padding: 9px 12px; font-size: 13px;
  color: var(--c-muted); background: var(--c-bg);
  border: 1.5px solid var(--c-border);
  border-radius: 8px; line-height: 1.45;
}

/* ── Analytics modal ── */
.an-modal-hdr-row { display: flex; align-items: center; gap: 6px; }
#an-export-wrap   { position: relative; }
[data-action="toggleExportMenu"] {
  height: 30px; padding: 0 10px; font-size: 12px;
  background: none; border: 1px solid var(--c-border);
  border-radius: 6px; cursor: pointer; white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}
#an-export-menu {
  display: none; position: absolute; right: 0; top: 34px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 10; min-width: 170px; padding: 4px 0;
}
.an-export-sec-lbl {
  padding: 6px 12px 4px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--c-muted);
}
.an-export-divider { height: 1px; background: var(--c-border); margin: 4px 0; }
.an-export-row2 { display:flex; align-items:center; }
.an-export-row2 .an-export-item { flex:1; }
.an-export-xls { padding:2px 7px; font-size:10px; font-weight:700; border-radius:3px; border:1px solid #1d6f42; background:none; cursor:pointer; color:#1d6f42; margin-right:8px; white-space:nowrap; }
.an-export-xls:hover { background:#1d6f4218; }

/* ── JS template literals: динамические элементы ── */
.bubble--empty-answer { color: var(--c-muted); font-style: italic; }
.bubble--error        { color: var(--c-danger); }

/* dbgRender: query rewriting block */
.dbg-rewrite-wrap  { padding: 8px 16px 10px; }
.dbg-rewrite-title {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: #64748b; margin-bottom: 6px;
}
.dbg-rewrite-row  { font-size: 12px; color: #475569; margin-bottom: 3px; }
.dbg-rewrite-row-last { font-size: 12px; color: #475569; }
.dbg-rewrite-orig { color: #94a3b8; }
.dbg-rewrite-new  { color: #7dd3fc; font-weight: 600; }

/* External API profile list (generated by renderExtProfiles) */
.ext-profile-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0; border-bottom: 1px solid var(--c-border);
}
.ext-profile-info  { flex: 1; min-width: 0; }
.ext-profile-name  {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ext-profile-url {
  font-size: 11px; color: var(--c-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ext-profile-btn-activate {
  flex-shrink: 0; height: 28px; padding: 0 10px;
  font-size: 12px; background: var(--c-primary);
  color: #fff; border: none; border-radius: 5px; cursor: pointer;
}
.ext-profile-btn-edit {
  flex-shrink: 0; height: 28px; padding: 0 8px;
  font-size: 12px; background: none;
  border: 1px solid var(--c-border); border-radius: 5px; cursor: pointer;
}
.ext-profile-btn-delete {
  flex-shrink: 0; height: 28px; padding: 0 8px;
  font-size: 12px; background: none; border: none;
  color: #ef4444; cursor: pointer;
}
.ext-profile-empty { font-size: 12px; color: var(--c-muted); margin-bottom: 4px; }

/* KB file list (generated by loadIndexInfo) */
.kb-file-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid var(--c-border);
}
.kb-file-name {
  font-size: 13px; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kb-file-size { font-size: 11px; color: var(--c-muted); white-space: nowrap; }
.kb-file-del  {
  background: none; border: none; cursor: pointer;
  color: #ef4444; padding: 2px 4px; font-size: 14px;
  line-height: 1; flex-shrink: 0;
}
.kb-file-empty { font-size: 12px; color: var(--c-muted); padding: 4px 0; }

/* Analytics chart bars (heights set via element.style from JS — CSSOM, not HTML attr) */
.an-bar-stack {
  display: flex; flex-direction: column; gap: 2px;
  align-items: center; height: 52px; justify-content: flex-end;
}
.an-bar--empty { height: 3px; width: 100%; background: var(--c-border); border-radius: 2px; }
.an-chart-legend       { margin-left: 8px; font-size: 10px; font-weight: 400; }
.an-chart-legend-found { color: var(--c-accent); }
.an-chart-legend-notfound { color: #fca5a5; }
.an-section-title--danger { color: var(--c-danger); }
.an-section-title--warn   { color: var(--c-warn); }
.an-log-count  { font-weight: 400; color: var(--c-muted); }
