/*
 * 星声门店助播 · 总控后台样式表
 * 遵循 Apple Human Interface Guidelines (HIG) 与 Apple Fluid Motion 规范：
 * 1) 双层材质分离：内容层使用纯净实色分层表面，仅导航侧栏/弹窗/轻提示使用 Liquid Glass
 * 2) 系统自适应外观：自动响应浅色/深色模式（prefers-color-scheme），无需手动切换
 * 3) 色彩克制预算：Apple System Blue 主操作色 + On-Air 直播绿点语义徽章
 * 4) 光学排版与等宽数字（tabular-nums）+ 瞬时按压物理反馈 + 完整无障碍降级
 */

:root {
  color-scheme: light dark;

  /* 浅色外观（macOS / iOS 默认系统语义色） */
  --bg: #f5f5f7;
  --bg-subtle: #efeff4;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-hover: #e8e8ed;
  --glass-bg: rgba(255, 255, 255, 0.74);
  --glass-border: rgba(255, 255, 255, 0.85);
  --glass-shadow: 0 12px 32px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);

  --border: rgba(60, 60, 67, 0.12);
  --border-strong: rgba(60, 60, 67, 0.22);

  --text: #1d1d1f;
  --text-secondary: #48484a;
  --muted: #6e6e73;

  --primary: #007aff;
  --primary-hover: #0066d6;
  --primary-tint: rgba(0, 122, 255, 0.11);
  --primary-text: #0066d6;

  --accent: #248a3d;
  --accent-bg: rgba(36, 138, 61, 0.12);
  --accent-text: #1e7a34;

  --warn: #c93400;
  --warn-bg: rgba(255, 149, 0, 0.14);
  --warn-text: #b25000;

  --danger: #d70015;
  --danger-bg: rgba(255, 59, 48, 0.12);
  --danger-text: #c20013;

  --chat-bg: #f5f5f7;
  --chat-item-bg: #ffffff;
  --chat-ai-bg: rgba(36, 138, 61, 0.08);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.03);
  --shadow-modal: 0 28px 70px rgba(0, 0, 0, 0.18), 0 2px 10px rgba(0, 0, 0, 0.06);
  --mask-bg: rgba(0, 0, 0, 0.36);

  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --radius-pill: 999px;

  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-subtle: #0d0d0f;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --surface-hover: #3a3a3c;
    --glass-bg: rgba(28, 28, 30, 0.76);
    --glass-border: rgba(255, 255, 255, 0.14);
    --glass-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);

    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);

    --text: #f5f5f7;
    --text-secondary: #d1d1d6;
    --muted: #98989d;

    --primary: #0a84ff;
    --primary-hover: #409cff;
    --primary-tint: rgba(10, 132, 255, 0.18);
    --primary-text: #64b5ff;

    --accent: #30d158;
    --accent-bg: rgba(48, 209, 88, 0.16);
    --accent-text: #4ae371;

    --warn: #ff9f0a;
    --warn-bg: rgba(255, 159, 10, 0.16);
    --warn-text: #ffb340;

    --danger: #ff453a;
    --danger-bg: rgba(255, 69, 58, 0.16);
    --danger-text: #ff6961;

    --chat-bg: #111113;
    --chat-item-bg: #1c1c1e;
    --chat-ai-bg: rgba(48, 209, 88, 0.11);

    --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-modal: 0 32px 80px rgba(0, 0, 0, 0.68), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --mask-bg: rgba(0, 0, 0, 0.64);
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: inherit;
}

/* 可见焦点环（HIG 键盘无障碍规范） */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ================= 登录页 ================= */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(880px 480px at 50% -10%, var(--primary-tint), transparent 70%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 34px 30px;
  box-shadow: var(--shadow-modal);
  animation: surfaceIn 380ms var(--ease-spring) both;
}

.login-brand-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
  display: inline-block;
  flex-shrink: 0;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.login-card .sub {
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 13px;
  line-height: 1.55;
}

/* ================= 主应用骨架（Liquid Glass 侧栏 + 纯净内容画布） ================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  border-right: 1px solid var(--border);
  padding: 22px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}

.brand {
  padding: 4px 12px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.brand-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.28);
  flex-shrink: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.brand-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 10px 13px;
  border-radius: 11px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out), transform 100ms var(--ease-out);
}

.nav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-btn:active {
  transform: scale(0.98);
}

.nav-btn.active {
  background: var(--primary-tint);
  color: var(--primary-text);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 6px 2px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* ================= 主内容画布 ================= */
.main-area {
  flex: 1;
  min-width: 0;
  padding: 28px 34px 48px;
  max-width: 1400px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.026em;
  line-height: 1.22;
}

/* ================= 栅格与分组卡片（内容层：纯净实色，无玻璃糊底） ================= */
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }

@media (max-width: 1120px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand { border-bottom: none; margin-bottom: 0; padding: 0 10px 0 0; }
  .nav-btn { width: auto; padding: 8px 12px; }
  .sidebar-foot { margin-top: 0; margin-left: auto; border-top: none; padding-top: 0; }
  .main-area { padding: 18px 16px 36px; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-card);
  transition: border-color 180ms var(--ease-out);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.014em;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat-val {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.text-green { color: var(--accent-text); }
.text-warn { color: var(--warn-text); }
.text-danger { color: var(--danger-text); }
.text-primary { color: var(--primary-text); }
.muted { color: var(--muted); font-size: 12.5px; }

/* ================= 表单控件（Apple HIG 输入与分组风格） ================= */
.field { margin-bottom: 13px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 9.5px 12px;
  outline: none;
  transition: border-color 140ms var(--ease-out), background-color 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3.5px var(--primary-tint);
}

textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.55;
}

/* ================= 按钮体系（严格色彩克制 + 瞬时物理按压） ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8.5px 15px;
  min-height: 36px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: -0.01em;
  background: var(--primary);
  color: #ffffff;
  text-decoration: none;
  transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), transform 95ms var(--ease-out), opacity 140ms var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-sm {
  padding: 5.5px 11px;
  min-height: 30px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

/* 语义次级操作按钮：采用 Apple 柔和着色（Tinted）避免花花绿绿 */
.btn-green {
  background: var(--accent-bg);
  color: var(--accent-text);
  border-color: transparent;
}
.btn-green:hover {
  background: var(--accent);
  color: #ffffff;
}

.btn-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: transparent;
}
.btn-warn:hover {
  background: var(--warn);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: transparent;
}
.btn-danger:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ================= 表格（清晰等宽数字 + 柔和分割线） ================= */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.01em;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 120ms var(--ease-out); }
tbody tr:hover td { background: var(--surface-2); }

/* ================= 语义状态胶囊 ================= */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--primary-tint);
  color: var(--primary-text);
  white-space: nowrap;
}
.tag-green { background: var(--accent-bg); color: var(--accent-text); }
.tag-warn { background: var(--warn-bg); color: var(--warn-text); }
.tag-danger { background: var(--danger-bg); color: var(--danger-text); }

/* ================= 分段控件式子 Tab（iOS / macOS Segmented Control） ================= */
.subtabs {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 20px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.subtab {
  padding: 7px 15px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background-color 160ms var(--ease-spring), color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.subtab:hover { color: var(--text); }
.subtab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* ================= 音色卡 ================= */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
  gap: 12px;
}

.voice-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 160ms var(--ease-out), transform 140ms var(--ease-spring), background-color 160ms var(--ease-out);
}

.voice-card:hover { border-color: var(--border-strong); }
.voice-card.selected {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-tint);
}

/* ================= 模拟直播公屏 ================= */
.chat-feed {
  background: var(--chat-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  height: 360px;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-item {
  background: var(--chat-item-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  border-left: 3px solid var(--primary);
}

.chat-item.ai {
  border-left-color: var(--accent);
  background: var(--chat-ai-bg);
}

.chat-meta {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

/* ================= Liquid Glass 模态弹窗与顶部轻提示 ================= */
.modal-mask {
  position: fixed;
  inset: 0;
  background: var(--mask-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}

.modal-mask.show { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 26px;
  box-shadow: var(--shadow-modal);
  animation: surfaceIn 260ms var(--ease-spring) both;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 14px;
  box-shadow: var(--glass-shadow);
  font-weight: 500;
  font-size: 13.5px;
  display: none;
  z-index: 1200;
  max-width: 420px;
}

.toast.show {
  display: block;
  animation: surfaceIn 240ms var(--ease-spring) both;
}

.hidden { display: none !important; }

@keyframes surfaceIn {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ================= Apple 无障碍系统偏好降级 ================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .btn:active, .nav-btn:active { transform: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .sidebar, .toast, .modal-mask {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .sidebar, .toast { background: var(--surface); }
}

@media (prefers-contrast: more) {
  :root {
    --border: rgba(0, 0, 0, 0.34);
    --border-strong: rgba(0, 0, 0, 0.55);
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --border: rgba(255, 255, 255, 0.32);
      --border-strong: rgba(255, 255, 255, 0.55);
    }
  }
}
