:root {
  --bg: #f4f4f5;
  --card: #ffffff;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --soft: #f4f4f5;
  --accent: #6d4aff;
  --accent-soft: #efeaff;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef9c3;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --card: #1b1b20;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --line: #2d2d35;
    --soft: #26262c;
    --accent-soft: #2a2246;
    --ok: #4ade80;
    --ok-bg: #14321f;
    --warn: #facc15;
    --warn-bg: #3a320f;
    --bad: #f87171;
    --bad-bg: #3b1616;
    --info: #93c5fd;
    --info-bg: #172554;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app, #login { max-width: 640px; margin: 0 auto; padding: 16px; }
@media (min-width: 960px) {
  #app { max-width: 1120px; padding: 24px; }
}

h1 { font-size: 24px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.4em; margin: 8px 0; white-space: pre-line; }

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
button:disabled { opacity: .5; cursor: default; }
.btn { border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: var(--soft); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.link { color: var(--accent); font-weight: 600; }
input, textarea {
  font: inherit; color: var(--text); background: var(--soft);
  border: 1px solid transparent; border-radius: 12px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

/* --- Вход --- */
#login { padding-top: 20vh; }
#login form { display: flex; gap: 8px; margin-top: 12px; }

/* --- Шапка --- */
.top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.brand { font-size: 22px; font-weight: 700; }
.tabs { display: flex; gap: 4px; background: var(--card); padding: 4px; border-radius: 12px; flex: 1; max-width: 460px; }
.tab-btn { flex: 1; padding: 8px; border-radius: 9px; color: var(--muted); white-space: nowrap; }
.tab-btn.active { background: var(--bg); color: var(--text); font-weight: 600; }
.count { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; margin-left: 2px; }
.tab { display: none; }
.tab.active { display: block; }

/* --- Редактор --- */
.editor { display: grid; gap: 12px; }
@media (min-width: 960px) {
  .editor { grid-template-columns: 1.15fr 1fr; align-items: start; gap: 16px; }
}
.col { display: grid; gap: 12px; min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; }
.card-title { font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: baseline; }
.hint { margin-top: 8px; }
.editing-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-weight: 600;
}

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--soft); padding: 4px; border-radius: 12px; }
.segmented.two { grid-template-columns: 1fr 1fr; }
.segmented button { padding: 9px 4px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.segmented button.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.dropzone { display: flex; flex-wrap: wrap; gap: 8px; border-radius: 12px; }
.dropzone.drag { outline: 2px dashed var(--accent); outline-offset: 4px; }
.thumbs { display: contents; }
.thumb, .add-file {
  width: 96px; height: 96px; border-radius: 12px; position: relative; overflow: hidden; background: var(--soft);
  flex: none;
}
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .video-label {
  position: absolute; left: 6px; bottom: 6px; background: rgb(0 0 0 / .6); color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 6px;
}
.thumb .remove, .thumb .move {
  position: absolute; top: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: rgb(0 0 0 / .55); color: #fff; font-size: 14px; line-height: 24px; text-align: center;
}
.thumb .remove { right: 4px; }
.thumb .move.left { left: 4px; }
.thumb .move.right { left: 32px; }
.thumb .progress {
  position: absolute; inset: auto 0 0 0; height: 4px; background: var(--accent); transition: width .2s;
}
.thumb .num {
  position: absolute; left: 6px; bottom: 6px; background: rgb(0 0 0 / .6); color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 6px;
}
.add-file {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted); font-size: 13px; border: 1px dashed var(--line);
}
.add-file .plus { font-size: 28px; line-height: 1; }

.targets { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.target { background: var(--soft); border-radius: 12px; padding: 10px 12px; }
.target.off { opacity: .55; }
.target-row { display: flex; align-items: center; gap: 10px; }
.target-row label { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; min-width: 0; }
.target-name { font-weight: 600; }
.target-note { font-size: 12px; color: var(--muted); }
.target-extra { display: flex; gap: 14px; flex-wrap: wrap; margin: 8px 0 0 32px; font-size: 13px; }
.target-extra label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.target-extra .locked { color: var(--muted); }
.target textarea { margin-top: 8px; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin: 0; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.api, .badge.done { color: var(--ok); background: var(--ok-bg); }
.badge.limited, .badge.manual, .badge.scheduled, .badge.partial { color: var(--warn); background: var(--warn-bg); }
.badge.failed { color: var(--bad); background: var(--bad-bg); }
.badge.draft, .badge.pending { color: var(--muted); background: var(--soft); }
.badge.queued, .badge.publishing { color: var(--info); background: var(--info-bg); }

#later-box { margin-top: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip { background: var(--soft); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.chip.active { background: var(--accent); color: var(--accent-text); }
.filters { margin: 0 0 12px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.filters .chip { white-space: nowrap; flex: none; }
.chip.active { background: var(--accent); color: var(--accent-text); }

.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
@media (max-width: 959px) {
  .actions {
    position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--bg) 30%);
  }
}

/* --- Посты --- */
.posts { display: grid; gap: 10px; }
@media (min-width: 960px) { .posts { grid-template-columns: 1fr 1fr; align-items: start; } }
.post { background: var(--card); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.post-head { display: flex; gap: 12px; }
.post-thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--soft); flex: none; }
.post-thumb.empty { display: flex; align-items: center; justify-content: center; font-size: 26px; }
.post-meta { min-width: 0; flex: 1; }
.post-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.post-caption { color: var(--muted); font-size: 13px; margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pubs { display: grid; gap: 6px; }
.pub { display: grid; gap: 6px; font-size: 13px; background: var(--soft); border-radius: 10px; padding: 8px 10px; }
.pub-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pub-head a { color: var(--accent); font-weight: 600; }
.pub-name { font-weight: 600; min-width: 74px; }
.pub-error { color: var(--bad); overflow-wrap: anywhere; }
.pub .btn.ghost { background: var(--card); }
.post-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }

/* --- Аккаунты --- */
.accounts { display: grid; gap: 10px; }
@media (min-width: 960px) { .accounts { grid-template-columns: 1fr 1fr; } }
.account { background: var(--card); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; }
.account-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 10;
  opacity: 0; transition: .2s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
