/* Reset — единственное, что касается body. Остальное под .cqa-app (Dynamics 365). */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: #F6F7F9; }

.cqa-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.cqa-app h1, .cqa-app h2, .cqa-app h3 { margin: 0; color: var(--text); }
/* :where() — нулевая специфичность, чтобы классы кнопок (.cqa-btn--text и т.п.) задавали цвет */
.cqa-app :where(button, input, select) { font: inherit; color: inherit; }
.cqa-app .num { font-variant-numeric: tabular-nums; }
.cqa-app .sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Единое кольцо фокуса: 2px зелёный с отступом 2px */
.cqa-app :focus { outline: none; }
.cqa-app :focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ================= Сайдбар ================= */
.cqa-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 10px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 5;
}

.cqa-sidebar__logo {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 14px;
  border-radius: var(--radius);
  transition: background-color 150ms ease;
}
.cqa-sidebar__logo img { width: 38px; height: 38px; display: block; }
.cqa-sidebar__logo:hover { background: var(--surface-hover); }

.cqa-sidebar__nav { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; }
.cqa-sidebar__bottom { margin-top: auto; display: flex; flex-direction: column; align-items: center; width: 100%; gap: 10px; }
.cqa-sidebar__divider { width: 44px; height: 1px; margin: 8px 0; background: var(--border); border: 0; flex-shrink: 0; }

.cqa-nav-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 76px;
  min-height: 62px;
  padding: 9px 2px 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-body);
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}
.cqa-nav-item .cqa-icon { width: 22px; height: 22px; flex-shrink: 0; }
.cqa-nav-item__label { display: block; white-space: nowrap; letter-spacing: -0.01em; }
.cqa-nav-item:hover { background: var(--surface-hover); }

.cqa-nav-item.is-active {
  background: var(--surface);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
  color: var(--text);
}
.cqa-nav-item.is-active .cqa-nav-item__label { font-weight: 600; }
.cqa-nav-item.is-active .cqa-icon { color: var(--nav-active-icon); }

.cqa-nav-item[aria-disabled="true"] { color: var(--text-muted); cursor: default; }
.cqa-nav-item[aria-disabled="true"]:hover { background: transparent; }

.cqa-nav-item__icon { position: relative; display: inline-flex; }
.cqa-badge-count {
  position: absolute;
  top: -7px;
  left: 13px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bad);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--bg);
}
.cqa-badge-count[hidden] { display: none; }

.cqa-tooltip {
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
  z-index: 10;
}
.cqa-nav-item:hover .cqa-tooltip,
.cqa-nav-item:focus-visible .cqa-tooltip { opacity: 1; }

/* Роль: подпись «Роль» + вертикальный сегмент из двух вариантов (иконка над подписью) */
.cqa-role { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 84px; }
.cqa-role__label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.cqa-role__seg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}
.cqa-role__opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 7px 0 6px;
  border: 0;
  border-radius: calc(var(--radius) - 3px);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}
.cqa-role__opt .cqa-icon { width: 14px; height: 14px; }
.cqa-role__opt:hover { color: var(--text); background: var(--surface-hover); }
.cqa-role__opt[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.035em;
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
  cursor: default;
}
.cqa-role__opt[aria-checked="true"][data-role="operator"] .cqa-icon { color: var(--brand-700); }
.cqa-role__opt[aria-checked="true"][data-role="reviewer"] .cqa-icon { color: var(--info); }

/* ================= Контент ================= */
.cqa-main { min-width: 0; padding: 32px 40px 48px; }
.cqa-page { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

/* Карточка: тонкая цветная полоска сверху (--card-accent, по умолчанию фирменный градиент),
   серая рамка по бокам и мягкая тень. Полоска нарисована фоном, поэтому повторяет скругление
   и её не перекрывают шапки внутри карточки. */
.cqa-card {
  --card-accent: var(--brand-gradient);
  --card-line: #E1E5EA;
  border: 1px solid transparent;
  border-top-width: 3px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--card-accent) top / 100% 3px no-repeat border-box,
    linear-gradient(var(--card-line), var(--card-line)) border-box;
  box-shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
}
/* Карточка внутри карточки — без полоски и тени */
.cqa-card .cqa-card {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: none;
}
.cqa-card--pad { padding: 24px; }
.cqa-muted { color: var(--text-secondary); }

/* ================= Кнопки и поля ================= */
.cqa-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}
.cqa-btn .cqa-icon { width: 16px; height: 16px; }
.cqa-btn:disabled { cursor: not-allowed; opacity: .55; }

.cqa-btn--primary { background: var(--brand-500); color: #fff; }
.cqa-btn--primary:hover:not(:disabled) { background: var(--brand-600); }

.cqa-btn--ghost { background: var(--surface); border-color: var(--border-control); color: var(--text); }
.cqa-btn--ghost:hover:not(:disabled) { background: var(--surface-2); border-color: #D5D9DF; }

.cqa-btn--text { height: auto; padding: 0 4px; color: var(--brand-700); }
.cqa-btn--text:hover:not(:disabled) { color: var(--brand-500); }

.cqa-btn--sm { height: 30px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.cqa-btn--outline { background: var(--surface); border-color: var(--brand-border); color: var(--brand-700); }
.cqa-btn--outline:hover:not(:disabled) { background: var(--brand-50); border-color: #C6E2C6; }

.cqa-spin { animation: cqa-spin 0.9s linear infinite; }
@keyframes cqa-spin { to { transform: rotate(360deg); } }

/* ================= Уведомления ================= */
.cqa-toasts {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 48px));
}
.cqa-toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-bar);
  animation: cqa-toast-in 150ms ease;
}
.cqa-toast--error { background: #7F1D1D; }
@keyframes cqa-toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  .cqa-app *, .cqa-toast { transition: none !important; animation-duration: 0.01ms !important; }
  .cqa-spin { animation: cqa-spin 1.8s linear infinite !important; }
}

@media (max-width: 900px) {
  .cqa-main { padding: 24px 20px 40px; }
}

/* ---------- Объяснение пересчёта итога (components/score-explain.js) ---------- */
.cqa-app .sx { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--border-inner); border-radius: var(--radius); background: var(--surface-2); font-size: 13px; }
.cqa-app .sx--compact { color: var(--text-body); }
.cqa-app .sx__head { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.cqa-app .sx__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cqa-app .sx__row { display: grid; grid-template-columns: minmax(0, 1fr) auto 72px; gap: 12px; align-items: baseline; color: var(--text-body); }
.cqa-app .sx__row--muted { color: var(--text-secondary); }
.cqa-app .sx__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cqa-app .sx__num { display: inline-block; min-width: 22px; color: var(--text-muted); }
.cqa-app .sx__ans { white-space: nowrap; }
.cqa-app .sx__val { text-align: right; font-weight: 600; }
.cqa-app .sx-delta--up { color: var(--ok); }
.cqa-app .sx-delta--down { color: var(--bad); }
.cqa-app .sx-delta--zero { color: var(--text-secondary); }

/* ================= Мобильная версия (≤ 640px) =================
   Сайдбар → верхняя шапка (логотип + роль, уезжает при прокрутке) и нижняя таб-панель (разделы).
   Работает и в браузере телефона, и в Telegram Mini App ([data-tg="1"]). Десктоп не затронут. */
/* Меню «Ещё» нижней панели — только на телефоне */
.cqa-app .cqa-nav-more, .cqa-app .cqa-nav-sheet { display: none; }
.cqa-app button.cqa-nav-item { border: 0; background: transparent; font-family: inherit; cursor: pointer; }

@media (max-width: 640px) {
  .cqa-app {
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
  }

  /* Шапка: логотип слева, роль справа */
  .cqa-sidebar {
    position: static;
    min-height: 0;
    height: calc(var(--m-topbar-h) + env(safe-area-inset-top, 0px));
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: env(safe-area-inset-top, 0px) var(--m-gutter) 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .cqa-sidebar__logo { width: 44px; height: 44px; margin: 0 0 0 -6px; }
  .cqa-sidebar__logo img { width: 32px; height: 32px; }
  .cqa-sidebar__bottom { margin: 0; width: auto; }
  .cqa-sidebar__divider, .cqa-role__label { display: none; }
  .cqa-role { width: auto; }
  .cqa-role__seg { flex-direction: row; width: auto; }
  .cqa-role__opt {
    flex-direction: row;
    gap: 6px;
    width: auto;
    min-height: 36px;
    padding: 0 12px;
    font-size: 13px;
    letter-spacing: -0.01em;
  }
  .cqa-role__opt[aria-checked="true"] { letter-spacing: -0.01em; }
  /* Невидимое расширение тач-цели до 44px по высоте */
  .cqa-role__opt { position: relative; }
  .cqa-role__opt::after { content: ""; position: absolute; inset: -4px 0; }

  /* Нижняя таб-панель */
  .cqa-sidebar__nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding: 0 4px var(--m-safe-bottom);
    background: rgba(255, 255, 255, .96);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(16, 24, 40, .04);
  }
  @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .cqa-sidebar__nav { background: rgba(255, 255, 255, .86); -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px); }
  }
  .cqa-nav-item {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: var(--m-tabbar-h);
    gap: 3px;
    padding: 8px 0 6px;
    border-radius: 0;
    font-size: 10.5px;
    color: var(--text-secondary);
  }
  .cqa-nav-item:hover { background: transparent; }
  .cqa-nav-item.is-active { background: transparent; box-shadow: none; color: var(--text); }
  .cqa-nav-item__icon { padding: 3px 14px; border-radius: 999px; transition: background-color 150ms ease; }
  .cqa-nav-item.is-active .cqa-nav-item__icon { background: var(--brand-50); }
  .cqa-nav-item__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .cqa-nav-item[aria-disabled="true"] { color: var(--text-muted); opacity: .7; }
  .cqa-badge-count { top: -3px; left: 30px; box-shadow: 0 0 0 2px var(--surface); }
  .cqa-app .cqa-nav-item--more { display: none; }
  .cqa-app .cqa-nav-more { display: flex; }
  .cqa-app .cqa-nav-more.is-active, .cqa-app .cqa-nav-more[aria-expanded="true"] { color: var(--text); }
  .cqa-app .cqa-nav-more.is-active .cqa-nav-item__icon { background: var(--brand-50); }
  .cqa-app .cqa-nav-sheet:not([hidden]) {
    position: fixed; right: 8px; bottom: calc(var(--m-tabbar-h) + var(--m-safe-bottom) + 8px); z-index: 31;
    display: flex; flex-direction: column; min-width: 280px; padding: 6px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  }
  .cqa-app .cqa-nav-sheet__item {
    display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-sm);
    font-size: 15px; color: var(--text); text-decoration: none;
  }
  .cqa-app .cqa-nav-sheet__item .cqa-icon { color: var(--text-secondary); }
  .cqa-app .cqa-nav-sheet__item.is-active { background: var(--brand-50); font-weight: 600; }
  .cqa-app .cqa-nav-sheet__item.is-active .cqa-icon { color: var(--nav-active-icon); }
  .cqa-app .cqa-nav-sheet__item[aria-disabled="true"] { color: var(--text-muted); }
  .cqa-app .cqa-nav-sheet__lock { margin-left: auto; font-size: 11.5px; color: var(--text-muted); }
  .cqa-app .cqa-nav-sheet__item:not([aria-disabled="true"]) .cqa-nav-sheet__lock { display: none; }
  .cqa-tooltip { display: none; }

  /* Контент */
  .cqa-main { padding: 16px var(--m-gutter) calc(var(--m-bottom-space) + 24px); }
  .cqa-page { gap: 16px; }
  .cqa-card--pad { padding: 16px; }
  .cqa-btn { min-height: 44px; }
  .cqa-btn--sm { min-height: 36px; }
  .cqa-btn--text { min-height: 0; }

  /* Тосты — на всю ширину, над таб-панелью */
  .cqa-toasts { left: var(--m-gutter); right: var(--m-gutter); bottom: calc(var(--m-bottom-space) + 12px); max-width: none; z-index: 60; }
  .cqa-toast { font-size: 14px; }

  .cqa-app .cqa-icon-btn { width: 44px; height: 44px; }
}

/* Telegram Mini App: высота окна задаётся Telegram — без 100vh, только dvh/min-height */
.cqa-app[data-tg="1"] { min-height: 100dvh; }

/* Подсказка при наведении/фокусе (ui/tooltip.js, атрибут data-tip) */
.cqa-app .cqa-tip {
  position: fixed;
  z-index: 10000;
  max-width: 320px;
  padding: 5px 9px;
  border-radius: var(--radius-xs);
  background: var(--text);
  color: #fff;
  font: 500 12px/16px var(--font);
  letter-spacing: 0;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 120ms ease, transform 120ms ease;
  box-shadow: 0 4px 12px rgba(16, 24, 40, .18);
}
.cqa-app .cqa-tip.is-on { opacity: 1; transform: none; }
.cqa-app .cqa-tip[hidden] { display: none; }
@media (hover: none) { .cqa-app .cqa-tip { display: none; } }
