:root {
  --bg-dark:    #f6f6f7;
  --bg-card:    #ffffff;
  --bg-input:   #fafafa;
  --red:        #E8341C;
  --red-hover:  #c92c17;
  --red-dim:    #fdeceb;
  --white:      #1c1c1e;
  --white-dim:  #6b6b70;
  --white-faint:#f0f0f0;
  --gray:       #f6f6f7;
  --border:     #e5e5e8;
  --shadow:     0 4px 20px rgba(0,0,0,0.06);
  --radius:     16px;
  --radius-sm:  12px;

  /* ── 活潑配色（圖示色 + 同色系淺底），比照個人中心視覺設計圖 ── */
  --orange:     #F5A623;
  --orange-bg:  #FDF1DE;
  --green:      #1a9c53;
  --green-bg:   #E7F7EE;
  --blue:       #3E7BFA;
  --blue-bg:    #EAF0FF;
  --purple:     #8B5CF6;
  --purple-bg:  #F3EEFF;

  /* ── 品牌強調色（按鈕/卡片標題/膠囊選中…會依頁面主題色變化）──
     預設＝紅（跟 --red 一致），--red 本身仍保留給「警示/必填/錯誤」語意固定用紅色，
     不會因為頁面套用 .theme-xxx 而跟著變色 */
  --accent:      var(--red);
  --accent-hover:var(--red-hover);
  --accent-dim:  var(--red-dim);
}

/* ── 功能頁主題色：請假＝綠、打卡＝藍、補班＝橘黃，只影響 --accent 系列 ── */
.theme-green  { --accent: var(--green); --accent-hover: #148044; --accent-dim: var(--green-bg); }
.theme-blue   { --accent: var(--blue);  --accent-hover: #2D62D6; --accent-dim: var(--blue-bg); }
.theme-orange { --accent: var(--orange);--accent-hover: #D68C0F; --accent-dim: var(--orange-bg); }

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

html, body {
  height: 100%;
  background: var(--bg-dark);
  color: var(--white);
  font-family: 'Noto Sans TC', -apple-system, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── 捲動容器 ── */
.page {
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 20px);
  display: flex;
  flex-direction: column;
}

/* ── 主要內容區 ── */
.content { flex: 1; padding: 8px 16px 24px; }

/* ── 卡片 ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::before {
  content: '';
  display: block;
  width: 3px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
}

/* ── 表單元件 ──
   全站規則：欄位名稱與輸入框同一列（不上下堆疊），節省版面高度，
   列與列之間靠 .field 的 margin-bottom 保持間距 */
.field { margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.field-label {
  flex: 0 0 112px;
  font-size: 12px;
  font-weight: 600;
  color: var(--white-dim);
  letter-spacing: .4px;
}
select, input[type="date"], input[type="time"], input[type="tel"], input[type="text"], input[type="datetime-local"] {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  background: var(--bg-input);
  color: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .2s, background-color .2s;
}
.input-warn { border-color: var(--red) !important; background-color: var(--red-dim) !important; }
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgba(0,0,0,0.4)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  background-color: #ffffff;
}
select option { background: #ffffff; }
select:disabled { opacity: .45; cursor: not-allowed; }

/* ── 按鈕 ── */
.btn {
  width: 100%;
  padding: 15px;
  background: var(--accent);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .5px;
  cursor: pointer;
  transition: background .2s, transform .1s, box-shadow .2s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  margin-top: 6px;
}
.btn:active { transform: scale(.98); }
.btn:hover  { background: var(--accent-hover); box-shadow: 0 4px 24px rgba(0,0,0,0.24); }
.btn:disabled { background: #555; box-shadow: none; cursor: not-allowed; transform: none; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  box-shadow: none;
}
.btn-outline:hover { background: var(--accent-dim); }

/* ── 標籤頁（既有 3-tab 樣式，供舊版/其他頁沿用） ── */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
}
.tab {
  flex: 1;
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--white-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all .2s;
  user-select: none;
}
.tab.active {
  background: var(--accent);
  color: #FFFFFF;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}

/* ── 膠囊切換（請假頁：請假申請／請假紀錄） ── */
.pill-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px;
}
.pill {
  flex: 1;
  padding: 10px 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--white-dim);
  cursor: pointer;
  border-radius: 999px;
  transition: all .2s;
  user-select: none;
}
.pill.active {
  background: var(--accent);
  color: #FFFFFF;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}

/* ── 請假快選膠囊按鈕（一鍵帶入日期時間，不是切換狀態，預設統一銀灰色） ── */
.quick-pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.quick-pill {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--white-dim);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.quick-pill:active { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }

/* ── 請假頁：所有欄位共用一個隱形表格（CSS Grid），每列的第一個輸入框
   都對齊在同一條垂直線上；.field-row 用 display:contents 攤平進外層 grid ──
   欄位名稱＋日曆圖示黏在一起（同一個 label），時鐘圖示＋時間欄位黏在一起，
   中間的日期欄位才有彈性空間，圖示才不會被日期欄位擠到重疊 */
.field-grid {
  display: grid;
  grid-template-columns: minmax(56px, auto) minmax(96px, 1fr) auto;
  align-items: center;
  row-gap: 14px;
  column-gap: 8px;
  margin-bottom: 14px;
}
.field-row { display: contents; }
.field-grid .field-label { margin: 0; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.field-icon { color: var(--white-dim); font-size: 13px; }
.field-icon-input { display: flex; align-items: center; gap: 4px; }
.field-icon-input input[type="time"] { width: auto; min-width: 108px; }
.field-grid input[type="date"],
.field-grid input[type="time"],
.field-grid select,
.field-grid input[type="text"] { min-width: 0; padding: 11px 8px; }
/* 假別／事由沒有圖示，輸入框直接從第 2 欄開始，填滿到最後一欄的寬度 */
.field-grid-fill { grid-column: 2 / -1; }

/* ── 待補班餘額 hero 卡 ── */
.balance-card {
  background: linear-gradient(135deg, var(--red), var(--red-hover));
  border-radius: var(--radius);
  padding: 26px 22px;
  color: #fff;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(232,52,28,0.28);
}
.balance-label { font-size: 13px; font-weight: 700; opacity: 0.9; margin-bottom: 4px; }
.balance-value { font-size: 40px; font-weight: 900; line-height: 1.1; }
.balance-value span { font-size: 17px; font-weight: 700; margin-left: 4px; }
.balance-sub { font-size: 13px; margin-top: 8px; opacity: 0.92; line-height: 1.6; }

.record-list { display: flex; flex-direction: column; gap: 10px; }
.record-item {
  background: var(--white-faint);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.record-item.clickable { cursor: pointer; }
.record-item.clickable:active { transform: scale(.99); }
.record-main { flex: 1; min-width: 0; }
.record-date { font-size: 13px; color: var(--white-dim); margin-bottom: 3px; }
.record-text { font-size: 14px; font-weight: 600; }
.record-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-green  { background: #e7f7ee; color: #1a9c53; }
.badge-red    { background: var(--red-dim); color: var(--red); }
.badge-yellow { background: #fdf3e2; color: #b5750a; }
.badge-gray   { background: var(--white-faint); color: var(--white-dim); }

/* ── 補班紀錄：左右分欄卡片 ── */
.makeup-record-item { align-items: stretch; }
.makeup-record-left {
  flex: 0 0 62%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.makeup-record-row { font-size: 13px; color: var(--white); }
.makeup-record-label {
  display: inline-block;
  min-width: 62px;
  color: var(--white-dim);
  font-weight: 600;
  margin-right: 4px;
}
.makeup-record-right {
  flex: 0 0 38%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  text-align: left;
  border-left: 1px dashed #b3b3ba;
  padding-left: 10px;
  margin-left: 8px;
}

/* ── 打卡紀錄：左欄日期/時間、右欄國家/狀態（狀態上色，不用色塊） ── */
.punch-row { align-items: center; }
.punch-col { display: flex; flex-direction: column; gap: 8px; }
.punch-col-right { align-items: flex-end; text-align: right; }
.punch-date { font-size: 14px; font-weight: 600; }
.punch-time { font-size: 13px; color: var(--white-dim); }
.punch-region { font-size: 14px; font-weight: 600; }
.punch-status { font-size: 13px; font-weight: 700; }
.text-green  { color: #1a9c53; }
.text-red    { color: var(--red); }
.text-yellow { color: #b5750a; }
.text-gray   { color: var(--white-dim); }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--white-dim);
  font-size: 13px;
}
.empty-state .icon { font-size: 36px; margin-bottom: 10px; }

/* ── 分隔線 ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

/* ── 提示文字 ── */
.hint {
  font-size: 12px;
  color: var(--white-dim);
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--white-faint);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--red);
}

/* ── 載入畫面 ── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  gap: 20px;
  transition: opacity .4s;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }
.loading-logo {
  width: 72px;
  height: 72px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  padding: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  animation: pulse 1.5s ease-in-out infinite;
}
.loading-logo img { width: 100%; height: 100%; object-fit: contain; }
@keyframes pulse {
  0%, 100% { transform: scale(1);    box-shadow: 0 8px 32px rgba(0,0,0,0.1); }
  50%       { transform: scale(1.06); box-shadow: 0 12px 40px rgba(0,0,0,0.16); }
}
.loading-text { font-size: 15px; color: var(--white-dim); }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(229,9,20,0.2);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 內文載入用小型/中型 spinner（取代純文字「…」「讀取中」） ── */
.spinner-mini {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
.spinner-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border: 3px solid rgba(0,0,0,0.08);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 10px;
}

/* ── 錯誤畫面 ── */
#error-screen {
  display: none;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 32px;
  text-align: center;
  gap: 12px;
}
#error-screen.visible { display: flex; }
.error-icon { font-size: 48px; }
.error-title { font-size: 18px; font-weight: 700; }
.error-msg   { font-size: 13px; color: var(--white-dim); max-width: 280px; }

/* ── Toast 通知 ── */
#toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2c2c2e;
  color: #ffffff;
  padding: 13px 22px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.1);
  opacity: 0;
  transition: opacity .3s, transform .3s;
  z-index: 999;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  white-space: normal;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { border-color: rgba(52,199,89,0.4); }
#toast.error   { border-color: rgba(229,9,20,0.4); }

/* ── 視圖切換動畫 ── */
.view { display: none; animation: fadeIn .25s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── 進度列（表單提交中） ── */
.submit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 500;
  display: none;
}
.submit-overlay.visible { display: flex; }
.submit-overlay .spinner { width: 40px; height: 40px; border-width: 4px; }
.submit-overlay p { font-size: 14px; color: var(--white-dim); }

/* ══════════════════════════════════════════════════
   個人中心儀表板（釘選 header + 內容區 + 釘選 footer nav）
   ══════════════════════════════════════════════════ */

#view-profile { display: flex; flex-direction: column; min-height: calc(100dvh - 90px); }

/* ── 釘選 Header：頭像/姓名/賀詞，可選背景圖 ── */
.profile-header-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.profile-header-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: .16;
  pointer-events: none;
}
.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.12);
  background: var(--white-faint);
  flex-shrink: 0;
  position: relative;
}
.profile-header-info { position: relative; min-width: 0; flex: 1; }
.profile-name-row { display: flex; align-items: center; gap: 8px; }
.profile-name { font-size: 19px; font-weight: 900; }
.edit-pencil {
  border: none;
  background: var(--white-faint);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.edit-pencil:active { transform: scale(.92); }
.profile-greeting { font-size: 13px; color: var(--white-dim); margin-top: 4px; min-height: 18px; }

/* ── 我的待辦：圖示在左（色底圓角）、標題在上／數字在下在右 ── */
.todo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}
.stat-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.stat-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  background: rgba(255,255,255,.55);
}
.stat-text { min-width: 0; }
.stat-label { font-size: 11px; color: var(--white-dim); line-height: 1.3; }
.stat-value {
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.stat-orange { background: var(--orange-bg); }
.stat-orange .stat-icon-wrap { color: var(--orange); }
.stat-red    { background: var(--red-dim); }
.stat-red    .stat-icon-wrap { color: var(--red); }
.stat-blue   { background: var(--blue-bg); }
.stat-blue   .stat-icon-wrap { color: var(--blue); }
.stat-green  { background: var(--green-bg); }
.stat-green  .stat-icon-wrap { color: var(--green); }
.stat-purple { background: var(--purple-bg); }
.stat-purple .stat-icon-wrap { color: var(--purple); }

/* ── 本月摘要：同樣圖示在左＋標題/數字在右，不上色底，用直線分隔 3 欄 ── */
.summary-grid {
  display: flex;
}
.summary-tile {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-left: 1px solid var(--border);
}
.summary-tile:first-child { border-left: none; padding-left: 0; }
.summary-tile .stat-icon-wrap { background: none; font-size: 20px; width: auto; height: auto; }

/* 數字 + 單位（hr／筆／天）：單位變小、不加粗、跟數字同一水平線靠底對齊 */
.stat-unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--white-dim);
  line-height: 1;
}

/* ── 最新公告清單（保留樣式，功能本輪隱藏） ── */
.announce-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.announce-item:last-child { border-bottom: none; }
.announce-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }
.announce-title { flex: 1; font-size: 14px; font-weight: 600; }
.announce-date { font-size: 12px; color: var(--white-dim); }

/* ── 內容區（footer 切換時被替換的區域） ── */
#profile-content { flex: 1; padding-bottom: 96px; }

/* ── 返回連結（子功能頁頂部回首頁） ── */
.back-link {
  display: inline-block;
  background: none;
  border: none;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 0 14px;
  cursor: pointer;
}

/* ── 釘選 Footer 功能切換列 ── */
.footer-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 8px max(12px, env(safe-area-inset-left, 0px)) calc(8px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
}
.footer-nav-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0 4px;
  padding: 8px 4px;
  color: var(--white-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background .2s;
}
.footer-nav-btn .footer-nav-icon { font-size: 19px; }
.footer-nav-divider { width: 1px; margin: 6px 0; background: var(--border); flex-shrink: 0; }

.footer-nav-orange { color: var(--orange); }
.footer-nav-orange.active { background: var(--orange); color: #FFFFFF; }
.footer-nav-green { color: var(--green); }
.footer-nav-green.active { background: var(--green); color: #FFFFFF; }
.footer-nav-blue { color: var(--blue); }
.footer-nav-blue.active { background: var(--blue); color: #FFFFFF; }

/* ── 骨架載入區塊 ── */
.skeleton-block {
  height: 64px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  background: linear-gradient(90deg, var(--white-faint) 25%, #e8e8ea 37%, var(--white-faint) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
