/* =====================================================================
   theme.css — v57 设计系统增强层（最后加载，可覆盖前序批次样式）
   ---------------------------------------------------------------------
   职责：
   1. 补齐前序批次中「被使用但从未定义」的类：
      .btn-xs / .form-input / .card-header / .card-title / .card-meta /
      .card-sub / .icon-btn / .global-search-* / .toast / .notif-badge …
   2. 统一 SVG 图标体系（替换 emoji 后的尺寸/对齐/颜色规则）
   3. 视觉打磨：焦点环、滚动条、侧边栏、徽章、表格、空态、暗色一致性
   4. 对比度修正（.user-role / .stat-subtitle 达到 WCAG AA）
   ===================================================================== */

/* ===== 1. 设计令牌补充（不改名，只补缺） ===== */
:root {
  /* 间距阶梯 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  /* 字号阶梯 */
  --font-xs: 11px;
  --font-sm: 12px;
  --font-md: 13px;
  --font-base: 14px;
  --font-lg: 16px;
  --font-xl: 18px;
  /* 层级表 */
  --z-dropdown: 1000;
  --z-sticky: 1100;
  --z-modal: 2000;
  --z-toast: 10000;
  /* 暗色统一表面色（收敛 #1e293b/#0f172a/#16213e/#1a1a24 四值并存问题） */
  --surface-1: #f8fafc;
  --surface-2: #ffffff;
  --surface-3: #f1f5f9;
  --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

[data-theme="dark"] {
  --surface-1: #0f172a;
  --surface-2: #1e293b;
  --surface-3: #273449;
}

/* ===== 2. 缺失组件补齐 ===== */

/* 超小按钮（views 中大量使用但从未定义，此前吃 .btn 默认 padding 与 btn-sm 混排大小不一） */
.btn.btn-xs {
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.5;
  gap: 3px;
  border-radius: var(--radius-sm);
}
.btn.btn-xs svg { vertical-align: -2px; }

/* 图标按钮：固定正方形命中区，居中 */
.btn.icon-btn {
  padding: 6px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.btn.icon-btn:hover { background: var(--bg-hover); }

/* .form-input：contracts.js 筛选栏使用但无基础样式（此前是浏览器默认外观） */
.input, .select, .textarea, .form-input {
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-sizing: border-box;
  outline: none;
  font-family: inherit;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.form-input::placeholder { color: var(--text-tertiary); }

/* 卡片元信息（contracts.js 卡片视图使用，此前排版裸奔） */
.card-list-item .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.card-list-item .card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-list-item .card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}
.card-list-item .card-meta svg { vertical-align: -2px; margin-right: 3px; }
.card-list-item .card-sub {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}
.card-list-item .icon {
  display: inline-flex;
  align-items: center;
  color: var(--text-tertiary);
}

/* ===== 3. 全局搜索框（v57 从内联样式迁入，主题令牌可作用） ===== */
.sidebar-search { padding: 8px 12px; }
.global-search-wrap { position: relative; }
.global-search-input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-hover);
  color: var(--text);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.global-search-input:focus {
  border-color: var(--primary);
  background: var(--bg-card);
  /* v96: 移除发光焦点环，保持扁平 */
  box-shadow: none;
}
.global-search-input::placeholder { color: var(--text-tertiary); }
.global-search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  display: inline-flex;
  pointer-events: none;
}

/* 搜索下拉结果项（v57：从内联样式迁入 + 键盘可达） */
.search-result-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-light);
}
.search-result-item:hover, .search-result-item:focus-visible { background: var(--bg-hover); outline: none; }
.search-result-icon { flex-shrink: 0; color: var(--primary); display: inline-flex; }
.search-result-body { flex: 1; min-width: 0; }
.search-result-title {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-result-sub {
  font-size: 11px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.search-result-field { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; }
.search-drop-label {
  padding: 8px 16px 4px; font-size: 11px;
  color: var(--text-tertiary); font-weight: 600;
}
.search-history-item { cursor: pointer; }
.search-history-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ===== 4. 侧边栏导航（SVG 图标化后的对齐与交互） ===== */
.sidebar .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  transition: color 0.15s ease;
}
.nav-item.active .nav-icon,
.nav-item.parent-active .nav-icon { color: var(--primary); }
.nav-item:hover .nav-icon { color: var(--primary); }
.sidebar-footer .nav-icon { color: inherit; }

/* 子菜单切换按钮：加大命中区（此前 4px padding 的 10px 字符，低于 24×24 最小命中） */
.nav-submenu-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  z-index: 5;
  padding: 0;
}
.nav-submenu-toggle:hover { background: var(--bg-hover); color: var(--text); }
.nav-submenu-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

/* 通知徽章（v57 从内联样式迁入） */
.notif-badge {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
.nav-item { position: relative; }

/* ===== 5. Toast（v57：类名实现替代内联 cssText，暗色/浅色自适应） ===== */
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  color: var(--text);
  max-width: 380px;
  animation: toastIn 0.25s ease-out;
}
.toast .toast-icon { display: inline-flex; flex-shrink: 0; }
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-error .toast-icon { color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }
.toast.toast-out { opacity: 0; transition: opacity 0.3s ease; }
@keyframes toastIn {
  from { transform: translateX(16px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== 6. 登录页打磨 ===== */
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}
.login-input-icon {
  display: inline-flex;
  align-items: center;
  color: var(--text-tertiary);
}
.login-input-wrap:focus-within .login-input-icon { color: var(--primary); }
.login-btn { letter-spacing: 4px; font-weight: 600; }

/* ===== 7. 全局体验细节 ===== */

/* 焦点环：键盘用户可见 */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn:focus-visible, .input:focus-visible, .select:focus-visible { outline: none; }

/* 细滚动条（WebKit + Firefox） */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* 文本选中色 */
::selection { background: rgba(99, 102, 241, 0.25); }

/* 对比度修正（WCAG AA：此前 11px #9ca3af 对比度约 2.6:1） */
.user-role { font-size: 12px; color: var(--text-secondary); }
.stat-subtitle { font-size: 12px; color: var(--text-secondary); }
.timeline-comment { font-size: 12px; }

/* btn-danger hover 与其他变体一致的实色深化 + 按压反馈 */
.btn-danger:hover { background: #dc2626; border-color: #dc2626; opacity: 1; }
.btn:active { transform: translateY(1px); }

/* 徽章统一圆角（收敛 20px 药丸与 4px 直角并存） */
.badge { border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 500; line-height: 1.5; }

/* 移动端头部按钮 */
.mobile-header .hamburger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.mobile-header .hamburger:active { background: var(--bg-hover); }

/* 表格行操作按钮统一几何（收敛 enhancements/batch5 两套定义） */
.row-actions .btn-xs { padding: 3px 7px; }
.row-actions { display: flex; align-items: center; gap: 4px; }

/* 空态统一：旧版 empty-state 与新版 empty-state-modern 视觉对齐 */
.empty-state { color: var(--text-secondary); }

/* 打印修正：data-print 时强制浅色（补上 app.js 设置了属性但无对应规则的缺口） */
@media print {
  [data-print="true"] {
    background: #fff !important;
    color: #111 !important;
  }
  [data-print="true"] .sidebar,
  [data-print="true"] .topbar-actions,
  [data-print="true"] .mobile-header { display: none !important; }
}
