:root{
  --bg:#EEF1F6; --bg2:#E3E8F0; --glass:rgba(255,255,255,.72); --glass-strong:rgba(255,255,255,.9);
  --line:rgba(26,34,48,.09); --ink:#18202D; --muted:#6A7383; --faint:#9AA2B0;
  --accent:#2F6BFF; --accent-ink:#fff; --accent-soft:rgba(47,107,255,.12);
  --ok:#14945A; --ok-soft:rgba(20,148,90,.12); --warn:#B97A06; --warn-soft:rgba(185,122,6,.13);
  --bad:#D23F3F; --bad-soft:rgba(210,63,63,.11);
  --bubble:#fff; --bubble-ink:#18202D; --chat:#C9D6E6;
  --r-lg:22px; --r-md:14px; --r-sm:10px;
  --shadow:0 1px 0 rgba(255,255,255,.7) inset, 0 8px 24px rgba(28,40,64,.08);
  --tab-h:64px; --sat:env(safe-area-inset-top,0px); --sab:env(safe-area-inset-bottom,0px);
  color-scheme:light;
}
@media (prefers-color-scheme:dark){:root{
  --bg:#0E1320; --bg2:#151B2B; --glass:rgba(28,35,52,.72); --glass-strong:rgba(32,40,58,.94);
  --line:rgba(255,255,255,.08); --ink:#E9EDF5; --muted:#98A1B3; --faint:#6B7488;
  --accent:#5B8CFF; --accent-soft:rgba(91,140,255,.16);
  --ok:#34C27E; --ok-soft:rgba(52,194,126,.14); --warn:#E2A52B; --warn-soft:rgba(226,165,43,.15);
  --bad:#FF6464; --bad-soft:rgba(255,100,100,.13);
  --bubble:#1D2638; --bubble-ink:#E9EDF5; --chat:#0B1019;
  --shadow:0 1px 0 rgba(255,255,255,.05) inset, 0 8px 24px rgba(0,0,0,.35);
  color-scheme:dark;
}}
*{box-sizing:border-box;margin:0}
html,body{height:100%}
body{font:15px/1.45 -apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,system-ui,sans-serif;color:var(--ink);
  background:radial-gradient(1200px 600px at 100% -10%,var(--bg2),transparent 60%),var(--bg);background-attachment:fixed;
  -webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent}
[hidden]{display:none!important}
svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer;border:0;background:none}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
a{color:var(--accent)}
.muted{color:var(--muted)} .small{font-size:13px} .num{font-variant-numeric:tabular-nums}
.glass{background:var(--glass);-webkit-backdrop-filter:blur(22px) saturate(1.6);backdrop-filter:blur(22px) saturate(1.6);
  border:1px solid var(--line);box-shadow:var(--shadow)}

/* вход */
.login{min-height:100%;display:grid;place-items:center;padding:24px}
.login-card{width:100%;max-width:360px;border-radius:var(--r-lg);padding:32px 24px;display:flex;flex-direction:column;align-items:center;gap:12px;text-align:center}
.login-card h1{font-size:24px;letter-spacing:-.02em}
.login-card input{width:100%}
.brand-mark{width:56px;height:56px;border-radius:18px;background:var(--accent);color:#fff;display:grid;place-items:center}
.brand-mark svg{width:30px;height:30px;fill:#fff;stroke:none}
.err{color:var(--bad);min-height:1.4em;font-size:14px}

/* шапка */
.top{position:sticky;top:0;z-index:20;padding:calc(var(--sat) + 10px) 16px 10px;border-width:0 0 1px;border-radius:0}
.top-row{display:flex;align-items:center;gap:12px;max-width:760px;margin:0 auto}
.chan-switch{display:flex;align-items:center;gap:8px;min-width:0;height:40px;padding:0 12px 0 10px;border-radius:20px;background:var(--glass-strong);border:1px solid var(--line)}
.chan-name{font-weight:650;font-size:16px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:46vw}
.chev{width:18px;height:18px;color:var(--muted)}
.dot{width:9px;height:9px;border-radius:50%;background:var(--faint);flex:none}
.dot.ok{background:var(--ok);box-shadow:0 0 0 3px var(--ok-soft)} .dot.bad{background:var(--bad);box-shadow:0 0 0 3px var(--bad-soft)}
.top-stats{margin-left:auto;display:flex;gap:14px;align-items:center}
.stat{display:flex;flex-direction:column;align-items:center;line-height:1.1}
.stat b{font-size:16px;font-variant-numeric:tabular-nums}
.stat span{font-size:11px;color:var(--muted);white-space:nowrap}
.chan-menu{position:absolute;left:16px;top:calc(100% + 6px);width:min(320px,calc(100vw - 32px));border-radius:var(--r-md);padding:6px;z-index:30}
.chan-menu button{display:flex;align-items:center;justify-content:space-between;gap:10px;width:100%;min-height:44px;padding:0 12px;border-radius:var(--r-sm);text-align:left}
.chan-menu button:hover,.chan-menu button.on{background:var(--accent-soft)}
.chan-menu .add{color:var(--accent);font-weight:600;justify-content:flex-start}
.chan-menu .add svg{width:18px;height:18px}

main{max-width:760px;margin:0 auto;padding:14px 16px calc(var(--tab-h) + var(--sab) + 32px)}

/* таббар-капсула */
.tabbar{position:fixed;left:50%;transform:translateX(-50%);bottom:calc(var(--sab) + 12px);z-index:20;display:flex;gap:2px;
  padding:5px;border-radius:32px;width:min(460px,calc(100vw - 20px))}
.tabbar button{flex:1;min-width:0;height:54px;border-radius:27px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:var(--muted);font-size:10.5px;font-weight:550;letter-spacing:-.01em}
.tabbar button svg{width:22px;height:22px}
.tabbar button.on{color:var(--accent);background:var(--accent-soft)}

/* общие блоки */
h2{font-size:22px;letter-spacing:-.02em;margin:6px 2px 12px}
.section{margin-bottom:22px}
.section-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 4px 8px}
.section-head h3{font-size:13px;font-weight:600;color:var(--muted)}
.card{border-radius:var(--r-lg);padding:16px}
.group{border-radius:var(--r-lg);overflow:hidden}
.row{display:flex;align-items:center;gap:12px;min-height:52px;padding:10px 16px;border-top:1px solid var(--line)}
.row:first-child{border-top:0}
.row .grow{flex:1;min-width:0}
.row .label{font-weight:550}
.row .hint{font-size:13px;color:var(--muted);margin-top:1px}
.row.col{flex-direction:column;align-items:stretch;gap:8px}
input[type=text],input[type=password],input[type=number],input[type=url],select,textarea{width:100%;min-height:44px;padding:10px 12px;border-radius:var(--r-sm);
  border:1px solid var(--line);background:var(--glass-strong);outline:none;-webkit-appearance:none;appearance:none}
input:focus,select:focus,textarea:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
textarea{resize:vertical;min-height:88px;line-height:1.45}
input.short{width:84px;text-align:center;flex:none}
select{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236A7383' stroke-width='2'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");background-repeat:no-repeat;background-position:right 10px center;background-size:18px;padding-right:34px}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;min-height:44px;padding:0 18px;border-radius:22px;font-weight:600;background:var(--glass-strong);border:1px solid var(--line);white-space:nowrap}
.btn svg{width:18px;height:18px}
.btn.primary{background:var(--accent);color:var(--accent-ink);border-color:transparent}
.btn.danger{color:var(--bad)}
.btn.ghost{background:transparent;border-color:transparent;color:var(--accent);padding:0 10px}
.btn.wrap{white-space:normal;text-align:left;align-self:flex-start;min-height:36px;padding:0 4px}
.btn.wide{width:100%}
.btn.sm{min-height:36px;padding:0 14px;font-size:14px;border-radius:18px}
.btn:disabled{opacity:.5;cursor:default}
.btns{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
.switch{position:relative;width:51px;height:31px;flex:none}
.switch input{position:absolute;inset:0;opacity:0;margin:0;cursor:pointer}
.switch span{position:absolute;inset:0;border-radius:16px;background:var(--line);transition:background .2s}
.switch span::after{content:"";position:absolute;top:2px;left:2px;width:27px;height:27px;border-radius:50%;background:#fff;box-shadow:0 2px 6px rgba(0,0,0,.2);transition:transform .2s}
.switch input:checked+span{background:var(--ok)}
.switch input:checked+span::after{transform:translateX(20px)}
.seg{display:flex;padding:3px;border-radius:12px;background:var(--line);gap:2px}
.seg button{flex:1;min-height:34px;border-radius:9px;font-size:14px;font-weight:550;color:var(--muted);padding:0 10px;white-space:nowrap}
.seg button.on{background:var(--glass-strong);color:var(--ink);box-shadow:0 1px 4px rgba(0,0,0,.08)}
.chips{display:flex;gap:8px;overflow-x:auto;padding:2px 2px 10px;margin:0 -2px;scrollbar-width:none}
.chips::-webkit-scrollbar{display:none}
.chip{flex:none;display:inline-flex;align-items:center;gap:6px;height:36px;padding:0 14px;border-radius:18px;background:var(--glass);border:1px solid var(--line);font-size:14px;font-weight:550;color:var(--muted)}
.chip b{font-weight:650;color:var(--ink);font-variant-numeric:tabular-nums}
.chip.on{background:var(--ink);color:var(--bg);border-color:transparent}
.chip.on b{color:var(--bg)}
.range{display:flex;align-items:center;gap:12px}
.range input{flex:1;accent-color:var(--accent)}
.range output{min-width:44px;text-align:right;font-variant-numeric:tabular-nums;font-weight:600}
.badge{display:inline-flex;align-items:center;height:22px;padding:0 8px;border-radius:11px;font-size:12px;font-weight:600;white-space:nowrap}
.badge.ok{background:var(--ok-soft);color:var(--ok)} .badge.warn{background:var(--warn-soft);color:var(--warn)}
.badge.bad{background:var(--bad-soft);color:var(--bad)} .badge.n{background:var(--line);color:var(--muted)}
.empty{text-align:center;padding:40px 20px;color:var(--muted)}
.empty b{display:block;color:var(--ink);font-size:17px;margin-bottom:4px}

/* шаги запуска */
.steps{counter-reset:s}
.step{display:flex;gap:14px;align-items:flex-start;padding:14px 16px;border-top:1px solid var(--line)}
.step:first-child{border-top:0}
.step-n{width:28px;height:28px;border-radius:50%;display:grid;place-items:center;font-size:14px;font-weight:700;background:var(--line);color:var(--muted);flex:none}
.step.done .step-n{background:var(--ok);color:#fff}
.step.done .step-n svg{width:16px;height:16px;stroke-width:2.6}
.step .grow{flex:1;min-width:0;padding-top:3px}
.step .label{font-weight:600}

/* карточка поста — превью как в Telegram */
.post{border-radius:var(--r-lg);margin-bottom:14px;overflow:hidden}
.post-head{display:flex;align-items:center;gap:10px;padding:12px 14px 0}
.post-src{font-weight:600;font-size:14px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.post-head .when{margin-left:auto;font-size:13px;color:var(--muted);white-space:nowrap}
.chat{margin:10px 10px 0;padding:12px;border-radius:16px;background:var(--chat)}
.bubble{max-width:100%;background:var(--bubble);color:var(--bubble-ink);border-radius:14px 14px 14px 4px;overflow:hidden;box-shadow:0 1px 1px rgba(0,0,0,.08)}
.bubble .media{display:grid;gap:2px;grid-template-columns:repeat(2,1fr);position:relative}
.bubble .media.n1{grid-template-columns:1fr}
.bubble .media.n3 .thumb:first-child{grid-column:1/-1}
.thumb{position:relative;aspect-ratio:4/3;background:var(--line);overflow:hidden}
.media.n1 .thumb{aspect-ratio:auto;max-height:420px}
.thumb img{width:100%;height:100%;object-fit:cover;display:block}
.thumb.nothumb img{display:none}
.thumb .play{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:44px;height:44px;border-radius:50%;background:rgba(0,0,0,.45);display:grid;place-items:center;color:#fff;z-index:1}
.thumb .play svg{width:20px;height:20px;fill:#fff;stroke:none;margin-left:3px}
.media .more{position:absolute;right:8px;bottom:8px;background:rgba(0,0,0,.55);color:#fff;font-size:13px;font-weight:600;padding:2px 8px;border-radius:10px}
.small-spin{width:13px;height:13px;border-width:2px;vertical-align:-2px;margin-right:4px}
.bubble .media .ph{aspect-ratio:4/3;display:flex;flex-direction:column;align-items:center;justify-content:center;background:var(--line);color:var(--muted);font-size:13px;gap:4px}
.bubble .text{padding:9px 12px 10px;white-space:pre-wrap;word-wrap:break-word;font-size:15px;line-height:1.42}
.bubble .text blockquote{border-left:3px solid var(--accent);padding-left:9px;margin:4px 0;white-space:pre-wrap}
.bubble .text code{font-family:ui-monospace,Menlo,monospace;font-size:13px}
.bubble .tg-spoiler{background:var(--line);border-radius:4px}
.bubble-btns{display:grid;gap:4px;margin-top:4px}
.bubble-btns div{display:grid;grid-auto-flow:column;grid-auto-columns:1fr;gap:4px}
.bubble-btns span{display:flex;align-items:center;justify-content:center;min-height:36px;border-radius:10px;background:rgba(255,255,255,.35);color:var(--bubble-ink);font-size:14px;font-weight:550;backdrop-filter:blur(6px)}
@media (prefers-color-scheme:dark){.bubble-btns span{background:rgba(255,255,255,.1)}}
.orig{margin:10px 14px 0;font-size:13px;color:var(--muted)}
.orig summary{cursor:pointer;color:var(--accent);font-weight:550;list-style:none}
.orig summary::-webkit-details-marker{display:none}
.orig p{margin-top:6px;white-space:pre-wrap}
.post-meta{display:flex;flex-wrap:wrap;gap:6px;align-items:center;padding:10px 14px 0}
.score{display:inline-flex;align-items:center;gap:6px;font-weight:650;font-variant-numeric:tabular-nums}
.meter{width:56px;height:6px;border-radius:3px;background:var(--line);overflow:hidden}
.meter i{display:block;height:100%;border-radius:3px;background:var(--accent)}
.post-reason{padding:6px 14px 0;font-size:13px;color:var(--muted)}
.post-actions{display:flex;flex-direction:column;gap:8px;padding:12px 14px 14px}
.act-main,.act-sub{display:flex;gap:8px}
.act-main .btn,.act-sub .btn{flex:1 1 0;min-width:0;padding:0 10px}
.edit-area{padding:10px 14px 0}

/* источники */
.src-title{font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.src-stats{font-size:13px;color:var(--muted);margin-top:2px}
.src-stats b{color:var(--ink);font-weight:600;font-variant-numeric:tabular-nums}
.icon-btn{width:40px;height:40px;border-radius:20px;display:grid;place-items:center;color:var(--muted);flex:none}
.icon-btn:hover{background:var(--line)}
.icon-btn svg{width:20px;height:20px}

/* редактор кнопок */
.btn-row{display:flex;gap:8px;align-items:center}
.btn-row input{flex:1;min-width:0}

/* водяной знак */
.wm-preview{display:flex;align-items:center;gap:14px}
.wm-box{width:72px;height:72px;border-radius:var(--r-md);display:grid;place-items:center;background:repeating-conic-gradient(var(--line) 0 25%,transparent 0 50%) 0 0/14px 14px;border:1px solid var(--line);overflow:hidden;flex:none}
.wm-box img{max-width:86%;max-height:86%}
.pos-grid{display:grid;grid-template-columns:repeat(3,36px);grid-template-rows:repeat(3,28px);gap:4px}
.pos-grid button{border-radius:7px;background:var(--line)}
.pos-grid button.on{background:var(--accent)}
.pos-grid button:disabled{visibility:hidden}

/* лог */
.log{font:12px/1.5 ui-monospace,Menlo,monospace;max-height:360px;overflow:auto;padding:12px 14px;white-space:pre-wrap;word-break:break-word}
.log .error{color:var(--bad)} .log .warn{color:var(--warn)}

/* шторка */
.sheet-back{position:fixed;inset:0;background:rgba(10,14,22,.35);z-index:40}
.sheet{position:fixed;left:50%;transform:translateX(-50%);bottom:0;width:min(560px,100%);max-height:88vh;overflow:auto;z-index:41;
  border-radius:24px 24px 0 0;padding:10px 18px calc(var(--sab) + 20px);background:var(--glass-strong)}
.sheet::before{content:"";display:block;width:38px;height:5px;border-radius:3px;background:var(--line);margin:0 auto 14px}
.sheet h3{font-size:18px;margin-bottom:8px}
.sheet p{margin-bottom:10px}
.sheet ol{padding-left:20px;margin-bottom:12px}
.sheet li{margin-bottom:6px}

.toast{position:fixed;left:50%;bottom:calc(var(--tab-h) + var(--sab) + 28px);transform:translate(-50%,20px);opacity:0;pointer-events:none;
  background:var(--ink);color:var(--bg);padding:10px 16px;border-radius:20px;font-size:14px;font-weight:550;z-index:60;transition:.25s;max-width:calc(100vw - 32px);text-align:center}
.toast.show{opacity:1;transform:translate(-50%,0)}
.toast.bad{background:var(--bad);color:#fff}
.spin{width:18px;height:18px;border-radius:50%;border:2px solid currentColor;border-right-color:transparent;animation:sp .7s linear infinite;display:inline-block}
@keyframes sp{to{transform:rotate(360deg)}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
@media (min-width:700px){main{padding-top:20px}}

.hours{display:flex;align-items:center;gap:6px;flex:none}
.hours select{width:92px;text-align:center}
.hours select[data-k=weekly_day]{width:76px}

.kpis{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:14px}
.kpi{border-radius:var(--r-md);padding:14px;display:flex;flex-direction:column;gap:2px}
.kpi b{font-size:24px;font-variant-numeric:tabular-nums;letter-spacing:-.02em}
.kpi span{font-size:13px;color:var(--muted)}
.funnel{justify-content:space-between;text-align:center}
.funnel div{display:flex;flex-direction:column;align-items:center;flex:1}
.funnel b{font-size:17px;font-variant-numeric:tabular-nums}
.funnel span{font-size:12px;color:var(--muted)}
.hours-chart{display:flex;align-items:flex-end;gap:4px;height:120px}
.hc{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;height:100%;gap:4px}
.hc i{display:block;width:100%;border-radius:4px 4px 0 0;background:var(--accent)}
.hc span{font-size:10px;color:var(--muted);font-variant-numeric:tabular-nums}
.post-meta .badge+.badge{margin-left:0}
a.btn{text-decoration:none;color:inherit}
.hc i.empty-bar{height:3px;background:var(--line)}
.hours-chart{gap:2px}
.ai-limits{padding:10px 12px;border-radius:var(--r-sm);background:var(--line);display:flex;flex-direction:column;gap:3px;align-items:flex-start}
.cover-box{width:96px;height:72px;background:var(--line)}
.cover-box img{max-width:100%;max-height:100%;width:100%;height:100%;object-fit:cover}
.cover-prev{width:100%;aspect-ratio:16/9;border-radius:var(--r-sm);object-fit:cover;background:var(--line);display:block}
#dgMode button{font-size:13px;padding:0 6px}

.sig-prev{padding:12px 14px;border-radius:var(--r-sm);background:var(--accent-soft);line-height:1.45;word-break:break-word}
.sig-prev a{color:var(--accent)}
.checks{display:flex;flex-direction:column;gap:6px;margin-top:2px}
.chk{font-size:14px;line-height:1.35}
.chk.ok{color:var(--ok)}
.chk.bad{color:var(--bad)}
