/* khcs-mcp 管理台 —— 浅色主题 */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --primary: #3370ff;
  --primary-hover: #245bdb;
  --green: #34a853;
  --green-bg: #e8f5ec;
  --red: #d93026;
  --red-bg: #fdecea;
  --gray-bg: #f0f1f3;
  --amber: #b06000;
  --amber-bg: #fff4e0;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(31, 35, 41, 0.06), 0 4px 14px rgba(31, 35, 41, 0.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef3ff 0%, #f7f8fa 60%);
}
.login-card {
  width: 400px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 40px 36px 32px;
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.login-brand h1 { font-size: 20px; font-weight: 600; }
.login-sub { color: var(--text-2); font-size: 13px; }
.logo {
  width: 44px; height: 44px;
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; letter-spacing: 0.5px;
}
.login-form label { display: block; margin-bottom: 16px; color: var(--text-2); font-size: 13px; }
.login-form input {
  width: 100%; margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.15s;
  background: #fff;
}
.login-form input:focus { outline: none; border-color: var(--primary); }

/* ---------- 布局 ---------- */
.app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand .logo { width: 36px; height: 36px; border-radius: 9px; font-size: 13px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14px; }
.brand-text span { font-size: 12px; color: var(--text-3); }
.nav { padding: 12px 10px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  margin-bottom: 4px;
  font-size: 14px;
  transition: all 0.15s;
}
.nav-item:hover { background: var(--gray-bg); color: var(--text); }
.nav-item.active { background: #e8efff; color: var(--primary); font-weight: 500; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border); }
.live-indicator { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.live-indicator .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
.live-indicator.off .dot { background: var(--text-3); animation: none; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}
.main { flex: 1; margin-left: 216px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 16px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.refresh-time { font-size: 12px; color: var(--text-3); }
.admin-name { font-size: 13px; color: var(--text-2); }
.content { padding: 24px; flex: 1; }

/* ---------- 统计卡 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.stat-label { font-size: 13px; color: var(--text-2); }
.stat-value { font-size: 30px; font-weight: 600; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-3); }
.text-green { color: var(--green); }

.panel-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}
.panel-title {
  font-size: 14px; font-weight: 600;
  margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.badge-live {
  font-size: 11px; font-weight: 400;
  color: var(--green);
  background: var(--green-bg);
  padding: 1px 8px; border-radius: 99px;
}

/* ---------- 表格 ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.toolbar-spacer { flex: 1; }
.toolbar-hint { font-size: 12px; color: var(--text-3); }
.input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  min-width: 220px;
  transition: border-color 0.15s;
}
.input:focus { outline: none; border-color: var(--primary); }
.select { min-width: 130px; cursor: pointer; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: none; }
.col-center { text-align: center; }
.col-right { text-align: right; }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.empty {
  text-align: center;
  color: var(--text-3);
  padding: 36px 0;
  font-size: 13px;
}
.empty.hidden { display: none; }
.audit-more { text-align: center; margin-top: 14px; }

/* ---------- 徽章 / 开关 / 按钮 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 99px;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { color: var(--green); background: var(--green-bg); }
.badge-gray { color: var(--text-3); background: var(--gray-bg); }
.badge-red { color: var(--red); background: var(--red-bg); }
.badge-amber { color: var(--amber); background: var(--amber-bg); }
.badge-blue { color: var(--primary); background: #e8efff; }

.switch {
  position: relative;
  display: inline-block;
  width: 40px; height: 22px;
  cursor: pointer;
}
.switch input { display: none; }
.switch .slider {
  position: absolute; inset: 0;
  background: #c9cdd4;
  border-radius: 99px;
  transition: background 0.2s;
}
.switch .slider::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  left: 2px; top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch.loading { opacity: 0.6; pointer-events: none; }

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--gray-bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b3261e; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.btn-link {
  background: none; border: none; color: var(--primary);
  cursor: pointer; font-size: 13px; padding: 4px 6px;
  font-family: inherit;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--red); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(31, 35, 41, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 560px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 64px);
  overflow: auto;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.16);
  animation: slideUp 0.18s;
}
.modal-sm { width: 420px; }
.modal-lg { width: 680px; }
@keyframes slideUp { from { transform: translateY(14px); opacity: 0.5; } to { transform: none; opacity: 1; } }
.modal-title { font-size: 16px; font-weight: 600; padding: 18px 22px 0; }
.modal-body { padding: 18px 22px; }
.modal-body label { display: block; margin-bottom: 14px; color: var(--text-2); font-size: 13px; }
.modal-body input, .modal-body textarea, .modal-body select {
  width: 100%; margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s;
}
.modal-body input:focus, .modal-body textarea:focus, .modal-body select:focus {
  outline: none; border-color: var(--primary);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-line {
  display: flex !important; align-items: center; gap: 8px;
  color: var(--text) !important; font-size: 14px !important;
  cursor: pointer;
}
.checkbox-line input { width: 16px !important; height: 16px; margin: 0 !important; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
}
.confirm-text { font-size: 14px; margin-bottom: 8px; }
.confirm-warn { font-size: 13px; color: var(--amber); }
.grant-hint { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
#grant-tbody input { width: 16px; height: 16px; cursor: pointer; }

.form-error {
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-top: 4px;
}

/* ---------- 审计 Feed ---------- */
.feed { display: flex; flex-direction: column; gap: 2px; max-height: 380px; overflow-y: auto; }
.feed-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13px;
}
.feed-item:hover { background: var(--gray-bg); }
.feed-item .feed-time { color: var(--text-3); font-size: 12px; white-space: nowrap; margin-left: auto; }
.feed-item .feed-name { font-weight: 500; }
.feed-item .feed-caller { color: var(--text-3); font-size: 12px; }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; top: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  padding: 12px 16px;
  font-size: 14px;
  min-width: 260px;
  animation: toastIn 0.2s;
  border-left: 3px solid var(--green);
}
.toast.error { border-left-color: var(--red); }
.toast.leaving { animation: toastOut 0.2s forwards; }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateX(20px); opacity: 0; } }
.toast-icon { font-size: 16px; }

/* 响应式 */
@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { width: 64px; }
  .brand-text, .nav-item span:not(.nav-icon), .sidebar-footer { display: none; }
  .nav-item { justify-content: center; }
  .main { margin-left: 64px; }
}

/* ---------- 工具定义编辑器 ---------- */
.editor-block {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.editor-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.editor-table { margin-bottom: 10px; }
.editor-table th { padding: 6px 8px; }
.editor-table td { padding: 6px 8px; }
.editor-table input, .editor-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}
.editor-table input:focus, .editor-table select:focus { outline: none; border-color: var(--primary); }
.editor-table input[type="checkbox"] { width: 16px; height: 16px; }
.editor-table .col-center input { margin: 0 auto; display: block; }
.editor-table .btn-link { padding: 2px 4px; }

/* ---------- 表单辅助说明 ---------- */
.field-hint {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
  margin: -2px 0 10px;
}

/* ---------- 令牌展示区（明文仅展示一次）---------- */
.token-reveal {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: #f5f9ff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.token-reveal-title {
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}
.token-value {
  flex: 1;
  min-width: 240px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #fff;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  user-select: all;
}
