/* ════════════════════════════════════════════════════════════════
   amoCRM Inspector — оформление в дизайн-системе amoCRM.
   Токены сняты с живого интерфейса amoCRM (PT Sans, палитра,
   радиус 4px, UPPERCASE-заголовки таблиц).
   ════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любые display из правил ниже. */
[hidden] { display: none !important; }

:root {
  --bg:          #f5f5f5;   /* фон рабочей области amoCRM            */
  --surface:     #ffffff;   /* белые панели                          */
  --surface-alt: #fbfbfb;   /* фон вторичных блоков (модалки amoCRM)  */
  --border:      #e8eaeb;   /* стандартный бордер amoCRM             */
  --border-soft: #f0f0f1;   /* разделители строк таблицы             */
  --text:        #363b44;   /* основной текст                        */
  --muted:       #92989b;   /* приглушённый текст                    */
  --muted-2:     #6e747a;   /* заголовки колонок                     */
  --blue:        #4c8bf7;   /* основная кнопка действия              */
  --blue-hover:  #3b7af0;
  --link:        #1b94d7;   /* ссылки amoCRM                         */
  --radius:      4px;
  --ring:        0 0 0 3px rgba(76, 139, 247, .22);  /* кольцо фокуса */
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  color-scheme: light;
  font-family: 'PT Sans', Arial, sans-serif;
  font-size: 13px;
}

/* Видимый фокус для клавиатуры — без него интерфейс недоступен. */
:focus-visible { outline: none; box-shadow: var(--ring); }

/* Уважаем системную настройку «уменьшить движение». */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ── Верхняя панель ───────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 11px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  border-radius: var(--radius);
  font-size: 13px;
}
.brand h1 { margin: 0; font-size: 15px; font-weight: 700; }
.subtitle { font-size: 11px; color: var(--muted); }

.account-box { display: flex; align-items: center; gap: 8px; }
.account-box label {
  font-size: 11px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}

select, input[type="search"] {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 34px;
  padding: 0 10px;
  outline: none;
}
input[type="search"]::placeholder { color: var(--muted); }
/* Нативная кнопка-крестик очистки — курсор-указатель вместо стрелки. */
input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }
/* Селекты — единый со всеми контролами вид и своя стрелка amoCRM. */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2392989b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select:hover { border-color: #d6d9db; }
select:focus, input[type="search"]:focus { border-color: var(--blue); }
#account { min-width: 230px; }

button {
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  height: 34px;
  padding: 0 16px;
  border: 1px solid transparent;
  transition: background-color .12s ease, border-color .12s ease;
}
#reload { padding: 0 11px; font-size: 14px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-primary:disabled { background: #b9cdf7; cursor: default; }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: #f3f4f5; }

/* ── Заглушка «Начало работы» ─────────────────────── */
.placeholder { display: flex; justify-content: center; padding: 56px 24px; }
.placeholder-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 30px;
  max-width: 460px;
}
.placeholder-card h2 { margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.placeholder-card ol { margin: 0; padding-left: 18px; line-height: 1.85; }
.muted { color: var(--muted); }
#empty-status { margin-top: 14px; font-size: 12px; }
#empty-status.error { color: #d1495b; }

/* ── Тулбар фильтров ──────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
}
#search { flex: 0 0 320px; }
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted-2);
  font-size: 12px;
}
.spacer { flex: 1; }
.summary { font-size: 12px; color: var(--muted); }
.summary b { color: var(--text); font-weight: 700; }

/* ── Таблица ──────────────────────────────────────── */
.table-wrap {
  margin: 0 20px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 210px);
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }

/* Заголовки колонок — фирменный стиль amoCRM: UPPERCASE, 12px,
   серый, жирный, с трекингом. */
thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted-2);
  padding: 13px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th.col-num { cursor: default; width: 46px; text-align: center; }
thead th:hover:not(.col-num) { color: var(--text); }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  font-size: 13px;
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f4f6f8; }
tbody tr.disabled { opacity: .5; }
tbody tr:last-child td { border-bottom: none; }

.col-num { text-align: center; color: var(--muted); }
.cell-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted-2);
}
.cell-type { color: var(--muted-2); }
.cell-muted { color: #c2c6ca; }
.yes { color: #2f8c4d; }
.no  { color: #c2c6ca; }

/* ── Боковая панель деталей ───────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(54, 59, 68, .35);
  z-index: 30;
}
.detail {
  position: fixed;
  top: 0; right: 0;
  width: 420px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 22px rgba(54, 59, 68, .14);
}
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.detail-head h3 { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.4; }
#detail-close { padding: 6px 10px; }
#detail-body { padding: 16px 20px; overflow: auto; }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
}
.detail-row .k { color: var(--muted); white-space: nowrap; }
.detail-row .v { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.detail-section-title {
  margin: 26px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted-2);
  font-weight: 700;
}
.enum-list { list-style: none; margin: 0; padding: 0; }
.enum-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 5px;
}
.enum-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex: 0 0 10px;
  border: 1px solid rgba(54, 59, 68, .12);
}
.enum-name { flex: 1; }
.enum-total { color: var(--muted); font-size: 11px; }
.detail-json {
  margin: 0;
  font-size: 11px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px;
  overflow: auto;
}

/* ── Экраны и общие блоки ─────────────────────────────────────── */
.page {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.page-head h2 { margin: 0; font-size: 17px; font-weight: 700; }

.link-back {
  background: none;
  border: none;
  padding: 0;
  height: auto;
  margin-bottom: 12px;
  font-weight: 400;
  color: var(--link);
}
.link-back:hover { text-decoration: underline; }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
  color: var(--muted-2);
  margin: 6px 0 10px;
}

.empty-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  color: var(--muted);
  font-size: 13px;
}
.loading-line { padding: 18px 4px; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 700;
}
.btn-ghost:hover { color: #d1495b; }

/* ── Список аккаунтов ─────────────────────────────────────────── */
.cards { display: flex; flex-direction: column; gap: 8px; }
.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  height: auto;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.account-card:hover { border-color: #ccd6e4; background: #f8f9fb; }
.account-card__name { font-size: 14px; }
.account-card__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.account-card__right { display: flex; align-items: center; gap: 14px; }
.account-card__snaps { font-size: 12px; color: var(--muted); }
.account-card__arrow { font-size: 20px; color: #c2c6ca; line-height: 1; }

/* ── Снимки ───────────────────────────────────────────────────── */
.snap-status {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.snap-status_progress { background: #eaf2fe; color: #2f6fd6; }
.snap-status_error    { background: #fdeaec; color: #c0392b; }

.snap-list { display: flex; flex-direction: column; gap: 6px; }
.snap-row {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s ease, background-color .15s ease;
}
.snap-row:hover { border-color: #ccd6e4; background: #f8f9fb; }
.snap-row__main {
  flex: 1;
  min-width: 0;
  height: auto;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  padding: 11px 14px;
  cursor: pointer;
}
.snap-row__date { font-size: 13px; }
.snap-row__sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.snap-row__actions { display: flex; align-items: center; padding-right: 8px; }
.snap-row__actions button { height: 30px; padding: 0 12px; }

/* ── Шапка экрана снимка ──────────────────────────────────────── */
.snapshot-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.snapshot-bar .link-back { margin: 0; font-size: 16px; }
#snapshot-meta { font-size: 13px; }

/* ── Экран входа ──────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand h1 { margin: 0; font-size: 16px; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12px; color: var(--muted-2); font-weight: 700; }
.field input {
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 36px;
  padding: 0 10px;
  outline: none;
}
.field input:focus { border-color: var(--blue); }
.login-error {
  background: #fdeaec;
  color: #c0392b;
  border-radius: var(--radius);
  padding: 8px 11px;
  font-size: 12px;
}
.login-card .btn-primary { height: 38px; margin-top: 4px; }

/* ── Топбар: пользователь ─────────────────────────── */
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: var(--muted-2); }

/* ── Уведомление (демо-режим) ─────────────────────── */
.notice {
  background: #fff4e0;
  color: #9a6207;
  border: 1px solid #f0d8a8;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  margin-bottom: 16px;
}

/* ── Пользователи (админ-панель) ──────────────────── */
.user-create {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.user-create__row { display: flex; gap: 14px; margin-bottom: 14px; }
.user-create__row .field { flex: 1; min-width: 0; }
.user-create__actions { display: flex; align-items: center; gap: 8px; }

#users-search { width: 100%; margin-bottom: 12px; }

.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
}
.user-row.inactive { opacity: .6; }
.user-row__name { font-size: 13px; }
.user-row__name .self-mark { color: var(--muted); font-weight: 400; }
.user-row__email { font-size: 12px; color: var(--muted); margin-top: 2px; }
.user-row__controls { display: flex; align-items: center; gap: 14px; }
.user-row__controls select { height: 30px; padding: 0 26px 0 8px; }
.user-row__controls button { height: 30px; padding: 0 12px; }

/* Тумблер активности */
.toggle-box { display: flex; align-items: center; gap: 8px; }
.toggle-label { font-size: 12px; color: var(--muted-2); width: 56px; }
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; flex: 0 0 36px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute;
  inset: 0;
  background: #cfd4d8;
  border-radius: 20px;
  cursor: pointer;
  transition: background .15s;
}
.toggle .track::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(54, 59, 68, .3);
  transition: transform .15s;
}
.toggle input:checked + .track { background: var(--blue); }
.toggle input:checked + .track::before { transform: translateX(16px); }
.toggle input:disabled + .track { opacity: .5; cursor: default; }
.toggle input:focus-visible + .track { box-shadow: var(--ring); }

/* ── Кастомный выпадающий список (dropdown.js) ────── */
.dd {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 34px;
  min-width: 160px;
  max-width: 100%;
  padding: 0 30px 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: border-color .12s ease;
}
.dd:hover { border-color: #d0d4d8; }
.dd.dd-open { border-color: var(--blue); }
.dd.dd-disabled { opacity: .55; pointer-events: none; }
.dd-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-value.dd-placeholder { color: var(--muted); }
/* Шеврон — повёрнутый уголок из бордеров. */
.dd-chevron {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -5px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .14s ease;
}
.dd.dd-open .dd-chevron { transform: rotate(-135deg); margin-top: -2px; }

.dd-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  z-index: 60;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(54, 59, 68, .16);
}
.dd-search {
  width: 100%;
  height: 30px;
  margin-bottom: 6px;
  padding: 0 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.dd-search:focus-visible { border-color: var(--blue); box-shadow: var(--ring); }
.dd-list { max-height: 240px; overflow-y: auto; }
.dd-option {
  padding: 7px 9px;
  border-radius: var(--radius);
  white-space: nowrap;
  cursor: pointer;
}
.dd-option.dd-hl { background: #eef2f8; }
.dd-option.dd-selected { color: var(--blue); font-weight: 700; }
.dd-empty { padding: 8px 9px; font-size: 12px; color: var(--muted); }

/* В форме создания пользователя dropdown занимает всю ширину поля. */
.field .dd { display: flex; width: 100%; min-width: 0; }
