/*
  Единые стили проекта: админка, вход, демо-сайт клиента, страница политики.
  Без сборки и внешних шрифтов. Все цвета и размеры только через переменные ниже.
  Тёмная тема включается сама по настройке системы.
  Виджет на сайте клиента живёт в Shadow DOM и стилизуется в widget.js (те же значения).
*/

/* ---------- 1. Токены ---------- */
:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  /* шрифтовая шкала */
  --fs-12: 12px; --fs-13: 13px; --fs-15: 15px; --fs-17: 17px; --fs-21: 21px; --fs-28: 28px; --fs-40: 40px; --fs-56: 56px;

  /* поверхности и текст */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --field: #f5f5f7;
  --field-hover: #ededf0;
  --fill: rgba(118, 118, 128, .12);
  --fill-soft: rgba(118, 118, 128, .07);
  --hover: rgba(0, 0, 0, .025);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --sep: rgba(0, 0, 0, .08);
  --sep-strong: rgba(0, 0, 0, .16);
  --bar: rgba(255, 255, 255, .72);

  /* акцент и семантика */
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-text: #ffffff;
  --link: #0066cc;
  --accent-soft: rgba(0, 113, 227, .1);
  --ring: rgba(0, 113, 227, .2);
  --green: #34c759; --green-text: #248a3d; --green-soft: rgba(52, 199, 89, .14);
  --orange: #ff9f0a; --orange-text: #b25000; --orange-soft: rgba(255, 159, 10, .16);
  --red: #ff3b30; --red-text: #d70015; --red-soft: rgba(255, 59, 48, .1);

  /* бабблы переписки */
  --bubble-in: #e9e9eb;
  --bubble-out: var(--accent);

  /* форма */
  --r-sm: 8px; --r-field: 10px; --r-card: 16px; --r-lg: 18px; --r-xl: 24px; --r-pill: 999px;
  --sh-sm: 0 1px 2px rgba(0, 0, 0, .04);
  --sh: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  --sh-lg: 0 2px 6px rgba(0, 0, 0, .04), 0 24px 64px rgba(0, 0, 0, .14);

  /* движение */
  --ease: cubic-bezier(.25, .1, .25, 1);
  --t-fast: 150ms; --t: 200ms; --t-slow: 250ms;

  /* сетка */
  --page: 1120px;
  --gutter: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-raised: #2c2c2e;
    --field: #2c2c2e;
    --field-hover: #3a3a3c;
    --fill: rgba(118, 118, 128, .24);
    --fill-soft: rgba(118, 118, 128, .14);
    --hover: rgba(255, 255, 255, .03);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --sep: rgba(255, 255, 255, .1);
    --sep-strong: rgba(255, 255, 255, .2);
    --bar: rgba(22, 22, 23, .72);
    --link: #2997ff;
    --accent-soft: rgba(41, 151, 255, .16);
    --ring: rgba(41, 151, 255, .32);
    --green-text: #30d158; --green-soft: rgba(48, 209, 88, .16);
    --orange-text: #ffb340; --orange-soft: rgba(255, 159, 10, .18);
    --red-text: #ff6961; --red-soft: rgba(255, 69, 58, .16);
    --bubble-in: #2c2c2e;
    --sh-sm: 0 0 0 1px rgba(255, 255, 255, .06);
    --sh: 0 0 0 1px rgba(255, 255, 255, .07);
    --sh-lg: 0 0 0 1px rgba(255, 255, 255, .08), 0 24px 64px rgba(0, 0, 0, .6);
  }
}

/* ---------- 2. Основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 var(--fs-15)/1.47 var(--font); letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 600; color: var(--text); }
h1 { font-size: var(--fs-28); line-height: 1.14; letter-spacing: -.022em; }
h2 { font-size: var(--fs-17); line-height: 1.3; letter-spacing: -.016em; }
h3 { font-size: var(--fs-15); line-height: 1.35; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .87em; letter-spacing: 0; }
code { background: var(--fill-soft); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--ring); }
.muted { color: var(--text-2); }
.small { font-size: var(--fs-13); }
.tiny { font-size: var(--fs-12); }
.err-text { color: var(--red-text); }
.nowrap { white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5;
        stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 24px; height: 24px; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.spacer { flex: 1; }

/* ---------- 3. Верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--bar); border-bottom: 1px solid var(--sep);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
}
.topbar-in {
  max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); height: 52px;
  display: flex; align-items: center; gap: 32px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600;
         font-size: var(--fs-15); letter-spacing: -.016em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r-pill);
  color: var(--text-2); font-size: var(--fs-13); font-weight: 500; transition: color var(--t) var(--ease), background var(--t) var(--ease);
}
.nav a:hover { color: var(--text); background: var(--fill-soft); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--fill); }
.account { display: flex; align-items: center; gap: 8px; font-size: var(--fs-13); color: var(--text-2); }
.avatar-sm {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--fill); color: var(--text); font-size: var(--fs-12); font-weight: 600; text-transform: uppercase;
}

/* ---------- 4. Страница ---------- */
.page { max-width: var(--page); margin: 0 auto; padding: 40px var(--gutter) 96px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head p { margin-top: 6px; color: var(--text-2); font-size: var(--fs-15); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-13); margin-bottom: 12px; }
.section-title { display: flex; align-items: baseline; gap: 12px; margin: 40px 0 12px; }
.section-title h2 { font-size: var(--fs-21); letter-spacing: -.02em; }
.section-title .count { color: var(--text-3); font-size: var(--fs-15); }

/* карточка клиента в шапке */
.entity { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.entity .titles { flex: 1; min-width: 220px; }
.entity-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--text-2); font-size: var(--fs-13); flex-wrap: wrap; }
.monogram {
  width: 52px; height: 52px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: var(--brand, var(--accent)); color: #fff; font-size: var(--fs-21); font-weight: 600; letter-spacing: -.02em;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}
.monogram.sm { width: 36px; height: 36px; border-radius: 10px; font-size: var(--fs-15); }

/* сегменты-вкладки */
.segmented {
  display: inline-flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--fill);
  max-width: 100%; overflow-x: auto; scrollbar-width: none; margin-bottom: 24px;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented a {
  display: inline-flex; align-items: center; height: 32px; padding: 0 16px; border-radius: 9px; white-space: nowrap;
  color: var(--text); font-size: var(--fs-13); font-weight: 500; transition: background var(--t) var(--ease);
}
.segmented a:hover { text-decoration: none; background: var(--fill-soft); }
.segmented a[aria-current="page"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .1), 0 0 0 .5px rgba(0, 0, 0, .04); }
@media (prefers-color-scheme: dark) { .segmented a[aria-current="page"] { background: #636366; box-shadow: none; } }

/* ---------- 5. Карточки и сетки ---------- */
.card { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--sh); padding: 24px; }
.card + .card, .card + .table-card, .table-card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.card-head .titles { flex: 1; min-width: 0; }
.card-head p { margin-top: 4px; color: var(--text-2); font-size: var(--fs-13); line-height: 1.45; }
.card-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--link);
}
.card-foot { display: flex; align-items: center; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.card-foot .hint { flex: 1; min-width: 200px; }
.divider { height: 1px; background: var(--sep); margin: 24px 0; border: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-form { display: grid; gap: 16px 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-form .full { grid-column: 1 / -1; }
.grid > .card { margin: 0; display: flex; flex-direction: column; }
.grid > .card > .grow { flex: 1; }

/* настройки: секции как в «Настройках» системы */
.settings-group + .settings-group { margin-top: 32px; padding-top: 32px; border-top: 1px solid var(--sep); }
.settings-group > h3 { font-size: var(--fs-15); margin-bottom: 4px; }
.settings-group > .hint { margin-bottom: 16px; }

/* ---------- 6. Поля ---------- */
.field { display: block; min-width: 0; }
.field > .label, .label { display: block; margin-bottom: 6px; font-size: var(--fs-13); font-weight: 500; color: var(--text); }
.label .opt { color: var(--text-3); font-weight: 400; }
.hint { display: block; margin-top: 6px; font-size: var(--fs-12); line-height: 1.45; color: var(--text-2); }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=color]),
.field select, .field textarea, .select, .textarea {
  display: block; width: 100%; min-height: 44px; padding: 11px 14px; margin: 0;
  border: 1px solid transparent; border-radius: var(--r-field); background: var(--field); color: var(--text);
  font: inherit; font-size: var(--fs-15); line-height: 1.4; letter-spacing: -.01em;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
  -webkit-appearance: none; appearance: none;
}
.field textarea, .textarea { resize: vertical; min-height: 88px; }
.input:hover, .field input:hover, .field select:hover, .field textarea:hover, .select:hover { background: var(--field-hover); }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus, .select:focus {
  outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring);
}
::placeholder { color: var(--text-3); opacity: 1; }
.field select, .select {
  padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 10l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
.field input[type=date], .field input[data-date] { min-width: 150px; }
.field input[data-date][type=text] {
  padding-right: 36px; background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5' width='17' height='15.5' rx='3'/%3E%3Cpath d='M3.5 10h17M8 3v4M16 3v4'/%3E%3C/svg%3E");
}
.field input[type=date]::-webkit-calendar-picker-indicator { opacity: .45; cursor: pointer; }
.field input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: .8; }
textarea.code, .code-text { font-family: var(--mono); font-size: var(--fs-13); line-height: 1.55; letter-spacing: 0; }

/* выбор цвета */
.color-field { display: flex; align-items: center; gap: 12px; height: 44px; padding: 0 6px 0 6px; border-radius: var(--r-field); background: var(--field); }
.color-field input[type=color] {
  -webkit-appearance: none; appearance: none; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px;
  background: none; cursor: pointer; flex: none;
}
.color-field input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type=color]::-webkit-color-swatch { border: 0; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.color-field input[type=color]::-moz-color-swatch { border: 0; border-radius: 8px; }
.color-field output { font-family: var(--mono); font-size: var(--fs-13); color: var(--text-2); text-transform: uppercase; }

/* сегментный выбор (радио) */
.choice { display: flex; padding: 3px; gap: 2px; border-radius: var(--r-field); background: var(--fill); height: 44px; }
.choice label { flex: 1; position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span {
  display: grid; place-items: center; height: 100%; border-radius: 8px; font-size: var(--fs-13); font-weight: 500;
  color: var(--text); transition: background var(--t) var(--ease);
}
.choice input:checked + span { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.choice input:focus-visible + span { box-shadow: 0 0 0 3px var(--ring); }
@media (prefers-color-scheme: dark) { .choice input:checked + span { background: #636366; } }

/* флажок */
input[type=checkbox].check, .check-row input[type=checkbox] {
  -webkit-appearance: none; appearance: none; width: 20px; height: 20px; margin: 0; flex: none; cursor: pointer;
  border-radius: 6px; border: 1.5px solid var(--sep-strong); background: var(--surface);
  display: inline-grid; place-items: center; transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
input[type=checkbox].check::after, .check-row input[type=checkbox]::after {
  content: ""; width: 11px; height: 6px; margin-top: -2px; border: solid #fff; border-width: 0 0 2px 2px;
  transform: rotate(-45deg) scale(0); transition: transform var(--t-fast) var(--ease);
}
input[type=checkbox].check:checked, .check-row input[type=checkbox]:checked { background: var(--accent); border-color: var(--accent); }
input[type=checkbox].check:checked::after, .check-row input[type=checkbox]:checked::after { transform: rotate(-45deg) scale(1); }
.check-row { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; font-size: var(--fs-15); cursor: pointer; }

/* переключатель */
.switch-row {
  display: flex; align-items: center; gap: 16px; padding: 14px 0; cursor: pointer;
}
.switch-row + .switch-row { border-top: 1px solid var(--sep); }
.switch-row .text { flex: 1; }
.switch-row .text b { display: block; font-weight: 500; }
.switch-row .text span { display: block; margin-top: 2px; font-size: var(--fs-13); color: var(--text-2); }
input[type=checkbox].switch {
  -webkit-appearance: none; appearance: none; position: relative; width: 51px; height: 31px; margin: 0; flex: none;
  border-radius: var(--r-pill); background: var(--fill); cursor: pointer; transition: background var(--t) var(--ease);
}
input[type=checkbox].switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16);
  transition: transform var(--t) var(--ease);
}
input[type=checkbox].switch:checked { background: var(--green); }
input[type=checkbox].switch:checked::after { transform: translateX(20px); }

/* выбор файла */
.file-pick {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--r-field);
  border: 1.5px dashed var(--sep-strong); cursor: pointer; transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.file-pick:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-pick:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--ring); }
.file-pick .btn { pointer-events: none; }
.file-pick .file-name { flex: 1; min-width: 0; font-size: var(--fs-13); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick.has-file .file-name { color: var(--text); }

/* ---------- 7. Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 18px;
  border: 0; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-text);
  font: inherit; font-size: var(--fs-13); font-weight: 500; letter-spacing: -.01em; white-space: nowrap; cursor: pointer;
  transition: background var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease), opacity var(--t) var(--ease);
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn:active { opacity: .85; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.lg { height: 44px; padding: 0 22px; font-size: var(--fs-15); }
.btn.block { width: 100%; }
.btn.secondary { background: var(--fill); color: var(--text); }
.btn.secondary:hover { background: var(--field-hover); }
@media (prefers-color-scheme: dark) { .btn.secondary:hover { background: rgba(118, 118, 128, .32); } }
.btn.tinted { background: var(--accent-soft); color: var(--link); }
.btn.tinted:hover { background: var(--ring); }
.btn.danger { background: var(--red-soft); color: var(--red-text); }
.btn.danger:hover { background: rgba(255, 59, 48, .16); }
.btn.icon-only { width: 36px; padding: 0; }
.link-btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--link); font: inherit; font-size: inherit;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 2px; }
.link-btn.danger { color: var(--red-text); }
.link-btn.muted { color: var(--text-2); }
form.inline { display: inline; margin: 0; }

/* ---------- 8. Статусы и уведомления ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: var(--fs-12); font-weight: 500; white-space: nowrap; background: var(--fill); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.badge.green { background: var(--green-soft); color: var(--green-text); }
.badge.orange { background: var(--orange-soft); color: var(--orange-text); }
.badge.red { background: var(--red-soft); color: var(--red-text); }
.badge.blue { background: var(--accent-soft); color: var(--link); }

.flash {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 16px; margin-bottom: 20px; border-radius: 12px;
  font-size: var(--fs-13); line-height: 1.45; background: var(--surface); box-shadow: var(--sh);
}
.flash .icon { margin-top: -1px; }
.flash.ok .icon { color: var(--green); }
.flash.err { background: var(--red-soft); box-shadow: none; color: var(--text); }
.flash.err .icon { color: var(--red-text); }
.flash.warn { background: var(--orange-soft); box-shadow: none; }
.flash.warn .icon { color: var(--orange-text); }
.flash .body { flex: 1; }
.callout {
  display: flex; gap: 12px; padding: 14px 16px; border-radius: 12px; background: var(--fill-soft);
  font-size: var(--fs-13); line-height: 1.5; color: var(--text-2);
}
.callout .icon { color: var(--text-3); margin-top: 1px; }
.callout.warn { background: var(--orange-soft); color: var(--text); }
.callout.warn .icon { color: var(--orange-text); }
.callout b { color: var(--text); font-weight: 600; }

/* пустое состояние */
.empty { text-align: center; padding: 56px 24px; }
.empty-icon {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; display: grid; place-items: center;
  background: var(--fill-soft); color: var(--text-3);
}
.empty-icon .icon { width: 28px; height: 28px; }
.empty h3 { font-size: var(--fs-17); margin-bottom: 6px; }
.empty p { color: var(--text-2); max-width: 420px; margin: 0 auto; }
.empty .btn { margin-top: 20px; }

/* ---------- 9. Таблицы ---------- */
.table-card { position: relative; background: var(--surface); border-radius: var(--r-card); box-shadow: var(--sh); overflow: hidden; }
.table-scroll { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-13); }
.table th {
  text-align: left; padding: 12px 20px; font-size: var(--fs-12); font-weight: 500; color: var(--text-2);
  border-bottom: 1px solid var(--sep); white-space: nowrap; background: var(--surface);
}
.table td { padding: 14px 20px; border-bottom: 1px solid var(--sep); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--t-fast) var(--ease); }
.table tbody tr:hover { background: var(--hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table span.title, .table .sub { display: block; }
.table .title { font-size: var(--fs-15); font-weight: 500; color: var(--text); }
.table a.title:hover { color: var(--link); text-decoration: none; }
.table .sub { margin-top: 2px; color: var(--text-2); font-size: var(--fs-12); }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * + * { margin-left: 16px; }
.table .clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .need { min-width: 240px; max-width: 340px; color: var(--text-2); line-height: 1.45; }
.row-link { display: flex; align-items: center; gap: 12px; color: inherit; }
.row-link:hover { text-decoration: none; }
.row-link:hover .title { color: var(--link); }

/* статус заявки как цветная «таблетка»-список */
.status-select {
  -webkit-appearance: none; appearance: none; height: 28px; padding: 0 28px 0 12px; border: 0; border-radius: var(--r-pill);
  font: inherit; font-size: var(--fs-12); font-weight: 500; cursor: pointer; background-color: var(--fill); color: var(--text);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 10l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 14px;
}
.status-select:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.status-select[data-status="new"] { background-color: var(--accent-soft); color: var(--link); }
.status-select[data-status="in_work"] { background-color: var(--orange-soft); color: var(--orange-text); }
.status-select[data-status="done"] { background-color: var(--green-soft); color: var(--green-text); }
.status-select[data-status="spam"] { background-color: var(--fill); color: var(--text-2); }

/* панель фильтров */
.toolbar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
  padding: 16px; background: var(--surface); border-radius: var(--r-card); box-shadow: var(--sh);
}
.toolbar .field { min-width: 150px; }
.toolbar .field.wide { min-width: 200px; flex: 1; max-width: 260px; }
.toolbar .field input, .toolbar .field select { min-height: 36px; padding-top: 7px; padding-bottom: 7px; font-size: var(--fs-13); }
.toolbar .field .label { font-size: var(--fs-12); color: var(--text-2); margin-bottom: 4px; }
.toolbar .check-row { min-height: 36px; font-size: var(--fs-13); }

/* ---------- 10. Код, ключи ---------- */
.code-block { position: relative; }
.code-block pre {
  margin: 0; padding: 16px; border-radius: 12px; background: var(--field);
  font-family: var(--mono); font-size: var(--fs-13); line-height: 1.6; letter-spacing: 0;
  white-space: pre; overflow-x: auto; color: var(--text);
}
.code-block .copy { position: absolute; bottom: 10px; right: 10px; height: 30px; padding: 0 12px; background: var(--surface); box-shadow: var(--sh-sm), 0 0 0 1px var(--sep); }
.code-block .copy:hover { background: var(--surface); color: var(--link); }
.kv { margin: 16px 0 0; }
.kv-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--sep); font-size: var(--fs-13); }
.kv-row dt { width: 128px; flex: none; color: var(--text-2); }
.kv-row dd { margin: 0; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.kv-row dd code { background: none; padding: 0; font-size: var(--fs-13); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.secret[data-hidden="1"] .secret-value { letter-spacing: .1em; }
.big-code { font-family: var(--mono); font-size: var(--fs-21); font-weight: 600; letter-spacing: .02em; padding: 8px 14px; border-radius: 10px; background: var(--field); }

.bookmarklet {
  display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0 20px 0 14px; border-radius: var(--r-pill);
  background: var(--brand, var(--accent)); color: #fff; font-weight: 500; cursor: grab; box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
}
.bookmarklet:hover { text-decoration: none; filter: brightness(1.06); }
.bookmarklet:active { cursor: grabbing; }
.drag-hint { display: flex; align-items: center; gap: 16px; padding: 20px; border-radius: 12px; background: var(--fill-soft); margin-bottom: 16px; flex-wrap: wrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--sep); }
.list li:first-child { border-top: 0; }

/* ---------- 11. Переписка ---------- */
.thread { display: flex; flex-direction: column; gap: 2px; }
.bubble {
  max-width: 72%; padding: 9px 14px; border-radius: var(--r-lg); white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: var(--fs-15); line-height: 1.4; background: var(--bubble-in); color: var(--text); align-self: flex-start;
}
.bubble.visitor { background: var(--bubble-out); color: #fff; align-self: flex-end; }
.bubble.system {
  align-self: center; max-width: 90%; background: none; color: var(--text-2); font-size: var(--fs-12); text-align: center; padding: 4px 12px;
}
.bubble + .bubble { margin-top: 2px; }
.bubble.agent + .bubble.visitor, .bubble.visitor + .bubble.agent, .bubble.system + .bubble, .bubble + .bubble.system { margin-top: 12px; }
.msg-meta { font-size: var(--fs-12); color: var(--text-3); margin: 4px 6px 0; white-space: normal; }
.bubble .msg-meta { margin: 4px 0 0; color: inherit; opacity: .6; }
.bubble .sources { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--sep); font-size: var(--fs-12); color: var(--text-2); white-space: normal; }
.bubble.visitor .sources { border-color: rgba(255, 255, 255, .25); color: rgba(255, 255, 255, .8); }
.bubble .sources.err-text { color: var(--red-text); }
.bubble .sources.form-note { color: var(--link); }
.chat-card { display: flex; flex-direction: column; min-height: 520px; padding: 0; overflow: hidden; }
.chat-card .chat-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--sep); }
.chat-card .chat-head .titles { flex: 1; }
.chat-card .chat-body { flex: 1; padding: 20px; overflow-y: auto; }
.chat-card .chat-compose { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--sep); }
.chat-card .chat-compose .input { min-height: 40px; padding: 9px 16px; border-radius: var(--r-pill); }
.chat-card .chat-compose .btn { height: 40px; }
.typing-dots { display: inline-flex; gap: 4px; padding: 14px 16px; border-radius: var(--r-lg); background: var(--bubble-in); align-self: flex-start; margin-top: 12px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite var(--ease); }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px 12px; }
.chip {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: var(--r-pill); border: 0;
  background: var(--fill-soft); color: var(--text); font: inherit; font-size: var(--fs-12); cursor: pointer; transition: background var(--t) var(--ease);
}
.chip:hover { background: var(--fill); }

/* ---------- 12. Вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 40px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh); padding: 40px 36px 32px; }
.auth-card .brand-mark { width: 56px; height: 56px; display: block; margin: 0 auto 20px; }
.auth-card h1 { text-align: center; font-size: var(--fs-28); }
.auth-card .lead { text-align: center; color: var(--text-2); margin: 8px 0 28px; }
.auth-card .stack > .field + .field { margin-top: 12px; }
.auth-card .btn { margin-top: 24px; }
.auth-foot { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--sep); text-align: center; font-size: var(--fs-12); color: var(--text-2); }

/* ---------- 13. Страница политики ---------- */
.doc { max-width: 720px; margin: 0 auto; padding: 56px var(--gutter) 96px; }
.doc .callout { margin-bottom: 32px; }
.doc-body { white-space: pre-wrap; font: inherit; font-size: var(--fs-17); line-height: 1.6; color: var(--text); margin: 0; }

/* ---------- 13a. Раскладки и мелочи ---------- */
.form-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 16px; align-items: end; }
.conv-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.conv-layout .chat-card { margin: 0; }
.conv-layout aside .card + .card, .conv-layout aside .card + .callout { margin-top: 16px; }
.card-icon.neutral { background: var(--fill-soft); color: var(--text-2); }
.cell-error { margin-top: 6px; max-width: 260px; font-size: var(--fs-12); color: var(--red-text); }
.hint.flush { margin-top: 0; }
.after-table { margin-top: 12px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
a .icon.sm, .link-btn .icon.sm { vertical-align: -3px; }
.table .actions a { display: inline-flex; align-items: center; gap: 4px; }
.msg-meta.visitor { align-self: flex-end; }
.msg-meta.system { display: none; }

/* ---------- 14. Адаптив админки ---------- */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .conv-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  :root { --gutter: 16px; }
  .topbar-in { height: auto; flex-wrap: wrap; gap: 0 12px; padding-top: 10px; }
  .topbar .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; margin: 6px -4px 8px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { height: 36px; padding: 0 14px; font-size: var(--fs-15); }
  .account .who { display: none; }
  .page { padding-top: 24px; }
  .grid-2, .grid-form, .form-row { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 24px; }
  .card { padding: 20px; }
  .table th, .table td { padding-left: 16px; padding-right: 16px; }
  .code-block pre { font-size: var(--fs-12); padding-bottom: 52px; }
  .bubble { max-width: 86%; }
  .kv-row { flex-wrap: wrap; }
  .kv-row dt { width: 100%; }
  .toolbar .field, .toolbar .field.wide { flex: 1 1 140px; max-width: none; }
  .auth-card { padding: 32px 24px 24px; }
  .code-block pre { padding-right: 16px; padding-top: 52px; }
}

/* =====================================================================
   15. Демо-сайт клиента (/demo/...). Это «чужой» сайт, на который встаёт виджет.
   Цвет бренда приходит из настроек клиента в --brand.
   ===================================================================== */
.site { --brand: #0f766e; background: var(--surface); }
.site .wrap { max-width: 1040px; margin: 0 auto; padding: 0 var(--gutter); }
.site-ribbon { background: var(--fill-soft); color: var(--text-2); font-size: var(--fs-12); text-align: center; padding: 9px 16px; }
.site-ribbon b { color: var(--text); font-weight: 500; }
.site-nav { position: sticky; top: 0; z-index: 20; background: var(--bar); border-bottom: 1px solid var(--sep);
            -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%); }
.site-nav .wrap { display: flex; align-items: center; gap: 32px; height: 56px; }
.site-logo { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; letter-spacing: -.02em; white-space: nowrap; }
.site-logo:hover { text-decoration: none; }
.site-logo svg { width: 30px; height: 30px; flex: none; }
.site-links { display: flex; gap: 24px; flex: 1; }
.site-links a { color: var(--text-2); font-size: var(--fs-13); }
.site-links a:hover { color: var(--text); text-decoration: none; }
.site-phone { margin-left: auto; font-size: var(--fs-13); color: var(--text); font-weight: 500; white-space: nowrap; }
.site-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 18px;
  border: 0; border-radius: var(--r-pill); background: var(--brand); color: #fff; font: inherit; font-size: var(--fs-13);
  font-weight: 500; cursor: pointer; white-space: nowrap; transition: filter var(--t) var(--ease);
}
.site-btn:hover { filter: brightness(1.08); text-decoration: none; }
.site-btn.lg { height: 48px; padding: 0 26px; font-size: var(--fs-17); }
.site-link { display: inline-flex; align-items: center; gap: 2px; color: var(--brand); font-size: var(--fs-17); font-weight: 500; }
@media (prefers-color-scheme: dark) { .site-link, .site-eyebrow, .site-card .card-icon { filter: brightness(1.5); } }

.site-hero { padding: 96px 0 72px; text-align: center; }
.site-eyebrow { color: var(--brand); font-size: var(--fs-17); font-weight: 600; letter-spacing: -.01em; margin-bottom: 12px; }
.site-hero h1 { font-size: var(--fs-56); line-height: 1.07; letter-spacing: -.035em; max-width: 820px; margin: 0 auto; }
.site-hero .lead { font-size: var(--fs-21); line-height: 1.4; color: var(--text-2); max-width: 640px; margin: 20px auto 0; letter-spacing: -.016em; }
.site-hero .ctas { display: flex; align-items: center; justify-content: center; gap: 28px; margin-top: 36px; flex-wrap: wrap; }
.site-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-top: 72px; background: var(--sep);
              border-radius: var(--r-xl); overflow: hidden; box-shadow: 0 0 0 1px var(--sep); }
.site-stats div { background: var(--surface); padding: 28px 20px; text-align: center; }
.site-stats b { display: block; font-size: var(--fs-28); font-weight: 600; letter-spacing: -.02em; }
.site-stats span { display: block; margin-top: 4px; font-size: var(--fs-13); color: var(--text-2); }

.site-section { padding: 88px 0; }
.site-section.alt { background: var(--bg); }
.site-section-head { text-align: center; margin-bottom: 48px; }
.site-section-head h2 { font-size: var(--fs-40); line-height: 1.1; letter-spacing: -.03em; }
.site-section-head p { margin-top: 12px; font-size: var(--fs-17); color: var(--text-2); }
.site-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.site-card { background: var(--surface); border-radius: var(--r-lg); padding: 28px; box-shadow: var(--sh); }
.site-section:not(.alt) .site-card { background: var(--bg); box-shadow: none; }
.site-card .card-icon { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 20px; color: var(--brand);
                        background: color-mix(in srgb, var(--brand) 12%, transparent); }
.site-card .card-icon .icon { width: 24px; height: 24px; }
.site-card h3 { font-size: var(--fs-17); letter-spacing: -.016em; }
.site-card p { margin-top: 8px; color: var(--text-2); font-size: var(--fs-15); }
.site-card .price { margin-top: 16px; font-size: var(--fs-15); font-weight: 600; color: var(--text); }

.price-table { max-width: 820px; margin: 0 auto; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh); padding: 8px 32px; }
.price-group { padding: 20px 0; }
.price-group + .price-group { border-top: 1px solid var(--sep); }
.price-group h3 { font-size: var(--fs-13); font-weight: 600; color: var(--text-2); margin-bottom: 8px; letter-spacing: 0; }
.price-row { display: flex; align-items: baseline; gap: 16px; padding: 8px 0; }
.price-row .name { flex: 1; font-size: var(--fs-17); }
.price-row .term { color: var(--text-2); font-size: var(--fs-13); white-space: nowrap; }
.price-row .cost { min-width: 150px; text-align: right; font-size: var(--fs-17); font-weight: 600; white-space: nowrap; }
.price-note { text-align: center; margin-top: 20px; color: var(--text-2); font-size: var(--fs-13); }

.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 32px; counter-reset: step; }
.step { counter-increment: step; }
.step::before {
  content: counter(step); display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; margin-bottom: 16px;
  background: var(--text); color: var(--surface); font-size: var(--fs-15); font-weight: 600;
}
.step h3 { font-size: var(--fs-17); }
.step p { margin-top: 6px; color: var(--text-2); }

.review { display: flex; flex-direction: column; }
.review .stars { display: flex; gap: 2px; color: var(--orange); margin-bottom: 16px; }
.review .stars svg { width: 16px; height: 16px; fill: currentColor; }
.review blockquote { margin: 0; flex: 1; font-size: var(--fs-17); line-height: 1.5; letter-spacing: -.012em; }
.review .who { display: flex; align-items: center; gap: 12px; margin-top: 24px; font-size: var(--fs-13); }
.review .who .avatar-sm { width: 36px; height: 36px; font-size: var(--fs-13); background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.review .who b { display: block; font-weight: 600; }
.review .who span { color: var(--text-2); }

.site-cta { text-align: center; padding: 96px 0; }
.site-cta h2 { font-size: var(--fs-40); letter-spacing: -.03em; line-height: 1.1; }
.site-cta p { margin: 12px auto 32px; max-width: 560px; color: var(--text-2); font-size: var(--fs-17); }
.site-footer { border-top: 1px solid var(--sep); padding: 28px 0 112px; font-size: var(--fs-12); color: var(--text-2); }
.site-footer a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.site-footer .wrap { display: flex; gap: 24px; flex-wrap: wrap; justify-content: space-between; }

/* Открытый чат на широком экране: фон секций остаётся во всю ширину, а содержимое
   уезжает в свободную часть экрана, чтобы виджет не закрывал текст */
.site .wrap { transition: margin var(--t-slow) var(--ease), max-width var(--t-slow) var(--ease); }
@media (min-width: 1180px) {
  .site.chat-open { --chat-room: 404px; --free: max(0px, (100% - var(--chat-room) - 980px) / 2); }
  .site.chat-open .wrap { max-width: 980px; }
  .site.chat-open.chat-right .wrap { margin-left: calc(var(--free)); margin-right: calc(var(--chat-room) + var(--free)); }
  .site.chat-open.chat-left .wrap { margin-right: calc(var(--free)); margin-left: calc(var(--chat-room) + var(--free)); }
  .site.chat-open .site-links { display: none; }
  .site.chat-open .site-hero h1 { font-size: 48px; }
}

@media (max-width: 900px) {
  .site-links, .site-phone { display: none; }
  .site-nav .wrap { justify-content: space-between; }
  .site-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .site-hero { padding: 56px 0 48px; }
  .site-hero h1 { font-size: 36px; }
  .site-hero .lead { font-size: var(--fs-17); }
  .site-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 48px; }
  .site-stats b { font-size: var(--fs-21); }
  .site-section, .site-cta { padding: 64px 0; }
  .site-section-head h2, .site-cta h2 { font-size: 30px; }
  .site-grid, .steps { grid-template-columns: 1fr; }
  .price-table { padding: 4px 20px; }
  .price-row { flex-wrap: wrap; gap: 2px 12px; }
  .price-row .name { flex-basis: 100%; font-size: var(--fs-15); }
  .price-row .term { flex: 1; }
  .price-row .cost { min-width: 0; font-size: var(--fs-15); }
}

/* ---------- 16. Без анимаций по просьбе системы ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
}
