:root {
  --bg: #f5f5f8;
  --card: #ffffff;
  --ink: #111118;
  --ink-2: #555566;
  --ink-3: #8a8a99;
  --line: #e6e6ee;
  --accent: #4a3aff;
  --accent-soft: #ecebff;
  --ok: #138a4e;
  --ok-soft: #e4f5ec;
  --warn: #a86400;
  --warn-soft: #fff3de;
  --bad: #c42b2b;
  --bad-soft: #fde9e9;
  --fb: #1877f2;
  --ig: #d62976;
  --th: #111118;
  --in: #0a66c2;
  --r: 12px;
  --shadow: 0 1px 2px rgba(17, 17, 24, .05), 0 4px 16px rgba(17, 17, 24, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Onest, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: #c9c9d6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 4px 8px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
}

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--card); border-radius: 16px; padding: 28px;
  box-shadow: var(--shadow); display: grid; gap: 12px;
}
.login-card .brand { margin-bottom: 8px; }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.err { color: var(--bad); margin: 0; font-size: 14px; min-height: 1em; }

/* шапка */
.top {
  position: sticky; top: 0; z-index: 10; background: rgba(245, 245, 248, .92); backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 18px; padding: 12px 24px; border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a {
  text-decoration: none; color: var(--ink-2); padding: 7px 12px; border-radius: 8px; font-weight: 500; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tabs a.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.count { background: var(--accent); color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 7px; font-weight: 600; }
.count.red { background: var(--bad); }

main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.section-head h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.section-head .sub { color: var(--ink-3); font-size: 14px; }
.empty { background: var(--card); border-radius: var(--r); padding: 40px; text-align: center; color: var(--ink-3); box-shadow: var(--shadow); }

/* календарь */
.cal-nav { display: flex; gap: 8px; margin-left: auto; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal-dow { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 0 4px; }
.day {
  background: var(--card); border-radius: 10px; min-height: 118px; padding: 8px; display: flex; flex-direction: column; gap: 5px;
  border: 1px solid transparent;
}
.day.past { opacity: .55; }
.day.today { border-color: var(--accent); }
.day-num { font-size: 13px; color: var(--ink-3); display: flex; justify-content: space-between; align-items: center; }
.day-num .add { opacity: 0; border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 2px; }
.day:hover .day-num .add { opacity: 1; }
.chip {
  display: flex; gap: 6px; align-items: flex-start; font-size: 12.5px; line-height: 1.3; padding: 5px 6px; border-radius: 7px;
  background: var(--bg); cursor: pointer; border-left: 3px solid var(--ink-3); text-align: left; border-top: 0; border-right: 0; border-bottom: 0; width: 100%;
}
.chip:hover { background: #ececf3; }
.chip .t { font-variant-numeric: tabular-nums; color: var(--ink-2); flex: none; }
.chip .x { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chip.st-approved { border-left-color: var(--accent); }
.chip.st-publishing { border-left-color: #8a5cff; }
.chip.st-published { border-left-color: var(--ok); }
.chip.st-failed { border-left-color: var(--bad); background: var(--bad-soft); }
.chip.st-pending, .chip.st-draft { border-left-style: dashed; border-left-color: var(--warn); }
.chip.st-rejected, .chip.st-removed { opacity: .5; text-decoration: line-through; }

.pf { flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 5px; color: #fff; font-size: 10px; font-weight: 700; }
.pf.facebook { background: var(--fb); }
.pf.instagram { background: var(--ig); }
.pf.threads { background: var(--th); }
.pf.linkedin { background: var(--in); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); margin-top: 14px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* карточки апрува и журнала */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.card-media { aspect-ratio: 1 / 1; background: #1a1a22; position: relative; }
.card-media img, .card-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-media .n { position: absolute; right: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.card-body { padding: 14px; display: grid; gap: 8px; flex: 1; }
.card-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.card-text { white-space: pre-wrap; font-size: 14px; max-height: 9.5em; overflow: hidden; position: relative; }
.card-text.long::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2em; background: linear-gradient(transparent, var(--card)); }
.card-foot { display: flex; gap: 8px; padding: 0 14px 14px; flex-wrap: wrap; }
.card-foot .btn { flex: 1; }

.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--ink-2); }
.status.approved { background: var(--accent-soft); color: var(--accent); }
.status.publishing { background: #efe8ff; color: #6a3de8; }
.status.published { background: var(--ok-soft); color: var(--ok); }
.status.failed { background: var(--bad-soft); color: var(--bad); }
.status.pending, .status.draft { background: var(--warn-soft); color: var(--warn); }

.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); }
.table td, .table th { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
.table th { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .when { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.table .msg-error { color: var(--bad); }
.table .msg-warn { color: var(--warn); }
h2.block { font-size: 16px; margin: 28px 0 10px; }

/* подключения */
.conn { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.conn-card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; display: grid; gap: 8px; align-content: start; }
.conn-card h3 { margin: 0; display: flex; align-items: center; gap: 10px; font-size: 16px; }
.conn-card .line { font-size: 14px; color: var(--ink-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--ink-3); margin-left: auto; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

/* редактор */
.modal { position: fixed; inset: 0; background: rgba(17, 17, 24, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.sheet { background: var(--card); border-radius: 16px; width: 100%; max-width: 1100px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-head .icon-btn { margin-left: auto; }
.sheet-body { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; padding: 18px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.sheet-foot .spacer { flex: 1; }
.ed-form { display: grid; gap: 12px; align-content: start; }
.ed-form label { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.ed-form input, .ed-form select, .ed-form textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; color: var(--ink); font-size: 15px; width: 100%;
}
.ed-form textarea { resize: vertical; line-height: 1.5; }
.ed-form input:focus, .ed-form select:focus, .ed-form textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.counter { font-size: 12.5px; color: var(--ink-3); margin-top: -6px; text-align: right; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--bad); font-weight: 600; }
.hint { margin: -4px 0 0; font-size: 13px; color: var(--ink-3); }

.media-zone { border: 1.5px dashed var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 10px; }
.media-zone.drag { border-color: var(--accent); background: var(--accent-soft); }
.media-list { display: flex; gap: 8px; flex-wrap: wrap; }
.media-list:empty { display: none; }
.mi { position: relative; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; background: #1a1a22; }
.mi img, .mi video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mi .ctl { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; background: linear-gradient(transparent, rgba(0,0,0,.7)); padding: 2px; }
.mi .ctl button { border: 0; background: none; color: #fff; cursor: pointer; font-size: 14px; padding: 2px 6px; }
.mi .vid { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 99px; }
.mi.loading::after { content: 'грузится'; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 12px; background: rgba(0,0,0,.5); }
.media-add { cursor: pointer; display: grid; gap: 2px; text-align: center; padding: 10px; border-radius: 8px; color: var(--accent); font-weight: 600; font-size: 14px; }
.media-add:hover { background: var(--accent-soft); }
.media-add small { color: var(--ink-3); font-weight: 400; font-size: 12px; }

.preview { position: sticky; top: 0; align-self: start; }
.pv-label { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.pv-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.pv-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 600; font-size: 14px; }
.pv-av { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.pv-media { aspect-ratio: 1 / 1; background: #1a1a22; position: relative; }
.pv-media.story { aspect-ratio: 9 / 16; }
.pv-media img, .pv-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv-media .n { position: absolute; right: 8px; top: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 99px; }
.pv-text { padding: 10px 12px 14px; font-size: 14px; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; }
.pv-text b { font-weight: 600; }
.pv-empty { padding: 30px 12px; text-align: center; color: var(--ink-3); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px;
  border-radius: 10px; z-index: 80; max-width: calc(100vw - 32px); font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.toast.bad { background: var(--bad); }

@media (max-width: 900px) {
  .sheet-body { grid-template-columns: 1fr; }
  .preview { position: static; }
}
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .brand-name { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  #newPost { margin-left: auto; }
  main { padding: 16px 16px 60px; }
  .cal { grid-template-columns: 1fr; }
  .cal-dow { display: none; }
  .day { min-height: 0; }
  .day.pad { display: none; }
  .day-num .add { opacity: 1; }
  .modal { padding: 0; }
  .sheet { max-height: 100vh; height: 100%; border-radius: 0; }
  .table .hide-m { display: none; }
}
