/* ===== 基础 ===== */
:root {
  --blue: #2f6df6;
  --blue-light: #eaf1ff;
  --green: #12a05c;
  --green-light: #e6f8ee;
  --amber: #d98416;
  --amber-light: #fff3e2;
  --red: #e04545;
  --red-light: #fdecec;
  --text: #1f2329;
  --text-2: #5c6470;
  --text-3: #99a0ac;
  --border: #e5e8ee;
  --bg: #f4f6f9;
  --radius: 10px;
  --hour-h: 52px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

[hidden] { display: none !important; }
.mobile-only { display: none; }

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ===== 按钮 ===== */
.btn-primary {
  height: 42px; padding: 0 22px; border: none; border-radius: 21px;
  background: var(--blue); color: #fff; font-size: 15px;
}
.btn-primary:hover { background: #2560e0; }
.btn-primary:disabled { background: #b9c6de; cursor: not-allowed; }
.btn-primary.wide { width: 100%; }

.btn-ghost {
  height: 36px; padding: 0 16px; border: 1px solid var(--border);
  border-radius: 18px; background: #fff; color: var(--text-2); font-size: 13px;
}
.btn-ghost:hover { border-color: #c9d3e3; color: var(--text); }

.btn-danger {
  height: 32px; padding: 0 14px; border: none; border-radius: 16px;
  background: var(--red); color: #fff; font-size: 13px;
}
.btn-danger:hover { background: #c93a3a; }

.icon-btn {
  width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text-2); font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: #f0f3f9; }

.link-btn { border: none; background: none; color: var(--text-3); font-size: 13px; padding: 4px; }
.link-btn:hover { color: var(--blue); }

/* ===== 登录页 ===== */
.screen { min-height: 100vh; }

.auth-card {
  width: 380px; max-width: calc(100vw - 32px); margin: 12vh auto; padding: 34px 32px;
  background: #fff; border-radius: 16px; box-shadow: 0 8px 32px rgba(30, 45, 80, .08);
}
.auth-title { font-size: 22px; }
.auth-sub { margin: 4px 0 22px; color: var(--text-3); font-size: 13px; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  flex: 1; height: 36px; border: none; border-radius: 8px;
  background: #f2f4f8; color: var(--text-2); font-size: 14px;
}
.tab.active { background: var(--blue); color: #fff; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-2); }
.field-label i { color: var(--red); font-style: normal; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fbfcfe; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--blue); background: #fff;
}
.field textarea { resize: vertical; min-height: 70px; }

/* ===== 实验位选择 ===== */
.field-label .hint {
  margin-left: 6px; font-style: normal; font-size: 12px;
  color: var(--text-3, #99a0ac); font-weight: 400;
}
.station-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.station-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: 17px;
  background: #fff; color: var(--text-2); font-size: 13px; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.station-chip:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.station-chip.active {
  background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 500;
}
.station-chip:disabled {
  background: #f4f5f7; color: #b6bcc7; cursor: not-allowed;
  border-color: #e8eaee; text-decoration: line-through;
}
.station-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #dfe3ea; }
.station-chip.active .dot { background: #fff; }
.station-hint { font-size: 12px; color: var(--text-3, #99a0ac); min-height: 16px; }
.station-hint.warn { color: #b3721a; }

/* ===== 时间选择弹窗 ===== */
.slot-card { max-width: 520px; }
.slot-row { margin-bottom: 14px; }
.slot-label {
  display: block; font-size: 13px; color: var(--text-2); margin-bottom: 7px;
}
.slot-opts {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px;
}
.slot-chip {
  padding: 7px 4px; border: 1px solid var(--border); border-radius: 8px;
  background: #fbfcfe; color: var(--text); font-size: 13px; cursor: pointer;
  min-height: 36px; font-variant-numeric: tabular-nums;
}
.slot-chip:hover { border-color: #b9c9ea; background: #fff; }
.slot-chip.active {
  border-color: var(--blue); background: #eef4ff; color: #185fa5; font-weight: 500;
}
.slot-quick { display: flex; gap: 8px; margin: 4px 0 10px; }
.quick-slot {
  flex: 1 1 0; min-height: 38px; padding: 9px 4px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
}
.quick-slot:hover { border-color: #b9c9ea; background: #fbfcfe; }

.error {
  padding: 9px 12px; margin-bottom: 14px; border-radius: 8px;
  background: var(--red-light); color: #b32d2d; font-size: 13px;
}

.demo-hint { margin-top: 20px; font-size: 12px; color: var(--text-3); }
.demo-hint summary { cursor: pointer; }
.demo-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.demo-list button {
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text-2); font-size: 12px;
}
.demo-list button:hover { border-color: var(--blue); color: var(--blue); }
.demo-note { margin: 8px 0 0; }

.link-admin {
  display: block; width: 100%; margin-top: 20px; padding: 10px;
  border: none; border-top: 1px solid var(--border); background: none;
  color: var(--text-3); font-size: 13px;
}
.link-admin:hover { color: var(--blue); }

/* ===== 顶栏 ===== */
.topbar {
  display: flex; align-items: center; gap: 26px;
  height: 58px; padding: 0 22px; background: #fff; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-size: 16px; font-weight: 600; letter-spacing: .5px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  height: 34px; padding: 0 14px; border: none; border-radius: 8px;
  background: none; color: var(--text-2); font-size: 14px;
}
.nav-btn:hover { background: #f2f4f8; }
.nav-btn.active { background: var(--blue-light); color: var(--blue); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { font-size: 13px; color: var(--text-2); }

.content { padding: 18px 22px 40px; }
.view { max-width: 1440px; margin: 0 auto; }

/* ===== 工具栏 ===== */
.toolbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
}
.lab-picker { display: flex; align-items: center; gap: 8px; }
.lab-picker label { font-size: 13px; color: var(--text-2); }
.lab-picker select {
  min-width: 200px; height: 34px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-label { margin-left: 8px; font-size: 13px; color: var(--text-2); }
.legend { display: flex; gap: 14px; margin-left: auto; font-size: 12px; color: var(--text-2); }
.legend span { display: flex; align-items: center; gap: 5px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.sw-free { background: #fff; border: 1px solid #cfe8d8; }
.sw-busy { background: #dfe3ea; }
.sw-mine { background: #9dc0ff; }

.lab-brief {
  display: flex; gap: 20px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; color: var(--text-2);
}
.lab-brief b { color: var(--text); font-weight: 500; }
.lab-brief .notice { flex-basis: 100%; color: var(--text-3); white-space: pre-wrap; }

/* 值日生 */
.duty-label {
  display: inline-block; margin-right: 6px; padding: 1px 8px;
  border-radius: 5px; background: var(--green-light); color: var(--green); font-size: 12px;
}
.duty b { color: var(--text); font-weight: 600; }
.duty-none { color: var(--text-3); font-weight: 400 !important; }
.duty-phone { margin-left: 8px; color: var(--blue); text-decoration: none; font-size: 12px; }

/* 实验位标签 */
.st-list { display: flex; gap: 5px; flex-wrap: wrap; margin: 8px 0 2px; }
.st-list.single { color: #99a0ac; font-size: 12px; }
.st-tag {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  background: #eef2fb; color: #2f6df6; font-size: 11px; font-weight: 500;
}
.st-inline { color: var(--blue); }
.hint-line {
  margin: 10px 0 0; font-size: 12px; color: #99a0ac;
}
.hint-line b { color: #5a6272; }

.duty-chip {
  display: flex; align-items: center; flex-wrap: wrap;
  margin-bottom: 10px; padding: 7px 10px;
  background: var(--green-light); border-radius: 8px; font-size: 13px;
}
.duty-chip a { margin-left: auto; color: var(--blue); text-decoration: none; font-size: 12px; }

/* 工时统计 */
.date-range { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.date-range input {
  height: 34px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.bar { height: 8px; background: #eef1f6; border-radius: 4px; overflow: hidden; }
.bar-in { height: 100%; background: var(--blue); border-radius: 4px; }
/* 占比列：桌面端固定宽度，窄屏由媒体查询改成撑满 */
.pct-cell { width: 110px; }

@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

.schedule-hint { margin-top: 10px; font-size: 12px; color: var(--text-3); text-align: center; }

/* ===== 周视图时间表===== */
.schedule-wrap {
  overflow-x: auto; overflow-y: auto; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius);
  /* 全天开放时一天 24 小时（约 1248px），限高并纵向滚动，避免页面过长 */
  max-height: 72vh;
}
.schedule { min-width: 980px; position: relative; }

.sc-head {
  display: grid; position: sticky; top: 0; z-index: 10;
  background: #fff; border-bottom: 1px solid var(--border);
}
.sc-head-cell {
  padding: 10px 6px; text-align: center; border-left: 1px solid var(--border);
}
.sc-head-cell:first-child { border-left: none; }
.sc-head-cell .d-week { font-size: 12px; color: var(--text-2); }
.sc-head-cell .d-date { font-size: 15px; font-weight: 600; margin-top: 2px; }
.sc-head-cell.today .d-date { color: var(--blue); }
.sc-head-cell.weekend .d-date { color: var(--text-3); }

.sc-body { display: grid; position: relative; }
.sc-gutter { border-right: 1px solid var(--border); }
.sc-hour {
  height: var(--hour-h); padding: 2px 8px 0 0; text-align: right;
  font-size: 12px; color: var(--text-3);
  border-bottom: 1px solid #f0f2f6;
}
.sc-col {
  position: relative; border-left: 1px solid var(--border);
  background-image: repeating-linear-gradient(to bottom, #f0f2f6 0 1px, transparent 1px var(--hour-h));
}
.sc-col.weekend { background-color: #fafbfc; }
.sc-col.past { background-color: #f7f8fa; }

/* 预约块 —— left / width 由 JS 按泳道动态计算（并行工位时并排显示）
   高度不够时通过 .compact / .tiny 逐级降级，优先保证姓名可见 */
.ev {
  position: absolute; padding: 5px 7px;
  border-radius: 6px; overflow: hidden; cursor: pointer;
  background: #dfe3ea; border: 1px solid #c3c9d4; border-left: 3px solid #9aa2b0;
  font-size: 12px; line-height: 1.4; color: #3a4250;
  box-shadow: 0 1px 2px rgba(20, 30, 50, .06);
}
.ev:hover { filter: brightness(.96); z-index: 3; }
.ev.busy { background: #dfe3ea; border-color: #c3c9d4; border-left-color: #9aa2b0; }
.ev.mine { background: #cddfff; border-color: #a8c8ff; border-left-color: var(--blue); color: #1b4ba8; }
.ev-title { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-time { font-size: 11px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-purpose { font-style: normal; font-weight: 400; opacity: .75; }

/* 泳道变窄（如5 个工位同时在用）时压缩内边距与字号 */
.ev.narrow { padding: 4px 4px; font-size: 11px; }
.ev.narrow .ev-time { font-size: 10px; }

/* 中等高度（30-42px）：紧凑排版，两行贴紧 */
.ev.compact { padding: 3px 5px; line-height: 1.25; }
.ev.compact .ev-title { font-size: 11px; }
.ev.compact .ev-time { font-size: 10px; opacity: .75; }

/* 极矮（<30px）：姓名和时间并排同一行 */
.ev.tiny { padding: 1px 4px; line-height: 1.2; display: flex; align-items: center; }
.ev.tiny .ev-inline { display: flex; align-items: baseline; gap: 4px; min-width: 0; }
.ev.tiny .ev-title { font-size: 11px; flex: 0 1 auto; min-width: 0; }
.ev.tiny .ev-time { font-size: 10px; flex: 0 0 auto; opacity: .7; }
/* 宽度不够时先砍时间，保住姓名 */
.ev.tiny.narrow .ev-time { display: none; }

/* 实验位标签（仅高度充裕时显示） */
.ev-station {
  display: inline-block; margin-bottom: 2px; padding: 0 5px; max-width: 100%;
  border-radius: 4px; background: rgba(255, 255, 255, .78);
  font-size: 10px; font-weight: 600; letter-spacing: .3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}

/* 拖选选区 */
.sel {
  position: absolute; left: 3px; right: 3px;
  background: rgba(47, 109, 246, .16);
  border: 1.5px dashed var(--blue); border-radius: 6px;
  pointer-events: none; z-index: 5;
}
.sel.invalid { background: rgba(224, 69, 69, .14); border-color: var(--red); }

/* ===== 卡片网格（实验室） ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.lab-card {
  padding: 16px; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.lab-card:hover { border-color: #b9c9ea; box-shadow: 0 2px 12px rgba(30, 45, 80, .06); }
.lab-card h3 { font-size: 16px; }
.lab-loc { margin: 4px 0 10px; font-size: 13px; color: var(--text-2); }
.lab-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.badge { padding: 2px 9px; border-radius: 5px; font-size: 12px; background: #f2f4f8; color: var(--text-2); }
.badge.blue { background: var(--blue-light); color: var(--blue); }
.badge.amber { background: var(--amber-light); color: var(--amber); }
.badge.green { background: var(--green-light); color: var(--green); }
.badge.red { background: var(--red-light); color: var(--red); }
.lab-free { font-size: 13px; color: var(--green); }
.lab-free.none { color: var(--red); }

/* ===== 列表 ===== */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  height: 32px; padding: 0 14px; border: 1px solid var(--border); border-radius: 16px;
  background: #fff; color: var(--text-2); font-size: 13px;
}
.chip:hover { border-color: #c9d3e3; }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.row-card {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 16px; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.row-main { flex: 1; min-width: 220px; }
.row-title { font-size: 15px; font-weight: 500; }
.row-sub { margin-top: 3px; font-size: 13px; color: var(--text-2); }
.row-time { font-size: 14px; color: var(--blue); font-weight: 500; }
.row-reason { margin-top: 4px; font-size: 12px; color: var(--red); }
.row-actions { display: flex; gap: 8px; align-items: center; }

/* ===== 借物登记 ===== */
.loan-toolbar .btn-primary { margin-left: auto; }
.loan-row { align-items: flex-start; }
.loan-row .row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.loan-row .row-sub b { color: var(--text); font-weight: 500; }
.loan-row .row-actions .btn-primary { height: 36px; padding: 0 18px; font-size: 14px; }

.empty { padding: 50px; text-align: center; color: var(--text-3); background: #fff; border-radius: var(--radius); }

/* ===== 管理端 ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { padding: 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); text-align: center; }
.stat-num { font-size: 26px; font-weight: 600; color: var(--blue); }
.stat-lbl { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.admin-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.admin-body { margin-top: 4px; }
.sub-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 10px; }
.sub-head h3 { font-size: 15px; }

/* ===== 站点设置 ===== */
.settings-panel {
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.settings-item {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 16px 18px; border-bottom: 1px solid #f0f2f6;
}
.settings-item:last-of-type { border-bottom: none; }
.settings-text { flex: 1 1 320px; min-width: 0; }
.settings-text b { font-size: 14px; font-weight: 500; }
.settings-text p {
  margin: 4px 0 0; font-size: 12.5px; color: var(--text-2); line-height: 1.6;
}
.settings-ctl { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; }
.settings-ctl input {
  width: 220px; padding: 7px 11px; border: 1px solid var(--border);
  border-radius: 8px; background: #fbfcfe; outline: none; font-size: 13px;
}
.settings-ctl input:focus { border-color: var(--blue); background: #fff; }
.settings-note {
  padding: 14px 18px; background: #f8fafd;
  border-top: 1px solid var(--border); font-size: 12.5px;
}
.settings-note b { display: block; margin-bottom: 6px; font-weight: 500; }
.settings-note ul { margin: 0; padding-left: 20px; color: var(--text-2); line-height: 1.9; }
.settings-note code {
  background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 11.5px;
  font-family: Consolas, "Cascadia Code", monospace;
}

.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; }
.table > table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
.table th { background: #f7f9fc; color: var(--text-2); font-weight: 500; }
.table tr:last-child td { border-bottom: none; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions button { margin-left: 6px; }

/* ==========================================================
   表格的移动端形态：把行变成卡片
   ----------------------------------------------------------
   问题：手机上 5-8 列的表格会被压到每列一个字宽（「实验室管理员」
   竖成一列），操作按钮直接被裁掉，且横向滚动很难用。
   解法：窄屏下隐藏表头，每行 display:block 变卡片，
        单元格前加 data-label 伪元素显示字段名。
   用 CSS 实现而不是改 JS —— 所有表格自动受益，不用逐个改。
   ========================================================== */
@media (max-width: 720px) {
  .table {
    display: block; width: 100%; min-width: 0;
    background: transparent; border-radius: 0; overflow: visible;
  }

  /* 外层 .table 已经撑满；内层 table 也必须撑满，否则会按内容缩窄。 */
  .table > table {
    display: block; width: 100%; table-layout: fixed;
    border-collapse: separate; border-spacing: 0;
  }

  .table thead { display: none; }          /* 表头在卡片里用 data-label 代替 */

  .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tbody { margin: 0; }
  .table tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 2px 0;
    overflow: hidden;
    /* 加一层极淡的投影，卡片从背景里"浮"起来，不再是一块白底 */
    box-shadow: 0 2px 10px rgba(20, 30, 50, .055);
  }

  .table td {
    display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
    padding: 9px 15px;
    line-height: 1.6;
    /* word-break 会让长字符串（如学号）在任意字符处断开，
       视觉上像数据错位。改成只在必要时断行 */
    overflow-wrap: anywhere;
  }
  /* 最后一行（操作列）之前加一条淡分隔线，卡片结构更清楚 */
  .table td + td { border-top: 1px solid #f7f9fc; }
  .table td:last-child { border-top-color: #eef1f6; }

  /* 字段名来自 HTML 里的 data-label，无数据时退化为空 */
  .table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    min-width: 64px; max-width: 100px;
    white-space: nowrap;
    color: var(--text-3, #99a0ac); font-size: 12px;
    font-weight: 400;
  }
  /* 关键：td 内的裸文本节点要包一层才能在 flex 里正常排版，
     否则纯文本会成为匿名 flex item，宽度表现与元素子节点不一致
     —— 表现为长数字串换行后与字段名错位。 */
  .table td > * { min-width: 0; flex: 0 1 auto; }

  /* 值比字段名更醒目一点，卡片读起来有主次 */
  .table td { font-size: 14px; font-variant-numeric: tabular-nums; }
  .table td b { font-weight: 500; }
  /* 徽章类内容（角色/状态）在窄屏略微放大，好识别 */
  .table td .badge { font-size: 12px; padding: 2px 8px; }
  .table td .badge,
  .table td .st-tag { flex: 0 0 auto; white-space: nowrap; }
  /* 进度条这类需要撑满的元素单独处理 */
  .table td > .bar { flex: 1 1 auto; width: auto; min-width: 80px; }
  .table td.pct-cell { width: auto; }   /* 窄屏不锁宽度 */

  /* 工时汇总卡：手机端用“姓名 + 工时”做主信息，不再逐行摊开成表格。 */
  #hours-by-user .table > table,
  #hours-by-lab .table > table { display: block; width: 100%; }
  #hours-by-user tbody,
  #hours-by-lab tbody { display: flex; flex-direction: column; gap: 10px; }

  #hours-by-user tr {
    display: grid; width: 100%;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name hours"
      "id hours"
      "count count"
      "pct pct";
    column-gap: 16px; row-gap: 4px;
    margin: 0; padding: 15px 16px 14px;
    border-left: 3px solid var(--blue);
  }
  #hours-by-user td { display: block; width: auto; padding: 0; border: 0 !important; }
  #hours-by-user .summary-name { grid-area: name; font-size: 17px; font-weight: 600; line-height: 1.35; }
  #hours-by-user .summary-name::before { content: none; }
  #hours-by-user .summary-id {
    grid-area: id; display: flex; align-items: center; gap: 5px;
    color: var(--text-3); font-size: 12px; line-height: 1.4;
  }
  #hours-by-user .summary-id::before {
    content: "学号"; flex: 0 0 auto; width: auto;
    color: var(--text-3); font-size: 11px;
  }
  #hours-by-user .summary-hours {
    grid-area: hours; align-self: center; text-align: right;
  }
  #hours-by-user .summary-count {
    grid-area: count; justify-self: start;
    display: inline-flex; align-items: center; gap: 3px;
    margin-top: 5px; padding: 3px 9px;
    border-radius: 999px; background: #f2f5fa;
    color: var(--text-2); font-size: 12px; line-height: 1.4;
  }
  #hours-by-user .summary-count::before {
    content: "共"; flex: 0 0 auto; width: auto;
    color: var(--text-3); font-size: 11px;
  }
  #hours-by-user .summary-count::after {
    content: "条"; margin-left: -2px; color: var(--text-3); font-size: 11px;
  }
  #hours-by-user .pct-cell {
    grid-area: pct; display: flex; align-items: center; gap: 10px;
    margin-top: 8px; padding: 10px 0 0;
    border-top: 1px solid #f0f3f7 !important;
  }
  #hours-by-user .pct-cell::before {
    content: "占比"; flex: 0 0 auto; width: auto;
    color: var(--text-3); font-size: 11px;
  }

  #hours-by-lab tr {
    display: grid; width: 100%;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name hours"
      "count hours";
    column-gap: 16px; row-gap: 5px;
    margin: 0; padding: 15px 16px;
    border-left: 3px solid #8aa8e8;
  }
  #hours-by-lab td { display: block; width: auto; padding: 0; border: 0 !important; }
  #hours-by-lab .summary-name { grid-area: name; font-size: 16px; font-weight: 600; line-height: 1.35; }
  #hours-by-lab .summary-name::before { content: none; }
  #hours-by-lab .summary-hours { grid-area: hours; align-self: center; text-align: right; }
  #hours-by-lab .summary-count {
    grid-area: count; justify-self: start;
    display: inline-flex; align-items: center; gap: 3px;
    padding: 3px 9px; border-radius: 999px;
    background: #f2f5fa; color: var(--text-2);
    font-size: 12px; line-height: 1.4;
  }
  #hours-by-lab .summary-count::before {
    content: "共"; flex: 0 0 auto; width: auto;
    color: var(--text-3); font-size: 11px;
  }
  #hours-by-lab .summary-count::after {
    content: "条"; margin-left: -2px; color: var(--text-3); font-size: 11px;
  }

  #hours-by-user .summary-hours,
  #hours-by-lab .summary-hours {
    display: flex; flex-direction: column; align-items: flex-end; gap: 1px;
    color: var(--text-3); font-size: 11px; line-height: 1.3;
  }
  #hours-by-user .summary-hours::before,
  #hours-by-lab .summary-hours::before {
    content: attr(data-label); flex: none; width: auto;
    color: var(--text-3); font-size: 11px; font-weight: 400;
  }
  #hours-by-user .summary-hours b,
  #hours-by-lab .summary-hours b {
    display: block; font-size: 20px; font-weight: 600; letter-spacing: -.2px;
    white-space: nowrap;
  }

  /* 5 个统计卡时，最后一个不再孤零零占左半屏。 */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats .stat { padding: 14px 10px; border-radius: 12px; }
  .stats .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stats .stat-num { font-size: 24px; }

  /* 操作按钮独占一行，按钮放大到好按 */
  .table td.actions {
    text-align: left; white-space: normal;
    padding-top: 10px; padding-bottom: 12px;
    border-top: 1px solid #f2f4f8;
    /* 按钮多时（用户表有 3 个）自动换行，不再被裁掉 */
    display: flex; flex-wrap: wrap; gap: 8px;
  }
  .table td.actions::before { flex-basis: 0; content: none; }
  .table td.actions button {
    margin: 0; flex: 0 0 auto; width: auto;
    min-height: 40px; padding: 0 16px;   /* 手指好按 */
  }
}

/* ===== 弹窗 ===== */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(24, 32, 48, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  width: 460px; max-width: 100%; max-height: 88vh; overflow: auto;
  background: #fff; border-radius: 14px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

.kv { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; }
.kv span { color: var(--text-2); }
.kv b { font-weight: 500; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  padding: 10px 22px; border-radius: 22px;
  background: rgba(28, 34, 46, .92); color: #fff; font-size: 14px; z-index: 200;
}
.toast.err { background: rgba(180, 45, 45, .95); }

/* 点击预约块弹出的详情卡（窄块/矮块信息显示不全时的兜底） */
.ev-detail {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  min-width: 220px; max-width: 340px; padding: 12px 16px; border-radius: 10px;
  background: rgba(255, 255, 255, .98); border: 1px solid var(--border);
  box-shadow: 0 8px 28px rgba(20, 30, 50, .18); z-index: 200; font-size: 13px;
}
.detail-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 4px 0; line-height: 1.5;
}
.detail-row span { color: var(--text-2); flex: 0 0 auto; }
.detail-row b { font-weight: 500; text-align: right; word-break: break-all; }
.detail-tip {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid #eef0f4;
  font-size: 12px; color: #99a0ac;
}


@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px 10px; }
  .topbar-right { min-width: 0; margin-left: auto; }
  .nav {
    order: 3; flex-basis: 100%; overflow-x: auto;
    overscroll-behavior-x: contain;
  }
  .content { padding: 14px; }
  .legend { margin-left: 0; }
  .toolbar { gap: 12px; }
  .lab-picker { width: 100%; }
  .lab-picker select { flex: 1; min-width: 0; width: 100%; }
  .week-nav { width: 100%; flex-wrap: wrap; }
  .week-label {
    order: 4; flex-basis: 100%; width: 100%;
    margin: 2px 0 0; text-align: center; font-size: 12px;
  }
  .date-range {
    display: grid; width: 100%;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px 10px;
  }
  .date-range input { width: 100%; min-width: 0; height: 42px; }
  .desktop-only { display: none; }
  .mobile-only { display: inline; }
}

/* ==========================================================
   手机端优化
   原则：小屏上少滚动、少输入、点击区域够大（>=44px 高）
   ========================================================== */
@media (max-width: 720px) {

  /* 顶栏导航：按钮不换行、不压缩，超出时横向滑动 */
  .nav { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn {
    white-space: nowrap;      /* 「周视图」不竖排 */
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 14px;
  }

  /* 弹窗改成全屏，避免在小屏里滚动找按钮 */
  .modal { padding: 0; }
  .modal-card {
    width: 100%; max-width: 100%; height: 100%;
    max-height: 100vh; border-radius: 0;
    display: flex; flex-direction: column;
  }
  .modal-head { flex: 0 0 auto; padding: 14px 16px; }
  .modal-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px; -webkit-overflow-scrolling: touch; }
  .modal-foot { flex: 0 0 auto; padding: 12px 16px; gap: 10px; }
  .modal-foot button { flex: 1; min-height: 44px; }   /* 按钮够大才好按 */

  /* 关闭按钮做成手机常见的圆形 */
  .icon-btn { width: 40px; height: 40px; font-size: 20px; }

  /* 输入控件加大 */
  .field input, .field textarea, .field select,
  #bm-purpose {
    font-size: 16px;          /* iOS 上小于 16px 会自动放大页面 */
    min-height: 44px;
    padding: 10px 12px;
  }
  textarea { min-height: 88px; }

  /* 实验位按钮也放大 */
  .station-chip { min-height: 44px; font-size: 14px; padding: 10px 14px; }

  /* 管理后台标签多，保持单行并横向滑动，避免每个标签内部换行。 */
  .admin-tabs {
    flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px;
    overscroll-behavior-x: contain;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .admin-tabs .chip {
    flex: 0 0 auto; min-height: 40px; padding: 0 14px;
    white-space: nowrap;
  }
  .chips .chip { white-space: nowrap; }

  /* 时间选择：格子大到好按，一屏能看到常用时长 */
  .slot-card .modal-body { padding-bottom: 8px; }
  .slot-row { margin-bottom: 14px; }
  .slot-label {
    display: block; font-size: 13px; color: var(--text-2); margin-bottom: 7px;
  }
  .slot-opts {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px;
  }
  .slot-chip {
    padding: 9px 4px; border: 1px solid var(--border); border-radius: 8px;
    background: #fbfcfe; color: var(--text); font-size: 14px; cursor: pointer;
    min-height: 44px; font-variant-numeric: tabular-nums;
  }
  .slot-chip.active {
    border-color: var(--blue); background: #eef4ff; color: #185fa5; font-weight: 500;
  }
  .quick-slot {
    flex: 1 1 0; min-height: 44px; padding: 10px 4px;
    border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: var(--text); font-size: 14px; cursor: pointer;
  }
  .quick-slot:active { background: #f0f4fb; }

  /* 实验室卡片单列，不再横滑 */
  .grid { grid-template-columns: 1fr; }

  /* 设置项在窄屏上让输入框和保存按钮共享整行，避免按钮被挤出屏幕。 */
  .settings-item { gap: 12px; }
  .settings-ctl { flex: 1 1 100%; width: 100%; min-width: 0; }
  .settings-ctl input { flex: 1 1 auto; width: auto; min-width: 0; }
  .settings-ctl button { flex: 0 0 auto; min-width: 76px; }
  .settings-note code { white-space: nowrap; }

  /* 主按钮加大，方便单手点击 */
  .btn-primary, .btn-ghost { min-height: 44px; }

  /* 借物登记：筛选和登记按钮各占一行，避免按钮被挤出屏幕 */
  .loan-toolbar .btn-primary { flex: 1 1 100%; width: 100%; margin-left: 0; }
  .loan-row .row-actions .btn-primary { height: 44px; }
  #btn-password { font-size: 12px; }
}

@media (max-width: 360px) {
  /* 极窄屏保留品牌与身份在同一行，身份信息用省略号收起。 */
  .topbar { gap: 8px; }
  .brand { flex: 0 0 auto; white-space: nowrap; }
  .topbar-right { gap: 6px; flex: 0 1 auto; }
  .who {
    min-width: 0; max-width: 112px;
    overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  }
}
