/* ==========================================================
   Этап 3. Библиотека компонентов
   ========================================================== */

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 41px; padding: 0 var(--sp-6);
  border: 1px solid transparent; border-radius: var(--r-btn);
  font-size: var(--fs-base); font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.btn--primary { background: var(--accent); color: var(--text-on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--outline { background: var(--bg-panel); border-color: var(--border-strong); color: var(--text); }
.btn--outline:hover { background: var(--bg-card); }
.btn--sm { height: 36px; padding: 0 var(--sp-4); font-size: var(--fs-sm); }
.btn--block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--accent-disabled); color: #fff; cursor: not-allowed; }
.btn--outline:disabled { background: var(--bg-card); color: var(--text-faint); border-color: var(--border); }

/* ---------- Ссылка-действие (в пустых состояниях) ---------- */
.link-action { font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.link-action:hover { color: var(--accent-hover); }
.link-plain { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Поля ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field, .field + .toggle-row, .form-stack > * + * { margin-top: var(--sp-5); }
.label { font-size: var(--fs-sm); color: var(--text-muted); }
.input, .textarea, .select {
  width: 100%; min-height: 44px; padding: 0 var(--sp-4);
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-input);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea { padding: var(--sp-3) var(--sp-4); min-height: 104px; resize: vertical; line-height: var(--lh-base); }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
.input:disabled, .textarea:disabled, .select:disabled { opacity: .6; cursor: not-allowed; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235B6B7E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.select--sm { min-height: 40px; }
.field-row { display: flex; align-items: center; gap: var(--sp-3); }
.field-row > .input { flex: 1; }
.field-row__sep { color: var(--text-muted); font-size: var(--fs-sm); }
.hint { font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- Переключатель ---------- */
.toggle { position: relative; display: inline-block; width: 40px; height: 24px; flex: none; }
.toggle input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.toggle__track { position: absolute; inset: 0; border-radius: var(--r-pill); background: #B9C6D4; transition: background var(--transition); pointer-events: none; }
.toggle__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(15,27,42,.25); transition: transform var(--transition); }
.toggle input:checked + .toggle__track { background: var(--accent); }
.toggle input:checked + .toggle__track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle__track { box-shadow: var(--focus-ring); }
.toggle input:disabled { cursor: not-allowed; }
.toggle input:disabled + .toggle__track { opacity: .5; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4) 0; border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.toggle-row:first-of-type { border-top: 1px solid var(--border); }

/* ---------- Чекбокс ---------- */
.check { display: flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer; line-height: 1.4; }
.check input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 18px; height: 18px; margin: 2px 0 0;
  border: 1.5px solid var(--border-strong); border-radius: 5px; background: var(--bg-panel);
  display: grid; place-items: center; cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ""; width: 9px; height: 5px; margin-top: -2px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(-45deg); }
.check input:focus-visible { box-shadow: var(--focus-ring); }

/* ---------- Табы (подчёркнутые) ---------- */
.tabs { display: flex; gap: var(--sp-6); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; flex: none; padding: var(--sp-3) 0 var(--sp-3);
  background: none; border: 0; color: var(--text-muted);
  font-size: var(--fs-md); text-decoration: none; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--text); font-weight: 500; }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--text);
}

/* ---------- «Пилюли»-фильтры ---------- */
.pills { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.pill {
  height: 36px; padding: 0 var(--sp-4); border: 0; border-radius: var(--r-pill);
  background: var(--bg-card); color: var(--text-muted); font-size: var(--fs-base);
  transition: background var(--transition), color var(--transition);
}
.pill:hover { background: var(--bg-card-hover); color: var(--text); }
.pill[aria-pressed="true"] { background: var(--text); color: #fff; }

/* ---------- Бейджи ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); background: var(--bg-card);
  font-size: var(--fs-xs); font-weight: 500; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--status-idle); }
.badge--warm, .badge--owner { background: var(--owner-bg); }
.badge--warm::before, .badge--owner::before { background: var(--owner-dot); }
.badge--blue, .badge--manager { background: var(--manager-bg); }
.badge--blue::before, .badge--manager::before { background: var(--manager-dot); }
.badge--green::before { background: var(--success); }
.status {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); background: var(--bg-card); font-size: var(--fs-xs); font-weight: 500; white-space: nowrap;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--status-idle); }
.status--running::before { background: var(--success); }

/* ---------- Баннер-предупреждение ---------- */
.banner {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  max-width: 720px; padding: var(--sp-3) var(--sp-4);
  background: var(--warn-bg); border-left: 3px solid var(--warn-line);
  border-radius: 4px 12px 12px 4px; font-size: var(--fs-base);
}
.banner .icon { margin-top: 2px; color: var(--warn-icon); }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; min-width: 560px; border-collapse: collapse; }
.table th {
  padding: 0 var(--sp-3) var(--sp-3) 0; text-align: left;
  font-size: var(--fs-sm); font-weight: 400; color: var(--text-muted); white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td { padding: var(--sp-3) var(--sp-3) var(--sp-3) 0; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table .num { font-variant-numeric: tabular-nums; }
.table .cell-muted { color: var(--text-muted); }
.table tbody tr:not(.row-details):hover { background: #F8FAFC; }
.row-toggle {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 0; background: none; border: 0; text-align: left; color: inherit; cursor: pointer;
}
.row-toggle::before {
  content: ""; width: 6px; height: 6px; flex: none;
  border-right: 1.5px solid var(--text-muted); border-top: 1.5px solid var(--text-muted);
  transform: rotate(45deg); transition: transform var(--transition);
}
.row-toggle[aria-expanded="true"]::before { transform: rotate(135deg); }
.row-details td { padding: var(--sp-4); background: var(--bg-card); color: var(--text-muted); }
.row-details[hidden] { display: none; }
.cell-clip { display: block; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Пустое состояние ---------- */
.empty { padding: var(--sp-5) 0; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.empty p { max-width: 460px; }
.empty .link-action { display: inline-block; margin-top: var(--sp-2); }

/* ---------- Воронка из шевронов ---------- */
.funnel { --tip: 26px; --gap: 4px; --r: 22px; display: flex; }
.funnel__step {
  flex: 1 1 0; min-width: 0; min-height: 133px;
  display: flex; flex-direction: column; justify-content: center;
  padding: var(--sp-5) calc(var(--tip) + var(--sp-2)) var(--sp-5) var(--sp-6);
  color: var(--text);
  clip-path: polygon(0 0, calc(100% - var(--tip)) 0, 100% 50%, calc(100% - var(--tip)) 100%, 0 100%, var(--tip) 50%);
}
.funnel__step:first-child { border-radius: var(--r) 0 0 var(--r); clip-path: polygon(0 0, calc(100% - var(--tip)) 0, 100% 50%, calc(100% - var(--tip)) 100%, 0 100%); }
.funnel__step:last-child { border-radius: 0 var(--r) var(--r) 0; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, var(--tip) 50%); padding-right: var(--sp-6); }
.funnel__step:only-child { border-radius: var(--r); clip-path: none; padding-right: var(--sp-6); }
.funnel__step + .funnel__step { margin-left: calc(var(--gap) - var(--tip)); padding-left: calc(var(--tip) + var(--sp-6)); }
.funnel__step--wide { flex-grow: 2.4; }
.funnel__step--blue   { background: var(--funnel-blue); }
.funnel__step--sage   { background: var(--funnel-sage); }
.funnel__step--yellow { background: var(--funnel-yellow); }
.funnel__step--orange { background: var(--funnel-orange); }
.funnel__num { font-size: var(--fs-num); line-height: 1.1; font-weight: 400; }
.funnel__label { margin-top: var(--sp-2); font-size: var(--fs-sm); font-weight: 600; }
.funnel__note { margin-top: 2px; font-size: var(--fs-xs); color: rgba(15, 27, 42, .65); }

@media (max-width: 900px) {
  .funnel { flex-direction: column; gap: var(--sp-2); }
  .funnel__step, .funnel__step:first-child, .funnel__step:last-child, .funnel__step + .funnel__step {
    clip-path: none; border-radius: 18px; margin-left: 0; min-height: 0;
    padding: var(--sp-4) var(--sp-6);
  }
  .funnel__step--wide { flex-grow: 1; }
  .split { grid-template-columns: 1fr !important; }
  .split > * + * { border-left: 0 !important; padding-left: 0 !important; }
}

/* ---------- Две колонки с разделителем (формы настроек) ---------- */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.split > * { min-width: 0; }
.split > :first-child { padding-right: var(--sp-8); }
.split > * + * { padding-left: var(--sp-8); border-left: 1px solid var(--border); }
.block-title { margin-bottom: var(--sp-4); }
