/**
 * 基础样式。零构建，手写 CSS 变量。
 *
 * ⚠️ 移动优先：员工端跑在飞书/企微的 webview 里。
 *    - 触摸目标 ≥ 44px（Apple HIG 的下限，低于它误触率明显上升）
 *    - 不能依赖 :hover —— 触摸设备上 hover 状态会"粘住"
 *    - 要处理安全区（刘海屏），否则底部按钮会被 Home 指示条盖住
 */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1d21;
  --text-2: #5c6470;
  --text-3: #8b93a1;

  --brand: #1f5f7a;
  --brand-weak: #e6f0f4;
  --danger: #b4462f;
  --danger-weak: #fbeae6;
  --warn: #8a6512;
  --warn-weak: #fbf1dc;
  --ok: #3f6b3f;
  --ok-weak: #e8f1e8;

  --radius: 8px;
  --gap: 12px;
  --tap: 44px; /* 最小触摸目标 */

  --shadow: 0 1px 2px rgba(26, 29, 33, .06), 0 6px 16px -10px rgba(26, 29, 33, .25);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --surface: #1c2026;
    --surface-2: #232830;
    --border: #2e343d;
    --text: #e6eaef;
    --text-2: #a6afbb;
    --text-3: #78808c;
    --brand: #6fb0cb;
    --brand-weak: #16303c;
    --danger: #e08a72;
    --danger-weak: #3a201a;
    --warn: #d9b45e;
    --warn-weak: #33280f;
    --ok: #8fbb8f;
    --ok-weak: #1e2a1e;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  /* 安全区：刘海屏下不让内容贴到边 */
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--brand); }

/* ---------------------------------------------------------------- 布局 */
/* 左侧是**导航菜单**，不是组织树。
   组织树属于「员工」这一页的上下文，放在页内左栏（.page-aside）。
   两者混在一起时，切到「审计」还看着一棵组织树是件很怪的事——
   那棵树对当前页没有任何作用。 */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 10px; overflow-y: auto;
}
.main { padding: 20px 24px 60px; overflow-y: auto; }

/* ---------------------------------------------------------------- 菜单 */
/* 通栏竖排列表：条目占满侧栏宽度，选中态是一条整行的底色。
   窄条目 + 小圆角看起来像一排按钮，而菜单要看起来像**目录**。 */
.brand { padding: 2px 12px 16px; }
.brand strong { display: block; font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.brand .sub { display: block; font-size: 12px; color: var(--text-3); margin-top: 2px; }

.menu { list-style: none; margin: 0 0 2px; padding: 0; }

.menu-group + .menu-group { margin-top: 18px; }
.menu-group > .label {
  font-size: 11px; letter-spacing: .12em; color: var(--text-3);
  padding: 0 12px 6px;
}

.menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 6px;
  text-decoration: none; color: var(--text);
  font-size: 14.5px; line-height: 1.4;
}
.menu a:hover { background: var(--surface-2); }

/* 选中态：整行底色 + 加重字重。不用左侧竖条——
   竖条在分组标题旁边容易被看成"这一组被选中了" */
.menu a[aria-current="page"] {
  background: var(--brand-weak); color: var(--brand); font-weight: 600;
}
.menu a:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

/* 右侧计数（例如待办数）。没有数字时不占位 */
.menu .badge {
  margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--danger-weak); color: var(--danger);
  font-variant-numeric: tabular-nums; font-weight: 600;
}
.menu a[aria-current="page"] .badge { background: var(--surface); }

/* 页内左栏（组织树）。只有「员工」页用 */
.page-split { display: grid; grid-template-columns: 240px 1fr; gap: var(--gap); align-items: start; }
.page-aside {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; position: sticky; top: 20px;
  max-height: calc(100vh - 40px); overflow-y: auto;
}

/* ---------------------------------------------------------------- 分页 */
.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pager .range { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.pager .spacer { flex: 1; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); padding: 12px; }
  .main { padding: 16px; }
  /* 窄屏菜单横排，省掉纵向空间。
     nav 自己要变成 flex —— 光给 .menu-group 设 display:contents 是不够的，
     每个 ul 仍然是块级，结果是每组各占一行。 */
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .menu { display: flex; flex-wrap: wrap; gap: 4px; }
  .menu-group { margin-top: 0; display: contents; }
  .menu-group > .label { display: none; }
  .menu a {
    min-height: 44px;               /* 触摸目标 */
    border: 1px solid var(--border);
  }
  .menu a[aria-current="page"] { border-color: var(--brand); }
  .page-split { grid-template-columns: 1fr; }
  .page-aside { position: static; max-height: 40vh; }
}

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; align-items: center; gap: var(--gap); flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card .sub { margin: 0 0 12px; color: var(--text-2); font-size: 13px; }

/* ---------------------------------------------------------------- 控件 */
button, .btn {
  min-height: var(--tap); padding: 0 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  /* 触摸设备上去掉点击高亮的蓝框 */
  -webkit-tap-highlight-color: transparent;
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }

input, select, textarea {
  min-height: var(--tap); width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit;
}
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.field { margin-bottom: 12px; }

/* ⚠️ 上面的 `input, select, textarea` 给了 width:100% + min-height:var(--tap)，
   复选框套进去会变成一个占满整行的大方块。复选框要单独拉回来，
   并且让它和后面的文字排在同一行——label 是 display:block 的。 */
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.check input[type="checkbox"] {
  width: auto; min-height: 0; flex: none;
  width: 16px; height: 16px; margin: 0;
}

/* ---------------------------------------------------------------- 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 标签 */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap;
}
.tag-ok { background: var(--ok-weak); color: var(--ok); }
.tag-warn { background: var(--warn-weak); color: var(--warn); }
.tag-danger { background: var(--danger-weak); color: var(--danger); }
.tag-muted { background: var(--surface-2); color: var(--text-3); }
.tag-brand { background: var(--brand-weak); color: var(--brand); }

/* ---------------------------------------------------------------- 组织树 */
.tree { list-style: none; margin: 0; padding: 0; }
.tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px solid var(--border); }
.tree-node {
  display: flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 2px 6px; border-radius: 6px; cursor: pointer;
}
.tree-node[aria-selected="true"] { background: var(--brand-weak); color: var(--brand); }
.tree-toggle {
  min-height: 24px; width: 24px; padding: 0; border: none; background: none;
  color: var(--text-3); font-size: 11px;
}
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- 提示条 */
.banner {
  border-left: 3px solid var(--c, var(--border));
  background: var(--bg2, var(--surface-2));
  padding: 12px 14px; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 14px; color: var(--text-2);
}
.banner-paywall { --c: var(--warn); --bg2: var(--warn-weak); }
.banner-denied { --c: var(--danger); --bg2: var(--danger-weak); }
.banner-info { --c: var(--brand); --bg2: var(--brand-weak); }
.banner-ok { --c: var(--ok); --bg2: var(--ok-weak); }
/* 中性提示。不设 --c/--bg2，落到 .banner 的兜底色 —— 但要有这个类名，
   否则模板里写 'banner-muted' 会变成一个匹配不到任何规则的字符串，
   下次有人搜它会以为漏了什么 */
.banner-muted { --c: var(--border); --bg2: var(--surface-2); }
.banner strong { color: var(--text); }

/* ---------------------------------------------------------------- 弹层 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 12px; padding: 20px;
  width: min(520px, 100%); max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 12px; font-size: 17px; }

/* ---------------------------------------------------------------- 状态 */
.empty, .loading {
  padding: 32px 16px; text-align: center; color: var(--text-3); font-size: 14px;
}
.skeleton {
  height: 14px; border-radius: 4px; background: var(--surface-2);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  button:active, .btn:active { transform: none; }
}

[x-cloak] { display: none !important; }

/* ---------------------------------------------------------------- 员工端（移动） */
.m-shell { max-width: 640px; margin: 0 auto; padding: 12px 12px 80px; }
.m-header { padding: 8px 4px 16px; }
.m-header h1 { margin: 0; font-size: 20px; }
.m-header .sub { color: var(--text-2); font-size: 13px; }
.m-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.m-item + .m-item { margin-top: 8px; }
.m-item .label { color: var(--text-2); font-size: 13px; min-width: 5em; }
.m-item .value { flex: 1; text-align: right; }
.m-actions {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: 8px;
}
.m-actions button { flex: 1; }

/* ---------------------------------------------------------------- 侧栏折叠 */
/*
  没有图标，所以不做"缩成一列图标"那种折叠——那需要给 26 个菜单项各配一个
  图标，而含义不明的图标比文字更难认。这里的折叠就是**整条收起**，
  把横向空间让给内容；收起后左上角留一个按钮把它叫回来。
*/
.sidebar { display: flex; flex-direction: column; }
.sidebar nav { flex: 1; }

/*
  ⚠️ 只在宽屏折叠。窄屏（<=860px）本来就是"侧栏占一整行、菜单横排"的布局，
     在那儿套 `0 1fr` 会让主区被挤到第二行去——即把一个本来好好的响应式布局
     改坏。窄屏的菜单已经很紧凑，也没有折叠的必要。
*/
@media (min-width: 861px) {
  .app.nav-collapsed { grid-template-columns: 0 1fr; }
  .app.nav-collapsed .sidebar {
    /* 用 visibility 而不是 display:none —— 后者会让 Alpine 的
       x-for 子树在展开时整棵重建，展开状态（expandedIds）看起来像被重置了 */
    visibility: hidden; padding: 0; border-right: none;
  }
}

/* 窄屏不给折叠按钮：折叠在那个布局下没有意义，留个点了没反应的按钮更糟 */
@media (max-width: 860px) {
  .nav-toggle, .nav-restore { display: none !important; }
}

.nav-toggle {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); border-radius: 6px; cursor: pointer;
  width: 26px; height: 26px; line-height: 1; padding: 0;
  font-size: 15px; flex: none;
}
.nav-toggle:hover { background: var(--surface-2); color: var(--text); }

/* 收起后浮在内容左上角的那个。position:fixed 是有意的——
   跟着页面滚动会让人在长列表底部找不到它 */
.nav-restore {
  position: fixed; top: 14px; left: 12px; z-index: 30;
}

/* ---------------------------------------------------------------- 页脚 */
/*
  ⚠️ 备案号是法定标注，不是装饰：字号可以小，但**不能藏**
  （不能 hover 才出现、不能折叠）。所以它跟着侧栏走，
  侧栏收起时由 .site-footer-inline 在主区底部接着显示。
*/
.site-footer {
  margin-top: 14px; padding: 12px 12px 4px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; line-height: 1.7; color: var(--text-3);
}
.site-footer a { color: var(--text-3); text-decoration: none; }
.site-footer a:hover { color: var(--text-2); text-decoration: underline; }
.site-footer div + div { margin-top: 2px; }

.site-footer-inline {
  margin: 28px auto 0; padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-3); text-align: center;
}
.site-footer-inline a { color: var(--text-3); text-decoration: none; }
.site-footer-inline a:hover { text-decoration: underline; }
