/* 办公小助手 Web 版 —— 全局样式 */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6eb;
  --border-strong: #c9cfd8;
  --text: #1f2329;
  --text-dim: #646a73;
  --primary: #1664ff;
  --primary-hover: #0d53e0;
  --danger: #e34d59;
  --success: #00a870;
  --warn: #ed7b2f;
  --head-bg: #eef1f5;
  --hover: #f2f6ff;
  --sel: #d6e4ff;
  --radius: 6px;
  --shadow: 0 2px 12px rgba(0, 0, 0, .08);
  --topbar-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

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

/* ---------------- 顶栏 ---------------- */
.topbar {
  height: var(--topbar-h); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 8px;
  position: sticky; top: 0; z-index: 100;
}
.topbar .brand { font-size: 16px; font-weight: 600; margin-right: 12px; white-space: nowrap; }
.topbar nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.topbar nav a {
  padding: 6px 12px; border-radius: var(--radius); color: var(--text-dim);
  white-space: nowrap; font-size: 13px;
}
.topbar nav a:hover { background: var(--hover); text-decoration: none; }
.topbar nav a.active { background: var(--primary); color: #fff; }
.topbar .user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); white-space: nowrap; }

/* ---------------- 布局 ---------------- */
.page { padding: 14px; height: calc(100% - var(--topbar-h)); display: flex; flex-direction: column; }
.page.full { height: calc(100vh - var(--topbar-h)); overflow: hidden; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-head {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-body { padding: 14px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------------- 表单控件 ---------------- */
input[type=text], input[type=password], input[type=number], select, textarea {
  height: 32px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: #fff; color: var(--text);
  font-size: 13px; outline: none; font-family: inherit;
}
textarea { height: auto; padding: 8px 10px; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input::placeholder { color: #a8aeb8; }

.btn {
  height: 32px; padding: 0 14px; border: 1px solid var(--border-strong);
  background: #fff; color: var(--text); border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-family: inherit; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: #f7f8fa; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #fef0f0; }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label.field { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); }

/* 设置页「基础选项」：标签与文本框强关联，避免点标签无反应 / 布局塌缩导致点不进去 */
.cfg-field { display: block; }
.cfg-text {
  display: block; width: 100%; min-height: 64px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: #fff; color: var(--text); padding: 8px 10px; line-height: 1.6;
  font-size: 13px; font-family: inherit; outline: none; cursor: text;
  box-sizing: border-box; resize: vertical;
}
.cfg-text:focus { border-color: var(--primary); }

/* ---------------- 表格 ---------------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
table.tbl th { background: var(--head-bg); font-weight: 600; white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--hover); }

/* ---------------- 虚拟滚动网格 ---------------- */
.grid-wrap { position: relative; flex: 1; min-height: 0; border: 1px solid var(--border); background: #fff; overflow: hidden; }
.grid-scroll { position: absolute; inset: 0; overflow: auto; }
.grid-canvas { position: relative; }
.gcell {
  position: absolute; box-sizing: border-box; border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border); padding: 0 6px; font-size: 13px;
  line-height: 30px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: #fff; cursor: cell; user-select: none;
}
.ghead {
  position: absolute; box-sizing: border-box; border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border-strong); padding: 0 6px; font-size: 13px;
  line-height: 32px; font-weight: 600; background: var(--head-bg); overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; user-select: none; cursor: default;
}
.growno {
  position: absolute; box-sizing: border-box; border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border); background: var(--head-bg); color: var(--text-dim);
  font-size: 12px; line-height: 30px; text-align: center; user-select: none;
}
.gcell.sel { background: var(--sel); }
.gcell.hit { background: #fff3d6; }
.gcell.editing { padding: 0; overflow: visible; }
.gcell input {
  width: 100%; height: 100%; border: 2px solid var(--primary); outline: none;
  padding: 0 5px; font-size: 13px; font-family: inherit; background: #fff;
}
.gfrozen { z-index: 5; }
.gheader-layer { position: absolute; top: 0; left: 0; height: 32px; overflow: hidden; z-index: 10; }
.gcorner { position: absolute; top: 0; left: 0; background: var(--head-bg); z-index: 20;
  border-right: 1px solid var(--border-strong); border-bottom: 1px solid var(--border-strong); }

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal {
  background: #fff; border-radius: 8px; box-shadow: 0 8px 32px rgba(0, 0, 0, .2);
  max-width: 92vw; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.x { cursor: pointer; color: var(--text-dim); font-size: 20px; line-height: 1; }
.x:hover { color: var(--danger); }

/* ---------------- 提示 ---------------- */
.toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(30, 34, 40, .92); color: #fff; padding: 9px 18px;
  border-radius: var(--radius); font-size: 13px; z-index: 2000; pointer-events: none;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }

.muted { color: var(--text-dim); font-size: 12px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px;
  background: #eef1f5; color: var(--text-dim);
}
.badge.ok { background: #e3f9ed; color: var(--success); }
.badge.warn { background: #fef3e6; color: var(--warn); }
.badge.err { background: #fde8ea; color: var(--danger); }

.empty { padding: 40px; text-align: center; color: var(--text-dim); }

/* ---------------- 登录页 ----------------
 * 不在本文件里：登录页样式（.au-* 一套）**全部在 app/templates/login.html 的 <style> 里**。
 * 本文件被每个页面加载，而登录页样式只服务那一个页面，放这里纯属让其它页面白下载。
 * 历史备份 _bak_realtime_* 里还留着旧的 .login-page / .login-box（360px 窄卡片），
 * 那是 2026-09-17 改版前的版本，别照抄回来。 */

/* ---------------- 统计卡片 ---------------- */
.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 16px; min-width: 110px;
}
.stat .n { font-size: 20px; font-weight: 600; }
.stat .l { font-size: 12px; color: var(--text-dim); }

/* ---------------- 移动端 ---------------- */
@media (max-width: 768px) {
  .topbar { padding: 0 8px; }
  .topbar .brand { display: none; }
  .page { padding: 8px; }
  .card-head { padding: 8px 10px; }
  .stat { padding: 8px 12px; min-width: 88px; }
  .stat .n { font-size: 16px; }
}

/* ---- 可勾选标签（多选名单用） ---- */
label.chip, .chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; margin: 2px 0;
  border: 1px solid var(--line, #d8dee9); border-radius: 14px;
  background: var(--panel-2, #f6f8fa);
  font-size: 13px; color: var(--text, #24292f); cursor: pointer;
  user-select: none; white-space: nowrap;
}
label.chip:hover, .chip:hover { border-color: var(--primary, #2f6fed); }
label.chip input, .chip input { margin: 0; }
label.field select, label.field input[type="text"],
label.field input[type="file"] { flex: 1; }
label.field.stretch { display: flex; align-items: center; }

/* 弹窗内表单项占满整行 */
.modal-body label.field {
  display: flex; align-items: center; gap: 8px; width: 100%;
  font-size: 13px; color: var(--text, #24292f);
}
.modal-body label.field > input[type="text"],
.modal-body label.field > input[type="file"],
.modal-body label.field > select { flex: 1; min-width: 0; }

/* ---- 统计卡片 ---- */
.stat-grid {
  display: grid; gap: 12px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat-card {
  background: var(--panel, #fff); border: 1px solid var(--line, #d8dee9);
  border-radius: 10px; padding: 14px 16px;
}
.stat-label { font-size: 13px; color: var(--text-dim, #6b7280); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 600; line-height: 1.1; color: var(--primary, #2f6fed); }
.stat-sub { margin-top: 6px; font-size: 12px; color: var(--text-dim, #6b7280); }
.stat-sub b { color: var(--text, #24292f); }
.stat-num { font-size: 28px; font-weight: 600; line-height: 1.1; color: var(--primary); }
.stat-num.ok { color: var(--success); }
.stat-num.warn { color: var(--warn); }
.stat-num.err { color: var(--danger); }

/* ---- 分段切换按钮 ---- */
.chip-group { display: inline-flex; gap: 4px; }
.chip-btn {
  padding: 4px 12px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--line, #d8dee9); background: var(--panel, #fff);
  border-radius: 6px; color: var(--text-dim, #6b7280);
}
.chip-btn.active {
  background: var(--primary, #2f6fed); border-color: var(--primary, #2f6fed); color: #fff;
}

/* 表格 */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td {
  border-bottom: 1px solid var(--line, #e5e7eb);
  padding: 7px 10px; text-align: left; white-space: nowrap;
}
table.tbl th { background: var(--panel-2, #f6f8fa); font-weight: 600; position: sticky; top: 0; }
table.tbl tbody tr:hover { background: var(--panel-2, #f6f8fa); }
.btn.danger { color: #c0392b; border-color: #e5b4b4; }

/* ---- 右键菜单 ---- */
.ctx-menu {
  position: fixed; z-index: 9999; min-width: 168px;
  background: var(--panel, #fff); border: 1px solid var(--line, #d8dee9);
  border-radius: 8px; box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
  padding: 4px; display: flex; flex-direction: column;
}
.ctx-menu button {
  all: unset; padding: 7px 12px; font-size: 13px; cursor: pointer;
  border-radius: 5px; color: var(--text, #24292f); white-space: nowrap;
}
.ctx-menu button:hover { background: var(--panel-2, #f0f3f7); }
.ctx-menu hr { border: none; border-top: 1px solid var(--line, #e5e7eb); margin: 4px 2px; }

/* 表头排序列标记 */
.ghead.sorted { color: var(--primary, #2f6fed); font-weight: 600; }
/* 表头三态排序指示：降序 ▼ / 升序 ▲（箭头跟随 .sorted 的主色） */
.ghead.sorted-asc::after { content: " \2191"; font-size: 11px; font-weight: 700; }
.ghead.sorted-desc::after { content: " \2193"; font-size: 11px; font-weight: 700; }
.gcell.cur { outline: 2px solid var(--primary, #2f6fed); outline-offset: -2px; z-index: 6; }

/* ---------------- 协作光标（多人实时编辑） ---------------- */
/* 每个协作者一个颜色（由内联 --peer-c 注入），用 2px 内描边标出他所在的格；
   右上角小三角是「有人在看这里」的弱提示，不遮住格子内容。
   用 box-shadow 而不是 outline：自己的光标 .cur 用的是 outline，
   两者能同时显示 —— 「我在这一格，张三也在」这种同格情况不会被谁盖掉谁。 */
.gcell.peer { box-shadow: inset 0 0 0 2px var(--peer-c, #2f6feb); }
.gcell.peer::after {
  content: ''; position: absolute; right: 0; top: 0;
  border: 5px solid transparent;
  border-top-color: var(--peer-c, #2f6feb);
  border-right-color: var(--peer-c, #2f6feb);
  pointer-events: none;
}

/* 顶部在线成员条：与格子上的光标同色，方便把「这个人」和「那个框」对上号 */
.rt-members { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rt-member {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px 1px 5px; border-radius: 10px; font-size: 12px;
  background: var(--head-bg, #f2f3f5); border: 1px solid var(--border, #dcdfe6);
}
.rt-member .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.rt-member.editing { border-color: var(--primary, #2f6fed); }
