:root {
  --bg: #f0f9ff;
  --card: #ffffff;
  --ink: #0c4a6e;
  --muted: #64748b;
  --brand: #0ea5e9;       /* 天空藍 sky-500 */
  --brand-2: #38bdf8;     /* sky-400 */
  --line: #bae6fd;
  --ok: #0284c7;          /* 連線正常 sky-600 */
  --err: #b42318;
  /* 請假狀態色：月曆格與我的假單膠囊共用 */
  --slot-selected: #3B82F6;
  --slot-pending: #F59E0B;
  --slot-approved: #10B981;
  --slot-pending-delete: #EF4444;
  --slot-blocked: #6B7280;
  --slot-on-light: #1c1917;
  --slot-on-dark: #fff;
  /* 日期字色對齊出勤 OvertimeTheme */
  --holiday-text: rgb(244, 67, 54);   /* HolidayText */
  --makeup-text: rgb(33, 150, 243);   /* MakeupText */
  --pending: #c9a227;
  --approved: #c44b4b;
  --blocked: #8a97a3;
  --selected: #38bdf8;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(14, 165, 233, 0.12);
  font-family: "Segoe UI", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@viewport {
  width: device-width;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: linear-gradient(180deg, #e0f2fe 0%, var(--bg) 42%);
  color: var(--ink);
  min-height: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}

.app-header-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px; /* 標題往上靠第一行 */
  padding: 8px 16px 6px; /* 上下更緊湊 */
  width: 100%;
  max-width: min(720px, 100%);
  min-width: 0;
  margin: 0 auto;
}

/* 第一行：左 logo；右狀態點＋導覽（同列置中） */
.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.header-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo-link {
  display: inline-flex;
  line-height: 0;
  text-decoration: none;
}

.brand-logo {
  height: auto;
  max-height: 84px; /* 原 28px ×3 */
  width: auto;
  max-width: min(46vw, 100%);
  display: block;
  flex-shrink: 1;
  object-fit: contain;
}

.brand-logo-lg {
  max-height: 108px; /* 原 36px ×3 */
  max-width: min(70vw, 100%);
}

.brand-heading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  margin: 0;
}

/* 第二行：系統標題置中（靠上、少空隙） */
.app-header-title {
  text-align: center;
  width: 100%;
  font-weight: 700;
  font-size: calc(1rem + 4pt); /* 原 1rem，+4pt */
  line-height: 1.15;
  margin: 0;
  padding: 0;
}

.app-header-title a {
  color: #fff;
  text-decoration: none;
}

.app-header-title a:hover {
  text-decoration: none;
  opacity: .95;
}

/* 標頭狀態點：與導覽同列置中，不貼 logo 右下 */
.header-right > .conn-dot {
  width: 9px;
  height: 9px;
  align-self: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35);
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  min-width: 0;
  font-size: .9rem;
}

.nav-links a {
  color: #f0f9ff;
  text-decoration: none;
  padding: 4px 6px;
}

.nav-logout-form {
  display: inline-flex;
  margin: 0;
}

.nav-logout {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, .85);
  background: transparent;
  color: #fff;
  border-radius: 999px;
  padding: 4px 12px;
  font: inherit;
  font-size: .9rem;
  line-height: 1.2;
  cursor: pointer;
}

.nav-logout:hover {
  background: rgba(255, 255, 255, .16);
}

.header-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 12px;
  max-width: 100%;
  min-width: 0;
}

.user-bar {
  width: 100%;
  max-width: min(720px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 0 16px 10px;
  font-size: .85rem;
  opacity: .9;
}

.conn-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  color: #e0f2fe;
  opacity: .95;
  white-space: nowrap;
}

.conn-bar-label {
  font-weight: 700;
  letter-spacing: .02em;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
  background: #8a97a3;
}

.conn-dot.conn-ok { background: #16a34a; }
.conn-dot.conn-err { background: #f5a8a0; }

.conn-bar.conn-ok .conn-bar-label { color: #bbf7d0; }
.conn-bar.conn-err .conn-bar-label { color: #ffd0cb; }

.conn-status-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.conn-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.status-pill.conn-ok { background: #dcfce7; color: #166534; }
.status-pill.conn-err { background: #fdecea; color: var(--err); }

.conn-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 16px;
}

.app-main {
  width: 100%;
  max-width: min(720px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.page-head h1, .card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.card h1.brand-heading {
  font-size: calc(1.35rem + 4pt); /* 原 .card h1 1.35rem +4pt */
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stack label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .92rem;
  font-weight: 600;
}

/* 假別｜已知｜場館：優先同一列，窄螢幕可換行 */
.apply-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.apply-fields > label {
  flex: 1 1 140px;
  min-width: 0;
}

.input:disabled,
select.input:disabled {
  background: #f0f4f7;
  color: var(--muted);
  cursor: not-allowed;
}

.input, select.input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { filter: brightness(0.98); text-decoration: none; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-line {
  background: #06c755;
  border-color: #06c755;
  color: #fff;
}

.btn-line:hover {
  filter: brightness(1.05);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-block {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
}

.center { text-align: center; }

.legacy-login {
  margin-top: 8px;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}

.legacy-login summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 10px;
}

.admin-entry {
  margin: 18px 0 0;
  text-align: center;
  font-size: .75rem;
}

.admin-entry a {
  color: #94a3b8;
  text-decoration: none;
}

.admin-entry a:hover {
  color: var(--muted);
  text-decoration: underline;
}

.admin-nav {
  gap: 10px;
}

.admin-filter {
  margin-bottom: 8px;
}

.admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.admin-row-actions summary {
  cursor: pointer;
  color: var(--brand);
  font-size: .85rem;
}

.admin-row-actions .stack {
  margin-top: 8px;
  padding: 8px;
  background: #f8fbff;
  border-radius: 10px;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: .8rem;
  word-break: break-all;
}

.btn-danger {
  background: #b42318;
  color: #fff;
  border: none;
}

.btn-sm {
  padding: 6px 10px;
  font-size: .85rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.muted { color: var(--muted); }
.small { font-size: .85rem; }

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: .95rem;
}

.alert-error { background: #fdecea; color: var(--err); }
.alert-ok { background: #e6f5fa; color: var(--ok); }
.alert-info { background: #eef4ff; color: #2554a0; }

.check {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-weight: 500 !important;
}

.leave-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leave-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leave-card.is-deleted { opacity: .55; }

.leave-range {
  font-size: .92rem;
  line-height: 1.35;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 .5em;
}

.leave-kind {
  font-weight: 700;
  white-space: nowrap;
}

.leave-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.leave-sent {
  font-size: .78rem;
  color: var(--muted);
}

.status-pill {
  font-size: .78rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eee;
  white-space: nowrap;
}

.status-pill.status-pending { background: var(--slot-pending); color: var(--slot-on-light); }
.status-pill.status-approved { background: var(--slot-approved); color: #064e3b; }
.status-pill.status-delete { background: var(--slot-pending-delete); color: var(--slot-on-dark); }

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 1rem;
  color: var(--muted);
}

.cal-legend .swatch {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -3px;
}

.swatch.selected { background: var(--slot-selected); }
.swatch.pending { background: var(--slot-pending); }
.swatch.approved { background: var(--slot-approved); }
.swatch.pendingdelete { background: var(--slot-pending-delete); }
.swatch.blocked {
  background-color: var(--slot-blocked);
  background-image: repeating-linear-gradient(
    -45deg,
    var(--slot-blocked),
    var(--slot-blocked) 3px,
    rgba(255, 255, 255, 0.45) 3px,
    rgba(255, 255, 255, 0.45) 5px
  );
}
.swatch.expired { background: #fff; border: 1px solid var(--line); opacity: .55; }

.calendar {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
}

/* 表頭「日／六」維持假日色（出勤 HolidayText） */
.cal-weekdays .is-weekend {
  color: var(--holiday-text);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-day {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 2px 4px;
  background: #f7fafc;
  min-height: 0;
  min-width: 0;
}

.cal-day.is-empty {
  border: none;
  background: transparent;
  pointer-events: none;
}

/* 今天：淡天空藍底＋較粗外框；不覆寫日期字色／時段鈕狀態色 */
.cal-day.is-today {
  background: #e3f2fd;
  border: 2px solid #42a5f5;
  box-shadow: inset 0 0 0 1px rgba(66, 165, 245, 0.35);
}

.cal-day-head {
  font-weight: 800;
  margin-bottom: 2px;
  font-size: .9rem;
  text-align: center;
  line-height: 1.25;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  border-radius: 4px;
}

.cal-day-head:hover {
  background: rgba(14, 165, 233, 0.12);
}

/* 出勤表假日桶：HolidayText；補班：MakeupText */
.cal-day-head.is-holiday {
  color: var(--holiday-text);
}

.cal-day-head.is-makeup {
  color: var(--makeup-text);
}

.cal-slots {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.slot-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 3px;
  padding: 1px 0;
  font-size: .62rem;
  font-weight: 600;
  line-height: 1.05;
  cursor: pointer;
  /* 內容剛好兩行；1px padding + 1px border 在 border-box 外加，空白格也不塌成一行 */
  height: calc(2lh + 4px);
  min-height: calc(2lh + 4px);
  max-height: calc(2lh + 4px);
  overflow: hidden;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.slot-btn .slot-name,
.slot-btn .slot-mark {
  line-height: 1.05;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.slot-btn .slot-mark {
  font-size: .58rem;
  font-weight: 700;
}

.slot-btn:disabled {
  cursor: not-allowed;
  opacity: .85;
}

.slot-btn.is-selected {
  background: var(--slot-selected);
  border-color: #1d4ed8;
  color: var(--slot-on-dark);
  box-shadow: inset 0 0 0 2px #1e3a8a;
}

.slot-btn.is-pending {
  background: var(--slot-pending);
  border-color: #d97706;
  color: var(--slot-on-light);
}

.slot-btn.is-approved {
  background: var(--slot-approved);
  border-color: #047857;
  color: #064e3b;
}

/* 可點刪／申請刪單：維持色塊但可點（勿用 :disabled 灰掉） */
.slot-btn.is-actionable {
  cursor: pointer;
  opacity: 1;
}

.slot-btn.is-actionable:active {
  transform: scale(0.96);
}

.slot-btn.is-blocked {
  background-color: var(--slot-blocked);
  background-image: repeating-linear-gradient(
    -45deg,
    var(--slot-blocked),
    var(--slot-blocked) 4px,
    rgba(255, 255, 255, 0.38) 4px,
    rgba(255, 255, 255, 0.38) 7px
  );
  border-color: #4b5563;
  color: var(--slot-on-dark);
}

.slot-btn.is-pendingdelete {
  background: var(--slot-pending-delete);
  border-color: #b91c1c;
  color: var(--slot-on-dark);
}

.slot-btn.is-pending.is-selected,
.slot-btn.is-approved.is-selected,
.slot-btn.is-pendingdelete.is-selected,
.slot-btn.is-blocked.is-selected {
  box-shadow: inset 0 0 0 2px var(--slot-selected);
}

/* 與桌面：過期格白底僅不可點（禁休才深灰） */
.slot-btn.is-expired {
  background: #fff;
  border-color: var(--line);
  color: var(--muted);
  opacity: .55;
}

code {
  background: #eef3f6;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: .9em;
}

/* 頁內確認（LINE WebView 常擋 window.confirm／alert） */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(12, 74, 110, 0.45);
}

.confirm-overlay[hidden] {
  display: none !important;
}

.confirm-card {
  width: min(100%, 22rem);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem 1rem;
  border: 1px solid var(--line);
}

.confirm-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.confirm-msg {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink);
  white-space: pre-wrap;
}

.confirm-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.confirm-actions .btn {
  min-width: 4.5rem;
}

.att-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  margin-top: 12px;
  width: 100%;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* phone-fullbleed-v2：720px 以下主欄貼齊螢幕，左右只留 8px */
@media (max-width: 720px) {
  .app-header,
  .app-header-inner,
  .user-bar,
  .app-main,
  .card,
  .calendar,
  .cal-grid,
  .cal-weekdays {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  .app-header-inner,
  .user-bar,
  .app-main {
    padding-left: 8px;
    padding-right: 8px;
  }

  .card {
    padding: 12px 8px;
  }

  .header-left {
    max-width: 46%;
  }

  .brand-logo,
  .brand-logo-lg {
    max-width: 100%;
  }
}

.att-sheet {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  background: var(--card);
}

.att-sheet th,
.att-sheet td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 2px 6px;
  text-align: center;
  white-space: nowrap;
  font-size: 0.82rem;
  line-height: 1.25;
  min-width: 3.1rem;
  height: 1.7rem;
  background: #fff;
}

.att-sheet .att-label {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 4.8rem;
  text-align: left;
  font-weight: 600;
  background: #f7f7f5;
  border-left: 1px solid var(--line);
}

.att-sheet thead th {
  position: sticky;
  top: 0;
  font-weight: 700;
}

.att-sheet thead .att-label { z-index: 2; }

.att-sheet th.att-holiday,
.att-sheet td.att-late,
.att-sheet th.att-evening { color: #f44336; }

.att-sheet th.att-holiday-bg { background: #fff4f6; }

/* Honeypot：對人隱藏，對簡單爬蟲仍可見 */
.hp-field {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
