/* ==========================================================================
   eSIM Store — монохромный плоский интерфейс.

   Правила стиля, от которых не отступаем:
     • только оттенки чёрно-белого; никаких градиентов и цветных акцентов.
       Чистые #FFF и #000 не используем: бумага слегка тёплая, чернила
       не абсолютно чёрные — контраст мягче, а вид опрятнее
     • прямые углы: border-radius нигде не используется
     • плоскость: ни теней, ни размытия, ни объёма
     • разделение — волосяной линией в 1px, границы соседних блоков
       схлопываются отрицательным margin, как в таблице
     • иерархия держится на типографике: вес, размер, капитель, воздух

   Тёмная тема — точная инверсия светлой, поэтому обе описывают один и тот же
   набор переменных (расхождение ловится тестом).
   ========================================================================== */

:root[data-theme="light"] {
  --paper:     #FBFAF7;   /* бумага, а не чистый белый: мягче для глаза */
  --paper-2:   #F1EFEA;
  --ink:       #1A1815;   /* чернила вместо абсолютного чёрного */
  --ink-soft:  #45413B;
  --muted:     #6F6A61;
  --rule:      #E3DFD8;
  --rule-firm: #1A1815;
  --invert-bg: #1A1815;
  --invert-fg: #FBFAF7;
  --focus:     #1A1815;
}

:root[data-theme="dark"] {
  --paper:     #141210;   /* тёплая ночь вместо провальной черноты */
  --paper-2:   #1F1C18;
  --ink:       #F4F1EB;
  --ink-soft:  #CFCAC1;
  --muted:     #8D877D;
  --rule:      #322E28;
  --rule-firm: #F4F1EB;
  --invert-bg: #F4F1EB;
  --invert-fg: #141210;
  --focus:     #F4F1EB;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* Иконки — штриховые SVG в currentColor: в монохроме они читаются лучше
   эмодзи и одинаково выглядят на всех платформах. Эмодзи-флаги отпали
   отдельно: на десктопе Telegram они вырождаются в буквы «TR», «AE». */
.ico { display: inline-flex; }
.ico svg { display: block; width: 18px; height: 18px; }
.tile .ico svg { width: 22px; height: 22px; }
.card-right svg { display: block; width: 16px; height: 16px; color: var(--muted); }
/* ------------------------------------------------------------ шапка */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.app-bar .spacer { flex: 1; }
.wordmark {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wordmark[hidden] { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--rule-firm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}
.chip:active { background: var(--invert-bg); color: var(--invert-fg); }
.chip[hidden] { display: none; }   /* иначе display:inline-flex перебивает hidden */
.chip .ico { font-size: 13px; line-height: 1; }

/* ------------------------------------------------------------ заголовок */
.hero {
  padding: 26px 20px 28px;
  background: var(--invert-bg);
  color: var(--invert-fg);
}
.hero .eyebrow {
  margin: 0 0 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  opacity: .62;
}
.hero h1 {
  margin: 0;
  font-size: 27px;
  line-height: 1.14;
  font-weight: 800;
  letter-spacing: -.015em;
}
.hero p { margin: 12px 0 0; font-size: 13px; line-height: 1.5; opacity: .72; }
.hero-cta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 46px;
  margin-top: 18px;
  padding: 0 18px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}
.hero-cta:active { opacity: .6; }
.hero-cta svg { width: 15px; height: 15px; }

.hero .stats {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid currentColor;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .72;
}

/* ------------------------------------------------------------ разметка */
main { padding: 0 0 28px; }
.stack { display: flex; flex-direction: column; }
.pad { padding: 0 16px; }

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 24px 16px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-title button {
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  text-decoration: underline;
  cursor: pointer;
}

/* ------------------------------------------------------------ плитки */
/* Ровная сетка 2x2: волосяные линии между ячейками дают фон контейнера,
   просвечивающий сквозь gap. Пустых ячеек быть не должно — иначе gap
   покажет серый прямоугольник вместо плитки. */
.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 0;
  background: var(--rule);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  min-height: 108px;
  padding: 16px;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.tile:active { background: var(--paper-2); }
.tile .ico { font-size: 19px; line-height: 1; margin-bottom: auto; }
.tile-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; margin-top: 14px; }
.tile b { font-size: 15px; font-weight: 750; letter-spacing: -.01em; }
.tile .tile-sub { font-size: 12px; color: var(--muted); }


.badge-count {
  position: absolute;
  top: 14px;
  right: 14px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--invert-bg);
  color: var(--invert-fg);
  font-size: 11px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

/* ------------------------------------------------------------ списки */
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 15px 16px;
  border: 0;
  border-top: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.card:last-child { border-bottom: 1px solid var(--rule); }
.card:active { background: var(--paper-2); }
.card-body { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 2px; }
.card-title { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { font-size: 12px; color: var(--muted); }
/* Квадрат с флагом. Флаги — SVG из набора lipis/flag-icons (MIT), лежат
   в webapp/flags. Пропорция флага 4:3, поэтому вписываем по `cover`:
   квадрат заполняется целиком, лишнее по бокам обрезается.
   Если файла нет (регион без флага или незнакомый код) — остаётся
   двухбуквенная подпись, поэтому пустых квадратов не бывает. */
.code {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--rule-firm);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
}
.code img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-right {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.price { font-size: 15px; font-weight: 750; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ лента */
.rail {
  display: flex;
  overflow-x: auto;
  padding: 0 16px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  width: 124px;
  height: 118px;
  padding: 14px;
  margin-right: -1px;                 /* границы соседей схлопываются */
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
}
.rail-item:active { background: var(--paper-2); }
.rail-item .code { width: 30px; height: 30px; font-size: 10px; }
.rail-item b {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}
.rail-item .rail-price {
  margin-top: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ поиск */
.search {
  width: 100%;
  height: 46px;
  padding: 0 16px;
  border: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  outline: none;
}
.search::placeholder { color: var(--muted); }
.search:focus { border-color: var(--focus); }

/* ------------------------------------------------------------ панели */
.panel {
  padding: 18px 16px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  margin-top: -1px;
  background: var(--paper);
}
.panel h3 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel ol, .panel ul { margin: 0; padding-left: 20px; }
.panel li { margin-bottom: 9px; font-size: 14px; line-height: 1.5; }
.panel li:last-child { margin-bottom: 0; }

.kv { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-top: -1px; }
.kv div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 13px 16px;
  border-top: 1px solid var(--rule);
  font-size: 14px;
}
.kv div:first-child { border-top: 0; }
.kv span:first-child { color: var(--muted); }
.kv code { font-size: 12px; word-break: break-all; text-align: right; }
.kv b { font-variant-numeric: tabular-nums; }

/* Шапка внутреннего экрана: тот же инвертированный блок, что и на главной */
.summary { padding: 22px 20px 24px; background: var(--invert-bg); color: var(--invert-fg); }
.summary .code {
  width: 42px;
  height: 42px;
  margin-bottom: 14px;
  border-color: currentColor;
  font-size: 13px;
}
.summary h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.015em; }
.summary p  { margin: 8px 0 0; font-size: 13px; opacity: .72; }

/* ------------------------------------------------------------ кнопки */
.btn {
  display: block;
  width: calc(100% - 32px);
  margin: 20px 16px 0;
  height: 52px;
  border: 1px solid var(--invert-bg);
  background: var(--invert-bg);
  color: var(--invert-fg);
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn:active { opacity: .82; }
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--paper); color: var(--ink); border-color: var(--rule-firm); }

.link {
  display: block;
  width: 100%;
  padding: 16px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}
.link:active { background: var(--paper-2); }

/* ------------------------------------------------------------ прочее */
.qr {
  display: grid;
  place-items: center;
  padding: 22px 16px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  background: #FFFFFF;   /* ровно белый: важно для надёжности сканирования */
}
.qr img { width: 100%; max-width: 240px; image-rendering: pixelated; }

.pill {
  display: inline-block;
  margin-top: 10px;
  padding: 3px 9px;
  border: 1px solid currentColor;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.note { padding: 12px 16px 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.loader, .empty { padding: 56px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* Скелет: те же волосяные строки, что и в готовом списке, — переход
   от загрузки к данным не «прыгает». */
.skeleton-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 16px;
  border-top: 1px solid var(--rule);
}
.skeleton-row:last-child { border-bottom: 1px solid var(--rule); }
.skeleton-box { background: var(--paper-2); animation: pulse 1.4s ease-in-out infinite; }
.skeleton-badge { width: 34px; height: 34px; flex: 0 0 auto; }
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.skeleton-line { height: 11px; }
.skeleton-line.short { width: 42%; height: 9px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.fade-in { animation: fade .18s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
