:root {
  --ink: #1b2733;
  --ink-soft: #55606d;
  --line: #d8dee6;
  --bg: #eff2f6;
  --surface: #fff;
  --accent: #0f6e5c;
  --accent-dark: #0b5445;
  --turquoise: #0a9aa5;
  --danger: #b42318;
  --warn: #9a6700;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h2 { font-size: 17px; margin: 0 0 4px; }
h3 { font-size: 14px; color: var(--ink-soft); font-weight: 600; margin: 0 0 8px; }

/* ---------- top bar ---------- */
.topbar { background: #23384d; color: #fff; }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 12px 20px 0; }
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: .04em; }
.brand-org { font-size: 13px; color: #a9bdd2; }

.tabs { display: flex; gap: 4px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { white-space: nowrap; flex: 0 0 auto; }
.tabs button {
  background: none; border: 0; color: #c3d3e2; font: inherit; font-size: 14px;
  padding: 8px 14px; cursor: pointer; border-radius: var(--radius) var(--radius) 0 0;
}
.tabs button:hover { color: #fff; background: rgba(255,255,255,.08); }
.tabs button.on { background: var(--bg); color: var(--ink); font-weight: 600; }

/* ---------- layout ---------- */
.page { max-width: 1180px; margin: 18px auto 60px; padding: 0 20px; }
.panel, .board {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--ink-soft); font-size: 13px; margin: 4px 0 12px; max-width: 68ch; }
.formrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.formrow label { font-size: 13px; color: var(--ink-soft); }
.spacer { flex: 1; }
.hide { display: none !important; }
.inline { font-size: 13px; color: var(--ink-soft); display: inline-flex; gap: 6px; align-items: center; }

/* ---------- date bar ---------- */
.datebar {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px;
}
.bar-date, .bar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.datebar input[type=date] { font-size: 16px; font-weight: 600; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head-actions input { width: 200px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.bulkbar {
  background: #f6f8fa; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 12px;
}
.bulkbar strong { font-size: 14px; }

/* ---------- controls ---------- */
button, input, select {
  font-family: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 10px; background: #fff; color: var(--ink);
}
button {
  cursor: pointer; background: #fff;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
button:hover { background: var(--turquoise); border-color: var(--turquoise); color: #fff; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--turquoise); outline-offset: 1px;
}
button.primary { font-weight: 600; }
button.danger { border-color: #e6b3ae; color: var(--danger); }
button.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { padding: 7px 11px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:disabled:hover { background: #fff; border-color: var(--line); color: var(--ink); }
button.mini { padding: 4px 9px; font-size: 13px; }
button.big { padding: 9px 20px; font-size: 15px; }

.badge {
  background: #fdf4e3; border: 1px solid #e4c98a; color: var(--warn);
  border-radius: 999px; padding: 3px 12px; font-size: 13px; font-weight: 600;
}

/* ---------- count board ---------- */
.board-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 10px; }
.totals { display: flex; gap: 18px; font-size: 14px; color: var(--ink-soft); }
.totals b { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; margin-left: 4px; }
.period { margin-top: 14px; }
.blocks { display: flex; flex-wrap: wrap; gap: 10px; }

.block {
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 9px 14px; min-width: 165px;
  background: #fbfcfd; cursor: pointer; text-align: left; font: inherit; display: block;
}
.block:hover { background: #f2f6f9; border-color: var(--line); border-left-color: var(--accent); color: var(--ink); }
.block .loc { font-size: 12px; color: var(--ink-soft); }
.block .meal { font-weight: 600; }
.block .n { font-size: 24px; font-variant-numeric: tabular-nums; float: right; line-height: 1.1; }
.block .names { clear: both; font-size: 12px; color: var(--ink-soft); padding-top: 8px; border-top: 1px dashed var(--line); margin-top: 6px; }
.blocks .none { color: var(--ink-soft); font-size: 13px; }

.summary { border-collapse: collapse; margin-top: 18px; font-size: 14px; }
.summary th, .summary td { border: 1px solid var(--line); padding: 5px 14px; text-align: right; }
.summary th:first-child, .summary td:first-child { text-align: left; }
.summary thead th { background: #f2f5f8; }
.summary tfoot td { font-weight: 700; background: #f8fafb; }
.summary td { font-variant-numeric: tabular-nums; }

.units-head { display: flex; align-items: center; gap: 14px; margin: 24px 0 10px; }
.units-head h3 { margin: 0; }
.unit-group { margin-bottom: 16px; }
.unit-group > .vendor { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.unit-group > .phones { font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; line-height: 1.6; }
table.units { border-collapse: collapse; font-size: 13px; }
.unit-group .table-scroll { padding-bottom: 2px; }
table.units th, table.units td { border: 1px solid var(--line); padding: 4px 12px; text-align: center; }
table.units thead th { background: #f2f5f8; font-weight: 600; }
table.units .unit { text-align: left; min-width: 110px; }
table.units td.num { font-variant-numeric: tabular-nums; min-width: 46px; }
table.units td.zero { color: #c2c8d0; }
table.units tfoot td { font-weight: 700; background: #f8fafb; }

/* ---------- tables ---------- */
.grid { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
.grid th, .grid td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.grid thead th { background: #f2f5f8; font-weight: 600; position: sticky; top: 0; }
.grid tbody tr:nth-child(even) { background: #fafbfc; }
.grid input, .grid select { width: 100%; padding: 4px 6px; }
.grid td.acts { white-space: nowrap; }
.scroll { max-height: 65vh; overflow: auto; border-radius: var(--radius); }

.tag {
  font-size: 12px; border-radius: 4px; padding: 2px 7px;
  background: #eef2f6; color: var(--ink-soft);
  display: inline-block; white-space: nowrap; margin: 1px 0;
}
.tag.punch { background: #e6f2ee; color: var(--accent-dark); }
.tag.lunch { background: #eaf0f7; color: #23384d; }
.tag.dinner { background: #f2ecf7; color: #5b3f7a; }
.tag.none { background: #fdf4e3; color: var(--warn); }
.tag.off { background: #fbeceb; color: var(--danger); }
.sheet-count { font-size: 13px; font-weight: 400; color: var(--ink-soft); }
tr.unordered td { background: #fffdf7; }
tr.skipped td { background: #f6f7f8; color: var(--ink-soft); }

.empty { color: var(--ink-soft); font-size: 14px; padding: 14px 0; }
.absent { background: #fdf9ef; border: 1px solid #ecdcb4; border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-top: 10px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(20,30,40,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-box { background: #fff; border-radius: 8px; padding: 20px 22px; width: min(620px, 100%); max-height: 84vh; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.datepick { display: block; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.datepick:last-child { border-bottom: 0; }
.datepick small { color: var(--ink-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #23384d; color: #fff; padding: 11px 20px; border-radius: 6px;
  font-size: 14px; z-index: 200; max-width: 90vw; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}
.toast.err { background: var(--danger); }

/* ---------- 手機 / 平板 ---------- */
@media (max-width: 900px) {
  .page { padding: 0 12px; }
  .panel, .board { padding: 14px; }
  .head-actions input { width: 100%; }
  .head-actions { width: 100%; }
  .head-actions button { flex: 1 1 auto; }
}

@media (max-width: 720px) {
  body { font-size: 15px; }
  .brand { flex-direction: column; gap: 0; align-items: flex-start; }
  .topbar-in { padding: 10px 12px 0; }

  /* 日期與功能鍵分兩段，功能鍵兩顆一列 */
  .datebar { padding: 10px; gap: 8px; }
  .bar-date, .bar-actions { width: 100%; }
  .bar-date input[type=date] { flex: 1 1 auto; }
  .bar-actions button { flex: 1 1 calc(50% - 4px); }

  /* 表單控制項兩欄排列，按鈕獨佔一列 */
  .formrow { gap: 6px; }
  .formrow input, .formrow select { flex: 1 1 calc(50% - 3px); width: auto !important; min-width: 130px; }
  .formrow button { flex: 1 1 100%; width: auto !important; }
  .formrow label { flex: 0 0 100%; margin-top: 4px; }

  .board-head { flex-direction: column; align-items: flex-start; }
  .totals { gap: 14px; }
  .block { min-width: calc(50% - 5px); flex: 1 1 calc(50% - 5px); }

  /* 訂單明細與員工資料改成一列一張卡 */
  .scroll { max-height: none; overflow: visible; }
  .grid.cards { font-size: 14px; }
  .grid.cards thead { display: none; }
  .grid.cards, .grid.cards tbody, .grid.cards tr, .grid.cards td { display: block; width: 100%; }
  .grid.cards tr {
    border: 1px solid var(--line); border-radius: var(--radius);
    margin-bottom: 10px; padding: 8px 12px; background: #fff;
  }
  .grid.cards tbody tr:nth-child(even) { background: #fff; }
  .grid.cards td { border: 0; padding: 4px 0; display: flex; align-items: center; gap: 10px; }
  .grid.cards td::before {
    content: attr(data-label); flex: 0 0 84px;
    color: var(--ink-soft); font-size: 13px;
  }
  .grid.cards td.acts { justify-content: flex-end; gap: 8px; padding-top: 8px; }
  .grid.cards td.acts::before { content: ''; flex: 0 0 0; }
  .grid.cards td.acts button { flex: 1 1 auto; }
  .grid.cards td input, .grid.cards td select { flex: 1 1 auto; }
  .grid.cards td[data-label="固定"], .grid.cards td[data-label="在職"] { text-align: left !important; }
  .grid.cards td[data-label="固定"] input, .grid.cards td[data-label="在職"] input { flex: 0 0 auto; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-box { max-height: 92vh; border-radius: 10px 10px 0 0; width: 100%; }
  .toast { left: 12px; right: 12px; bottom: 12px; transform: none; max-width: none; }
  .units-head { flex-wrap: wrap; }
}

/* 當日訂餐上方的部門篩選 */
.deptpick { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; font-weight: 600; }
.deptpick select { width: 150px; }
.deptpick.on select { border-color: var(--accent, #2563eb); background: #eef4ff; }

/* 訂單明細表頭的部門下拉 */
.th-filter select { width: 100%; font-weight: 700; padding: 3px 4px; }
.th-filter select.on { border-color: var(--accent, #2563eb); background: #eef4ff; }

/* 標題列裡的勾選框不要被 .head-actions input 撐寬 */
.head-actions input[type="checkbox"] { width: auto; }
