:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4e9;
  --text: #1b1f24;
  --muted: #646b75;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --accent-soft: #ecebff;
  --fb: #1877f2;
  --yt: #e62117;
  --danger: #d4343a;
  --danger-soft: #fdecec;
  --st-idea: #9a8cd8;
  --st-draft: #d99a00;
  --st-ready: #1f9d55;
  --st-scheduled: #2b8ac6;
  --st-posted: #8a929c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #232730;
    --border: #2f343e;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --accent: #8b8cf0;
    --accent-text: #111317;
    --accent-soft: #2a2a4a;
    --danger: #f0676c;
    --danger-soft: #3a1d20;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 11px; font-size: 16px; line-height: 1; }
.btn.small { padding: 4px 8px; font-size: 12px; }

input, select, textarea {
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; width: 100%;
}
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button {
  font: inherit; border: 0; background: transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 7px; cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 280px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
.menu-list button {
  font: inherit; text-align: left; border: 0; background: transparent; color: var(--text);
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.menu-list button:hover { background: var(--surface-2); }

.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px;
  padding: 16px; max-width: 1500px; margin: 0 auto;
}
main { min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav h1 { font-size: 20px; min-width: 150px; text-align: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; }
.filters input { width: 220px; }

/* ---------- month grid ---------- */
.month {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px; background: var(--border);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.dow { background: var(--surface-2); padding: 7px 4px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.day {
  background: var(--surface); min-height: 122px; padding: 6px;
  display: flex; flex-direction: column; gap: 4px; cursor: pointer; min-width: 0;
}
.day:hover { background: color-mix(in srgb, var(--surface) 85%, var(--accent-soft)); }
.day.other { background: var(--surface-2); }
.day.other .day-num, .day.other .day-posts { opacity: .5; }
.day.drop-target { outline: 2px dashed var(--accent); outline-offset: -3px; background: var(--accent-soft); }
.day-head { display: flex; align-items: center; gap: 6px; min-height: 24px; }
.day-num {
  font-size: 13px; font-weight: 600; min-width: 24px; height: 24px; padding: 0 4px;
  display: inline-grid; place-items: center; border-radius: 999px;
}
.day.today .day-num { background: var(--accent); color: var(--accent-text); }
.empty-tag { font-size: 11px; color: var(--muted); border: 1px dashed var(--border); border-radius: 4px; padding: 0 5px; }
.day .add {
  margin-left: auto; opacity: 0; font: inherit; font-size: 16px; line-height: 1;
  border: 0; background: var(--surface-2); color: var(--muted); border-radius: 6px; width: 24px; height: 24px; cursor: pointer;
}
.day:hover .add, .day .add:focus-visible { opacity: 1; }
@media (hover: none) { .day .add { opacity: .7; } }
.day-posts { display: flex; flex-direction: column; gap: 3px; overflow: hidden auto; max-height: 190px; }

/* status colour is carried by --st */
.st-idea { --st: var(--st-idea); }
.st-draft { --st: var(--st-draft); }
.st-ready { --st: var(--st-ready); }
.st-scheduled { --st: var(--st-scheduled); }
.st-posted { --st: var(--st-posted); }

.chip {
  display: grid; align-items: center; column-gap: 4px; row-gap: 1px; width: 100%;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "time pf . st" "title title title title";
  font-size: 12px; padding: 3px 6px;
  border: 1px solid var(--border); border-left: 3px solid var(--st); border-radius: 6px;
  background: var(--surface-2); color: var(--text); cursor: grab; user-select: none;
}
.chip:hover { border-color: var(--st); }
.chip.st-posted { opacity: .65; }
.chip.overdue { border-color: var(--danger); border-left-color: var(--danger); background: var(--danger-soft); }
.chip.dragging, .side-item.dragging { opacity: .4; }
.chip-time { grid-area: time; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); }
.chip .pf { grid-area: pf; }
.chip-title { grid-area: title; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-st { grid-area: st; font-size: 11px; }

.pf { display: inline-flex; gap: 2px; flex-shrink: 0; }
.pf i {
  font-style: normal; width: 15px; height: 15px; border-radius: 4px;
  display: inline-grid; place-items: center; font-size: 9px; font-weight: 800; color: #fff;
}
.pf .pf-facebook { background: var(--fb); }
.pf .pf-youtube { background: var(--yt); }

/* ---------- list view ---------- */
.group { margin-bottom: 18px; }
.group h2 { font-size: 14px; margin: 0 0 8px; display: flex; gap: 8px; align-items: center; }
.group h2 small { color: var(--muted); font-weight: 400; }
.tag { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1px 8px; background: var(--accent); color: var(--accent-text); }
.tag.warn { background: var(--danger); color: #fff; }
.row {
  display: grid; grid-template-columns: 52px 56px minmax(0, 1fr) auto auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--st);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 6px; cursor: pointer;
}
.row:hover { box-shadow: var(--shadow); }
.row.overdue { border-color: var(--danger); }
.r-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.thumb, .thumb-ph { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; display: block; background: var(--surface-2); }
.thumb-ph { display: grid; place-items: center; color: var(--muted); font-size: 20px; }
.r-main { min-width: 0; }
.r-title { font-weight: 600; display: flex; gap: 6px; align-items: center; min-width: 0; }
.r-title .txt, .r-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-sub { color: var(--muted); font-size: 13px; }
.badge {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--st) 18%, transparent);
}
.r-actions { display: flex; gap: 4px; }
.empty {
  text-align: center; padding: 48px 16px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty .btns { display: flex; gap: 8px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }

/* ---------- sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.card.warn h3 { color: var(--danger); }
.card.drop-target { outline: 2px dashed var(--accent); outline-offset: -3px; background: var(--accent-soft); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stat b { font-size: 20px; display: block; line-height: 1.2; }
.stat small { color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 2px 0 10px; }
.progress > div { height: 100%; background: var(--accent); }
.st-row { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 2px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--st); flex-shrink: 0; }
.st-row .n { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.side-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  font: inherit; color: var(--text); background: transparent; border: 0; border-radius: 8px;
  padding: 7px 8px; cursor: pointer; min-width: 0;
}
.side-item:hover { background: var(--surface-2); }
.side-item[draggable="true"] { cursor: grab; }
.side-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.side-row { display: flex; align-items: center; gap: 4px; }
.side-row .side-item { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.date-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.date-chips button {
  font: inherit; font-size: 12px; border: 1px dashed var(--border); background: transparent; color: var(--text);
  border-radius: 6px; padding: 3px 8px; cursor: pointer;
}
.date-chips button:hover { border-color: var(--accent); color: var(--accent); }
.more { font-size: 12px; color: var(--muted); padding: 4px 8px; }

/* ---------- dialogs ---------- */
.dialog {
  border: 0; padding: 0; border-radius: 14px;
  width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialog.small { width: min(520px, calc(100vw - 24px)); }
.dialog.wide { width: min(1100px, calc(100vw - 24px)); }
.radios { display: grid; gap: 6px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.lib-files { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.lib-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.lib-stats span { background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.lib-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.lib-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lib-table th, .lib-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.lib-table th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--muted); z-index: 1; }
.lib-table td.d { white-space: nowrap; font-variant-numeric: tabular-nums; }
.lib-table .w { color: var(--danger); font-size: 12px; }
.lib-table input { width: auto; }
.lib-table tr.off td { opacity: .45; }
.dialog::backdrop { background: rgba(10, 12, 16, .5); }
.dialog form, .dialog .dlg-wrap { display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.dlg-head, .dlg-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 18px; }
.dlg-head { border-bottom: 1px solid var(--border); }
.dlg-head h2 { font-size: 17px; }
.dlg-foot { border-top: 1px solid var(--border); flex-wrap: wrap; }
.dlg-foot .left, .dlg-foot .right { display: flex; gap: 8px; }
.dlg-body { overflow-y: auto; padding: 16px 18px; display: grid; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field > span small { font-weight: 400; }
.row3 { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.check input { width: auto; }

.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle, .pill { position: relative; }
.toggle input, .pill input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  display: inline-block; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.toggle.fb input:checked + span { background: var(--fb); border-color: var(--fb); color: #fff; }
.toggle.yt input:checked + span { background: var(--yt); border-color: var(--yt); color: #fff; }
.toggle input:focus-visible + span, .pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.status-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.pill span { display: inline-block; padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-size: 13px; }
.pill input:checked + span { border-color: var(--st); background: color-mix(in srgb, var(--st) 18%, transparent); font-weight: 600; }

.media { border: 1px dashed var(--border); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.media.drag { border-color: var(--accent); background: var(--accent-soft); }
.media.uploading { opacity: .7; pointer-events: none; }
.media-preview:empty { display: none; }
.media-preview img, .media-preview video { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; }
.media-preview a { word-break: break-all; }
.media-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.media-actions input { flex: 1; min-width: 180px; width: auto; }
.publish-links { display: flex; gap: 8px; flex-wrap: wrap; }
.fill-preview { margin: 0; font-weight: 600; }

/* ---------- auto-publish ---------- */
.conn-dots { display: inline-flex; gap: 3px; }
.conn-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.conn-dots i.on-facebook { background: var(--fb); }
.conn-dots i.on-youtube { background: var(--yt); }
.pub-list { display: grid; gap: 6px; }
.pub-list:empty { display: none; }
.pub-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.pub-row .pf { margin-right: 2px; }
.pub-row .msg { flex: 1; min-width: 180px; }
.pub-row.err { background: var(--danger-soft); }
.pub-row.err .msg { color: var(--danger); }
.pub-row .acts { display: flex; gap: 6px; }
.pub-note { font-size: 12px; color: var(--muted); margin: 0; }
.pub-note.warn { color: var(--danger); }
.pubs { display: inline-flex; gap: 6px; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }

.conn { border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.conn h3 { font-size: 15px; display: flex; gap: 8px; align-items: center; }
.conn-ok { color: var(--st-ready); font-weight: 600; }
.conn-no { color: var(--muted); }
.conn details { display: grid; gap: 10px; }
.conn details[open] > summary { margin-bottom: 10px; }
.conn summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.conn .form-grid { display: grid; gap: 10px; }
.conn .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.test-results { display: grid; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.test-row { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.test-row.bad { color: var(--danger); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 13px; }
.steps a, .note a { color: var(--accent); }
.steps code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; font-size: 12px; }
.note { font-size: 13px; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--st-draft) 14%, transparent); }
.dlg-foot .hint { flex: 1; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast {
  display: flex; align-items: center; gap: 12px; max-width: 380px;
  background: #22262e; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow);
  animation: toast-in .18s ease-out;
}
.toast.error { background: #c62f35; }
.toast button { font: inherit; color: inherit; background: rgba(255, 255, 255, .16); border: 0; border-radius: 6px; padding: 4px 9px; cursor: pointer; white-space: nowrap; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 680px) {
  .layout { padding: 12px 16px; }
  .top-actions { margin-left: 0; width: 100%; }
  .filters, .filters input { width: 100%; }
  .filters select { flex: 1; }
  .month-nav h1 { font-size: 17px; min-width: 0; flex: 1; }
  .day { min-height: 72px; padding: 3px; }
  .day-posts { flex-direction: row; flex-wrap: wrap; }
  .chip { width: auto; padding: 2px 3px; display: flex; }
  .chip-time, .chip-title, .chip-st, .empty-tag { display: none; }
  .row { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .row .r-media, .row .badge { display: none; }
  .row3, .row2 { grid-template-columns: 1fr; }
}
