/* ============================================================
   元工管理台 — Custom Design System
   ============================================================ */

/* 1. Design Tokens */
:root {
  --sidebar-width: 240px;
  --sidebar-bg: #1e1b4b;
  --sidebar-text: rgba(255,255,255,0.7);
  --sidebar-text-active: #ffffff;
  --sidebar-accent: #6366f1;
  --sidebar-hover-bg: rgba(99,102,241,0.15);
  --sidebar-active-bg: rgba(99,102,241,0.25);

  --body-bg: #f1f5f9;
  --card-bg: #ffffff;
  --text-primary: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #e2e8f0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-hover: 0 10px 25px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.2s ease;
}

/* 2. Base Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

/* 3. Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--sidebar-text-active);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--sidebar-accent);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-section-label {
  padding: 20px 20px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
}

.sidebar-nav { padding: 8px 12px; flex: 1; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
  border-left: 3px solid transparent;
}

.sidebar-link i { font-size: 16px; flex-shrink: 0; }

.sidebar-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px;
  color: rgba(255,255,255,0.28);
}

/* 4. Main Content Area */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-body { padding: 28px 32px; }

/* 5. Component Library */

/* Stat Cards */
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--border);
  transition: var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

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

.stat-icon.total   { background: #ede9fe; color: #6366f1; }
.stat-icon.running { background: #d1fae5; color: #059669; }
.stat-icon.stopped { background: #fee2e2; color: #dc2626; }

.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-bottom: 2px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); line-height: 1; }

/* Agent Cards */
.agent-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  transition: var(--transition);
  height: 100%;
  display: flex;
  flex-direction: column;
}

.agent-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
  border-color: rgba(99,102,241,0.3);
}

.agent-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.agent-avatar {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  flex-shrink: 0;
}

.agent-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.agent-appid {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  background: #f8fafc;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.status-badge.running { background: #d1fae5; color: #065f46; }
.status-badge.stopped { background: #fee2e2; color: #991b1b; }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.running {
  background: #10b981;
  animation: pulse-green 2s infinite;
}

.status-dot.stopped { background: #ef4444; }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(16,185,129,0); }
}

.model-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  background: #ede9fe;
  color: #5b21b6;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.skills-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
  margin-bottom: 12px;
  flex: 1;
  align-content: flex-start;
}

.skill-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  background: #f1f5f9;
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.agent-card-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Buttons */
.btn-accent {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.btn-accent:hover { background: var(--accent-hover); color: white; transform: translateY(-1px); box-shadow: var(--shadow-md); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
}

.btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: #f5f3ff; }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-danger-ghost:hover { background: #fef2f2; border-color: var(--danger); }

.btn-toggle-on {
  background: transparent;
  color: #d97706;
  border: 1px solid #fde68a;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-toggle-on:hover { background: #fffbeb; }

.btn-toggle-off {
  background: transparent;
  color: #059669;
  border: 1px solid #a7f3d0;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-toggle-off:hover { background: #ecfdf5; }

/* Flash Alerts */
.flash-alerts { padding: 0 32px; }

.flash-alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid transparent;
}

.flash-alert.success   { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.flash-alert.danger    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.flash-alert.warning   { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.flash-alert.secondary { background: #f1f5f9; color: #475569; border-color: var(--border); }

/* Form Sections */
.form-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.form-section-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-section-icon {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: #ede9fe;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.form-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.form-section-body { padding: 20px 24px; }

/* Form Controls */
.form-label-custom {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label-custom .required { color: #ef4444; margin-left: 2px; }

.form-input {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  background: white;
  transition: var(--transition);
  font-family: inherit;
  outline: none;
  display: block;
}

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

.form-input.monospace {
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 13px;
}

.form-select-custom {
  width: 100%;
  padding: 9px 36px 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  background: white;
  transition: var(--transition);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  cursor: pointer;
  font-family: inherit;
}

.form-select-custom:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

/* Pill Checkboxes */
.pill-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-checkbox-group input[type="checkbox"] { display: none; }

.pill-checkbox-group label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
  background: white;
}

.pill-checkbox-group label:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #f5f3ff;
}

.pill-checkbox-group input[type="checkbox"]:checked + label {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Workspace Path */
.workspace-path {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--text-muted);
  background: #f8fafc;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-top: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-all;
}

/* Chat (Logs) — Two-panel layout */
.chat-wrapper {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: row;
  height: calc(100vh - 130px);
  min-height: 400px;
}

/* Left: Channel Sidebar */
.channel-sidebar {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #fafbfc;
}

.channel-sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.channel-count-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
}

.channel-list::-webkit-scrollbar { width: 4px; }
.channel-list::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

.channel-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid var(--border);
}

.channel-item:hover { background: #f1f5f9; }

.channel-item.active {
  background: #ede9fe;
  border-right: 3px solid var(--accent);
}

.channel-item-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: #e0e7ff;
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.channel-item.active .channel-item-avatar {
  background: var(--accent);
  color: white;
}

.channel-item-info {
  flex: 1;
  min-width: 0;
}

.channel-item-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: monospace;
}

.channel-item-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.channel-item-count {
  font-size: 11px;
  background: #e2e8f0;
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
  font-weight: 500;
}

.channel-item.active .channel-item-count {
  background: var(--accent);
  color: white;
}

/* Right: Chat Main */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-panel-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-avatar-sm {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 16px;
  flex-shrink: 0;
}

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.chat-message.user      { align-self: flex-end; align-items: flex-end; }
.chat-message.assistant { align-self: flex-start; align-items: flex-start; }

.chat-meta {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

/* Markdown inside bubbles */
.chat-bubble p { margin: 0 0 6px; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { padding-left: 18px; margin: 4px 0; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3, .chat-bubble h4 {
  font-size: 1em; font-weight: 700; margin: 8px 0 4px;
}
.chat-bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.88em;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0,0,0,0.08);
}
.chat-message.user .chat-bubble code { background: rgba(255,255,255,0.22); }
.chat-bubble pre {
  background: rgba(0,0,0,0.07);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.chat-bubble pre code { background: transparent; padding: 0; font-size: 0.85em; }
.chat-message.user .chat-bubble pre { background: rgba(255,255,255,0.15); }
.chat-bubble blockquote {
  border-left: 3px solid rgba(0,0,0,0.15);
  padding: 2px 10px;
  margin: 6px 0;
  opacity: 0.85;
}
.chat-message.user .chat-bubble blockquote { border-left-color: rgba(255,255,255,0.4); }
.chat-bubble a { color: inherit; text-decoration: underline; opacity: 0.9; }
.chat-bubble table { border-collapse: collapse; font-size: 13px; margin: 8px 0; width: 100%; }
.chat-bubble th, .chat-bubble td {
  border: 1px solid rgba(0,0,0,0.12);
  padding: 4px 8px;
  text-align: left;
}
.chat-message.user .chat-bubble th,
.chat-message.user .chat-bubble td { border-color: rgba(255,255,255,0.2); }
.chat-bubble hr { border: none; border-top: 1px solid rgba(0,0,0,0.1); margin: 8px 0; }

.chat-message.user .chat-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant .chat-bubble {
  background: #f1f5f9;
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  gap: 10px;
  padding: 40px;
}

.chat-empty i { font-size: 40px; opacity: 0.4; display: block; }

/* Empty State (agents list) */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state i { font-size: 48px; color: var(--text-light); margin-bottom: 16px; display: block; }
.empty-state h5 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }
.empty-state p  { font-size: 14px; }


/* 6. Utilities */
.gap-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mt-small { margin-top: 8px; }
