/* ==========================================================================
   Infiai 统一外壳（Shell）
   —— 顶栏 + 二级导航 + 设计 token

   所有后台页面共用此文件。导航项在 static/js/shell.js 中单点定义，
   页面只需放置 <div id="app-shell"></div> 并引入本文件与 shell.js。

   【修改前必读】管理后台前端设计规范：docs/FRONTEND_DESIGN_SYSTEM.md
   本文件是该规范中「设计 Token」「顶栏规范」「二级导航规范」的实现，
   新增颜色/间距/圆角前请先确认规范中是否已有对应 token。
   ========================================================================== */

:root {
  /* 主色 */
  --shell-primary: #4f46e5;
  --shell-primary-hover: #4338ca;
  --shell-primary-soft: #eef2ff;

  /* 语义色 */
  --shell-success: #16a34a;
  --shell-warning: #d97706;
  --shell-danger: #dc2626;
  --shell-danger-soft: #fef2f2;

  /* 中性色 */
  --shell-bg: #f8fafc;
  --shell-surface: #ffffff;
  --shell-surface-hover: #f1f5f9;
  --shell-border: #e2e8f0;
  --shell-border-strong: #cbd5e1;
  --shell-text: #0f172a;
  --shell-text-muted: #475569;
  --shell-text-subtle: #64748b;

  /* 间距（4/8 体系） */
  --shell-space-1: 4px;
  --shell-space-2: 8px;
  --shell-space-3: 12px;
  --shell-space-4: 16px;
  --shell-space-5: 20px;
  --shell-space-6: 24px;

  /* 圆角 */
  --shell-radius-sm: 6px;
  --shell-radius-md: 8px;
  --shell-radius-lg: 12px;

  /* 阴影 */
  --shell-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shell-shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);

  /* 字号 */
  --shell-font-xs: 12px;
  --shell-font-sm: 13px;
  --shell-font-base: 14px;
  --shell-font-lg: 15px;
  --shell-font-xl: 18px;

  /* 层级 */
  --shell-z-header: 50;

  /* 动效 */
  --shell-ease: 150ms cubic-bezier(0.4, 0, 0.2, 1);

  /* 字体栈 */
  --shell-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

/* ===== 页面基底 ===== */
/* 各内容页不必重复声明字体与画布色；页面 @head 中的同名规则仍可覆盖 */
body {
  margin: 0;
  font-family: var(--shell-font-family);
  background: var(--shell-bg);
  color: var(--shell-text);
  -webkit-font-smoothing: antialiased;
}

/* ===== 挂载点 ===== */
/* 页面 body 多为 flex 纵向布局，外壳不应被压缩 */
#app-shell {
  display: block;
  flex-shrink: 0;
}

/* ===== 顶栏 ===== */
.shell-header {
  flex-shrink: 0;
  position: relative;
  z-index: var(--shell-z-header);
  display: flex;
  align-items: stretch;
  height: 56px;
  padding: 0 var(--shell-space-5);
  background: var(--shell-surface);
  border-bottom: 1px solid var(--shell-border);
  box-shadow: var(--shell-shadow-sm);
  font-family: var(--shell-font-family);
}

.shell-brand {
  display: flex;
  align-items: center;
  gap: var(--shell-space-2);
  padding-right: var(--shell-space-5);
  font-size: var(--shell-font-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--shell-text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.shell-brand-logo {
  display: block;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.shell-nav {
  display: flex;
  flex: 1;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.shell-nav::-webkit-scrollbar {
  display: none;
}

/* 宽度不足时导航可横向滚动（滚轮/触摸板）：滚动条保持隐藏避免挤压 tab 高度，
   改用边缘渐隐提示还有更多内容；is-overflow-* 由 shell.js 按滚动位置切换 */
.shell-nav.is-overflow-left:not(.is-overflow-right) {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px);
  mask-image: linear-gradient(to right, transparent 0, #000 24px);
}

.shell-nav.is-overflow-right:not(.is-overflow-left) {
  -webkit-mask-image: linear-gradient(to left, transparent 0, #000 24px);
  mask-image: linear-gradient(to left, transparent 0, #000 24px);
}

.shell-nav.is-overflow-left.is-overflow-right {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent);
}

.shell-nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--shell-space-3);
  font-size: var(--shell-font-sm);
  font-weight: 500;
  color: var(--shell-text-muted);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--shell-ease), background-color var(--shell-ease);
}

.shell-nav-item i {
  font-size: 13px;
  opacity: 0.75;
  transition: opacity var(--shell-ease);
}

.shell-nav-item:hover {
  color: var(--shell-text);
  background: var(--shell-surface-hover);
}

.shell-nav-item:hover i {
  opacity: 1;
}

.shell-nav-item.is-active {
  font-weight: 600;
  color: var(--shell-primary);
  border-bottom-color: var(--shell-primary);
}

.shell-nav-item.is-active i {
  opacity: 1;
}

.shell-nav-item:focus-visible,
.shell-subnav-item:focus-visible,
.shell-logout:focus-visible,
.shell-brand:focus-visible {
  outline: 2px solid var(--shell-primary);
  outline-offset: -2px;
}

.shell-user {
  display: flex;
  align-items: center;
  gap: var(--shell-space-3);
  padding-left: var(--shell-space-4);
  white-space: nowrap;
  flex-shrink: 0;
}

.shell-user-name {
  font-size: var(--shell-font-sm);
  color: var(--shell-text-subtle);
}

/* ===== 用户信息区：头像 + hover 详情卡 ===== */
.shell-profile {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--shell-space-2);
  cursor: default;
}

.shell-avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  background: var(--shell-primary-soft);
}

/* 接口未返回头像时，用姓名首字生成的文字头像 */
.shell-avatar--fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--shell-font-xs);
  font-weight: 600;
  color: var(--shell-primary);
}

/* 详情卡：展示接口返回的部门 / 职位 / 邮箱 / 星座等，用于确认接口连通 */
.shell-profile-card {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 100;
  min-width: 240px;
  max-width: min(360px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: var(--shell-space-3) var(--shell-space-4);
  font-family: var(--shell-font-family);
  white-space: normal;
  background: var(--shell-surface);
  border: 1px solid var(--shell-border);
  border-radius: var(--shell-radius-md);
  box-shadow: var(--shell-shadow-md);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity var(--shell-ease), transform var(--shell-ease), visibility var(--shell-ease);
}

.shell-profile-card:empty {
  display: none;
}

.shell-profile:hover .shell-profile-card,
.shell-profile:focus-within .shell-profile-card {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.shell-profile-row {
  display: flex;
  gap: var(--shell-space-3);
  padding: 3px 0;
  font-size: var(--shell-font-xs);
  line-height: 1.6;
}

.shell-profile-row > span {
  flex-shrink: 0;
  width: 44px;
  color: var(--shell-text-subtle);
}

.shell-profile-row > b {
  min-width: 0;
  font-weight: 500;
  color: var(--shell-text);
  word-break: break-all;
}

.shell-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px var(--shell-space-3);
  font-family: inherit;
  font-size: var(--shell-font-sm);
  color: var(--shell-text-muted);
  background: var(--shell-surface);
  border: 1px solid var(--shell-border-strong);
  border-radius: var(--shell-radius-sm);
  cursor: pointer;
  transition: color var(--shell-ease), border-color var(--shell-ease), background-color var(--shell-ease);
}

.shell-logout:hover {
  color: var(--shell-danger);
  border-color: var(--shell-danger);
  background: var(--shell-danger-soft);
}

/* ===== 二级导航 ===== */
.shell-subnav {
  flex-shrink: 0;
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 44px;
  padding: 0 var(--shell-space-5);
  background: var(--shell-surface);
  border-bottom: 1px solid var(--shell-border);
  font-family: var(--shell-font-family);
  overflow-x: auto;
  scrollbar-width: none;
}

.shell-subnav::-webkit-scrollbar {
  display: none;
}

/* 与顶栏导航同规则：滚动条隐藏，边缘渐隐提示可横向滚动 */
.shell-subnav.is-overflow-left:not(.is-overflow-right) {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px);
  mask-image: linear-gradient(to right, transparent 0, #000 24px);
}

.shell-subnav.is-overflow-right:not(.is-overflow-left) {
  -webkit-mask-image: linear-gradient(to left, transparent 0, #000 24px);
  mask-image: linear-gradient(to left, transparent 0, #000 24px);
}

.shell-subnav.is-overflow-left.is-overflow-right {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent);
}

.shell-subnav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--shell-space-3);
  font-size: var(--shell-font-sm);
  color: var(--shell-text-subtle);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color var(--shell-ease), background-color var(--shell-ease);
}

.shell-subnav-item:hover {
  color: var(--shell-text);
  background: var(--shell-surface-hover);
}

.shell-subnav-item.is-active {
  font-weight: 600;
  color: var(--shell-primary);
  border-bottom-color: var(--shell-primary);
}

/* ===== 二级导航：深色变体（供视觉处理等深色模块使用） ===== */
.shell-subnav--dark {
  background: #1a1d29;
  border-bottom-color: #2a2f3e;
}

.shell-subnav--dark .shell-subnav-item {
  color: #94a3b8;
}

.shell-subnav--dark .shell-subnav-item:hover {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.06);
}

.shell-subnav--dark .shell-subnav-item.is-active {
  color: #a5b4fc;
  border-bottom-color: #818cf8;
}

/* ===== 按钮规范 =====
   层次原则：一屏之内只保留一个实心按钮（主操作），其余一律白底描边。
   危险 / 成功 / 警告按钮默认只描边，hover 时才填充实心——避免整屏颜色过重。
   新页面请直接使用 .shell-btn 系列；老页面保留原类名，但配色须与此处一致。 */
.shell-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px var(--shell-space-3);
  font-family: inherit;
  font-size: var(--shell-font-sm);
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: var(--shell-radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--shell-ease), border-color var(--shell-ease), color var(--shell-ease);
}

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

.shell-btn--primary:hover {
  background: var(--shell-primary-hover);
  border-color: var(--shell-primary-hover);
}

.shell-btn--secondary {
  background: var(--shell-surface);
  border-color: var(--shell-border-strong);
  color: var(--shell-text-muted);
}

.shell-btn--secondary:hover {
  background: var(--shell-surface-hover);
  border-color: var(--shell-text-subtle);
  color: var(--shell-text);
}

.shell-btn--ghost {
  background: transparent;
  color: var(--shell-text-muted);
}

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

.shell-btn--danger {
  background: var(--shell-surface);
  border-color: #fecaca;
  color: var(--shell-danger);
}

.shell-btn--danger:hover {
  background: var(--shell-danger);
  border-color: var(--shell-danger);
  color: #fff;
}

.shell-btn--success {
  background: var(--shell-surface);
  border-color: #bbf7d0;
  color: var(--shell-success);
}

.shell-btn--success:hover {
  background: var(--shell-success);
  border-color: var(--shell-success);
  color: #fff;
}

.shell-btn--warning {
  background: var(--shell-surface);
  border-color: #fde68a;
  color: var(--shell-warning);
}

.shell-btn--warning:hover {
  background: var(--shell-warning);
  border-color: var(--shell-warning);
  color: #fff;
}

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

.shell-btn:focus-visible {
  outline: 2px solid var(--shell-primary);
  outline-offset: 1px;
}

/* ===== 窄屏适配 ===== */
@media (max-width: 900px) {
  .shell-header,
  .shell-subnav {
    padding: 0 var(--shell-space-4);
  }

  .shell-brand {
    padding-right: var(--shell-space-3);
  }

  .shell-user-name {
    display: none;
  }
}

/* 手机宽度保留品牌可访问名称和账号操作，把有限空间留给可滚动导航。 */
@media (max-width: 600px) {
  .shell-brand > span {
    display: none;
  }

  .shell-user {
    position: relative;
    gap: var(--shell-space-2);
    padding-left: var(--shell-space-2);
  }

  .shell-profile {
    position: static; /* 资料卡相对完整账号区定位，避免从头像右边向左越过视口。 */
  }
}
