:root {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --bg-soft: #f7f7fa;
  --sidebar-bg: #fbfbfd;
  --border: #ececf0;
  --text: #1a1a1f;
  --text-muted: #6b6b78;
  --primary: #7c3aed;
  --primary-2: #a855f7;
  --primary-soft: #f3eaff;
  --primary-text: #6d28d9;
  --info-soft: #e0f0ff;
  --info-text: #2563eb;
  --info-dot: #3b82f6;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .12);
  --radius: 14px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #0f1014;
  --bg-elev: #16181f;
  --bg-soft: #1b1d26;
  --sidebar-bg: #121319;
  --border: #2a2c36;
  --text: #ececf1;
  --text-muted: #9a9aa6;
  --primary-soft: #2a1f47;
  --primary-text: #c4b5fd;
  --info-soft: #1e293b;
  --info-text: #93c5fd;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 18px;
}
.brand-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  object-fit: cover;
  background: #000;
  box-shadow: 0 6px 14px rgba(59, 130, 246, .25), 0 0 0 1px var(--border);
  display: block;
}
.brand-title { font-weight: 700; font-size: 14px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg-soft); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary-text);
}
.nav-icon { width: 20px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.footer-btn {
  display: flex; align-items: center; gap: 8px;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  text-align: left;
}
.footer-btn:hover { background: var(--bg-soft); }

/* Main */
.main {
  padding: 36px 48px;
  max-width: 1200px;
  width: 100%;
}
.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 24px;
  margin-bottom: 22px;
}
.page-title {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  background: linear-gradient(90deg, #7c3aed, #a855f7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.page-sub {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 13px;
  transition: transform .05s, background .15s, box-shadow .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: #fff;
  box-shadow: 0 6px 16px rgba(124, 58, 237, .35);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost {
  background: var(--bg-elev);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-soft); }
.icon-btn {
  background: transparent; border: 0; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 8px;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

/* Tabs */
.tabs {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 18px;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
}
.tab-count {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  min-width: 22px;
  text-align: center;
}
.tab.active .tab-count {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary-text);
}

/* Panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}

/* Job card */
.job-list { display: flex; flex-direction: column; gap: 10px; }
.job-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .05s;
}
.job-card:hover { box-shadow: var(--shadow-lg); }
.job-row-1 {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.job-title-wrap {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--info-dot);
  display: inline-block;
}
.status-dot.running { background: var(--success); animation: pulse 1.2s infinite; }
.status-dot.paused { background: var(--info-dot); }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(22,163,74,.5); }
  50%     { box-shadow: 0 0 0 6px rgba(22,163,74,0); }
}
.job-name { font-weight: 700; font-size: 15px; }
.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--info-text);
  text-transform: uppercase;
}
.badge.running { background: #dcfce7; color: #166534; }
.job-status-text { color: var(--text-muted); font-size: 13px; }

.job-metrics {
  display: flex; gap: 18px;
  color: var(--text-muted); font-size: 13px;
}
.job-metrics b { color: var(--text); margin-left: 4px; font-weight: 700; }

.job-row-2 {
  margin-top: 8px;
  display: flex; gap: 6px; align-items: center;
  color: var(--text-muted); font-size: 13px;
}
.job-row-2 .sep { opacity: .5; }

.job-row-3 {
  margin-top: 10px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.job-meta {
  color: var(--text-muted); font-size: 13px;
  display: flex; gap: 14px; flex-wrap: wrap;
}
.job-meta b { color: var(--text); font-weight: 700; }
.job-actions { display: flex; align-items: center; gap: 6px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}
.empty-emoji { font-size: 36px; margin-bottom: 8px; }
.empty-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-label { color: var(--text-muted); font-size: 13px; }
.stat-value {
  font-size: 28px; font-weight: 800;
  margin-top: 4px;
}

/* Card */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card:last-child { margin-bottom: 0; }
.card-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
.card-desc { margin: 0 0 14px; font-size: 13px; }
.form-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.form-row:last-child { border-bottom: 0; }

/* Connection (FB/IG) */
.connect-card { margin-bottom: 18px; }

.conn-summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
  padding: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-wrap: wrap;
}
.conn-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.conn-pages-wrap { margin-top: 14px; }
.link { color: var(--primary-text); text-decoration: underline; }
.conn-user { display: flex; align-items: center; gap: 12px; }
.conn-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--border);
  object-fit: cover;
  flex: 0 0 auto;
}
.conn-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 0 10px;
  flex-wrap: wrap; gap: 8px;
}
.conn-section-title {
  margin: 0; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.badge-count {
  background: var(--primary-soft);
  color: var(--primary-text);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
}
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.page-list { display: flex; flex-direction: column; gap: 10px; }
.page-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
}
.page-row {
  display: flex; align-items: center; gap: 12px;
}
.page-pic {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--border);
  object-fit: cover;
  flex: 0 0 auto;
}
.page-info { flex: 1; min-width: 0; }
.page-info .row-title { font-size: 14px; }
.page-info .muted { font-size: 12px; }

.ig-line {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(135deg, rgba(245,133,41,.06), rgba(221,42,123,.06), rgba(129,52,175,.06));
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}
.ig-line .ic-ig { width: 22px; height: 22px; font-size: 13px; }
.ig-meta { color: var(--text-muted); font-size: 12px; }

.no-ig {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* Modal */
.modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 16, 20, .45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(440px, 92vw);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-card-lg {
  width: min(640px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.modal-body {
  padding: 18px 22px 22px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field-label { font-weight: 600; color: var(--text); }
.field-label .req { color: var(--danger); font-style: normal; }
.field-hint { color: var(--text-muted); font-size: 12px; }
.hint-green { color: #16a34a; }
.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent-blue, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 4px;
}
.sticky-actions {
  position: sticky;
  bottom: -22px;
  background: var(--bg-elev);
  margin: 4px -22px -22px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

/* Segmented buttons */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}
.seg-btn {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}
.seg-btn:hover { background: var(--bg-soft); }
.seg-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .25);
}
.seg-green .seg-btn.active {
  background: #16a34a;
  border-color: #16a34a;
  box-shadow: 0 4px 12px rgba(22, 163, 74, .25);
}

/* Chips (small pill toggle) */
.chips { display: inline-flex; gap: 6px; }
.chip {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.chip:hover { background: var(--bg); color: var(--text); }
.chip.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

/* Card-like grouped fields */
.card-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,.03);
  display: flex; flex-direction: column; gap: 10px;
}
.section-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.section-icon { display: inline-grid; place-items: center; }
.section-icon.shield { color: #16a34a; }
.section-icon.shop { color: #7c3aed; }

.row-toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.row-bare { padding: 4px 2px; background: transparent; border: 0; box-shadow: none; }
.row-title { font-weight: 600; }
.row-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.row-between {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap;
}

/* Toggle switch */
.switch {
  position: relative; display: inline-block;
  width: 42px; height: 24px;
  flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background .2s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
  transition: transform .2s;
}
.switch input:checked + .switch-slider { background: #2563eb; }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }

/* Grid 2-cols */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* Platform checks */
.checks { display: flex; gap: 16px; flex-wrap: wrap; padding-top: 4px; }
.check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer;
  user-select: none;
}
.check input[type="checkbox"] {
  width: 16px; height: 16px; accent-color: #2563eb;
}
.ic {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px;
  border-radius: 4px;
  font-size: 11px; font-weight: 700;
  color: #fff;
}
.ic-fb { background: #1877f2; }
.ic-ig { background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af); }
.ic-yt { background: #ff0000; }

/* Blue primary button (modal) */
.btn-blue {
  background: #2563eb;
  color: #fff;
  border: 1px solid #2563eb;
  box-shadow: 0 6px 16px rgba(37, 99, 235, .3);
}
.btn-blue:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-block { width: 100%; padding: 12px 16px; font-size: 14px; }
.btn-lg { padding: 12px 18px; font-size: 14px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  z-index: 60;
  opacity: 0;
  transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* Responsive */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px; }
  .sidebar .nav { flex-direction: row; flex: 1; justify-content: center; }
  .sidebar-footer { flex-direction: row; border-top: 0; padding-top: 0; margin: 0 0 0 auto; }
  .brand-text { display: none; }
  .main { padding: 20px; }
  .page-header { flex-direction: column; align-items: stretch; }
  .page-title { font-size: 24px; }
  .job-row-1, .job-row-3 { flex-wrap: wrap; }
}
