:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --text: #15172b;
  --muted: #5d6178;
  --line: #e2e4ef;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef0ff;
  --ok: #0f8a5f;
  --ok-soft: #e3f6ee;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --bad: #c42b3c;
  --bad-soft: #fde8eb;
  --info: #2563eb;
  --info-soft: #e6efff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 50, .06), 0 8px 24px rgba(20, 22, 50, .06);
  --yt: #ff0033;
  --tt: #111111;
  --ig: #d62976;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020;
    --surface: #181a2e;
    --surface-2: #20233a;
    --text: #eceefe;
    --muted: #a3a7c2;
    --line: #2d3150;
    --accent: #8b85ff;
    --accent-ink: #11122a;
    --accent-soft: #262a52;
    --ok: #4cd39b;
    --ok-soft: #133528;
    --warn: #ffbf5c;
    --warn-soft: #3a2b12;
    --bad: #ff7a8a;
    --bad-soft: #3d1820;
    --info: #7aa7ff;
    --info-soft: #1a2747;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --tt: #f2f2f2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, calc((100vw - 1080px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 17px; }
.account-slot { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.user-chip img, .avatar-fallback { width: 30px; height: 30px; border-radius: 50%; flex: none; object-fit: cover; }
.avatar-fallback { display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; }
.user-chip .email { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-list button { display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list .danger { color: var(--bad); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-google {
  display: inline-flex; align-items: center; gap: 12px; padding: 12px 22px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow);
  font-weight: 600; font-size: 16px; cursor: pointer;
}
.btn-google:hover { border-color: var(--accent); }
.btn-google.compact { padding: 7px 14px; font-size: 14px; box-shadow: none; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; }

/* ---------- landing ---------- */
.landing { width: 100%; max-width: 1080px; margin: 0 auto; padding: 56px 16px 32px; flex: 1; }
.hero { text-align: center; max-width: 720px; margin: 0 auto; }
.eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .02em; margin: 0 0 12px; }
.hero h1 { font-size: clamp(30px, 6vw, 50px); letter-spacing: -.02em; }
.lead { color: var(--muted); font-size: 18px; margin: 18px auto 28px; max-width: 600px; }
.fine { color: var(--muted); font-size: 13px; margin-top: 14px; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; margin-top: 56px; }
.steps article { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.steps h2 { font-size: 18px; margin: 10px 0 6px; }
.steps p { color: var(--muted); margin: 0; }
.step-n { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* ---------- app ---------- */
.app { width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 16px 40px; flex: 1; display: grid; gap: 20px; align-content: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { font-size: 18px; }

.accounts { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; }
.account { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); min-width: 0; }
.account .meta { flex: 1; min-width: 0; }
.account .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .sub.warn { color: var(--warn); white-space: normal; }
.pf-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; color: #fff; position: relative; }
.pf-icon img { width: 100%; height: 100%; border-radius: 10px; object-fit: cover; }
.pf-icon .badge { position: absolute; right: -4px; bottom: -4px; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; border: 2px solid var(--surface-2); }
.pf-youtube { background: var(--yt); }
.pf-tiktok { background: #111; }
.pf-instagram { background: linear-gradient(45deg, #feda75, #fa7e1e 30%, #d62976 60%, #962fbf 85%, #4f5bd5); }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; scrollbar-width: none; }
.tabs button { padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }

.posts { display: grid; gap: 10px; }
.day-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 10px 2px 0; }
.post { display: grid; grid-template-columns: 76px 1fr auto; gap: 14px; align-items: start; padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.post .time { font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.post .date { font-size: 12px; color: var(--muted); }
.post .body { min-width: 0; }
.post .caption { margin: 0 0 8px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.post .caption.empty { color: var(--muted); font-style: italic; }
.post .file { font-size: 12px; color: var(--muted); margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.post .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.targets { display: flex; gap: 6px; flex-wrap: wrap; }
.target { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 5px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--text); text-decoration: none; max-width: 100%; }
.target .dot { width: 18px; height: 18px; border-radius: 6px; display: grid; place-items: center; color: #fff; flex: none; }
.target.published { background: var(--ok-soft); color: var(--ok); }
.target.failed { background: var(--bad-soft); color: var(--bad); }
.target.processing, .target.publishing { background: var(--info-soft); color: var(--info); }
.target.canceled { opacity: .7; }
.target-error { font-size: 12.5px; color: var(--bad); margin: 6px 0 0; overflow-wrap: anywhere; }
.status { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 2px; }
.status.scheduled { background: var(--accent-soft); color: var(--accent); }
.status.publishing { background: var(--info-soft); color: var(--info); }
.status.published { background: var(--ok-soft); color: var(--ok); }
.status.partial { background: var(--warn-soft); color: var(--warn); }
.status.failed { background: var(--bad-soft); color: var(--bad); }
.status.canceled { background: var(--surface-2); color: var(--muted); }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- dialogs ---------- */
.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .3); overflow: hidden;
}
.dialog.wide { width: min(760px, calc(100vw - 24px)); }
.dialog.small { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 12, 30, .5); backdrop-filter: blur(2px); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 18px; }
.dlg-body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 18px; }
.dlg-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlg-foot .grow { flex: 1; min-width: 160px; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 0; background: none; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }

.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-weight: 650; font-size: 14px; }
.hint { font-size: 12.5px; color: var(--muted); }
.hint.err { color: var(--bad); }
.hint.warn { color: var(--warn); }
input[type=text], input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.counter { font-size: 12px; color: var(--muted); text-align: right; }
.counter.over { color: var(--bad); font-weight: 700; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 180px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.check.disabled { opacity: .55; cursor: not-allowed; }
.seg { display: inline-flex; justify-self: start; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { position: relative; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.seg label:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -3px; }

.drop {
  display: grid; place-items: center; gap: 6px; text-align: center; padding: 26px 16px; border: 2px dashed var(--line); border-radius: 14px;
  background: var(--surface-2); cursor: pointer; color: var(--muted);
}
.drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--text); }
.video-preview { display: grid; grid-template-columns: 140px 1fr auto; gap: 14px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.video-preview video { width: 140px; height: 100px; object-fit: cover; border-radius: 8px; background: #000; }
.video-preview .meta { min-width: 0; font-size: 13px; color: var(--muted); }
.video-preview .meta strong { display: block; color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pf-block { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pf-block > .pf-toggle { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.pf-block > .pf-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.pf-block > .pf-toggle .pf-icon { width: 30px; height: 30px; border-radius: 8px; }
.pf-block > .pf-toggle .meta { flex: 1; min-width: 0; }
.pf-block > .pf-toggle .meta small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-block.off .pf-settings { display: none; }
.pf-block.unavailable { opacity: .65; }
.pf-settings { padding: 4px 14px 14px 56px; display: grid; gap: 12px; }
.creator { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.creator img { width: 24px; height: 24px; border-radius: 50%; }
.legal { font-size: 12.5px; color: var(--muted); margin: 0; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.form-error { color: var(--bad); font-weight: 600; font-size: 14px; margin: 0; }

/* ---------- misc ---------- */
.booting { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 80px 0; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.footer { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; padding: 22px 16px 30px; color: var(--muted); font-size: 13px; }
.footer a { color: var(--muted); }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: min(460px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 14px; animation: rise .2s ease-out; }
.toast.err { background: var(--bad); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.mock-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: 13px; padding: 6px 16px; font-weight: 600; }

@media (max-width: 640px) {
  .user-chip .email { display: none; }
  .post { grid-template-columns: 1fr; gap: 8px; }
  .post .when { display: flex; gap: 8px; align-items: baseline; }
  .post .actions { justify-content: flex-start; }
  .video-preview { grid-template-columns: 96px 1fr; }
  .video-preview video { width: 96px; height: 72px; }
  .video-preview .btn { grid-column: 1 / -1; }
  .pf-settings { padding-left: 14px; }
  .landing { padding-top: 36px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
