/* Витрина набора эмодзи. Цвета берутся из темы Telegram, а если витрину
   открыли в обычном браузере — из системной светлой/тёмной схемы. */

:root {
  --bg: #ffffff;
  --fg: #0f1115;
  --muted: #6b7280;
  --card: #f4f5f7;
  --line: #e4e6ea;
  --accent: #2f86e0;
  --accent-fg: #ffffff;
  --danger: #d64545;
  --radius: 14px;
  --pad: 14px;
  --bar-h: 68px;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --fg: #f2f3f5;
    --muted: #9aa0a8;
    --card: #22242a;
    --line: #33363d;
  }
}

body.tg {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #0f1115);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --card: var(--tg-theme-secondary-bg-color, #f4f5f7);
  --accent: var(--tg-theme-button-color, #2f86e0);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Любой явный `display` в правилах ниже перебивает браузерное
   `[hidden] { display: none }`. Без этого прячущиеся через `hidden` элементы
   (hex-поле, вкладка «Админ») видны всем и всегда. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 0 var(--pad);
  /* Место под нижнюю панель и таббар, плюс вырез на iPhone. */
  padding-bottom: calc(var(--bar-h) + var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  overscroll-behavior-y: contain;
}

.loader, .fatal { padding: 40px var(--pad); text-align: center; color: var(--muted); }
.fatal { color: var(--danger); }

/* -- шапка -------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 10px;
  background: var(--bg);
}
.topbar__title {
  font-size: 17px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.chip__unit { font-weight: 500; color: var(--muted); margin-left: 4px; font-size: 12px; }

.pack-desc { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.h2 { font-size: 15px; font-weight: 700; margin: 22px 0 8px; }

/* -- поля --------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field__row { display: flex; align-items: baseline; gap: 10px; }
.field__label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: 6px;
  flex: 1;
}
.linkbtn {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 6px;
}
.linkbtn.is-set { color: #2aa66a; }

.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--fg);
  padding: 12px 14px;
  font-size: 17px;
  font-weight: 600;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input.bad { border-color: var(--danger); }
.input--hex { text-transform: uppercase; font-size: 15px; }

.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.hint.bad { color: var(--danger); }
.hint.ok { color: #2aa66a; }

/* -- цвет --------------------------------------------------------------- */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
  position: relative;
}
.swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.swatch--custom {
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--fg);
  background: conic-gradient(#f44, #fa4, #ff4, #4f4, #4ff, #44f, #f4f, #f44);
}
.hexrow { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.hexrow .input { flex: 1; }
.colorpicker {
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  flex: none;
}

/* -- сетка эмодзи ------------------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0 12px;
}
.toolbar__count { color: var(--muted); font-size: 13px; flex: 1; }
.toolbar__count b { color: var(--fg); }
.toolbar__actions { display: flex; gap: 6px; }

.grid {
  display: grid;
  /* 72px даёт четыре колонки на телефоне: из 93 карточек важно видеть
     сразу много, иначе выбор превращается в бесконечную прокрутку. */
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.cell {
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .12s, transform .1s, opacity .12s;
  /* Подложка светлая в обеих темах намеренно: эмодзи — чёрная контурная
     графика на прозрачном фоне, на тёмной карточке она просто исчезает.
     Шахматка поверх показывает, что фон именно прозрачный. */
  background-color: #f7f7fa;
  background-image:
    linear-gradient(45deg, rgba(0,0,0,.05) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0,0,0,.05) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,.05) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,.05) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}
.cell img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cell:active { transform: scale(.94); }
.cell.on { border-color: var(--accent); }
/* Невыбранное приглушаем, чтобы выбор читался одним взглядом по всей сетке. */
.cell:not(.on) { opacity: .42; filter: grayscale(1); }
.cell__tick {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  opacity: 0;
  transition: opacity .12s;
}
.cell.on .cell__tick { opacity: 1; }

/* -- профиль ------------------------------------------------------------ */
.profile { display: flex; align-items: center; gap: 14px; margin: 4px 0 18px; }
.avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--card);
}
.avatar--stub {
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--muted);
  border: 1px solid var(--line);
}
.profile__meta { min-width: 0; }
.profile__name { font-size: 18px; font-weight: 700; }
.profile__id { color: var(--muted); font-size: 13px; }

.balance-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.balance-card__value { font-size: 26px; font-weight: 700; }
.balance-card__rate { color: var(--muted); font-size: 13px; margin-top: 2px; }

.packages { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.package {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  text-align: left;
}
.package__shifts { font-size: 17px; font-weight: 700; }
.package__stars { color: var(--muted); font-size: 13px; }
.package__bonus { color: #2aa66a; font-size: 12px; font-weight: 600; }

.orders, .txs { display: flex; flex-direction: column; gap: 8px; }
.order, .tx {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
}
.order__top { display: flex; justify-content: space-between; gap: 10px; }
.order__title { font-weight: 700; }
.order__status { color: var(--muted); font-size: 13px; white-space: nowrap; }
.order__meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.order a { color: var(--accent); font-weight: 600; text-decoration: none; }
.tx { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.tx__amount { font-weight: 700; white-space: nowrap; }
.tx__amount.plus { color: #2aa66a; }
.tx__amount.minus { color: var(--danger); }
.tx__note { color: var(--muted); font-size: 13px; min-width: 0; }
.empty { color: var(--muted); font-size: 14px; }

/* -- кнопки ------------------------------------------------------------- */
.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn--ghost { padding: 8px 12px; }
.btn--primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; }
.btn--danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn--wide { flex: 1; padding: 14px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: default; }

/* -- нижняя панель и таббар --------------------------------------------- */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--pad);
  background: var(--bg);
  border-top: 1px solid var(--line);
  z-index: 6;
}
.bar__price { font-size: 19px; font-weight: 700; white-space: nowrap; }
.bar__unit { font-size: 13px; font-weight: 500; color: var(--muted); }
.bar__hint { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); }
/* Внутри Telegram действие живёт в MainButton — своя панель была бы второй
   кнопкой о том же. Вкладка профиля тоже не про выбор эмодзи. */
body.tg-mainbutton .bar,
body.tab-profile .bar,
body.tab-admin .bar { display: none; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 7;
}
.tabbar__item {
  flex: 1;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  height: var(--tabbar-h);
  justify-content: center;
}
.tabbar__item.is-active { color: var(--accent); }
.tabbar__icon { font-size: 18px; line-height: 1; }

/* -- тост --------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + var(--tabbar-h) + 16px);
  transform: translateX(-50%);
  background: rgba(20, 20, 24, .94);
  color: #fff;
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 20;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.bad { background: var(--danger); }

/* -- лист подтверждения ------------------------------------------------- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
  padding: 12px;
}
.sheet__card {
  background: var(--bg);
  border-radius: 18px;
  padding: 18px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
}
.sheet__close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.sheet__img {
  width: 100%;
  border-radius: var(--radius);
  background: #f7f7fa;
  margin-bottom: 12px;
  display: block;
}
.sheet__rows { margin-bottom: 14px; }
.sheet__rows div {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.sheet__rows div:last-child { border-bottom: 0; }
.sheet__rows span { color: var(--muted); }
.sheet__card .btn { margin-top: 8px; }

/* Вывод админских ответов — моноширинным, там таблицы и id. */
.out {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 10px;
  max-height: 240px;
  overflow-y: auto;
}


/* -- живой предпросмотр -------------------------------------------------
   Слово и цвет иначе никак не проверить: в сетке лежат исходные картинки
   набора, и выбор цвета там не виден вообще. */
.live {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f7f7fa;
  padding: 8px;
  margin-bottom: 14px;
  position: relative;
  min-height: 90px;
}
.live__img { width: 100%; display: block; border-radius: 8px; }
.live__note {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding-top: 6px;
}
.live.is-busy { opacity: .5; }


/* «Как в наборе» — не цвет, а отказ от перекраски: показываем это крестиком,
   а не пустым кружком, который читается как «белый». */
.swatch--none {
  display: grid;
  place-items: center;
  font-size: 17px;
  color: var(--muted);
  background: var(--card);
}
.swatches + .field__label { display: block; }
