/* 全站樣式 2/16：頂部導航列、系統切換下拉（sys-dropdown） */
/* ============================================
   頂部導航
   ============================================ */
header {
  background: rgba(251, 248, 243, 0.88);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(60,60,67,0.06);
  padding: 6px 16px 10px;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

#user-info {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: color 0.2s, background 0.2s;
}
.logout-btn:hover { color: var(--red); background: rgba(255, 59, 48, 0.06); }
.logout-btn:active { opacity: 0.6; }

header h1 {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 10px;
  letter-spacing: -0.02em;
}

/* 系統切換 */
#header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 600px;
  margin: 0 auto 6px;
}
#system-switcher {
  position: relative;
  flex-shrink: 0;
}
#sys-current {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid rgba(231, 111, 81, 0.28);
  border-radius: 8px;
  background: linear-gradient(180deg, #FDEEDC 0%, #FDEEDC 100%);
  color: #E07B35;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 1px 2px rgba(231, 111, 81, 0.08);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}
#sys-current:hover {
  background: linear-gradient(180deg, #FDEEDC 0%, #FDEEDC 100%);
  border-color: rgba(231, 111, 81, 0.45);
  transform: translateY(-1px);
}
#sys-current:active {
  transform: translateY(0) scale(0.97);
  transition: transform 0.08s ease;
}
#header-row .unit-filter {
  flex: 1;
  margin: 0;
  max-width: none;
}
.sys-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  background: rgba(253, 249, 243, 0.92);
  backdrop-filter: saturate(180%) blur(40px);
  -webkit-backdrop-filter: saturate(180%) blur(40px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 1) inset,
    0 0 0 1px rgba(255, 255, 255, 0.55) inset,
    0 36px 90px -24px rgba(15, 44, 64, 0.28),
    0 16px 36px -10px rgba(244, 162, 97, 0.18),
    0 4px 14px -2px rgba(15, 44, 64, 0.08);
  padding: 14px 14px 16px;
  z-index: 1000;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  display: none;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  width: 340px;
  transform-origin: top left;
  isolation: isolate;
}
.sys-dropdown::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 28px;
  width: 14px;
  height: 14px;
  background: rgba(253, 249, 243, 0.92);
  backdrop-filter: saturate(180%) blur(40px);
  -webkit-backdrop-filter: saturate(180%) blur(40px);
  border-left: 1px solid rgba(255, 255, 255, 0.8);
  border-top: 1px solid rgba(255, 255, 255, 0.8);
  transform: rotate(45deg);
  border-top-left-radius: 8px;
  z-index: -1;
}
.sys-dropdown.open {
  display: grid;
  animation: sysDropOpen 0.26s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes sysDropOpen {
  from { opacity: 0; transform: translateY(-8px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes sysItemFade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* 超細分隔線（取代文字標籤，只給視覺呼吸） */
.sys-divider {
  grid-column: 1 / -1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(15, 44, 64, 0.08) 20%, rgba(15, 44, 64, 0.08) 80%, transparent);
  margin: 2px 0;
}
/* 動畫：分隔線不參與動畫，按鈕按 nth-of-type 依序進場 */
.sys-dropdown.open button {
  animation: sysItemFade 0.3s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.sys-dropdown.open button:nth-of-type(-n+4)         { animation-delay: 0.02s; }
.sys-dropdown.open button:nth-of-type(n+5):nth-of-type(-n+8)   { animation-delay: 0.06s; }
.sys-dropdown.open button:nth-of-type(n+9):nth-of-type(-n+12)  { animation-delay: 0.10s; }
.sys-dropdown.open button:nth-of-type(n+13):nth-of-type(-n+16) { animation-delay: 0.14s; }
.sys-dropdown.open button:nth-of-type(n+17):nth-of-type(-n+18) { animation-delay: 0.18s; }
.sys-dropdown.open button:nth-of-type(n+19)         { animation-delay: 0.22s; }
.sys-dropdown button {
  position: relative;
  padding: 10px 8px;
  border: 1px solid rgba(15, 44, 64, 0.06);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #FDEEDC 100%);
  color: #2D2A26;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.22s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.22s ease,
              background 0.22s ease,
              color 0.22s ease;
  white-space: nowrap;
  text-align: center;
  letter-spacing: -0.3px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.95) inset,
    0 0 0 1px rgba(255, 255, 255, 0.4) inset,
    0 1px 2px rgba(15, 44, 64, 0.04),
    0 2px 6px -2px rgba(15, 44, 64, 0.05);
  overflow: hidden;
}
.sys-dropdown button::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 50%);
  pointer-events: none;
  opacity: 0.5;
  transition: opacity 0.22s ease;
}
.sys-dropdown button:hover {
  background: linear-gradient(180deg, #ffffff 0%, #FDEEDC 100%);
  border-color: rgba(244, 162, 97, 0.5);
  color: #E07B35;
  transform: translateY(-3px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 1) inset,
    0 0 0 1px rgba(244, 162, 97, 0.15) inset,
    0 12px 24px -6px rgba(244, 162, 97, 0.32),
    0 4px 10px -2px rgba(244, 162, 97, 0.2);
}
.sys-dropdown button:active {
  transform: translateY(-1px) scale(0.97);
  transition: transform 0.08s ease;
}
.sys-dropdown button.active {
  background: linear-gradient(135deg, #E07B35 0%, #C9652A 100%);
  color: white;
  border-color: rgba(231, 111, 81, 0.4);
  text-shadow: 0 1px 2px rgba(143, 51, 26, 0.25);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.4) inset,
    0 0 0 1px rgba(255, 255, 255, 0.18) inset,
    0 12px 26px -6px rgba(244, 162, 97, 0.55),
    0 4px 10px -2px rgba(231, 111, 81, 0.4);
}
.sys-dropdown button.active::after {
  background: linear-gradient(180deg, rgba(255,255,255,0.28) 0%, rgba(255,255,255,0) 55%);
  opacity: 1;
}
.sys-dropdown button.active:hover {
  background: linear-gradient(135deg, #E07B35 0%, #CF4130 100%);
  color: white;
  transform: translateY(-3px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.45) inset,
    0 0 0 1px rgba(255, 255, 255, 0.22) inset,
    0 16px 32px -6px rgba(244, 162, 97, 0.62),
    0 6px 14px -2px rgba(231, 111, 81, 0.5);
}

/* 系統下拉開啟時，把後方的子導航淡出，避免那條鬼影 tab 露出 */
#main-nav { transition: opacity 0.22s ease; }
header:has(.sys-dropdown.open) #main-nav {
  opacity: 0;
  pointer-events: none;
}

/* 手機版：避免下拉選單超出 viewport（原本寫死 440px 會被截掉右半） */
@media (max-width: 600px) {
  /* header 四顆按鈕在窄螢幕壓縮。塞不下就換行——絕對不准把整頁撐寬變成可左右滑
     （2026-09-02：切換系統＋切換身分＋待辦事項＋建議 加起來 424px > iPhone 390px，
       整站 206 個畫面都被這一排拉歪，就是「手機版破圖」的元兇。
       2026-09-04：「建議」按鈕已移除，四顆改成同一組尺寸一起縮） */
  /* 2026-09-14 排版重做：原本靠 flex-wrap 亂折＋#todo-bell-btn 的 margin-left:auto，
     手機上變成「第一排三顆擠中間、待辦事項自己掉到第二排靠右」，右半整片空白。
     改成固定兩段式：
       第 1 排＝系統切換（主按鈕）整排撐滿
       第 2 排＝切換系統／切換身分／待辦事項 等寬平分剩下的寬度
     flex-basis:0 + min-width:fit-content ＝ 有空間就等寬平分、空間不夠就各自保住字不被壓爛，
     全部只在容器寬度內長大，永遠不會把整頁撐寬變成可左右滑（2026-09-02 那個破圖不會回來）。 */
  #header-row {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
    row-gap: 6px;
    max-width: 100%;
  }
  #header-row #system-switcher {
    flex: 1 0 100%;
  }
  #header-row #sys-current {
    width: 100%;
    justify-content: center;
  }
  #header-row #btn-switch-system,
  #header-row #btn-impersonate,
  #header-row #todo-bell-btn {
    flex: 1 1 0;
    min-width: -webkit-fit-content;
    min-width: fit-content;
    justify-content: center;
    margin-left: 0;          /* 取消桌機版的 margin-left:auto，不然它又自己飛到最右邊 */
  }
  #sys-current,
  #btn-switch-system,
  #btn-impersonate,
  #todo-bell-btn {
    height: 30px !important;
    padding: 0 10px !important;
    font-size: 0.75rem !important;
    white-space: nowrap;
  }
  .sys-dropdown {
    width: calc(100vw - 32px);
    max-width: 100vw;
    left: 0;
    padding: 12px;
    gap: 8px;
    border-radius: 16px;
  }
  .sys-dropdown button {
    padding: 12px 4px;
    font-size: 0.75rem;
    border-radius: 12px;
    letter-spacing: -0.4px;
  }
}
@media (max-width: 380px) {
  .sys-dropdown {
    padding: 10px;
    gap: 6px;
  }
  .sys-dropdown button {
    font-size: 0.75rem;
    padding: 10px 2px;
  }
}

