:root {
  --primary: #6864F5;
  --primary-soft: #EFF0FE;
  --bg: #F7F8FB;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #14142B;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #1AA260;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.tiktok-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.tiktok-account-list {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  max-width: min(220px, 22vw);
  scrollbar-width: thin;
}
.tiktok-chip {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.youtube-chip {
  background: #fee2e2;
  color: #b91c1c;
}
.twitter-chip {
  background: #e5e7eb;
  color: #111827;
}
.instagram-chip {
  background: #fce7f3;
  color: #9d174d;
}
.linkedin-chip {
  background: #dbeafe;
  color: #1d4ed8;
}
a.btn { text-decoration: none; display: inline-flex; align-items: center; }

.video-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 16px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.video-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 340px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.video-tab:hover { background: var(--primary-soft); }
.video-tab.is-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.video-tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.video-tab-plat {
  flex: 0 0 auto;
  opacity: 0.75;
  font-size: 11px;
}
.video-tab-status {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  opacity: 0.8;
}
.video-tab.is-error {
  border-color: #fecaca;
  color: var(--danger);
}
.video-tab.is-posting {
  border-color: #fdba74;
  color: #9a3412;
  background: #fff7ed;
}
.video-tab.is-posting.is-on {
  background: #c2410c;
  border-color: #c2410c;
  color: #fff;
}
.video-tab.is-done {
  border-color: #bbf7d0;
  color: #166534;
  background: #f0fdf4;
}
.video-tab.is-done.is-on {
  background: #166534;
  border-color: #166534;
  color: #fff;
}
.video-tab.is-done .video-tab-name {
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.video-tab-clear {
  margin-left: auto;
  color: var(--muted);
  font-weight: 600;
}
.video-tab-clear:hover {
  background: #fee2e2;
  color: var(--danger);
}

.app-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 340px;
  align-items: start;
  min-height: calc(100vh - 73px);
}
.app-main { min-width: 0; padding-bottom: 48px; }
.activity-rail {
  position: sticky;
  top: 73px;
  height: calc(100vh - 73px);
  overflow: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.activity-head {
  flex: 0 0 auto;
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.activity-head h2 {
  margin: 0 0 4px;
  font-size: 16px;
}
.activity-head .sync-hint { margin: 0 0 8px; }
.activity-totals {
  margin: 0 0 10px;
  padding: 8px;
  background: var(--bg);
  border-radius: 12px;
}
.activity-totals-ranges {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.activity-range {
  flex: 1;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 6px;
  border-radius: 999px;
  cursor: pointer;
}
.activity-range.is-on {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}
.activity-totals-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  text-align: center;
}
.activity-totals-metrics b {
  display: block;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.activity-totals-metrics span {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}
#activitySearch {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--bg);
}
#activitySearch:focus { border-color: var(--primary); background: #fff; }
.activity-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.activity-filter {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.activity-filter.is-on {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}
.activity-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 0 0 38%;
  border-bottom: 1px solid var(--border);
}
.activity-pane-videos { flex: 1 1 auto; border-bottom: none; }
.activity-section-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
#accountSort {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  max-width: 130px;
}
.activity-account-list,
.activity-video-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 10px;
}
.activity-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 8px 4px;
}
.activity-account {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 28px 44px 18px;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.activity-account:hover { background: var(--bg); }
.activity-account-cols {
  cursor: default;
  padding: 0 8px 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.activity-account-cols:hover { background: transparent; }
.activity-account.is-on { background: var(--primary-soft); }
.activity-badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-align: center;
  padding: 2px 0;
  border-radius: 4px;
  background: var(--primary-soft);
  color: var(--primary);
}
.activity-badge.youtube {
  background: #fee2e2;
  color: #b91c1c;
}
.activity-badge.twitter {
  background: #e5e7eb;
  color: #111827;
}
.activity-badge.instagram {
  background: #fce7f3;
  color: #9d174d;
}
.activity-badge.linkedin {
  background: #dbeafe;
  color: #1d4ed8;
}
.activity-badge.all {
  background: var(--bg);
  color: var(--muted);
}
.activity-account-name {
  font-size: 12px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-account-count,
.activity-account-last {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--muted);
}
.activity-account-count {
  font-weight: 700;
  color: var(--text);
}
.activity-account-count.is-hot { color: var(--danger); }
.activity-account-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}
.activity-account-remove:hover { background: #fdecea; }
.activity-account-remove:disabled { opacity: 0.45; cursor: wait; }
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 20, 43, 0.45);
}
.confirm-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 18px 16px;
  box-shadow: 0 8px 24px rgba(20, 20, 43, 0.16);
}
.confirm-card p {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.45;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.confirm-card .confirm-input {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: var(--bg);
  color: inherit;
}
.activity-video {
  width: 100%;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 7px 8px;
  cursor: pointer;
  font-family: inherit;
}
.activity-video:hover { background: var(--bg); }
.activity-video.is-open { background: var(--bg); }
.activity-video-head {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.activity-video-title {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}
.activity-video-remove {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--danger);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}
.activity-video-remove:hover { background: #fdecea; }
.activity-video-remove:disabled { opacity: 0.45; cursor: wait; }
.activity-video.is-open .activity-video-title { -webkit-line-clamp: unset; }
.activity-video-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.activity-video-plats { display: inline-flex; gap: 4px; }
.activity-video-plats a,
.activity-video-plats span {
  font-size: 10px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}
.activity-video-plats a.youtube-link,
.activity-video-plats span.youtube-link { color: #b91c1c; }
.activity-video-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.activity-video-stats b {
  display: block;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.activity-video-stats span {
  font-size: 10px;
  color: var(--muted);
}
.activity-video-sync {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
}
.app-sidebar {
  position: sticky;
  top: 73px;
  height: calc(100vh - 73px);
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px 18px 40px;
}
.sidebar-block + .sidebar-block {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.app-sidebar h2 {
  margin: 0 0 12px;
  font-size: 16px;
}
.app-sidebar label { display: block; }
.app-sidebar .planner-field { min-width: 0; }
.app-sidebar select,
.app-sidebar textarea,
.app-sidebar input[type="text"] {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.app-sidebar select:focus,
.app-sidebar textarea:focus,
.app-sidebar input[type="text"]:focus { border-color: var(--primary); }
.app-sidebar textarea { resize: vertical; }
.color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.color-row input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.overlay-preview {
  background: #1a1a1a;
  border-radius: 12px;
  min-height: 110px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px 12px 22px;
}
.overlay-preview-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 100%;
}
.overlay-preview-line {
  display: inline-block;
  font-family: "Segoe UI", "Avenir Next", Arial, sans-serif;
  font-weight: 800;
  font-size: 18px;
  line-height: 1.2;
  padding: 5px 12px;
  border-radius: 10px;
  margin: 3px 0;
  word-break: break-word;
}
.tiktok-post-link {
  display: inline-block;
  margin-top: 10px;
  margin-right: 14px;
  font-weight: 600;
  color: var(--primary);
}
.caption-variant {
  margin: 10px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px 10px;
  background: var(--bg);
}
.caption-variant summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.caption-variant .char-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.caption-variant .char-count.is-over {
  color: #b91c1c;
}
.sidebar-block label .char-count {
  float: right;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.sidebar-block label .char-count.is-over {
  color: #b91c1c;
}
.caption-variant label {
  margin-top: 10px;
}
.import-account-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.import-account-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.import-account-list small {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.planner {
  max-width: 980px;
  margin: 20px auto 0 auto;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(20,20,43,0.04);
}
.planner-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.planner-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}
.planner-field label {
  margin-top: 0;
}
.planner select,
.planner textarea,
.planner input[type="text"] {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.planner select:focus,
.planner textarea:focus,
.planner input[type="text"]:focus { border-color: var(--primary); }
.planner textarea { width: 100%; resize: vertical; }
.planner-row + .planner-field { margin-top: 12px; }
#randomizeBtn,
#regenerateBtn { flex: 0 0 auto; height: 42px; }
.template-row { margin-top: 12px; }
.template-row .btn { flex: 0 0 auto; height: 42px; }
.template-row + .sync-hint {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 13px;
}
.voice-speed-field { min-width: 180px; flex: 0.7; }
.voice-speed-field input[type="range"] { width: 100%; accent-color: var(--primary); }
.voice-select-field { min-width: 150px; flex: 0.55; }
.sfx-field {
  flex: 0 0 auto;
  min-width: 168px;
}
.slide1-video-field {
  flex: 0 0 auto;
  min-width: 132px;
}
.planner-check-label {
  font-size: 13px;
  color: var(--muted);
}
.planner-check {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.planner-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}
#voiceSpeedValue { color: var(--primary); font-weight: 700; text-transform: none; letter-spacing: 0; }

.script-type-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.script-type-row select { flex: 1; min-width: 0; }
.script-type-row .btn { flex: 0 0 auto; height: 42px; }
.hook-editor {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}
.hook-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  margin: 8px 0;
}
.hook-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.hook-row input[type="text"] { flex: 1; min-width: 0; }
.hook-row .btn { flex-shrink: 0; }
.hook-editor-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.design-image-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 8px;
}
.design-image-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 13px;
}
.design-image-chip img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
  flex-shrink: 0;
}
.design-image-chip-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.design-image-chip-label {
  font-weight: 600;
}
.design-image-chip-desc {
  width: 100%;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.design-image-chip-desc:focus { border-color: var(--primary); }
.design-image-chip .btn { flex-shrink: 0; margin-top: 2px; }
.design-image-add {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.design-image-add input[type="text"] { flex: 1; min-width: 160px; }

.slot-col select {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--text);
}
.slot-col select:focus { border-color: var(--primary); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: #fdecea; color: var(--danger); }
.btn-tiny { padding: 5px 9px; font-size: 12px; border-radius: 6px; }

.connect-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.connect-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 28px 24px;
  box-shadow: 0 1px 3px rgba(20, 20, 43, 0.08);
}
.connect-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
}
.connect-card .lede {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}
.connect-keep {
  background: #ecfdf3;
  color: #166534;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 16px;
}
.connect-steps {
  margin: 0 0 20px;
  padding-left: 18px;
  color: var(--text);
  line-height: 1.5;
}
.connect-steps li { margin: 0 0 8px; }
.connect-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.slots {
  max-width: 980px;
  margin: 24px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.slot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 3px rgba(20,20,43,0.04);
}

.slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.slot-index {
  font-weight: 700;
  color: var(--primary);
  font-size: 14px;
}
.slot-header-actions { display: flex; gap: 6px; }

.slot-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 760px) {
  .slot-body { grid-template-columns: 1fr; }
}

.slot-col { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-top: 8px;
}
label:first-child { margin-top: 0; }

textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: vertical;
  outline: none;
}
textarea:focus { border-color: var(--primary); }

.paste-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  position: relative;
  overflow: hidden;
}
.paste-zone:focus { border-color: var(--primary); outline: none; }
.remove-reference {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(20, 20, 43, 0.72);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.remove-reference:hover { background: var(--danger); }
.reference-thumb {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
}
.reference-thumb.hidden, .hidden { display: none !important; }

.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.status-msg {
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#statusMsg {
  max-width: min(420px, 42vw);
}
#tiktokPostStatus {
  flex: 1;
  min-width: 0;
}
.status-msg.error { color: var(--danger); }
.status-msg.ok { color: var(--success); }
.sync-hint.error { color: var(--danger); }

.audio-preview { width: 100%; margin-top: 8px; }
.sync-hint code {
  font-size: 11px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
}
.clip-preview {
  width: 100%;
  max-width: 260px;
  border-radius: 10px;
  margin-top: 10px;
  background: #000;
  aspect-ratio: 9/16;
}

.add-slot-row {
  max-width: 980px;
  margin: 0 auto 40px auto;
  padding: 0 20px;
}

.export-section {
  max-width: 980px;
  margin: 0 auto 60px auto;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
#exportVideo {
  width: 300px;
  aspect-ratio: 9/16;
  background: #000;
  border-radius: 10px;
  display: block;
  margin: 12px 0;
}

@media (max-width: 1280px) {
  .app-layout { grid-template-columns: 1fr; }
  .activity-rail,
  .app-sidebar {
    position: relative;
    top: 0;
    height: auto;
    border-right: none;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .activity-rail { overflow: visible; }
  .activity-pane,
  .activity-pane-videos { flex: none; max-height: 360px; }
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.mode-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.mode-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.mode-switch-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}
.mode-switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(20, 20, 43, 0.25);
  transition: transform 0.15s;
}
.mode-switch input:checked + .mode-switch-slider {
  background: var(--primary);
}
.mode-switch input:checked + .mode-switch-slider::before {
  transform: translateX(20px);
}
.mode-switch input:focus-visible + .mode-switch-slider {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

body.reply-mode .tiktok-bar,
body.reply-mode #exportBtn,
body.reply-mode .video-tabs {
  display: none !important;
}

.reply-screen {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 72px);
  align-items: start;
}
.reply-screen.hidden { display: none !important; }
.reply-side {
  padding: 20px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 72px);
  overflow: auto;
}
.reply-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.reply-card h2 {
  margin: 0 0 4px;
  font-size: 15px;
}
.reply-card label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.reply-card input,
.reply-card textarea,
.reply-card select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  background: #fff;
}
.reply-balance {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--success);
}
.reply-add-service {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}
.reply-catalog {
  max-height: 160px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  background: var(--bg);
}
.reply-catalog button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
.reply-catalog button:hover { background: var(--primary-soft); }
.reply-service-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reply-service-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 10px;
}
.reply-service-row b { font-size: 13px; }
.reply-main {
  padding: 20px 24px 40px;
  min-width: 0;
}
.reply-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}
.reply-toolbar .planner-field { min-width: 180px; }
.reply-toolbar input[type="number"] {
  width: 90px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
.reply-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.reply-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
.reply-table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.reply-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.reply-table th,
.reply-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}
.reply-table th {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  position: sticky;
  top: 0;
}
.reply-table textarea {
  width: 100%;
  min-width: 280px;
  min-height: 72px;
  height: auto;
  overflow: hidden;
  resize: vertical;
  field-sizing: content;
  line-height: 1.4;
  white-space: pre-wrap;
}
.reply-video-link {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.reply-video-link:hover { color: var(--primary); }
.reply-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
}
.reply-status {
  font-weight: 700;
  text-transform: capitalize;
  white-space: nowrap;
}
.reply-status.sent { color: var(--success); }
.reply-status.loaded { color: var(--primary); }
.reply-status.draft { color: var(--success); }
.reply-badge-ready { background: #ecfdf3; color: #166534; }
.reply-badge-run { background: var(--primary-soft); color: var(--primary); }
.reply-badge-err { background: #fdecea; color: var(--danger); }
.reply-badge-ok { background: #ecfdf3; color: #166534; }
.reply-status.error { color: var(--danger); }
.reply-status.skipped { color: var(--muted); }
.reply-error {
  display: block;
  color: var(--danger);
  font-size: 11px;
  margin-top: 4px;
}
.reply-sent {
  margin-top: 28px;
}
.reply-sent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.reply-sent-head h2 {
  margin: 0;
  font-size: 16px;
}
.reply-sent-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.reply-like-toolbar {
  margin: 10px 0 12px;
}
.reply-status.pending,
.reply-status.in-progress,
.reply-status.processing { color: var(--primary); }
.reply-status.completed,
.reply-status.complete { color: var(--success); }
.reply-status.canceled,
.reply-status.cancelled,
.reply-status.refunded,
.reply-status.error { color: var(--danger); }
.reply-status.partial { color: #92400e; }
.reply-comment-preview {
  max-width: 520px;
  line-height: 1.4;
  white-space: pre-wrap;
}

@media (max-width: 1100px) {
  .reply-screen { grid-template-columns: 1fr; }
  .reply-side {
    position: relative;
    top: 0;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  display: grid;
  gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { font-size: 13px; font-weight: 600; }
.login-card input[type="password"] {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.business-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.business-bar label { font-size: 12px; color: var(--muted); }
.business-bar select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.business-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 43, 0.4);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}
.business-modal.hidden { display: none; }
.business-modal-card {
  width: min(640px, 100%);
  max-height: 80vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 16px;
  padding: 20px;
}
.account-assign-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

body.is-viewer .operator-only,
body.is-viewer .tiktok-bar,
body.is-viewer .app-main,
body.is-viewer #replyScreen,
body.is-viewer .activity-video-remove,
body.is-viewer .mode-switch {
  display: none !important;
}
body.is-viewer .app-layout {
  grid-template-columns: minmax(0, 1fr);
}
body.is-viewer .activity-rail {
  position: relative;
  top: 0;
  height: auto;
  min-height: calc(100vh - 73px);
  border-right: none;
}

