/* Спільні стилі міні-апки та адмін-панелі «Свидетель».
   Кольори беруться з теми Telegram (--tg-theme-*), запасні — темна гама. */
:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --text: var(--tg-theme-text-color, #e8e9ec);
  --hint: var(--tg-theme-hint-color, #8b909a);
  --link: var(--tg-theme-link-color, #4aa3ff);
  --btn: var(--tg-theme-button-color, #2f81f7);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --sec: var(--tg-theme-secondary-bg-color, #171a21);
  --hdr: var(--tg-theme-header-bg-color, var(--sec));
  --card: color-mix(in srgb, var(--text) 7%, var(--bg));
  --line: color-mix(in srgb, var(--text) 13%, transparent);
  --del: #e5484d; --edit: #f5a623; --eph: #ff7a1a; --ok: #3fb950;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.38 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---- каркас ---- */
.view { display: none; height: 100dvh; flex-direction: column; }
.view.active { display: flex; }
.top { display: flex; align-items: center; gap: 10px; padding: 11px 14px; background: var(--hdr); border-bottom: 1px solid var(--line); flex: none; }
.top .logo { font-size: 22px; }
.top b { font-size: 17px; letter-spacing: .2px; }
.top .ttl { flex: 1; min-width: 0; }
.top .ttl div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--hint); }
.ibtn { background: none; border: 0; color: var(--link); font-size: 20px; line-height: 1; padding: 6px 8px; border-radius: 8px; text-decoration: none; }
.ibtn:active { background: var(--line); }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.pane.active { display: flex; }
.tabs { display: flex; flex: none; background: var(--hdr); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; background: none; border: 0; padding: 10px 0 9px; color: var(--hint); font-size: 12px; display: grid; gap: 1px; justify-items: center; }
.tabs button span { font-size: 20px; }
.tabs button.active { color: var(--link); font-weight: 600; }
.chips { display: flex; gap: 8px; padding: 9px 12px; overflow-x: auto; flex: none; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: none; font-size: 13px; }
.chip.active { background: var(--btn); color: var(--btn-text); border-color: transparent; }
.search { padding: 8px 12px; flex: none; }
.search input { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; outline: none; }
.empty { padding: 48px 24px; text-align: center; color: var(--hint); }
.empty big { display: block; font-size: 38px; margin-bottom: 8px; }
.loader { text-align: center; padding: 14px; color: var(--hint); font-size: 13px; }
.ava { width: 48px; height: 48px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 19px; flex: none; }
.badges { display: flex; gap: 6px; margin-top: 3px; flex-wrap: wrap; }
.badge { font-size: 11.5px; padding: 1px 7px; border-radius: 999px; font-weight: 600; }
.badge.b-del { background: color-mix(in srgb, var(--del) 18%, transparent); color: var(--del); }
.badge.b-edit { background: color-mix(in srgb, var(--edit) 20%, transparent); color: var(--edit); }
.badge.b-eph { background: color-mix(in srgb, var(--eph) 20%, transparent); color: var(--eph); }
.badge.b-ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.b-mute { background: var(--line); color: var(--hint); }

/* ---- повідомлення ---- */
.msgs { padding: 8px 10px 14px; background: var(--sec); }
.day { align-self: center; text-align: center; margin: 12px auto 6px; font-size: 12px; color: var(--hint); background: var(--card); padding: 3px 10px; border-radius: 999px; width: fit-content; }
.line { display: flex; margin-top: 8px; } .line.same { margin-top: 2px; } .line.out { justify-content: flex-end; }
.bubble { max-width: 82%; padding: 7px 11px 6px; border-radius: 15px; background: var(--bg); word-wrap: break-word; white-space: pre-wrap; position: relative; --vp-fg: var(--btn); --vp-ic: var(--btn-text); }
.line.out .bubble { background: var(--btn); color: var(--btn-text); --vp-fg: var(--btn-text); --vp-ic: var(--btn); }
.bubble.deleted { outline: 2px dashed var(--del); outline-offset: -1px; }
.bubble.ephemeral { box-shadow: 0 0 0 2px var(--eph) inset; }
.meta2 { font-size: 11.5px; opacity: .75; margin-top: 3px; text-align: right; white-space: normal; }
.meta2 .t-del { color: var(--del); font-weight: 700; opacity: 1; }
.line.out .meta2 .t-del { color: #ffd2d4; }
.edit { font-size: 13px; margin-top: 6px; padding: 6px 8px; border-radius: 8px; background: rgba(127,127,127,.18); }
.edit s { opacity: .7; }
.eph-tag { display: inline-block; font-size: 12px; font-weight: 700; color: var(--eph); margin-bottom: 4px; }
.line.out .eph-tag { color: #ffe1c4; }

/* ---- медіа ---- */
.media { min-width: 120px; min-height: 80px; border-radius: 10px; overflow: hidden; display: block; margin-bottom: 4px; position: relative; background: rgba(127,127,127,.15); }
.media.voice { min-width: 0; min-height: 0; background: none; overflow: visible; border-radius: 0; margin-bottom: 2px; }
.media img, .media video { display: block; max-width: 100%; max-height: 360px; width: 100%; object-fit: cover; cursor: zoom-in; }
.media video.note { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; cursor: default; }
.media .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--hint); font-size: 22px; text-align: center; }
.ephbadge { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #ffb27a; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; z-index: 2; pointer-events: none; }
.file { color: var(--link); display: inline-flex; gap: 6px; align-items: center; padding: 4px 0; }
.line.out .file { color: var(--btn-text); }

/* ---- відеокружечок ---- */
.notebox { margin-bottom: 2px; }
.note-circle { width: 220px; height: 220px; max-width: 100%; aspect-ratio: 1; border-radius: 50%; overflow: hidden; position: relative; background: #000; cursor: pointer; margin: 2px auto; }
.note-circle video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.note-circle .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.note-circle .prg { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: butt; opacity: .9; }
.note-circle .nplay { position: absolute; inset: 0; display: grid; place-items: center; transition: opacity .15s; }
.note-circle .nplay svg { width: 56px; height: 56px; padding: 14px 12px 14px 16px; border-radius: 50%; background: rgba(0,0,0,.45); fill: #fff; }
.note-circle.playing .nplay { opacity: 0; }
.note-circle .ntime { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; background: rgba(0,0,0,.5); color: #fff; padding: 1px 8px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.note-circle .ntime:empty { display: none; }
.bubble:has(.note-circle) { background: transparent; padding: 0 0 2px; }
.line.out .bubble:has(.note-circle) { background: transparent; color: var(--text); }
.bubble:has(.note-circle) .eph-tag { padding-left: 4px; }
.bubble:has(.note-circle) .meta2 { text-align: center; }
.ev .notebox { display: flex; flex-direction: column; align-items: center; }

/* ---- голосове повідомлення ---- */
.vp { display: flex; align-items: center; gap: 10px; width: 250px; max-width: 100%; padding: 2px 0; white-space: normal; }
.vp-btn { flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--vp-fg); color: var(--vp-ic); display: grid; place-items: center; padding: 0; }
.vp-btn svg { width: 18px; height: 18px; fill: currentColor; }
.vp-btn:active { transform: scale(.94); }
.vp-main { flex: 1; min-width: 0; }
.vp-wave { display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer; touch-action: none; }
.vp-wave i { flex: 1; min-width: 2px; border-radius: 2px; background: var(--vp-fg); opacity: .3; transition: opacity .12s; }
.vp-wave i.on { opacity: 1; }
.vp-info { display: flex; justify-content: space-between; align-items: center; font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; opacity: .85; }
.vp-speed { border: 1px solid currentColor; background: none; border-radius: 999px; padding: 0 7px; font-size: 11px; line-height: 17px; opacity: .8; }
.vp.err .vp-info { color: var(--del); }

/* ---- сітка медіа ---- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; background: var(--sec); }
.cell { aspect-ratio: 1; position: relative; background: var(--card); overflow: hidden; cursor: pointer; display: grid; place-items: center; font-size: 26px; }
.cell img, .cell video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cell .ephbadge { font-size: 11px; padding: 1px 6px; }
.cell .tint { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(135deg, color-mix(in srgb, var(--btn) 35%, var(--card)), var(--card)); }

/* ---- повноекранний перегляд ---- */
#viewer { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 50; display: flex; flex-direction: column; touch-action: none; }
#viewer .vtop { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: #fff; }
#viewer .vtop button { background: rgba(255,255,255,.14); border: 0; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; }
#viewer .vtop div { display: flex; gap: 8px; }
#vstage { flex: 1; display: grid; place-items: center; overflow: hidden; min-height: 0; }
#vstage img, #vstage video { max-width: 100%; max-height: 100%; user-select: none; -webkit-user-drag: none; transform-origin: center; }
#vtoast { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.16); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; max-width: 90%; text-align: center; }

/* ---- екран «потрібна підписка» ---- */
.gate { position: fixed; inset: 0; z-index: 1000; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.gate-box { max-width: 340px; width: 100%; text-align: center; display: grid; gap: 12px; }
.gate-box b { font-size: 19px; }
.gate-box p { margin: 0; color: var(--hint); }
.gate-ico { font-size: 44px; }
.gate-btn { border: 0; border-radius: 12px; padding: 13px; font-weight: 600; background: var(--card); color: var(--text); }
.gate-btn.primary { background: var(--btn); color: var(--btn-text); }
.gate-btn.ok { background: var(--ok); color: #fff; }
.gate-btn:disabled { opacity: .6; }
