:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --off: #fde68a;
  --work: #dbeafe;
  --holiday: #fecaca;
  --line: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.55;
}

/* ---------- 版面：響應式 ---------- */
header.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  padding: .75rem 1rem; display: flex; align-items: center; gap: .75rem;
  box-shadow: var(--shadow);
}
header.appbar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; }
.tabbar {
  display: flex; gap: .25rem; flex-wrap: wrap;
  background: var(--card); padding: .4rem .6rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 52px; z-index: 15;
}
.tabbar button {
  border: 0; background: transparent; color: var(--muted);
  padding: .5rem .8rem; border-radius: 8px; cursor: pointer; font-size: .95rem;
}
.tabbar button.active { background: var(--work); color: var(--brand-dark); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem; margin-bottom: 1rem;
}
.card h2 { margin: 0 0 .6rem; font-size: 1.1rem; }
.muted { color: var(--muted); font-size: .9rem; }

.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
label.field { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
select, input[type=text], input[type=date] {
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  font-size: 1rem; background: #fff; min-width: 140px;
}
button.btn {
  background: var(--brand); color: #fff; border: 0; border-radius: 8px;
  padding: .6rem 1rem; font-size: 1rem; cursor: pointer; font-weight: 600;
}
button.btn:hover { background: var(--brand-dark); }
button.btn.ghost { background: #eef2ff; color: var(--brand-dark); }
button.btn.warn { background: var(--warn); }
button.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- 引導式精靈步驟條 ---------- */
.steps { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.steps .step {
  flex: 1 1 120px; min-width: 90px; text-align: center; padding: .5rem;
  border-radius: 8px; background: #eef2f7; color: var(--muted); font-size: .85rem;
}
.steps .step.active { background: var(--brand); color: #fff; font-weight: 600; }
.steps .step.done { background: #d1fae5; color: var(--ok); }

/* ---------- 行事曆（桌機格狀，手機自動轉清單） ---------- */
.calendar {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: .4rem;
}
.cal-head { font-weight: 600; text-align: center; color: var(--muted); font-size: .8rem; }
.cal-cell {
  border: 1px solid var(--line); border-radius: 8px; padding: .4rem; min-height: 64px;
  cursor: pointer; background: #fff; position: relative; user-select: none;
}
.cal-cell .d { font-size: .85rem; color: var(--muted); }
.cal-cell.want_off { background: var(--off); border-color: #f59e0b; }
.cal-cell.want_on { background: var(--work); border-color: var(--brand); }
.cal-cell.blocked { background: #f3f4f6; color: #9ca3af; cursor: not-allowed; }
.cal-cell .tag { font-size: .72rem; font-weight: 600; }
.cal-cell.holiday { background: var(--holiday); }

/* 班表格 */
.grid-wrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-size: .82rem; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: .3rem .4rem; text-align: center; white-space: nowrap; }
table.grid th.sticky { position: sticky; left: 0; background: #f9fafb; z-index: 1; }
.cellt { display: inline-block; min-width: 2.2em; border-radius: 5px; padding: 0 .3em; }
.t-workday { background: var(--work); }
.t-rest_day { background: var(--off); }
.t-regular_day_off { background: #fbcfe8; }
.t-national_holiday { background: var(--holiday); }
.t-store_closed, .t-company_shutdown { background: #e5e7eb; }

/* ---------- 提示/警示 ---------- */
.alert { padding: .7rem .9rem; border-radius: 8px; margin: .6rem 0; font-size: .92rem; }
.alert.ok { background: #dcfce7; color: #166534; }
.alert.warn { background: #fef3c7; color: #92400e; }
.alert.bad { background: #fee2e2; color: #991b1b; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.chip { background: #eef2ff; color: var(--brand-dark); border-radius: 999px; padding: .25rem .7rem; cursor: pointer; font-size: .85rem; }

/* ---------- 不可跳過的閱讀確認 modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: none; align-items: center; justify-content: center; z-index: 50; padding: 1rem;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); max-width: 540px; width: 100%;
  padding: 1.2rem; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 .5rem; }
.modal .read-box {
  max-height: 220px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 8px; padding: .8rem; font-size: .9rem; background: #fafafa;
}
.modal .ack { display: flex; gap: .5rem; align-items: flex-start; margin: .8rem 0; font-size: .9rem; }

.legend { display: flex; gap: .8rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* ---------- 手機：行事曆轉為清單，步驟條縮小 ---------- */
@media (max-width: 640px) {
  main { padding: .6rem; }
  .calendar { grid-template-columns: 1fr; }
  .cal-head { display: none; }
  .cal-cell { display: flex; justify-content: space-between; align-items: center; min-height: 0; }
  .cal-cell .d::after { content: attr(data-weekday); margin-left: .4rem; color: var(--muted); }
  .steps .step { flex-basis: 100%; }
  header.appbar h1 { font-size: .95rem; }
}
