/* Цвета берём из темы Telegram (переменные ставит telegram-web-app.js); запасные — для светлой темы */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #14161a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f7bf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7bf6);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sep: var(--tg-theme-section-separator-color, rgba(128, 128, 140, 0.18));
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --ok: #22a06b;
  --warn: #e8a317;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --tabbar-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
video { display: block; }

/* ───── шапка ───── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--sep);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; min-width: 0; }
.brand span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-logo { font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.balance-pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 12px; border-radius: 17px;
  background: var(--bg); font-weight: 650; font-variant-numeric: tabular-nums;
}
.balance-icon { font-size: 14px; }

/* ───── кнопки ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 18px; border-radius: 14px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 650; font-size: 16px;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn-small { height: 34px; padding: 0 14px; border-radius: 17px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-soft { background: var(--soft); color: var(--link); }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-surface { background: var(--surface); color: var(--text); }
.btn-danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn .spinner { width: 18px; height: 18px; border-width: 2px; }

/* ───── основной экран ───── */
.view { padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px); min-height: 60vh; }
.section-head { display: flex; align-items: center; gap: 8px; margin: 4px 2px 14px; }
.section-title { font-size: 22px; font-weight: 750; letter-spacing: -.01em; margin: 0; }
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 12px;
  background: var(--soft); color: var(--link); font-size: 12.5px; font-weight: 650; white-space: nowrap;
}
.muted { color: var(--hint); }
.small { font-size: 13px; }

/* ───── карточки трендов ───── */
.trends-head { display: flex; align-items: center; gap: 10px; margin: 4px 2px 16px; }
.trends-head .fire { font-size: 28px; line-height: 1; flex-shrink: 0; }
.trends-head h1 { margin: 0; font-size: 20px; font-weight: 800; line-height: 1.2; text-transform: uppercase; letter-spacing: .01em; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.trend-card {
  position: relative; display: block; width: 100%; overflow: hidden; isolation: isolate;
  aspect-ratio: 9 / 13; border-radius: 24px; background: #111216; text-align: left;
  border: 1px solid color-mix(in srgb, var(--text) 14%, transparent);
}
.trend-card video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-badges { position: absolute; top: 8px; left: 8px; right: 8px; z-index: 1; display: flex; align-items: center; gap: 4px; }
.glass { background: rgba(20, 21, 26, .6); color: #fff; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.badge-icon { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.badge-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; }
.badge {
  height: 30px; padding: 0 9px; border-radius: 15px; min-width: 0;
  display: inline-flex; align-items: center; font-size: 12px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.trend-card .overlay {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 56px 14px 14px; color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, .82), rgba(0, 0, 0, .4) 55%, rgba(0, 0, 0, 0));
}
.trend-card .title { font-size: 16.5px; font-weight: 750; line-height: 1.22; margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.trend-card .price { font-size: 13.5px; color: rgba(255, 255, 255, .72); }

/* ───── пустые состояния ───── */
.empty { text-align: center; padding: 48px 16px; }
.empty .emoji { font-size: 52px; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; font-size: 19px; }
.empty p { margin: 0 0 20px; color: var(--hint); }

/* ───── списки (история, админка) ───── */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; }
.row + .row { border-top: 1px solid var(--sep); }
.row-icon {
  flex-shrink: 0; width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center; font-size: 20px; background: var(--bg); overflow: hidden;
}
.row-icon video { width: 100%; height: 100%; object-fit: cover; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--hint); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px;
  border-radius: 13px; font-size: 12.5px; font-weight: 650; }
.status.done { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.status.pending { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.status.failed { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.more { margin-top: 12px; }

/* ───── профиль ───── */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.card + .card, .card + .btn, .btn + .card { margin-top: 12px; }
.stack > * + * { margin-top: 12px; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: grid; place-items: center; background: var(--soft); color: var(--link); font-weight: 750; font-size: 22px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-name { font-size: 19px; font-weight: 750; }
.balance-big { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.balance-big .value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.card-title { font-weight: 750; font-size: 16px; margin: 0 0 4px; }
.link-field {
  display: flex; align-items: center; gap: 8px; margin: 12px 0;
  background: var(--bg); border-radius: var(--radius-sm); padding: 4px 4px 4px 12px;
}
.link-field input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 14px; color: var(--link); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.stat { background: var(--bg); border-radius: var(--radius-sm); padding: 10px; text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--hint); font-size: 12px; }
.stat small { display: block; color: var(--hint); font-size: 11px; margin-top: 2px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* ───── нижняя панель ───── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--sep);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--hint);
  font-size: 11.5px; font-weight: 600; }
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }

/* ───── нижние шторки ───── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45);
  opacity: 0; transition: opacity .2s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(var(--safe-bottom) + 20px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: translateY(0); }
.sheet-backdrop.open { opacity: 1; }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 750; }
.icon-btn { width: 32px; height: 32px; border-radius: 16px; background: var(--bg); color: var(--hint); font-size: 18px; line-height: 32px; flex-shrink: 0; }
.sheet-video { width: 100%; max-height: 46vh; object-fit: contain; border-radius: var(--radius); background: #000; }
.sheet-media { position: relative; display: block; width: 100%; }
.sheet-media .sheet-video { display: block; }
.sound-btn { position: absolute; right: 10px; bottom: 10px; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; }
.sound-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.field-label { font-weight: 650; margin: 18px 0 8px; display: block; }
.hint-text { color: var(--hint); font-size: 13px; margin-top: 6px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--bg); padding: 4px; border-radius: 14px; }
.segmented button { border-radius: 11px; padding: 9px 6px; text-align: center; color: var(--hint); font-weight: 650; }
.segmented button small { display: block; font-weight: 500; font-size: 12px; margin-top: 1px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

.photo-slots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.photo-slot {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  border: 1.5px dashed color-mix(in srgb, var(--hint) 55%, transparent);
  display: grid; place-items: center; color: var(--hint); font-size: 26px; background: var(--bg);
}
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot.filled { border-style: solid; border-color: transparent; }
.photo-slot .remove {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 11px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 14px; line-height: 22px;
}
.photo-slot small { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 11px; }
.sheet-actions { margin-top: 20px; }
.sheet-actions .btn + .btn { margin-top: 8px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--bg); font-size: 14px; }
.notice.error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
.success-box { text-align: center; padding: 18px 4px 4px; }
.success-box .emoji { font-size: 48px; }
.success-box h3 { margin: 8px 0 6px; font-size: 19px; }
.success-box p { margin: 0 0 18px; color: var(--hint); }

/* ───── пакеты оплаты ───── */
.package { background: var(--bg); border-radius: var(--radius); padding: 14px; }
.package + .package { margin-top: 10px; }
.package-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.package-head b { font-size: 17px; }
.package .btn { height: 42px; font-size: 15px; }

/* ───── админка ───── */
.form-input, .form-textarea, .form-select {
  width: 100%; border: 1px solid var(--sep); background: var(--bg); border-radius: var(--radius-sm);
  padding: 11px 12px; outline: none;
}
.form-textarea { min-height: 130px; resize: vertical; line-height: 1.4; }
.form-input:focus, .form-textarea:focus, .form-select:focus { border-color: var(--accent); }
.prompt-tools { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.prompt-tools .hint-text { margin-top: 0; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.video-pick { display: flex; align-items: center; gap: 12px; }
.video-pick video { width: 72px; height: 96px; object-fit: cover; border-radius: 10px; background: #000; flex-shrink: 0; }
.admin-row .row-sub { white-space: normal; }
.admin-row .row-sub b { color: var(--text); font-weight: 600; }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.row-actions button { width: 34px; height: 34px; border-radius: 17px; background: var(--bg); font-size: 15px; }
.hidden-badge { color: var(--danger); font-weight: 650; }

/* ───── мелочи ───── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px;
  background: rgba(20, 22, 26, .92); color: #fff; font-size: 14px; text-align: center;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
  animation: spin .8s linear infinite; display: inline-block;
}
.center { display: grid; place-items: center; padding: 48px 0; color: var(--hint); }
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, color-mix(in srgb, var(--surface) 70%, var(--bg)) 50%, var(--surface) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 24px; aspect-ratio: 9 / 13; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 370px) {           /* Android 360 px: плашка «★ Популярное» иначе обрезается */
  .badge { font-size: 11px; padding: 0 8px; }
}
@media (max-width: 340px) {
  .badge-icon { display: none; }     /* совсем узкие экраны: плашке нужнее место */
}
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .view, .sheet { max-width: 640px; margin-left: auto; margin-right: auto; }
}

/* Невидимый, но рабочий input: с display:none часть WebView не открывает выбор файла по нажатию на label */
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
