:root {
  --bg: #f4f3f0;
  --card: #ffffff;
  --text: #161616;
  --muted: #7a766f;
  --line: #e6e3dd;
  --chip: #efede8;
  --accent: #161616;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #a86400;
  --bad: #c2352b;
  --info: #2d5bd7;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10;
    --card: #1a1a1c;
    --text: #f2f1ee;
    --muted: #9a968e;
    --line: #2b2b2e;
    --chip: #26262a;
    --accent: #f2f1ee;
    --accent-text: #111111;
    --ok: #4cc17f;
    --warn: #e0a040;
    --bad: #ff6b5e;
    --info: #7ea2ff;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); white-space: pre-line; }
a { color: var(--info); }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; opacity: .45; }

.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 600;
}
.primary.big { width: 100%; padding: 15px; font-size: 17px; border-radius: 14px; }
.ghost { color: var(--muted); padding: 10px 12px; }
.danger { color: var(--bad); padding: 10px 12px; }

textarea, input[type="password"], input[type="text"], input[type="datetime-local"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-size: 16px; /* не даёт iOS увеличивать страницу */
  outline: none;
}
textarea { resize: vertical; min-height: 48px; }
textarea:focus, input:focus { border-color: var(--muted); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 340px; display: grid; gap: 14px; text-align: center; }
.login-box h1 { margin: 0 0 8px; font-size: 24px; }
.logo {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 18px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 30px; font-weight: 700;
}

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0 auto; max-width: 560px; font-size: 26px; letter-spacing: -.02em; }
main { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px); }
.tab { display: grid; gap: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 180px;
  display: grid; justify-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 4px 0;
}
.tabbar .ico { font-size: 20px; line-height: 1; }
.tabbar button[aria-current="page"] { color: var(--text); font-weight: 600; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--line);
}
.card h2 { margin: 0 0 6px; font-size: 18px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 500; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
#schedule-at { margin-top: 12px; }
.card .check:first-child { margin-top: 0; }
#threads-box { margin-top: 10px; }

/* ---------- файлы ---------- */
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.media-grid:not(:empty) { margin-bottom: 10px; }
.tile { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--chip); }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .num, .tile .badge, .tile .tile-note {
  position: absolute; font-size: 11px; font-weight: 600;
  background: rgba(0,0,0,.55); color: #fff; border-radius: 6px; padding: 2px 6px;
}
.tile .num { top: 6px; left: 6px; }
.tile .badge { bottom: 6px; left: 6px; }
.tile .tile-note { bottom: 6px; right: 6px; }
.tile .remove {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; font-size: 18px; line-height: 28px; padding: 0;
}
.tile-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: rgba(0,0,0,.45); color: #fff; font-size: 13px; font-weight: 600; padding: 6px;
}
.tile-overlay.error { background: rgba(160,30,20,.75); font-size: 11px; font-weight: 500; }
.tile .move {
  position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); color: #fff; border-radius: 6px; font-size: 13px; padding: 4px 10px;
}

.add-media {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 18px; border: 1.5px dashed var(--line); border-radius: 12px;
  color: var(--muted); cursor: pointer; font-weight: 500;
}
.add-media .plus { font-size: 22px; line-height: 1; }

/* ---------- цели ---------- */
.target-group + .target-group { margin-top: 14px; }
.target-group-name { font-weight: 600; margin-bottom: 8px; font-size: 15px; }
.target-group-name .muted { font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 16px; border-radius: 999px; background: var(--chip);
  border: 1px solid transparent; font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.counters { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.counter.over { color: var(--bad); font-weight: 600; }
.counter.warn { color: var(--warn); }

.hints { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.hints li { font-size: 14px; color: var(--warn); padding-left: 18px; position: relative; }
.hints li::before { content: "•"; position: absolute; left: 4px; }

/* ---------- история ---------- */
.post.highlight { border-color: var(--muted); }
.post-head { display: flex; gap: 12px; }
.thumb { position: relative; width: 64px; height: 64px; flex: none; border-radius: 10px; overflow: hidden; background: var(--chip); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-text { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-weight: 600; }
.thumb .count { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; border-radius: 5px; padding: 1px 5px; }
.post-meta { min-width: 0; flex: 1; }
.post-meta time { font-size: 12px; color: var(--muted); margin-left: 8px; }
.post-text { margin: 4px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--chip); }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.bad { color: var(--bad); }
.status.info { color: var(--info); }
.results { list-style: none; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.results li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.rname { flex: 1; }
.rstatus { font-size: 13px; }
.rstatus.ok { color: var(--ok); } .rstatus.bad { color: var(--bad); } .rstatus.info { color: var(--info); } .rstatus.muted { color: var(--muted); }
.rerror { flex-basis: 100%; margin: 0 0 0 16px; font-size: 12px; color: var(--bad); overflow-wrap: anywhere; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.info { background: var(--info); }
.post-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.post-actions:empty { display: none; }
.post-actions button { font-size: 14px; padding: 8px 10px; border-radius: 10px; background: var(--chip); }
.post-actions .danger { background: none; }
.post-actions .ghost { background: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- подключения ---------- */
.conn form { display: grid; gap: 8px; margin-top: 10px; }
.conn p { margin: 0; }
.hint { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 20;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); width: max-content;
  background: var(--accent); color: var(--accent-text);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; white-space: pre-line;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--bad); color: #fff; }
