/* Компоненты интерфейса. Значения берутся только из tokens.css. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--text-body-lh);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.icon {
  width: var(--size-icon);
  height: var(--size-icon);
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon-sm {
  width: var(--size-icon-sm);
  height: var(--size-icon-sm);
}

/* --- Каркас --------------------------------------------------------------- */

.app {
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + var(--space-6));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  /* Непрозрачный фон: под шапкой прокручивается контент, полупрозрачность
     ломала бы контраст текста поверх произвольных карточек. */
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  font-size: var(--text-h2);
  line-height: var(--text-h2-lh);
  font-weight: var(--weight-semibold);
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--size-control-sm);
  height: var(--size-control-sm);
  margin-left: calc(var(--space-2) * -1);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease);
}

.topbar__back:hover {
  background: var(--surface-2);
}

.view {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) 0;
  display: grid;
  gap: var(--space-5);
}

.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  cursor: pointer;
  transition: color var(--motion-fast) var(--ease);
}

.nav__item:hover {
  color: var(--text);
}

.nav__item[aria-current="page"] {
  color: var(--accent);
  font-weight: var(--weight-medium);
}

/* --- Типографика ---------------------------------------------------------- */

.display {
  font-size: var(--text-display);
  line-height: var(--text-display-lh);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  margin: 0;
}

.h1 {
  font-size: var(--text-h1);
  line-height: var(--text-h1-lh);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  margin: 0;
}

.h2 {
  font-size: var(--text-h2);
  line-height: var(--text-h2-lh);
  font-weight: var(--weight-semibold);
  margin: 0;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

/* --- Карточки ------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.card--flat {
  box-shadow: none;
}

.card--hero {
  padding: var(--space-6);
  display: grid;
  gap: var(--space-2);
  background: linear-gradient(140deg, var(--surface), var(--accent-soft));
}

.stack {
  display: grid;
  gap: var(--space-3);
}

.stack-sm {
  display: grid;
  gap: var(--space-2);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.row--between {
  justify-content: space-between;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.metric {
  display: grid;
  gap: var(--space-05);
}

.metric__value {
  font-size: var(--text-h1);
  line-height: var(--text-h1-lh);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.metric__label {
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  color: var(--text-muted);
}

/* --- Кнопки: 8 состояний -------------------------------------------------- */

.btn {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-fg);
  --btn-border: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--size-control);
  padding: 0 var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease),
    transform var(--motion-fast) var(--ease), opacity var(--motion-fast) var(--ease);
}

.btn:hover:not(:disabled) {
  --btn-bg: var(--accent-hover);
}

.btn:active:not(:disabled) {
  --btn-bg: var(--accent-active);
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn[data-loading="true"] {
  color: transparent;
  pointer-events: none;
}

.btn[data-loading="true"]::after {
  content: "";
  position: absolute;
  width: var(--size-spinner);
  height: var(--size-spinner);
  border-radius: 50%;
  border: var(--space-05) solid currentColor;
  border-top-color: transparent;
  color: var(--btn-fg);
  animation: spin var(--motion-spin) linear infinite;
}

.btn--secondary {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
}

.btn--secondary:hover:not(:disabled) {
  --btn-bg: var(--surface-2);
}

.btn--secondary:active:not(:disabled) {
  --btn-bg: var(--surface-2);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-border: transparent;
  min-height: var(--size-control-xs);
  padding: 0 var(--space-3);
}

.btn--ghost:hover:not(:disabled) {
  --btn-bg: var(--surface-2);
}

.btn--danger {
  --btn-bg: var(--danger);
  --btn-fg: var(--c-white);
}

.btn--danger:hover:not(:disabled) {
  --btn-bg: var(--danger-hover);
}

.btn--danger:active:not(:disabled) {
  --btn-bg: var(--danger-hover);
}

.btn--block {
  width: 100%;
}

.btn--sm {
  min-height: var(--size-control-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Поля ----------------------------------------------------------------- */

.field {
  display: grid;
  gap: var(--space-1);
}

.field__label {
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  color: var(--text-muted);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--size-control);
  padding: 10px var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--motion-fast) var(--ease),
    box-shadow var(--motion-fast) var(--ease);
}

.textarea {
  min-height: var(--size-textarea);
  resize: vertical;
  line-height: var(--text-body-lh);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--text-muted);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.field__error {
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  color: var(--danger);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--size-control);
  cursor: pointer;
}

.checkbox input {
  width: var(--size-icon);
  height: var(--size-icon);
  accent-color: var(--accent);
}

/* --- Бейджи и чипы -------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--text-xs-lh);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.badge--accent {
  background: var(--accent-soft);
  color: var(--accent-on-soft);
}

.badge--success {
  background: var(--success-soft);
  color: var(--success-on-soft);
}

.badge--warning {
  background: var(--warning-soft);
  color: var(--warning-on-soft);
}

.badge--danger {
  background: var(--danger-soft);
  color: var(--danger-on-soft);
}

.chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-1);
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  padding: 7px var(--space-3);
  font-size: var(--text-sm);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--motion-fast) var(--ease);
}

.chip:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: var(--weight-medium);
}

/* --- Списки --------------------------------------------------------------- */

.list {
  display: grid;
  gap: var(--space-2);
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease),
    background var(--motion-fast) var(--ease);
}

.list-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.list-item__body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: var(--space-05);
}

.list-item__title {
  font-weight: var(--weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item__meta {
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thumb {
  width: var(--size-thumb);
  height: var(--size-thumb);
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}

.thumb--empty {
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

/* --- Пустое состояние, ошибки, скелетоны ---------------------------------- */

.empty {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}

.empty__icon {
  width: var(--size-control);
  height: var(--size-control);
  color: var(--text-muted);
  opacity: 0.7;
}

.notice {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--warning-soft);
  color: var(--warning-on-soft);
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
}

.notice--danger {
  background: var(--danger-soft);
  color: var(--danger-on-soft);
}

.notice a {
  color: inherit;
  text-decoration: underline;
}

.notice--info {
  background: var(--accent-soft);
  color: var(--accent-on-soft);
}

.skeleton {
  border-radius: var(--radius-md);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface) 50%,
    var(--surface-2) 75%
  );
  background-size: 200% 100%;
  animation: shimmer var(--motion-shimmer) linear infinite;
  height: var(--size-skeleton);
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* --- Модальное окно ------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--overlay);
  animation: fade var(--motion-base) var(--ease);
}

.sheet__panel {
  width: 100%;
  max-width: var(--content-max);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-5) var(--space-4) var(--space-8);
  display: grid;
  gap: var(--space-4);
  animation: rise var(--motion-slow) var(--ease);
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    transform: translateY(var(--space-6));
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--space-4));
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100% - var(--space-8));
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--c-ink-900);
  color: var(--c-white);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  line-height: var(--text-sm-lh);
  animation: rise var(--motion-base) var(--ease);
}

.toast--danger {
  background: var(--c-red-600);
}

/* --- Специфика экранов ---------------------------------------------------- */

.auction-card {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--motion-fast) var(--ease);
}

.auction-card:hover {
  border-color: var(--accent);
}

.price {
  font-size: var(--text-h1);
  line-height: var(--text-h1-lh);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.bar {
  height: var(--size-bar);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width var(--motion-slow) var(--ease);
}

.level-row {
  display: grid;
  grid-template-columns: var(--size-marker) 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.level-row:last-child {
  border-bottom: 0;
}

.level-row__body {
  display: grid;
  gap: var(--space-05);
  min-width: 0;
}

.level-row__num {
  width: var(--size-marker);
  height: var(--size-marker);
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-on-soft);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.copy-field {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.copy-field .input {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.gallery {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.gallery::-webkit-scrollbar {
  display: none;
}

.gallery img {
  width: var(--size-gallery-w);
  height: var(--size-gallery-h);
  object-fit: cover;
  border-radius: var(--radius-md);
  flex: none;
}

.variant {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  white-space: pre-wrap;
  font-size: var(--text-sm);
  line-height: var(--text-body-lh);
}

.article-body {
  white-space: pre-wrap;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--text-body-lh);
}

/* Списки шагов: без pre-wrap, иначе переносы между <li> дают пустые строки. */
.steps {
  margin: 0;
  padding-left: var(--space-5);
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--text-body-lh);
}

.steps li + li {
  margin-top: var(--space-1);
}

@media (min-width: 720px) {
  .view {
    padding-top: var(--space-6);
  }

  .grid-2 {
    gap: var(--space-4);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important; /* ds-allow-hardcode: канонический сброс анимаций */
    transition-duration: 0.01ms !important; /* ds-allow-hardcode: канонический сброс анимаций */
  }
}
