/* ============================================================
   UI-компоненты: кнопки, карточки, поля, модалки, тосты, ...
   ============================================================ */

/* --- Button --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 44px;
  padding: 0 var(--s-5);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  transition: transform var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn--primary {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: var(--shadow-sm);
}
.btn--primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-md); }

.btn--secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}
.btn--secondary:hover { background: var(--bg-hover); }

.btn--ghost {
  background: transparent;
  color: var(--text);
}
.btn--ghost:hover { background: var(--bg-hover); }

.btn--danger {
  background: var(--danger);
  color: white;
}
.btn--danger:hover { background: #B83535; }

.btn--full { width: 100%; }
.btn--sm { min-height: 36px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--lg { min-height: 52px; padding: 0 var(--s-6); font-size: var(--fs-md); }

.btn--icon {
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
}

/* --- Card --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-xs);
  border: 1px solid var(--border);
}

.card--flat { box-shadow: none; }
.card--elevated { box-shadow: var(--shadow-md); }
.card--accent { border-left: 3px solid var(--primary); }

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s-4);
  gap: var(--s-3);
}

.card__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}

.card__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* --- Input / Field --- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.field__label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}

.field__input,
.field__textarea,
.field__select {
  min-height: 44px;
  padding: var(--s-3) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}

.field__textarea { min-height: 96px; resize: vertical; padding-top: var(--s-3); }

.field__input:focus,
.field__textarea:focus,
.field__select:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
  outline: none;
}

.field__input::placeholder { color: var(--text-muted); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field__error { font-size: var(--fs-xs); color: var(--danger); }

/* --- Badge --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 3px var(--s-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
}

.badge--primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--accent { background: var(--accent-soft); color: var(--accent); }

/* --- Avatar --- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar--sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-md); }
.avatar--xl { width: 80px; height: 80px; font-size: var(--fs-xl); }

.avatar--ring {
  box-shadow: 0 0 0 3px var(--bg-elevated), 0 0 0 5px var(--primary);
}

/* --- Progress bar --- */
.progress {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--t-slow);
}

/* --- Skeleton --- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 0%,
    var(--bg-hover) 50%,
    var(--bg-subtle) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton--text { height: 14px; margin: var(--s-2) 0; }
.skeleton--title { height: 22px; width: 60%; margin-bottom: var(--s-3); }
.skeleton--card { height: 96px; border-radius: var(--radius-lg); }

/* --- Empty state --- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--s-10) var(--s-5);
  gap: var(--s-4);
}

.empty__icon {
  font-size: 48px;
  line-height: 1;
  color: var(--primary);
  opacity: 0.85;
}
.empty__icon .fas,
.empty__icon .far,
.empty__icon .fab {
  font-size: inherit;
}

.empty__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}

.empty__text {
  color: var(--text-secondary);
  max-width: 320px;
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-h) + var(--s-4));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
  width: calc(100% - var(--s-8));
  max-width: 420px;
}

@media (min-width: 768px) {
  .toast-container {
    left: auto;
    right: var(--s-6);
    bottom: var(--s-6);
    transform: none;
  }
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--text);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  animation: toast-in var(--t-spring);
}

.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--warning { background: var(--warning); color: #1A1A1A; }

.toast__icon { font-size: var(--fs-lg); }
.toast__close { margin-left: auto; opacity: 0.7; }

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

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade-in var(--t-base);
}

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background: var(--bg-elevated);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--s-6) var(--s-5) calc(var(--s-6) + env(safe-area-inset-bottom, 0));
  animation: slide-up var(--t-spring);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

@media (min-width: 640px) {
  .modal { border-radius: var(--radius-xl); padding: var(--s-6); }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}

.modal__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }

.modal__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.modal__close:hover { background: var(--bg-hover); color: var(--text); }

.modal__body { display: flex; flex-direction: column; gap: var(--s-4); }

.modal__actions {
  display: flex;
  gap: var(--s-2);
  padding-top: var(--s-2);
}

@media (max-width: 480px) {
  .modal__actions { flex-direction: column-reverse; }
  .modal__actions .btn { width: 100%; }
}

/* --- Bottom sheet --- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  animation: fade-in var(--t-base);
}

.sheet {
  width: 100%;
  background: var(--bg-elevated);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--s-3) var(--s-5) calc(var(--s-6) + env(safe-area-inset-bottom, 0));
  max-height: 90vh;
  overflow-y: auto;
  animation: slide-up var(--t-spring);
}

.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  margin: 0 auto var(--s-4);
}

.sheet__title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--s-4);
}

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

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

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: var(--s-1);
  padding: var(--s-1);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  flex: 1;
  min-height: 40px;
  padding: 0 var(--s-4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all var(--t-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
}

.tab--active {
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-xs);
}

.tab .fas,
.tab .fab {
  font-size: 0.85em;
  opacity: 0.85;
}

/* --- Switch --- */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch__slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: background var(--t-fast);
  cursor: pointer;
}

.switch__slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: var(--radius-full);
  transition: transform var(--t-fast);
  box-shadow: var(--shadow-sm);
}

.switch input:checked + .switch__slider { background: var(--primary); }
.switch input:checked + .switch__slider::before { transform: translateX(20px); }

.switch input:focus-visible + .switch__slider {
  box-shadow: var(--shadow-focus);
}

/* --- List row --- */
.list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: background var(--t-fast);
  min-height: 60px;
}

.row--clickable { cursor: pointer; }
.row--clickable:hover { background: var(--bg-hover); }
.row--clickable:active { transform: scale(0.995); }

.row__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: var(--fs-md);
  flex-shrink: 0;
}
.row__icon .step-num {
  font-weight: 700;
  font-size: 14px;
  color: var(--primary);
}

.row__body { flex: 1; min-width: 0; }

.row__title {
  font-weight: var(--fw-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__action { color: var(--text-muted); flex-shrink: 0; }

/* --- Stat tile --- */
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  padding: var(--s-4);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.stat__icon { font-size: var(--fs-xl); }
.stat__value {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  color: var(--text);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
}
.stat__label {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* --- Chips --- */
.chips {
  display: flex;
  gap: var(--s-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--s-1);
  margin: 0 calc(var(--s-5) * -1);
  padding-left: var(--s-5);
  padding-right: var(--s-5);
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  padding: var(--s-2) var(--s-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all var(--t-fast);
}

.chip--active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--border);
  margin: var(--s-4) 0;
}

/* --- SwipeCard --- */
.swipe-card {
  transition: transform 160ms ease;
  touch-action: pan-y;
  position: relative;
}
.swipe-card--dragging { transition: none; z-index: 2; }

/* --- DatePicker --- */
.datepicker,
input.datepicker {
  /* inherits .field__input */
}

/* --- Breadcrumb --- */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 4px;
  width: 100%;
}
.breadcrumb__link { color: var(--primary); font-weight: var(--fw-medium); }
.breadcrumb__sep { opacity: 0.5; }
.breadcrumb__cur { color: var(--text-secondary); font-weight: var(--fw-semibold); }

/* --- Progress --- */
.progress {
  position: relative;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--t-base);
}
.progress__label {
  position: absolute;
  right: 0;
  top: -18px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* --- Splash / A2HS --- */
.cp-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 280ms ease, visibility 280ms ease;
}
.cp-splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.cp-splash-mark {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 28px;
  color: var(--primary);
  letter-spacing: -0.02em;
}

/* --- Screen-reader only --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
