/* ============================================================
   格侖工程師排程系統 — 樣式
   色票與元件語彙沿用 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: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.cal-title { font-size: 19px; font-weight: 700; min-width: 150px; }
.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 {
  min-height: 104px; 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; }
.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.3; padding: 3px 5px; border-radius: 5px;
  border-left: 3px solid transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--cat, var(--cat-other)); color: #fff; font-weight: 600;
}
.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; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
/* 狀態列的色票直接套月曆上的 .ev 類別，尺寸放寬一點才看得出虛線與內框。
   ⚠️ 手機版把 .ev 壓成 6px 高的色條，圖例要豁免，否則整列變成看不懂的細線。 */
.legend i.sw {
  width: 26px; height: 14px; flex: 0 0 auto; padding: 0;
  text-indent: 0; border-left-width: 0;
}

/* 待辦欄 */
.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)); }

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

.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; }

/* 日期多選器 */
.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; }
  .ev {
    height: 6px; padding: 0; border-radius: 3px; border-left-width: 0;
    text-indent: -9999px; overflow: hidden;
  }
  .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; }
}
