/* ============ XMAPKET: строгий монохром, две темы, без градиентов и эмодзи ============ */
:root, :root[data-theme="dark"] {
  --bg: #000000;
  --bg2: #0c0c0c;
  --bg3: #161616;
  --text: #ffffff;
  --hint: #8a8a8a;
  --line: rgba(255, 255, 255, .14);
  --line-strong: rgba(255, 255, 255, .32);
  --inv-bg: #ffffff;
  --inv-text: #000000;
  --danger: #ff453a;
  --danger-line: rgba(255, 69, 58, .45);
  /* старые имена, которые ещё встречаются в разметке */
  --btn: var(--inv-bg);
  --btn-text: var(--inv-text);
  --link: var(--text);
  --radius: 12px;
  --icon-filter: grayscale(1) brightness(0) invert(1);
  --icon-filter-inv: grayscale(1) brightness(0);
  --brand-h: 52px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --bg2: #f5f5f5;
  --bg3: #ebebeb;
  --text: #000000;
  --hint: #767676;
  --line: rgba(0, 0, 0, .12);
  --line-strong: rgba(0, 0, 0, .3);
  --inv-bg: #000000;
  --inv-text: #ffffff;
  --danger: #d70015;
  --danger-line: rgba(215, 0, 21, .4);
  --icon-filter: grayscale(1) brightness(0);
  --icon-filter-inv: grayscale(1) brightness(0) invert(1);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); transition: background-color .2s, color .2s; }
body {
  font: 15px/1.45 "Inter", -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  padding-top: var(--brand-h);
  min-height: 100vh;
}
h1, h2, h3, .stat .v, .stat3 .v, .chat-name, .card-title {
  font-family: "Unbounded", "Inter", system-ui, sans-serif; letter-spacing: -.01em;
}
.view { padding: 14px 16px 40px; max-width: 720px; margin: 0 auto; }
.view:not(.hidden) { animation: viewIn .22s ease-out; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }
.muted { color: var(--hint); }
.small { font-size: 13px; margin: 4px 0 10px; }
h1 { font-size: 22px; font-weight: 800; margin: 4px 0 6px; display: flex; align-items: center; gap: 8px; text-transform: uppercase; }
h2 { font-size: 14px; font-weight: 700; margin: 0; text-transform: uppercase; letter-spacing: .02em; }
a { color: var(--text); }

/* ---------- верхняя плашка с логотипом ---------- */
.brandbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 15; height: var(--brand-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; color: var(--text); cursor: pointer; }
.logo { height: 22px; width: auto; display: block; }
.brand-actions { display: flex; gap: 6px; }

/* ---------- иконки ---------- */
.ic { display: inline-flex; width: 1.2em; height: 1.2em; vertical-align: -0.22em; align-items: center; justify-content: center; flex: none; }
.ic svg { width: 100%; height: 100%; display: block; }
.ic .media { width: 100%; height: 100%; }
/* иконки из набора перекрашиваются в цвет темы */
.ic-pack .media { filter: var(--icon-filter); }
.btn.primary .ic-pack .media, .tab.active .ic-pack .media, .chip-btn.active .ic-pack .media,
.chat-input .send .ic-pack .media, .badge .ic-pack .media { filter: var(--icon-filter-inv); }
.ic-text { font-size: 1em; line-height: 1; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 11px 14px;
  font: inherit; font-weight: 600; background: transparent; color: var(--text); cursor: pointer; flex: 1;
  transition: transform .1s, background-color .15s, color .15s, border-color .15s;
}
.btn:hover { border-color: var(--text); }
.btn:active, .icon-btn:active, .tab:active, .chip-btn:active, .pack-card:active, .dialog:active, .slot:active { transform: scale(.97); }
.btn.primary { background: var(--inv-bg); color: var(--inv-text); border-color: var(--inv-bg); }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .4; }
.btn.locked { opacity: .55; }
.link { background: none; border: 0; color: var(--text); font: inherit; font-weight: 600; padding: 4px 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px;
  font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text);
  transition: transform .1s, border-color .15s;
}
.icon-btn:hover { border-color: var(--text); }
.row, .actions { display: flex; gap: 8px; margin-top: 12px; }
.row.tight { margin-top: 6px; }
.actions { position: sticky; bottom: 8px; background: var(--bg); padding: 6px 0; }

/* ---------- поверхности ---------- */
.card, .note, .switch-row, .pack-card, .stat, .stat3, .pay, .slot, .dialog {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
}
.card { padding: 12px; margin-bottom: 8px; }
.card.premium { border-color: var(--line-strong); }
.card-title { font-weight: 700; display: flex; align-items: center; gap: 7px; font-size: 13px; text-transform: uppercase; }
.note { padding: 10px 12px; margin-bottom: 10px; }
.empty { color: var(--hint); text-align: center; padding: 18px 0; }

/* главная */
.home-head { margin-bottom: 12px; }
.stats3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat3 { padding: 10px 12px; }
.stat3 .v { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat3 .k { font-size: 12px; color: var(--hint); }

.packs { display: flex; flex-direction: column; gap: 8px; }
.pack-card { display: flex; align-items: center; gap: 12px; padding: 10px; cursor: pointer; transition: transform .1s, border-color .15s; }
.pack-card:hover { border-color: var(--line-strong); }
.pack-card .cover { width: 54px; height: 54px; flex: none; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.pack-card .info { flex: 1; min-width: 0; }
.pack-card .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pack-card .chev { color: var(--hint); display: flex; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--inv-text); background: var(--inv-bg); border-radius: 6px; padding: 2px 7px; }
.lock-badge { font-size: 12px; color: var(--hint); display: inline-flex; align-items: center; gap: 4px; }

.section { margin-top: 24px; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.section-head h2 { display: flex; align-items: center; gap: 6px; }

/* набор */
.bar { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.title-input {
  flex: 1; font-family: "Unbounded", "Inter", sans-serif; font-size: 19px; font-weight: 700; line-height: 1.3; color: var(--text);
  background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 6px 0; outline: none; min-width: 0;
}
.title-input:focus { border-bottom-color: var(--text); }
.link-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-width: 0; }
.link-text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 8px; }
.switch { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--bg3); border: 1px solid var(--line-strong); position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--hint); transition: transform .15s, background .15s; }
.switch:checked { background: var(--inv-bg); border-color: var(--inv-bg); }
.switch:checked::after { transform: translateX(18px); background: var(--inv-text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; transition: transform .1s;
}
.tile:active { transform: scale(.94); }
.grid .tile { animation: tileIn .25s both; }
@keyframes tileIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
.tile .em { position: absolute; right: 3px; bottom: 2px; font-size: 13px; }
.tile.selected { border: 2px solid var(--text); }
.tile.selected::before {
  content: ""; position: absolute; top: 5px; left: 5px; width: 18px; height: 18px; border-radius: 50%; z-index: 2;
  background: var(--inv-bg);
}
.tile.ghost { opacity: .25; }
.tile.chosen { transform: scale(1.06); }
.tile.auto { font-size: 12px; color: var(--hint); text-align: center; }
.media { width: 86%; height: 86%; object-fit: contain; pointer-events: none; display: block; }
.media svg { width: 100% !important; height: 100% !important; }

/* ---------- шторка, загрузка, тост ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.sheet:not(.hidden) .sheet-backdrop { animation: fadeIn .18s ease; }
.sheet:not(.hidden) .sheet-body { animation: sheetIn .26s cubic-bezier(.2, .9, .25, 1); }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet-body {
  position: relative; width: 100%; max-width: 720px; max-height: 85vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet-body::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: -8px auto 14px; }
.sheet-body h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; text-transform: uppercase; }
.preview { width: 180px; height: 180px; margin: 0 auto 12px; display: flex; align-items: center; justify-content: center; }
.field {
  width: 100%; font: inherit; font-size: 20px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); outline: none;
}
.field:focus { border-color: var(--text); }
.field.text { font-size: 16px; }
.field.area { resize: vertical; min-height: 120px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.5; }
.field.gap { margin-top: 6px; }
select.field { appearance: none; -webkit-appearance: none; }
.emoji-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; min-height: 30px; }
.chip { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; font-size: 20px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.busy {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55);
  display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; color: #fff;
}
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; top: calc(var(--brand-h) + 10px); transform: translateX(-50%);
  z-index: 50; background: var(--inv-bg); color: var(--inv-text); padding: 9px 14px; border-radius: 10px;
  max-width: calc(100% - 32px); font-size: 14px; font-weight: 600;
}
.toast:not(.hidden) { animation: toastIn .2s ease-out; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- админка ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.tab, .chip-btn {
  flex: none; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; background: transparent;
  color: var(--text); font: inherit; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  transition: transform .1s, background-color .15s;
}
.tab.active, .chip-btn.active { background: var(--inv-bg); color: var(--inv-text); border-color: var(--inv-bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip-btn .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .6; }
.count { background: var(--danger); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 18px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { padding: 12px; }
.stat .v { font-size: 22px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.stat .k { color: var(--hint); font-size: 12px; }
h2.sub { font-size: 13px; margin: 22px 0 8px; display: flex; align-items: center; gap: 6px; }
.lbl { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 16px 0 6px; }
.card .lbl:first-child { margin-top: 0; }
.photo-box img { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; border: 1px solid var(--line); }
.pay { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.pay .info { flex: 1; min-width: 0; }
.pay .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.pay.refunded { opacity: .45; }
.slot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer; }
.slot .ic { width: 28px; height: 28px; font-size: 24px; }
.slot .name { flex: 1; font-weight: 600; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.icon-grid .tile > .media { filter: var(--icon-filter); }
.icon-grid .tile .ic { width: 26px; height: 26px; }

/* ---------- диалоги ---------- */
.dialog { display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--inv-bg); color: var(--inv-text); display: flex; align-items: center; justify-content: center; font-family: "Unbounded", sans-serif; font-weight: 700; font-size: 16px; flex: none; }
.dialog .info { flex: 1; min-width: 0; }
.dialog .top { display: flex; justify-content: space-between; gap: 8px; }
.dialog .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog .when { color: var(--hint); font-size: 12px; flex: none; }
.dialog .prev { color: var(--hint); font-size: 14px; white-space: nowrap; overflow: hidden; display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.dialog .prev span:first-child { overflow: hidden; text-overflow: ellipsis; }

/* ---------- чат ---------- */
.chat-view { padding: 0; display: flex; flex-direction: column; height: calc(100vh - var(--brand-h)); height: calc(var(--tg-viewport-height, 100dvh) - var(--brand-h)); max-width: 720px; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.chat-name { font-weight: 700; font-size: 14px; text-transform: uppercase; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 7px 11px 5px; border-radius: 14px 14px 14px 4px; background: var(--bg2); border: 1px solid var(--line); align-self: flex-start; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: var(--inv-bg); color: var(--inv-text); border-color: var(--inv-bg); border-radius: 14px 14px 4px 14px; }
.msg.out a { color: inherit; }
.msg .time { font-size: 11px; opacity: .55; text-align: right; margin-top: 2px; }
.msg img.ph, .msg video { max-width: 100%; max-height: 300px; border-radius: 9px; display: block; margin-bottom: 4px; }
.msg.sticker { background: transparent; border: 0; padding: 0; }
.msg.sticker .media { width: 140px; height: 140px; }
.msg.sticker .time { color: var(--hint); }
.msg audio { max-width: 240px; display: block; }
.msg blockquote { margin: 4px 0; padding: 2px 8px; border-left: 2px solid currentColor; }
.msg .file-link { display: inline-flex; align-items: center; gap: 4px; }
.day-sep { align-self: center; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--hint); border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; margin: 6px 0; }
.chat-input { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.chat-input textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; background: var(--bg2); color: var(--text); font: inherit; padding: 9px 12px; max-height: 120px; outline: none; }
.chat-input textarea:focus { border-color: var(--text); }
.chat-input .send { background: var(--inv-bg); color: var(--inv-text); border-color: var(--inv-bg); }
.tg-spoiler { background: currentColor; border-radius: 3px; }
.tg-spoiler.open { background: transparent; }
