/* ==========================================================================
   МиниCRM — Design System v1
   Слой оформления поверх style.css. Подключается ПОСЛЕ него.
   Правила: docs/design-system.md. Новые цвета/тени/радиусы — только через токены.
   ========================================================================== */

/* ------------------------------- 1. Tokens -------------------------------- */
:root {
  /* Бренд */
  --brand-grad: linear-gradient(135deg, #3b2399 0%, #5b38c8 52%, #7c53e2 100%);
  --accent-grad: linear-gradient(180deg, #4a82f5 0%, #2f6fed 100%);
  --success-grad: linear-gradient(180deg, #38d27c 0%, #25b865 100%);

  /* Поверхности и текст */
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-hover: #f1f5fb;
  --text-strong: #111827;
  --text-soft: #4b5563;

  /* Радиусы */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* Тени (мягкие, многослойные) */
  --sh-xs: 0 1px 2px rgba(17, 24, 39, .05);
  --sh-sm: 0 1px 2px rgba(17, 24, 39, .05), 0 2px 6px rgba(17, 24, 39, .04);
  --sh-md: 0 2px 4px rgba(17, 24, 39, .04), 0 8px 20px rgba(17, 24, 39, .07);
  --sh-lg: 0 4px 8px rgba(17, 24, 39, .05), 0 18px 40px rgba(17, 24, 39, .12);
  --sh-brand: 0 6px 18px rgba(91, 56, 200, .28);
  --ring: 0 0 0 3px rgba(47, 111, 237, .18);

  /* Движение */
  --ease: cubic-bezier(.22, .8, .24, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .5, 1);
  --t-fast: 120ms;
  --t-base: 200ms;
  --t-slow: 320ms;

  /* Размеры контролов */
  --control-h: 36px;
  --control-h-sm: 30px;

  --radius: var(--r-sm);
}

/* ------------------------------ 2. Base ----------------------------------- */
html, body {
  font-family: "Inter", "Segoe UI Variable Text", "Segoe UI", "Open Sans", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { background: var(--bg); }
::selection { background: rgba(91, 56, 200, .2); }
h1, h2, h3 { color: inherit; font-weight: 700; }

a { transition: color var(--t-fast) var(--ease); }

:focus-visible {
  outline: 2px solid rgba(47, 111, 237, .55);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible, .btn:focus-visible, a:focus-visible { outline-offset: 2px; }

/* Тонкие скроллбары */
* { scrollbar-width: thin; scrollbar-color: #c9d2e0 transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: #cbd4e2; border-radius: var(--r-pill); border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #aab6ca; background-clip: padding-box; border: 2px solid transparent; }

/* ------------------------------ 3. Topbar --------------------------------- */
.topbar {
  background: rgba(255, 255, 255, .86);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid rgba(228, 233, 240, .9);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6), var(--sh-xs);
}
.brand-mark {
  background: var(--brand-grad);
  box-shadow: 0 4px 10px rgba(91, 56, 200, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform var(--t-base) var(--ease-spring);
}
.brand:hover .brand-mark { transform: rotate(-6deg) scale(1.06); }
.brand:hover { text-decoration: none; }
.nav-link { border-radius: var(--r-sm); transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.nav-link:hover { background: var(--surface-hover); text-decoration: none; }

/* ------------------------------ 4. Left menu ------------------------------ */
.left-menu-item {
  position: relative;
  border-radius: 10px;
  transition: background var(--t-fast) var(--ease), transform var(--t-base) var(--ease);
}
.left-menu-item:hover { transform: translateX(2px); }
.left-menu-item.active { background: rgba(255, 255, 255, .2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14), 0 4px 14px rgba(20, 8, 70, .25); }
.left-menu-item.active::before {
  content: '';
  position: absolute;
  left: -9px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, .7);
}
.left-menu-icon {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--menu-color, #7c53e2), color-mix(in srgb, var(--menu-color, #7c53e2) 72%, #000));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), 0 3px 8px rgba(10, 4, 50, .28);
  transition: transform var(--t-base) var(--ease-spring);
}
.left-menu-icon .ico { width: 17px; height: 17px; }
.left-menu-item:hover .left-menu-icon { transform: scale(1.08) rotate(-3deg); }
.left-menu-caption { opacity: .6; }
.left-menu-settings { border-radius: 10px; transition: background var(--t-fast) var(--ease); }

/* ------------------------------ 5. Hero ----------------------------------- */
.hero {
  background:
    radial-gradient(900px 300px at 85% -40%, rgba(160, 130, 255, .6), transparent 62%),
    radial-gradient(620px 240px at 12% -30%, rgba(64, 169, 255, .26), transparent 68%),
    radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1.4px) 0 0 / 22px 22px,
    linear-gradient(105deg, #35208a 0%, #4a2bb4 42%, #6840d4 76%, #7c53e2 100%);
}
.hero-top h1 { font-size: 28px; font-weight: 800; letter-spacing: -.7px; text-shadow: 0 2px 14px rgba(15, 6, 60, .28); }
.hero-total { font-variant-numeric: tabular-nums; }

.subnav-pill {
  height: 32px;
  border-radius: var(--r-pill);
  backdrop-filter: blur(6px);
  transition: background var(--t-base) var(--ease), color var(--t-base) var(--ease), transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease);
}
.subnav-pill:hover { transform: translateY(-1px); }
.subnav-pill.active { background: #fff; box-shadow: 0 4px 14px rgba(15, 6, 60, .25); }

.hero-search input, .hero-filter, .hero-refresh { border-radius: 10px; transition: background var(--t-base) var(--ease), border-color var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease); }
.hero-refresh:hover { transform: rotate(60deg); transition: transform var(--t-slow) var(--ease), background var(--t-fast); }

.content-card {
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: 0 -4px 30px rgba(26, 16, 74, .14), var(--sh-md);
}

/* --------------------------- 6. Buttons & controls ------------------------ */
.btn {
  height: var(--control-h-sm);
  border-radius: 10px;
  border-color: #d6deea;
  box-shadow: var(--sh-xs);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-base) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-soft); border-color: #bfcadc; box-shadow: var(--sh-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.98); box-shadow: var(--sh-xs); }
.btn-sm { height: 28px; border-radius: 9px; }
.btn-primary, .deal-task-done {
  background: var(--accent-grad);
  border-color: #2a62d6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 4px 12px rgba(47, 111, 237, .32);
}
.btn-primary:hover, .deal-task-done:hover { background: linear-gradient(180deg, #4079ee 0%, #2760d8 100%); border-color: #2559c8; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 6px 18px rgba(47, 111, 237, .4); }
.btn-create {
  height: var(--control-h);
  background: var(--success-grad);
  border-color: #21a95b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 4px 14px rgba(37, 184, 101, .4);
}
.btn-create:hover { background: linear-gradient(180deg, #34c775 0%, #1fa859 100%); border-color: #1c9a52; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 7px 20px rgba(37, 184, 101, .5); }
.btn-danger { border-radius: 10px; }
.btn-ghost { box-shadow: none; }
.btn-ghost:hover { box-shadow: none; }

.deal-create-main, .deal-create-arrow { transition: background var(--t-fast) var(--ease), box-shadow var(--t-base) var(--ease); }
.filter-open-btn { transition: background var(--t-base) var(--ease), border-color var(--t-base) var(--ease); }

input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="url"], input[type="email"], input[type="password"], select, textarea {
  border-radius: 10px;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-base) var(--ease), background var(--t-fast) var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
input[type="checkbox"] { border-radius: 4px; cursor: pointer; transition: transform var(--t-fast) var(--ease-spring); }
input[type="checkbox"]:active { transform: scale(.85); }

/* ------------------------------ 7. Cards ---------------------------------- */
.panel, .desk-card, .settings-card {
  border-radius: var(--r-md);
  border-color: #e6ebf3;
  box-shadow: var(--sh-sm);
}
.panel-head, .desk-card-head { background: linear-gradient(180deg, #fff, #fbfcfe); }

.settings-home-card, .desk-kpi {
  border-radius: var(--r-md);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}
.settings-home-card:hover, .desk-kpi:hover { transform: translateY(-3px); box-shadow: var(--sh-lg); border-color: #cdd8ee; text-decoration: none; }
.settings-home-icon { border-radius: 14px; background: linear-gradient(145deg, #f5f8ff, #e9efff); box-shadow: inset 0 1px 0 #fff, var(--sh-xs); transition: transform var(--t-base) var(--ease-spring); color: #5b38c8; }
.settings-ai-icon { background: linear-gradient(145deg, #f6f1ff, #ece2ff); color: #7c53e2; }
.settings-home-icon .ico, .desk-kpi-icon .ico { display: block; }
.desk-kpi-icon { color: currentColor; }
.settings-home-card:hover .settings-home-icon { transform: scale(1.1) rotate(-4deg); }
.desk-kpi-icon { transition: transform var(--t-base) var(--ease-spring); }
.desk-kpi:hover .desk-kpi-icon { transform: scale(1.15) rotate(-6deg); }
.desk-kpi-value { font-variant-numeric: tabular-nums; letter-spacing: -.5px; }

/* ------------------------------ 8. Tables --------------------------------- */
table.grid thead th { position: sticky; top: 0; z-index: 2; background: #f8fafd; letter-spacing: .02em; backdrop-filter: blur(6px); }
table.grid tbody tr { transition: background var(--t-fast) var(--ease); }
table.grid tbody tr:hover { background: #f4f7ff; }
table.grid tbody tr[data-href] { cursor: pointer; }
table.grid td, table.grid th { font-variant-numeric: tabular-nums; }

.badge, .task-type-pill, .status-pill { border-radius: var(--r-pill); }

.stage-progress { border-radius: 8px; box-shadow: inset 0 1px 2px rgba(17, 24, 39, .05); }
.stage-progress-step { transition: opacity var(--t-fast) var(--ease), background var(--t-base) var(--ease); }

/* ------------------------------ 9. Overlays ------------------------------- */
.modal-overlay {
  background: rgba(17, 12, 48, .5);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: ds-fade var(--t-base) var(--ease) both;
}
.modal {
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg), 0 0 0 1px rgba(17, 24, 39, .04);
  animation: ds-pop var(--t-slow) var(--ease-spring) both;
}
.modal-head { background: linear-gradient(180deg, #fff, #fbfcfe); border-radius: var(--r-lg) var(--r-lg) 0 0; }
.modal-close { border-radius: 9px; transition: background var(--t-fast) var(--ease), transform var(--t-base) var(--ease); }
.modal-close:hover { transform: rotate(90deg); }

/* Выпадающие меню появляются плавно (анимация перезапускается при снятии hidden) */
.create-menu, .settings-menu, .deal-chip-menu, .deal-task-menu, .document-menu, .task-actions-menu {
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  animation: ds-menu var(--t-base) var(--ease) both;
  transform-origin: top right;
}
.deal-task-menu { transform-origin: bottom right; }

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  padding: 12px 16px 12px 14px;
  box-shadow: var(--sh-lg);
  transform: translateY(14px) scale(.98);
  transition: opacity var(--t-base) var(--ease), transform var(--t-slow) var(--ease-spring), visibility var(--t-base);
}
.toast.show { transform: translateY(0) scale(1); }
.toast::before { content: 'i'; flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: rgba(255, 255, 255, .18); font-weight: 700; font-size: 12px; line-height: 1; }
.toast.success::before { content: '✓'; }
.toast.error::before { content: '!'; }

/* ---------------------------- 10. Empty & loading ------------------------- */
.empty { padding: 56px 20px; color: var(--muted); }
.empty::before {
  content: '';
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237c53e2' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 13.5 6.5 5.5a1.5 1.5 0 0 1 1.4-1h8.2a1.5 1.5 0 0 1 1.4 1l2.5 8'/%3E%3Cpath d='M4 13.5V18a1.5 1.5 0 0 0 1.5 1.5h13A1.5 1.5 0 0 0 20 18v-4.5h-4.5l-1 2h-5l-1-2z'/%3E%3C/svg%3E") center / 34px no-repeat,
    linear-gradient(145deg, #f3efff, #e8f0ff);
  box-shadow: inset 0 1px 0 #fff, var(--sh-sm);
}
.empty strong { display: block; margin-bottom: 4px; color: var(--text-strong); font-size: 15px; }

/* Скелетон-загрузка */
.sk { display: inline-block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, #eceff5 25%, #f7f9fc 45%, #eceff5 65%); background-size: 220% 100%; animation: ds-shimmer 1.3s linear infinite; }
.sk-page { margin: -22px -24px 0; }
.sk-hero { display: grid; gap: 16px; padding: 28px 24px 22px; background: linear-gradient(105deg, #35208a, #6840d4); }
.sk-hero .sk { background: linear-gradient(90deg, rgba(255,255,255,.14) 25%, rgba(255,255,255,.26) 45%, rgba(255,255,255,.14) 65%); background-size: 220% 100%; }
.sk-title { width: 220px; height: 28px; border-radius: 9px; }
.sk-pills { width: 360px; max-width: 80%; height: 30px; border-radius: var(--r-pill); }
.sk-card { margin: 0 12px; padding: 8px 16px 18px; background: #fff; border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--sh-md); min-height: 60vh; }
.sk-table { display: grid; }
.sk-row { display: flex; align-items: center; gap: 22px; padding: 17px 8px; border-bottom: 1px solid #f0f3f8; }
.sk-row:nth-child(2n) .sk-w30 { width: 24%; }
.sk-check { width: 16px; height: 16px; border-radius: 4px; }
.sk-w10 { width: 8%; } .sk-w15 { width: 12%; } .sk-w20 { width: 16%; } .sk-w30 { width: 30%; }
.sk-row .sk { animation-delay: calc(var(--i, 0) * 80ms); }

/* ----------------------------- 11. Timeline & tasks ----------------------- */
.timeline-item { position: relative; }
.timeline-item.is-menu-open { z-index: 30; }
.timeline-item.is-menu-open .timeline-content { box-shadow: var(--sh-lg); }
.timeline-item { animation: ds-up var(--t-slow) var(--ease) both; }
.timeline-item:nth-child(2) { animation-delay: 40ms; }
.timeline-item:nth-child(3) { animation-delay: 80ms; }
.timeline-item:nth-child(n+4) { animation-delay: 120ms; }
.timeline-content { border-radius: var(--r-md); box-shadow: var(--sh-xs); transition: box-shadow var(--t-base) var(--ease), transform var(--t-base) var(--ease); }
.timeline-content:hover { box-shadow: var(--sh-md); }
.timeline-icon { box-shadow: var(--sh-xs); }
.timeline-icon-badge { animation: ds-pulse 2.4s var(--ease) infinite; }

.deal-task-card { border-radius: var(--r-md); transition: box-shadow var(--t-base) var(--ease), transform var(--t-base) var(--ease); }
.deal-task-card:hover { box-shadow: var(--sh-md); transform: translateY(-1px); }
.deal-task-cal { border-radius: 12px; transition: transform var(--t-base) var(--ease-spring), background var(--t-fast); }
.deal-task-cal:hover { transform: scale(1.05); }
.deal-task-check input { transition: transform var(--t-fast) var(--ease-spring); }
.deal-task-check input:checked { transform: scale(1.1); }

.deal-chip { transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease); }
.deal-chip:hover { transform: translateY(-1px); }

/* Редактор документа */
.document-editor-section { margin-top: 6px; padding-top: 10px; border-top: 1px solid #eef2f7; }
.document-editor-section h3 { margin: 0; color: #7c8795; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.document-editor-link { margin-top: 12px; padding: 8px 10px; border-radius: 8px; background: #f5f8ff; color: #5f6b79; font-size: 11.5px; word-break: break-all; }
.document-editor-link code { color: #2f6fd0; }

/* Чат открытых линий: страница строго в высоту окна, композер всегда виден */
.app:has(.chat-page) { padding-bottom: 0; }
.chat-page {
  height: calc(100dvh - 56px);
  margin: -22px -24px 0;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) minmax(250px, 310px);
}
.chat-sidebar, .chat-main, .chat-info { min-height: 0; }
.chat-composer { position: relative; z-index: 5; flex: 0 0 auto; }
.chat-composer textarea { min-width: 0; }
.chat-composer .btn { flex: none; }
@media (max-width: 1280px) {
  .chat-page { grid-template-columns: 260px minmax(0, 1fr); }
  .chat-info { display: none; }
}
@media (max-width: 900px) {
  .chat-page {
    grid-template-columns: minmax(0, 1fr);
    height: calc(100dvh - 56px);
    margin: -14px -12px 0;
  }
  .chat-sidebar { display: none; }
  .chat-mobile-back { display: inline-flex; }
}

/* Миниатюры файловых полей */
.file-thumb {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  max-width: 180px;
  text-decoration: none;
}
.file-thumb-img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border: 1px solid #e6ebf3;
  border-radius: 10px;
  background: #f8fafc;
  box-shadow: var(--sh-xs);
  transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease), border-color var(--t-base);
}
.file-thumb:hover .file-thumb-img { transform: scale(1.03); box-shadow: var(--sh-md); border-color: #cfe0ff; }
.file-thumb-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11.5px; }
.file-thumb.is-compact { flex-direction: row; align-items: center; gap: 6px; max-width: none; }
.file-thumb.is-compact .file-thumb-img { width: 28px; height: 28px; border-radius: 6px; }
.file-current { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }

/* Плашка «доступно обновление» после деплоя */
.crm-update-banner {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 80;
  transform: translateX(-50%);
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--brand-grad);
  color: #fff;
  font: 600 13px/1.2 inherit;
  box-shadow: 0 12px 30px rgba(30, 15, 90, .35);
  cursor: pointer;
  animation: ds-pop var(--t-slow) var(--ease-spring) both;
}
.crm-update-banner:hover { box-shadow: 0 16px 36px rgba(30, 15, 90, .45); }

/* ------------------------------ 12. Rail ---------------------------------- */.rail-new, .rail-gpt, .rail-messenger, .rail-profile { transition: transform var(--t-base) var(--ease-spring), box-shadow var(--t-base) var(--ease); }
.rail-new:hover, .rail-gpt:hover { transform: scale(1.1) rotate(8deg); }
.rail-gpt { box-shadow: 0 6px 18px rgba(124, 83, 226, .45); }

/* Единый блок «Клиент»: контакт и компания в одной карточке (как в Битрикс24) */
.client-field { gap: 8px; }
.client-card {
  border: 1px solid #e6ebf3;
  border-radius: var(--r-md);
  background: #fff;
  box-shadow: var(--sh-xs);
}
.client-row { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px; }
.client-row + .client-row { border-top: 1px solid #eef2f7; }
.client-row-label { color: #8b95a3; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.client-row-body { min-width: 0; }
.client-row .field-value { min-height: 0; margin: 0; padding: 0; background: transparent !important; }
.client-field.field-display .client-row .contact-search .contact-preview { display: none; }
.client-row .contact-search { display: grid; gap: 8px; }
.client-row .contact-preview {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.client-row .contact-preview-label { display: none; }
.client-row .contact-preview .name { font-size: 16px; font-weight: 600; }
.client-row .contact-preview .meta { margin-top: 2px; font-size: 12.5px; }
.client-row .contact-preview-actions { gap: 12px; }
.contact-preview-action.is-disabled { cursor: default; }
.contact-preview-action.is-disabled:hover { background: transparent; color: #c6d0dc; }
.client-row .company-preview-badge { display: none; }
.client-row .contact-search-input input { height: 32px; font-size: 12.5px; }
.client-row .contact-search-results { z-index: 25; }
@media (max-width: 640px) {
  .client-row { padding: 10px 12px; }
  .client-row .contact-preview .name { font-size: 15px; }
}

/* ------------------------------ 13. Page motion --------------------------- */
#app > * { animation: ds-up var(--t-slow) var(--ease) backwards; }
#app > .sk-page { animation: none; }
#list-table tbody tr { animation: ds-row var(--t-slow) var(--ease) backwards; }
#list-table tbody tr:nth-child(1) { animation-delay: 0ms; }
#list-table tbody tr:nth-child(2) { animation-delay: 25ms; }
#list-table tbody tr:nth-child(3) { animation-delay: 50ms; }
#list-table tbody tr:nth-child(4) { animation-delay: 75ms; }
#list-table tbody tr:nth-child(5) { animation-delay: 100ms; }
#list-table tbody tr:nth-child(6) { animation-delay: 125ms; }
#list-table tbody tr:nth-child(7) { animation-delay: 150ms; }
#list-table tbody tr:nth-child(n+8) { animation-delay: 175ms; }

.stage-progress-step.is-filled { transform-origin: left center; animation: ds-fill var(--t-slow) var(--ease) backwards; }
.stage-progress-step:nth-child(2) { animation-delay: 40ms; } .stage-progress-step:nth-child(3) { animation-delay: 80ms; }
.stage-progress-step:nth-child(4) { animation-delay: 120ms; } .stage-progress-step:nth-child(5) { animation-delay: 160ms; }
.desk-progress span, .stage-track > span { transform-origin: left center; animation: ds-grow 700ms var(--ease) backwards; }

.robot-card, .robot-chip { transition: transform var(--t-base) var(--ease), box-shadow var(--t-base) var(--ease); }
.robot-card:hover, .robot-chip:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }

/* ------------------------------ 14. Keyframes ----------------------------- */
@keyframes ds-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ds-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ds-row { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ds-pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ds-menu { from { opacity: 0; transform: translateY(-6px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes ds-fill { from { transform: scaleX(0); opacity: 0; } to { transform: none; } }
@keyframes ds-grow { from { transform: scaleX(0); } to { transform: none; } }
@keyframes ds-shimmer { to { background-position: -220% 0; } }
@keyframes ds-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 92, 92, .5); } 60% { box-shadow: 0 0 0 6px rgba(255, 92, 92, 0); } }

/* ------------------------------ 15. Accessibility ------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 900px) {
  .sk-page { margin: -14px -12px 0; }
  .sk-hero { padding: 22px 14px 16px; }
}

/* --------------------- Настройки внешней базы данных -------------------- */
.db-form { display: grid; gap: 16px; }
.db-postgres-fields[hidden],
.db-postgres-fields.is-hidden { display: none; }
.db-ssl-field { align-self: end; }
.checkbox-line {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}
.checkbox-line input { width: auto; margin: 0; }
.db-status-grid {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfd;
}
.db-status-row { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; }
.db-status-row span { color: var(--muted); }
.db-status-row strong { font-weight: 500; overflow-wrap: anywhere; }
.db-test-result {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  font-size: 13px;
}
.db-test-result.is-ok { border-color: #bfe6cd; background: #eefaf2; color: #1f8d55; }
.db-test-result.is-error { border-color: #f2cccc; background: #fff4f4; color: var(--danger); }
.db-test-result.is-pending { color: var(--muted); }
@media (max-width: 700px) {
  .db-status-row { flex-direction: column; gap: 2px; }
}

/* ------------------------------ Модули ---------------------------------- */
.module-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
}
.module-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.module-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.module-title { display: flex; flex-direction: column; gap: 1px; margin-right: auto; }
.module-title h2 { margin: 0; font-size: 17px; }
.module-title span { color: var(--muted); font-size: 12px; }
.module-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: #f1f3f5;
  color: #667085;
}
.module-status.is-on { background: #e8f7ee; color: #1f8d55; }
.module-status.is-warn { background: #fff6e5; color: #9a6b00; }
.module-status.is-off { background: #f1f3f5; color: #667085; }
.module-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.module-switch input { width: auto; margin: 0; }
.module-description { margin: 0; color: var(--muted); font-size: 13px; }
.module-fields { margin-top: 2px; }
.module-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 4px; }
.module-test-result { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 13px; }
.module-test-result.is-ok { border-color: #bfe6cd; background: #eefaf2; color: #1f8d55; }
.module-test-result.is-error { border-color: #f2cccc; background: #fff4f4; color: var(--danger); }
.module-test-result.is-pending { color: var(--muted); }
.section-title { margin: 8px 0 0; font-size: 15px; }
.module-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfd;
}
.module-summary-icon { color: var(--accent); }
.module-summary > div:nth-child(2) { margin-right: auto; }
.event-log { display: grid; gap: 4px; }
.event-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 7px 10px;
  border-radius: 8px;
  background: #f8fafc;
  font-size: 12px;
}
.event-status { font-weight: 600; font-size: 11px; }
.event-status.is-ok { color: #1f8d55; }
.event-status.is-error { color: var(--danger); }
.event-target { font-weight: 500; }
.event-detail { color: var(--muted); flex: 1; min-width: 120px; }
.event-date { color: var(--muted); white-space: nowrap; }

/* -------------------------------- Диск ---------------------------------- */
.disk-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.disk-path { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 13px; }
.disk-crumb {
  border: 0;
  background: none;
  padding: 2px 4px;
  border-radius: 6px;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
}
.disk-crumb:hover { background: var(--accent-soft); }
.disk-sep { color: var(--muted); }
.disk-list { display: grid; gap: 2px; padding: 8px 12px 16px; }
.disk-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13px;
}
.disk-row:hover { background: #f7f9fc; }
.disk-row-icon { width: 20px; text-align: center; }
.disk-row-name {
  border: 0;
  background: none;
  padding: 0;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  flex: 1;
  min-width: 120px;
  overflow-wrap: anywhere;
}
.disk-row-name:hover { color: var(--accent); }
.disk-row-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.disk-empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 13px; }
@media (max-width: 700px) {
  .disk-row { flex-wrap: wrap; }
  .disk-row-name { flex-basis: calc(100% - 40px); }
}

/* ----------------------------- Обновления -------------------------------- */
.update-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
}
.update-summary > div { display: flex; flex-direction: column; gap: 2px; }
.update-summary strong { font-size: 16px; font-weight: 600; }
.update-source { overflow-wrap: anywhere; }
.update-notes {
  max-height: 260px;
  overflow: auto;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfcfd;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.update-release, .update-progress { display: grid; gap: 8px; }

/* ------------------------------ Аналитика -------------------------------- */
.analytics-body { display: grid; gap: 18px; }
.analytics-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.analytics-kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfd;
}
.analytics-kpi span { color: var(--muted); font-size: 12px; }
.analytics-kpi strong { font-size: 22px; font-weight: 600; letter-spacing: -.4px; }
.analytics-kpi small { color: var(--muted); font-size: 11px; }
.analytics-kpi.is-accent { border-color: #bfe6cd; background: #f2fbf6; }
.analytics-kpi.is-good strong { color: #1f8d55; }
.analytics-section { display: grid; gap: 10px; }
.analytics-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 170px;
  padding: 8px 4px 0;
  border-bottom: 1px solid var(--border);
}
.analytics-bar {
  flex: 1;
  min-width: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.analytics-bar-inner {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  width: 100%;
  height: 100%;
}
.analytics-bar-visits, .analytics-bar-leads {
  flex: 1;
  min-height: 0;
  border-radius: 2px 2px 0 0;
  background: #7fa7d9;
}
.analytics-bar-leads { background: #2f9e74; }
.analytics-bar em { color: var(--muted); font-size: 9px; font-style: normal; white-space: nowrap; }
.analytics-legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.analytics-legend span::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 2px;
  background: #7fa7d9;
}
.analytics-legend .legend-leads::before { background: #2f9e74; }
.analytics-table-wrap { overflow-x: auto; }
.analytics-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.analytics-table th {
  padding: 8px 10px;
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.analytics-table td { padding: 8px 10px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.analytics-table tr:last-child td { border-bottom: 0; }
.analytics-table .is-good { color: #1f8d55; }
.analytics-sites-list { display: flex; flex-wrap: wrap; gap: 6px; }
.analytics-site-chip {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.analytics-site-chip strong { font-size: 12px; }
.analytics-site-chip span { color: var(--muted); font-size: 11px; }
.analytics-site-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.analytics-site-chip.is-add {
  border-style: dashed;
  justify-content: center;
  color: var(--accent);
  background: #fbfefc;
}
.analytics-sites-list + .analytics-section, .analytics-sites-list + .analytics-code-card { margin-top: 6px; }
.analytics-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: fit-content;
  max-width: 100%;
  margin-top: 14px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f6f8fa;
}
.analytics-tab {
  padding: 7px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}
.analytics-tab:hover { color: var(--text); background: #eaeff4; }
.analytics-tab.active {
  color: var(--text);
  background: #fff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 32, 51, .08);
}
.analytics-code-card {
  padding: 16px;
  border: 1px solid #cfe8da;
  border-radius: 14px;
  background: linear-gradient(180deg, #f3fbf6 0%, #fff 72%);
}
.analytics-code-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.analytics-code-head .section-title { margin: 0; }
.analytics-help {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 12px;
}
.analytics-help summary { color: #2b4a3c; font-weight: 600; cursor: pointer; }
.analytics-help ol { display: grid; gap: 4px; margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
.analytics-help b { color: var(--text); font-weight: 600; }
.analytics-check-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.analytics-settings .form-grid > .span-2 { grid-column: 1 / -1; }
.analytics-snippet {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  color: #1f2d3d;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.analytics-check-input { min-width: 220px; }
.analytics-divider { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.analytics-select { width: auto; }
@media (max-width: 700px) {
  .analytics-kpi strong { font-size: 18px; }
  .analytics-chart { height: 130px; }
  .analytics-check-input { min-width: 0; width: 100%; }
  .analytics-tabs { width: 100%; }
  .analytics-tab { flex: 1; padding: 7px 8px; text-align: center; }
  .analytics-code-head { flex-direction: column; }
  .analytics-code-head .btn { width: 100%; }
  .analytics-code-card { padding: 12px; }
}
/* ---------------------- Экспресс-аналитика ------------------------------- */
.analytics-hero-controls { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#analytics-overview-controls[hidden], #analytics-overview[hidden], #analytics-express[hidden] { display: none; }
.analytics-express { display: grid; gap: 18px; padding: 16px; }
.express-toolbar { display: grid; gap: 10px; }
.express-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.express-field { display: flex; flex-direction: column; gap: 4px; min-width: 140px; }
.express-field > span { color: var(--muted); font-size: 11px; font-weight: 600; }
.express-field select, .express-field input { height: 34px; min-width: 0; }
.express-manual-row { display: flex; align-items: center; gap: 6px; }
.express-manual-row input { min-width: 125px; }
.express-filter-actions { display: flex; align-items: flex-end; gap: 8px; margin-left: auto; }
.express-period-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.express-drill-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
}
.express-drill-chip button { border: 0; background: transparent; color: inherit; font-size: 16px; line-height: 1; cursor: pointer; }
.express-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.express-card { padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: #fbfcfd; }
.express-chart-host { display: grid; gap: 8px; }
.express-chart-summary { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 12px; }
.express-chart-summary b { color: var(--text); font-weight: 600; }
.express-chart-wrap { display: flex; align-items: stretch; gap: 8px; }
.express-chart-scale {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 0 0 28px;
  padding-bottom: 20px;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}
.analytics-chart.express-chart {
  flex: 1;
  min-width: 0;
  height: 200px;
  background-image: repeating-linear-gradient(to top, #eef1f5 0 1px, transparent 1px 50px);
}
.analytics-bar-won { flex: 1; min-height: 0; border-radius: 2px 2px 0 0; background: #d08a3e; }
.analytics-legend .legend-won::before { background: #d08a3e; }
.express-funnel { display: grid; gap: 4px; }
.express-funnel-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.express-funnel-legend span { display: inline-flex; align-items: center; gap: 5px; }
.express-funnel-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; }
.express-funnel-legend .is-created { background: #7fa7d9; }
.express-funnel-legend .is-previous { background: #b3c5dc; }
.express-funnel-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 84px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 7px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.express-funnel-row:hover { background: #f4f8f6; }
.express-funnel-row.active { background: var(--accent-soft); }
.express-funnel-name { display: flex; flex-direction: column; font-size: 12px; font-weight: 600; }
.express-funnel-name small { color: var(--muted); font-size: 10px; font-weight: 400; }
.express-funnel-track { display: flex; height: 16px; overflow: hidden; border-radius: 8px; background: #eef2f6; }
.express-funnel-track i { display: block; height: 100%; }
.express-funnel-track .is-created { background: #7fa7d9; }
.express-funnel-track .is-previous { background: #b3c5dc; }
.express-funnel-value { display: flex; justify-content: flex-end; gap: 6px; font-size: 12px; }
.express-funnel-value small { color: var(--muted); }
.express-table tr.express-clickable { cursor: pointer; }
.express-table tr.express-clickable:hover { background: #f7faf9; }
.express-table tr.express-clickable.active { background: var(--accent-soft); }
.express-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}
.express-badge.is-good { background: #e9f7ef; color: #1f8d55; }
.express-badge.is-bad { background: #fdecec; color: #b23b3b; }
@media (max-width: 1000px) {
  .express-charts { grid-template-columns: 1fr; }
  .express-filter-actions { margin-left: 0; }
}
@media (max-width: 700px) {
  .analytics-express { padding: 12px; }
  .express-field { min-width: 100%; }
  .express-field select, .express-field input { width: 100%; }
  .express-manual-row { width: 100%; }
  .express-manual-row input { flex: 1; min-width: 0; }
  .express-funnel-row { grid-template-columns: 96px minmax(0, 1fr) 62px; gap: 6px; }
}
