/* === JS Agency — Dashboard Theme === */

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

:root {
  --bg: #0b0e14;
  --sidebar-bg: #0f1219;
  --surface: #131720;
  --surface2: #1a1f2e;
  --surface3: #212736;
  --border: #1e2433;
  --border2: #2a3144;
  --text: #d0d5e3;
  --text-dim: #6b7280;
  --text-muted: #4b5060;
  --accent: #22d3ee;
  --accent2: #6366f1;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --pink: #ec4899;
  --blue: #3b82f6;
  --orange: #f97316;
  --cyan: #22d3ee;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --radius: 12px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

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

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

.logo-icon svg { width: 30px; height: 30px; }

.logo-text {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav {
  padding: 12px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.nav-item:hover { color: var(--text); background: var(--surface2); }

.nav-item.active {
  color: var(--accent);
  background: rgba(34, 211, 238, 0.08);
}

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

.sidebar-section-title {
  padding: 16px 18px 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.sidebar-agents {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px;
}

.sidebar-agent {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: default;
  transition: background 0.15s;
}

.sidebar-agent:hover { background: var(--surface2); }

.agent-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.agent-avatar.researcher { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.agent-avatar.writer { background: linear-gradient(135deg, #ec4899, #f43f5e); }
.agent-avatar.seo { background: linear-gradient(135deg, #10b981, #22d3ee); }

.sidebar-agent-name { font-size: 13px; font-weight: 500; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-green { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.dot-red { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot-gray { background: #4b5060; }

.sidebar-agent .status-dot { margin-left: auto; }

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

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.logout-btn:hover { border-color: var(--red); color: var(--red); }

/* === Main === */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === Topbar === */
.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
}

.page-title { font-size: 14px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; }

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

.gateway-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
}

.topbar-user { color: var(--text-dim); font-size: 12px; }

/* === Content === */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.page { display: none; }
.page.active { display: block; }

/* === Stat Cards === */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.agents { background: rgba(99,102,241,0.15); }
.stat-icon.tasks { background: rgba(34,211,238,0.15); }
.stat-icon.done { background: rgba(16,185,129,0.15); }
.stat-icon.dlq { background: rgba(239,68,68,0.15); }

.stat-info .stat-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
}

.stat-info .stat-value span { font-size: 14px; font-weight: 400; color: var(--text-dim); }
.stat-info .stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }

/* === QG Grid === */
.qg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card h3 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-icon { font-size: 15px; }

/* === Activity Feed === */
.activity-feed { max-height: 320px; overflow-y: auto; }

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.activity-dot.check { background: var(--green); }
.activity-dot.alert { background: var(--red); }
.activity-dot.info { background: var(--accent); }
.activity-dot.warning { background: var(--yellow); }

.activity-agent { font-weight: 700; color: var(--accent); margin-right: 4px; }
.activity-time { color: var(--text-muted); margin-left: auto; white-space: nowrap; font-size: 11px; }

.activity-text { flex: 1; color: var(--text-dim); line-height: 1.4; }

.empty-state { color: var(--text-muted); text-align: center; padding: 32px 16px; font-size: 13px; }

/* === Agent Status Grid (QG) === */
.agent-status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.agent-status-card {
  background: var(--surface2);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-status-card .agent-avatar { width: 36px; height: 36px; font-size: 14px; }
.agent-status-card .agent-info { flex: 1; }
.agent-status-card .agent-name { font-weight: 700; font-size: 13px; }

.agent-status-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.agent-status-label.idle { color: var(--yellow); }
.agent-status-label.busy { color: var(--green); }
.agent-status-label.error { color: var(--red); }
.agent-status-label.operational { color: var(--green); }

/* === Crew Grid (Agent Cards) === */
.section-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 20px;
  color: var(--text);
}

.crew-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
}

.crew-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.crew-card-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.crew-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.crew-avatar.researcher { background: linear-gradient(135deg, #6366f1, #8b5cf6); border-color: #6366f1; }
.crew-avatar.writer { background: linear-gradient(135deg, #ec4899, #f43f5e); border-color: #ec4899; }
.crew-avatar.seo { background: linear-gradient(135deg, #10b981, #22d3ee); border-color: #10b981; }

.crew-info { flex: 1; }
.crew-name { font-size: 18px; font-weight: 800; }
.crew-role { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.crew-status-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.crew-skills { margin-bottom: 16px; }

.skill-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.skill-label { width: 120px; font-size: 12px; color: var(--text-dim); }

.skill-bar {
  flex: 1;
  height: 6px;
  background: var(--surface3);
  border-radius: 3px;
  overflow: hidden;
}

.skill-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }

.skill-bar-fill.purple { background: linear-gradient(90deg, #6366f1, #8b5cf6); }
.skill-bar-fill.pink { background: linear-gradient(90deg, #ec4899, #f43f5e); }
.skill-bar-fill.cyan { background: linear-gradient(90deg, #22d3ee, #10b981); }
.skill-bar-fill.yellow { background: linear-gradient(90deg, #f59e0b, #f97316); }
.skill-bar-fill.red { background: linear-gradient(90deg, #ef4444, #ec4899); }

.skill-pct { font-size: 12px; font-weight: 600; color: var(--text-dim); width: 35px; text-align: right; }

.crew-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.crew-stat { display: flex; gap: 16px; }
.crew-stat span { display: flex; align-items: center; gap: 4px; }

.crew-provider {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--surface3);
  color: var(--text-dim);
  font-weight: 600;
}

/* === Data Tables === */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.015); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-DONE, .badge-idle { background: rgba(16,185,129,0.12); color: var(--green); }
.badge-PENDING, .badge-QUEUED { background: rgba(59,130,246,0.12); color: var(--blue); }
.badge-RUNNING, .badge-busy { background: rgba(99,102,241,0.12); color: var(--accent2); }
.badge-FAILED, .badge-error { background: rgba(239,68,68,0.12); color: var(--red); }
.badge-RETRY { background: rgba(245,158,11,0.12); color: var(--yellow); }

.id-cell {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Consolas', monospace;
}

.error-preview {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--red);
  font-size: 11px;
}

/* === Pipeline Cards === */
.pipeline-cards { display: flex; flex-wrap: wrap; gap: 16px; }

.pipeline-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 280px;
  max-width: 400px;
}

.pipeline-card h4 { font-size: 14px; font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.pipeline-card p { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; line-height: 1.4; }
.pipeline-card .steps { font-size: 11px; color: var(--text-muted); }

.cron-schedule {
  font-size: 11px;
  font-family: 'SF Mono', 'Consolas', monospace;
  color: var(--cyan);
}

/* === Buttons === */
.btn-sm {
  padding: 6px 14px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-sm:hover { border-color: var(--accent); color: var(--accent); }

.btn-accent {
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-accent:hover { opacity: 0.9; }

.btn-danger {
  padding: 6px 12px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 6px;
  color: var(--red);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-retry {
  padding: 6px 12px;
  background: rgba(16,185,129,0.12);
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: 6px;
  color: var(--green);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

.btn-retry:hover { background: rgba(16,185,129,0.2); }

/* === Forms === */
.form-field { margin-bottom: 14px; }
.form-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

select, textarea, input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

select:focus, textarea:focus, input:focus { border-color: var(--accent); }
textarea { resize: vertical; }

/* === Activity Full === */
.activity-full { max-height: calc(100vh - 160px); overflow-y: auto; }

.activity-full .activity-item { padding: 12px 0; }
.activity-full .activity-text { font-size: 13px; }

/* === Logs === */
.log-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  font-size: 11px;
  font-family: 'SF Mono', 'Consolas', monospace;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
}

/* === Page toolbar === */
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* === Providers in QG === */
.provider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.provider-row:last-child { border-bottom: none; }
.provider-name { font-weight: 700; flex: 1; }
.provider-type { color: var(--text-muted); font-size: 11px; }

.provider-key-ok { color: var(--green); font-size: 10px; font-weight: 700; }
.provider-key-missing { color: var(--red); font-size: 10px; font-weight: 700; }

/* === Toasts === */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 12px;
  animation: fadeSlideIn 0.25s ease;
  max-width: 360px;
  border-left: 3px solid var(--accent);
}

.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--yellow); }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Irving Agent Avatar === */
.agent-avatar.irving { background: linear-gradient(135deg, #f59e0b, #f97316); }
.crew-avatar.irving { background: linear-gradient(135deg, #f59e0b, #f97316); border-color: #f59e0b; }

/* === Pipeline Version === */
.pipeline-version { font-size: 10px; color: var(--accent); margin-top: 6px; }

/* === Chat === */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-agent-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.chat-agent-selector select {
  width: auto;
  min-width: 200px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-welcome {
  color: var(--text-muted);
  text-align: center;
  padding: 60px 20px;
  font-size: 14px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.chat-msg.user { align-self: flex-end; }
.chat-msg.agent { align-self: flex-start; }

.chat-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.agent {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-bubble.error { color: var(--red); }

.chat-input-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

.chat-input-form input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.chat-input-form input:focus { border-color: var(--accent); }

/* === Knowledge Base === */
.kb-search-bar { display: flex; align-items: center; }
.kb-search-bar input { width: 260px; }

.kb-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  height: calc(100vh - 160px);
}

.kb-file-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  padding: 8px;
}

.kb-file-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-dim);
  transition: all 0.15s;
  border-bottom: 1px solid var(--border);
}

.kb-file-item:hover { background: var(--surface2); color: var(--text); }
.kb-file-item:last-child { border-bottom: none; }

.kb-snippet {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kb-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kb-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

.kb-filename {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  font-family: 'SF Mono', 'Consolas', monospace;
}

.kb-textarea {
  flex: 1;
  width: 100%;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  border: none;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  resize: none;
  outline: none;
}

/* === Responsive === */
@media (max-width: 900px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .qg-grid { grid-template-columns: 1fr; }
  .crew-grid { grid-template-columns: 1fr; }
}
