:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #14161a; --muted: #6b7280; --line: #e5e7eb;
  --brand: #2563eb; --brand-ink: #fff; --good: #16a34a; --bad: #dc2626; --warn: #d97706; --chip: #f1f5f9;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0f13; --panel: #151820; --ink: #eef0f4; --muted: #9aa3b2; --line: #262b36; --chip: #1e2330; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 Inter, system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 800; font-size: 18px; display: flex; gap: 8px; align-items: center; }
.logo { width: 28px; height: 28px; border-radius: 7px; display: block; }
.app-pick { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
nav { display: grid; gap: 2px; }
nav a { padding: 8px 10px; border-radius: 9px; cursor: pointer; color: var(--ink); font-weight: 500; }
nav a:hover { background: var(--chip); }
nav a.on { background: var(--brand); color: var(--brand-ink); }
.meter { margin-top: auto; font-size: 12px; color: var(--muted); display: grid; gap: 4px; }
main { padding: 28px clamp(16px, 3vw, 40px); max-width: 1280px; width: 100%; min-width: 0; box-sizing: border-box; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
button { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: progress; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--chip); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.chip.good { color: var(--good); } .chip.bad { color: var(--bad); } .chip.warn { color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: flex; gap: 6px; align-items: center; background: var(--chip); padding: 6px 10px; border-radius: 999px; cursor: pointer; }
.checks input { width: auto; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.strip img, .strip video { height: 280px; border-radius: 10px; scroll-snap-align: start; flex: none; background: #000; }
.strip.small img, .strip.small video { height: 150px; }
.post { display: grid; gap: 12px; }
.post .caption { white-space: pre-wrap; font-size: 13px; max-height: 160px; overflow: auto; }
.app-head { display: flex; gap: 14px; align-items: center; }
.app-head img { width: 56px; height: 56px; border-radius: 13px; }
.swipe { max-width: 460px; margin: 0 auto; display: grid; gap: 14px; }
.swipe .strip img, .swipe .strip video { height: 520px; }
.swipe-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.swipe-actions button { padding: 14px; font-size: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.issue { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.issue > span:last-child { grid-column: 1 / -1; }
.count { font-variant-numeric: tabular-nums; font-size: 12px; }
.count.over { color: var(--bad); font-weight: 700; }
.stat { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
#toast { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 10; }
#toast div { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; max-width: 420px; box-shadow: var(--shadow); }
#toast div.err { background: var(--bad); color: #fff; }
.help { font-size: 12px; color: var(--muted); }
.help a { color: var(--brand); }
.slide-edit { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 6px; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  nav { grid-template-columns: repeat(3, 1fr); }
  .swipe .strip img, .swipe .strip video { height: 420px; }
  .slide-edit, .issue { grid-template-columns: 1fr; }
}

/* v2: dashboard, editor, calendar, assets */
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 2px; }
.side { overflow-y: auto; }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.tight { gap: 10px; }
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.inline { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 13px; }
label.inline input { width: auto; }
label.big { font-size: 16px; }
a { color: var(--brand); text-decoration: none; }
.line { padding: 8px 0; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.stat-card, .action-card { display: grid; gap: 4px; color: var(--ink); transition: transform .12s; }
.stat-card:hover, .action-card:hover, .clickable:hover { transform: translateY(-2px); border-color: var(--brand); }
.clickable { cursor: pointer; transition: transform .12s; }
.chip.score { font-variant-numeric: tabular-nums; }
.chip.st-draft { color: var(--muted); } .chip.st-approved { color: var(--brand); } .chip.st-scheduled { color: #7c3aed; }
.chip.st-posted { color: var(--good); } .chip.st-failed, .chip.st-rejected { color: var(--bad); }
.swipe-actions { grid-template-columns: repeat(4, 1fr); }
.warn-card { border-color: var(--warn); }
.log { white-space: pre-wrap; font-size: 12px; background: var(--chip); padding: 12px; border-radius: 10px; max-height: 320px; overflow: auto; margin: 0; }
.bar { width: 80px; height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.bar span { display: block; height: 100%; background: var(--muted); }
.bar .good { background: var(--good); } .bar .warn { background: var(--warn); } .bar .bad { background: var(--bad); }
.upl { display: inline-flex; cursor: pointer; font-weight: 600; color: var(--brand); font-size: 13px; }
.primary-upl { background: var(--brand); color: var(--brand-ink); padding: 8px 14px; border-radius: 10px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.thumbs img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.thumbs.big img { width: 96px; height: 96px; }
.thumbs img.on { border-color: var(--brand); }
.thumb-x { position: relative; }
.thumb-x img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; display: block; }
.thumb-x button { position: absolute; top: 4px; right: 4px; padding: 2px 7px; font-size: 11px; }
.actor { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; }
.actor img { width: 64px; height: 64px; object-fit: cover; border-radius: 50%; }
details > summary { cursor: pointer; }

/* Editor modal */
#modal { position: fixed; inset: 0; background: rgba(8,10,14,.6); z-index: 20; display: grid; place-items: center; padding: 16px; }
#modal[hidden] { display: none; }
.editor { background: var(--bg); border-radius: 18px; width: min(1360px, 100%); height: min(920px, 100%); display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.editor > header { padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.ed-grid { display: grid; grid-template-columns: 300px 1fr 300px; min-height: 0; }
.ed-panel { padding: 14px; overflow-y: auto; display: grid; gap: 8px; align-content: start; background: var(--panel); }
.ed-panel:first-child { border-right: 1px solid var(--line); } .ed-panel:last-child { border-left: 1px solid var(--line); }
.ed-panel h3 { margin: 10px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ed-panel textarea { min-height: 60px; }
.row.tight { gap: 6px; } .row.tight button { flex: 1; }
.row.center { justify-content: center; }
.ed-stage { display: grid; gap: 12px; align-content: start; padding: 16px; overflow-y: auto; }
.stage-wrap { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 8px; }
.stage { display: grid; place-items: center; }
.stage img { max-height: 62vh; max-width: 100%; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.nav-btn { font-size: 24px; padding: 6px 0; }
.dots { display: flex; gap: 6px; justify-content: center; }
.dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--line); cursor: pointer; }
.dots span.on { background: var(--brand); }
.video-box video { max-height: 50vh; display: block; margin: 8px auto 0; border-radius: 10px; }
.pf { font-size: 12px; padding: 6px 8px; border-radius: 8px; background: var(--chip); margin-bottom: 4px; }
.pf.error { color: var(--bad); } .pf.warn { color: var(--warn); } .pf.ok { color: var(--good); }
.hook-opt { text-align: left; white-space: normal; font-weight: 500; font-size: 12px; display: flex; gap: 6px; align-items: flex-start; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.cal-h { padding: 8px; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
.cal-d { min-height: 110px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; gap: 4px; align-content: start; }
.cal-d:nth-child(7n) { border-right: 0; }
.cal-d.out { background: var(--bg); opacity: .6; }
.cal-d.today .cal-n { background: var(--brand); color: #fff; border-radius: 999px; padding: 0 7px; }
.cal-d.drop { outline: 2px dashed var(--brand); outline-offset: -3px; }
.cal-n { font-size: 12px; font-weight: 600; justify-self: start; }
.cal-chip { font-size: 11px; padding: 3px 6px; border-radius: 6px; background: var(--chip); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: grab; border-left: 3px solid var(--muted); }
.cal-chip.st-scheduled { border-color: #7c3aed; } .cal-chip.st-posted { border-color: var(--good); cursor: pointer; }
.cal-chip.st-failed { border-color: var(--bad); } .cal-chip.st-approved { border-color: var(--brand); }
.cal-tray { margin-bottom: 12px; display: grid; gap: 10px; }
.tray { display: flex; flex-wrap: wrap; gap: 6px; } .tray .cal-chip { max-width: 260px; }
.legend { display: flex; gap: 8px; margin-bottom: 8px; }

@media (max-width: 1000px) {
  .ed-grid { grid-template-columns: 1fr; overflow-y: auto; }
  .editor { height: 100%; }
  .ed-panel { border: 0 !important; }
}
@media (max-width: 760px) {
  .cal-d { min-height: 70px; } .cal-chip b { display: none; }
  .swipe-actions { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  nav { display: flex; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  nav a { white-space: nowrap; }
  .nav-h { display: none; }
}

/* v3: auth, onboarding, connect */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.auth-card { width: min(420px, 100%); display: grid; gap: 12px; }
.auth-err { color: var(--bad); font-size: 13px; min-height: 1em; }
.big-btn { padding: 12px; font-size: 15px; }
.center { text-align: center; }
a.btn { display: inline-flex; align-items: center; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; padding: 8px 14px; white-space: nowrap; }
a.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.onboard { display: grid; gap: 4px; }
.step { display: grid; grid-template-columns: 32px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step .num { width: 28px; height: 28px; border-radius: 50%; background: var(--chip); display: grid; place-items: center; font-weight: 700; }
.step.done .num { background: var(--good); color: #fff; } .step.done b { color: var(--muted); text-decoration: line-through; }
.connect-card { display: grid; gap: 10px; align-content: start; }
.pf-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 800; background: #111; }
.pf-facebook { background: #1877f2; } .pf-instagram { background: linear-gradient(45deg, #f58529, #dd2a7b, #8134af); } .pf-tiktok { background: #010101; } .pf-youtube { background: #ff0000; } .pf-threads { background: #000; }

.tt-panel { display: grid; gap: 8px; text-align: left; }
.tt-sub { display: grid; gap: 6px; padding-left: 24px; }

.legal { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; line-height: 1.6; }
.legal h2 { margin-top: 28px; }

.plan ul { padding-left: 18px; margin: 12px 0 16px; line-height: 1.8; }
.plan.on { outline: 2px solid var(--brand); }

/* Public homepage */
.home { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; }
.home header { padding: 8px 0 24px; flex-wrap: wrap; gap: 12px; }
.home header .brand { color: inherit; text-decoration: none; }
.home nav { gap: 16px; flex-wrap: wrap; }
.home section { margin: 48px 0; }
.home .hero { margin-top: 32px; }
.home .hero h1 { font-size: clamp(32px, 6vw, 52px); line-height: 1.08; margin: 0 0 16px; max-width: 760px; }
.home .hero .sub { font-size: 18px; max-width: 680px; }
.home .steps-list { line-height: 1.8; padding-left: 20px; }
.home .grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.home .grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.home footer { border-top: 1px solid var(--line); padding-top: 20px; flex-wrap: wrap; gap: 8px; }

/* Studio: one-click Generate */
button.big { font-size: 17px; padding: 12px 22px; border-radius: 12px; }
#genSummary { flex: 1; min-width: 220px; }
.actor-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actor-row img { width: 56px; height: 70px; object-fit: cover; border-radius: 10px; cursor: pointer; border: 2px solid transparent; }
.actor-row img.on { border-color: var(--brand); }

/* Analytics */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat-tile { text-align: left; font-weight: 400; white-space: normal; }
.stat-tile.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 6px 12px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.chart { position: relative; margin-top: 12px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--brand); opacity: 0.1; }
.chart .dot { fill: var(--brand); stroke: var(--panel); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; box-shadow: 0 4px 14px rgba(0,0,0,.12); min-width: 90px; }
.chart-empty { padding: 60px 0; text-align: center; }
table.cmp th:first-child { width: 150px; }
table.cmp td, table.cmp th { min-width: 180px; }
table.cmp .app-head img { width: 36px; height: 36px; }

/* Admin */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
table.admin input, table.admin select, table.admin textarea { padding: 5px 8px; font-size: 13px; min-width: 90px; }
table.admin td { vertical-align: middle; }
table.raw td { white-space: nowrap; font-size: 12px; cursor: pointer; }
table.raw tr:hover td { background: var(--chip); }
img.mini, video.mini { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.data-grid { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: start; }
.data-grid .tables { display: grid; gap: 2px; padding: 8px; }
.data-grid .tables a { padding: 6px 8px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; }
.data-grid .tables a.on { background: var(--brand); color: var(--brand-ink); }
.data-grid .tables a.on .muted { color: inherit; }
.modal-card { max-width: 640px; margin: 6vh auto; }
.banner { background: var(--warn); color: #fff; border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-weight: 600; }
@media (max-width: 800px) { .data-grid { grid-template-columns: 1fr; } }
table.admin button { padding: 4px 9px; font-size: 12px; }
table.admin .row { gap: 4px; flex-wrap: wrap; }
.modal-card textarea { min-height: 0; resize: vertical; }
.data-grid .tables a { color: var(--ink); }
[hidden] { display: none !important; }
