:root {
  color-scheme: dark;
  --bg: #080b12;
  --bg-elevated: #0e131f;
  --surface: rgba(18, 24, 38, 0.86);
  --surface-solid: #121826;
  --surface-soft: #171f31;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.22);
  --ig: #ec4899;
  --ig-glow: rgba(236, 72, 153, 0.2);
  --tt: #06b6d4;
  --tt-glow: rgba(6, 182, 212, 0.2);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.16);
  --red: #f43f5e;
  --red-soft: rgba(244, 63, 94, 0.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fb;
  --bg-elevated: #ffffff;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-soft: #f8fafc;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(59, 130, 246, 0.14), transparent 60%),
    radial-gradient(760px 380px at 90% -8%, rgba(6, 182, 212, 0.11), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top Navigation ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  backdrop-filter: blur(16px);
  background: color-mix(in srgb, var(--bg-elevated) 82%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.5px;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.brand-title { font-weight: 750; font-size: 15px; letter-spacing: -0.2px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-pills {
  display: flex;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.nav-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 18px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.18s ease;
}
.nav-pill:hover { color: var(--text); }
.nav-pill.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}
.status-pill.ready .dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 15px;
  transition: border-color 0.15s, transform 0.15s;
}
.icon-btn:hover { border-color: var(--border-strong); transform: translateY(-1px); }

/* ---------- Layout ---------- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero-head {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.hero-head h1 {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 800;
  letter-spacing: -0.6px;
}
.hero-head p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

/* ---------- Platform Selector ---------- */
.platform-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
@media (max-width: 640px) {
  .platform-grid { grid-template-columns: 1fr; }
}

.platform-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: all 0.18s ease;
}
.platform-card:hover { border-color: var(--border-strong); color: var(--text); }
.platform-card .p-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(148, 163, 184, 0.1);
  flex-shrink: 0;
}
.platform-card .p-name { font-weight: 700; font-size: 14px; color: var(--text); }
.platform-card .p-desc { font-size: 11px; color: var(--text-muted); }

.platform-card.active[data-platform="facebook"] {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.18), rgba(59, 130, 246, 0.04));
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.platform-card.active[data-platform="facebook"] .p-icon { background: rgba(59, 130, 246, 0.25); color: #60a5fa; }

.platform-card.active[data-platform="instagram"] {
  border-color: var(--ig);
  background: linear-gradient(135deg, rgba(236, 72, 153, 0.18), rgba(168, 85, 247, 0.06));
  box-shadow: 0 0 0 1px var(--ig) inset;
}
.platform-card.active[data-platform="instagram"] .p-icon { background: rgba(236, 72, 153, 0.22); color: #f472b6; }

.platform-card.active[data-platform="tiktok"] {
  border-color: var(--tt);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.18), rgba(244, 63, 94, 0.06));
  box-shadow: 0 0 0 1px var(--tt) inset;
}
.platform-card.active[data-platform="tiktok"] .p-icon { background: rgba(6, 182, 212, 0.22); color: #22d3ee; }

/* ---------- Mode Pills & Form ---------- */
.mode-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.mode-pill {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-pill:hover { color: var(--text); border-color: var(--border-strong); }
.mode-pill.active {
  background: var(--text);
  color: var(--bg-elevated);
  border-color: var(--text);
}

.notice-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--amber);
  font-size: 12.5px;
  margin-bottom: 16px;
}

.url-hero-row {
  display: grid;
  grid-template-columns: 1fr 165px auto;
  gap: 12px;
  align-items: end;
}
@media (max-width: 820px) {
  .url-hero-row { grid-template-columns: 1fr; }
}

.field { margin-bottom: 14px; }
.field.no-mb { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field label small { font-weight: 400; color: var(--text-faint); }

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
textarea,
select {
  width: 100%;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 13px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

.batch-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.toggles-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}

.toggles-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}
.chip-toggle input { display: none; }
.chip-toggle .track {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.2s;
}
.chip-toggle .track::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: left 0.2s;
}
.chip-toggle input:checked + .track { background: var(--accent); }
.chip-toggle input:checked + .track::after { left: 19px; }
.chip-toggle input:checked ~ span { color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}
.btn.secondary {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-soft); }
.btn.sm { padding: 7px 12px; font-size: 12px; border-radius: 8px; }

/* ---------- Compact Activity Strip ---------- */
.activity-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.activity-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.activity-msg {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 999px;
}
.badge.idle { background: var(--border); color: var(--text-muted); }
.badge.running { background: var(--accent-glow); color: #60a5fa; }
.badge.done { background: var(--green-soft); color: var(--green); }
.badge.error, .badge.stopped { background: var(--red-soft); color: var(--red); }

.trace-drawer {
  background: #070a10;
  color: #cbd5e1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  height: 220px;
  overflow-y: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.65;
  margin-bottom: 20px;
}
.log-line .t { color: #64748b; margin-right: 8px; }
.log-line.ok { color: var(--green); }
.log-line.warn { color: var(--amber); }
.log-line.err { color: var(--red); }

/* ---------- Result Analytics Workspace ---------- */
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.author-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.author-link { font-size: 15px; font-weight: 700; color: var(--accent); text-decoration: none; }
.author-link:hover { text-decoration: underline; }
.platform-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-glow);
  color: #60a5fa;
  text-transform: uppercase;
}
.date-label { font-size: 12px; color: var(--text-muted); }

.caption-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  white-space: pre-wrap;
  line-height: 1.6;
  margin-bottom: 16px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-tile {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.kpi-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.4px; }
.kpi-val { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.reaction-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.reaction-pill {
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 12px;
}

.media-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.media-strip img {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}

/* ---------- Sentiment Studio Panel ---------- */
.sentiment-card {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.08), rgba(16, 185, 129, 0.03));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}
.sentiment-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.sentiment-head h3 { font-size: 15px; font-weight: 750; }
.score-pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.score-pill.pos { background: var(--green-soft); color: var(--green); }
.score-pill.neu { background: var(--border); color: var(--text-muted); }
.score-pill.neg { background: var(--red-soft); color: var(--red); }

.sentiment-bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--border);
  margin-bottom: 14px;
}
.sentiment-bar .seg-pos { background: var(--green); }
.sentiment-bar .seg-neu { background: var(--text-faint); }
.sentiment-bar .seg-neg { background: var(--red); }

.ai-report {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  white-space: pre-wrap;
  font-size: 13.5px;
  line-height: 1.65;
}

/* ---------- Comments Explorer ---------- */
.comments-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-bottom: 12px;
}
.comment-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filter-chip {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.comment-card {
  border-left: 3px solid var(--border-strong);
  padding: 10px 14px;
  margin: 10px 0;
  background: var(--surface-soft);
  border-radius: 0 10px 10px 0;
}
.comment-card.s-pos { border-left-color: var(--green); }
.comment-card.s-neg { border-left-color: var(--red); }
.comment-card .who { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.comment-card .who a { color: var(--text); text-decoration: none; }
.comment-card .who a:hover { color: var(--accent); text-decoration: underline; }
.comment-card .meta { color: var(--text-faint); font-size: 11.5px; margin-top: 6px; }
.comment-card .replies { margin-top: 10px; padding-left: 10px; }

.sent-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
}
.sent-badge.pos { background: var(--green-soft); color: var(--green); }
.sent-badge.neu { background: var(--border); color: var(--text-muted); }
.sent-badge.neg { background: var(--red-soft); color: var(--red); }

/* ---------- Library Grid ---------- */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.14s, border-color 0.14s;
}
.post-card:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.post-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.post-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.post-snippet {
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 20px;
}
.post-metrics { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.post-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }

.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

/* ---------- Modal, Floating Selection & Toast ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(820px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body pre {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
}

.selection-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 140;
  box-shadow: var(--shadow);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: var(--shadow);
}
.toast.error { border-color: var(--red); color: var(--red); }

.loading-row { display: flex; align-items: center; gap: 10px; color: var(--text-muted); padding: 12px 0; }
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Admin Table ---------- */
.jobs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.jobs-table th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.jobs-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.jobs-table tbody tr:last-child td { border-bottom: none; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
}
