:root {
  --bg: #f6f6f9;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e3e3ea;
  --text: #1c1c24;
  --muted: #6b6b7b;
  --accent: #d6336c;
  --accent-hover: #c2255c;
  --accent-soft: #fde8ef;
  --danger: #d6455b;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --ok: #2f9e6b;
  --ok-soft: #e3f5ec;
  --info-soft: #ececfd;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 4px 16px rgba(20, 20, 40, .05);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111116;
    --surface: #1a1a21;
    --surface-2: #23232c;
    --border: #2e2e39;
    --text: #ececf1;
    --muted: #9a9aab;
    --accent: #f0609a;
    --accent-hover: #f57aab;
    --accent-soft: #3a1f2b;
    --danger: #f06a7e;
    --warn: #e0a940;
    --warn-soft: #33281a;
    --ok: #4cc28d;
    --ok-soft: #1a3328;
    --info-soft: #26264a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h3 { font-size: 15px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; line-height: 1.45; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 550; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; cursor: default; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.small { padding: 5px 10px; font-size: 13.5px; border-radius: 8px; }
.btn.big { padding: 12px 18px; font-size: 16px; width: 100%; white-space: normal; text-align: center; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.insta { background: linear-gradient(90deg, #f58529, #dd2a7b 45%, #8134af); border: 0; color: #fff; }
.btn.insta:hover { filter: brightness(1.05); }

input:not([type=checkbox]):not([type=radio]), textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field > span:first-child { font-weight: 550; font-size: 13.5px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; cursor: pointer; font-size: 14px; }
.check input { margin-top: 3px; accent-color: var(--accent); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 44px; height: 26px; border-radius: 13px;
  background: var(--border); position: relative; cursor: pointer; transition: background .15s; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(18px); }
.switch:focus-visible { outline: 3px solid var(--accent-soft); }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-top: 10px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 550; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.notice { background: var(--warn-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 440px; min-width: 0; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-title { font-size: 22px; line-height: 1.3; }
.login .hint { color: var(--muted); margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack .field { margin-top: 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.tabs2 { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.tabs2 button { border: 0; background: none; padding: 7px 6px; border-radius: 8px; font-weight: 600; font-size: 14px;
  color: var(--muted); cursor: pointer; }
.tabs2 button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.steps { margin: 0; padding-left: 18px; color: var(--muted); }
.steps li + li { margin-top: 2px; }
#sid-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.approve-icon { align-self: center; color: var(--accent); }
#approve-msg { margin: 0; font-size: 14.5px; }
#approve-msg.wait { color: var(--warn); }
#code-msg { margin: 0; font-size: 14px; }
#code-msg.bad { color: var(--danger); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.brand .sub { font-size: 13px; }
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 8v16M8 16h16' stroke='white' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E") center/100% no-repeat;
}

/* ---------- шапка ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.account { display: flex; align-items: center; gap: 8px; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.chip {
  display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 10px 4px 4px;
  border: 1px solid var(--border); border-radius: 20px; font-weight: 550; font-size: 14px; max-width: 220px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; }
.menu-body { position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; padding: 6px; z-index: 10; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }

.banners { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.banner { margin-top: 14px; padding: 10px 14px; border-radius: 10px; font-size: 14px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.banner.ok { background: var(--ok-soft); }
.banner.info { background: var(--info-soft); }
.banner.warn { background: var(--warn-soft); }
.banner.bad { background: var(--accent-soft); }

.tabs { display: flex; gap: 4px; max-width: 1200px; margin: 16px auto 0; padding: 0 24px; }
.tab {
  border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted);
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.count { font-weight: 500; color: var(--muted); font-size: 13px; }
main { max-width: 1200px; margin: 0 auto; padding: 16px 24px 48px; }
.empty { color: var(--muted); text-align: center; padding: 48px 0; margin: 0; }

/* ---------- посты ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.post {
  display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.post:hover { transform: translateY(-2px); border-color: var(--accent); }
.post:focus-visible { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 4 / 5; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.badge {
  position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px; backdrop-filter: blur(4px);
}
.on {
  position: absolute; top: 8px; right: 8px; background: var(--ok); color: #fff; font-size: 11.5px; font-weight: 650;
  padding: 2px 8px; border-radius: 10px;
}
.post-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.post-caption { font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.9em; }
.post-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.post-meta b { color: var(--ok); font-weight: 650; }

/* ---------- журнал ---------- */
.log { display: flex; flex-direction: column; gap: 8px; }
.ev { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: start; padding: 12px; }
.ev img, .ev .ph { width: 44px; height: 55px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.ev-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.ev-head b { font-weight: 650; }
.ev-comment { font-size: 14px; word-break: break-word; }
.ev details { margin-top: 4px; font-size: 13.5px; }
.ev summary { cursor: pointer; color: var(--muted); }
.ev .dm { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin-top: 6px; }
.ev .reason { color: var(--warn); font-size: 13px; margin-top: 4px; }
.pill { font-size: 12px; font-weight: 650; padding: 2px 9px; border-radius: 10px; white-space: nowrap; }
.pill.sent { background: var(--ok-soft); color: var(--ok); }
.pill.pending { background: var(--info-soft); }
.pill.skipped { background: var(--surface-2); color: var(--muted); }
.pill.failed { background: var(--accent-soft); color: var(--danger); }

/* ---------- редактор ---------- */
.drawer-bg { position: fixed; inset: 0; background: rgba(10, 10, 20, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 21;
  background: var(--bg); border-left: 1px solid var(--border); display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
}
.drawer-head { display: flex; gap: 12px; padding: 14px 16px; background: var(--surface); border-bottom: 1px solid var(--border); align-items: flex-start; }
.drawer-head img { width: 56px; height: 70px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex: none; }
.ed-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ed-caption { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.close { font-size: 16px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.block h3 { margin-bottom: 2px; }
.block .row { margin-top: 12px; }
.drawer-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.kw { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); border-radius: 14px; padding: 3px 4px 3px 11px; font-weight: 600; }
.kw button { border: 0; background: none; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; color: var(--muted); }
.kw button:hover { background: rgba(0,0,0,.08); color: var(--text); }
.preview { margin-top: 12px; }
.preview .row { margin-top: 0; flex-wrap: nowrap; }
.preview input { flex: 1; min-width: 0; }
.bubble {
  margin-top: 10px; white-space: pre-wrap; background: linear-gradient(135deg, #8134af, #dd2a7b); color: #fff;
  padding: 10px 14px; border-radius: 18px 18px 4px 18px; max-width: 92%; margin-left: auto; font-size: 14.5px;
}
.bubble.note { background: var(--surface-2); color: var(--text); border-radius: 12px; margin-left: 0; }
#ed-dm-bytes.over { color: var(--danger); font-weight: 700; }
#ed-status.bad { color: var(--danger); }
#ed-status.ok { color: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- статичные страницы ---------- */
.page-static { max-width: 720px; margin: 0 auto; padding: 32px 16px 64px; }
.page-static h1 { font-size: 24px; margin-bottom: 12px; }
.page-static h2 { font-size: 17px; margin: 22px 0 6px; }
main.page { max-width: 560px; margin: 64px auto; padding: 0 16px; }

@media (max-width: 640px) {
  .top { padding: 10px 16px; }
  .brand .sub, #sync { display: none; }
  .banners, .tabs { padding: 0 16px; }
  main { padding: 12px 16px 40px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .post-caption { font-size: 13px; }
  .ev { grid-template-columns: 40px 1fr; }
  .ev .pill { grid-column: 2; justify-self: start; }
  .drawer { width: 100vw; border-left: 0; }
  .login-card { padding: 22px; }
}
