/* ============ 基础 ============ */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f7cff;
  --primary-dark: #3a64e0;
  --success: #10b981;
  --success-dark: #0e9e72;
  --purple: #8b5cf6;
  --purple-dark: #7646ea;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --orange: #f59e0b;
  --dirty: #fbcfe8;
  --dirty-text: #831843;
  --cleaned: #bbf7d0;
  --noclean: #fde68a;
  --pending: #f3f4f6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ============ 顶部栏 ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #111827;
  color: #fff;
}

.topbar__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.topbar__actions { display: flex; align-items: center; gap: 8px; }

.topbar__btn {
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.06);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
}

.topbar__btn:hover { background: rgba(255,255,255,0.14); }
/* 顶部栏里的链接按钮（跳转预定登记）需要和 <button> 表现一致 */
a.topbar__btn { display: inline-block; text-decoration: none; line-height: 1.4; }

.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,0.2);
  transition: background .3s, box-shadow .3s;
}
.conn-dot.ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,0.2); }
.conn-dot.bad { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.2); }

/* ============ 主体 ============ */
.main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* 控制面板 */
.controls {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.countdown {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.countdown strong { color: var(--text); }
/* 当前日期时间：等宽数字，秒数跳动时不会左右抖动 */
.now-clock {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding-right: 8px;
  border-right: 1px solid var(--line, #e5e7eb);
}

.controls__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 4px;
}

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, transform .05s, box-shadow .15s;
  user-select: none;
}
.btn:active { transform: translateY(1px); }

.btn--outline {
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  color: #4f46e5;
}
.btn--outline:hover { background: #e0e7ff; }

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); }

.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: var(--success-dark); }

.btn--purple { background: var(--purple); color: #fff; }
.btn--purple:hover { background: var(--purple-dark); }

.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger-dark); }

.btn--ghost { color: var(--muted); }
.btn--ghost:hover { background: #f3f4f6; }

/* 小图标 */
.icon-refresh::before {
  content: "";
  display: inline-block; width: 14px; height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M17.65 6.35A7.95 7.95 0 0012 4a8 8 0 108 8h-2a6 6 0 11-6-6 5.9 5.9 0 014.22 1.78L13 11h7V4z'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M17.65 6.35A7.95 7.95 0 0012 4a8 8 0 108 8h-2a6 6 0 11-6-6 5.9 5.9 0 014.22 1.78L13 11h7V4z'/></svg>") center/contain no-repeat;
}

.icon-clock::before {
  content: "";
  display: inline-block; width: 13px; height: 13px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M12 2a10 10 0 100 20 10 10 0 000-20zm1 10.414l4.293 4.293-1.414 1.414L11 13.414V6h2z'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M12 2a10 10 0 100 20 10 10 0 000-20zm1 10.414l4.293 4.293-1.414 1.414L11 13.414V6h2z'/></svg>") center/contain no-repeat;
}

/* ============ 房间区域 ============ */
.rooms-panel { padding: 14px 14px 18px; position: relative; }

.floors {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 6px 0 12px;
}

.floor-row {
  display: flex;
  align-items: flex-start; /* 顶部对齐：备注撑高时方块顶边保持整齐 */
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.floor-row__refresh {
  margin-top: 14px; /* 相对 64px 房间方块垂直居中 */
  width: 36px; height: 36px; border-radius: 10px;
  background: #eef2ff;
  color: #4f46e5;
  border: 1px solid #c7d2fe;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.floor-row__refresh:hover { background: #e0e7ff; }

.floor-row__arrow {
  width: 22px; text-align: center; font-size: 20px; color: var(--purple);
  flex: 0 0 auto;
  height: 64px; /* 与房间方块同高，箭头垂直居中 */
  display: inline-flex; align-items: center; justify-content: center;
  visibility: hidden;
}
.floor-row.has-arrow .floor-row__arrow { visibility: visible; }

/* 单个房间 */
.room {
  position: relative;
  width: 64px; height: 64px;
  background: #f3f4f6;
  border-radius: 12px;
  border: 2px solid transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600;
  color: #1f2937;
  transition: transform .1s, box-shadow .15s, background .15s, border-color .15s;
  user-select: none;
}
.room:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(15,23,42,0.08); }
.room:active { transform: translateY(0); }

/* 背景类状态 */
.room.is-dirty    { background: var(--dirty); color: var(--dirty-text); }
.room.is-cleaned  { background: #bbf7d0; color: #065f46; }
.room.is-noclean  { background: #fde68a; color: #78350f; }

/* 边框类状态 */
.room.is-extended { border-color: #3b82f6; }
.room.is-checkout { border-color: #ef4444; }
.room.is-occupied { border-color: #3b82f6; }
.room.has-note    { border-color: var(--purple); }

/* 同时有 extended + cleaned -> cleaned 覆盖颜色 + 蓝色外框依然显示 */
.room.is-cleaned.is-extended { background: #86efac; }

/* 徽标 */
.room__badges {
  position: absolute;
  top: -10px;
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}
.badge {
  font-size: 11px;
  background: #fff;
  color: #4f46e5;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  padding: 1px 5px;
  line-height: 1.2;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.badge--red { color: #b91c1c; border-color: #fecaca; }
.badge--purple { color: var(--purple-dark); border-color: #ddd6fe; }
/* ---- 预定台账派生的标记 ----
   位置刻意与手动标记错开：续住占左边框，退房占右上角，
   手动标记则在顶部徽标行 / 左上角 / 右下角，两套互不重叠 */
/* 骑在左边框线上的「续」：形状同顶部徽标，但用浅蓝底白字，
   与前台手动勾的「续」（白底蓝字）一眼区分开，和右上角的「退」同属"有色底=自动判定" */
.room .badge--edge-left {
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 1px 4px;
  background: #60a5fa;
  color: #fff;
  border-color: #3b82f6;
}
.room .corner-tr {
  position: absolute;
  top: -8px;
  right: -6px;
  background: #b91c1c;
  color: #fff;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* 房间弹窗里的台账提示 */
.auto-stay-tip {
  margin-bottom: 10px;
  padding: 8px 10px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  color: #3730a3;
}

/* 左上角 住 */
.room .corner-tl {
  position: absolute;
  top: -8px;
  left: -6px;
  background: #3b82f6;
  color: #fff;
  width: 18px; height: 18px;
  border-radius: 50%;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* 左下角 查 */
.room .corner-bl {
  position: absolute;
  bottom: 2px;
  left: 5px;
  color: #92400e;
  font-size: 11px;
  font-weight: 700;
}

/* 右下角 退 */
.room .corner-br-txt {
  position: absolute;
  bottom: 2px;
  right: 5px;
  color: #b91c1c;
  font-size: 11px;
  font-weight: 700;
}

/* 右下角 待查红点 */
.room .corner-br {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 2px #fff;
}
/* 与“退”字并存时红点左移避让 */
.room .corner-br--shift { right: 20px; }

/* 房间 + 备注 的竖向容器 */
.room-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 64px;
  flex: 0 0 auto;
}

/* 方块下方备注内容（自动换行，完整显示） */
.room__note {
  width: 100%;
  font-size: 10px;
  line-height: 1.35;
  font-weight: 500;
  color: var(--purple-dark);
  text-align: center;
  word-break: break-all;      /* 连续数字/字母也能折行 */
  overflow-wrap: anywhere;
}

/* 选中（换房方案选中） */
.room.is-selected { box-shadow: 0 0 0 3px #fbbf24; }

/* ============ 图例 ============ */
.legend {
  margin-top: 6px;
  padding: 10px 6px 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  justify-content: center;
  font-size: 12.5px;
  color: #374151;
  border-top: 1px dashed var(--border);
}
.legend__item { display: inline-flex; align-items: center; gap: 5px; }
.legend__box {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 4px;
  background: #e5e7eb;
  border: 1px solid transparent;
  position: relative;
}
.legend__box--dirty    { background: var(--dirty); }
.legend__box--extended { background: #fff; border: 2px solid #3b82f6; }
.legend__box--cleaned  { background: #bbf7d0; }
.legend__box--noclean  { background: #fde68a; }
.legend__box--pending  { background: #f3f4f6; }
.legend__box--occupied { background: #fff; border: 2px solid #3b82f6; }
.legend__box--checked-hint { background: #fff; border: 1px solid #d1d5db; position: relative; }
.legend__box--checked-hint::after { content: "查"; position: absolute; left: 1px; bottom: -2px; font-size: 10px; color: #92400e; font-weight: 700; }
.legend__box--checkout { background: #fff; border: 2px solid #ef4444; position: relative; }
.legend__box--checkout::after { content: "退"; position: absolute; right: 0; bottom: -2px; font-size: 10px; color: #b91c1c; font-weight: 700; }
.legend__box--pendingcalc { background: #d1d5db; }
.legend__box--needcheck { background: #fff; border: 1px solid #d1d5db; }
.legend__box--needcheck::after { content: ""; position: absolute; right: 2px; bottom: 2px; width: 5px; height: 5px; border-radius: 50%; background: #ef4444; }
.legend__text--check { color: #92400e; font-weight: 700; font-size: 13px; }
/* 预定台账派生的两个标记，图例里按它们在房间上的真实位置画 */
.legend__box--auto-stay { background: #fff; border: 1px solid #d1d5db; overflow: visible; }
.legend__box--auto-stay::after {
  content: "续";
  position: absolute; left: -7px; top: 50%; transform: translateY(-50%);
  background: #60a5fa; color: #fff;
  border: 1px solid #3b82f6; border-radius: 4px;
  padding: 0 2px;
  font-size: 8px; font-weight: 700; line-height: 1.4;
}
.legend__box--auto-out { background: #fff; border: 1px solid #d1d5db; overflow: visible; }
.legend__box--auto-out::after {
  content: "退";
  position: absolute; top: -5px; right: -5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #b91c1c; color: #fff;
  font-size: 8px; font-weight: 700; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

.rooms-panel__footer {
  position: absolute;
  right: 14px;
  bottom: 14px;
}

/* ============ 弹窗 ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal__mask {
  position: absolute; inset: 0;
  background: rgba(17,24,39,0.5);
  backdrop-filter: blur(2px);
}
.modal__card {
  position: relative;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 30px 60px rgba(15,23,42,0.25);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popup .18s ease-out;
}
.modal__card--small { max-width: 360px; }
@keyframes popup {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal__head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal__head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal__close {
  font-size: 24px; line-height: 1; color: #9ca3af;
  padding: 0 4px;
}
.modal__close:hover { color: var(--text); }
.modal__body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}
.modal__foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* 复选框网格 */
.checks {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 10px;
  margin-bottom: 14px;
}
.checks label {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background .1s, border-color .1s;
}
.checks label:hover { background: #f9fafb; }
.checks label:has(input:checked) { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }
.checks input { width: 16px; height: 16px; accent-color: var(--primary); }

.field {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--muted);
}
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  color: var(--text);
  background: #fff;
}
.field textarea:focus { outline: none; border-color: var(--primary); }

/* chips / 公共房选择 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #374151;
  font-size: 13px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.chip:hover { background: #e5e7eb; }
.chip.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

.hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }

/* 方案结果 */
.swap-result { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.swap-plan {
  padding: 10px 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.swap-plan:hover { background: #eef2ff; }
.swap-plan.is-active {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

.sub {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.record-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 40vh;
  overflow-y: auto;
}
.record-list li {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.record-list li:last-child { border-bottom: none; }
.record-list .time { color: var(--muted); font-size: 12px; }
.record-list .del {
  color: #ef4444; font-size: 12px; padding: 4px 8px;
  border-radius: 6px;
}
.record-list .del:hover { background: #fef2f2; }

/* 统计 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stats-cell {
  padding: 12px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: background .1s, border-color .1s;
}
.stats-cell:hover { background: #eef2ff; border-color: #c7d2fe; }
.stats-cell.is-active { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.stats-cell__label { font-size: 12px; color: inherit; opacity: .85; }
.stats-cell__value { font-size: 22px; font-weight: 700; margin-top: 2px; }

.stats-rooms {
  margin-top: 8px;
  padding: 10px;
  min-height: 40px;
  background: #f9fafb;
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
}
.stats-rooms .r {
  display: inline-block;
  margin: 2px;
  padding: 4px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-weight: 600;
  font-size: 13px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  animation: toastin .2s ease-out;
}
@keyframes toastin {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ 响应式：移动端 ============ */
@media (max-width: 600px) {
  .main { padding: 10px; gap: 10px; }
  .panel { border-radius: 12px; }
  .controls { padding: 12px; }
  .rooms-panel { padding-bottom: 70px; }
  .rooms-panel__footer {
    position: static;
    display: flex;
    justify-content: center;
    margin-top: 12px;
  }
  .room {
    width: 58px; height: 58px;
    font-size: 15px;
    border-radius: 10px;
  }
  .floor-row { gap: 8px; }
  .room-wrap { width: 58px; }
  .floor-row__refresh { width: 32px; height: 32px; border-radius: 8px; margin-top: 13px; }
  .floor-row__arrow { height: 58px; }
  .checks { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .legend { font-size: 11.5px; gap: 8px 10px; }
  .topbar__title { font-size: 15px; }
  .btn { padding: 8px 14px; font-size: 13px; }
}

@media (max-width: 380px) {
  .room { width: 52px; height: 52px; font-size: 14px; }
  .room-wrap { width: 52px; }
  .floor-row__refresh { margin-top: 10px; }
  .floor-row__arrow { height: 52px; }
}

