/* Повторно используемые элементы: кнопки, поля, аватары, карточки, окна. */

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 600;
  background: var(--blue);
  color: var(--label-on-accent);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}

.btn:active {
  transform: scale(0.97);
  background: var(--blue-pressed);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--blue);
}

.btn-secondary:active {
  background: var(--bg-active);
}

.btn-danger {
  background: var(--red);
}

.btn-plain {
  background: none;
  color: var(--blue);
  height: auto;
  padding: 6px 8px;
  font-weight: 500;
}

.btn-plain:active {
  background: var(--bg-hover);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--blue);
  flex: 0 0 36px;
}

.btn-icon:hover {
  background: var(--bg-hover);
}

.btn-icon:active {
  background: var(--bg-active);
  transform: scale(0.94);
}

.icon {
  width: 22px;
  height: 22px;
  display: block;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

/* ---------- Поля ввода ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--label-secondary);
  padding-left: 2px;
}

.input {
  height: 46px;
  padding: 0 14px;
  border-radius: var(--r-md);
  background: var(--bg-input);
  border: 1px solid transparent;
  outline: none;
  font-size: 17px;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  width: 100%;
}

.input:focus {
  border-color: var(--blue);
  background: var(--bg);
}

.input.is-invalid {
  border-color: var(--red);
}

/* Поле кода второго фактора: крупные разреженные цифры */
.input-code {
  text-align: center;
  letter-spacing: 8px;
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  height: 58px;
  padding-left: 8px;
}

.search-field {
  position: relative;
  flex: 1;
}

.search-input {
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--bg-input);
  border: none;
  outline: none;
  width: 100%;
  padding: 0 12px 0 34px;
  font-size: 15px;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--label-secondary);
  pointer-events: none;
}

/* ---------- Аватар ---------- */

.avatar {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.2px;
  user-select: none;
  position: relative;
  /* Цвет подставляется из JS по идентификатору — у каждого свой, но постоянный */
  background: var(--avatar-bg, var(--gray));
}

.avatar-sm {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.avatar-lg {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

.avatar-online::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 13px;
  height: 13px;
  border-radius: var(--r-full);
  background: var(--green);
  border: 2.5px solid var(--bg);
}

/* ---------- Строки списка ---------- */

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  width: 100%;
  text-align: left;
  background: none;
  transition: background var(--dur-fast) var(--ease);
  position: relative;
}

.row:hover {
  background: var(--bg-hover);
}

.row:active {
  background: var(--bg-active);
}

.row.is-selected {
  background: var(--blue-soft);
}

/* Разделитель начинается после аватара, как в iOS */
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 74px;
  right: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}

.row-body {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  font-size: 14px;
  color: var(--label-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: 0 0 auto;
}

.badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--r-full);
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-muted {
  background: var(--gray);
}

/* Нейтральный счётчик — например, число дел у клиента. */
.badge-neutral {
  background: var(--bg-active);
  color: var(--label-secondary);
}

/* Включённый переключатель в шапке (архив в картотеке). */
.btn-icon.is-active {
  background: var(--blue-soft);
}

/* Статус заявки на подтверждение — обращает на себя внимание. */
.badge-warn {
  background: var(--orange, #FF9500);
  color: #fff;
}

/* ---------- Пустые состояния ---------- */

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
  color: var(--label-secondary);
}

.empty-icon {
  width: 56px;
  height: 56px;
  color: var(--label-tertiary);
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--label);
}

/* ---------- Модальные окна ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in var(--dur-fast) var(--ease);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 420px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur) var(--ease);
}

@keyframes modal-in {
  from { transform: translateY(16px) scale(0.97); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--separator);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-foot {
  padding: 12px 18px 16px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--separator);
}

.modal-foot .btn {
  flex: 1;
}

/* На телефоне окно выезжает снизу листом */
@media (max-width: 899px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: none;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 88vh;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheet-in var(--dur) var(--ease);
  }

  @keyframes sheet-in {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
}

/* ---------- Всплывающее меню ---------- */

.menu {
  position: fixed;
  min-width: 200px;
  background: rgba(250, 250, 250, 0.96);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 200;
  animation: menu-in var(--dur-fast) var(--ease);
}

@keyframes menu-in {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}

.menu-item + .menu-item {
  border-top: 1px solid var(--separator);
}

.menu-item:hover {
  background: var(--bg-hover);
}

.menu-item.is-danger {
  color: var(--red);
}

/* ---------- Всплывающие уведомления ---------- */

.toasts {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
  width: min(440px, calc(100vw - 32px));
}

.toast {
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  padding: 11px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: toast-in var(--dur) var(--ease);
}

.toast.is-error {
  background: var(--red);
}

@keyframes toast-in {
  from { transform: translateY(-14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Сводка раздела в разработке ---------- */

.stub {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 24px;
  text-align: center;
}

.stub-badge {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--blue);
  background: var(--blue-soft);
  padding: 5px 12px;
  border-radius: var(--r-full);
}

.stub-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 380px;
  text-align: left;
  color: var(--label-secondary);
  font-size: 14px;
}

.stub-list li {
  display: flex;
  gap: 8px;
}

.stub-list li::before {
  content: "•";
  color: var(--blue);
}

/* ---------- Карточка клиента: контакты ---------- */

/* Заголовок раздела в карточке со счётчиком справа. */
.card-section {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 18px 16px 6px;
}

.card-section-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--label-secondary);
}

.card-section-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  opacity: 0.7;
}

/* Строка контакта: иконка, значение, кнопка копирования. */
.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  position: relative;
}

.contact-row + .contact-row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 44px;
  right: 16px;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
}

.contact-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--blue);
}

.contact-main {
  flex: 1;
  min-width: 0;
}

.contact-label {
  font-size: 13px;
  color: var(--label-secondary);
}

.contact-value {
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

a.contact-value {
  color: var(--blue);
  text-decoration: none;
}

.contact-note {
  font-size: 13px;
  color: var(--label-secondary);
}

/* Шеврон-указатель «перейти» справа в строке (повёрнутая стрелка «назад»). */
.rot180 {
  transform: rotate(180deg);
  color: var(--label-secondary);
  flex: 0 0 auto;
}

/* Отпечаток ключа шифрования — моноширинным, чтобы группы читались. */
.key-fingerprint {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  letter-spacing: 1px;
  word-break: break-all;
}

/* ---------- Безопасность ключей (E2EE, этап D) ---------- */

/* Щит в шапке чата: проверено — зелёный, тревога — оранжевый. */
.btn-icon.shield-ok { color: var(--green, #34C759); }
.btn-icon.shield-alert { color: var(--orange, #FF9500); }

/* Баннер о смене ключей — между шапкой и лентой. */
.sec-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255, 149, 0, 0.12);
  color: var(--label);
  font-size: 14px;
  border-bottom: 1px solid var(--separator);
}

.sec-banner .icon { color: var(--orange, #FF9500); flex: 0 0 auto; }
.sec-banner span { flex: 1; min-width: 0; }

.sec-banner-btn {
  flex: 0 0 auto;
  background: none;
  color: var(--blue);
  font-weight: 600;
  font-size: 14px;
  padding: 4px 8px;
}

/* Код безопасности — моноширинным, крупно, для сверки вслух. */
.safety-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 20px;
  letter-spacing: 2px;
  line-height: 1.6;
  text-align: center;
  padding: 16px;
  background: var(--bg-grouped);
  border-radius: var(--r-md, 12px);
  word-spacing: 4px;
}

/* Подпись внизу карточки: когда заведена. */
.card-meta {
  padding: 20px 16px 8px;
  font-size: 13px;
  color: var(--label-secondary);
}
