/* ========== 基础 ========== */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text2: #6b7280;
  --text3: #9ca3af;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-bg: #eff6ff;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
input, select { font-family: inherit; }

/* ========== 顶栏 ========== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(246, 247, 249, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.logo { font-size: 18px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 8px; }
.nav-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 20px; line-height: 1;
  cursor: pointer; transition: background .15s;
}
.nav-btn:hover { background: var(--primary-bg); border-color: var(--primary); color: var(--primary-dark); }
.today-btn {
  padding: 6px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; color: var(--text2); font-size: 13px; cursor: pointer;
}
.today-btn:hover { color: var(--primary-dark); border-color: var(--primary); }
.month-label { min-width: 96px; text-align: center; font-size: 16px; font-weight: 600; }

/* ========== 布局 ========== */
.layout {
  max-width: 1200px; margin: 0 auto; padding: 16px;
  display: flex; gap: 16px; align-items: flex-start;
}

/* ========== 日历区 ========== */
.calendar-wrap {
  flex: 1; min-width: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
}
.weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px;
}
.weekdays div {
  text-align: center; font-size: 12px; color: var(--text2);
  padding: 6px 0; font-weight: 500;
}
.weekdays .sun, .weekdays .sat { color: var(--text3); }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cell {
  min-height: 92px; border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; background: #fff; cursor: pointer; position: relative;
  display: flex; flex-direction: column; gap: 4px;
  transition: box-shadow .12s, transform .05s;
}
.cell:hover { box-shadow: var(--shadow); border-color: #d1d5db; }
.cell:active { transform: scale(.97); }
.cell.out { opacity: .38; }
.cell.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.cell.weekend { background: #fafbfc; }
.cell.pick-target { border-style: dashed; border-color: var(--primary); }
.day-num { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1; }
.cell.today .day-num { color: var(--primary); }
.cell.weekend .day-num { color: var(--text3); }
.dots { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.dot {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 11px; font-weight: 600; line-height: 1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .3);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .1), inset 0 -1px 1px rgba(0, 0, 0, .12);
}
.dot-more { font-size: 11px; color: var(--text2); align-self: center; }
.calendar-hint { margin-top: 10px; font-size: 12px; color: var(--text3); text-align: center; }

/* ========== 工具栏 ========== */
.toolbar { width: 320px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; }
.panel {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.panel h2 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.panel h2 .count { font-weight: 400; color: var(--text3); font-size: 12px; margin-left: 4px; }

/* 人员列表 */
.people-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.people-list:empty::after {
  content: "还没有人员，先添加一个吧";
  display: block; text-align: center; color: var(--text3);
  font-size: 13px; padding: 10px 0;
}
.person-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; cursor: pointer; user-select: none; transition: box-shadow .12s;
}
.person-card:hover { box-shadow: var(--shadow); }
.person-card.pick {
  border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary);
  background: var(--primary-bg);
}
.person-card .swatch { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(0,0,0,.1); }
.person-card .name { flex: 1; font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-card .tag { font-size: 11px; color: var(--primary-dark); background: var(--primary-bg); border-radius: 6px; padding: 2px 6px; }
.person-card .del {
  border: none; background: none; color: var(--text3); font-size: 16px;
  cursor: pointer; width: 24px; height: 24px; border-radius: 6px; line-height: 1; flex-shrink: 0;
}
.person-card .del:hover { color: var(--danger); background: #fef2f2; }

/* 添加人员 */
.add-person input { width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #fff; }
.add-person input:focus, .add-person input:active { outline: none; border-color: var(--primary); }
.color-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.color-swatch {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform .1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--text); }

/* 通用 */
.btn {
  border: none; border-radius: 10px; padding: 10px 14px; font-size: 14px;
  cursor: pointer; font-weight: 500; transition: filter .15s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn.ghost:hover { border-color: var(--text3); }
.btn.danger-ghost { background: #fff; border: 1px solid #fecaca; color: var(--danger); }
.btn.danger-ghost:hover { background: #fef2f2; }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 12px; }

/* 表单字段 */
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
input[type=text], input[type=number], input[type=date], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.two-col .field:last-child select { padding: 8px 6px; }
.custom-shift { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.custom-shift span { font-size: 13px; color: var(--text2); }
.custom-shift input { width: 56px; text-align: center; }
.custom-shift input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* chips */
.chip-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; font-size: 13px; user-select: none;
  color: var(--text); transition: background .12s;
}
.chip:hover { border-color: var(--text3); }
.chip.on { border-color: var(--primary); background: var(--primary-bg); color: var(--primary-dark); font-weight: 600; }
.chip .swatch { width: 10px; height: 10px; border-radius: 50%; }

/* 提示与操作 */
.hint { font-size: 12px; color: var(--text3); margin-top: 8px; line-height: 1.5; }
.hint.ok { color: #16a34a; }
.hint.err { color: var(--danger); }
.data-ops { display: flex; gap: 8px; }
.data-ops .btn { flex: 1; padding: 8px 6px; font-size: 13px; }

/* ========== 浮动按钮（移动端） ========== */
.fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 30;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; font-size: 22px;
  box-shadow: 0 6px 16px rgba(59, 130, 246, .45);
  display: none; align-items: center; justify-content: center; cursor: pointer;
}
.fab:active { transform: scale(.92); }

/* ========== 遮罩 ========== */
.mask {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .4); z-index: 35;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.mask.show { opacity: 1; pointer-events: auto; }

/* ========== 日期编辑弹层 ========== */
.modal {
  position: fixed; z-index: 45; left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(.95);
  background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg);
  width: min(380px, calc(100vw - 32px)); max-height: 82vh;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.modal.show { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 600;
}
.modal-close {
  border: none; background: none; font-size: 20px; color: var(--text3);
  cursor: pointer; width: 28px; height: 28px; border-radius: 8px; line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 12px 16px; overflow-y: auto; }
.modal-tip { font-size: 12px; color: var(--text3); margin-bottom: 10px; }
.modal-people { display: flex; flex-direction: column; gap: 8px; }
.modal-people:empty::after {
  content: "暂无人员，请先在工具栏添加"; display: block;
  text-align: center; color: var(--text3); font-size: 13px; padding: 12px 0;
}
.person-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--border); user-select: none; transition: background .12s;
}
.person-row:hover { border-color: var(--text3); }
.person-row .swatch { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; }
.person-row .name { flex: 1; font-size: 14px; font-weight: 500; }
.person-row .check {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 13px; transition: all .12s;
}
.person-row.on { border-color: var(--pc, var(--primary)); background: color-mix(in srgb, var(--pc, var(--primary)) 10%, white); }
.person-row.on .check { background: var(--pc, var(--primary)); border-color: var(--pc, var(--primary)); }
.modal-foot {
  display: flex; gap: 10px; padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.modal-foot .btn { flex: 1; }

/* ========== 点选模式提示条 ========== */
.pick-bar {
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 10px;
  background: var(--primary-bg); border: 1px solid #bfdbfe;
  border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--primary-dark);
}
.pick-bar .swatch { width: 12px; height: 12px; border-radius: 50%; }
.pick-bar b { font-weight: 600; }
.pick-bar .btn { margin-left: auto; }

/* ========== 响应式：移动端 ========== */
@media (max-width: 900px) {
  .layout { flex-direction: column; padding: 10px; padding-bottom: 96px; gap: 12px; }
  .topbar-inner { padding: 8px 12px; }
  .logo { font-size: 16px; }
  .month-label { min-width: 88px; font-size: 15px; }
  .today-btn { padding: 5px 10px; }
  .calendar-wrap { padding: 8px; }
  .weekdays { gap: 3px; }
  .weekdays div { padding: 4px 0; font-size: 11px; }
  .grid { gap: 3px; }
  .cell {
    min-height: 0; aspect-ratio: 1 / .95;
    padding: 4px; border-radius: 8px; gap: 3px;
  }
  .day-num { font-size: 12px; }
  .dots { gap: 3px; }
  .dot { width: 14px; height: 14px; font-size: 9px; }

  /* 工具栏变为底部抽屉 */
  .toolbar {
    position: fixed; left: 0; right: 0; bottom: 0; width: 100%;
    max-height: 76vh; overflow-y: auto;
    background: var(--card);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 28px rgba(0, 0, 0, .14);
    transform: translateY(105%);
    transition: transform .26s ease;
    z-index: 40;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 12px;
  }
  .toolbar.open { transform: none; }
  .fab { display: flex; }

  .modal { width: calc(100vw - 20px); }
}

@media (min-width: 901px) {
  .fab { display: none !important; }
}
