:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --card: #ffffff;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, .1), 0 8px 10px -6px rgba(0, 0, 0, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- 布局 ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #eff6ff 0%, #f9fafb 50%, #f0fdf4 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 28px;
}
.auth-brand h1 {
  font-size: 22px;
  margin: 0 0 6px;
  font-weight: 700;
}
.auth-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.auth-switch {
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
}
.form-group .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, textarea.input:focus, select.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea.input { resize: vertical; min-height: 76px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { background: #f9fafb; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: #f3f4f6; color: var(--text); }

/* ---------- 提示 ---------- */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar .logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
}
.topbar nav a:hover { background: #f3f4f6; text-decoration: none; }
.topbar nav a.active { background: var(--primary-light); color: var(--primary-dark); }
.topbar .user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- 容器 ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
.container-narrow { max-width: 760px; }

.page-title { font-size: 24px; font-weight: 700; margin: 0 0 6px; }
.page-desc { color: var(--text-muted); margin: 0 0 24px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.card-body { padding: 20px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.table th, table.table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.table th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
table.table tbody tr:hover { background: #fafafa; }
table.table td.wrap { white-space: normal; max-width: 320px; word-break: break-all; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-muted { background: #f3f4f6; color: #4b5563; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ---------- 栅格 ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- 统计卡 ---------- */
.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 28px; font-weight: 700; line-height: 1.2; }

/* ---------- 开关 ---------- */
/* 注意：.field-row > label 会把 display 设为 block，这里用更高特异性覆盖 */
.switch,
.field-row > label.switch,
.switch-label {
  display: inline-flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex-wrap: nowrap;
  line-height: 1.5;
  font-weight: normal;
}
.switch input {
  /* 视觉隐藏但仍参与 a11y；用 clip 而非 display:none，避免 flex 布局错位 */
  position: absolute;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
  white-space: nowrap;
}
/* 文字节点包在 span 里，保证不被滑块挤压（排除滑块自身） */
.switch > span:not(.track) {
  flex: 1;
  min-width: 0;
}
/* 滑块必须保持固定尺寸，不能被 flex 挤压 */
.switch > .track {
  flex: 0 0 40px;
  width: 40px;
  min-width: 40px;
}
.switch .track {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #d1d5db;
  position: relative;
  transition: background .18s;
  flex-shrink: 0;
}
.switch .track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- 模态框 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: #fff;
}
.close-x {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.close-x:hover { background: #f3f4f6; }

/* ---------- 复制块 ---------- */
.code-block {
  background: #1f2937;
  color: #e5e7eb;
  padding: 14px 16px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
  max-height: 420px;
  margin: 0;
}

/* ---------- 上传区域 ---------- */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: #fafafa;
}
.upload-zone:hover,
.upload-zone.drag {
  border-color: var(--primary);
  background: #eff6ff;
}
.upload-zone input[type=file] { display: none; }
.upload-zone.uploading {
  pointer-events: none;
  opacity: .7;
}

/* 形象选择小卡片 */
.avatar-chip {
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  width: 84px;
  background: #fff;
  transition: border-color .15s;
  padding: 0;
  text-align: left;
  font: inherit;
}
.avatar-chip:hover { border-color: var(--primary); }
.avatar-chip.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.avatar-chip img { width: 100%; height: 106px; object-fit: cover; display: block; }
.avatar-chip .nm {
  font-size: 11px;
  padding: 4px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 加载 ---------- */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { color: var(--text-muted); text-align: center; padding: 40px 0; }

/* ---------- 分页 ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.pager .pages { display: flex; gap: 6px; }

/* ---------- toast ---------- */
#toast-box {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: #111827;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn .22s ease-out;
  max-width: 360px;
}
.toast.error { background: #b91c1c; }
.toast.success { background: #047857; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---------- 音色列表 ---------- */
.voice-list {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 168px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: var(--radius, 8px);
  background: #fafafa;
}
.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #fff;
  color: #374151;
  cursor: pointer;
  transition: all 0.15s ease;
}
.voice-chip:hover {
  border-color: #2563eb;
  color: #2563eb;
}
.voice-chip.is-active {
  border-color: #2563eb;
  background: #dbeafe;
  color: #1e40af;
  font-weight: 600;
}
.voice-chip .voice-tag {
  font-size: 10px;
  opacity: 0.65;
}
/* 试听按钮 */
.voice-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-right: 2px;
  font-size: 9px;
  line-height: 1;
  border-radius: 50%;
  background: #eef2ff;
  color: #4f46e5;
  cursor: pointer;
  transition: all 0.15s ease;
}
.voice-play:hover {
  background: #4f46e5;
  color: #fff;
}
.voice-play.is-playing {
  background: #16a34a;
  color: #fff;
}
.voice-play.is-loading {
  background: #fde68a;
  color: #92400e;
  animation: voice-pulse 1s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
/* 音色列表工具栏 */
.voice-toolbar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 6px;
}
.voice-toolbar .input {
  height: 32px;
  font-size: 12px;
}
.voice-toolbar #g-voice-scope {
  width: 168px;
  flex: 0 0 auto;
}
.voice-list {
  max-height: 220px;
}
/* 不可试听的音色 */
.voice-play.is-disabled {
  background: #f3f4f6;
  color: #c0c4cc;
  cursor: not-allowed;
}
.voice-play.is-disabled:hover {
  background: #f3f4f6;
  color: #c0c4cc;
}
/* ---------- 关键词播报规则 ---------- */
.kw-rules {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 2px;
}
.kw-rule {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fafafa;
}
.kw-rule-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
}
.kw-rule .field-row { margin-bottom: 6px; }
.kw-rule .field-row:last-child { margin-bottom: 0; }
.kw-rule .input { font-size: 12px; }
.kw-rule textarea.input { resize: vertical; min-height: 52px; }