/*
 * ib-button
 * Источник: Figma "ipotekabank.uz — Design System", Actions / Controls → Button
 * (значения подтверждены через get_design_context на реальных вариантах компонента).
 *
 * Focus-состояние — DEV DRAFT (в Figma не нарисовано), см. CHANGELOG.md.
 * Loading-состояние — DEV DRAFT (в Figma не нарисовано), см. CHANGELOG.md.
 */

.ib-button {
  box-sizing: border-box; /* высота 40/48 вместе с отступами, и у ссылки <a class="ib-button"> (у <button> так по умолчанию) */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs); /* 8px — подтверждено для всех размеров */
  border: none;
  border-radius: var(--radius-full); /* кнопки в Figma всегда pill-shape */
  font-family: var(--font-button-family);
  font-weight: var(--font-button-weight);
  line-height: var(--font-button-line-height);
  letter-spacing: var(--font-button-letter-spacing);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.2s ease;
}

.ib-button:active:not(:disabled),
.ib-button[data-pressed]:not(:disabled) {
  transform: scale(var(--press-scale)); /* «прожимается» при нажатии, как вкладки; DEV DRAFT */
}

.ib-button[hidden] {
  display: none; /* без этого display: inline-flex у .ib-button перекрывает атрибут hidden, и скрытая кнопка остаётся на экране */
}

.ib-button:disabled {
  background-color: var(--action-disabled-bg);
  color: var(--text-disabled);
  cursor: not-allowed;
}

.ib-button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ===== Size (подтверждено: height/padding/font-size/icon-size различаются по Size, не по общей шкале spacing) ===== */

.ib-button--sm {
  height: 32px;
  padding: 6px 16px;
  font-size: var(--font-button-size-sm);
}

.ib-button--md {
  height: 40px;
  padding: 10px 20px;
  font-size: var(--font-button-size-md);
}

.ib-button--lg {
  height: 48px;
  padding: 12px 24px;
  font-size: var(--font-button-size-lg);
}

.ib-button__icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.ib-button--sm .ib-button__icon {
  width: 16px;
  height: 16px;
}

/* ===== Type ===== */

.ib-button--primary {
  background-color: var(--action-primary);
  color: var(--text-on-action-primary);
}
.ib-button--primary:hover:not(:disabled) {
  background-color: var(--action-primary-hover);
}
.ib-button--primary:active:not(:disabled),
.ib-button--primary[data-pressed]:not(:disabled) {
  background-color: var(--action-primary-pressed);
}

.ib-button--secondary {
  background-color: var(--action-secondary);
  color: var(--text-primary);
}
.ib-button--secondary:hover:not(:disabled) {
  background-color: var(--action-secondary-hover);
}
.ib-button--secondary:active:not(:disabled),
.ib-button--secondary[data-pressed]:not(:disabled) {
  background-color: var(--action-secondary-pressed);
}

.ib-button--ghost {
  background-color: transparent;
  color: var(--action-ghost-text);
}
.ib-button--ghost:hover:not(:disabled) {
  background-color: var(--action-ghost-hover);
}
.ib-button--ghost:active:not(:disabled),
.ib-button--ghost[data-pressed]:not(:disabled) {
  background-color: var(--action-ghost-pressed);
}

.ib-button--white {
  background-color: var(--action-white);
  color: var(--text-primary);
}
.ib-button--white:hover:not(:disabled) {
  background-color: var(--action-white-hover);
}
.ib-button--white:active:not(:disabled),
.ib-button--white[data-pressed]:not(:disabled) {
  background-color: var(--action-white-pressed);
}

/* Accent: оранжевая кнопка на фото (Hero, фото-баннер). Из Figma только цвет #FF6600; Hover и Pressed — DEV DRAFT */
.ib-button--accent {
  background-color: var(--action-accent);
  color: var(--text-inverse);
}
.ib-button--accent:hover:not(:disabled) {
  background-color: var(--action-accent-hover);
}
.ib-button--accent:active:not(:disabled),
.ib-button--accent[data-pressed]:not(:disabled) {
  background-color: var(--action-accent-pressed);
}

/* ===== Icon-only =====
   Подтверждено из Figma: паддинг у icon-only ТОТ ЖЕ, что у текстовой кнопки того же
   размера (не уменьшается) — переопределений не требуется, размер задаётся самим
   --radius-full + квадратной иконкой внутри стандартного padding.
   Обязательно: aria-label на <button>, см. README. */

/* ===== Loading (DEV DRAFT — не из Figma) ===== */

.ib-button--loading {
  position: relative;
  pointer-events: none;
}
.ib-button--loading .ib-button__icon,
.ib-button--loading .ib-button__label {
  visibility: hidden;
}
.ib-button--loading::after {
  content: "";
  box-sizing: border-box; /* 16×16 вместе с рамкой: иначе круг 20×20 и центр смещён на 2px вниз и вправо */
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: ib-button-spin 0.6s linear infinite;
}

@keyframes ib-button-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ib-button:active:not(:disabled),
  .ib-button[data-pressed]:not(:disabled) {
    transform: none;
  }

  .ib-button--loading::after {
    animation-duration: 1.2s;
  }
}
