:root {
  --navy: #163a5f;
  --navy-2: #1f4e79;
  --accent: #c45c26;
  --fill: #fff8e8;
  --grid: #c5d0dc;
  --head: #1f4e79;
  --weekend: #e4ebf3;
  --short: #ffe08a;
  --long: #9fd4ff;
  --holiday: #f8d0d6;
  --ok: #1b7a4e;
  --danger: #b42318;
  --bg: #eef2f6;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #5b6b7c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: linear-gradient(90deg, var(--navy), var(--navy-2));
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand-title { font-size: 18px; font-weight: 700; }
.ver {
  display: inline-block;
  background: #fff;
  color: var(--navy);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: 2px;
}
.brand-sub { font-size: 12px; opacity: 0.85; margin-top: 3px; }
.top-tools { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.year-box { font-size: 12px; display: flex; align-items: center; gap: 6px; }
.year-box select {
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 700;
}

.mode-switch {
  display: flex;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 4px;
}
.mode-btn {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 7px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.mode-btn.is-active { background: #fff; color: var(--navy); }

.year-banner {
  background: #fff4d6;
  color: #6a4a00;
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.year-banner[hidden] { display: none !important; }

.share-blocker {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(16, 32, 48, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.share-blocker[hidden] { display: none !important; }
.share-box {
  max-width: 520px;
  background: #fff;
  border-radius: 12px;
  padding: 22px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.share-box h1 { margin: 0 0 10px; font-size: 18px; color: var(--navy); }
.share-box p { margin: 0 0 10px; font-size: 14px; line-height: 1.6; }
.share-box code {
  background: #eef3f8;
  padding: 1px 6px;
  border-radius: 4px;
}
.share-muted { color: var(--muted); font-size: 13px !important; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  background: #d9e3ee;
  border-bottom: 1px solid #b7c6d6;
}
.tab {
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.tab.is-active {
  background: var(--card);
  color: var(--navy);
  border-color: #b7c6d6;
  font-weight: 700;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 16px;
  background: var(--card);
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--grid);
}
.hint { color: var(--accent); font-weight: 700; }

.main { padding: 10px; flex: 1; }
.panel { display: none; }
.panel.is-active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--grid);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.card h2 { margin: 0 0 8px; font-size: 14px; color: var(--navy); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 8px;
}
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11px; color: var(--muted); }
.field.req label::after { content: " *"; color: var(--danger); }
.field input, .field select {
  border: 1px solid #9eb1c4;
  background: var(--fill);
  padding: 6px 7px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.field.readonly input, .field.readonly select { background: #eef2f6; }
.field.warn input, .field.warn select { border-color: var(--danger); background: #fff1f0; }
.auto-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chip {
  background: #e8eef5;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--navy);
}
.chip b { margin-right: 4px; }
.note { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.note.alert { color: var(--danger); font-weight: 700; }

.actions { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
button.btn {
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.btn-primary { background: var(--navy-2); color: #fff; }
.btn-ghost { background: #e6edf4; color: var(--navy); }
.btn-danger { background: #fde8e6; color: var(--danger); }
.btn-ok { background: #e5f6ec; color: var(--ok); }
.btn-small { padding: 3px 8px; font-size: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; align-items: end; }
.filters .field { min-width: 130px; }

.table-wrap { overflow: auto; max-height: calc(100vh - 340px); border: 1px solid var(--grid); }
.table-wrap.stats-full { max-height: none; overflow-x: auto; }
table.sheet {
  border-collapse: collapse;
  width: 100%;
  min-width: 860px;
  font-size: 12px;
}
table.sheet.stats-weeks {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}
table.sheet.stats-weeks th,
table.sheet.stats-weeks td {
  min-width: 40px;
  padding: 4px 4px;
}
table.sheet.stats-weeks th:first-child,
table.sheet.stats-weeks td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 148px;
  background: #fff;
  text-align: left;
}
table.sheet.stats-weeks thead th:first-child {
  z-index: 3;
  background: var(--head);
}
table.sheet.stats-weeks tbody tr:nth-child(even) td:first-child {
  background: #f7fafc;
}
table.sheet.stats-weeks td.total:first-child {
  background: #fff3d6;
}
table.sheet th, table.sheet td {
  border: 1px solid var(--grid);
  padding: 5px 7px;
  white-space: nowrap;
}
table.sheet th {
  position: sticky;
  top: 0;
  background: var(--head);
  color: #fff;
  z-index: 1;
}
table.sheet tbody tr:nth-child(even) { background: #f7fafc; }
table.sheet td.num { text-align: right; }
table.sheet td.center { text-align: center; }
table.sheet td.total { font-weight: 700; background: #fff3d6; }
.empty { padding: 18px; text-align: center; color: var(--muted); }

.kind-short { background: var(--short); padding: 1px 6px; border-radius: 999px; font-size: 11px; }
.kind-long { background: var(--long); padding: 1px 6px; border-radius: 999px; font-size: 11px; }

.cal-wrap { max-width: none; }
.calendar-year {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}
.month {
  border: 1px solid #5d6d7e;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
  min-width: 0;
}
.month h3 {
  margin: 0;
  padding: 4px;
  text-align: center;
  background: var(--navy-2);
  color: #fff;
  font-size: 12px;
}
.month table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.month th, .month td {
  border: 1px solid #5d6d7e;
  vertical-align: top;
  padding: 0;
  font-size: 9px;
  background: #fff;
}
.month td {
  height: 64px;
  max-height: 64px;
  overflow: hidden;
}
.month th { height: 18px; background: #e8eef5; color: var(--navy); text-align: center; }
.month th.weekend { background: #d5e0ec; color: #4a5d70; }
.month td.out { color: #b0b8c1; background: #fafbfc; }
.month td.weekend { background: var(--weekend); }
.month td.has-short { background: var(--short); }
.month td.has-long { background: var(--long); }
.month td.has-short.has-long { background: var(--short); }
.month td.holiday { background: var(--holiday); }
.month td.has-long .cell-head { background: var(--long); }
.month td.holiday .cell-head { background: var(--holiday); }
.cell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 64px;
  min-height: 64px;
  max-height: 64px;
  overflow: hidden;
  box-sizing: border-box;
}
.cell-head {
  flex: 0 0 auto;
  border-bottom: 1px solid #6e7d8d;
  background: transparent;
}
.day-num {
  font-weight: 700;
  display: block;
  text-align: center;
  font-size: 11px;
  line-height: 1.15;
  padding: 1px 0 0;
}
.cell-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.band {
  flex: 1 1 0;
  min-height: 0;
  padding: 1px 3px 0;
  text-align: left;
  font-size: 9px;
  overflow: hidden;
}
.en-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  line-height: 1.2;
  height: 1.2em;
}
.band-short { background: var(--short); color: #8a5a00; }
.band-long { background: var(--long); color: #0b4f86; font-weight: 700; }
.band-holiday {
  background: var(--holiday);
  color: #8a3040;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.legend { font-size: 12px; color: var(--muted); margin: 0 0 8px; display: flex; gap: 12px; flex-wrap: wrap; }
.swatch { display: inline-block; width: 11px; height: 11px; border: 1px solid #bbb; margin-right: 4px; vertical-align: -1px; }
.swatch.short { background: var(--short); }
.swatch.long { background: var(--long); }
.swatch.holiday { background: var(--holiday); }
.swatch.weekend { background: var(--weekend); }

.people-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 0 0 10px;
  padding: 8px;
  background: #f4f8fc;
  border: 1px solid var(--grid);
  border-radius: 6px;
}
.people-chip {
  font-size: 12px;
  white-space: nowrap;
  background: #fff;
  border: 1px solid #d5dee8;
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--text);
}
.people-chip b { margin-right: 4px; color: var(--navy); }

.holi-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.data-box {
  background: #f4f8fc;
  border: 1px dashed #9bb4c9;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: #334155;
}
.data-box code {
  background: #fff;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(3, 1fr); }
  .calendar-year { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
  .calendar-year { grid-template-columns: repeat(2, 1fr); }
}

button.btn:active, .tab:active, .mode-btn:active {
  transform: scale(0.96);
  filter: brightness(1.1);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35);
}
.btn-ripple {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  pointer-events: none;
  animation: btn-ripple 0.55s ease-out forwards;
  z-index: 1;
}
.btn-ghost .btn-ripple,
.btn-danger .btn-ripple,
.tab .btn-ripple {
  background: rgba(22, 58, 95, 0.28);
}
@keyframes btn-ripple {
  from { transform: scale(0); opacity: 0.8; }
  to { transform: scale(22); opacity: 0; }
}
body.is-busy { cursor: progress; }
.busy-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(16, 32, 48, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
}
.busy-overlay[hidden] { display: none !important; }
.busy-box {
  background: #fff;
  border-radius: 12px;
  padding: 16px 22px;
  min-width: 260px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--navy);
  font-weight: 700;
  font-size: 15px;
}
.busy-spin {
  width: 22px;
  height: 22px;
  border: 3px solid #d5e0ec;
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: busy-spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes busy-spin {
  to { transform: rotate(360deg); }
}

html[data-dept="pr"] {
  --navy: #1a5c4a;
  --navy-2: #247a63;
  --accent: #c9a227;
  --fill: #f3faf6;
  --grid: #b7d4c8;
  --head: #1f6b56;
  --weekend: #e3f2eb;
  --short: #ffe6a3;
  --long: #8fd4c1;
  --holiday: #f5d0c8;
  --bg: #e7f3ee;
}
html[data-dept="pr"] .tabs { background: #cfe6dc; border-bottom-color: #b7d4c8; }
html[data-dept="pr"] .tab.is-active { border-color: #b7d4c8; }
html[data-dept="pr"] .people-strip { background: #eef8f3; }
html[data-dept="pr"] .data-box { background: #eef8f3; border-color: #9bc4b3; }

.who-text {
  font-size: 12px;
  opacity: 0.92;
  white-space: nowrap;
}

/* ===== 入口畫面（照搬原本出勤入口設計） ===== */
#portal {
  --paper: #faf6eb;
  --pcard: #fbf7eb;
  --ink: #1e1e1e;
  --line: #2a2a2a;
  --pgrid: #e3dccd;
  --p-navy: #2c567c;
  --orange: #e78b4c;
  --mist: #a6b8c4;
  --blue-btn: #afc0da;
  --green-btn: #9ebdad;
  --hand: "Segoe Print", "Comic Sans MS", cursive;
  position: relative;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  overflow-x: hidden;
}
#portal[hidden] { display: none !important; }

#portal .stripes { position: fixed; left: 26px; top: 0; bottom: 0; display: flex; gap: 6px; z-index: 1; }
#portal .stripes i { display: block; width: 10px; height: 100%; }
#portal .stripes i:nth-child(1) { background: var(--p-navy); }
#portal .stripes i:nth-child(2) { background: var(--orange); }
#portal .stripes i:nth-child(3) { background: var(--mist); }

#portal .side-date {
  position: fixed; left: 6px; top: 50%;
  transform: translateY(-50%) rotate(180deg);
  writing-mode: vertical-rl; white-space: nowrap;
  font-family: var(--hand); font-size: 11px; color: #333; z-index: 2;
}
#portal .grid-floor {
  position: fixed; left: 0; right: 0; bottom: 0; height: 42vh;
  background-image:
    linear-gradient(var(--pgrid) 1px, transparent 1px),
    linear-gradient(90deg, var(--pgrid) 1px, transparent 1px);
  background-size: 24px 24px; z-index: 0;
}

#portal .menu-btn {
  position: fixed; top: 22px; right: 26px; z-index: 6;
  background: transparent; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: var(--hand); color: var(--ink);
}
#portal .menu-btn span { font-size: 14px; letter-spacing: 0.06em; margin-bottom: 2px; }
#portal .menu-btn b { display: block; width: 46px; height: 9px; border: 2px solid var(--line); border-radius: 50%; }

#portal .menu {
  position: fixed; top: 92px; right: 22px; width: 340px; z-index: 6;
  background: #fffdf7; border: 2.5px solid var(--line); border-radius: 18px;
  padding: 16px 18px; box-shadow: 6px 6px 0 rgba(0,0,0,0.12);
}
#portal .menu[hidden] { display: none !important; }
#portal .menu h3 { margin: 0 0 6px; font-size: 16px; }
#portal .menu h4 { margin: 14px 0 6px; font-size: 13px; }
#portal .menu-who { margin: 0 0 8px; font-size: 13px; color: #555; }
#portal .menu-item {
  border: 2px solid var(--line); background: #fff; border-radius: 999px;
  padding: 4px 14px; cursor: pointer; font-family: inherit;
}
#portal .menu-item[hidden] { display: none !important; }
#portal .menu-note { font-size: 12px; color: #666; margin: 10px 0 0; }

#portal .page { position: relative; z-index: 3; max-width: 1280px; margin: 0 auto; padding: 18px 60px 40px 120px; }
#portal .head { text-align: center; margin-bottom: 26px; }
#portal .factory { width: 58px; display: block; margin: 0 auto 2px; mix-blend-mode: multiply; }
#portal .head h1 { margin: 0; font-size: 44px; font-weight: 900; letter-spacing: 0.08em; }
#portal .head p { margin: 8px 0 0; font-size: 20px; letter-spacing: 0.06em; }

#portal .cards { display: grid; grid-template-columns: 1fr 1fr; gap: 72px; }

#portal .card {
  position: relative; background: var(--pcard);
  border: 3px solid var(--line); border-radius: 26px;
  padding: 26px 26px 20px; box-shadow: 7px 7px 0 rgba(0,0,0,0.08);
  min-height: 440px; display: flex; flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
#portal .card:hover { transform: translateY(-2px) rotate(-0.2deg); box-shadow: 9px 10px 0 rgba(0,0,0,0.1); }
#portal .card-wh { border-top-right-radius: 4px; }
#portal .fold {
  position: absolute; top: -3px; right: -3px; width: 34px; height: 34px;
  background: linear-gradient(225deg, var(--paper) 50%, #efe6d2 50%);
  border-left: 3px solid var(--line); border-bottom: 3px solid var(--line);
  border-bottom-left-radius: 8px;
}
#portal .art {
  width: 100%; max-width: 420px; height: 248px;
  margin: 0 auto 12px; display: block; object-fit: contain; pointer-events: none;
}
#portal .foot { margin-top: auto; display: grid; grid-template-columns: auto 1fr; gap: 6px 22px; align-items: end; }
#portal .name strong { display: block; font-size: 46px; font-weight: 900; line-height: 1; letter-spacing: 0.06em; }
#portal .name em { display: block; font-style: normal; font-family: var(--hand); font-size: 22px; margin-top: 4px; }

#portal .login { display: grid; gap: 6px; }
#portal .login label { display: grid; grid-template-columns: 44px 1fr; align-items: end; gap: 6px; font-size: 15px; }
#portal .login input {
  border: 0; border-bottom: 2px solid var(--line); background: transparent;
  font: inherit; padding: 2px 4px; outline: none; min-width: 0;
}
#portal .login input:focus { border-bottom-color: var(--orange); }
#portal .btn-login {
  justify-self: center; margin-top: 8px;
  border: 2px solid var(--line); border-radius: 999px;
  padding: 5px 30px; font-family: inherit; font-size: 15px; cursor: pointer;
}
#portal .card-wh .btn-login { background: var(--blue-btn); }
#portal .card-pr .btn-login { background: var(--green-btn); }
#portal .btn-login:disabled { opacity: 0.6; cursor: wait; }

#portal .chooser[hidden], #portal .login[hidden] { display: none !important; }
#portal .chooser { display: grid; gap: 8px; }
#portal .hello { display: none; }
#portal .chooser-btns { display: flex; gap: 10px; flex-wrap: wrap; }
#portal .btn-pick {
  flex: 1; min-width: 92px;
  border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 8px; font-family: inherit; font-size: 18px; font-weight: 800;
  cursor: pointer; background: #fff; box-shadow: 3px 3px 0 rgba(0,0,0,0.15);
}
#portal .btn-pick:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0,0,0,0.15); }
#portal .card-wh .btn-pick.leave { background: #dbe5f1; }
#portal .card-pr .btn-pick.leave { background: #d6e8de; }
#portal .btn-pick.ot { background: #f1d9e2; }

#portal .msg { grid-column: 1 / -1; margin: 4px 0 0; min-height: 18px; font-size: 13px; }
#portal .msg.err { color: #a22a1c; }
#portal .msg.ok { color: #1b6b45; }

/* 第一次登入改密碼：沿用紙感對話框 */
.share-blocker {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(30, 30, 30, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.share-blocker[hidden] { display: none !important; }
.share-box {
  background: #fffdf7; border: 3px solid #2a2a2a; border-radius: 20px;
  padding: 22px 24px; max-width: 440px; width: 100%;
  font-family: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}
.share-box h2 { margin: 0 0 8px; font-size: 19px; }
.share-box p { margin: 0 0 12px; font-size: 14px; line-height: 1.6; color: #444; }
.pass-form { display: grid; gap: 10px; }
.pass-form label { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: #333; }
.pass-form input {
  border: 1px solid #9c9c9c; border-radius: 8px; background: #fff;
  padding: 9px 10px; font-size: 16px; font-family: inherit;
}
.btn-plain {
  justify-self: start;
  border: 2px solid #2a2a2a; background: #afc0da; border-radius: 999px;
  padding: 7px 22px; cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 700;
}

@media (max-width: 860px) {
  #portal .cards { grid-template-columns: 1fr; gap: 28px; }
  #portal .page { padding-left: 80px; padding-right: 24px; }
  #portal .head h1 { font-size: 34px; }
  #portal .head p { font-size: 16px; }
  #portal .art { height: 190px; }
  #portal .name strong { font-size: 38px; }
}
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .calendar-year { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .who-text { display: none; }
  .table-wrap { max-height: none; }
}
