:root {
  --bg: #0c0f14;
  --bg-elevated: #12161e;
  --surface: #181c27;
  --surface-hover: #1e2430;
  --border: #2a3142;
  --border-subtle: rgba(42, 49, 66, 0.65);
  --text: #e8eaef;
  --muted: #8b93a7;
  --accent: #5b8def;
  --accent-hover: #7aa3f5;
  --accent-muted: rgba(91, 141, 239, 0.14);
  --danger: #e85d5d;
  --color-error: #e85d5d;
  --color-success: #4ade80;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.25);
  --layout-pad-x: clamp(0.75rem, 3vw, 1.75rem);
  --layout-max: min(1320px, 100%);
  --topbar-h: auto;
  color-scheme: dark;

  /* Telegram Mini App: системный safe-area + переменные из telegram-web-app.js + --tg-js-* из applyTelegramChromeLayout() */
  --tg-js-safe-top: 0px;
  --tg-js-safe-bottom: 0px;
  --tg-js-safe-left: 0px;
  --tg-js-safe-right: 0px;
  --tg-js-content-top: 0px;
  --tg-js-content-bottom: 0px;
  --tg-js-content-left: 0px;
  --tg-js-content-right: 0px;
  --app-content-inset-top: max(
    env(safe-area-inset-top, 0px),
    var(--tg-content-safe-area-inset-top, 0px),
    var(--tg-js-content-top, 0px),
    var(--tg-js-safe-top, 0px)
  );
  --app-content-inset-bottom: max(
    env(safe-area-inset-bottom, 0px),
    var(--tg-content-safe-area-inset-bottom, 0px),
    var(--tg-js-content-bottom, 0px)
  );
  --app-content-inset-left: max(
    env(safe-area-inset-left, 0px),
    var(--tg-content-safe-area-inset-left, 0px),
    var(--tg-js-content-left, 0px)
  );
  --app-content-inset-right: max(
    env(safe-area-inset-right, 0px),
    var(--tg-content-safe-area-inset-right, 0px),
    var(--tg-js-content-right, 0px)
  );
  /* Стабильная высота витрины в Mini App: в WebView 100dvh часто не совпадает с реальной областью */
  --app-viewport-stable-height: var(--tg-viewport-stable-height, 100dvh);
}

img {
  -webkit-user-drag: none;
  -khtml-user-drag: none;
  -moz-user-drag: none;
  -o-user-drag: none;
  user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Единые поля: input / select / textarea */
.field-control {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 0.25rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.4;
  font-family: inherit;
  min-height: 2.75rem;
}
.field-control:focus {
  outline: none;
}
.field-control:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.22);
}
@supports not selector(:focus-visible) {
  .field-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.22);
  }
}
/* Нативный select после закрытия пикера остаётся в :focus — на сенсоре это выглядит как «залипшая» подсветка */
@media (hover: none) {
  select.field-control:focus,
  select.field-control:focus-visible,
  select.field-control.field-select:focus,
  select.field-control.field-select:focus-visible {
    border-color: var(--border);
    box-shadow: none;
  }
}
.field-control::placeholder {
  color: var(--muted);
  opacity: 0.85;
}
select.field-control,
.field-control.field-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238b93a7' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}
input[type="file"].field-control {
  padding: 0.45rem 0.4rem;
  cursor: pointer;
  min-height: auto;
}
input[type="file"].field-control::file-selector-button {
  margin-right: 0.65rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  input[type="file"].field-control::file-selector-button:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

@media (min-width: 900px) {
  .field-control {
    font-size: 0.9375rem;
    min-height: 2.5rem;
    padding: 0.5rem 0.65rem;
  }
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  min-height: var(--app-viewport-stable-height);
}
body {
  margin: 0;
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(0.9375rem, 0.88rem + 0.25vw, 1rem);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: var(--app-viewport-stable-height);
  padding-left: var(--app-content-inset-left);
  padding-right: var(--app-content-inset-right);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* Меньше «резинового» фона Telegram за краями мини-приложения */
html.telegram-mini-app {
  overscroll-behavior: none;
}
html.telegram-mini-app body {
  overscroll-behavior-y: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.65rem var(--layout-pad-x);
  padding-top: max(0.65rem, var(--app-content-inset-top));
  /* Полупрозрачная «стеклянная» шапка (контент под ней слегка просвечивает при скролле) */
  background: rgba(18, 22, 30, 0.78);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
}

/*
 * Mini App: тот же визуальный стиль, что и в браузере (полупрозрачность + blur).
 * setHeaderColor() в app.js по-прежнему задаёт системный цвет TG; локальная шапка остаётся glass.
 */
html.telegram-mini-app .topbar {
  background: rgba(18, 22, 30, 0.78);
  backdrop-filter: blur(14px) saturate(1.15);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
}

.topbar-inner {
  display: grid;
  width: var(--layout-max);
  max-width: 100%;
  margin: 0 auto;
  gap: 0.6rem 0.85rem;
  align-items: center;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "lead user"
    "nav nav";
}

.topbar-lead {
  grid-area: lead;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  min-width: 0;
}

.brand-link {
  font-weight: 700;
  font-size: clamp(0.98rem, 0.93rem + 0.32vw, 1.22rem);
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  line-height: 1.2;
}
@media (hover: hover) and (pointer: fine) {
  .brand-link:hover {
    color: var(--accent);
  }
}

.header-players {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.12rem 0.3rem;
  background: rgba(91, 141, 239, 0.12);
  color: var(--text);
  border: 1px solid rgba(91, 141, 239, 0.28);
  border-radius: var(--radius-sm);
  /* Как у ника в шапке (.user-label) */
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
button.header-players {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  /* Не font: inherit — перебивает font-size/font-weight у .header-players (у button выше специфичность). */
  font-family: inherit;
  cursor: pointer;
  text-align: inherit;
}
@media (hover: hover) and (pointer: fine) {
  button.header-players:hover {
    background: rgba(91, 141, 239, 0.2);
    border-color: rgba(91, 141, 239, 0.45);
  }
}

.nav {
  grid-area: nav;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem;
  margin: 0 -0.35rem;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border-subtle);
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 2.5rem;
  display: inline-flex;
  align-items: center;
  transition: color 0.15s ease, background 0.15s ease;
}
.nav-link.active {
  color: var(--text);
  background: var(--accent-muted);
}
@media (hover: hover) and (pointer: fine) {
  .nav-link:hover {
    color: var(--text);
    background: var(--accent-muted);
  }
}

.userbox {
  grid-area: user;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  min-width: 0;
}
.user-profile-hit {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  /* В RTL у контейнера первый flex-ребёнок оказывается справа — фиксируем порядок: аватар слева. */
  direction: ltr;
  max-width: min(200px, 48vw);
  background: none;
  border: none;
  padding: 0.25rem 0.35rem;
  margin: -0.25rem -0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: right;
  color: inherit;
  font: inherit;
}
@media (hover: hover) and (pointer: fine) {
  .user-profile-hit:hover {
    background: rgba(255, 255, 255, 0.04);
  }
  .user-profile-hit:hover .user-label {
    color: var(--accent);
  }
}

/* Личный кабинет открыт — как активный пункт навигации (.nav-link.active) */
.user-profile-hit.active {
  background: var(--accent-muted);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  margin: -0.5rem -0.85rem;
}
.user-profile-hit.active .user-label {
  color: var(--text);
}
.user-profile-hit.active .user-balance {
  color: var(--muted);
}
@media (hover: hover) and (pointer: fine) {
  .user-profile-hit.active:hover {
    background: var(--accent-muted);
    filter: brightness(1.06);
  }
  .user-profile-hit.active:hover .user-label {
    color: var(--text);
  }
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--border);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  min-width: 0;
}
.user-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-balance {
  font-size: 0.72rem;
  display: block;
}
.user-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
}
@media (hover: hover) and (pointer: fine) {
  #btn-login.btn-link:hover {
    color: var(--accent);
  }
}

@media (min-width: 900px) {
  .topbar-inner {
    grid-template-columns: minmax(0, auto) 1fr minmax(0, auto);
    grid-template-areas: "lead nav user";
    gap: 1rem 1.5rem;
    padding: 0.15rem 0;
  }
  .topbar-lead {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }
  .nav {
    justify-self: center;
    width: auto;
    flex-wrap: nowrap;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
  }
  .user-profile-hit {
    max-width: 260px;
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: inherit;
  min-height: 2.75rem;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn-large {
  padding: 0.75rem 1rem;
  font-size: 1rem;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--surface-hover);
  }
}
.btn.btn-small,
.btn-primary-inline.btn-small,
.btn-danger-inline.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8125rem;
  min-height: auto;
}

.btn-icon {
  padding: 0 !important;
  width: 2rem;
  height: 2rem;
  min-height: 2rem !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}
.btn-icon svg {
  margin: 0;
  display: block;
}
.btn-pill {
  border-radius: var(--radius-sm);
  padding: 0.45rem 1rem;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.65rem 1rem;
  font-weight: 600;
}
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
  }
}
.btn-primary:disabled,
.btn-primary.is-loading,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(1);
}
.btn.is-loading {
  position: relative;
  padding-left: 2.25rem;
}
.btn.is-loading::before {
  content: "";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  width: 1rem;
  height: 1rem;
  margin-top: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  transform: translateY(-50%);
  animation: btn-spin 0.65s linear infinite;
}
@keyframes btn-spin {
  from {
    transform: translateY(-50%) rotate(0deg);
  }
  to {
    transform: translateY(-50%) rotate(360deg);
  }
}
.btn-link {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
  min-height: 2.5rem;
}
@media (hover: hover) and (pointer: fine) {
  .btn-link:hover {
    border: none;
    background: transparent;
    color: var(--accent);
  }
}

.btn-inline-link {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 0;
  min-height: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.btn-inline-link:hover {
  color: var(--color-primary-hover);
}
.btn-primary-inline {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  min-height: 2.75rem;
  touch-action: manipulation;
  transition: background 0.15s ease, border-color 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
  .btn-primary-inline:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
  }
}
.btn-primary-inline:disabled,
.btn-primary-inline.is-loading,
.btn-danger-inline:disabled,
.btn-danger-inline.is-loading {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(1);
}
.btn-danger-inline {
  border-color: rgba(232, 93, 93, 0.55);
  color: var(--danger);
  background: rgba(232, 93, 93, 0.08);
}
@media (hover: hover) and (pointer: fine) {
  .btn-danger-inline:hover {
    border-color: var(--danger);
    color: #fff;
    background: var(--danger);
  }
}

/* ——— Main layout ——— */
.main {
  width: var(--layout-max);
  max-width: 100%;
  margin: 0 auto;
  padding: clamp(1rem, 2.5vw, 2rem) var(--layout-pad-x);
  padding-bottom: max(1.5rem, var(--app-content-inset-bottom));
  flex: 1 1 auto;
  min-height: 0;
}

.page-title {
  margin: 0 0 1rem;
  font-size: clamp(1.35rem, 1.1rem + 1.1vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.view.hidden {
  display: none;
}

.catalog-toolbar {
  position: relative;
  display: grid;
  gap: 0.85rem clamp(0.5rem, 2vw, 1.25rem);
  margin-bottom: clamp(1rem, 2vw, 1.5rem);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}
.catalog-toolbar-skel {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem clamp(0.5rem, 2vw, 1.25rem);
  align-items: end;
  pointer-events: none;
}
.catalog-toolbar-skel .cts-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.catalog-toolbar-skel .cts-label {
  display: block;
  height: 0.8125rem;
  width: 4.5rem;
  max-width: 55%;
  border-radius: 4px;
}
.catalog-toolbar-skel .cts-field {
  display: block;
  min-height: 2.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-sizing: border-box;
}
.filter-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}
.filter-label select.field-control {
  min-width: 0;
  margin-top: 0.25rem;
}

@media (min-width: 900px) {
  .catalog-toolbar {
    grid-template-columns: repeat(2, minmax(200px, 280px));
  }
  .catalog-toolbar-skel {
    grid-template-columns: repeat(2, minmax(200px, 280px));
  }
}

.cabinet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.cabinet-head .cabinet-title {
  margin: 0;
}
.btn.btn-link.cabinet-logout {
  color: var(--danger);
}
@media (hover: hover) and (pointer: fine) {
  .btn.btn-link.cabinet-logout:hover {
    border: none;
    color: #fff;
    background: var(--danger);
  }
}

.orders-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}
.orders-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ——— Product grid: плотная сетка на телефоне, простор на десктопе ——— */
.product-grid {
  display: grid;
  gap: clamp(0.75rem, 2vw, 1.25rem);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
}

@media (min-width: 400px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  }
}

@media (min-width: 700px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  }
}

@media (min-width: 1100px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: clamp(0.85rem, 2vw, 1.1rem);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
@media (hover: hover) and (pointer: fine) {
  .product-card:hover {
    transform: translateY(-3px);
    border-color: rgba(91, 141, 239, 0.35);
    box-shadow: var(--shadow-card);
  }
}
.product-card .thumb {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: contain;
  object-position: center;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
.product-card h3 {
  margin: 0;
  font-size: clamp(0.95rem, 0.9rem + 0.2vw, 1.1rem);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
}
.product-card .servers {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}
.product-card .price {
  color: var(--accent);
  font-weight: 700;
  font-size: clamp(0.95rem, 0.9rem + 0.15vw, 1.05rem);
}
.product-card .product-rate {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text);
  font-weight: 500;
  opacity: 0.88;
}
.product-card .product-exchange {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  font-size: clamp(0.9rem, 0.85rem + 0.15vw, 1rem);
  line-height: 1.3;
}
.product-card .product-exchange .ex-pay {
  color: var(--accent);
  font-weight: 700;
}
.product-card .product-exchange .ex-arrow {
  color: var(--muted);
  font-weight: 600;
  opacity: 0.85;
}
.product-card .product-exchange .ex-get {
  color: var(--text);
  font-weight: 600;
}
.product-card .desc {
  color: var(--muted);
  font-size: 0.8125rem;
  flex: 1;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-card .btn-buy {
  margin-top: 0.35rem;
  width: 100%;
}
.product-card .btn-buy:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: clamp(1rem, 3vw, 1.5rem);
  max-width: 640px;
  box-shadow: var(--shadow-sm);
}

@media (min-width: 900px) {
  .card {
    max-width: 720px;
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.75rem;
  }
}

.cabinet-actions {
  margin: 0.85rem 0 1.1rem;
  display: flex;
  gap: 0.75rem;
}

.stats {
  display: grid;
  grid-template-columns: minmax(5.5rem, auto) 1fr;
  gap: 0.4rem 1rem;
}
@media (max-width: 400px) {
  .stats {
    grid-template-columns: 1fr;
  }
  .stats dt {
    margin-top: 0.5rem;
  }
  .stats dt:first-child {
    margin-top: 0;
  }
}
.stats dt {
  color: var(--muted);
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
}
.stats dd {
  margin: 0;
  font-weight: 500;
}
.mono {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.78rem;
  word-break: break-all;
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 0.875rem;
}

/* ——— Modals ——— */
:root {
  /* Длительность закрытия: держите в синхроне с MODAL_CLOSE_MS в app.js */
  --modal-close-duration: 0.12s;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--layout-pad-x);
  padding-top: max(var(--layout-pad-x), var(--app-content-inset-top));
  padding-bottom: max(1rem, var(--app-content-inset-bottom));
  padding-left: max(var(--layout-pad-x), var(--app-content-inset-left));
  padding-right: max(var(--layout-pad-x), var(--app-content-inset-right));
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 1;
  transition: opacity var(--modal-close-duration) ease-out;
}
.modal-overlay.hidden {
  display: none;
}
.modal-overlay.modal-overlay--closing {
  pointer-events: none;
  opacity: 0;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.15rem, 4vw, 1.5rem);
  width: 100%;
  max-width: 400px;
  position: relative;
  max-height: min(90dvh, calc(var(--tg-viewport-stable-height, 100dvh) * 0.92));
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

@media (max-width: 540px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
    padding-bottom: var(--app-content-inset-bottom);
    padding-left: var(--app-content-inset-left);
    padding-right: var(--app-content-inset-right);
  }
  .modal {
    max-width: none;
    max-height: min(88dvh, calc(var(--tg-viewport-stable-height, 100dvh) * 0.9));
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: max(1.25rem, var(--app-content-inset-bottom), 12px);
    animation: modal-sheet-up 0.28s ease;
  }
  .modal-overlay.modal-overlay--closing .modal {
    animation: none;
    transition:
      transform var(--modal-close-duration) ease-in,
      opacity var(--modal-close-duration) ease-in;
    transform: translateY(10px);
    opacity: 0.88;
  }
}

@keyframes modal-sheet-up {
  from {
    opacity: 0.9;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 541px) {
  .modal-overlay.modal-overlay--closing .modal {
    animation: none;
    transition:
      transform var(--modal-close-duration) ease-in,
      opacity var(--modal-close-duration) ease-in;
    transform: scale(0.98);
    opacity: 0;
  }
}

.modal.modal-wide {
  max-width: min(560px, 100%);
}
@media (min-width: 900px) {
  .modal.modal-wide {
    max-width: 640px;
  }
}

.modal-wide form label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.modal-wide form input[type="text"].field-control,
.modal-wide form input[type="number"].field-control,
.modal-wide form input[type="file"].field-control,
.modal-wide form textarea.field-control,
.modal-wide form select.field-control {
  margin-top: 0.25rem;
}
.modal-wide .admin-servers {
  margin-top: 0.35rem;
}
.modal-wide .inline-check {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  flex-direction: row !important;
}
.modal-wide .inline-check input {
  width: auto !important;
  margin: 0 !important;
}
.modal h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.15rem, 1rem + 0.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Product Detail Modal */
.product-detail-image-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}
.product-detail-image-wrap img.hidden {
  display: none;
}
.product-detail-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.product-detail-desc {
  color: var(--muted);
  font-size: 0.9375rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.login-modal > h2 {
  margin: 0 0 0.75rem;
}
.login-modal > p.muted.small {
  margin: 0 0 0.75rem;
}
.login-modal #form-login > label {
  margin-top: 0.75rem;
}
.login-modal #form-login > label:first-of-type {
  margin-top: 0;
}
.login-modal #form-login > .error {
  margin-top: 0.75rem;
}
.login-modal #form-login > .btn-primary {
  margin-top: 1.35rem;
}

.topup-modal > h2 {
  margin: 0 0 0.75rem;
}
.topup-modal-lead {
  margin: 0 0 0.75rem;
}
.topup-field {
  margin-top: 0.75rem;
}
.topup-field:first-of-type {
  margin-top: 0;
}
.topup-field-label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
  line-height: 1.3;
}
.topup-modal .field-control {
  margin-top: 0;
}
.topup-tg-hint {
  margin: 0.65rem 0 0;
  line-height: 1.4;
}
.topup-error {
  margin: 0.65rem 0 0;
}
.topup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.topup-actions .btn,
.topup-actions .btn-primary-inline {
  flex: 1 1 auto;
  min-width: 120px;
}

.play-ip-modal > h2 {
  margin: 0 0 0.75rem;
}
.play-ip-modal > p.muted.small {
  margin: 0 0 0.75rem;
}
.play-ip-modal .field-control {
  width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.9375rem;
}

/* Поля суммы к оплате: один вид в модалках пополнения и покупки */
.modal .modal-amount-field {
  font-variant-numeric: tabular-nums;
}
.modal .modal-amount-field:disabled,
.field-readonly {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--border-subtle);
  cursor: not-allowed;
  -webkit-text-fill-color: var(--muted);
}
.modal .modal-amount-field:disabled::placeholder {
  color: var(--muted);
  opacity: 0.75;
}
.play-ip-modal-actions {
  margin-top: 1rem;
}
.play-ip-modal-actions .btn-primary-inline {
  width: 100%;
}

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 10;
  margin-top: -1.85rem;
  margin-right: 0;
  margin-bottom: -2.25rem;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
@media (hover: hover) and (pointer: fine) {
  .modal-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
  }
}
.modal form label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.modal form .field-control {
  margin-top: 0.25rem;
}
.buy-modal .buy-nick-field,
.buy-modal .buy-delivery-field {
  display: block;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.buy-modal .buy-nick-field .field-control,
.buy-modal .buy-delivery-field .field-control {
  margin-top: 0.25rem;
}
.buy-modal #buy-modal-sub {
  margin-top: 0.35rem;
}
.buy-modal #buy-scale-wrap:not(.hidden) + #buy-modal-sub {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}
.buy-modal #buy-modal-sub.buy-cost-fixed {
  margin-top: 0.5rem;
}
.buy-modal .buy-scale-wrap {
  margin-top: 0.75rem;
  padding: 0.75rem 0 0.25rem;
  border-top: 1px solid var(--border-subtle);
}
.buy-modal .buy-scale-fields {
  margin-top: 0.5rem;
}
.buy-modal .buy-scale-labels-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.65rem;
  margin: 0 0 0.4rem;
  line-height: 1.35;
}
.buy-modal .buy-scale-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.65rem;
  align-items: stretch;
}
.buy-modal .buy-scale-input-row .field-control {
  margin-top: 0;
  width: 100%;
}
.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}
.error.hidden {
  display: none;
}
.hidden {
  display: none !important;
}

.admin-search-input {
  cursor: text;
  text-align: left;
  outline: none;
}
.admin-search-input::placeholder {
  color: var(--muted);
  font-weight: 400;
}
.admin-search-input:focus,
.admin-search-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.22);
}

.admin-toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.admin-toolbar .muted {
  flex: 1 1 min(100%, 220px);
}
.admin-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.35rem;
  flex-wrap: wrap;
}
.admin-tab {
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  min-height: 2.5rem;
  touch-action: manipulation;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
  .admin-tab:hover {
    color: var(--text);
    background: var(--accent-muted);
  }
}
.admin-tab.active {
  color: var(--text);
  border-color: var(--border);
  background: var(--bg-elevated);
}
.admin-orders-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface);
  margin-top: 1rem;
}
.admin-orders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0;
}
.admin-orders-table th,
.admin-orders-table td {
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.85rem 0.75rem;
  text-align: left;
  vertical-align: middle;
}
.admin-orders-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.2);
  border-bottom-width: 2px;
}
.admin-orders-table tbody tr {
  transition: background-color 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
  .admin-orders-table tbody tr:hover {
    background-color: var(--surface-hover);
  }
}
.admin-orders-table tbody tr:last-child td {
  border-bottom: none;
}
.admin-orders-table .mono-cell {
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  word-break: break-all;
  max-width: 11rem;
}
.admin-orders-table .cmd-cell {
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  word-break: break-word;
  max-width: 14rem;
}
.admin-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.admin-row-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}
.admin-editor {
  max-width: 560px;
  margin-top: 1rem;
}
.admin-editor label {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.admin-editor input[type="text"],
.admin-editor input[type="number"],
.admin-editor textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.admin-servers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.35rem;
}
.admin-servers label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.85rem;
}
.inline-check {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  flex-direction: row !important;
}
.inline-check input {
  width: auto !important;
  margin: 0 !important;
}
.admin-form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.view code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
}

/* ——— Заглушки: интерфейс на месте, данные «доезжают» ——— */
@keyframes shop-skel-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.shop-skel {
  background: linear-gradient(
    90deg,
    var(--surface) 0%,
    var(--surface-hover) 38%,
    rgba(91, 141, 239, 0.12) 50%,
    var(--surface-hover) 62%,
    var(--surface) 100%
  );
  background-size: 220% 100%;
  animation: shop-skel-shimmer 1.35s ease-in-out infinite;
}

/* Пока грузятся данные магазина — не показываем «Войти» (только скелет шапки или потом профиль). */
body.shop-data-loading #btn-login {
  display: none !important;
}

/* До выполнения JS кнопка входа скрыта, а профиль с hidden — без этого блок справа пустой на десктопе. */
body.shop-data-loading #btn-profile.hidden {
  display: flex !important;
}

body.shop-data-loading .nav {
  pointer-events: none;
  opacity: 0.72;
}

body.shop-data-loading .brand-link,
body.shop-data-loading .header-players {
  pointer-events: none;
}

body.shop-data-loading .catalog-toolbar {
  pointer-events: none;
}
body.shop-data-loading #view-home .catalog-toolbar .filter-label {
  visibility: hidden;
}
body.shop-data-loading #view-home .catalog-toolbar .catalog-toolbar-skel {
  display: grid;
}

.userbox--data-loading .user-profile-hit--shell {
  pointer-events: none;
  cursor: default;
}

.userbox--data-loading .user-profile-hit--shell .user-label.shop-skel-line,
.userbox--data-loading .user-profile-hit--shell .user-balance.shop-skel-line {
  display: block;
  min-height: 0.85rem;
  color: transparent !important;
  border-radius: 4px;
}

.userbox--data-loading .user-profile-hit--shell .user-label.shop-skel-line {
  width: 6.5rem;
  min-height: 0.95rem;
  margin-bottom: 0.2rem;
}

.userbox--data-loading .user-profile-hit--shell .user-balance.shop-skel-line {
  width: 5.5rem;
}

.product-card.product-card--skeleton {
  pointer-events: none;
  border-style: dashed;
  border-color: var(--border);
}

.product-card--skeleton .pc-skel-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.product-card--skeleton .pc-skel-line {
  height: 11px;
  border-radius: 4px;
  max-width: 100%;
}

.product-card--skeleton .pc-skel-line--title {
  height: 16px;
  width: 92%;
}

/* цена или блок обмена (.price / .product-exchange) */
.product-card--skeleton .pc-skel-line--price {
  height: 14px;
  width: 58%;
  margin-top: 0;
}

/* .product-rate */
.product-card--skeleton .pc-skel-line--rate {
  height: 10px;
  width: 78%;
  margin-top: 0.25rem;
}

.product-card--skeleton .pc-skel-desc {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
}

.product-card--skeleton .pc-skel-line--desc {
  height: 10px;
  width: 100%;
}

.product-card--skeleton .pc-skel-line--desc-last {
  width: 64%;
}

.product-card--skeleton .pc-skel-servers {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  margin: 0;
}

.product-card--skeleton .pc-skel-line--serv {
  height: 9px;
  width: 94%;
}

.product-card--skeleton .pc-skel-line--serv-short {
  width: 72%;
}

.product-card--skeleton .pc-skel-btn {
  min-height: 2.75rem;
  height: 2.75rem;
  margin-top: 0.35rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-sizing: border-box;
}

/* Два доп. скелетона в HTML/JS — только ≥900px (иначе перекрывалось бы правилом .product-card { display: flex }). */
article.product-card.product-card--skeleton.product-grid-skel-wide {
  display: none !important;
}
@media (min-width: 900px) {
  article.product-card.product-card--skeleton.product-grid-skel-wide {
    display: flex !important;
  }
}

@media (min-width: 900px) {
  body.shop-data-loading #view-home .product-grid.product-grid--skeleton {
    min-height: min(52vh, 560px);
  }
}

/* ——— Toasts ——— */
.toast-stack {
  position: fixed;
  top: max(0.65rem, var(--app-content-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  width: min(calc(100dvw - 1.5rem), 440px);
  padding: 0 var(--layout-pad-x);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  cursor: pointer;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  animation: toast-in 0.28s ease;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.toast--out {
  animation: toast-out 0.22s ease forwards;
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}
.toast--success {
  background: rgba(36, 110, 72, 0.96);
  border-color: rgba(90, 200, 130, 0.45);
  color: #ecfdf3;
}
.toast--error {
  background: rgba(140, 42, 42, 0.96);
  border-color: rgba(255, 130, 130, 0.4);
  color: #fff8f8;
}
.toast--info {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
