/* Складові гайдбука Fregat 0.4.5 для екранів CRM: вкладки й сегменти, що ковзають, порожні стани з Фрегатиком, плитки
   підсумків, вікна (аудит docs/ui/guidebook-audit.md, P1-3, P1-5, P2-1, P2-2). Підключено останнім — правила тут перемагають.
   Розмітку дають помічники js/kit.js. Еталон значень — Портал 2.2 (css/portal-ui.css); у CRM нема Tailwind, тож без !important.
   Рух вимикають обидва вимикачі гайдбука (розділ 20): особистий «Анімації» (html[data-anim="off"]) і prefers-reduced-motion. */

/* ── 1. Ковзні перемикачі (гайдбук 7) — Портал 9–54 ──────────────────────────────────────────────────────────────
   Відмінності від Порталу: неактивна вкладка — #4b5563 (порталівський #6b7280 на тлі сторінки дає 4.39); лічильник — усередині кнопки. */
.pt-tabs { position: relative; scrollbar-width: none; isolation: isolate; }
.pt-tabs::-webkit-scrollbar { display: none; }
.pt-ind { position: absolute; left: 0; top: 0; z-index: 0; width: 0; height: 0; pointer-events: none; opacity: 0; will-change: transform, width;
  transition: transform .42s cubic-bezier(.34, 1.32, .5, 1), width .42s cubic-bezier(.34, 1.32, .5, 1), height .3s ease, opacity .2s ease; }
.pt-ind.pt-now, html[data-anim="off"] .pt-ind { transition: none; }
@media (prefers-reduced-motion: reduce) { .pt-ind { transition: none; } }

/* вкладки розділу: текст, лінія 2 px під обраною, сіра межа під усім рядом */
.pt-line { display: flex; flex-wrap: nowrap; gap: 4px; overflow-x: auto; overflow-y: hidden; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.pt-line > button { position: relative; z-index: 1; flex: 0 0 auto; margin: 0; padding: 10px 16px; border: 0; border-radius: 0; background: transparent;
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1.35; white-space: nowrap; color: #4b5563; cursor: pointer;
  transition: color .25s ease; -webkit-tap-highlight-color: transparent; }
html.dark .pt-line > button { color: #9ca3af; }
.pt-line > button:hover { color: #374151; }
html.dark .pt-line > button:hover { color: #e5e7eb; }
.pt-line > .pt-on, .pt-line > .pt-on:hover { color: #7c3aed; }
html.dark .pt-line > .pt-on, html.dark .pt-line > .pt-on:hover { color: #c4b5fd; }
.pt-line > .pt-ind { border-radius: 2px; background: linear-gradient(90deg, #a78bfa, #7c3aed); box-shadow: 0 0 10px rgba(139, 92, 246, .55); }
/* вкладки всередині картки: від країв картки — як вміст, межа під рядом — та сама, що в шапки картки */
.card > .pt-line { margin: 0; padding: 4px 12px 0; }

/* сегменти: «таблетка» на фіолетовій доріжці */
.pt-seg { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 100%; padding: 4px; border-radius: 14px; vertical-align: top;
  background: linear-gradient(180deg, rgba(139, 92, 246, .10), rgba(99, 102, 241, .07)); box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .2); }
html.dark .pt-seg { background: rgba(15, 12, 35, .65); box-shadow: inset 0 0 0 1px rgba(167, 139, 250, .18); }
.pt-seg > button { position: relative; z-index: 1; flex: 0 0 auto; margin: 0; padding: 6px 14px; border: 0; border-radius: 10px; background: transparent;
  font: inherit; font-size: 13px; font-weight: 600; line-height: 1.35; white-space: nowrap; color: #4b5563; cursor: pointer;
  transition: color .25s ease; -webkit-tap-highlight-color: transparent; }
html.dark .pt-seg > button { color: #9ca3af; }
.pt-seg > button:hover { color: #374151; }
html.dark .pt-seg > button:hover { color: #e5e7eb; }
.pt-seg > .pt-on, .pt-seg > .pt-on:hover { color: #6d28d9; }
html.dark .pt-seg > .pt-on, html.dark .pt-seg > .pt-on:hover { color: #f5f3ff; }
.pt-seg > .pt-ind { border-radius: 10px; background: #fff;
  box-shadow: 0 1px 2px rgba(76, 29, 149, .12), 0 4px 14px -4px rgba(124, 58, 237, .35), inset 0 0 0 1px rgba(139, 92, 246, .28); }
html.dark .pt-seg > .pt-ind { background: linear-gradient(135deg, rgba(139, 92, 246, .42), rgba(99, 102, 241, .3));
  box-shadow: 0 4px 16px -4px rgba(139, 92, 246, .6), inset 0 0 0 1px rgba(196, 181, 253, .35); }
.pt-seg.pt-solid > .pt-on, html.dark .pt-seg.pt-solid > .pt-on { color: #fff; }
.pt-seg.pt-solid > .pt-ind { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 4px 14px -4px rgba(124, 58, 237, .7); }
.pt-tabs > button:focus-visible { outline: 2px solid #8b5cf6; outline-offset: -2px; }

/* лічильник — усередині кнопки; в обраній — фіолетовий на мʼякому (7.10, був білий .7 на #7c3aed — 3.58) */
.pt-n { display: inline-block; margin-left: 7px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 700; line-height: 1.6;
  font-variant-numeric: tabular-nums; background: rgba(148, 163, 184, .2); color: #374151; }
.pt-on .pt-n { background: rgba(139, 92, 246, .14); color: #6d28d9; }
html.dark .pt-n { background: rgba(148, 163, 184, .16); color: #e5e7eb; }
html.dark .pt-on .pt-n { background: rgba(139, 92, 246, .28); color: #ede9fe; }
@media (max-width: 640px) { .pt-line > button { padding: 10px 12px; } .pt-seg > button { padding: 6px 11px; } }

/* фільтри «кілька разом» — «таблетка з галочкою» (Портал 653–667); справжній прапорець лишається для клавіатури */
.chk { position: relative; display: inline-flex; flex: none; cursor: pointer; }
.chk > input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chk > span { display: inline-flex; align-items: center; gap: 7px; min-height: 40px; box-sizing: border-box; padding: 7px 13px 7px 9px; border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1.2; white-space: nowrap; color: #4b5563; background: #f3f4f6; box-shadow: inset 0 0 0 1px #e5e7eb;
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease; user-select: none; -webkit-user-select: none; }
.chk > span::before { content: ''; flex: none; width: 16px; height: 16px; border-radius: 50%; background: #fff center / 10px 10px no-repeat;
  box-shadow: inset 0 0 0 1.5px #9ca3af; transition: background-color .15s ease, box-shadow .15s ease; }
.chk:hover > span { background: #ebe9fe; }
.chk > input:checked + span { color: #5b21b6; background: #ede9fe; box-shadow: inset 0 0 0 1px #c4b5fd; }
.chk > input:checked + span::before { background-color: #7c3aed; box-shadow: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.3l2.3 2.3 4.7-5'/%3E%3C/svg%3E"); }
.chk > input:focus-visible + span { outline: 2px solid #8b5cf6; outline-offset: 2px; }
html.dark .chk > span { color: #d1d5db; background: rgba(148, 163, 184, .12); box-shadow: inset 0 0 0 1px rgba(148, 163, 184, .26); }
html.dark .chk > span::before { background-color: transparent; box-shadow: inset 0 0 0 1.5px #6b7280; }
html.dark .chk:hover > span { background: rgba(139, 92, 246, .16); }
html.dark .chk > input:checked + span { color: #ede9fe; background: rgba(139, 92, 246, .28); box-shadow: inset 0 0 0 1px rgba(167, 139, 250, .55); }
html.dark .chk > input:checked + span::before { background-color: #8b5cf6; box-shadow: none; }

/* стан «увімкнено / вимкнено» в рядку — вимикач Порталу (portal-fx.css 157–162) і слово поруч */
.sw-row { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.sw-word { font-size: 13px; font-weight: 600; color: var(--muted); }
.fx-switch { position: relative; flex-shrink: 0; width: 44px; height: 26px; padding: 0; border: 0; border-radius: 999px; cursor: pointer;
  background: #d1d5db; transition: background-color .2s ease; }
html.dark .fx-switch { background: #4b5563; }
.fx-switch > i { position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s cubic-bezier(.3, 1.4, .5, 1); }
.fx-switch[aria-checked="true"], html.dark .fx-switch[aria-checked="true"] { background: #8b5cf6; }
.fx-switch[aria-checked="true"] > i { transform: translateX(18px); }
.fx-switch[aria-checked="true"] + .sw-word { color: var(--text); }
.fx-switch:disabled { cursor: progress; }
.fx-switch:focus-visible { outline: 2px solid #a78bfa; outline-offset: 2px; }
html[data-anim="off"] :is(.chk > span, .chk > span::before, .fx-switch, .fx-switch > i, .pt-tabs > button) { transition: none; }
@media (prefers-reduced-motion: reduce) { :is(.chk > span, .chk > span::before, .fx-switch, .fx-switch > i, .pt-tabs > button) { transition: none; } }

/* ── 2. Порожній стан (гайдбук 17) — .pe Порталу 236–249; малюнок — Фрегатик CRM (fregatik.js) ───────────────────── */
.pe { max-width: 520px; margin: 18px auto; padding: 20px 26px 24px; text-align: center; border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(250, 245, 255, .9)); border: 1.5px dashed #d8b4fe; }
html.dark .pe { background: linear-gradient(180deg, rgba(31, 41, 55, .7), rgba(46, 16, 101, .25)); border-color: rgba(167, 139, 250, .4); }
.pe-pic { display: flex; justify-content: center; }
.pe-pic .frg-svg { width: 118px; height: auto; display: block; margin: 0 auto 6px; }
.pe-tx { min-width: 0; }
.pe-t { margin: 0; font-size: 17px; font-weight: 800; line-height: 1.3; color: var(--text); }
.pe-s { margin: 6px auto 0; max-width: 400px; font-size: 13.5px; line-height: 1.45; color: var(--muted); overflow-wrap: anywhere; }
.pe .btn { margin-top: 12px; }
.pe.pe-sm { display: flex; align-items: center; gap: 14px; max-width: 460px; padding: 12px 18px; text-align: left; border-radius: 16px; }
.pe.pe-sm .pe-pic .frg-svg { width: 62px; margin: 0; }
.pe.pe-sm .pe-pic { flex: none; }
.pe.pe-sm .pe-t { font-size: 14.5px; }
.pe.pe-sm .pe-s { margin: 3px 0 0; font-size: 12.5px; }
.pe.pe-sm .btn { margin-top: 8px; }
.pe.pe-plain { max-width: 460px; margin: 12px auto; padding: 12px 18px; border-radius: 14px; }
.pe.pe-plain .pe-t { font-size: 14px; font-weight: 600; color: var(--muted); }
.pe.pe-plain .pe-s { margin-top: 3px; font-size: 12.5px; }
td > .pe, .card-body > .pe:only-child { margin-top: 6px; margin-bottom: 6px; }
html[data-anim="off"] .pe-pic * { animation: none !important; }
@media (prefers-reduced-motion: reduce) { .pe-pic * { animation: none !important; } }

/* ── 3. Плитки підсумків (гайдбук 8) — Портал 76–99; поверхня й межа — токенами, щоб темна тема була своя ────────── */
.pk-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card-body > .pk-kpis:last-child { margin-bottom: 0; }
.pk-kpi { --tint: 139, 92, 246; position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; padding: 14px 16px; border-radius: 16px;
  text-align: left; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 10px 24px -14px rgba(15, 23, 42, .3);
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), box-shadow .25s, border-color .25s; }
html.dark .pk-kpi { box-shadow: 0 10px 24px -14px rgba(0, 0, 0, .7); }
.pk-kpi[data-tint="blue"] { --tint: 59, 130, 246; } .pk-kpi[data-tint="sky"] { --tint: 14, 165, 233; } .pk-kpi[data-tint="amber"] { --tint: 245, 158, 11; }
.pk-kpi[data-tint="green"] { --tint: 34, 197, 94; } .pk-kpi[data-tint="red"] { --tint: 239, 68, 68; } .pk-kpi[data-tint="gray"] { --tint: 100, 116, 139; }
.pk-kpi::after { content: ''; position: absolute; inset: auto -30% -70% auto; width: 70%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(var(--tint), .16), transparent); pointer-events: none; }
.pk-kpi:hover { transform: translateY(-2px); border-color: rgba(var(--tint), .5); box-shadow: 0 16px 30px -16px rgba(var(--tint), .55); }
.pk-kpi-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pk-kpi-ico { flex-shrink: 0; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; font-size: 14px; line-height: 1;
  background: rgba(var(--tint), .16); color: rgb(var(--tint)); }
.pk-kpi-ico .ic svg { width: 16px; height: 16px; }
.pk-kpi-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); }
.pk-kpi-num { margin-top: 8px; font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.pk-kpi-num.pk-kpi-txt { font-size: 19px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.pk-kpi[data-tint="red"] .pk-kpi-num:not(.pk-kpi-txt) { color: var(--danger); }
.pk-kpi-sub { margin-top: 2px; min-height: 16px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .pk-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .pk-kpi { padding: 12px 13px; } .pk-kpi-num { font-size: 24px; } }
html[data-anim="off"] .pk-kpi { transition: none; }
html[data-anim="off"] .pk-kpi:hover { transform: none; }
@media (prefers-reduced-motion: reduce) { .pk-kpi { transition: none; } .pk-kpi:hover { transform: none; } }

/* ── 4. Вікна (гайдбук 11, 12): поля з мітками одне під одним, пояснення над полями ─────────────────────────────── */
.modal-card .field + .field, .modal-card .field + .form-row, .modal-card .form-row + .field { margin-top: 10px; }
.modal-lead { margin: 0 0 12px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.field > .meta { font-size: 12px; color: var(--muted); }
.field-pair { display: flex; gap: 8px; }
.field-pair > * { flex: 1 1 0; min-width: 0; }
/* окрема дія ліворуч у низу вікна («Вимкнути доступ»), «Скасувати» й головна — праворуч */
.modal-actions > .ma-left { margin-right: auto; }
/* небезпечна «мʼяка» кнопка звичайного розміру — Портал 627, 629 (мала — .btn.sm.danger) */
.btn.danger-soft { background: #fee2e2; color: #b91c1c; box-shadow: none; }
.btn.danger-soft:hover { background: #fecaca; }
html.dark .btn.danger-soft { background: rgba(220, 38, 38, .2); color: #fca5a5; }
html.dark .btn.danger-soft:hover { background: rgba(220, 38, 38, .3); }

/* ── 5. Повідомлення (гайдбук 15) — ширина й «довідка» (Портал 458–462) ─────────────────────────────────────────── */
.toast { max-width: min(380px, calc(100vw - 32px)); align-items: flex-start; }
.toast-t { min-width: 0; padding-top: 2px; overflow-wrap: anywhere; }

/* ── 6. Палітра емодзі в картці клієнта — випадне меню (гайдбук 14): поверхня, радіус 14, межа, тінь меню, поява .18 с ── */
.emoji-palette { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-menu); box-shadow: var(--shadow-menu);
  transform-origin: top left; }
.emoji-palette.open { animation: kitMenuIn .18s cubic-bezier(.2, .8, .2, 1) both; }
.emoji-palette .emoji-btn { border-radius: 9px; }
.emoji-palette .emoji-btn:hover, .emoji-palette .emoji-btn:focus-visible { background: rgba(139, 92, 246, .1); border-color: transparent; outline: none; }
.emoji-palette .emoji-reset { flex-basis: 100%; margin-top: 4px; justify-content: center; }
@keyframes kitMenuIn { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
html[data-anim="off"] .emoji-palette.open { animation: none; }
@media (prefers-reduced-motion: reduce) { .emoji-palette.open { animation: none; } }

/* ── 7. Шапка сторінки-деталі (гайдбук 6) і аватар людини (аудит P2-10) ──────────────────────────────────────────── */
.ph-back { width: 40px; height: 40px; padding: 0; justify-content: center; flex: none; }
.ph-back svg { width: 20px; height: 20px; }
.ph-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.page-head .ph-titles h1 { overflow-wrap: anywhere; }
/* аватар: кружечок 30 px у списках, 48 px у шапці картки (радіус 15, як плитка розділу) — раніше без .who був прозорим квадратом */
.avatar { position: relative; display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-soft-ink); font-weight: 700; line-height: 1; }
.avatar-lg { width: 48px; height: 48px; font-size: 24px; border-radius: 15px; }
button.avatar { padding: 0; border: 0; font: inherit; font-weight: 700; cursor: pointer; }
.avatar-lg:is(button) { font-size: 24px; }
button.avatar:focus-visible { outline: 2px solid #8b5cf6; outline-offset: 2px; }
.avatar-lg .online-dot { right: -2px; bottom: -2px; }

/* ── 8. Значки в тексті й кнопках (гайдбук 4), кнопка-посилання, прапорець у рядку ─────────────────────────────────── */
.ic { display: inline-flex; flex: none; align-items: center; justify-content: center; vertical-align: -3px; }
.ic svg { width: 16px; height: 16px; }
.btn .ic svg { width: 18px; height: 18px; }
.btn.sm .ic svg { width: 16px; height: 16px; }
.btn.icon-only { padding-left: 0; padding-right: 0; width: 40px; justify-content: center; }
.btn.sm.icon-only { width: 32px; }
/* кнопка-посилання (аудит P3-29): колір, тло й рамку дає .link з app.css; тут — лише значок поруч із текстом */
button.link { display: inline-flex; align-items: center; gap: 4px; text-align: left; }
button.link:focus-visible { outline: 2px solid #8b5cf6; outline-offset: 2px; border-radius: 4px; }
.link.ic-only { vertical-align: -3px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; font-size: 14px; }
.check-row input { flex: none; width: 16px; height: 16px; margin: 0; }
.dot-only { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
/* тип заявки в рядку таблиці — мала плитка 22 px замість емодзі (поруч із назвою в .ic-line) */
.mini-tile { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 22px; height: 22px; border-radius: 7px; }
.mini-tile::before { display: none; }
.mini-tile svg { width: 13px; height: 13px; }
/* картка-деталь на дві колонки: ліва може стиснутись (широка таблиця гортається у .grid-wrap), а не виштовхує праву
   колонку за край екрана — помітно з пігулками, що не переносяться */
.split > * { min-width: 0; }
/* рядок зі значком (канали звернень, банер) */
.ic-line { display: inline-flex; align-items: center; gap: 6px; }
.banner-ic { flex: none; display: inline-flex; }
.banner-ic svg { width: 18px; height: 18px; }
/* довга примітка в пігулці (зауваження приймача) — переноситься, а не розпирає таблицю */
.badge.wrap { white-space: normal; text-align: left; line-height: 1.4; border-radius: 12px; }
/* реквізити у вузькій боковій картці — мітки 116 px; на телефоні — мітка над значенням (раніше ширину давав style і
   перебивав телефонне правило app.css, аудит P3-25) */
.kv.kv-narrow { grid-template-columns: 116px 1fr; }
@media (max-width: 900px) { .kv.kv-narrow { grid-template-columns: 1fr; } }
/* значення пігулкою + дія окремою малою кнопкою поруч («Тип: фізособа · Позначити як бізнес») */
.kind-row { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }

/* «Картка абонента» (Артьом 19.11: «поля в карточке абона можно визуальнее приятнее сделать»): групи з малими
   заголовками, мітка 12.5 приглушена, значення 14 основним, рядки через тонку лінію, порожнє «—» приглушене */
.cd-group + .cd-group { margin-top: 16px; }
.cd-title { margin-bottom: 2px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.cd { margin: 0; }
.cd-row { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 4px 12px; align-items: baseline; padding: 8px 0; }
.cd-row + .cd-row { border-top: 1px solid var(--border); }
.cd-row > dt { font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.cd-row > dd { margin: 0; min-width: 0; font-size: 14px; line-height: 1.4; color: var(--text); overflow-wrap: anywhere; }
.cd-empty { color: var(--muted); }
.cd-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.cd-note { margin: 4px 0 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 900px) { .cd-row { grid-template-columns: 1fr; } }
