:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0f172a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.view { height: 100dvh; display: flex; flex-direction: column; }

.login-view { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--card);
  border: 1px solid var(--line); border-radius: 18px; padding: 26px 20px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.07);
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: 0.5px; }
.brand-sub { font-size: 12px; color: var(--muted); margin: 3px 0 22px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input {
  width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; font-size: 15px; background: #f8fafc; outline: none; color: var(--text);
}
input:focus { border-color: #94a3b8; background: #fff; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; }
.primary {
  width: 100%; height: 46px; border: 0; border-radius: 11px; background: var(--brand);
  color: #fff; font-size: 15px; font-weight: 600; margin-top: 6px;
}
.primary:active { opacity: 0.85; }
.ghost {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  color: #334155; font-size: 13px; padding: 0 12px;
}
.code-row .ghost { width: 104px; height: 44px; flex: 0 0 auto; }
.tiny { font-size: 12px; padding: 6px 10px; border-radius: 8px; }
.msg { min-height: 17px; font-size: 12px; color: #dc2626; text-align: center; margin: 10px 0 0; }
.hint { font-size: 11px; color: var(--muted); text-align: center; margin: 12px 0 0; line-height: 1.8; }

/* ---------- 主界面 ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 6px;
}
.week-nav { display: flex; align-items: center; gap: 6px; flex: 1; }
.wk { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.week-label { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.week-sub { font-size: 11px; color: var(--muted); }
.navbtn {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px;
  border: 1px solid #2563eb;
  background: #2563eb;
  font-size: 18px; line-height: 1; color: #fff; padding: 0;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.28);
}
.navbtn:active { background: #1d4ed8; border-color: #1d4ed8; }

.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 4px 10px 8px; }
.day {
  position: relative; padding: 6px 0 5px; border-radius: 10px; background: var(--card);
  border: 1px solid var(--line); text-align: center; line-height: 1.2; color: var(--text); padding-inline: 0;
}
.day .dn { font-size: 11px; color: var(--muted); }
.day .dd { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.day.active { background: var(--brand); border-color: var(--brand); }
.day.active .dn, .day.active .dd { color: #fff; }
.day .dot {
  position: absolute; top: 4px; right: 5px; width: 4px; height: 4px;
  border-radius: 50%; background: #6d28d9;
}
.day.active .dot { background: #c4b5fd; }

.grid-wrap { flex: 1; min-height: 0; padding: 0 10px 6px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.grid {
  display: flex; flex-direction: column; gap: 1px;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.row { flex: 0 0 30px; min-height: 30px; display: flex; gap: 5px; }
.hr {
  width: 48px; flex: 0 0 48px; display: flex; align-items: center; justify-content: flex-end;
  font-size: 11px; color: #94a3b8; font-variant-numeric: tabular-nums; padding-right: 2px;
}
.cells { flex: 1; min-width: 0; display: flex; gap: 5px; }
.cell {
  flex: 1 1 0;
  min-width: 0;
  border-radius: 2px;
  background: #ffffff;
  min-height: 0;
  cursor: pointer;
  border: none;
  transition: background 0.06s linear, box-shadow 0.06s linear, border-color 0.06s linear;
}
/* 鼠标悬停：明确告诉用户"这是第几个 15 分钟格" */
.cell:hover {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.18);
}
.cell:active {
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.4);
}

.palette {
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--card); border-top: 1px solid var(--line);
}
.tools {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 7px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.tools::-webkit-scrollbar { display: none; }
.tool {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 11px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 12px; color: #334155; white-space: nowrap; padding-block: 7px;
}
.tool .sw { width: 12px; height: 12px; border-radius: 3px; }
.tool.active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.13); }
.statusbar { display: flex; align-items: center; justify-content: space-between; }
.save-status { font-size: 11px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.93); color: #fff; font-size: 13px;
  padding: 9px 15px; border-radius: 10px; max-width: 80vw; text-align: center;
  /* 必须高于 .modal（100）：否则弹窗内保存失败时的提示会被弹窗盖住，表现为「点保存没反应」 */
  z-index: 200; pointer-events: none;
}

@media (min-width: 640px) {
  .view { max-width: 1280px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--bg); }
  body { background: #e9eef5; }
}

/* ---------- 管理后台 ---------- */
.admin-title { align-items: flex-start; }
.admin-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 12px 28px; -webkit-overflow-scrolling: touch; }
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat-card .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .k { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; color: #334155; white-space: nowrap; }
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.admin-body { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; align-items: center; gap: 10px; }
.item .dotx { width: 14px; height: 14px; border-radius: 4px; flex: 0 0 14px; }
.item .grow { flex: 1; min-width: 0; }
.item .nm { font-size: 14px; font-weight: 600; }
.item .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: #f1f5f9; color: #475569; display: inline-block; margin-right: 4px; }
.badge.off { background: #fee2e2; color: #b91c1c; }
.btn-sm { font-size: 12px; padding: 7px 11px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: #334155; white-space: nowrap; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.row-actions { display: flex; gap: 6px; }
.add-btn { margin: 2px 0 10px; width: 100%; height: 42px; border-radius: 12px; border: 1px dashed #cbd5e1; background: #fff; color: #475569; font-size: 13px; }
.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 0; }

/* 弹层 */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
.modal-card { width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto; background: #fff; border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 20px); }
.modal-card h3 { margin: 0 0 14px; font-size: 16px; }
.form-row { margin-bottom: 12px; }
.form-row > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.form-row input, .form-row select { height: 42px; }
.form-row.invalid input, .form-row.invalid select { border-color: #e11d48; background: #fff1f2; }
.field-err { font-size: 12px; line-height: 1.5; color: #e11d48; margin-top: 6px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 2px solid transparent; }
.swatch.on { border-color: #0f172a; }
.check-group { max-height: 32dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; }
.check input { width: 18px; height: 18px; flex: 0 0 18px; height: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }
.modal-actions button { flex: 1; height: 44px; border-radius: 11px; font-size: 14px; }

/* 占位页 */
.notice-view { align-items: center; justify-content: center; padding: 24px; }
.notice-card { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; max-width: 340px; }
.notice-card h2 { font-size: 17px; margin: 0 0 8px; }
.notice-card p { font-size: 13px; color: var(--muted); line-height: 1.75; margin: 0 0 18px; }

.btn-danger { color: #b91c1c; border-color: #fecaca; background: #fff; }
.btn-danger:active { background: #fee2e2; }

/* 15 分钟刻度表头 */
.head-row { flex: 0 0 13px; margin-bottom: 2px; }
.head-cells { display: flex; gap: 5px; }
.head-cells span { flex: 1 1 0; text-align: center; }
.head-cells span { font-size: 9px; color: #94a3b8; text-align: center; letter-spacing: 0.5px; }

.build-tag {
  display: inline-block;
  font-size: 10px;
  color: #64748b;
  background: #f1f5f9;
  border-radius: 5px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

/* 88 行布局：每小时第一行作为整点分隔 */
.row.hour-start { margin-top: 4px; }
.row.hour-start .hr { color: #475569; font-weight: 600; }

/* ===== 整周网格：7 列 × 88 档 ===== */
.ghead { display: flex; gap: 1px; position: sticky; top: 0; z-index: 6; background: #f1f5f9; padding: 2px 0 4px; }
.gcorner { width: 38px; flex: 0 0 38px; }
.gday { flex: 1 1 0; min-width: 0; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 5px 0 4px; line-height: 1.15; position: relative; }
.gday .dn { font-size: 10px; color: var(--muted); }
.gday .dd { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.gday.today { background: var(--brand); border-color: var(--brand); }
.gday.today .dn, .gday.today .dd { color: #fff; }
.gday .dot { position: absolute; top: 4px; right: 5px; width: 4px; height: 4px; border-radius: 50%; background: #6d28d9; }
.gday.today .dot { background: #c4b5fd; }
.grow { flex: 0 0 13px; min-height: 13px; display: flex; gap: 1px; align-items: stretch; }
.grow .gtime { width: 38px; flex: 0 0 38px; display: flex; align-items: center; justify-content: flex-end; font-size: 9px; line-height: 1; color: #b0bac6; font-variant-numeric: tabular-nums; padding-right: 3px; }
.grow.hour-start { margin-top: 2px; }
.grow.hour-start .gtime { color: #334155; font-weight: 700; font-size: 12px; }

/* ===== 团队 / 全局排班（只读甘特） ===== */
.team-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 24px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.team-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 2px 0 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: #475569; }
.legend-item .sw { width: 10px; height: 10px; border-radius: 3px; }
.team-axis-head { display: flex; align-items: center; padding: 0 0 4px; font-size: 9px; color: #94a3b8; }
.team-axis-head .ta-spacer { width: 78px; flex: 0 0 78px; }
.team-axis-head span { flex: 1 1 0; }
.team-dept { font-size: 11px; color: #94a3b8; margin: 8px 0 4px; }
.team-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.team-name { width: 72px; flex: 0 0 72px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #0f172a; }
.team-axis {
  position: relative; flex: 1; height: 22px; border-radius: 4px; overflow: hidden;
  background-color: #fff;
  /* 每半小时一条细线（44 格），每整点一条深一点的线（22 格） */
  background-image:
    linear-gradient(to right, #cbd5e1 0 1px, transparent 1px),
    linear-gradient(to right, #eef2f7 0 1px, transparent 1px);
  background-size: calc(100% / 22) 100%, calc(100% / 44) 100%;
  background-repeat: repeat-x;
}
.team-seg { position: absolute; top: 2px; bottom: 2px; border-radius: 2px; }
.team-hours { width: 36px; flex: 0 0 36px; text-align: right; font-size: 10px; color: #94a3b8; font-variant-numeric: tabular-nums; }

/* 团队视图：点击展开整周 */
.team-row.clickable { cursor: pointer; border-radius: 6px; }
.team-row.clickable:hover { background: #f8fafc; }
.team-chevron { width: 18px; flex: 0 0 18px; text-align: center; color: #94a3b8; font-size: 12px; }
.team-week { margin: 2px 0 8px 78px; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.team-week-line { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.team-week-day { width: 76px; flex: 0 0 76px; font-size: 11px; color: #64748b; white-space: nowrap; }

/* ===== 全局排班：表格布局 ===== */
.tt-head, .tt-row {
  display: grid;
  grid-template-columns: 110px repeat(7, 1fr) 62px;
  align-items: center;
  gap: 4px;
}
.tt-head {
  position: sticky; top: 0; z-index: 6;
  background: #f1f5f9;
  font-size: 10px; color: #94a3b8;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.tt-day { text-align: center; }
.tt-row { padding: 3px 0; border-bottom: 1px solid #eef2f7; }
.tt-name { font-size: 12px; color: #0f172a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tt-name.clickable { cursor: pointer; font-weight: 600; }
.tt-name.clickable:hover { color: #6d28d9; }
.tt-cell { height: 18px; background: #fff; border-radius: 3px; position: relative; overflow: hidden; box-shadow: inset 0 0 0 1px #eef2f7; }
.mini-axis { position: absolute; inset: 0; }
.mini-seg { position: absolute; top: 1px; bottom: 1px; border-radius: 2px; }
.tt-total { text-align: right; font-size: 10px; color: #94a3b8; font-variant-numeric: tabular-nums; }
.tt-dept { font-size: 11px; color: #94a3b8; margin: 12px 0 2px; }
.tt-detail { margin: 4px 0 10px 0; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.tt-detail-line { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.tt-detail-day { width: 76px; flex: 0 0 76px; font-size: 11px; color: #64748b; white-space: nowrap; }

/* ===== 全局：按天折叠 ===== */
.day-acc { border-bottom: 1px solid var(--line); }
.day-head { display: flex; align-items: center; gap: 8px; padding: 11px 6px; cursor: pointer; border-radius: 8px; }
.day-head:hover { background: #f8fafc; }
.day-title { font-size: 13px; font-weight: 650; color: #0f172a; white-space: nowrap; }
.day-sum { flex: 1; font-size: 11px; color: #94a3b8; text-align: right; }
.day-body { padding: 0 0 8px 6px; }
.day-person { display: flex; align-items: center; gap: 6px; padding: 4px; border-radius: 6px; cursor: pointer; }
.day-person:hover { background: #f8fafc; }
.day-person-name { width: 72px; flex: 0 0 72px; font-size: 12px; color: #0f172a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 过去日期锁定 */
.cell.locked { opacity: 0.45; cursor: not-allowed; }
.gday.past { opacity: 0.55; }
.gday.selected { box-shadow: 0 0 0 2px #6d28d9; }

/* 全局：展开当日的时间段刻度 */
.day-axis-head { display: flex; align-items: center; gap: 6px; padding: 2px 4px 3px; }
.day-axis-labels { flex: 1; position: relative; height: 12px; }
.day-axis-labels span { position: absolute; top: 0; transform: translateX(-50%); font-size: 8px; color: #94a3b8; letter-spacing: -0.2px; }

/* 站内确认框文案 */
.confirm-msg { font-size: 15px; line-height: 1.65; color: #0f172a; margin: 2px 0 18px; white-space: pre-line; }

/* 全局：周标签页 */
.week-tabs { display: flex; gap: 6px; padding: 0 10px 8px; overflow-x: auto; scrollbar-width: none; }
.week-tabs::-webkit-scrollbar { display: none; }
.week-tab { flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 12px; color: #334155; white-space: nowrap; }
.week-tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.day-summary { font-size: 12px; color: #475569; padding: 2px 4px 8px; }

.day-person-name.inactive { color: #94a3b8; }
