/* Фирменный стиль Muratov.tech: белый фон, оранжевый акцент, персиковые градиенты.
   Все цвета приложения — здесь. Фон и цвет меню также продублированы
   в app.js (setupTelegram) и index.html (theme-color) для шапки Telegram. */
:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface2: #FFF3E8;
  --line: #F1E4D8;
  --text: #1C1C1C;
  --text-soft: #3D3D3D;
  --muted: #7A7A7A;
  --accent: #F37A1F;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(243, 122, 31, .12);
  --peach: linear-gradient(135deg, #FFF8F1 0%, #FDE3CB 100%);
  --shadow: 0 6px 24px rgba(28, 28, 28, .08);
  --tabbar-bg: rgba(255, 255, 255, .97);
  --toast-bg: #1C1C1C;
  --warn: #D9861A;
  --danger: #E04B3C;
  --ok: #3BA55C;
  --radius: 20px;
  --tabbar-h: 60px;
  /* В полноэкранном режиме Telegram сверху свои кнопки — отступаем от них. */
  --top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); }
body {
  color: var(--text);
  font: 15px/1.45 "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; }
.ic { display: inline-grid; place-items: center; }
.ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#views { position: relative; flex: 1; overflow: hidden; }
.view {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .3s;
}
.view.left { transform: translateX(-22%); opacity: 0; pointer-events: none; visibility: hidden; }
.view.right { transform: translateX(22%); opacity: 0; pointer-events: none; visibility: hidden; }
.view.active { transform: none; opacity: 1; visibility: visible; }
.view.no-anim { transition: none; }
@media (prefers-reduced-motion: reduce) { .view { transition: opacity .15s; } .view.left, .view.right { transform: none; } }

.page { max-width: 640px; margin: 0 auto; padding: calc(var(--top) + 18px) 16px 28px; }
.page-head { margin-bottom: 16px; }
h1 { font-size: 30px; line-height: 1.1; font-weight: 800; letter-spacing: -.02em; color: var(--accent); }
.sub { color: var(--text); font-size: 15px; font-weight: 600; margin-top: 4px; }
.empty { color: var(--muted); text-align: center; padding: 48px 12px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 2px; }

/* Фирменная плашка сверху, как на сайте */
.brandbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--accent); color: #fff; border-radius: 18px; padding: 12px 14px 12px 18px; margin-bottom: 18px;
}
.brandbar b { font-weight: 700; font-size: 16px; letter-spacing: .01em; }
.brandbar span { background: #fff; color: var(--accent); font-size: 12px; font-weight: 700; padding: 6px 12px; border-radius: 999px; white-space: nowrap; }

.web-banner {
  flex: none; background: var(--surface2); color: #8A4A12;
  border-bottom: 1px solid var(--line); font-size: 12.5px; font-weight: 500; padding: 8px 16px; text-align: center;
}

/* ---------- нижнее меню ---------- */
#tabbar {
  flex: none; display: grid; grid-template-columns: repeat(var(--n, 4), 1fr);
  height: calc(var(--tabbar-h) + var(--bottom)); padding-bottom: var(--bottom);
  background: var(--tabbar-bg); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 20px rgba(28, 28, 28, .04);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: #9A9A9A; font-size: 10.5px; font-weight: 600; transition: color .2s; min-width: 0; }
.tab span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; padding: 0 2px; }
.tab .ic svg { transition: transform .2s; }
.tab.on { color: var(--accent); }
.tab.on .ic svg { transform: translateY(-1px) scale(1.06); }
.tab.admin { color: var(--warn); }
.tab.admin.on { color: var(--warn); }

/* ---------- кнопки ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border-radius: 999px; padding: 14px 18px; font-weight: 700; font-size: 15px;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; transition: transform .1s, opacity .2s;
  box-shadow: 0 6px 16px rgba(243, 122, 31, .28);
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--surface2); color: var(--accent); box-shadow: none; }
.btn.small { width: auto; padding: 9px 16px; font-size: 13.5px; }
.btn .ic svg { width: 18px; height: 18px; }
.btn + .btn { margin-top: 10px; }

/* ---------- «Про канал» ---------- */
.about { text-align: center; }
.about .brandbar { text-align: left; }
.ava {
  width: 108px; height: 108px; border-radius: 50%; margin: 6px auto 14px; overflow: hidden;
  background: var(--peach); color: var(--accent); display: grid; place-items: center; font-size: 34px; font-weight: 800;
  box-shadow: 0 0 0 5px #fff, 0 0 0 7px var(--accent-soft), var(--shadow);
}
.ava img { width: 100%; height: 100%; object-fit: cover; }
.about h1 { font-size: 26px; color: var(--text); }
.about .sub { color: var(--accent); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.about-desc {
  background: var(--peach); border-radius: var(--radius); padding: 16px; margin: 18px 0 14px;
  color: var(--text-soft); font-size: 14px; white-space: pre-line; text-align: left; user-select: text;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 6px; }
.stats b { display: block; font-size: 22px; font-weight: 800; color: var(--accent); }
.stats span { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.quick { display: grid; gap: 8px; margin-top: 16px; }
.quick button { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 13px 14px; text-align: left; }
.quick button .ic { color: var(--accent); background: var(--accent-soft); width: 38px; height: 38px; border-radius: 12px; }
.quick button span:nth-child(2) { flex: 1; font-weight: 700; }
.quick i { color: var(--muted); font-style: normal; font-size: 13px; font-weight: 600; }

/* ---------- карточки ---------- */
.cards { display: grid; gap: 16px; }
@media (min-width: 560px) { .cards { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); border: 1px solid #F6EEE6; }
.cover { position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; background: var(--peach); overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover .ph { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; padding: 0 22px; background: var(--peach); }
.cover .ph b { font-size: 52px; font-weight: 800; color: var(--accent); letter-spacing: -.03em; line-height: 1; }
.cover .ph span { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; color: #B5652A; }
.num { position: absolute; top: 10px; left: 10px; background: var(--accent); color: #fff; border-radius: 999px; padding: 3px 11px; font-size: 12px; font-weight: 700; }
.dur { position: absolute; bottom: 10px; right: 10px; background: rgba(28, 28, 28, .7); color: #fff; backdrop-filter: blur(6px); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.cover .play {
  position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; transition: transform .15s;
  box-shadow: 0 6px 18px rgba(243, 122, 31, .45);
}
.cover .play svg { fill: currentColor; stroke: none; width: 24px; height: 24px; margin-left: 3px; }
.cover:active .play { transform: scale(.92); }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; flex: 1; }
.kind { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--accent); font-weight: 700; margin-bottom: 5px; }
.card h3 { font-size: 16px; line-height: 1.3; font-weight: 700; margin-bottom: 6px; }
.desc { color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 14px; white-space: pre-line; }
.watch {
  margin-top: auto; align-self: flex-start; display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13.5px; padding: 9px 18px 9px 14px; border-radius: 999px;
}
.watch svg { fill: currentColor; stroke: none; width: 16px; height: 16px; }

/* Материалы («Полезности»): обложка ниже, иконки контурные, есть имя файла */
.card.doc .cover { aspect-ratio: 16 / 6; }
.card.doc .cover .ph b { font-size: 40px; }
.card.doc .play svg, .card.doc .watch svg { fill: none; stroke: currentColor; stroke-width: 2.2; margin-left: 0; }
.file { font-size: 12.5px; font-weight: 600; color: #A85512; background: var(--surface2); border-radius: 8px; padding: 5px 9px; align-self: flex-start; margin-bottom: 12px; word-break: break-all; }
.watch:active { transform: scale(.97); }

/* ---------- шторка ---------- */
#sheet-layer { position: fixed; inset: 0; z-index: 20; }
.sheet-dim { position: absolute; inset: 0; background: rgba(28, 28, 28, .45); opacity: 0; transition: opacity .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92%; max-width: 640px; margin: 0 auto;
  background: var(--surface); border-radius: 24px 24px 0 0; padding: 10px 16px calc(20px + var(--bottom));
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2, .8, .2, 1); display: flex; flex-direction: column;
}
.sheet.tall { height: calc(92% - var(--top)); }
#sheet-layer.open .sheet-dim { opacity: 1; }
#sheet-layer.open .sheet { transform: none; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: #E2D6CB; margin: 0 auto 12px; flex: none; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; flex: 1; }

.video { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 16px; overflow: hidden; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-meta { padding: 14px 2px 4px; }
.player-meta h3 { font-size: 18px; line-height: 1.3; font-weight: 800; margin-bottom: 8px; }
.full-desc { color: var(--text-soft); font-size: 14px; white-space: pre-line; margin-bottom: 14px; user-select: text; }

.gate { text-align: center; padding: 10px 6px 4px; }
.lock { width: 76px; height: 76px; border-radius: 50%; background: var(--peach); display: grid; place-items: center; margin: 4px auto 14px; color: var(--accent); }
.lock svg { width: 32px; height: 32px; }
.gate h3 { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.gate p { color: var(--muted); font-size: 14px; margin-bottom: 18px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--bottom) + 14px); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .25s;
  background: var(--toast-bg); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 500;
  max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- админка ---------- */
.admin h1 { font-size: 26px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface2); border-radius: 999px; padding: 3px; margin-bottom: 12px; }
.seg button { padding: 8px 4px; border-radius: 999px; color: #8A6A52; font-size: 13px; font-weight: 600; transition: .2s; }
.seg button.on { background: var(--accent); color: #fff; }
.refresh { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.refresh-info { font-size: 12px; color: var(--muted); }
.refresh-info .err { color: var(--danger); margin-top: 2px; }
.notice { background: var(--accent-soft); color: #A85512; border-radius: 12px; padding: 10px 12px; font-size: 13px; font-weight: 500; margin-bottom: 12px; }
.alist { display: grid; gap: 6px; }
.arow { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px 8px 4px; cursor: pointer; transition: opacity .2s, box-shadow .2s; }
.arow.hidden { opacity: .5; }
.arow.dragging { box-shadow: 0 0 0 2px var(--accent), var(--shadow); opacity: .95; }
.grip { color: #B9AA9C; touch-action: none; cursor: grab; padding: 6px 2px; }
.grip svg { fill: currentColor; stroke: none; width: 18px; height: 18px; }
.th { width: 52px; height: 32px; border-radius: 6px; flex: none; overflow: hidden; background: var(--peach); }
.th img { width: 100%; height: 100%; object-fit: cover; }
.arow .t { flex: 1; min-width: 0; font-size: 13.5px; line-height: 1.3; font-weight: 500; }
.arow .t > span:first-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; gap: 4px; margin-top: 3px; }
.pill { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; background: #F2F2F2; color: var(--muted); font-weight: 600; }
.pill.new { background: var(--accent-soft); color: var(--accent); }
.switch { width: 40px; height: 24px; border-radius: 12px; background: #DDD; position: relative; flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(16px); }

.editor h3 { font-size: 20px; font-weight: 800; margin-bottom: 12px; }
.edit-cover { aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: var(--peach); display: grid; place-items: center; color: var(--muted); margin-bottom: 8px; }
.edit-cover img { width: 100%; height: 100%; object-fit: cover; }
.row2 { display: flex; gap: 8px; flex-wrap: wrap; }
.row2 .btn + .btn { margin-top: 0; }
.editor label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 14px; }
.editor input, .editor textarea, .editor select {
  display: block; width: 100%; margin-top: 5px; background: #FFFBF7; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 15px; font-weight: 500; user-select: text;
}
.editor input:focus, .editor textarea:focus, .editor select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor textarea { resize: vertical; }
.linkish { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13px; font-weight: 600; margin: 14px 0 16px; }
.linkish svg { width: 16px; height: 16px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.kpis div { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.kpis b { display: block; font-size: 24px; font-weight: 800; color: var(--accent); }
.kpis span { font-size: 12px; color: var(--muted); font-weight: 500; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin-bottom: 14px; }
.chart-title { font-size: 12px; font-weight: 600; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 90px; margin-top: 10px; }
.bars i { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-width: 2px; }
.chart-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.sec { font-size: 16px; font-weight: 800; margin: 4px 0 8px; }
.top { list-style: none; counter-reset: t; }
.top li { counter-increment: t; display: flex; gap: 10px; justify-content: space-between; font-size: 13.5px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.top li span::before { content: counter(t) ". "; color: var(--muted); }
.top li b { color: var(--accent); }
