/* === Social Master Dashboard — Light Theme === */
:root {
  --bg: #f8f9fb;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f9;
  --border: #e2e5ee;
  --text: #1a1d26;
  --text-dim: #6b7280;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99,102,241,0.08);
  --success: #16a34a;
  --success-light: rgba(22,163,74,0.08);
  --warning: #d97706;
  --warning-light: rgba(217,119,6,0.08);
  --danger: #dc2626;
  --danger-light: rgba(220,38,38,0.08);
  --info: #2563eb;
  --info-light: rgba(37,99,235,0.08);
  --sidebar-w: 230px;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  padding: 22px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.version {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 500;
  border: 1px solid var(--border);
}

/* === Sidebar User === */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-credits {
  font-size: 11.5px;
  color: var(--text-dim);
  font-weight: 500;
}

.badge-admin {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: white;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 14px;
  list-style: none;
}

.nav-links {
  list-style: none;
  padding: 14px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.nav-links a:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-links a.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 3px rgba(99,102,241,0.3);
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
}

.meta-auth-btn {
  display: block;
  text-align: center;
  padding: 9px;
  background: var(--bg);
  color: var(--text-dim);
  text-decoration: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.meta-auth-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* === Content === */
.content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 36px;
  min-height: 100vh;
  max-width: 1200px;
  width: 100%;
  overflow-x: hidden;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* === Stats Cards === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.stat-card:hover { box-shadow: var(--shadow); }

.stat-card .stat-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.5px;
}

.stat-card .stat-label {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 6px;
  font-weight: 500;
}

.stat-card.success .stat-value { color: var(--success); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.info .stat-value { color: var(--info); }

/* === Tables === */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.table-wrap h3 {
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.2px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

tr:hover { background: var(--bg-hover); }
tr:last-child td { border-bottom: none; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-completed, .badge-success { background: var(--success-light); color: var(--success); }
.badge-failed, .badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-queued, .badge-info { background: var(--info-light); color: var(--info); }
.badge-running, .badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-carousel { background: var(--accent-light); color: var(--accent); }
.badge-story { background: rgba(168,85,247,0.08); color: #7c3aed; }
.badge-reel { background: rgba(236,72,153,0.08); color: #db2777; }
.badge-post { background: rgba(20,184,166,0.08); color: #0d9488; }
.badge-fb_post { background: rgba(37,99,235,0.08); color: #1d4ed8; }
.badge-base { background: var(--info-light); color: var(--info); }
.badge-wrapper { background: rgba(168,85,247,0.08); color: #7c3aed; }
.badge-orchestrator { background: var(--warning-light); color: var(--warning); }

/* === Brand colors === */
.brand-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  background: var(--bg-hover);
  border-color: #ccd0da;
  box-shadow: var(--shadow);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 1px 3px rgba(99,102,241,0.25);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 6px rgba(99,102,241,0.3);
}

.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-trigger {
  background: var(--success-light);
  border-color: rgba(22,163,74,0.3);
  color: var(--success);
}

.btn-trigger:hover {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

/* === Toggle === */
.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  appearance: none;
  background: #d1d5db;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle:checked { background: var(--success); }

.toggle::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle:checked::before { transform: translateX(16px); }

/* === Textarea (prompts) === */
.prompt-editor {
  width: 100%;
  min-height: 200px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 14px;
  resize: vertical;
  line-height: 1.7;
}

.prompt-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

/* === Forms === */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-dim);
}

.form-group input, .form-group select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

/* === Color preview === */
.color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  border: 1px solid var(--border);
  vertical-align: middle;
  margin-right: 4px;
  box-shadow: var(--shadow-sm);
}

/* === Detail page === */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.detail-card h4 {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
  font-weight: 600;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.kv-row:last-child { border-bottom: none; }
.kv-label { color: var(--text-dim); }
.kv-value { font-weight: 600; }

/* === Pill list === */
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  display: inline-block;
  padding: 4px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

/* === Empty state === */
.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-dim);
  font-size: 14px;
}

/* === Jobs Tabs === */
.jobs-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}

.jobs-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  border-radius: 8px 8px 0 0;
}

.jobs-tab:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.jobs-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-light);
}

.jobs-tab-count {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.jobs-tab-count.running { background: var(--warning-light); color: var(--warning); }
.jobs-tab-count.success { background: var(--success-light); color: var(--success); }
.jobs-tab-count.danger { background: var(--danger-light); color: var(--danger); }

/* === Brand Widget Cards === */
.brand-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 28px; }
.brand-widget {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 20px;
  box-shadow: var(--shadow-sm); transition: all 0.2s ease; text-decoration: none; color: var(--text); display: block;
}
.brand-widget:hover { border-color: var(--accent); box-shadow: 0 4px 16px rgba(99,102,241,0.1); }
.brand-widget-header { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.brand-widget-avatar { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); }
.brand-widget-meta h3 { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.brand-widget-meta .brand-widget-category { font-size: 12px; color: var(--text-dim); }
.brand-widget-ig {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
  color: white; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; margin-top: 6px;
}
.brand-widget-ig img { width: 16px; height: 16px; border-radius: 50%; }
.brand-widget-stats { display: flex; gap: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.brand-widget-stat { display: flex; flex-direction: column; align-items: center; flex: 1; }
.brand-widget-stat-value { font-size: 16px; font-weight: 700; }
.brand-widget-stat-label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.3px; }
.brand-widget-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }

/* === Responsive === */
/* Job action buttons */
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-trigger { background: var(--accent-light); color: var(--accent); }
.btn-trigger:hover { background: var(--accent); color: white; }

/* SSE live update flash */
@keyframes jobFlash {
  0% { background-color: rgba(99,102,241,0.15); }
  100% { background-color: transparent; }
}
tr.job-updated { animation: jobFlash 2s ease-out; }

/* Live indicator */
.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #16a34a; margin-right: 6px; animation: livePulse 2s infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Icon buttons */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  vertical-align: middle;
}
.icon-btn svg { vertical-align: middle; }

/* Lucide nav icons */
.nav-icon i, .nav-icon svg { width: 16px; height: 16px; }

/* Spinning loader icon */
@keyframes iconSpin { to { transform: rotate(360deg); } }
.icon-spin { animation: iconSpin 0.8s linear infinite; display: inline-flex; }

/* === Mobile Top Bar === */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 200;
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.mobile-topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.mobile-topbar-logo svg { width: 18px; height: 18px; color: var(--accent); }

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

.mobile-topbar-credits {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 4px 10px;
  border-radius: 20px;
}

.mobile-topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  object-fit: cover;
}

/* === Mobile Bottom Nav — Scrollable horizontal === */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 200;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-scroll {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  height: 64px;
  padding: 0 8px;
  gap: 0;
}

.bottom-nav-scroll::-webkit-scrollbar { display: none; }

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-dim);
  font-size: 9.5px;
  font-weight: 500;
  padding: 8px 12px;
  flex-shrink: 0;
  scroll-snap-align: center;
  transition: all 0.15s;
  position: relative;
  min-width: 64px;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item i,
.bottom-nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.bottom-nav-item.active {
  color: var(--accent);
  font-weight: 600;
}

.bottom-nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 2.5px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

.bottom-nav-item:active {
  transform: scale(0.9);
  opacity: 0.7;
}

.bottom-nav-sep {
  width: 1px;
  background: var(--border);
  margin: 14px 0;
  flex-shrink: 0;
}

.bottom-nav-item.danger { color: var(--danger); }

/* Scroll hint — fading edges */
.bottom-nav::before,
.bottom-nav::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  z-index: 1;
  pointer-events: none;
}

.bottom-nav::before {
  left: 0;
  background: linear-gradient(to right, var(--bg-card), transparent);
}

.bottom-nav::after {
  right: 0;
  background: linear-gradient(to left, var(--bg-card), transparent);
}

@media (max-width: 768px) {
  html, body { overflow-x: hidden; max-width: 100vw; }

  .sidebar { display: none; }
  .mobile-topbar { display: flex; }
  .bottom-nav { display: block; }

  body { padding-bottom: 0; }

  .content {
    margin-left: 0;
    padding: 14px;
    padding-top: 68px;
    padding-bottom: 80px;
    min-height: 100vh;
    max-width: 100vw;
    width: 100%;
    box-sizing: border-box;
  }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .detail-grid { grid-template-columns: 1fr; }
  .brand-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 16px; }
  .page-header h2 { font-size: 18px; }
  .page-header .btn,
  .page-header a.btn { width: 100%; justify-content: center; text-align: center; }
  .page-header select { width: 100%; }
  .page-header > div { display: flex; gap: 8px; width: 100%; }
  .page-header > div > * { flex: 1; }
  table { font-size: 11px; }
  th, td { padding: 7px 8px; white-space: nowrap; }
  .btn { font-size: 12px; padding: 6px 10px; }
  .stat-card { padding: 12px 14px; }
  .stat-card .stat-value { font-size: 20px; }
  .stat-card .stat-label { font-size: 10px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  .brand-widget { padding: 14px; }
  .brand-widget-header { gap: 10px; }
  .brand-widget-avatar { width: 38px; height: 38px; }
  .brand-widget-stats { gap: 8px; }
  .brand-widget-stat-value { font-size: 14px; }
  .brand-widget-stat-label { font-size: 9px; }
  .kv-row { font-size: 12px; flex-wrap: wrap; gap: 4px; }
  .detail-card { padding: 14px; }
  .detail-card h4 { font-size: 11px; margin-bottom: 10px; }
  .pill { font-size: 11px; padding: 3px 8px; }
  .prompt-editor { font-size: 12px; min-height: 140px; padding: 10px; }
  .jobs-tabs { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .jobs-tabs::-webkit-scrollbar { display: none; }
  .jobs-tab { padding: 8px 12px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }

  .wa-widget {
    right: 12px;
    top: auto;
    bottom: 80px;
    transform: none;
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }
  .wa-widget:hover { transform: scale(1.05); }
  .wa-glow { border-radius: 15px; }
  .wa-glow::after { border-radius: 12px; }
}
