* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
  -webkit-overflow-scrolling: touch;
}

:root {
  --border-color: #d1d8e0;
  --text-main: #2d3436;
  --text-muted: #b2bec3;
  --color-1-pale: #f0f7ff;
  --color-2-pale: #fff5f5;
  --color-3-pale: #f0fff4;
  --color-4-pale: #f6ffed;
}

body {
  background-image: url("Images/16pic_745596_b.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-color: #f0f2f5;
  margin: 0;
  padding: 20px;
  font-family:
    "Outfit",
    -apple-system,
    sans-serif;
  color: var(--text-main);
  min-height: 100vh;
}

.calendar-app {
  max-width: 1100px;
  margin: 10px auto;
  background: rgba(255, 255, 255, 0.6);
  padding: 15px 25px;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  position: relative;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.5rem;
  font-weight: 800;
  flex: 1;
  /* 讓容器展開，提供貓貓跑動軌道空間 */
  min-width: 0;
}

.cat-track {
  flex: 1;
  /* 佔滿剩餘空白距離 */
  position: relative;
  height: 45px;
  margin: 0 15px 0 5px;
  /* 與旁邊按鈕格開 */
  min-width: 100px;
  /* 保證有最低跑動空間 */
  overflow: hidden;
  /* 防止溢出干擾 */
}

.cat-wrapper {
  position: absolute;
  top: 50%;
  animation: roamLeftRight 20s linear infinite;
}

.cat-container {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  animation: catPushOrder 20s step-end infinite;
}

.logo-text {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
}

.logo-cat {
  width: 80px;
  height: auto;
  display: block;
  animation: catPushFace 20s step-end infinite;
}

@keyframes catPushOrder {
  0% {
    flex-direction: row;
  }

  /* 往右移動時：貓(左) 字(右) */
  50% {
    flex-direction: row-reverse;
  }

  /* 往左移動時：字(左) 貓(右) */
  100% {
    flex-direction: row;
  }
}

@keyframes catPushFace {
  0% {
    transform: scaleX(1);
  }

  /* 面向右 */
  50% {
    transform: scaleX(-1);
  }

  /* 面向左 */
  100% {
    transform: scaleX(1);
  }
}

/* 計算左右位移，並使用 transform 補償自身寬度讓它剛好碰到邊緣 */
@keyframes roamLeftRight {
  0% {
    left: 0%;
    transform: translate(0%, -50%);
  }

  49.99% {
    left: 100%;
    transform: translate(-100%, -50%);
  }

  50% {
    left: 100%;
    transform: translate(-100%, -50%);
  }

  99.99% {
    left: 0%;
    transform: translate(0%, -50%);
  }

  100% {
    left: 0%;
    transform: translate(0%, -50%);
  }
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  /* 允許自動換行避免按鈕過度擁擠 */
  justify-content: flex-end;
  gap: 8px;
}

.action-btn {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.nav-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 600px;
  margin: 0 auto 10px auto;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.nav-cell {
  background: transparent;
  border: none;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-main);
  border-right: 1px solid #eee;
}

.nav-cell.main {
  background: #f8f9fa;
  cursor: default;
}

.nav-cell.side {
  opacity: 0.35;
}

.nav-cell.arrow {
  color: #95a5a6;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 10px;
  /* 從 15px 縮小，緊湊版面 */
  padding: 4px 6px;
  /* 縮小內距降低高度 */
  background: rgba(255, 255, 255, 0.45);
  border-radius: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 4px;
  /* 縮小內外距 */
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: 0.2s;
}

.stat-item:hover {
  filter: brightness(0.95);
}

.stat-item.solo-active {
  transform: scale(1.05);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  outline: 2px solid currentColor;
  background: #fff;
  z-index: 2;
}

.stat-item.s1 {
  border-color: #3498db;
  color: #3498db;
  background: #ebf5fb;
}

.stat-item.s2 {
  border-color: #e74c3c;
  color: #e74c3c;
  background: #fdedec;
}

.stat-item.s3 {
  border-color: #2ecc71;
  color: #2ecc71;
  background: #eafaf1;
}

.stat-item.s4 {
  border-color: #f39c12;
  color: #f39c12;
  background: #fef5e7;
}

/* =========================
   單一員工專注模式 (Solo Mode)
   ========================= */

/* 非指定員工按鈕淡化為灰白且無法點擊 */
body[data-solo="1"] .staff-btn:not(.btn-1) {
  opacity: 0.15 !important;
  filter: grayscale(1);
  pointer-events: none;
}

body[data-solo="2"] .staff-btn:not(.btn-2) {
  opacity: 0.15 !important;
  filter: grayscale(1);
  pointer-events: none;
}

body[data-solo="3"] .staff-btn:not(.btn-3) {
  opacity: 0.15 !important;
  filter: grayscale(1);
  pointer-events: none;
}

body[data-solo="4"] .staff-btn:not(.btn-4) {
  opacity: 0.15 !important;
  filter: grayscale(1);
  pointer-events: none;
}

/* 指定員工當週(月)沒有排班的日子，套用紅色虛線外框 */
body[data-solo="1"] .date-cell:not(.other-month):not(.has-s1) {
  border: 2px dashed #e74c3c !important;
}

body[data-solo="2"] .date-cell:not(.other-month):not(.has-s2) {
  border: 2px dashed #e74c3c !important;
}

body[data-solo="3"] .date-cell:not(.other-month):not(.has-s3) {
  border: 2px dashed #e74c3c !important;
}

body[data-solo="4"] .date-cell:not(.other-month):not(.has-s4) {
  border: 2px dashed #e74c3c !important;
}

.weekday-header {
  display: grid;
  grid-template-columns: repeat(7, 14.2857%);
  text-align: center;
  font-weight: 700;
  padding-bottom: 10px;
  color: #636e72;
  /* 改為深灰色與早中晚一致 */
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 14.2857%);
  border-top: 1.5px solid var(--border-color);
}

.date-cell {
  min-height: 120px;
  border-right: 1.5px solid var(--border-color);
  border-bottom: 1.5px solid var(--border-color);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
}

/* 移除每排最後一格的右邊框，讓視覺更乾淨 */
.date-cell:nth-child(7n) {
  border-right: none;
}

/* 標示今天的格子 */
.today-cell {
  background-color: rgba(252, 236, 161, 0.15) !important; /* 淡黃色微亮背景 */
  box-shadow: inset 0 0 0 3px #fceca1 !important; /* 使淡黃色邊框在手機版也支援 */
  border-radius: 4px;
  z-index: 1;
}

.date-num {
  font-size: 0.85rem;
  font-weight: 700;
  text-align: right;
  margin-bottom: 8px;
}

/* 非本月格子內容淡化，保留實體邊框 */
.other-month > * {
  opacity: 0.35;
  pointer-events: none;
}

.fade-right {
  border-right-color: rgba(209, 216, 224, 0.35) !important;
}

.fade-bottom {
  border-bottom-color: rgba(209, 216, 224, 0.35) !important;
}

.shift-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex: 1;
}

.shift-label {
  font-size: 0.72rem;
  color: #636e72;
  /* 深灰色 */
  width: 22px;
  text-align: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* 只有符合本月的格子（不含 .other-month），空班才會出現紅框與紅字 */
.date-cell:not(.other-month) .empty-warning .staff-row-btns {
  outline: 2px solid #e74c3c;
  outline-offset: 1px;
  border-radius: 4px;
}

.date-cell:not(.other-month) .empty-warning .shift-label {
  color: #e74c3c;
  opacity: 0.9;
}

.staff-row-btns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  flex: 1;
}

.staff-btn {
  border: 1px solid #f8f8f8;
  border-radius: 4px;
  cursor: pointer;
  min-height: 28px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.65rem;
  font-weight: 800;
  color: transparent;
}

.btn-1::after {
  content: "臻";
}

.btn-2::after {
  content: "文";
}

.btn-3::after {
  content: "萍";
}

.btn-4::after {
  content: "新";
}

.staff-btn.active {
  color: white;
  border-color: transparent;
}

.btn-1 {
  background-color: var(--color-1-pale);
}

.btn-1.active {
  background-color: #3498db;
}

.btn-2 {
  background-color: var(--color-2-pale);
}

.btn-2.active {
  background-color: #e74c3c;
}

.btn-3 {
  background-color: var(--color-3-pale);
}

.btn-3.active {
  background-color: #2ecc71;
}

.btn-4 {
  background-color: var(--color-4-pale);
}

.btn-4.active {
  background-color: #f39c12;
}

.disabled-shift {
  background-color: #f2f2f2 !important;
  border: 1px dashed #ccc !important;
  cursor: not-allowed;
  pointer-events: none;
  opacity: 0.3;
}

.disabled-shift::after {
  content: "" !important;
}

.legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: 50px;
  width: fit-content;
  margin: 15px auto 0 auto;
  font-size: 0.8rem;
  font-weight: 700;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.blue {
  background: #3498db;
}

.dot.red {
  background: #e74c3c;
}

.dot.green {
  background: #2ecc71;
}

.dot.orange {
  background: #f39c12;
}

/* 行動裝置優化 */
@media (max-width: 1366px) {
  body {
    padding: 5px;
    background-attachment: scroll;
    background-size: cover;
  }

  .calendar-app {
    padding: 10px;
    margin: 5px;
    width: calc(100% - 10px);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px) !important;
  }

  .shift-label {
    display: none;
  }

  .logo-cat {
    width: 60px;
  }

  /* 放大手機版與小視窗的貓咪 */
  .nav-bar {
    margin-bottom: 8px;
  }

  .calendar-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    background: transparent;
    border-radius: 8px;
  }

  .weekday-header,
  .calendar-grid {
    min-width: 600px;
    width: 100%;
  }

  .date-cell {
    min-height: 70px;
    padding: 4px 2px;
    box-sizing: border-box;
  }

  /* 橫向模式優化 */
  @media (orientation: landscape) {
    .calendar-app {
      padding: 5px 10px;
    }

    .app-header {
      margin-bottom: 5px;
    }

    .logo-cat {
      width: 50px;
    }

    /* 放大橫向模式的貓咪 */

    .calendar-container {
      padding: 0;
      overflow-x: auto !important;
    }

    .date-cell {
      min-height: 50px;
      padding: 2px;
      border-right: 1px solid var(--border-color);
    }

    .date-num {
      font-size: 0.6rem;
      margin-bottom: 2px;
    }

    .staff-row-btns {
      gap: 2px;
    }

    .staff-btn {
      min-height: 16px;
      border-radius: 2px;
    }

    .year-selector,
    .month-selector {
      display: inline-grid;
      width: 48%;
      margin-bottom: 2px;
    }

    .nav-cell {
      padding: 5px;
      font-size: 0.8rem;
    }
  }

  @media (max-width: 600px) {
    .staff-btn::after {
      content: "" !important;
    }

    .app-header {
      flex-direction: column;
      gap: 8px;
      align-items: stretch;
    }

    .top-actions {
      justify-content: center;
    }

    /* 手機螢幕窄，調整為 20 秒一輪 */
    .cat-wrapper {
      animation: roamLeftRight 20s linear infinite;
    }

    .cat-container {
      animation: catPushOrder 20s step-end infinite;
    }

    .logo-cat {
      animation: catPushFace 20s step-end infinite;
    }
  }
}
