/* ============================================================
   格侖工程師排程系統 — 樣式
   色票與元件語彙沿用 ServiceReport（同一家公司的兩個站要像同一套東西）。
   月曆的視覺編碼有三個維度，不能互相蓋掉：
     類別 → 色塊底色      狀態 → 邊框與樣式      工程師 → 左緣色條
   ============================================================ */

:root {
  color-scheme: light;

  --brand:        #2fa36b;   /* JIATEK 綠 */
  --brand-dark:   #238053;
  --brand-blue:   #1a63b8;   /* JIATEK 藍 */
  --ink:          #16202a;
  --ink-2:        #47576a;
  --ink-3:        #7d8b9b;
  --line:         #d9e0e7;
  --bg:           #eef1f4;
  --surface:      #ffffff;
  --focus:        #2fa36b;
  --danger:       #c0392b;
  --warn:         #e08b2a;

  --radius:       12px;
  --appbar-h:     56px;

  /* 工作類別色 —— 這五個是使用者定的分類，不要自己加第六個 */
  --cat-maintenance: #2fa36b;   /* 保養 */
  --cat-repair:      #c0392b;   /* 維修 */
  --cat-install:     #1a63b8;   /* 裝機 */
  --cat-visit:       #7d4fbe;   /* 拜訪 */
  --cat-other:       #6b7a8a;   /* 其他 */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Microsoft JhengHei",
               "PingFang TC", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.app { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
.spacer { flex: 1 1 auto; }

/* ── 上方工具列 ───────────────────────────────────────────── */

.appbar {
  position: sticky; top: 0; z-index: 30;
  min-height: var(--appbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px; padding-top: env(safe-area-inset-top);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(22, 32, 42, .06);
}
.appbar-brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 15px; white-space: nowrap;
}
.appbar-brand .dot {
  width: 10px; height: 10px; border-radius: 3px;
  background: linear-gradient(135deg, var(--brand), var(--brand-blue));
}
.appbar-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who { color: var(--ink-2); font-size: 13px; white-space: nowrap; }

.tabs {
  display: flex; gap: 4px; padding: 6px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
  position: sticky; top: var(--appbar-h); z-index: 29;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: 0; background: transparent;
  color: var(--ink-2); font: inherit; font-size: 15px; font-weight: 600;
  padding: 8px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--brand-dark); }
.tab.is-on { background: #e7f4ec; color: var(--brand-dark); }
.tab .badge {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; line-height: 18px; text-align: center; font-weight: 700;
}

.screen { display: none; flex: 1 1 auto; padding: 14px; }
.screen.is-on { display: block; }

/* ── 通用元件 ─────────────────────────────────────────────── */

.btn {
  appearance: none; font: inherit; font-size: 15px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 40px;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-dark));
  border-color: var(--brand-dark); color: #fff;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { font-size: 13px; padding: 6px 10px; min-height: 32px; border-radius: 8px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: #eef1f4; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card-h {
  margin: 0 0 12px; font-size: 15px; font-weight: 700; color: var(--brand-dark);
  display: flex; align-items: center; gap: 8px;
}

.field { margin-bottom: 14px; }
.field > label {
  display: block; margin-bottom: 6px;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
}
input[type="text"], input[type="email"], input[type="tel"], input[type="date"],
input[type="password"], input[type="number"], select, textarea {
  width: 100%; font: inherit; font-size: 15px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: var(--surface); color: var(--ink);
}
textarea { line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus);
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 180px; margin-bottom: 0; }
.hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; line-height: 1.5; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; font: inherit; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 8px 14px; cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-on { background: var(--brand); border-color: var(--brand-dark); color: #fff; }

.tablewrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
table.list th, table.list td {
  padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle;
}
table.list th { color: var(--ink-2); font-size: 12px; font-weight: 700; white-space: nowrap; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #f6f8fa; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill-proposed  { background: #eef1f4; color: var(--ink-2); border: 1px dashed var(--ink-3); }
.pill-replied   { background: #fff3e0; color: #a45f00; border: 1px solid #e8c48a; }
.pill-confirmed { background: #e7f4ec; color: var(--brand-dark); border: 1px solid #a9d9bf; }
.pill-done      { background: #eef1f4; color: var(--ink-3); border: 1px solid var(--line); }
.pill-incomplete{ background: #fdf0e3; color: #a05a10; border: 1px solid #e8c48a; }

.empty { padding: 28px 12px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ── 月曆 ─────────────────────────────────────────────────── */

.cal-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.cal-title { font-size: 17px; font-weight: 700; min-width: 120px; }
/* 建立行程用藍色，跟綠色的「建立預約」一眼分得開 */
.btn-book {
  background: linear-gradient(180deg, #2f7fd4, var(--brand-blue));
  border-color: var(--brand-blue); color: #fff;
}
.btn-book:hover { filter: brightness(1.06); }
.cal-layout { display: grid; grid-template-columns: 1fr 300px; gap: 14px; align-items: start; }

.cal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-head div {
  padding: 8px 4px; text-align: center; font-size: 12px; font-weight: 700;
  color: var(--ink-2); background: #f6f8fa; border-bottom: 1px solid var(--line);
}
.cal-head div:first-child, .cal-head div:last-child { color: var(--danger); }

.cal-cell {
  position: relative;          /* 右上角的勾選框靠它定位 */
  min-height: 68px;            /* 只是「最矮」——事件多的日子會自己長高，不裁切 */ border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 4px; display: flex; flex-direction: column; gap: 3px; cursor: pointer;
}
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.is-out { background: #fafbfc; }
.cal-cell.is-out .cal-date { color: #c3ccd4; }
.cal-cell.is-today { background: #f3fbf6; }
.cal-cell.is-sel { outline: 2px solid var(--brand); outline-offset: -2px; }
/* ── 每一格右上角的勾選框 ──────────────────────────────
   勾起來的日期會集合成一批候選日，一鍵帶去建立預約。
   ⚠️ 它跟「點格子看當日清單」共用同一個格子，所以點它時要 stopPropagation，
   否則勾一下就順便把當日清單也開了。 */
.cal-pick {
  position: absolute; top: 5px; right: 5px; z-index: 2;
  width: 17px; height: 17px; padding: 0;
  border: 1.5px solid var(--line); border-radius: 5px;
  background: var(--surface); cursor: pointer;
  display: grid; place-items: center;
  font-size: 11px; line-height: 1; color: transparent;
}
.cal-pick:hover { border-color: var(--brand); }
.cal-cell:hover .cal-pick { border-color: var(--ink-3); }
.cal-pick.is-on {
  background: var(--brand); border-color: var(--brand-dark); color: #fff;
}

/* 勾選後的動作列 */
.pickbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: #e7f4ec; border: 1px solid #a9d9bf; border-radius: 10px;
  padding: 7px 10px; margin-bottom: 8px; font-size: 13px; color: var(--brand-dark);
}
.pickbar b { font-weight: 700; }
.pickbar.is-confirm { background: #eaf2fb; border-color: #a9c8e8; color: #1a4f8a; }
/* 沒勾日期時也留在原位（只是變淡）—— 讓它一出現一消失，整張月曆會上下跳 */
.pickbar.is-idle {
  background: var(--surface); border-color: var(--line); color: var(--ink-3);
}
/* 高度固定成「有按鈕時」的高度：沒勾時那條列只有一行字會比較矮，
   一勾就長高 9px，整張月曆跟著往下跳。按鈕 32px ＋ 上下 padding 7px = 46px。 */
.pickbar { min-height: 48px; }
/* 勾很多天時日期清單不要換行 —— 一換行整條列就變高，月曆又跟著跳 */
.pickbar .days { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pickbar .days { color: var(--ink-2); font-size: 13px; }
.pickbar .sp { flex: 1 1 auto; }

/* 轉行程模式：整張月曆變成「選一天」的介面，勾選框先讓路 */
.cal.is-picking .cal-cell { cursor: pointer; }
.cal.is-picking .cal-cell:hover {
  background: #e7f4ec;
  outline: 2px solid var(--brand); outline-offset: -2px;
}
/* 轉行程時整格都可以點（不用瞄準小方框），所以勾選框留著當狀態指示 */
.cal.is-picking .cal-pick { pointer-events: none; }

.cal-date { font-size: 12px; font-weight: 700; color: var(--ink-2); padding: 2px 4px; }
.cal-cell.is-today .cal-date {
  background: var(--brand); color: #fff; border-radius: 999px;
  width: 22px; height: 22px; display: grid; place-items: center; padding: 0;
}

/* 事件方塊：底色＝類別、樣式＝狀態、左緣色條＝工程師 */
.ev {
  font-size: 11.5px; line-height: 1.25; padding: 3px 5px; border-radius: 5px;
  border-left: 3px solid transparent; overflow: hidden;
  background: var(--cat, var(--cat-other)); color: #fff; font-weight: 600;
  display: flex; flex-direction: column; justify-content: center; gap: 0;
  /* 高度固定：沒有標題的（只有一行）也要跟兩行的一樣高，
     否則同一個跨多天的行程在每一天看起來會忽高忽低。 */
  min-height: 33px; flex: 0 0 auto;
}
/* 第一行客戶（有簡稱就用簡稱），第二行標題 —— 兩者各自省略，不要互相擠 */
.ev-l1, .ev-l2 { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-l2 { font-size: 10.5px; font-weight: 400; opacity: .88; }
/* 「全部工程師」檢視時右下角的簡寫。padding-right 讓文字不會被它蓋到。 */
.ev { position: relative; }
.ev-eng {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 9.5px; font-weight: 700; line-height: 1;
  opacity: .95; letter-spacing: .5px; pointer-events: none;
}
.ev:has(.ev-eng) .ev-l1, .ev:has(.ev-eng) .ev-l2 { padding-right: 14px; }
.ev-option {
  background: #fff; color: var(--ink-2); font-weight: 500;
  border: 1px dashed var(--cat, var(--ink-3));
  border-left-width: 3px; border-left-style: solid;
}
.ev-replied {
  background: #fff8ec; color: #8a5200;
  border: 1px solid var(--warn); border-left-width: 3px; border-left-style: solid;
}
.ev-done { opacity: .55; }
/* 外框而不是內框：內框畫在深色的類別底色上幾乎看不見，
   而「這趟沒做完、還要再排」正是最需要一眼看到的那一種。 */
.ev-incomplete { box-shadow: 0 0 0 2px var(--warn); }
/* 同一趟的候選日 hover 時整組亮起 —— 否則月曆上散落的方塊看不出關聯 */
.ev.is-kin { outline: 2px solid var(--brand-blue); outline-offset: 1px; }
.ev-more { font-size: 11px; color: var(--ink-3); padding-left: 5px; }

/* 圖例：從月曆下方搬到上方，壓成一列。色票用的就是月曆上那幾個 class，
   改樣式時圖例會跟著變 —— 不要改成手寫的 inline style，那會變成兩份。 */
.legendbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px 10px;
  font-size: 11.5px; color: var(--ink-2); margin-bottom: 8px; padding: 0 2px;
}
.legendbar span { display: inline-flex; align-items: center; gap: 4px; }
.legendbar i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.legendbar i.sw {
  width: 22px; height: 12px; flex: 0 0 auto;
  padding: 0; text-indent: 0; border-left-width: 0;
}
.legendbar .sep { width: 1px; height: 13px; background: var(--line); margin: 0 3px; }

/* 待辦欄 */
.todo-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.todo-h { font-size: 13px; font-weight: 700; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.todo-h .n {
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 0 6px; line-height: 17px;
}
.todo-h.is-warn .n { background: var(--warn); }
.todo-h.is-mute .n { background: var(--ink-3); }
.todo-item {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  margin-bottom: 7px; cursor: pointer; font-size: 13px; line-height: 1.5;
}
.todo-item:hover { border-color: var(--brand); background: #f6faf7; }
.todo-item b { font-weight: 700; }
.todo-item .sub { color: var(--ink-3); font-size: 12px; }

/* 某一天的清單（點月曆格子後） */
.day-list { margin-top: 12px; }
.day-row {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
  background: var(--surface); cursor: pointer;
}
.day-row:hover { border-color: var(--brand); }
.day-row .bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--cat, var(--ink-3)); }

/* ── 引導遮罩 ─────────────────────────────────────────────
   用 box-shadow 把目標區域「挖空」造出聚光效果。整層 pointer-events:none，
   所以使用者可以直接去點被高亮的月曆，不必先把遮罩關掉。 */
.guide { position: fixed; inset: 0; z-index: 70; pointer-events: none; }
.guide-hole {
  position: absolute; border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(16, 24, 32, .55);
  outline: 3px solid var(--brand); outline-offset: 2px;
}
.guide-msg {
  position: absolute; pointer-events: auto;
  background: var(--surface); border-radius: 12px; padding: 12px 16px;
  box-shadow: 0 14px 36px rgba(16, 24, 32, .35);
  font-size: 15px; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 14px; max-width: 92vw;
}
.guide-msg .sub { font-weight: 400; font-size: 13px; color: var(--ink-2); }
.guide-msg .btn { flex: 0 0 auto; }

/* ── 對話框 ───────────────────────────────────────────────── */

.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(16, 24, 32, .55);
  display: flex; align-items: center; justify-content: center; padding: 12px;
  overflow-y: auto;
}
.modal-box {
  background: var(--surface); border-radius: 14px; padding: 18px;
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto;
  box-shadow: 0 18px 48px rgba(16, 24, 32, .3);
}
.modal-box.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-foot { display: flex; gap: 10px; margin-top: 18px; }
.modal-foot .btn { flex: 1 1 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 80; background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(16, 24, 32, .3); max-width: 92vw; text-align: center;
}
.toast.is-err { background: var(--danger); }

/* 登入畫面 */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.gate-box { width: 100%; max-width: 380px; }
.gate-box h1 { font-size: 20px; margin: 0 0 4px; }
.gate-box .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 18px; }

/* 日期多選器 */
.inline-chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink-2); }
.inline-chk input { width: auto; margin: 0; }

.datepick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.datepick .d {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--brand); background: #e7f4ec; color: var(--brand-dark);
  border-radius: 999px; padding: 6px 8px 6px 12px; font-size: 14px; font-weight: 600;
}
.datepick .d select {
  width: auto; font-size: 12px; padding: 2px 4px; border-radius: 6px; border-color: #a9d9bf;
  background: #fff;
}
.datepick .d button {
  appearance: none; border: 0; background: transparent; color: var(--brand-dark);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}

/* ── 手機 ─────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .cal-layout { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .screen { padding: 10px; }
  /* 手機格子放不下文字，改成彩色圓點；點某天在下方展開清單。
     硬塞文字的結果是每一塊都變成「…」，等於什麼都沒顯示。 */
  .cal-cell { min-height: 56px; padding: 3px 2px; gap: 2px; }
  .cal-date { font-size: 11px; padding: 1px 2px; }
  /* 手機一格只有 ~53px 寬，勾選框要縮一點才不會跟日期數字擠在一起 */
  .cal-pick { width: 15px; height: 15px; top: 3px; right: 3px; font-size: 9px; border-radius: 4px; }
  .pickbar { font-size: 13px; padding: 9px 10px; }
  .pickbar .days { width: 100%; }
  .ev {
    height: 6px; min-height: 0; padding: 0; border-radius: 3px; border-left-width: 0;
    overflow: hidden;
  }
  .ev-l1, .ev-l2 { display: none; }   /* 手機只剩色條，兩行文字整個收起來 */
  .ev-option { border-width: 1px; border-style: dashed; }
  .ev-more { display: none; }
  .cal-title { font-size: 17px; min-width: 120px; }
  .modal-foot { flex-wrap: wrap; }
}

/* ── 小筆電（螢幕矮）───────────────────────────────────────
   1366×768 / 1536×864 這類機器，扣掉瀏覽器工具列只剩約 600–700px。
   用 max-height 而不是 max-width：問題出在高度，不是寬度。 */
@media (max-height: 900px) {
  .cal-cell { min-height: 60px; }
  .screen { padding: 10px 14px; }
}
@media (max-height: 820px) {
  /* 矮螢幕只縮「空白日子」的最小高度；有事件的日子照樣長，不裁切。
     ⚠️ 這裡不要再壓 .ev 的 min-height —— 壓到比兩行內容矮，
     沒有標題的方塊就會變矮，同一列看起來忽高忽低。 */
  .cal-cell { min-height: 52px; padding: 3px; }
  .cal-head div { padding: 5px 4px; font-size: 11px; }
  .cal-bar { margin-bottom: 6px; }
  .cal-title { font-size: 16px; min-width: 108px; }
  .legendbar { font-size: 11px; margin-bottom: 6px; gap: 2px 8px; }
  .ev { font-size: 11px; padding: 2px 4px; }
}
