:root {
  --primary: #4285f4;
  --primary-dark: #3367d6;
  --primary-light: #e8f0fe;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --bg: #f6f8fc;
  --surface: #ffffff;
  --danger: #d93025;
  --success: #188038;
  --warning: #f9ab00;
  --info: #1a73e8;
  --muted: #5f6368;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, .16), 0 1px 3px rgba(60, 64, 67, .08);
  --shadow-2: 0 2px 6px rgba(60, 64, 67, .18), 0 1px 2px rgba(60, 64, 67, .12);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Google Sans", "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

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

/* Edge/浏览器默认样式重置 —— 干掉 button/select/a 的默认边框和外观 */
*:focus { outline: none !important; }
*:focus-visible { outline: none !important; }

button {
  border: none !important;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
  outline: none !important;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* ===== 全局输入框/下拉框 —— 统一以客户列表搜索框为基准 =====
   所有页面（客户列表、活码列表、活动表单、登录页、标签弹窗...）
   一律使用这套高度/字号/边框，不再按 wrapper class 区分。
   wrapper 类（.field / .field-inline）只负责排版布局（标签位置、flex 等），
   不再重新定义 input/select 自身样式。 */
input, select, textarea {
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}

input, select {
  height: 32px;
}

/* textarea 与输入框同款边框，仅布局参数不同（多行） */
textarea {
  padding: 7px 9px;
  line-height: 1.6;
  min-height: 68px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(66, 133, 244, .18);
}

input[type="checkbox"], input[type="radio"] {
  height: auto;
  padding: 0;
  border: none;
  border-radius: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: .5;
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%235f6368'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  padding-right: 28px;
  cursor: pointer;
}

select:disabled { cursor: not-allowed; opacity: .7; }

a { outline: none !important; border: none; }
a:link, a:visited, a:hover, a:active { outline: none; border: none; text-decoration: none; }

/* Edge 下 visited link 会变颜色——重置 */
a.dropdown-item:visited { color: var(--text); }

/* hidden —— 用 CSS class 控制显示（比 hidden 属性在 Edge 下更稳） */
.is-hidden { display: none !important; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 64px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.brand-logo { font-size: 24px; }

.main-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  overflow: visible;
}

.nav-item {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
  text-decoration: none;
  font-size: 14px;
  font-family: inherit;
  /* button 类型 nav-item 不需要单独 border/outline */
}

a.nav-item {
  border: none;
  background: transparent;
}

button.nav-item {
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
}

.nav-item:hover {
  background: #f1f3f4;
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* 导航下拉组 */
.nav-group { position: relative; }

/* 父分组高亮：当子页面 active 时，父按钮也要高亮 */
.nav-group.active .nav-item.nav-trigger {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.nav-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.nav-caret {
  font-size: 10px;
  opacity: .6;
  transition: transform .15s;
}

.nav-group.open .nav-caret { transform: rotate(180deg); }

/* ===== 导航下拉菜单 —— 完全独立，不依赖 .dropdown 类 ===== */
.nav-dropdown {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  min-width: 160px;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  z-index: 100;
}

.nav-dropdown .dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  text-decoration: none;
}

.nav-dropdown .dropdown-item:hover { background: #f1f3f4; }

.nav-dropdown .dropdown-item.active {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.activity-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-weight: 500;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f3f4;
  color: var(--text);
  vertical-align: middle;
}
.table tbody tr:hover { background: #fafbfc; }
.table .empty-row td {
  text-align: center;
  padding: 40px 12px;
  color: var(--text-secondary);
}

.user-menu { position: relative; }

.user-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.user-button:hover { background: #f1f3f4; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary-light);
}

.role-chip {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 12px;
}

.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 180px;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-2);
}

.dropdown-meta {
  padding: 8px 14px;
  color: var(--text-secondary);
  font-size: 12px;
  border-bottom: 1px solid #f1f3f4;
  word-break: break-all;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.dropdown-item:hover { background: #f1f3f4; }

/* ---------- Layout ---------- */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-dark);                    /* 降级兜底色 */
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 65%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;          /* 渐变文字 */
}

.page-desc {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  margin-bottom: 20px;
}

.panel-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.panel-text {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ---------- Cards ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.metric-card {
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  transition: box-shadow .15s, transform .15s;
}

.metric-card:hover {
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

.metric-label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 30px;
  font-weight: 600;
  color: var(--primary-dark);
  line-height: 1.2;
}

.metric-card.skeleton {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, border-color .15s;
  white-space: nowrap;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-1);
}

.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: var(--shadow-2); }

.btn-ghost {
  background: var(--surface);
  color: var(--primary-dark);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) { background: var(--primary-light); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: #fad2cf;
}

.btn-danger:hover:not(:disabled) { background: #fce8e6; }

.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.field-label {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
}

.field-full {
  grid-column: 1 / -1;
}

.field input,
.field select {
  width: 100%;
  /* height/font-size/border 等由全局 input,select 规则统一 */
}

/* ---------- Toolbar / Filter (列表页过滤栏) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 23px;             /* column 8px, row 23px ← 统一行间距 */
  margin-bottom: 16px;
}

.toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 23px;             /* column 8px, row 23px ← 统一行间距 */
  flex: 1;
}

/* 过滤栏里的 field-inline —— 一行 3 列 */
.filter-group .field-inline {
  flex: 0 1 200px;           /* 基础宽度，让 3 个能挤下一行 */
  min-width: 150px;
  max-width: 240px;
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 1 auto;
  color: var(--text-secondary);
  font-size: 12px;
}

.field-inline input,
.field-inline select {
  width: 100%;
}

/* activity picker select —— 只设尺寸 */
.activity-picker select {
  min-width: 130px;
}

/* ---------- Form Grid (表单页一行 3 列) ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 23px 23px;            /* row/column 都是 23px ← 统一行间距 */
  padding: 4px 0;
  /* 去掉 panel 包边：表单输入区域不用白底描边卡片，控件自身带边框 */
  background: transparent;
  border: none;
  box-shadow: none;
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* 表单页字段横排：标签在左、控件在右，同一行 */
.form-grid .field {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 4px 10px;
}

.form-grid .field > .field-label {
  flex: 0 0 auto;
  white-space: nowrap;
  line-height: 32px;      /* 与单行控件同高，视觉垂直居中 */
}

.form-grid .field > input,
.form-grid .field > select,
.form-grid .field > textarea,
.form-grid .field > div {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
}

.form-grid .field > small {
  flex-basis: 100%;       /* 提示文字独占一行，放在控件下方 */
  line-height: 1.4;
}

/* checkbox 行（如员工表单的允许群发/允许编辑SOP）——不跨列时跟在前一字段同一行 */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 24px;
}

.checkbox-inline span { white-space: nowrap; }

/* ===== 行式三列表单（试卷表单启用，可复用） =====
   .form-box：纯分组容器，只控制内部行间距；
   背景色/边框已去掉，由外层 .panel 统一负责边界
   .form-lines：整个基本信息区是一个网格，一行三组「标签+控件」；
   标签宽度按字数自适应（不统一定宽），字数相近的标签放同一列；
   标签与对应控件间距 32px（约 2.5 个汉字）；
   控件宽度按列的实际输入内容分档（w-md=180 / w-lg=240），同一列必须同宽；
   .lb-4/.lb-6：列内标签盒定宽 = 该列最宽标签，保证同列控件起点对齐 */
.form-box > * + * { margin-top: 23px; }

.form-lines {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  justify-content: space-between;
  gap: 23px;
}

.form-line-block { display: flex; }

.form-lines .field,
.form-line-block .field {
  flex-direction: row;
  align-items: center;
  gap: 32px;                 /* 标签与控件间距 ≈ 2.5 个汉字 */
}

.form-lines .field > .field-label,
.form-line-block .field > .field-label {
  flex: 0 0 auto;            /* 标签宽度按字数自适应 */
  white-space: nowrap;
  line-height: 32px;
}

/* 控件宽度按列的输入内容分档（同一列内宽度必须相同） */
.form-lines .field.w-sm > input,
.form-lines .field.w-sm > select { width: 120px; flex: 0 0 auto; }
.form-lines .field.w-md > input,
.form-lines .field.w-md > select { width: 180px; flex: 0 0 auto; }
.form-lines .field.w-lg > input,
.form-lines .field.w-lg > select { width: 240px; flex: 0 0 auto; }

/* 列内标签盒定宽 = 该列最宽标签（em ≈ 汉字数），
   保证同列上下两行的输入框/下拉框起点对齐；
   标签文字不足盒宽时留白，视觉间距仍控制在 2-5 字符内 */
.form-lines .field > .field-label.lb-2 { width: 2em; }
.form-lines .field > .field-label.lb-3 { width: 3em; }
.form-lines .field > .field-label.lb-4 { width: 4em; }
.form-lines .field > .field-label.lb-5 { width: 5em; }
.form-lines .field > .field-label.lb-6 { width: 6em; }
.form-lines .field > .field-label.lb-8 { width: 8em; }

/* 新增窄档位：超短内容（如启用开关、个位数输入） */
.form-lines .field.w-xs > input,
.form-lines .field.w-xs > select { width: 90px; flex: 0 0 auto; }

.form-line-block .field { flex: 1 1 auto; }
.form-line-block .field > textarea { flex: 1 1 auto; width: auto; min-width: 0; }

@media (max-width: 1140px) {
  .form-lines { grid-template-columns: 1fr; justify-content: stretch; }
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ---------- form-inline (独立 inline 表单) ---------- */
.form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 23px;             /* row 23px */
  margin-bottom: 14px;
}

.form-inline .field-inline {
  flex: 0 1 200px;
  min-width: 150px;
  max-width: 240px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}
/* checkbox-inline 的 input 样式已由全局 input[type="checkbox"] 统一 */

/* ---------- Simulate ---------- */
.simulate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
}

.simulate-grid .panel { margin-bottom: 0; }

.result-box {
  margin: 12px 0 0;
  padding: 12px 14px;
  max-height: 240px;
  overflow: auto;
  background: #202124;
  color: #e8eaed;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-warn { background: #fef7e0; color: #b06000; }

/* ---------- Auth ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f0fe 0%, #f6f8fc 60%, #eef3ff 100%);
}

.auth-wrap { width: 100%; max-width: 420px; padding: 24px; }

.auth-card {
  padding: 32px 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--primary-dark);
}

.auth-sub {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.auth-divider {
  position: relative;
  margin: 20px 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
}

.auth-divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}

.auth-divider span {
  position: relative;
  padding: 0 12px;
  background: var(--surface);
}

.auth-hint {
  margin: 18px 0 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 240px;
  max-width: 420px;
  padding: 12px 16px;
  background: #323232;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow-2);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

@media (max-width: 860px) {
  .app-header { gap: 12px; padding: 0 12px; }
  .brand-name { display: none; }
  .activity-label { display: none; }
  .activity-picker select { min-width: 110px; }
  .page { padding: 16px; }
  .simulate-grid { grid-template-columns: 1fr; }
}

/* ---------- Badge ---------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: 12px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 500;
}

.badge-success { background: #e6f4ea; color: var(--success); }
.badge-info    { background: #e8f0fe; color: var(--info); }
.badge-warn    { background: #fef7e0; color: #c27000; }
.badge-muted   { background: #e8eaed; color: var(--muted); }
.badge-danger  { background: #fce8e6; color: var(--danger); }

/* ---------- Activity detail layout ---------- */
.detail-top {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.detail-info .info-list {
  margin: 0;
  display: grid;
  gap: 10px 14px;
  font-size: 13px;
}

.detail-info .info-list dt {
  color: var(--text-secondary);
  font-weight: 500;
}

.detail-info .info-list dd {
  margin: 0;
  color: var(--text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.metric-card {
  background: #f8f9fa;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  padding: 14px 16px;
}

.metric-card .metric-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--primary-dark);
  line-height: 1;
}

.metric-card .metric-label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.metric-card.skeleton {
  color: var(--text-secondary);
  text-align: center;
  padding: 32px 0;
}

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  padding: 10px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.pager .pager-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.pager .pager-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.pager .pager-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

@media (max-width: 860px) {
  .detail-top { grid-template-columns: 1fr; }
}
