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

:root {
  --primary: #4f6ef7;
  --primary-hover: #3d5bd9;
  --bg: #f5f6fa;
  --card-bg: #fff;
  --sidebar-bg: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-active: #fff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

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

/* ============ Login ============ */
#login-page {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
#login-page.active {
  display: flex;
}

.login-card {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 12px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.login-card h1 {
  text-align: center;
  font-size: 28px;
  margin-bottom: 4px;
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

/* ============ Form ============ */
.form-group {
  margin-bottom: 16px;
  flex: 1;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select.select-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .2s;
  background: var(--card-bg);
}
input:focus, textarea:focus, select.select-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,.1);
}
textarea {
  resize: vertical;
  line-height: 1.5;
}

.form-row {
  display: flex;
  gap: 16px;
}

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

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .2s;
}
.btn:disabled {
  opacity: .6;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-block { width: 100%; }
.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-danger {
  background: var(--error);
  color: #fff;
}
.btn-danger:hover { background: #dc2626; }
.btn-danger-outline {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}
.btn-danger-outline:hover {
  background: var(--error);
  color: #fff;
}

/* ============ Admin Layout ============ */
#admin-page {
  display: none;
}
#admin-page.active {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
}

.top-bar {
  grid-column: 1 / -1;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.top-bar h2 { font-size: 16px; font-weight: 600; }
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--sidebar-text);
}
.top-bar-right .btn-outline {
  color: var(--sidebar-text);
  border-color: rgba(255,255,255,.2);
}
.top-bar-right .btn-outline:hover {
  color: #fff;
  background: rgba(255,255,255,.1);
}

.sidebar {
  background: var(--sidebar-bg);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}
.nav-item {
  display: block;
  padding: 12px 24px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.nav-item:hover {
  color: #e2e8f0;
  background: rgba(255,255,255,.05);
}
.nav-item.active {
  color: var(--sidebar-active);
  background: rgba(255,255,255,.08);
  border-left-color: var(--primary);
}

.content {
  padding: 24px 32px;
  overflow-y: auto;
}
.content h3 {
  font-size: 20px;
  margin-bottom: 20px;
}

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 4px;
}
.tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  color: var(--text-secondary);
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  font-weight: 500;
}

/* ============ Status & Toast ============ */
.status-msg {
  font-size: 13px;
  transition: opacity .3s;
}
.status-msg.success { color: var(--success); }
.status-msg.error { color: var(--error); }

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  opacity: 0;
  transform: translateY(-10px);
  transition: all .3s;
  z-index: 9999;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--error); color: #fff; }

/* ============ Section Header ============ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h3 { margin-bottom: 0; }

/* ============ Data Table ============ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
}
.data-table tbody tr:hover {
  background: var(--bg);
}
.data-table .link {
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.data-table .link:hover {
  text-decoration: underline;
}

/* ============ Badges ============ */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-muted { background: var(--bg); color: var(--text-secondary); }

.empty-msg {
  text-align: center;
  color: var(--text-secondary);
  padding: 24px;
  font-size: 14px;
}

/* ============ Back Link ============ */
.back-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  margin-right: 8px;
}
.back-link:hover { color: var(--primary); }

/* ============ Switch ============ */
.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-top: 6px;
}
.switch-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
}
.switch-text {
  font-size: 14px;
  color: var(--text);
}

/* ============ Module Tabs ============ */
.module-tab { display: none; }
.module-tab.active { display: block; }

/* ============ Tool Item ============ */
.tool-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.tool-item:hover { background: var(--bg); }
.tool-item-info {
  flex: 1;
  min-width: 0;
}
.tool-item-name {
  font-weight: 600;
  font-size: 14px;
  font-family: 'Menlo', 'Consolas', monospace;
}
/* 角色组 / 岗位名称：中文友好字体 */
.role-item-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
/* 角色组卡片 header 行 */
.tool-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}
/* 角色组卡片专属样式 */
.role-group-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  background: var(--card-bg);
}
.role-group-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(79,110,247,0.1);
}
.role-group-card-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
.role-group-card-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
}
.role-group-card-desc {
  color: #666;
  font-size: 13px;
  margin: 6px 0;
  line-height: 1.5;
}
.role-group-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.role-group-card-footer {
  text-align: right;
  font-size: 12px;
  color: var(--primary);
  margin-top: 10px;
  font-weight: 500;
}
/* 岗位行 */
.role-prompt-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--card-bg);
}
.role-prompt-item:hover { background: var(--bg); }
.role-prompt-item.unconfigured { opacity: 0.72; }
.role-prompt-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.role-prompt-item-preview {
  margin-top: 6px;
  color: #666;
  font-size: 13px;
  line-height: 1.5;
}
.tool-item-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-item-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ============ Knowledge Item ============ */
.knowledge-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.knowledge-item:hover { background: var(--bg); }
.knowledge-item-info { flex: 1; min-width: 0; }
.knowledge-item-title { font-weight: 600; font-size: 14px; }
.knowledge-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ Param Row ============ */
.param-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}
.param-row input, .param-row select {
  font-size: 13px;
  padding: 6px 8px;
}
.param-row .param-name { flex: 2; }
.param-row .param-type { flex: 1; }
.param-row .param-desc { flex: 3; }
.param-row .param-remove {
  padding: 4px 8px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--error);
  font-size: 16px;
}

/* ============ Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
}
.modal-content {
  position: relative;
  background: var(--card-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h4 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  #admin-page.active {
    grid-template-columns: 1fr;
    grid-template-rows: 56px auto 1fr;
  }
  .sidebar {
    flex-direction: row;
    padding: 0;
    overflow-x: auto;
  }
  .nav-item {
    padding: 10px 16px;
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
  }
  .nav-item.active { border-bottom-color: var(--primary); }
  .content { padding: 16px; }
  .form-row { flex-direction: column; gap: 0; }
  .modal-content { width: 95%; max-width: none; }
}

.subsection-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.subsection-hint {
  font-size: 12px;
  font-weight: 400;
  color: #999;
}
