:root {
  --bg: #edf0f3;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #18202e;
  --muted: #5d6878;
  --line: #d5dbe3;
  --signal: #2b44c7;
  --signal-soft: #e4e8fb;
  --ok: #17845a;
  --ok-soft: #e1f3ea;
  --warn: #a8670f;
  --warn-soft: #fbf0dc;
  --bad: #bf3a30;
  --bad-soft: #fbe6e4;
  --radius: 10px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --text: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161e; --surface: #1a202b; --surface-2: #202836; --ink: #e8ecf2; --muted: #9aa5b5;
    --line: #2e3747; --signal: #8a9bff; --signal-soft: #252e52; --ok: #4cc493; --ok-soft: #1a3329;
    --warn: #e0a64e; --warn-soft: #3a2e19; --bad: #f07a70; --bad-soft: #3d2120; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161e; --surface: #1a202b; --surface-2: #202836; --ink: #e8ecf2; --muted: #9aa5b5;
  --line: #2e3747; --signal: #8a9bff; --signal-soft: #252e52; --ok: #4cc493; --ok-soft: #1a3329;
  --warn: #e0a64e; --warn-soft: #3a2e19; --bad: #f07a70; --bad-soft: #3d2120; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--text); }
a { color: var(--signal); }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { padding: 24px 16px; border-right: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { font-family: var(--display); font-weight: 700; font-size: 1.35rem; padding: 0 10px 18px; display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--signal); display: grid; place-items: center; }
.brand-mark svg { width: 15px; height: 15px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--signal-soft); color: var(--signal); }
.nav .count { margin-left: auto; font-size: .78rem; background: var(--bad); color: #fff; border-radius: 99px; padding: 0 7px; }
.side .compose-btn { margin: 0 0 14px; }
.side-foot { margin-top: auto; font-size: .82rem; color: var(--muted); padding: 0 10px; }
.main { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

/* ---------- elements */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: 600 .92rem var(--text); padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #10131a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #10131a; } }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .84rem; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--signal); font: inherit; cursor: pointer; text-decoration: underline; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.compose > .panel + .panel { margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.help { font-size: .82rem; color: var(--muted); margin-top: 5px; }
input[type=text], input[type=password], input[type=datetime-local], input[type=url], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--signal-soft); border-color: var(--signal); }
textarea { resize: vertical; min-height: 90px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; background: var(--ok-soft); color: var(--ok); font-weight: 500; }
.flash.err { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.pill { display: inline-block; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.scheduled { background: var(--signal-soft); color: var(--signal); }
.pill.published, .pill.posted { background: var(--ok-soft); color: var(--ok); }
.pill.failed { background: var(--bad-soft); color: var(--bad); }
.pill.partial, .pill.publishing { background: var(--warn-soft); color: var(--warn); }

.badge { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; font: 700 .72rem var(--display); color: #fff; flex: none; }
.badge.facebook { background: #1877f2; }
.badge.instagram { background: #c13584; }
.badge.twitter { background: #2a3140; }
.badge.whatsapp { background: #1a9e50; }
.badge.tiktok { background: #e8274f; }
.badge.lg { width: 34px; height: 34px; font-size: .9rem; border-radius: 8px; }
.badge.failed { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--bad); }
.badges { display: inline-flex; gap: 5px; flex-wrap: wrap; }

/* ---------- timetable (queue) */
.day { display: grid; grid-template-columns: 140px 1fr; gap: 0 24px; padding: 22px 0; border-top: 1px solid var(--line); }
.day:first-of-type { border-top: 0; padding-top: 4px; }
.day-label { font-family: var(--display); }
.day-label .dname { font-size: 1.15rem; font-weight: 650; display: block; }
.day-label .ddate { color: var(--muted); font-size: .88rem; }
.slots { display: flex; flex-direction: column; gap: 10px; }
.slot { display: grid; grid-template-columns: 92px 1fr auto; gap: 18px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; }
.slot:hover { border-color: var(--signal); }
.slot .time { font: 600 1.7rem/1 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.slot .time small { display: block; font: 500 .75rem var(--text); color: var(--muted); margin-top: 6px; letter-spacing: 0; }
.slot .text { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.slot .meta { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.slot .thumbs { display: flex; gap: 4px; }
.thumb { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: .7rem; color: var(--muted); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 8px; }

.statusbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 26px; }
.stat { flex: 1 1 160px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.stat b { font: 650 1.4rem var(--display); display: block; }
.stat span { color: var(--muted); font-size: .85rem; }
.cron-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--ok); vertical-align: middle; }
.cron-dot.off { background: var(--bad); }

/* ---------- compose */
.compose { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.editor textarea.main-text { min-height: 220px; font-size: 1.02rem; line-height: 1.6; border: 0; padding: 0; resize: vertical; }
.editor textarea.main-text:focus { outline: none; }
.counter { font-size: .82rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.counter .over { color: var(--bad); font-weight: 600; }
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; display: block; font-weight: 500; }
.drop:hover, .drop.drag { border-color: var(--signal); color: var(--signal); background: var(--signal-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.media-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item label { position: absolute; inset: auto 4px 4px auto; margin: 0; background: rgba(0,0,0,.65); color: #fff; font-size: .72rem; padding: 2px 6px; border-radius: 5px; cursor: pointer; display: flex; gap: 4px; align-items: center; }
.media-item .kind { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: .7rem; padding: 1px 6px; border-radius: 5px; }

.channel-pick { display: flex; flex-direction: column; gap: 6px; }
.channel-pick .opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; margin: 0; font-weight: 500; }
.channel-pick .opt:has(input:checked) { border-color: var(--signal); background: var(--signal-soft); }
.channel-pick input { accent-color: var(--signal); width: 16px; height: 16px; margin: 0; }
.channel-pick .opt .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.when label { margin: 0; text-align: center; padding: 8px 4px; font-size: .86rem; cursor: pointer; border-left: 1px solid var(--line); font-weight: 600; color: var(--muted); }
.when label:first-child { border-left: 0; }
.when input { position: absolute; opacity: 0; pointer-events: none; }
.when label:has(input:checked) { background: var(--ink); color: var(--surface); }
.when label:has(input:focus-visible) { outline: 2px solid var(--signal); outline-offset: -2px; }
.warnings { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.warnings li { background: var(--warn-soft); color: var(--warn); border-radius: 7px; padding: 7px 10px; font-size: .84rem; }
.captions details { border-top: 1px solid var(--line); padding: 10px 0; }
.captions summary { cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .92rem; list-style: none; }
.captions summary::-webkit-details-marker { display: none; }
.captions summary .hint { margin-left: auto; font-weight: 400; color: var(--muted); font-size: .82rem; }
.captions textarea { margin-top: 10px; min-height: 80px; }

/* ---------- tables / lists */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; border-radius: 99px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .9rem; }
.tabs a[aria-current="true"] { background: var(--ink); color: var(--surface); }
.rows { display: flex; flex-direction: column; }
.row { display: grid; grid-template-columns: 150px 1fr auto auto; gap: 16px; align-items: center; padding: 14px 4px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.row:first-child { border-top: 0; }
.row:hover .rtext { color: var(--signal); }
.row .rtext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.target { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: start; padding: 14px 0; border-top: 1px solid var(--line); }
.target:first-child { border-top: 0; padding-top: 0; }
.target .err { color: var(--bad); font-size: .88rem; margin-top: 4px; }
.target .note { color: var(--muted); font-size: .88rem; margin-top: 4px; }
.post-body { white-space: pre-wrap; font-size: 1.02rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.log { font-size: .86rem; }
.log .row { grid-template-columns: 150px 70px 1fr; }
.lvl-error { color: var(--bad); font-weight: 600; }

/* ---------- channels */
.ch-list { display: flex; flex-direction: column; }
.ch { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.ch:first-child { border-top: 0; }
.ch.off { opacity: .55; }
.connect-grid { display: grid; align-items: start; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.connect-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.connect-card header { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.connect-card details { margin-top: 12px; }
.connect-card summary { cursor: pointer; color: var(--signal); font-weight: 600; font-size: .9rem; }
.connect-card form { margin-top: 12px; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; word-break: break-all; }
.code { display: block; padding: 10px 12px; margin: 6px 0 12px; }

/* ---------- calendar */
.cal-head { display: flex; align-items: center; gap: 10px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: var(--surface-2); padding: 8px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.cal .cell { background: var(--surface); min-height: 112px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.cal .cell.out { background: var(--surface-2); }
.cal .cell.out .dnum { color: var(--muted); opacity: .6; }
.cal .cell.today .dnum { background: var(--signal); color: #fff; }
.cal .dnum { font: 600 .82rem var(--display); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.cal .cell-head { display: flex; justify-content: space-between; align-items: center; }
.cal .add { opacity: 0; text-decoration: none; font-weight: 700; color: var(--signal); padding: 0 6px; }
.cal .cell:hover .add, .cal .add:focus-visible { opacity: 1; }
.cal .ev { display: block; font-size: .76rem; padding: 3px 6px; border-radius: 5px; text-decoration: none; color: var(--ink); background: var(--signal-soft); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-left: 3px solid var(--signal); }
.cal .ev.published { background: var(--ok-soft); border-color: var(--ok); }
.cal .ev.failed, .cal .ev.partial { background: var(--bad-soft); border-color: var(--bad); }
.cal .ev.draft { background: var(--surface-2); border-color: var(--muted); }
.cal .ev b { font-variant-numeric: tabular-nums; margin-right: 4px; }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .panel { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin-bottom: 6px; }
.auth p { color: var(--muted); }

/* ---------- responsive */
.mobile-bar { display: none; }
@media (max-width: 900px) {
  .compose { grid-template-columns: 1fr; }
  .compose > div[style*=sticky] { position: static !important; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; transform: translateX(-100%); transition: transform .2s; z-index: 20; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .mobile-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 10; }
  .main { padding-top: 20px; }
  h1 { font-size: 1.5rem; }
  .day { grid-template-columns: 1fr; gap: 10px; }
  .slot { grid-template-columns: 70px 1fr; }
  .slot .thumbs { display: none; }
  .slot .time { font-size: 1.35rem; }
  .row { grid-template-columns: 1fr auto; }
  .row .rwhen { grid-column: 1 / -1; font-size: .82rem; }
  .row .badges { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .cal .cell { min-height: 70px; }
  .cal .ev { font-size: 0; padding: 0; height: 6px; border-left-width: 0; }
  .log .row { grid-template-columns: 1fr; gap: 2px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
