/* ============================================================
   索微运营中心 · 组件库 v2
   依赖：tokens.css（必须先引入）
   引入方式：<link rel="stylesheet" href="/static/design/v2/components.css">
   ============================================================ */

/* ============================================================
   1. 应用骨架（Layout）
   ============================================================ */

/* 应用容器 - 全屏 flex */
.sw-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* 侧边栏 */
.sw-sidebar {
  width: var(--sw-sidebar-w);
  flex-shrink: 0;
  background: var(--sw-bg-sidebar);
  border-right: 0.5px solid var(--sw-border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
}

/* 品牌区（基于真截图诊断：紧凑、有视觉块感） */
.sw-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 6px 14px;
  margin-bottom: 14px;
  text-decoration: none;
  color: inherit;
  border-bottom: 0.5px solid var(--sw-border);
}

.sw-sidebar-brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--sw-accent);
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.sw-sidebar-brand-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.sw-sidebar-brand-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--sw-text);
  letter-spacing: 0;
  margin: 0;
}

.sw-sidebar-brand-sub {
  font-size: 12px;
  color: var(--sw-text-muted);
  letter-spacing: 0;
  margin-top: 2px;
  text-transform: none;
  font-weight: var(--sw-fw-regular);
}

/* ============================================================
   侧栏二级菜单（数据看板下拉等）
   ============================================================ */
.sw-nav-group {
  display: flex;
  flex-direction: column;
}

/* 二级菜单 toggle（按 Linear/Vercel 重做） */
.sw-nav-item-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--sw-fs-md);
  color: var(--sw-text-muted);
  padding: 9px 10px;
  border-radius: var(--sw-radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background var(--sw-dur-fast), color var(--sw-dur-fast);
  line-height: 1.3;
}
.sw-nav-item-toggle:hover {
  background: var(--sw-bg-hover);
  color: var(--sw-text);
}
.sw-nav-group.is-open .sw-nav-item-toggle {
  color: var(--sw-text);            /* 展开时主题色加深，暗示活跃 */
}
.sw-nav-item-toggle.is-active {
  background: var(--sw-bg-active);
  color: var(--sw-text);
  font-weight: var(--sw-fw-medium);
}
.sw-nav-item-toggle .arrow {
  font-size: 10px;
  color: var(--sw-text-faint);
  transition: transform var(--sw-dur-fast);
  display: inline-block;
}
.sw-nav-group.is-open .sw-nav-item-toggle .arrow {
  transform: rotate(90deg);
  color: var(--sw-text-muted);
}

/* 子菜单（关键：同字号、不缩进容器、用左 padding 内凹） */
.sw-nav-children {
  display: none;
  padding: 0;                       /* 移除外缩进 */
}
.sw-nav-group.is-open .sw-nav-children {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sw-nav-child {
  font-size: var(--sw-fs-base);     /* 12px，比一级菜单 13 弱半档 */
  color: var(--sw-text-faint);      /* faint 比 muted 更弱，体现"次要" */
  padding: 7px 10px 7px 26px;       /* 左 padding 制造内凹（同列起点+文字往右）*/
  border-radius: var(--sw-radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: block;
  line-height: 1.3;
  position: relative;
  transition: color var(--sw-dur-fast), background var(--sw-dur-fast);
}
.sw-nav-child:hover {
  background: var(--sw-bg-hover);
  color: var(--sw-text-muted);      /* hover 提升一档（faint → muted） */
}
.sw-nav-child.is-active {
  color: var(--sw-text);             /* 只用文字色暗示，不用背景（避免双重活跃） */
  font-weight: var(--sw-fw-medium);
  background: transparent;
}
.sw-nav-child.is-active::before {
  content: "";
  position: absolute;
  left: 12px;                       /* 子菜单的左竖条放在缩进里 */
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 14px;
  background: var(--sw-accent);
  border-radius: 0 2px 2px 0;
}

.sw-sidebar-group {
  font-size: var(--sw-fs-sm);
  color: var(--sw-text-faint);
  padding: 4px 8px;
  margin: 12px 0 4px;
  letter-spacing: var(--sw-track-widest);
}

.sw-sidebar-group:first-of-type { margin-top: 0; }

.sw-nav-item {
  font-size: var(--sw-fs-md);
  color: var(--sw-text-muted);
  padding: 9px 10px;
  border-radius: var(--sw-radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: block;
  line-height: 1.3;
  position: relative;                  /* 给 active 左竖条做定位锚点 */
  transition: background var(--sw-dur-fast) var(--sw-ease),
              color var(--sw-dur-fast) var(--sw-ease);
}

.sw-nav-item:hover {
  background: var(--sw-bg-hover);
  color: var(--sw-text);
}

.sw-nav-item.is-active {
  background: var(--sw-bg-active);
  color: var(--sw-text);
  font-weight: var(--sw-fw-medium);
}

/* active 左竖条（Linear/Vercel 标准）—— 让当前页一眼可见 */
.sw-nav-item.is-active::before {
  content: "";
  position: absolute;
  left: -12px;                          /* 顶到 sidebar padding 边缘 */
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--sw-accent);
  border-radius: 0 2px 2px 0;
}

/* 二级菜单（缩进 + 小圆点） */
.sw-nav-sub {
  padding: 0 8px 0 22px;
}

.sw-nav-sub-item {
  font-size: var(--sw-fs-base);
  color: var(--sw-text-muted);
  padding: 8px 0;               /* 提升触摸目标 */
  cursor: pointer;
  line-height: 1.3;
}

.sw-nav-sub-item::before {
  content: "·";
  margin-right: var(--sw-space-2);
  color: var(--sw-text-faint);
}

.sw-nav-sub-item.is-active {
  color: var(--sw-text);
  font-weight: var(--sw-fw-medium);
}

/* 主区 */
.sw-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;   /* 关键：让 flex 子元素被约束（参考 wiki/前端Flex滚动布局） */
}

/* 顶栏 */
.sw-topbar {
  height: var(--sw-topbar-h);
  border-bottom: 0.5px solid var(--sw-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sw-content-px);
  flex-shrink: 0;
  background: var(--sw-bg-page);
}

.sw-topbar-title {
  font-size: var(--sw-fs-lg);
  font-weight: var(--sw-fw-medium);
  color: var(--sw-text);
}

.sw-topbar-title-meta {
  color: var(--sw-text-faint);
  font-weight: var(--sw-fw-regular);
  margin-left: var(--sw-space-2);
}

.sw-topbar-right {
  font-size: var(--sw-fs-sm);
  color: var(--sw-text-faint);
  letter-spacing: var(--sw-track-wide);
  display: flex;
  align-items: center;
  gap: var(--sw-space-5);
}

/* 内容区 - 必须可滚动 */
.sw-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sw-content-py) var(--sw-content-px);
  padding-bottom: 60px;   /* 防止底部内容被截断 */
}

/* ============================================================
   1.5 页面大标题（content 区顶部的欢迎/页面名）
   ============================================================ */

.sw-page-title {
  font-size: 28px;
  font-weight: var(--sw-fw-medium);
  color: var(--sw-text);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 6px;
}

.sw-page-subtitle {
  font-size: var(--sw-fs-md);
  color: var(--sw-text-muted);
  margin: 0 0 var(--sw-space-9);
  line-height: 1.6;
}

/* ============================================================
   2. 卡片
   ============================================================ */

.sw-card {
  background: var(--sw-bg-surface);
  border: 0.5px solid var(--sw-border);
  border-radius: var(--sw-radius-md);
  padding: var(--sw-space-6) var(--sw-space-7);
}

.sw-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sw-space-5);
}

.sw-card-title {
  font-size: var(--sw-fs-md);
  color: var(--sw-text);
  font-weight: var(--sw-fw-medium);
}

.sw-card-meta {
  font-size: var(--sw-fs-sm);
  color: var(--sw-text-faint);
}

/* KPI 卡 */
.sw-kpi {
  background: var(--sw-bg-surface);
  border: 0.5px solid var(--sw-border);
  border-radius: var(--sw-radius-md);
  padding: var(--sw-space-6) var(--sw-space-7);   /* 与 .sw-card 对齐 */
}

.sw-kpi-label {
  font-size: var(--sw-fs-sm);
  color: var(--sw-text-faint);
  margin-bottom: var(--sw-space-2);
  letter-spacing: var(--sw-track-wide);
}

.sw-kpi-value {
  font-family: var(--sw-font-num);
  font-size: var(--sw-fs-3xl);
  font-weight: var(--sw-fw-bold);          /* 加重到 600 */
  color: var(--sw-text);
  letter-spacing: var(--sw-track-tight);
  line-height: 1.1;                        /* 数字行高更紧 */
  font-feature-settings: "tnum" 1, "lnum" 1;  /* 表格数字模式 + 等高 */
}

.sw-kpi-delta {
  font-size: var(--sw-fs-sm);
  margin-top: var(--sw-space-1);
}

.sw-kpi-delta.is-up   { color: var(--sw-success-fg); }
.sw-kpi-delta.is-down { color: var(--sw-danger-fg); }

/* KPI 网格 */
.sw-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sw-gap-tight);
  margin-bottom: var(--sw-space-7);
}

@media (max-width: 768px) {
  .sw-kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   3. 按钮
   ============================================================ */

.sw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sw-space-2);
  padding: 7px 14px;
  font-size: var(--sw-fs-base);
  font-family: inherit;
  font-weight: var(--sw-fw-regular);
  line-height: 1;
  border-radius: var(--sw-radius-sm);
  border: 0.5px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background var(--sw-dur-fast) var(--sw-ease),
              border-color var(--sw-dur-fast) var(--sw-ease),
              transform var(--sw-dur-fast) var(--sw-ease);
}

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

.sw-btn:focus-visible { outline: none; box-shadow: var(--sw-focus-ring); }

.sw-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* 主按钮：黑底反白 */
.sw-btn-primary {
  background: var(--sw-accent);
  color: var(--sw-accent-on);
}

.sw-btn-primary:hover:not(:disabled) {
  background: var(--sw-accent-hover);
}

/* 次按钮：白底 + 边框 */
.sw-btn-secondary {
  background: var(--sw-bg-surface);
  color: var(--sw-text-body);
  border-color: var(--sw-border);
}

.sw-btn-secondary:hover:not(:disabled) {
  border-color: var(--sw-border-strong);
  background: var(--sw-bg-hover);
}

/* 幽灵按钮：透明 */
.sw-btn-ghost {
  background: transparent;
  color: var(--sw-text-muted);
}

.sw-btn-ghost:hover:not(:disabled) {
  background: var(--sw-bg-hover);
  color: var(--sw-text);
}

/* 文字链 */
.sw-link {
  color: var(--sw-link);
  text-decoration: none;
  font-size: var(--sw-fs-sm);
  cursor: pointer;
}

.sw-link:hover { color: var(--sw-link-hover); text-decoration: underline; }

/* ============================================================
   4. 输入框 / 表单
   ============================================================ */

.sw-input,
.sw-select {
  background: var(--sw-bg-page);
  border: 0.5px solid var(--sw-border);
  border-radius: var(--sw-radius-sm);
  padding: 7px 10px;
  font-size: var(--sw-fs-base);
  font-family: inherit;
  color: var(--sw-text);
  transition: border-color var(--sw-dur-fast) var(--sw-ease);
  width: 100%;
}

.sw-input::placeholder { color: var(--sw-text-faint); }

.sw-input:hover,
.sw-select:hover { border-color: var(--sw-border-strong); }

.sw-input:focus,
.sw-select:focus {
  outline: none;
  border-color: var(--sw-link);
  box-shadow: var(--sw-focus-ring);
}

.sw-label {
  display: block;
  font-size: var(--sw-fs-base);
  color: var(--sw-text-muted);
  margin-bottom: var(--sw-space-2);
}

/* 筛选条 */
.sw-filter-bar {
  display: flex;
  gap: var(--sw-space-3);
  margin-bottom: var(--sw-space-5);
  flex-wrap: wrap;
  align-items: center;
}

.sw-filter-chip {
  background: var(--sw-bg-surface);
  border: 0.5px solid var(--sw-border);
  border-radius: var(--sw-radius-sm);
  padding: 6px 10px;
  font-size: var(--sw-fs-base);
  color: var(--sw-text-body);
  cursor: pointer;
  transition: border-color var(--sw-dur-fast) var(--sw-ease);
}

.sw-filter-chip:hover { border-color: var(--sw-border-strong); }

/* ============================================================
   5. 表格
   ============================================================ */

.sw-table {
  background: var(--sw-bg-surface);
  border: 0.5px solid var(--sw-border);
  border-radius: var(--sw-radius-md);
  overflow: hidden;
  width: 100%;
}

.sw-thead {
  display: grid;
  padding: var(--sw-space-3) var(--sw-space-7);
  font-size: var(--sw-fs-xs);
  color: var(--sw-text-faint);
  background: var(--sw-bg-subtle);
  border-bottom: 0.5px solid var(--sw-border);
  letter-spacing: var(--sw-track-wide);
}

.sw-trow {
  display: grid;
  padding: 12px var(--sw-space-7);     /* 提升到 ~44px 行高（触摸目标） */
  font-size: var(--sw-fs-base);
  color: var(--sw-text-body);
  border-bottom: 0.5px solid var(--sw-border-soft);
  align-items: center;
  transition: background var(--sw-dur-fast) var(--sw-ease);
}

.sw-trow:last-child { border-bottom: none; }

.sw-trow:hover { background: var(--sw-bg-hover); }   /* 用 hover 色，区分度更高 */

.sw-trow .num {
  font-family: var(--sw-font-num);
  color: var(--sw-text);
}

/* ============================================================
   6. 状态 pill / 标签 / 状态点
   ============================================================ */

.sw-pill {
  display: inline-block;
  font-size: var(--sw-fs-xs);
  padding: 1px 6px;
  border-radius: var(--sw-radius-xs);
  letter-spacing: var(--sw-track-wide);
  line-height: 1.5;
}

.sw-pill-success { background: var(--sw-success-bg); color: var(--sw-success-fg); }
.sw-pill-warning { background: var(--sw-warning-bg); color: var(--sw-warning-fg); }
.sw-pill-danger  { background: var(--sw-danger-bg);  color: var(--sw-danger-fg); }
.sw-pill-info    { background: var(--sw-info-bg);    color: var(--sw-info-fg); }
.sw-pill-neutral { background: var(--sw-neutral-bg); color: var(--sw-neutral-fg); }

.sw-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  vertical-align: middle;
}

.sw-dot-ok   { background: var(--sw-dot-ok); }
.sw-dot-warn { background: var(--sw-dot-warn); }
.sw-dot-err  { background: var(--sw-dot-err); }

/* ============================================================
   7. 空状态 / Toast / Modal
   ============================================================ */

.sw-empty {
  text-align: center;
  padding: 48px var(--sw-space-7);
  color: var(--sw-text-faint);
  font-size: var(--sw-fs-md);
}

.sw-empty-title {
  color: var(--sw-text-muted);
  font-size: var(--sw-fs-lg);
  margin-bottom: var(--sw-space-2);
}

.sw-toast {
  background: var(--sw-bg-surface);
  border: 0.5px solid var(--sw-border);
  border-radius: var(--sw-radius-sm);
  padding: var(--sw-space-5) var(--sw-space-7);
  font-size: var(--sw-fs-md);
  color: var(--sw-text);
  box-shadow: var(--sw-shadow-md);
  display: inline-flex;
  align-items: center;
  gap: var(--sw-space-3);
}

.sw-modal-backdrop {
  background: rgba(20, 23, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sw-space-7);
}

.sw-modal {
  background: var(--sw-bg-surface);
  border-radius: var(--sw-radius-md);
  border: 0.5px solid var(--sw-border);
  box-shadow: var(--sw-shadow-lg);
  width: 100%;
  max-width: 480px;
  padding: var(--sw-space-9);
}

/* ============================================================
   8. 移动端适配（@media block 回退，参考 wiki/前端Flex滚动布局）
   ============================================================ */

@media (max-width: 768px) {
  body {
    display: block;
    overflow: auto;
    height: auto;
    min-height: 100vh;
  }
  .sw-app {
    display: block;
    height: auto;
    overflow: visible;
  }
  .sw-sidebar {
    display: none;   /* 移动端可改为抽屉，先隐藏 */
  }
  .sw-main {
    display: block;
    flex: none;
    height: auto;
    overflow: visible;
  }
  .sw-content {
    flex: none;
    overflow: visible;
    height: auto;
    padding: var(--sw-space-7);
  }
  .sw-kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
