/**
 * siren.css — SIREN Standalone Frontend Styles
 * SKYbrary white-and-navy institutional aesthetic
 *
 * Changelog:
 *   2026-03-28 — SVG outline иконки за feedback бутоните (премахнати emoji);
 *                .rag-feedback-modal__btn.is-active → navy fill + бял текст/икона;
 *                .rag-feedback-btn → inline-flex + currentColor за SVG stroke.
 *                Добавени стилове за feedback UI:
 *                .rag-feedback-bar, .rag-feedback-btn,
 *                .rag-feedback-modal и всички под-компоненти.
 *   2026-03-24 — Добавени .rag-analytics-toggle и .rag-analytics-badge
 *                за Extended Analytics (Experimental) checkbox.
 */

@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600;700&display=swap');

:root {
  --rag-bg: #ffffff;
  --rag-surface: #f4f6f8;
  --rag-surface-dark: #e8ecf0;
  --rag-border: #d0d7de;
  --rag-navy: #003366;
  --rag-navy-light: #004488;
  --rag-navy-dim: rgba(0, 51, 102, 0.08);
  --rag-text: #1a1a2e;
  --rag-text-muted: #6b7280;
  --rag-red: #c0392b;
  --rag-blue-light: #e8f0f8;
  --rag-radius: 4px;
  --rag-font: 'Open Sans', Arial, sans-serif;
}

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

body {
  margin: 0;
  padding: 1rem;
  background: #eef1f5;
  font-family: var(--rag-font);
}

/* ── Widget ─────────────────────────────────────────────────────────────────── */
.skybrary-rag {
  font-family: var(--rag-font);
  background: var(--rag-bg);
  border: 1px solid var(--rag-border);
  border-top: 4px solid var(--rag-navy);
  border-radius: var(--rag-radius);
  overflow: hidden;
  max-width: 900px;
  margin: 2rem auto;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.rag-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 1.25rem;
  background: var(--rag-navy);
  color: #fff;
}
.rag-header__icon     { font-size: 1.1rem; color: #fff; }
.rag-header__title    { font-size: 0.9rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #fff; }
.rag-header__subtitle { font-size: 0.68rem; font-weight: 400; color: rgba(255,255,255,0.55); letter-spacing: 0.02em; }

.rag-status {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.06em;
  transition: color 0.3s;
}
.rag-status.is-loading { color: #f9ca24; animation: analyzing-pulse 1.4s ease-in-out infinite; }
.rag-status.is-done    { color: #6fcf97; }
.rag-status.is-error   { color: #ff6b6b; }

/* ── Route bar ──────────────────────────────────────────────────────────────── */
.rag-route {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1.25rem;
  background: var(--rag-blue-light);
  border-bottom: 1px solid var(--rag-border);
  font-size: 0.72rem;
  font-weight: 600;
  flex-wrap: wrap;
}
.rag-route__item   { color: var(--rag-navy); }
.rag-route__sep    { color: var(--rag-border); }
.rag-route__router { color: var(--rag-text-muted); font-weight: 400; }

.rag-route__mode {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; padding: 0.15rem 0.55rem;
  border-radius: 3px; border: 1px solid transparent;
}
.rag-route__mode.is-conceptual    { background: rgba(0,51,102,0.1);   border-color: rgba(0,51,102,0.25);   color: var(--rag-navy); }
.rag-route__mode.is-investigative { background: rgba(180,100,0,0.1);  border-color: rgba(180,100,0,0.3);   color: #7a4200; }
.rag-route__mode.is-analytical    { background: rgba(80,0,140,0.08);  border-color: rgba(80,0,140,0.22);   color: #50008c; }
.rag-route__mode.is-refusal       { background: rgba(192,57,43,0.08); border-color: rgba(192,57,43,0.25);  color: var(--rag-red); }

/* ── Stats panel ────────────────────────────────────────────────────────────── */
.rag-stats {
  display: none;
  border-bottom: 1px solid var(--rag-border);
  padding: 1rem 1.25rem;
  background: var(--rag-surface);
}
.rag-stats__summary { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }

.rag-stats__pill {
  font-size: 0.72rem; font-weight: 600; padding: 0.2rem 0.65rem;
  background: var(--rag-navy-dim); border: 1px solid rgba(0,51,102,0.2);
  border-radius: 3px; color: var(--rag-navy);
}
.rag-stats__pill.is-filter {
  background: var(--rag-navy); border-color: var(--rag-navy); color: #fff; letter-spacing: 0.04em;
}

.rag-stats__chart            { margin-bottom: 1rem; }
.rag-stats__chart:last-child { margin-bottom: 0; }
.rag-stats__chart-title {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--rag-text-muted);
  margin-bottom: 0.5rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--rag-border);
}
.rag-stats__bar-row {
  display: grid; grid-template-columns: 220px 1fr 44px;
  align-items: center; gap: 0.6rem; margin-bottom: 0.3rem;
}
.rag-stats__bar-label { font-size: 0.78rem; color: var(--rag-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rag-stats__bar-track { height: 7px; background: var(--rag-surface-dark); border-radius: 4px; overflow: hidden; }
.rag-stats__bar-fill  { height: 100%; background: var(--rag-navy); border-radius: 4px; transition: width 0.5s ease; }
.rag-stats__bar-count { font-size: 0.72rem; font-weight: 600; color: var(--rag-text-muted); text-align: right; }
.rag-stats__sparkline { width: 100%; height: 52px; display: block; }
.rag-stats__spark-labels {
  display: flex; justify-content: space-between;
  font-size: 0.68rem; color: var(--rag-text-muted); margin-top: 0.2rem;
}


.rag-rate-limit {
    font-size: 11px;
    color: var(--rag-text-muted);
    margin-left: auto;
}
.rag-rate-limit.is-low {
    color: var(--rag-red);
    font-weight: 600;
}

/* ── Response area ──────────────────────────────────────────────────────────── */
.rag-response {
  min-height: 120px; max-height: 480px; overflow-y: auto;
  padding: 0; font-size: 0.92rem; line-height: 1.7;
  color: var(--rag-text); scrollbar-width: thin; scrollbar-color: var(--rag-border) transparent;
}
.rag-response__placeholder { color: var(--rag-text-muted); font-style: italic; padding: 1.4rem 1.5rem; margin: 0; }
.rag-response::-webkit-scrollbar       { width: 4px; }
.rag-response::-webkit-scrollbar-track { background: transparent; }
.rag-response::-webkit-scrollbar-thumb { background: var(--rag-border); border-radius: 2px; }

/* ── Q/A blocks ─────────────────────────────────────────────────────────────── */
.rag-qa-block    { border-bottom: 1px solid var(--rag-border); }
.rag-qa-q {
  display: flex; gap: 0.75rem; align-items: baseline;
  padding: 0.85rem 1.5rem; background: var(--rag-blue-light);
  border-bottom: 1px solid var(--rag-border);
}
.rag-qa-q__label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--rag-navy); flex-shrink: 0; }
.rag-qa-q__text  { font-size: 0.9rem; font-weight: 600; color: var(--rag-navy); }

.rag-qa-a        { display: flex; gap: 0.75rem; align-items: baseline; padding: 1rem 1.5rem; }
.rag-qa-a__label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--rag-text-muted); flex-shrink: 0; }
.rag-qa-a__text  { font-size: 0.92rem; color: var(--rag-text); line-height: 1.75; flex: 1; }
.rag-qa-a__text-refusal { color: var(--rag-text-muted); font-style: italic; margin: 0; }

/* ── Cursor ─────────────────────────────────────────────────────────────────── */
.rag-cursor {
  display: inline-block; width: 2px; height: 1em; background: var(--rag-navy);
  margin-left: 2px; vertical-align: text-bottom; animation: blink 0.8s step-end infinite;
}
@keyframes blink {0%, 50%, 100% { opacity: 1; }
  25%, 75% { opacity: 0; } }

/* ── Analyzing ──────────────────────────────────────────────────────────────── */
.rag-analyzing { color: var(--rag-text-muted); font-style: italic; animation: analyzing-pulse 1.4s ease-in-out infinite; }
@keyframes analyzing-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Progress bar (indeterminate) ───────────────────────────────────────────── */
.rag-progress-bar {
  display: block;
  height: 2px;
  margin-top: 0.5rem;
  background: linear-gradient(90deg, transparent 0%, var(--rag-navy) 40%, var(--rag-navy-light) 60%, transparent 100%);
  background-size: 200% 100%;
  animation: rag-progress-slide 1.6s linear infinite;
  border-radius: 1px;
  opacity: 0.6;
}
@keyframes rag-progress-slide {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* Fade transition for analyzing text updates */
.rag-analyzing.is-updating {
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* ── Sources ────────────────────────────────────────────────────────────────── */
.rag-sources { border-top: 1px solid var(--rag-border); padding: 0.8rem 1.25rem; background: var(--rag-surface); }
.rag-sources__title {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--rag-text-muted); margin: 0 0 0.55rem;
}
.rag-sources__list  { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.rag-sources__group {
  width: 100%; font-size: 0.63rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--rag-text-muted); margin: 0.4rem 0 0.15rem;
}
.rag-sources__group:first-child { margin-top: 0; }
.rag-sources__item a {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.22rem 0.6rem; background: var(--rag-bg); border: 1px solid var(--rag-border);
  border-radius: 3px; font-size: 0.74rem; color: var(--rag-navy);
  text-decoration: none; transition: background 0.15s, border-color 0.15s;
}
.rag-sources__item a:hover { background: var(--rag-blue-light); border-color: var(--rag-navy); }
.rag-sources__score { color: var(--rag-text-muted); font-size: 0.66rem; }

.rag-sources__badge {
  font-size: 0.62rem; font-weight: 700; padding: 0.1rem 0.3rem;
  border-radius: 2px; margin-right: 0.25rem; flex-shrink: 0; line-height: 1;
}
.rag-sources__badge.is-curated  { background: rgba(180,140,0,0.12); border: 1px solid rgba(180,140,0,0.35); color: #7a5c00; }
.rag-sources__badge.is-category { background: rgba(0,100,100,0.1);  border: 1px solid rgba(0,100,100,0.25); color: #005555; }
.rag-sources__badge.is-operator { background: rgba(0,48,96,0.09);   border: 1px solid rgba(0,48,96,0.28);   color: #003060; }

.rag-sources__item--grouped {
  padding-bottom: .4rem;
}
.rag-sources__chunk {
  display: block;
  font-size: .75rem;
  color: #6b7280;
  padding-left: .75rem;
  line-height: 1.6;
}
.rag-sources__chunk::before {
  content: '· ';
}

.rag-citation {
  color: var(--rag-navy, #1a3a5c);
  font-size: 0.75em;
  vertical-align: super;
  text-decoration: none;
  font-weight: 600;
  padding: 0 1px;
}

.rag-citation:hover {
  text-decoration: underline;
}

/* ── Form ───────────────────────────────────────────────────────────────────── */
/*.rag-form {
  display: flex; gap: 0.6rem; padding: 0.9rem 1.25rem;
  border-top: 2px solid var(--rag-navy); background: var(--rag-surface);
}
*/
.rag-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.9rem 1.25rem;
  border-top: 2px solid var(--rag-navy);
  background: var(--rag-surface);
}
.rag-form__input {
  flex: 1; background: var(--rag-bg); border: 1px solid var(--rag-border);
  border-radius: var(--rag-radius); color: var(--rag-text); font-family: var(--rag-font);
  font-size: 0.9rem; line-height: 1.5; padding: 0.6rem 0.9rem;
  resize: none; transition: border-color 0.2s; outline: none;
}
.rag-form__input:focus       { border-color: var(--rag-navy); }
.rag-form__input::placeholder { color: var(--rag-text-muted); }

.rag-form__button {
  display: flex; align-items: center; gap: 0.4rem; padding: 0 1.2rem;
  background: var(--rag-navy); border: 2px solid rgba(255,255,255,0.6); border-radius: var(--rag-radius);
  color: #fff; font-family: var(--rag-font); font-size: 0.85rem; font-weight: 700;
  letter-spacing: 0.04em; cursor: pointer; transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}
.rag-form__button:hover:not(:disabled)  { background: var(--rag-navy-light); }
.rag-form__button:active:not(:disabled) { transform: scale(0.97); }
.rag-form__button:disabled { opacity: 0.5; cursor: not-allowed; }

 /* ── Form row + hint ─────────────────────────────────────────────────────────── */
/*
.rag-form__row {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}
*/

.rag-form__row {
  display: flex;
  gap: 0.6rem;
  width: 100%;
}

.rag-form__hint {
  display: none;
  margin: 0.45rem 0 0;
  font-size: 0.74rem;
  color: #4b5568;
  line-height: 1.5;
  transition: color 0.3s ease;
}

.rag-form__hint.is-appearing {
  animation: hint-flash 3.8s ease forwards;
}

@keyframes hint-flash {
  0%   { color: #4b5568; }
  15%  { color: #1d4ed8; }
  30%  { color: #4b5568; }
  45%  { color: #1d4ed8; }
  60%  { color: #4b5568; }
  75%  { color: #1d4ed8; }
  90%  { color: #4b5568; }
  100% { color: #1d4ed8; }
}

.rag-form__hint strong {
  font-weight: 700;
  color: var(--rag-navy);
}

/* ── Error ──────────────────────────────────────────────────────────────────── */
.rag-error { color: var(--rag-red); font-size: 0.85rem; padding: 0.8rem 1.5rem; white-space: pre-line; text-align: center; background: #fdf0ef; border-top: 1px solid #f5c6c3; }

/* ── Markdown rendered content ──────────────────────────────────────────────── */
.rag-qa-a__text h2,
.rag-qa-a__text h3,
.rag-qa-a__text h4 { font-family: var(--rag-font); color: var(--rag-navy); margin: 1em 0 0.35em; line-height: 1.3; }
.rag-qa-a__text h2 { font-size: 1rem;    font-weight: 700; }
.rag-qa-a__text h3 { font-size: 0.95rem; font-weight: 700; }
.rag-qa-a__text h4 { font-size: 0.88rem; font-weight: 700; }
.rag-qa-a__text h2:first-child,
.rag-qa-a__text h3:first-child,
.rag-qa-a__text h4:first-child { margin-top: 0; }
.rag-qa-a__text p           { margin: 0 0 0.75em; line-height: 1.75; }
.rag-qa-a__text p:last-child { margin-bottom: 0; }
.rag-qa-a__text ul,
.rag-qa-a__text ol { margin: 0.35em 0 0.75em; padding-left: 1.4em; }
.rag-qa-a__text li { margin-bottom: 0.3em; line-height: 1.6; }
.rag-qa-a__text strong { font-weight: 700; color: var(--rag-text); }
.rag-qa-a__text em     { font-style: italic; }
.rag-qa-a__text code   {
  font-family: 'Consolas', 'Monaco', monospace; font-size: 0.84em;
  background: var(--rag-surface-dark); padding: 0.1em 0.35em; border-radius: 2px;
}

/* ── New conversation button ───────────────────────────────────────────────── */
.rag-new-conv-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  margin-left: 0.6rem;
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: 1px solid var(--rag-border, #d0d5dd);
  border-radius: 6px;
  color: var(--rag-muted, #667085);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.rag-new-conv-btn:hover {
  background: var(--rag-surface-alt, #f9fafb);
  border-color: var(--rag-navy, #1c2b4a);
  color: var(--rag-navy, #1c2b4a);
}

/* ── Context indicator in route bar ────────────────────────────────────────── */
.rag-route__context {
  display: inline-flex;
  align-items: center;
  gap: 0.2em;
  padding: 0.1rem 0.45rem;
  background: var(--rag-accent-muted, #e8f0fe);
  color: var(--rag-accent, #2563eb);
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ── Reformulation notice ──────────────────────────────────────────────────── */
.rag-reformulation {
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.3rem 0.75rem;
  margin-top: 0.3rem;
  background: var(--rag-surface-alt, #f9fafb);
  border-left: 2px solid var(--rag-accent, #2563eb);
  border-radius: 0 4px 4px 0;
  color: var(--rag-muted, #667085);
  font-size: 0.78rem;
  line-height: 1.4;
  animation: rag-fade-in 0.2s ease;
}
.rag-reformulation em {
  font-style: normal;
  color: var(--rag-text, #1a1a2e);
  font-weight: 500;
}
.rag-reformulation__icon {
  font-size: 0.85em;
  flex-shrink: 0;
}
@keyframes rag-fade-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Cache hit indicator ───────────────────────────────────────────────────── */
.rag-route__cache {
  display: inline-flex;
  align-items: center;
  gap: 0.2em;
  padding: 0.1rem 0.45rem;
  background: #f0fdf4;
  color: #16a34a;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-left: 0.3rem;
}

/* ── Markdown rendered content ────────────────────────────────────────────── */
.rag-answer table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.875rem;
}
.rag-answer table th,
.rag-answer table td {
  border: 1px solid var(--rag-border);
  padding: 0.45rem 0.75rem;
  text-align: left;
}
.rag-answer table th {
  background: var(--rag-navy);
  color: #fff;
  font-weight: 600;
}
.rag-answer table tr:nth-child(even) td {
  background: rgba(0,0,0,0.03);
}
.rag-answer h2, .rag-answer h3, .rag-answer h4 {
  margin: 1.1rem 0 0.4rem;
  color: var(--rag-navy);
}
.rag-answer ul, .rag-answer ol {
  padding-left: 1.4rem;
  margin: 0.5rem 0;
}
.rag-answer li { margin: 0.25rem 0; }
.rag-answer p  { margin: 0.5rem 0; }
.rag-answer code {
  background: rgba(0,0,0,0.06);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.85em;
}

.rag-help-btn {
    width: 24px;
    height: 24px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--rag-border);
    border-radius: 50%;

    text-decoration: none;
    font-size: 14px;
    line-height: 1;

    color: inherit;
    background: transparent;

    cursor: pointer;
    user-select: none;

    font-size: 13px;

    transition: 
        background 0.15s ease,
        border-color 0.15s ease,
        transform 0.05s ease;
}
.rag-help-btn:hover {
    background: rgba(255,255,255,0.08);
}
.rag-help-btn:active {
    transform: scale(0.95);
}
.rag-help-btn:focus-visible {
    outline: 2px solid var(--rag-border);
    outline-offset: 2px;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile-first adjustments
   Breakpoints:
     ≤ 600px  — phone portrait (primary target)
     ≤ 900px  — phone landscape / small tablet
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Base adjustments for the page wrapper ─────────────────────────────────── */
@media (max-width: 900px) {
  body {
    padding: 0;
    background: #fff;
  }

  .skybrary-rag {
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    border-top: 4px solid var(--rag-navy);
    box-shadow: none;
    /* Full-height layout: header + content + form pinned at bottom */
    display: flex;
    flex-direction: column;
    min-height: 100dvh;      /* dvh handles mobile browser chrome resize */
    min-height: 100vh;       /* fallback for older Safari */
  }

  /* Response area grows to fill available space, form stays pinned */
  .rag-response {
    flex: 1;
    max-height: none;        /* remove the 480px cap */
    min-height: 0;           /* allow flex shrink */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Sources pushes form down naturally */
  .rag-sources {
    flex-shrink: 0;
  }

  /* Form pinned at bottom */
  .rag-form {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
    border-top: 2px solid var(--rag-navy);
    background: var(--rag-surface);
  }
}

/* ── Phone portrait ────────────────────────────────────────────────────────── */
@media (max-width: 600px) {

  /* Header — compact, subtitle hidden to save space */
  .rag-header {
    padding: 0.6rem 1rem;
    gap: 0.5rem;
  }
  .rag-header__subtitle {
    display: none;
  }
  .rag-header__title {
    font-size: 0.85rem;
  }
  .rag-status {
    font-size: 0.68rem;
  }

  /* Route bar — smaller text, tighter padding */
  .rag-route {
    padding: 0.3rem 1rem;
    font-size: 0.68rem;
    gap: 0.35rem;
  }

  /* Stats — fix the broken 3-column grid (220px label overflows on phone) */
  .rag-stats {
    padding: 0.75rem 1rem;
  }
  .rag-stats__bar-row {
    grid-template-columns: 1fr 80px 36px;   /* label fluid, bar narrower */
    gap: 0.4rem;
  }
  .rag-stats__bar-label {
    font-size: 0.72rem;
  }

  /* Q/A blocks — reduce padding, avoid cramped layout */
  .rag-qa-q {
    padding: 0.7rem 1rem;
    gap: 0.5rem;
  }
  .rag-qa-q__label {
    font-size: 0.65rem;
  }
  .rag-qa-q__text {
    font-size: 0.85rem;
  }

  .rag-qa-a {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
    /* On narrow screens the Q/A label wastes horizontal space — hide it */
    align-items: flex-start;
  }
  .rag-qa-a__label {
    display: none;
  }
  .rag-qa-a__text {
    font-size: 0.88rem;
    line-height: 1.65;
  }

  /* Response placeholder */
  .rag-response__placeholder {
    padding: 1.2rem 1rem;
    font-size: 0.88rem;
  }

  /* Sources — full-width pills on narrow screens */
  .rag-sources {
    padding: 0.65rem 1rem;
  }
  .rag-sources__item a {
    font-size: 0.72rem;
    padding: 0.28rem 0.55rem;
  }

  /* Form — stack textarea + button vertically */
  .rag-form {
    flex-direction: column;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }
  .rag-form__input {
    width: 100%;
    font-size: 1rem;           /* 1rem prevents iOS auto-zoom on focus */
    rows: 3;
    padding: 0.65rem 0.85rem;
  }
  .rag-form__button {
    width: 100%;
    justify-content: center;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    min-height: 44px;          /* iOS HIG minimum tap target */
  }

  /* New conversation button — smaller */
  .rag-new-conv-btn {
    font-size: 0.72rem;
    padding: 0.28rem 0.6rem;
  }

  /* Error */
  .rag-error {
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
  }

  /* Reformulation notice */
  .rag-reformulation {
    font-size: 0.74rem;
    padding: 0.25rem 0.6rem;
    margin-top: 0.25rem;
  }

  /* Analytics toggle — full width on mobile */
  .rag-analytics-toggle {
    width: 100%;
  }
/*
  .rag-form__row {
    flex-direction: column;
    gap: 0.5rem;
  }
  .rag-form__hint {
    font-size: 0.71rem;
  }
*/
.rag-form__row {
    flex-direction: column;
    gap: 0.5rem;
  }
  .rag-form__hint {
    font-size: 0.71rem;
  }
}

/* ── Landscape phone (short viewport, wide) ────────────────────────────────── */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .rag-header__subtitle { display: none; }
  .rag-header           { padding: 0.45rem 1rem; }
  .rag-response         { min-height: 120px; }
}


/* ── Preset selector ─────────────────────────────────────────────────────────── */
.rag-presets {
  display: flex;
  gap: 0.4rem;
  padding: 0.55rem 1.25rem;
  background: var(--rag-surface);
  border-top: 1px solid var(--rag-border);
  flex-wrap: wrap;
  align-items: center;
}

.rag-preset__label {
  cursor: pointer;
  user-select: none;
}

.rag-preset__radio {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.rag-preset__pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--rag-border);
  border-radius: 20px;
  background: var(--rag-bg);
  color: var(--rag-text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.rag-preset__label:hover .rag-preset__pill {
  border-color: var(--rag-navy);
  color: var(--rag-navy);
}

.rag-preset__radio:checked + .rag-preset__pill {
  background: var(--rag-navy);
  border-color: var(--rag-navy);
  color: #fff;
}

.rag-preset__icon { font-size: 0.85em; line-height: 1; }

/* ── Locked preset (анонимни потребители) ────────────────────────────────────── */
.rag-preset__label--locked {
  cursor: not-allowed;
  position: relative;
}

.rag-preset__label--locked .rag-preset__pill {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.rag-preset__lock {
  font-size: 0.72em;
  margin-left: 0.2em;
  vertical-align: middle;
  opacity: 0.7;
}

/* CSS tooltip */
.rag-preset__label--locked::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.45;
  padding: 0.45rem 0.7rem;
  border-radius: 5px;
  white-space: nowrap;
  width: 220px;
  white-space: normal;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Стрелка надолу */
.rag-preset__label--locked::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1a1a2e;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 100;
}

.rag-preset__label--locked:hover::after,
.rag-preset__label--locked:hover::before {
  opacity: 1;
}

/* ── Timing indicator in route bar ──────────────────────────────────────────── */
.rag-route__timing {
  display: inline-flex;
  align-items: center;
  gap: 0.15em;
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--rag-text-muted);
  white-space: nowrap;
}
.rag-route__timing-total {
  font-weight: 400;
  color: var(--rag-border);
}

/* ── Extended Analytics toggle ───────────────────────────────────────────────
   Renders inline in the preset bar, after the preset pills.
   The checkbox itself is native — styled minimally to match institutional tone.
   ─────────────────────────────────────────────────────────────────────────── */
.rag-analytics-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-left: auto;           /* pushes to the right of the preset pills */
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--rag-border);
  border-radius: 20px;
  background: var(--rag-bg);
  color: var(--rag-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.rag-analytics-toggle:hover {
  border-color: #7c3aed;
  color: #5b21b6;
}

.rag-analytics-toggle input[type="checkbox"] {
  accent-color: #7c3aed;       /* purple tint — distinct from navy presets */
  cursor: pointer;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

/* Active state — checkbox checked */
.rag-analytics-toggle:has(input:checked) {
  border-color: #7c3aed;
  background: rgba(124, 58, 237, 0.06);
  color: #5b21b6;
}

/* ── Experimental badge ──────────────────────────────────────────────────────
   Small pill next to the label text.
   Purple palette to signal "not production-stable".
   ─────────────────────────────────────────────────────────────────────────── */
.rag-analytics-badge {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.3);
  border-radius: 3px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #6d28d9;
  line-height: 1.3;
  vertical-align: middle;
}

/* ── Responsive adjustments for preset bar ───────────────────────────────────── */
@media (max-width: 600px) {
  .rag-presets {
    padding: 0.5rem 1rem;
    gap: 0.35rem;
  }
  .rag-preset__pill {
    font-size: 0.74rem;
    padding: 0.28rem 0.6rem;
  }
  .rag-analytics-toggle {
    margin-left: 0;            /* no auto-margin on mobile — wraps naturally */
    font-size: 0.72rem;
  }
}


/* ── Quick disclaimer — full width below answer row ─────────────────────────── */
.rag-quick-disclaimer {
  margin: 0 1.5rem 0.75rem;
  padding: 0.4rem 0.75rem;
  background: rgba(249, 202, 36, 0.1);
  border-left: 3px solid #f9ca24;
  border-radius: 0 3px 3px 0;
  font-size: 0.78rem;
  color: var(--rag-text-muted);
  font-style: italic;
  clear: both;
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.rag-footer {
  padding: 0.65rem 1.25rem 0.75rem;
  border-top: 1px solid var(--rag-border);
  background: var(--rag-surface);
  flex-shrink: 0;
}

.rag-footer p {
  margin: 0 0 0.25rem;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--rag-text-muted);
}
.rag-footer p:last-child { margin-bottom: 0; }

.rag-footer a {
  color: var(--rag-navy);
  text-decoration: none;
}
.rag-footer a:hover { text-decoration: underline; }

.rag-footer__disclaimer {
  font-style: italic;
}

@media (max-width: 600px) {
  .rag-footer         { padding: 0.55rem 1rem 0.65rem; }
  .rag-footer p       { font-size: 0.7rem; }
  .rag-quick-disclaimer { margin: 0 1rem 0.6rem; }
}

/* ── Avatar menu ─────────────────────────────────────────────────────────── */
.rag-avatar-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.rag-avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #003366;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  border: 2px solid rgba(255,255,255,0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.15s;
  flex-shrink: 0;
}
.rag-avatar-btn:hover { background: #00509e; }
.rag-avatar-pro {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #f59e0b;
  color: #000;
  font-size: 0.45rem;
  font-weight: 800;
  padding: 1px 3px;
  border-radius: 3px;
  letter-spacing: 0.03em;
}
.rag-avatar-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 200px;
  z-index: 1000;
  overflow: hidden;
}
.rag-avatar-menu.is-open { display: block; }
.rag-avatar-menu__header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rag-avatar-menu__name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rag-avatar-menu__tier {
  font-size: 0.72rem;
  color: #9ca3af;
}
.rag-avatar-menu__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.82rem;
  color: #374151;
  background: none;
  border: 2px solid rgba(255,255,255,0.6);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}
.rag-avatar-menu__item:hover { background: #f9fafb; }
.rag-avatar-menu__item.is-danger { color: #dc2626; }
.rag-avatar-menu__item.is-danger:hover { background: #fef2f2; }
.rag-avatar-menu__divider {
  height: 1px;
  background: #f3f4f6;
  margin: 2px 0;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   FEEDBACK UI
   2026-03-28 — Inline feedback bar + modal dialog
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Feedback bar — рендерира се под последния .rag-qa-block ─────────────────── */
.rag-feedback-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1.5rem 0.7rem;
  animation: rag-fade-in 0.2s ease;
}

.rag-feedback-bar__label {
  font-size: 0.78rem;
  color: var(--rag-text-muted);
  flex-shrink: 0;
}

/* Thumbs buttons в bar-а */
.rag-feedback-btn {
  background: none;
  border: 1px solid var(--rag-border);
  border-radius: var(--rag-radius);
  padding: 0.3rem 0.65rem;
  cursor: pointer;
  line-height: 0;              /* SVG vertical alignment */
  color: var(--rag-text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rag-feedback-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}
.rag-feedback-btn:hover {
  background: var(--rag-navy-dim);
  border-color: var(--rag-navy);
  color: var(--rag-navy);
  transform: scale(1.12);
}
.rag-feedback-btn:active { transform: scale(0.95); }

/* Потвърдено изпратен feedback — показва само текст */
.rag-feedback-bar.is-done .rag-feedback-bar__label {
  color: var(--rag-navy);
  font-weight: 600;
}

@media (max-width: 600px) {
  .rag-feedback-bar {
    padding: 0.4rem 1rem 0.6rem;
  }
  .rag-feedback-bar__label {
    font-size: 0.74rem;
  }
}

/* ── Feedback modal ───────────────────────────────────────────────────────────
   Прикачен към <body>, позициониран фиксирано.
   Показва се/скрива с .is-open клас.
   ─────────────────────────────────────────────────────────────────────────── */
.rag-feedback-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: rag-fade-in 0.15s ease;
}
.rag-feedback-modal.is-open {
  display: flex;
}

.rag-feedback-modal__box {
  background: var(--rag-bg);
  border-radius: 8px;
  padding: 1.75rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  animation: rag-modal-in 0.18s ease;
}

@keyframes rag-modal-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)     scale(1);    }
}

.rag-feedback-modal__title {
  margin: 0 0 1.1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--rag-navy);
  font-family: var(--rag-font);
}

/* Rating бутони (Helpful / Not helpful) */
.rag-feedback-modal__rating {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.rag-feedback-modal__btn {
  flex: 1;
  padding: 0.55rem 1rem;
  border: 2px solid var(--rag-border);
  border-radius: var(--rag-radius);
  background: var(--rag-bg);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--rag-font);
  color: var(--rag-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.rag-feedback-modal__btn svg {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}
.rag-feedback-modal__btn:hover {
  border-color: var(--rag-navy);
  background: var(--rag-blue-light);
  color: var(--rag-navy);
}
/* Избран рейтинг */
.rag-feedback-modal__btn.is-active {
  border-color: var(--rag-navy);
  background: var(--rag-navy);
  color: #fff;
}

/* Comment textarea */
.rag-feedback-modal__textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--rag-border);
  border-radius: var(--rag-radius);
  font-family: var(--rag-font);
  font-size: 0.85rem;
  color: var(--rag-text);
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.2s;
  outline: none;
}
.rag-feedback-modal__textarea:focus {
  border-color: var(--rag-navy);
}
.rag-feedback-modal__textarea::placeholder {
  color: var(--rag-text-muted);
}

/* Character counter */
.rag-feedback-modal__charcount {
  font-size: 0.72rem;
  color: var(--rag-text-muted);
  text-align: right;
  margin-top: 0.2rem;
  margin-bottom: 0.5rem;
  min-height: 1em;
}

/* Error message */
.rag-feedback-modal__error {
  font-size: 0.8rem;
  color: var(--rag-red);
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

/* Action buttons row */
.rag-feedback-modal__actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.25rem;
}

.rag-feedback-modal__cancel {
  padding: 0.45rem 1rem;
  border: 1px solid var(--rag-border);
  border-radius: var(--rag-radius);
  background: var(--rag-bg);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--rag-font);
  color: var(--rag-text);
  transition: background 0.15s, border-color 0.15s;
}
.rag-feedback-modal__cancel:hover {
  background: var(--rag-surface);
  border-color: var(--rag-text-muted);
}

.rag-feedback-modal__submit {
  padding: 0.45rem 1.25rem;
  border: none;
  border-radius: var(--rag-radius);
  background: var(--rag-navy);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: var(--rag-font);
  letter-spacing: 0.03em;
  transition: background 0.15s, opacity 0.15s;
  opacity: 0.45;
}
.rag-feedback-modal__submit:not(:disabled) {
  opacity: 1;
  cursor: pointer;
}
.rag-feedback-modal__submit:not(:disabled):hover {
  background: var(--rag-navy-light);
}
.rag-feedback-modal__submit:disabled {
  cursor: not-allowed;
}

@media (max-width: 600px) {
  .rag-feedback-modal__box {
    padding: 1.25rem;
  }
  .rag-feedback-modal__rating {
    flex-direction: column;
    gap: 0.5rem;
  }
  .rag-feedback-modal__actions {
    flex-direction: column-reverse;
    gap: 0.5rem;
  }
  .rag-feedback-modal__cancel,
  .rag-feedback-modal__submit {
    width: 100%;
    text-align: center;
    padding: 0.65rem 1rem;
    min-height: 44px;
  }
}