/* ─────────────────────────────────────────────────────────────
   Дизайн-токены. Стиль: чистый чёрный фон, тёмно-серые карточки
   с крупным радиусом, монохромный акцент — белая пилюля.
   ───────────────────────────────────────────────────────────── */
:root {
  --bg: #000000;
  --surface: #141414;        /* карточка */
  --surface-2: #1f1f1f;      /* вложенный элемент, поле ввода */
  --surface-3: #2a2a2a;      /* ховер, неактивная кнопка */
  --line: #262626;

  --text: #ffffff;
  --text-dim: #8d8d93;
  --text-faint: #636369;

  --accent: #ffffff;         /* акцент монохромный */
  --accent-ink: #000000;
  --promo: #d6d6d6;          /* светлая карточка-баннер */
  --promo-ink: #0a0a0a;

  --ok: #32d583;
  --warn: #fdb022;
  --danger: #ff5247;

  --r-xs: 12px;
  --r-sm: 16px;
  --r: 22px;
  --r-lg: 28px;
  --pill: 999px;

  --pad: 18px;
  --gap: 10px;
  --edge: 14px;

  --topbar-h: 50px;
  --tabbar-h: 68px;

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/*
 * Атрибут hidden скрывает элемент правилом браузера, а любое наше правило с display
 * его перебивает — селектор по id или классу сильнее. Поэтому закрепляем явно,
 * иначе скрытые окна и значки остаются на экране и ловят нажатия.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; font-size: inherit; color: inherit; }

/* ───────────────── каркас ───────────────── */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--edge) 0;
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px);
  z-index: 20;
}

#title {
  flex: 1;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--surface-2); color: var(--text);
  font-size: 22px; line-height: 1;
  cursor: pointer;
}

/* Пилюля баланса, как в шапке профиля */
.chip {
  padding: 8px 14px;
  border-radius: var(--pill);
  background: var(--surface);
  font-size: 14px; font-weight: 700;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .lbl { font-size: 11px; font-weight: 500; color: var(--text-dim); }

#screen {
  padding: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px) var(--edge)
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  min-height: 100vh;
}

/* Плавающий таббар-пилюля */
#tabbar {
  position: fixed;
  left: var(--edge); right: var(--edge);
  bottom: calc(10px + env(safe-area-inset-bottom));
  height: var(--tabbar-h);
  padding: 7px;
  display: flex; gap: 2px;
  background: var(--surface);
  border-radius: var(--pill);
  z-index: 20;
}

#tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  border-radius: var(--pill);
  font-size: 10.5px; font-weight: 600;
  color: var(--text-dim);
  transition: background .15s, color .15s;
}
#tabbar a .ico { font-size: 18px; line-height: 1; }
#tabbar a.active { background: var(--accent); color: var(--accent-ink); }

.with-badge { position: relative; }
.with-badge i {
  position: absolute; top: -16px; right: -13px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--pill);
  background: var(--danger); color: #fff;
  font-size: 10px; font-style: normal; font-weight: 700;
  display: grid; place-items: center;
}

/* ───────────────── типографика ───────────────── */

h1.page {
  margin: 6px 0 4px;
  font-size: 34px; font-weight: 800; letter-spacing: -0.9px; line-height: 1.1;
}
h1.page + .sub { color: var(--text-dim); font-size: 15px; margin-bottom: 18px; }

h2.section {
  margin: 22px 4px 10px;
  font-size: 12px; font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 13.5px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 700; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.loader, .empty { padding: 48px 16px; text-align: center; color: var(--text-dim); }
.empty .big { font-size: 38px; display: block; margin-bottom: 10px; opacity: .5; }

/* ───────────────── карточки ───────────────── */

.card {
  background: var(--surface);
  border-radius: var(--r);
  padding: var(--pad);
  margin-bottom: var(--gap);
}
.card.tight { padding: 14px; }

/* Светлая карточка-баннер */
.promo {
  background: var(--promo);
  color: var(--promo-ink);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: var(--gap);
}
.promo h3 { margin: 0 0 6px; font-size: 22px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.15; }
.promo p { margin: 0 0 14px; font-size: 14px; opacity: .72; }
.promo .btn { width: auto; background: rgba(0,0,0,.14); color: var(--promo-ink); }

/* Строка-ссылка с шевроном */
.nav-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: var(--gap);
}
.nav-card .t { font-size: 17px; font-weight: 700; }
.nav-card .d { font-size: 13.5px; color: var(--text-dim); margin-top: 2px; }
.nav-card .chev { color: var(--text-faint); font-size: 20px; }

/* Сетка быстрых действий 4-в-ряд */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: var(--gap); }
.quick a {
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 16px 6px 13px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600;
}
.quick a .ico { font-size: 20px; }

/* ───────────────── кнопки ───────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 17px 20px;
  border: none; border-radius: var(--pill);
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 16px;
  cursor: pointer;
}
.btn:disabled { opacity: .35; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ok { background: var(--ok); color: #04210f; }
.btn.small { width: auto; padding: 10px 18px; font-size: 14px; }
.btn.tiny { width: auto; padding: 7px 14px; font-size: 12.5px; }

/* Переключатель «Себе / Другу» */
.toggle {
  display: flex; gap: 4px; padding: 5px;
  background: var(--surface); border-radius: var(--pill);
  margin-bottom: 18px;
}
.toggle button {
  flex: 1; padding: 13px; border: none; border-radius: var(--pill);
  background: transparent; color: var(--text-dim);
  font-weight: 700; font-size: 15px; cursor: pointer;
}
.toggle button.on { background: var(--accent); color: var(--accent-ink); }

/* ───────────────── выбираемые строки (тариф, способ оплаты) ───────────────── */

.option {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  background: var(--surface);
  border: none; border-radius: var(--r);
  padding: 18px;
  margin-bottom: 8px;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.option .ico-circle {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  background: var(--surface-3);
  display: grid; place-items: center;
  font-size: 19px;
}
.option > span:not(.ico-circle):not(.amount):not(.tag) { flex: 1; min-width: 0; }
.option .t { display: block; font-size: 17px; font-weight: 700; letter-spacing: -0.2px; }
.option .d { display: block; font-size: 13.5px; color: var(--text-dim); margin-top: 2px; }
.option .amount { margin-left: auto; font-size: 20px; font-weight: 800; letter-spacing: -0.4px; white-space: nowrap; }
.option .tag {
  display: inline-block; margin-left: 8px; padding: 4px 11px;
  border: 1px solid var(--line); border-radius: var(--pill);
  font-size: 11.5px; font-weight: 600; color: var(--text-dim);
  vertical-align: middle;
}

.option.on { background: var(--accent); color: var(--accent-ink); }
.option.on .d { color: rgba(0,0,0,.55); }
.option.on .ico-circle { background: var(--accent-ink); color: var(--accent); }
.option.on .tag { border-color: rgba(0,0,0,.25); color: rgba(0,0,0,.6); }

/* ───────────────── поля ───────────────── */

.input, .textarea, .select {
  width: 100%;
  padding: 16px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit; font-size: 16px;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--surface-3); }
.select { appearance: none; background-image: none; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; margin: 0 4px 7px; font-size: 12px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-faint); }
label.check { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; font-size: 15px; }
label.check input { width: 20px; height: 20px; accent-color: #fff; }

/* ───────────────── бейджи ───────────────── */

.badge {
  display: inline-block;
  padding: 5px 11px;
  border-radius: var(--pill);
  font-size: 11.5px; font-weight: 700;
  background: var(--surface-2); color: var(--text-dim);
}
.badge.ok     { background: color-mix(in srgb, var(--ok) 16%, transparent);     color: var(--ok); }
.badge.warn   { background: color-mix(in srgb, var(--warn) 16%, transparent);   color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.badge.accent { background: var(--accent); color: var(--accent-ink); }

/* ───────────────── каталог ───────────────── */

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .chip {
  background: var(--surface); color: var(--text-dim);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  padding: 9px 16px;
}
.filters .chip.on { background: var(--accent); color: var(--accent-ink); }

.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row .input { padding: 14px 16px; border-radius: var(--pill); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); }

.tile {
  background: var(--surface);
  border-radius: var(--r);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.tile .thumb {
  aspect-ratio: 16 / 10;
  background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center;
  font-size: 26px; color: var(--text-faint);
}
.tile .body { padding: 12px 14px 15px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.tile .name { font-size: 14.5px; font-weight: 700; line-height: 1.25; max-height: 2.5em; overflow: hidden; letter-spacing: -0.2px; }
.tile .price { font-weight: 800; font-size: 17px; letter-spacing: -0.3px; }
.tile .meta { font-size: 11px; color: var(--text-faint); display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* ───────────────── объявление ───────────────── */

.hero {
  width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--r);
  background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center;
  font-size: 46px; color: var(--text-faint);
  margin-bottom: 16px;
}
.shots { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.shots::-webkit-scrollbar { display: none; }
.shots img { height: 92px; border-radius: var(--r-xs); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv > span:first-child { color: var(--text-dim); font-size: 14px; }
.kv > span:last-child { text-align: right; font-weight: 700; }

.kv.total { padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--line); }
.kv.total > span:first-child { color: var(--text); font-size: 17px; font-weight: 700; }
.kv.total > span:last-child { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }

.desc { white-space: pre-wrap; word-break: break-word; line-height: 1.5; }

.sticky-bar {
  position: fixed;
  left: var(--edge); right: var(--edge);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  display: flex; gap: 8px;
  z-index: 15;
}
.sticky-bar .btn { box-shadow: 0 10px 30px rgba(0,0,0,.6); }

/* ───────────────── списки ───────────────── */

.item {
  display: flex; gap: 13px; align-items: center;
  background: var(--surface);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 8px;
}
.item .thumb-sm {
  width: 52px; height: 52px; flex: none;
  border-radius: var(--r-xs);
  background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center;
  font-size: 21px; color: var(--text-faint);
}
.avatar {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  background: var(--surface-2) center/cover no-repeat;
  display: grid; place-items: center;
  font-weight: 700; color: var(--text-dim);
}

.profile-row { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.profile-row .avatar { width: 56px; height: 56px; font-size: 19px; }
.profile-row .nm { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; }
.profile-row .uid { font-size: 14px; color: var(--text-dim); }

/* ───────────────── чат ───────────────── */

.chat-wrap { display: flex; flex-direction: column; gap: 8px; padding-bottom: 86px; }
.bubble {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: var(--r-sm);
  background: var(--surface);
  white-space: pre-wrap; word-break: break-word;
  font-size: 15px;
}
.bubble.mine { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.bubble.system {
  align-self: center; max-width: 94%;
  background: transparent; color: var(--text-faint);
  font-size: 12.5px; text-align: center; padding: 6px 10px;
}
.bubble .time { font-size: 10.5px; opacity: .55; margin-top: 4px; }
.bubble .attach { display: inline-flex; gap: 6px; align-items: center; margin-top: 6px; font-size: 13.5px; text-decoration: underline; }

.composer {
  position: fixed; left: var(--edge); right: var(--edge);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px);
  padding: 6px;
  display: flex; gap: 6px; align-items: flex-end;
  background: var(--surface);
  border-radius: var(--r-lg);
  z-index: 15;
}
.composer textarea {
  flex: 1; max-height: 110px; min-height: 44px;
  padding: 12px 14px;
  background: transparent; border: none;
  color: var(--text); resize: none; font-family: inherit; font-size: 15.5px;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--text-faint); }
.composer .icon-btn { width: 44px; height: 44px; font-size: 19px; }
.composer .icon-btn.send { background: var(--accent); color: var(--accent-ink); }

/* ───────────────── формы товара ───────────────── */

.asset-row {
  display: flex; gap: 10px; align-items: center;
  padding: 13px 14px; margin-bottom: 8px;
  background: var(--surface); border-radius: var(--r-sm);
}
.asset-row .k { font-size: 11px; }

.upload-zone {
  padding: 26px 18px; text-align: center;
  border: 1.5px dashed var(--surface-3); border-radius: var(--r);
  color: var(--text-dim); cursor: pointer;
  font-size: 14.5px;
}
.upload-zone.busy { opacity: .55; }

.progress { height: 4px; background: var(--surface-2); border-radius: var(--pill); overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ───────────────── всплывашки ───────────────── */

#toast {
  position: fixed; left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  transform: translateX(-50%);
  max-width: 86vw;
  padding: 13px 20px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--pill);
  font-size: 14px; font-weight: 600; text-align: center;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.6);
}
#toast.err { background: var(--danger); color: #fff; }

#modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  display: grid; place-items: end center;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.modal-card {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 24px var(--edge) calc(22px + env(safe-area-inset-bottom));
}
.modal-card h3 { margin: 0 0 16px; font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }

/* ───────────────── админка ───────────────── */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--surface); border-radius: var(--r-sm); padding: 16px; }
.stat .n { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.stat .l { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }

.admin-tabs { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.admin-tabs::-webkit-scrollbar { display: none; }

pre.code {
  background: var(--surface-2); border-radius: var(--r-xs); padding: 12px;
  font-size: 12px; overflow-x: auto; margin: 0;
  white-space: pre-wrap; word-break: break-all;
}

.copyable { display: flex; gap: 8px; align-items: center; }
.copyable code {
  flex: 1; padding: 13px 15px;
  background: var(--surface-2); border-radius: var(--r-xs);
  font-size: 13.5px; word-break: break-all;
}

.legal { text-align: center; color: var(--text-faint); font-size: 13px; margin: 26px 0 8px; line-height: 1.5; }
.legal a { text-decoration: underline; }
