/* ============================================================
   全局样式
   ============================================================ */
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
       background: #f4f6fa; color: #1a1f36; font-size: 14px; }
.hidden { display: none !important; }
.muted { color: #6b7280; }
.small { font-size: 12px; }
.err { color: #c00; margin-top: 8px; font-size: 13px; }

/* 登录页 */
.view { min-height: 100vh; }
#login-view { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#1f3864 0%, #2e74b5 100%); }
.login-box { background: #fff; padding: 40px 36px; border-radius: 12px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.login-box h1 { margin: 0 0 4px; color: #1f3864; }
.login-box .hint { margin: 0 0 24px; color: #6b7280; font-size: 13px; }
.login-box label { display: block; font-size: 12px; color: #4b5563; margin-top: 12px; }
.login-box input { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 6px; margin-top: 4px; font-size: 14px; }
.login-box button { width: 100%; padding: 10px; margin-top: 20px; background: #1f3864; color: #fff; border: 0; border-radius: 6px; font-size: 15px; cursor: pointer; }
.login-box button:hover { background: #2e74b5; }
.login-box .muted { margin-top: 16px; font-size: 11px; text-align: center; }

/* 主应用顶栏 */
.topbar { display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 52px;
          background: #1f3864; color: #fff; border-bottom: 1px solid #1e2e4f; }
.brand { font-weight: 700; font-size: 16px; }
.topnav { display: flex; gap: 4px; }
.topnav button { background: transparent; border: 0; color: #cbd5e1; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.topnav button:hover { background: rgba(255,255,255,0.1); color: #fff; }
.topnav button.active { background: #2e74b5; color: #fff; }
.topright { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topright select, .topright input[type=month] { background: #2e3a5a; color: #fff; border: 1px solid #3b4970; padding: 5px 10px; border-radius: 5px; font-size: 13px; }
.month-nav { display: inline-flex; align-items: center; gap: 4px; }
.month-nav .nav-btn { background: #2e3a5a; color: #fff; border: 1px solid #3b4970; padding: 5px 12px; border-radius: 5px; cursor: pointer; font-size: 13px; line-height: 1.4; }
.month-nav .nav-btn:hover { background: #3b4970; }
.month-nav .nav-btn.today { font-size: 12px; padding: 5px 10px; }
.month-display {
  background: #2e3a5a; color: #fff; border: 1px solid #3b4970;
  padding: 5px 14px; border-radius: 5px; font-size: 14px; font-weight: 600;
  min-width: 110px; text-align: center; user-select: none; line-height: 1.4;
}
.topright #user-info { font-size: 12px; opacity: 0.85; }

/* mini-loader：所有 API 调用期间显示，让用户知道系统在工作 */
.mini-loader {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff; padding: 4px 10px; border-radius: 12px;
  font-size: 12px; line-height: 1;
}
.mini-spinner {
  display: inline-block; width: 12px; height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.mini-text { font-weight: 500; }

/* 全局阻塞遮罩：可爱风格的飞机加载动画 */
#global-blocker {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(2px);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  cursor: wait;
  user-select: none;
}
#global-blocker.hidden { display: none; }
#global-blocker .cute-card {
  background: linear-gradient(160deg, #e0f2fe 0%, #fce7f3 100%);
  padding: 28px 36px 22px;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  text-align: center;
  min-width: 240px;
  animation: card-pop 0.35s cubic-bezier(.34,1.56,.64,1);
}
@keyframes card-pop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* 飞机+云朵舞台 */
#global-blocker .cute-stage {
  position: relative;
  width: 180px; height: 80px;
  margin: 0 auto 12px;
  overflow: hidden;
}
#global-blocker .cute-plane {
  position: absolute;
  top: 24px; left: 50%;
  font-size: 36px;
  transform: translateX(-50%);
  animation: plane-float 1.4s ease-in-out infinite;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.15));
  z-index: 2;
}
@keyframes plane-float {
  0%, 100% { transform: translate(-50%, 0) rotate(-5deg); }
  50%      { transform: translate(-50%, -10px) rotate(5deg); }
}

#global-blocker .cute-cloud {
  position: absolute;
  font-size: 22px;
  opacity: 0.85;
  animation: cloud-drift 4s linear infinite;
}
#global-blocker .cloud-1 { top: 0; left: 100%; animation-delay: 0s; }
#global-blocker .cloud-2 { top: 40px; left: 100%; animation-delay: -1.3s; font-size: 16px; opacity: 0.6; }
#global-blocker .cloud-3 { top: 18px; left: 100%; animation-delay: -2.6s; font-size: 28px; opacity: 0.7; }
@keyframes cloud-drift {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-260px); }
}

/* 三个跳动小点 */
#global-blocker .cute-trail {
  display: flex; gap: 6px; justify-content: center;
  margin-bottom: 10px;
}
#global-blocker .cute-trail span {
  width: 8px; height: 8px;
  background: #f472b6;
  border-radius: 50%;
  display: inline-block;
  animation: dot-bounce 1.2s infinite ease-in-out;
}
#global-blocker .cute-trail span:nth-child(2) { animation-delay: 0.2s; background: #60a5fa; }
#global-blocker .cute-trail span:nth-child(3) { animation-delay: 0.4s; background: #fbbf24; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
  40%           { transform: translateY(-8px); opacity: 1; }
}

#global-blocker .cute-msg {
  font-size: 15px;
  color: #1f3864;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: opacity 0.18s;
  min-height: 22px;
}
#global-blocker .cute-sub {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
}

/* 顶部细线进度条（API 调用期间） */
#top-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent 0%, #2e74b5 50%, transparent 100%);
  background-size: 200% 100%;
  animation: top-progress-slide 1.2s linear infinite;
  z-index: 4000; pointer-events: none;
}
@keyframes top-progress-slide {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.topright button.text { background: transparent; color: #cbd5e1; border: 0; cursor: pointer; }

/* 主区 */
main { padding: 16px 20px; }
.page { display: none; }
.page.active { display: block; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.btn { background: #fff; border: 1px solid #d1d5db; padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
       display: inline-flex; align-items: center; gap: 6px; color: #1f2937; }
.btn:hover { border-color: #1f3864; color: #1f3864; }
.btn.primary { background: #1f3864; color: #fff; border-color: #1f3864; }
.btn.primary:hover { background: #2e74b5; }
.btn.danger { color: #c00; border-color: #fcc; }

/* 布局：侧栏 + 网格 */
.layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
.sidebar {
  background: #fff; border-radius: 8px; padding: 12px;
  position: sticky; top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  align-self: start;
}
/* 手机/窄屏不固定（grid-template-columns 已改成单列） */
@media (max-width: 1100px) {
  .sidebar { position: static; max-height: none; }
}
.sidebar h3 { margin: 4px 0 8px; font-size: 13px; color: #1f3864; display: flex; align-items: center; gap: 6px; }
.badge { background: #c00; color: #fff; padding: 1px 6px; border-radius: 999px; font-size: 11px; }
.cards .card { background: #fafbfd; border-radius: 6px; padding: 8px; margin-bottom: 6px; font-size: 12px; cursor: grab; border-left: 4px solid transparent; }
.cards .card:active { cursor: grabbing; }
.cards .card .head { font-weight: 600; color: #1f3864; display: flex; justify-content: space-between; align-items: center; }
.cards .card .meta { color: #6b7280; font-size: 11px; margin-top: 2px; }
.cards .unplaced-card { border-left-color: #c00; background: #fff7f7; }
.sidebar.drop-target-sidebar, #unplaced-list.drop-target-sidebar {
  background: #e0f2fe; outline: 2px dashed #1f3864; outline-offset: -4px;
}
/* 让未排区始终有最小高度，空时也能 drop */
#unplaced-list { min-height: 80px; }
.unplaced-empty {
  border: 2px dashed #cbd5e1;
  border-radius: 6px;
  padding: 20px 12px;
  text-align: center;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.6;
  pointer-events: none;  /* 不阻挡 drop 事件 */
}
.unplaced-empty small { color: #94a3b8; }
.cards .unplaced-card .head { color: #c00; }
.cards .reason { margin-top: 6px; font-size: 11px; }
.cards .reason summary { color: #2e74b5; cursor: pointer; user-select: none; }
.cards .reason summary:hover { color: #1f3864; }
.cards .reason-line { padding: 2px 0 2px 8px; color: #4b5563; border-left: 2px solid #e5e7eb; margin-left: 4px; }
.cards .reason-line b { color: #1f3864; }

/* 候选格高亮 */
.grid td.cell.highlight { background: #fff9c4 !important; outline: 2px solid #f59e0b; }

/* 月历网格 */
.grid-wrap { background: #fff; border-radius: 8px; padding: 8px; overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 12px; }
.grid th, .grid td { border: 1px solid #d8dde6; padding: 0; vertical-align: top; }
.grid th { background: #f1f5fb; padding: 8px 4px; font-weight: 600; color: #1f3864; }
.grid th.date, .grid td.date { width: 86px; padding: 6px 8px; text-align: left; font-size: 11px; }
.grid td.cell { height: 86px; min-width: 46px; padding: 2px; position: relative; }
.grid th.slot-head {
  padding: 6px 4px; font-size: 12px;
  background: #f1f5fb; border-bottom: 2px solid #cbd5e1;
}
.grid th.hour-head {
  padding: 3px 0; font-size: 10px;
  color: #6b7280; font-weight: 500;
  border-right: 1px solid #e5e7eb;
}
.grid th.hour-head.slot-edge { border-right: 2px solid #cbd5e1; }
.grid td.cell.slot-edge { border-right: 2px solid #cbd5e1; }
.grid td.cell.slot-bg-a { background: #fafbfd; }
.grid td.cell.slot-bg-b { background: #fff; }
.grid td.cell.slot-bg-a.empty:hover, .grid td.cell.slot-bg-b.empty:hover {
  background: #e0f2fe;
}
.grid tr.weekend td.date { background: #fff3e0; color: #c00; }
.grid td.fixed { background: #f0f0f0 !important; }
.grid td.fixed .fixed-label { font-size: 11px; color: #555; text-align: center; padding-top: 20px; }

.ph {
  font-size: 11px; padding: 4px 6px; border-radius: 3px;
  margin-bottom: 2px; line-height: 1.35; cursor: grab;
  border: 1px solid rgba(0,0,0,0.08);
}
.ph:active { cursor: grabbing; }
.ph .label { display: block; color: #1f3864; font-weight: 700; font-size: 12px; }
.ph .who { display: block; color: #111; font-weight: 600; margin-top: 1px; }
.ph .stus { display: block; color: #444; font-size: 11px; margin-top: 1px; }

/* 2h 配对合并为一个 4h 班次容器：内部左右两栏分前/后 */
.ph-pair {
  padding: 3px 5px;
  line-height: 1.25;
  position: relative;
}
.ph-pair .pair-label {
  font-weight: 700; color: #1f3864; font-size: 12px;
  text-align: center; padding: 0 0 2px;
}
.ph-pair .pair-cols {
  display: flex; gap: 4px;
}
.ph-pair .pair-col {
  flex: 1; min-width: 0;
  font-size: 10px; line-height: 1.3;
  padding: 0 2px;
}
.ph-pair .pair-col:first-child {
  border-right: 1px dashed rgba(0,0,0,0.25);
}
.ph-pair .pair-tag-row {
  font-weight: 600; color: #111;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ph-pair .pair-tag {
  background: rgba(0,0,0,0.12); border-radius: 2px;
  padding: 0 4px; font-weight: 700; font-size: 9px;
  color: #1f3864;
}
.ph-pair .pair-stus {
  color: #444; font-size: 10px;
  line-height: 1.25; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* 精确时刻 ⏱ 编辑按钮 + 显示 */
.ph .time-edit-btn {
  border: 0; background: transparent;
  cursor: pointer; padding: 0 4px;
  font-size: 11px; color: #6b7280;
  float: right; line-height: 1;
}
.ph .time-edit-btn:hover { color: #1f3864; }
.ph .exact-time {
  font-size: 10px; color: #2e74b5;
  font-weight: 600; margin-top: 1px;
}
.ph .exact-time-inline {
  font-size: 10px; color: #2e74b5;
  font-weight: 500;
}

/* 特殊场次 */
.ph-adhoc {
  border: 1px solid #7b1fa2 !important;
  position: relative;
}
.ph-adhoc::before {
  content: "特";
  position: absolute; top: -6px; left: -6px;
  background: #7b1fa2; color: #fff;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.ph .adhoc-time { color: #6b7280; font-size: 10px; font-weight: 400; }
.cards .adhoc-card { background: #f3e5f5; }
.cards .adhoc-card .head { color: #6a1b9a; }

/* 配合人员：底部独立一行 */
.ph .helper-row, .ph-pair .helper-row {
  margin-top: 3px;
  padding-top: 2px;
  border-top: 1px dashed rgba(0,0,0,0.18);
  font-size: 10px;
  color: #555;
  text-align: center;
  font-style: italic;
}

/* pair 分槽：当 2h 配对的两条 2h 不在同一时段（旧数据），单独显示 */
.ph.ph-pair-split {
  border-left: 3px dashed #f59e0b !important;
}
.ph .split-warn {
  background: #f59e0b; color: #fff;
  padding: 0 4px; border-radius: 2px;
  font-size: 9px; vertical-align: middle;
  cursor: help;
}
.ph.drop-hover { outline: 2px solid #1f3864; }
.cell.drop-target { background: #e0f2fe; }
.cell.drop-forbid { background: #fee2e2; }
.cell.drop-swap { background: #fef3c7; outline: 2px dashed #f59e0b; }
.cell.drop-swap::before {
  content: "↔ 互换";
  position: absolute; top: 2px; right: 4px;
  font-size: 10px; color: #b45309; font-weight: 600;
  background: #fff; padding: 1px 4px; border-radius: 3px; pointer-events: none;
}

/* 冲突标注 */
.ph.conflict-error {
  border: 2px solid #dc2626 !important;
  box-shadow: 0 0 0 1px #fecaca inset;
  position: relative;
}
.ph.conflict-warn {
  border: 2px dashed #f59e0b !important;
  position: relative;
}
.ph .conflict-badge {
  position: absolute; top: -6px; right: -6px;
  background: #dc2626; color: #fff;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.ph.conflict-warn .conflict-badge { background: #f59e0b; }

/* 数据表 */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td { padding: 8px 12px; border-bottom: 1px solid #eef2f8; font-size: 13px; text-align: left; }
.data-table th { background: #f1f5fb; color: #1f3864; font-weight: 600; font-size: 12px; }
.data-table tr:hover td { background: #fafbfd; }

.subsec { background: #fff; border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; }
.subsec h3 { margin: 4px 0 10px; font-size: 14px; color: #2e74b5; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: #fff; border-radius: 10px; width: 460px; max-width: 90vw; max-height: 80vh; display: flex; flex-direction: column; }
.modal-box header { padding: 14px 18px; border-bottom: 1px solid #eef2f8; display: flex; justify-content: space-between; font-weight: 600; }
.modal-box header .close { background: transparent; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: #6b7280; }
.modal-box #modal-body { padding: 16px 18px; overflow: auto; }
.modal-box #modal-body label { display: block; font-size: 12px; color: #4b5563; margin-top: 8px; }
.modal-box #modal-body input, .modal-box #modal-body select, .modal-box #modal-body textarea { width: 100%; padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 5px; margin-top: 3px; font-size: 13px; box-sizing: border-box; }
.modal-box footer { padding: 12px 18px; border-top: 1px solid #eef2f8; display: flex; justify-content: flex-end; gap: 8px; }

/* Toast — 屏幕中上大号通知 */
.toast {
  position: fixed;
  top: 28%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(26, 31, 54, 0.92);
  backdrop-filter: blur(6px);
  color: #fff;
  padding: 20px 36px;
  border-radius: 14px;
  z-index: 2500;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 1px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255,255,255,0.08) inset;
  pointer-events: none;
  text-align: center;
  min-width: 200px;
  max-width: 70vw;
  animation: toast-pop 0.32s cubic-bezier(.34,1.56,.64,1);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.toast::before {
  font-size: 26px;
  line-height: 1;
}
.toast.ok {
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.95), rgba(5, 150, 105, 0.95));
}
.toast.ok::before { content: "✅"; }
.toast.err {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.95), rgba(185, 28, 28, 0.95));
}
.toast.err::before { content: "⚠️"; }
.toast:not(.ok):not(.err)::before { content: "💬"; }
@keyframes toast-pop {
  0%   { transform: translate(-50%, -65%) scale(0.7); opacity: 0; }
  60%  { transform: translate(-50%, -48%) scale(1.06); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* Loading overlay (导入/排班进度) */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 3000; backdrop-filter: blur(2px);
}
.loading-box {
  background: #fff; border-radius: 12px; padding: 30px 40px; min-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #e5e7eb; border-top-color: #1f3864;
  border-radius: 50%; animation: spin 0.9s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 16px; font-weight: 600; color: #1f3864; margin-bottom: 6px; }
.loading-step { font-size: 13px; color: #4b5563; margin-bottom: 14px; min-height: 18px; }
.progress-track {
  background: #e5e7eb; height: 6px; border-radius: 3px; overflow: hidden;
  margin-bottom: 8px;
}
.progress-fill {
  background: linear-gradient(90deg, #1f3864 0%, #2e74b5 100%);
  height: 100%; width: 0%; transition: width 0.3s ease;
}
.loading-detail { font-size: 11px; color: #6b7280; margin-top: 4px; min-height: 14px; }

/* 打印 */
@media print {
  body { background: #fff; }
  .topbar, .sidebar, .toolbar, #login-view { display: none !important; }
  .grid-wrap { box-shadow: none; padding: 0; }
  .layout { grid-template-columns: 1fr; }
  .grid { font-size: 9px; }
  .grid td.cell { height: 50px; }
  @page { size: A3 landscape; margin: 8mm; }
}
