/* =========================================================
   KARMA DESIGN SYSTEM — REUSABLE COMPONENTS
   Строго на токенах var(--...). Без hex/rgb/!important.
   ========================================================= */

/* === Утилиты === */
.is-hidden {
  display: none !important;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

/* === Типографика === */
.k-t-balance {
  font-size: var(--text-balance);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.k-t-title {
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
  margin: 0;
}

.k-t-subtitle {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin: 0;
}

.k-t-body {
  font-size: var(--text-base);
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-secondary);
  margin: 0;
}

.k-t-caption {
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-muted);
}

.k-t-mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--surface-code);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
}

/* === Каркас страницы === */
.k-page {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: calc(var(--space-3) + env(safe-area-inset-top, 0px)) var(--space-4)
    calc(var(--nav-height) + var(--space-8) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  box-sizing: border-box;
}

.k-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--touch-min);
}

.k-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* === Поверхности и списки === */
.k-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.k-card--elevated {
  background: var(--surface-2);
  border-color: var(--border-default);
}

.k-list {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.k-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-3) var(--space-4);
  text-decoration: none;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
  box-sizing: border-box;
}

.k-row:last-child {
  border-bottom: none;
}

.k-row:active {
  background: var(--surface-interactive-hover);
}

.k-row__left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.k-row__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.k-row__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-md);
  color: var(--text-primary);
}

.k-row__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.k-row__title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.k-row__sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === Кнопки === */
.k-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: transform var(--transition-fast), background var(--transition-normal),
    box-shadow var(--transition-normal), opacity var(--transition-fast);
  box-sizing: border-box;
}

.k-btn--full {
  width: 100%;
}

.k-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.k-btn:disabled,
.k-btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.k-btn--primary {
  background: var(--gradient-accent);
  color: var(--text-primary);
  box-shadow: var(--shadow-accent);
}

.k-btn--secondary {
  background: var(--surface-2);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.k-btn--secondary:active:not(:disabled) {
  background: var(--surface-3);
}

.k-btn--ghost {
  background: var(--surface-interactive);
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}

.k-btn--danger {
  background: var(--status-danger-soft);
  border-color: var(--status-danger-border);
  color: var(--status-danger-light);
}

.k-btn--circle {
  width: var(--touch-min);
  height: var(--touch-min);
  min-height: var(--touch-min);
  padding: 0;
  border-radius: var(--radius-full);
  background: var(--surface-pill);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.k-btn--pill {
  min-height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  background: var(--surface-pill);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.k-btn__spinner {
  display: none;
}

.k-btn.is-loading {
  pointer-events: none;
  opacity: 0.8;
}

.k-btn.is-loading .k-btn__spinner {
  display: inline-flex;
}

.k-btn.is-loading .k-btn__icon {
  display: none;
}

/* === Поля ввода === */
.k-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.k-field__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.k-field__control {
  width: 100%;
  min-height: 50px;
  padding: 0 var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  font-weight: 600;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  box-sizing: border-box;
}

.k-field__control::placeholder {
  color: var(--text-subtle);
}

.k-field__control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-soft);
}

.k-field__error {
  font-size: var(--text-xs);
  color: var(--status-danger-light);
  font-weight: 500;
}

/* === Бейджи === */
.k-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.k-badge--accent {
  background: var(--accent-primary-soft);
  color: var(--accent-primary-light);
  border: 1px solid var(--border-accent);
}

.k-badge--success {
  background: var(--status-success-soft);
  color: var(--status-success-light);
  border: 1px solid var(--status-success-border);
}

.k-badge--danger {
  background: var(--status-danger-soft);
  color: var(--status-danger-light);
  border: 1px solid var(--status-danger-border);
}

.k-badge--warning {
  background: var(--status-warning-soft);
  color: var(--status-warning-light);
  border: 1px solid var(--status-warning-border);
}

/* === Bottom Sheet === */
.k-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-backdrop);
  backdrop-filter: var(--blur-sm);
  -webkit-backdrop-filter: var(--blur-sm);
  z-index: var(--z-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.k-sheet-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.k-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: var(--container-max);
  max-height: 88vh;
  background: var(--surface-1);
  border-top: 1px solid var(--border-default);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-3) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-sheet);
  transform: translateY(100%);
  transition: transform var(--transition-sheet);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-sizing: border-box;
  box-shadow: var(--shadow-lg);
}

.k-sheet.is-open {
  transform: translateY(0);
}

.k-sheet__handle {
  width: 38px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  margin: 0 auto var(--space-1);
  flex-shrink: 0;
}

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

.k-sheet__body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* === Скелетоны и Empty State === */
@keyframes k-skeleton-pulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.k-skeleton {
  background: linear-gradient(
    90deg,
    var(--skeleton-base) 25%,
    var(--skeleton-shine) 50%,
    var(--skeleton-base) 75%
  );
  background-size: 200% 100%;
  animation: k-skeleton-pulse 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

.k-skeleton--line {
  height: 14px;
  width: 100%;
}

.k-skeleton--circle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.k-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}

.k-empty__icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
  color: var(--accent-primary-light);
  margin-bottom: var(--space-1);
}

/* === Система уведомлений (alerts.html + ui_alerts.js) === */
.k-toast-stack {
  position: fixed;
  top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 2 * var(--space-4));
  max-width: var(--container-max);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.k-toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity var(--transition-fast), transform var(--transition-normal);
}

.k-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.k-toast--success {
  border-color: var(--status-success-border);
}

.k-toast--success .k-toast__icon {
  color: var(--status-success-light);
}

.k-toast--error {
  border-color: var(--status-danger-border);
}

.k-toast--error .k-toast__icon {
  color: var(--status-danger-light);
}

.k-toast--warning {
  border-color: var(--status-warning-border);
}

.k-toast--warning .k-toast__icon {
  color: var(--status-warning-light);
}

.k-toast--info .k-toast__icon {
  color: var(--accent-primary-light);
}

.k-alert-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-backdrop);
  backdrop-filter: var(--blur-sm);
  -webkit-backdrop-filter: var(--blur-sm);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.k-alert-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.k-alert-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-6) var(--space-5) var(--space-5);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  transform: scale(0.95);
  transition: transform var(--transition-normal);
}

.k-alert-overlay.is-open .k-alert-card {
  transform: scale(1);
}

.k-alert-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xl);
}

.k-alert-icon--error {
  background: var(--status-danger-soft);
  color: var(--status-danger-light);
  border: 1px solid var(--status-danger-border);
}

.k-alert-icon--warning {
  background: var(--status-warning-soft);
  color: var(--status-warning-light);
  border: 1px solid var(--status-warning-border);
}

.k-alert-icon--success {
  background: var(--status-success-soft);
  color: var(--status-success-light);
  border: 1px solid var(--status-success-border);
}

.k-alert-icon--info {
  background: var(--accent-primary-soft);
  color: var(--accent-primary-light);
  border: 1px solid var(--border-accent);
}

.k-alert-meta {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.k-alert-meta__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.k-alert-meta__val {
  color: var(--text-primary);
  font-weight: 600;
  font-family: var(--font-mono);
}

.k-alert-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.k-alert-actions--row {
  flex-direction: row;
}

.k-alert-actions--row > * {
  flex: 1;
}

/* === Утилиты размеров скелетонов === */
.k-skeleton--w-55 { width: 55%; }
.k-skeleton--w-65 { width: 65%; }
.k-skeleton--w-22 { width: 22%; }
.k-skeleton--h-10 { height: 10px; }

.k-sr-only {
  position: fixed;
  opacity: 0;
  pointer-events: none;
}

/* === Единый брендовый хедер главных вкладок === */
.k-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.k-brand__logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.k-brand__name {
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--text-primary);
}

/* === Потоковая вёрстка без рамочных страниц (DESIGN.md) === */
.k-flow {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.k-flow-hero {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.k-flow-hero--center {
  align-items: center;
  text-align: center;
  padding-top: var(--space-2);
}

.k-flow-hero__title {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.k-flow-hero__accent {
  color: var(--accent-primary-light);
}

.k-flow-hero__sub {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.45;
}

.k-quiet-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

/* === Страница HTTP-ошибки (errors.html) === */
.k-error-page {
  min-height: 70vh;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.k-error-code {
  margin: 0;
  font-size: 72px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--accent-primary-light);
  font-variant-numeric: tabular-nums;
}
