/* ============================================
   智能工坊 - Clean & Professional UI
   ============================================ */

/* ========== Variables ========== */
:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-bg: #eef2ff;
  --primary-border: #c7d2fe;

  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;

  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  --info: #0ea5e9;
  --info-bg: #f0f9ff;
  --info-border: #bae6fd;

  /* 金色渐变（首页风格） */
  --gold: #b8926a;
  --gold-light: #d4a574;
  --gold-gradient: linear-gradient(135deg, #b8926a 0%, #d4a574 50%, #c9a96e 100%);
  --gold-bg: #f5efe8;

  /* 装饰色块 */
  --accent-purple: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-teal: #14b8a6;
  --accent-orange: #f97316;

  --bg: #f8fafc;
  --bg-white: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-sidebar: #1e293b;
  --bg-sidebar-hover: #334155;
  --bg-sidebar-active: rgba(99, 102, 241, 0.2);

  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #ffffff;

  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 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.06), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.08), 0 4px 6px rgba(0, 0, 0, 0.04);

  --sidebar-w: 240px;
}

/* ========== Reset ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary-light); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
::selection { background: var(--primary-bg); color: var(--primary); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ========== Layout ========== */
.app-layout { display: flex; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-brand {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sidebar-brand .logo {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff; font-weight: 800;
}
.sidebar-brand h1 {
  font-size: 15px; color: #f1f5f9; font-weight: 700; line-height: 1.3;
}
.sidebar-brand h1 small {
  display: block; font-size: 11px; color: #64748b; font-weight: 400;
}

.sidebar-nav { flex: 1; padding: 10px 10px; overflow-y: auto; }
.nav-section { margin-bottom: 2px; }
.nav-section-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
  color: #475569; padding: 16px 14px 6px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-radius: var(--radius-xs);
  color: var(--text-sidebar); cursor: pointer;
  transition: all 0.15s; font-size: 13.5px; font-weight: 500;
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-sidebar-hover); color: #e2e8f0; }
.nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  font-weight: 600;
}
.nav-item .icon { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif; }
.nav-item .badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10px; padding: 1px 7px; border-radius: 10px; font-weight: 700; line-height: 1.5;
}

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-xs); cursor: pointer; transition: background 0.15s;
}
.sidebar-user:hover { background: var(--bg-sidebar-hover); }
.sidebar-user .avatar {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 13px;
}
.sidebar-user .info { flex: 1; }
.sidebar-user .info .name { font-size: 13px; color: #e2e8f0; font-weight: 600; }
.sidebar-user .info .role { font-size: 11px; color: #64748b; }

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

/* ---- Top Bar ---- */
.topbar {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  padding: 0 28px; height: 52px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.topbar .breadcrumb { font-size: 13px; color: var(--text-muted); }
.topbar .breadcrumb span { margin: 0 6px; color: #cbd5e1; }
.topbar .breadcrumb a { color: var(--text-secondary); transition: color 0.2s; }
.topbar .breadcrumb a:hover { color: var(--primary); }
.topbar .actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---- Page Body ---- */
.page-body { padding: 24px 28px; flex: 1; }
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 {
  font-size: 22px; font-weight: 700; color: var(--text);
}
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ========== Components ========== */

/* ---- Stat Card ---- */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; flex-direction: column; gap: 4px;
  transition: all 0.2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-card .change { font-size: 12px; font-weight: 600; }
.stat-card .change.up { color: var(--success); }
.stat-card .change.down { color: var(--danger); }

/* ---- Card ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden; transition: all 0.2s;
}
.card:hover { box-shadow: var(--shadow-sm); }
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 700; color: var(--text); }
.card-body { padding: 20px; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th, table td {
  text-align: left; padding: 10px 16px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
table th {
  background: var(--bg); color: var(--text-muted);
  font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
}
table td { color: var(--text-secondary); }
table tbody tr { transition: background 0.15s; }
table tbody tr:hover td { background: var(--bg-hover); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-xs);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-light); }
.btn-outline {
  background: var(--bg-white); color: var(--text-secondary);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--bg-hover); border-color: #cbd5e1; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 5px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* ---- Tags ---- */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.tag-primary { background: var(--primary-bg); color: var(--primary); }
.tag-success { background: var(--success-bg); color: #059669; }
.tag-warning { background: var(--warning-bg); color: #d97706; }
.tag-danger { background: var(--danger-bg); color: var(--danger); }
.tag-purple { background: #f5f3ff; color: #7c3aed; }
.tag-cyan { background: var(--info-bg); color: #0284c7; }

/* ---- Grid ---- */
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---- Agent Card ---- */
.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px; cursor: pointer;
  transition: all 0.2s;
  display: flex; flex-direction: column; gap: 12px;
}
.agent-card:hover {
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.agent-card .icon-wrap {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  background: var(--primary-bg);
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
}
.agent-card .name { font-size: 15px; font-weight: 700; color: var(--text); }
.agent-card .desc {
  font-size: 12.5px; color: var(--text-muted); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.agent-card .meta {
  display: flex; align-items: center; gap: 10px;
  margin-top: auto; padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.agent-card .meta span { font-size: 11px; color: var(--text-muted); font-weight: 500; }

/* ---- Chat ---- */
.chat-messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.chat-msg { display: flex; max-width: 960px; margin: 0 auto; width: 100%; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { 
  justify-content: flex-start; 
  flex-direction: column; 
  align-items: flex-start;
}
.chat-bubble {
  max-width: 80%; padding: 12px 16px; border-radius: 16px;
  line-height: 1.7; font-size: 14px;
}
.chat-msg.user .chat-bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
  background: var(--bg-white);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.typing-dots span { animation: blink 1.4s infinite both; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:0.2} 40%{opacity:1} }

/* ---- Markdown 渲染样式 ---- */
.markdown-content strong {
  font-weight: 700;
  color: var(--text);
}
.markdown-content em {
  font-style: italic;
  color: var(--text-secondary);
}
.markdown-content del {
  text-decoration: line-through;
  color: var(--text-muted);
}
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  font-weight: 700;
  margin: 12px 0 8px 0;
  color: var(--text);
}
.markdown-content h1 { font-size: 18px; }
.markdown-content h2 { font-size: 16px; }
.markdown-content h3 { font-size: 14px; }
.markdown-content .code-block {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px 16px;
  border-radius: 8px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  overflow-x: auto;
  margin: 8px 0;
  line-height: 1.5;
}
.markdown-content .inline-code {
  background: var(--bg);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
}
.markdown-content .list-item {
  display: list-item;
  margin-left: 20px;
  margin-bottom: 4px;
}
.markdown-content .list-item.ordered {
  list-style-type: decimal;
}
.markdown-content blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}
.markdown-content .divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
.markdown-content .md-link {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px dotted var(--primary);
}
.markdown-content .md-link:hover {
  text-decoration: underline;
}

.input-bar {
  padding: 14px 20px; border-top: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg-white);
}
.input-bar .row { display: flex; gap: 10px; max-width: 860px; margin: 0 auto; }

/* ---- Empty State ---- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 20px; text-align: center;
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 4px; font-weight: 700; }
.empty-state p { font-size: 13px; color: var(--text-muted); }

/* ---- Form ---- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--text-secondary); margin-bottom: 6px;
}
.form-control,
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 12px; font-size: 13px;
  color: var(--text); outline: none;
  background: var(--bg-white);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
.form-group textarea { line-height: 1.6; }
select.form-control { cursor: pointer; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius); width: 90%; max-width: 600px;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-body { padding: 22px; }
.modal-foot {
  padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---- Toggle ---- */
.toggle {
  width: 42px; height: 24px; border-radius: 12px;
  background: #cbd5e1; position: relative;
  cursor: pointer; transition: 0.2s;
}
.toggle.on { background: var(--primary); }
.toggle::after {
  content: ''; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; position: absolute; top: 2px; left: 2px;
  transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle.on::after { left: 20px; }

/* ---- Filter Bar ---- */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 20px; flex-wrap: wrap;
}

/* ---- Utility ---- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-16 { gap: 16px; }
.flex-1 { flex: 1; }

/* ---- Status dots ---- */
.status-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600;
}
.status-dot::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
}
.status-active::before { background: var(--success); }
.status-active { color: var(--success); }
.status-inactive::before { background: #cbd5e1; }
.status-inactive { color: var(--text-muted); }

/* ---- 装饰色块（首页风格） ---- */
.color-block {
  position: absolute;
  border-radius: 50%;
  opacity: 0.15;
  pointer-events: none;
}
.color-block-gold {
  background: var(--gold-gradient);
}
.color-block-purple {
  background: var(--accent-purple);
}
.color-block-pink {
  background: var(--accent-pink);
}
.color-block-teal {
  background: var(--accent-teal);
}
.color-block-orange {
  background: var(--accent-orange);
}

/* 金色渐变卡片 */
.card-gold {
  background: var(--gold-gradient);
  color: #fff;
  border: none;
}
.card-gold-gradient {
  background: linear-gradient(135deg, var(--gold-bg) 0%, #f0e8dc 100%);
  border: 1px solid rgba(184, 146, 106, 0.3);
}

/* 色块标签 */
.tag-gold {
  background: var(--gold-bg);
  color: var(--gold);
  border: 1px solid rgba(184, 146, 106, 0.3);
}
.tag-purple {
  background: rgba(139, 92, 246, 0.1);
  color: var(--accent-purple);
  border: 1px solid rgba(139, 92, 246, 0.2);
}
.tag-pink {
  background: rgba(236, 72, 153, 0.1);
  color: var(--accent-pink);
  border: 1px solid rgba(236, 72, 153, 0.2);
}
.tag-teal {
  background: rgba(20, 184, 166, 0.1);
  color: var(--accent-teal);
  border: 1px solid rgba(20, 184, 166, 0.2);
}
.tag-orange {
  background: rgba(249, 115, 22, 0.1);
  color: var(--accent-orange);
  border: 1px solid rgba(249, 115, 22, 0.2);
}
