/**
 * 灵境 — 主题样式
 * 日间模式 / 夜间模式 / 跟随系统
 */

:root,
[data-theme="light"] {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0f2f5;
  --bg-modal: rgba(0, 0, 0, 0.45);
  --bg-hover: #f0f2f5;

  --text-primary: #1a1a2e;
  --text-secondary: #555770;
  --text-hint: #8e90a6;
  --text-inverse: #ffffff;

  --border-color: #e4e6ef;
  --border-light: #f0f2f5;

  --accent-primary: #4f6ef7;
  --accent-hover: #3b5de7;
  --accent-light: #eef1ff;

  --danger: #e74c4c;
  --danger-hover: #c0392b;
  --success: #27ae60;
  --warning: #f39c12;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --transition: 0.25s ease;
}

[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #1e1e36;
  --bg-input: #252540;
  --bg-modal: rgba(0, 0, 0, 0.7);
  --bg-hover: #252540;

  --text-primary: #e8e8f0;
  --text-secondary: #a0a3b8;
  --text-hint: #6b6e85;
  --text-inverse: #0f0f1a;

  --border-color: #2a2a45;
  --border-light: #222240;

  --accent-primary: #6c82ff;
  --accent-hover: #5b6fe7;
  --accent-light: #1e2240;

  --danger: #e74c4c;
  --danger-hover: #ff6b6b;
  --success: #2ecc71;
  --warning: #f1c40f;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

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

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-hint); border-radius: 3px; }

a { color: var(--accent-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

button {
  cursor: pointer; font-family: inherit; font-size: 0.9rem;
  padding: 8px 18px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); background: var(--bg-secondary);
  color: var(--text-primary); transition: all var(--transition); outline: none;
}
button:hover { background: var(--bg-hover); border-color: var(--accent-primary); }
button:disabled, button.btn-disabled { opacity: 0.5; cursor: not-allowed; }
button.btn-primary { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }
button.btn-primary:hover { background: var(--accent-hover); }
button.btn-danger { color: var(--danger); border-color: var(--danger); }
button.btn-danger:hover { background: var(--danger); color: #fff; }
button.btn-sm { padding: 4px 12px; font-size: 0.8rem; }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], textarea, select {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); background: var(--bg-input);
  color: var(--text-primary); font-family: inherit; font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition); outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-light);
}
textarea { resize: vertical; min-height: 120px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-secondary); font-size: 0.9rem; }
.form-group .hint { font-size: 0.78rem; color: var(--text-hint); margin-top: 4px; }

.page-container { display: flex; flex-direction: column; min-height: 100vh; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg-primary); }
.login-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  padding: 40px 36px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.login-card h1 { text-align: center; margin-bottom: 0; font-size: 1.6rem; color: var(--accent-primary); }
.login-card .brand-sub { display: block; text-align: center; font-size: 0.8rem; color: var(--text-hint); margin-bottom: 24px; }
.login-card .switch-link { text-align: center; margin-top: 18px; font-size: 0.88rem; color: var(--text-secondary); }

.top-bar {
  background: var(--bg-card); border-bottom: 1px solid var(--border-color);
  padding: 0 24px; display: flex; align-items: center; height: 56px;
  box-shadow: var(--shadow-sm); position: sticky; top: 0; z-index: 100;
}
.top-bar .brand { font-weight: 700; font-size: 1.1rem; color: var(--accent-primary); margin-right: 8px; white-space: nowrap; }
.top-bar .brand-sub { font-weight: 400; color: var(--text-hint); font-size: 0.85rem; margin-right: 24px; }
.top-bar .nav-links { display: flex; gap: 4px; flex: 1; }
.top-bar .nav-links button {
  border: none; background: transparent; padding: 8px 16px;
  font-size: 0.9rem; border-radius: var(--radius-sm); color: var(--text-secondary);
}
.top-bar .nav-links button.active { background: var(--accent-light); color: var(--accent-primary); font-weight: 600; }
.top-bar .top-actions { display: flex; align-items: center; gap: 12px; }
.top-bar .points-badge { font-weight: 600; color: var(--accent-primary); font-size: 0.9rem; }

.main-content { flex: 1; padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

.panel {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 24px; box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
.panel h2 { font-size: 1.2rem; margin-bottom: 16px; color: var(--text-primary); }

.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.agent-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 20px;
  transition: box-shadow var(--transition), transform var(--transition);
}
.agent-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.agent-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.agent-card-header h3 { font-size: 1.05rem; color: var(--text-primary); }
.agent-status { font-size: 0.75rem; padding: 2px 10px; border-radius: 12px; }
.agent-status.active { background: var(--success); color: #fff; }
.agent-status.inactive { background: var(--text-hint); color: #fff; }
.agent-desc { color: var(--text-secondary); font-size: 0.85rem; margin-bottom: 6px; min-height: 40px; }
.agent-model { color: var(--accent); font-size: 0.78rem; margin-bottom: 10px; }
.agent-card-footer { display: flex; gap: 8px; flex-wrap: wrap; }

/* 表单 select */
.form-select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--card-bg); color: var(--text-primary);
  font-size: 0.9rem;
}
.form-select:focus { border-color: var(--accent); outline: none; }

/* QQ 绑定卡片 */
.qq-bot-card {
  background: var(--bg-secondary); border-radius: 8px;
  padding: 16px; margin-bottom: 12px;
}
.qq-bot-name { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.qq-bot-meta { color: var(--text-secondary); font-size: 0.82rem; margin-bottom: 12px; }
.qq-bot-actions { display: flex; gap: 8px; }
.qq-status-bar {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 12px; font-size: 0.75rem;
  margin-bottom: 8px;
}
.qq-status-bar.online { background: #d4edda; color: #155724; }
.qq-status-bar.waiting { background: #fff3cd; color: #856404; }
.qq-status-bar.error { background: #f8d7da; color: #721c24; }
.qq-status-bar.offline { background: #e2e3e5; color: #6c757d; }
.qq-status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: currentColor;
  display: inline-block;
}
.qq-manager h2 { margin: 0 0 12px 0; font-size: 1.1rem; }

.editor-section { margin-bottom: 20px; }
.editor-section h3 {
  font-size: 1rem; margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light); color: var(--text-primary);
}

.records-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.records-table th, .records-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border-light); }
.records-table th { font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; }

.pagination { display: flex; gap: 6px; margin-top: 16px; justify-content: center; }
.page-btn { padding: 6px 12px; font-size: 0.82rem; min-width: 36px; text-align: center; }
.page-btn.active { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }

.modal-overlay { display: none; position: fixed; inset: 0; background: var(--bg-modal); z-index: 1000; align-items: center; justify-content: center; }
.modal-content {
  background: var(--bg-card); border-radius: var(--radius-md);
  padding: 28px; max-width: 520px; width: 90%; max-height: 80vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-card h3 { margin-bottom: 16px; color: var(--accent-primary); }

.guide-dialog h3 { text-align: center; margin-bottom: 20px; color: var(--accent-primary); }
.guide-step { margin-bottom: 16px; padding: 14px; background: var(--bg-input); border-radius: var(--radius-sm); }
.guide-step strong { display: block; margin-bottom: 4px; color: var(--text-primary); }
.guide-step p { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.5; }

.toast {
  position: fixed; bottom: 32px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary); color: var(--text-inverse);
  padding: 12px 24px; border-radius: 24px; font-size: 0.9rem;
  z-index: 2000; opacity: 0; transition: all 0.3s ease;
  pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.theme-selector { display: flex; gap: 8px; }
.theme-option { padding: 6px 14px; font-size: 0.82rem; border-radius: 20px; }
.theme-option.active { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-hint); }
.empty-state p { margin-bottom: 16px; }
.loading { text-align: center; padding: 32px; color: var(--text-hint); }

/* ── QQ 接入面板 ── */
.qq-manager { max-width: 640px; }
.qq-manager h2 { font-size: 1.15rem; margin-bottom: 12px; color: var(--accent-primary); }
.qq-bot-grid { display: flex; flex-direction: column; gap: 12px; }
.qq-bot-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 16px;
}
.qq-status-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 6px;
  font-size: 12px; margin-bottom: 10px; width: fit-content;
}
.qq-status-bar.online { background: rgba(34,197,94,0.1); color: #4ade80; }
.qq-status-bar.offline { background: rgba(100,116,139,0.1); color: #94a3b8; }
.qq-status-bar.waiting { background: rgba(234,179,8,0.1); color: #facc15; }
.qq-status-bar.error { background: rgba(239,68,68,0.1); color: #f87171; }
.qq-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.qq-status-bar.online .qq-status-dot { background: #4ade80; box-shadow: 0 0 6px rgba(34,197,94,0.5); }
.qq-status-bar.offline .qq-status-dot { background: #94a3b8; }
.qq-status-bar.waiting .qq-status-dot { background: #facc15; box-shadow: 0 0 6px rgba(234,179,8,0.5); }
.qq-status-bar.error .qq-status-dot { background: #f87171; }
.qq-bot-info { margin-bottom: 8px; }
.qq-bot-name { font-weight: 600; font-size: 0.95rem; }
.qq-bot-meta { font-size: 0.8rem; color: var(--text-hint); margin-top: 2px; }
.qq-qr-area { margin: 8px 0; text-align: center; }
.qq-bot-actions { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 768px) {
  .main-content { padding: 16px; }
  .agent-grid { grid-template-columns: 1fr; }
  .top-bar { padding: 0 12px; }
  .top-bar .brand-sub { display: none; }
}
