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

:root {
  --bg: #0b0e14;
  --bg2: #151921;
  --bg3: #1c222c;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #f8fafc;
  --text-dim: #94a3b8;
  --muted: #64748b;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #f59e0b;
  --blue: #3b82f6;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.2);
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --radius: 12px;
}

body { 
  background: var(--bg); 
  color: var(--text); 
  font-family: 'Inter', system-ui, -apple-system, sans-serif; 
  font-size: 14px; 
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Header (UX fix: sticky, brand responsive, hide refresh on mobile) ── */
header {
  background: rgba(21, 25, 33, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky; top: 0; z-index: 100;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; max-width: 1400px; margin: 0 auto; }
.header-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 22px; line-height: 1; }
.brand-sub { font-size: 11px; color: var(--muted); font-weight: 500; display: block; margin-top: 1px; }
header h1 { 
  font-size: 17px; 
  font-weight: 800; 
  letter-spacing: -0.5px; 
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-meta { display: flex; align-items: center; gap: 12px; }
.status-pill { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px; }
.status-pill.online { background: rgba(16,185,129,0.15); color: var(--green); border: 1px solid rgba(16,185,129,0.3); }
.refresh-time { color: var(--muted); font-size: 11px; }

/* ── Layout ── */
main { 
  max-width: 1400px; 
  margin: 0 auto; 
  padding: 28px 24px; 
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Grid 2-col → stack mobile (UX fix #1) ── */
.grid-2 { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 20px; 
}

/* ── Cards ── */
.card { 
  background: var(--bg2); 
  border: 1px solid var(--border); 
  border-radius: var(--radius); 
  padding: 22px; 
  box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.card-header h2 { 
  font-size: 11px; 
  font-weight: 700; 
  color: var(--muted); 
  text-transform: uppercase; 
  letter-spacing: 1px; 
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.icon { font-size: 14px; }
.card-badge { 
  font-size: 11px; font-weight: 600; 
  background: var(--bg3); color: var(--muted); 
  padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border);
  white-space: nowrap; flex-shrink: 0;
}

.loading, .empty { color: var(--muted); font-size: 13px; padding: 16px 0; text-align: center; font-style: italic; }

/* ── Agent Status ── */
.agent-grid { display: flex; flex-direction: column; gap: 10px; }
.agent-card { padding: 14px 16px; background: var(--bg3); border-radius: 10px; border: 1px solid var(--border); transition: border-color 0.2s; }
.agent-card.agent-active { border-color: rgba(99,102,241,0.35); }
.agent-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.agent-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.agent-dot.dot-green { background: var(--green); }
.agent-dot.dot-grey { background: var(--muted); }
.agent-dot.dot-red { background: var(--red); }
@keyframes pulse-shadow { 
  0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.6); }
  70% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
.agent-dot.dot-green { animation: pulse-shadow 2s infinite; }
.agent-name { font-weight: 700; font-size: 14px; flex: 1; color: var(--text); }
.agent-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.agent-preview { font-size: 12px; color: var(--text-dim); line-height: 1.5; padding-left: 16px; }

/* ── Task Queue (UX fix #4: touch targets 44px) ── */
.task-row { 
  padding: 12px 14px; 
  border-radius: 10px; 
  border: 1px solid var(--border); 
  margin-bottom: 10px; 
  background: var(--bg3); 
}
.task-info { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.task-id { font-family: monospace; font-size: 11px; color: var(--muted); background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.task-title { font-weight: 600; color: var(--text); flex: 1; min-width: 120px; }
.task-assignee { 
  font-size: 11px; font-weight: 600; color: var(--accent); 
  background: var(--accent-glow); 
  padding: 3px 10px; border-radius: 6px; 
}
/* UX fix #4: buttons 44px touch target, full-width stack mobile */
.task-actions { display: flex; gap: 10px; margin-top: 10px; }
.btn-approve, .btn-reject { 
  border: none;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 8px; 
  font-size: 13px; font-weight: 700; cursor: pointer; 
  transition: all 0.2s ease;
  flex: 1;
}
.btn-approve { background: var(--green); color: #062016; }
.btn-approve:hover { filter: brightness(1.1); }
.btn-reject { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.btn-reject:hover { background: var(--red); color: white; }
.btn-approve:disabled, .btn-reject:disabled { opacity: 0.5; cursor: not-allowed; }

/* Badges */
.badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.badge-green { background: rgba(16,185,129,0.15); color: var(--green); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-blue { background: rgba(59,130,246,0.15); color: var(--blue); }

/* ── Daily Report (UX fix #2: max-width 860px, typography) ── */
.report-body { 
  line-height: 1.8; 
  color: var(--text-dim); 
  max-width: 860px;
  margin: 0 auto;
  font-size: 15px;
}
.report-body h1, .report-body h2, .report-body h3 { 
  margin: 1.8em 0 0.7em; font-weight: 700; color: var(--text); 
  display: flex; align-items: center; gap: 8px;
}
.report-body h1 { font-size: 18px; }
.report-body h2 { font-size: 15px; }
.report-body h2::before { content: '#'; color: var(--accent); opacity: 0.5; }
.report-body h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.report-body p { margin-bottom: 12px; }
.report-body ul, .report-body ol { padding-left: 24px; margin-bottom: 16px; }
.report-body li { margin-bottom: 6px; }
.report-body code { 
  background: var(--bg3); 
  padding: 2px 6px; border-radius: 5px; 
  font-size: 13px; font-family: 'JetBrains Mono', monospace; 
  color: var(--yellow); border: 1px solid var(--border);
}
.report-body pre { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; margin-bottom: 16px; }
.report-body pre code { background: none; border: none; padding: 0; }
.report-body table { width: 100%; border-collapse: collapse; margin-bottom: 16px; overflow-x: auto; display: block; }
.report-body th, .report-body td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; font-size: 13px; }
.report-body th { background: var(--bg3); color: var(--text); font-weight: 600; }

/* ── Lab Status (UX fix #3: overflow-x auto) ── */
.lab-table { display: flex; flex-direction: column; gap: 8px; }
.lab-row { 
  display: flex; align-items: center; gap: 14px; 
  padding: 12px 16px; border-radius: 10px; 
  background: var(--bg3); border: 1px solid var(--border); 
  overflow-x: auto;
  min-width: 0;
}
.lab-name { font-weight: 600; flex: 1; color: var(--text); min-width: 0; white-space: nowrap; }
.lab-mem { font-family: monospace; color: var(--blue); font-size: 12px; white-space: nowrap; }
.lab-restart { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ── Sessions + Knowledge (UX fix #5: auto-fill grid, click affordance) ── */
.session-grid { 
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); 
  gap: 14px; 
}
/* UX fix #5: click affordance — arrow indicator */
.session-card, .knowledge-card { 
  position: relative;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); 
  padding: 18px; cursor: pointer; transition: all 0.2s ease;
  display: flex; flex-direction: column; gap: 6px;
}
.session-card::after, .knowledge-card::after {
  content: '→';
  position: absolute;
  bottom: 14px; right: 16px;
  font-size: 14px;
  color: var(--muted);
  transition: all 0.2s;
}
.session-card:hover, .knowledge-card:hover { 
  border-color: var(--accent); 
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}
.session-card:hover::after, .knowledge-card:hover::after {
  color: var(--accent);
  transform: translateX(3px);
}
.session-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.session-icon { font-size: 20px; }
.session-card .session-date { font-size: 11px; color: var(--muted); }
.session-card .session-name { font-size: 10px; color: var(--muted); font-family: monospace; letter-spacing: 0.5px; }
.session-card .session-title { font-weight: 600; font-size: 14px; line-height: 1.4; }
.session-card .session-summary { font-size: 12px; color: var(--text-dim); line-height: 1.5; }

/* Knowledge cards */
.knowledge-grid { 
  display: grid; 
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); 
  gap: 12px; 
}
.knowledge-icon { font-size: 22px; }
.knowledge-title { font-weight: 700; font-size: 13px; color: var(--text); line-height: 1.3; }
.knowledge-meta { font-size: 11px; color: var(--muted); margin-top: auto; padding-top: 8px; }

/* Session viewer nav */
.session-nav { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.btn-back { 
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text-dim); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-back:hover { color: var(--text); border-color: var(--accent); }
.session-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.session-tab { 
  min-height: 44px; padding: 0 18px;
  border-radius: 8px; border: 1px solid var(--border); 
  background: var(--bg2); color: var(--muted); 
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s ease;
  white-space: nowrap;
}
.session-tab:hover { border-color: var(--border-strong); color: var(--text); }
.session-tab.active { 
  background: var(--accent); color: white; border-color: var(--accent); 
  box-shadow: 0 4px 12px var(--accent-glow);
}

/* ── Responsive — tablet (768px) ── */
@media (max-width: 768px) {
  /* UX fix #1: grid-2 → stack */
  .grid-2 { grid-template-columns: 1fr; gap: 16px; }
  
  main { padding: 16px; gap: 16px; }
  
  /* header: ẩn brand-sub và refresh-time (UX fix #7) */
  .brand-sub { display: none; }
  .refresh-time { display: none; }
  
  /* report max-width reset */
  .report-body { max-width: 100%; font-size: 14px; }
  
  /* task actions: full width stack */
  .task-actions { flex-direction: column; gap: 8px; }
  
  /* session / knowledge grid: 2 col */
  .session-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* ── Responsive — mobile (480px) ── */
@media (max-width: 480px) {
  header { padding: 10px 14px; }
  .brand-icon { font-size: 18px; }
  header h1 { font-size: 15px; }
  
  main { padding: 12px; gap: 12px; }
  .card { padding: 16px; }
  
  /* session / knowledge: 1 col */
  .session-grid { grid-template-columns: 1fr; }
  .knowledge-grid { grid-template-columns: 1fr 1fr; }
  
  /* task: stagger buttons */
  .task-info { flex-direction: column; align-items: flex-start; }
}

/* ── Live Chat section ── */
.btn-start-chat {
  min-height: 32px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent-glow); color: var(--accent);
  font-size: 12px; font-weight: 700; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.btn-start-chat:hover { background: var(--accent); color: white; }

#chat-topic-input:focus { border-color: var(--accent); }

.chat-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.chat-live-content {
  max-height: 600px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Running session: green border pulse */
.session-card:has(.dot-green) {
  border-color: rgba(99,102,241,0.4);
  animation: card-pulse 3s ease-in-out infinite;
}
@keyframes card-pulse {
  0%, 100% { border-color: rgba(99,102,241,0.2); }
  50% { border-color: rgba(99,102,241,0.5); }
}
