:root {
  --bg: #eef4f6;
  --surface: #fff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #d9e0e7;
  --line-soft: #e5eaf0;
  --line-strong: #a3adb9;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #f0fdfa;
  --accent-line: #99e6da;
  --ok: #166534;
  --ok-bg: #f0fdf4;
  --ok-line: #86efac;
  --warn-bg: #fef9c3;
  --warn-line: #fde047;
  --err: #b91c1c;
  --rest: #e5e5e5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background-color: var(--bg);
  background-image: url("images/bg1.webp");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

.hero h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.lede {
  color: var(--muted);
  margin: 2px 0 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.upload-panel {
  margin-top: 24px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 0;
}

.panel-head h2 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.upload-count {
  font-size: 0.8125rem;
  color: var(--muted);
  margin: 0;
}

.upload-count.ready {
  color: var(--accent);
  font-weight: 600;
}

.uploads {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 14px 20px 18px;
}

.upload-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.upload-card.has-file {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.upload-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.upload-step {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  line-height: 22px;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 50%;
}

.upload-card.has-file .upload-step {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.upload-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-weight: 600;
  font-size: 0.9375rem;
}

.upload-hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.45;
}

.upload-status {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
}

.upload-card.has-file .upload-status {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.howto {
  font-size: 0.75rem;
  color: var(--muted);
}

.howto > summary {
  display: inline-block;
  cursor: pointer;
  color: var(--accent);
  font-weight: 500;
  list-style: none;
}

.howto > summary::-webkit-details-marker {
  display: none;
}

.howto > summary:hover {
  text-decoration: underline;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 0;
  margin: 6px 0 0;
  padding: 8px 10px;
  list-style: none;
  background: var(--surface-2);
  border-radius: 6px;
  color: var(--ink);
  line-height: 1.6;
}

.crumbs li + li::before {
  content: "›";
  margin: 0 6px;
  color: var(--line-strong);
}

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 92px;
  margin-top: auto;
  padding: 12px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.dropzone:hover,
.upload-card.drag .dropzone {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.dropzone:focus-within {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
}

.dropzone-icon svg {
  display: block;
  width: 24px;
  height: 24px;
}

.upload-card.has-file .dropzone {
  align-items: stretch;
  justify-content: flex-start;
  border-style: solid;
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.upload-card.has-file .dropzone-icon {
  display: none;
}

.file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
  z-index: 2;
}

.upload-file {
  font-size: 0.8125rem;
}

/* The "+N 個" chip sits on its own line below the file names. */
.upload-file:not(.empty) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.file-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 100%;
}

.file-chip {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 1px 8px;
  font-size: 0.75rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--accent-line);
  border-radius: 999px;
}

.file-chip-more {
  color: var(--accent);
  font-weight: 600;
  border-style: dashed;
}

.optional-uploads {
  border-top: 1px solid var(--line-soft);
}

.optional-uploads > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 12px 20px;
  cursor: pointer;
  list-style: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
  user-select: none;
}

.optional-uploads > summary::-webkit-details-marker {
  display: none;
}

.optional-uploads > summary::before {
  content: "";
  align-self: center;
  width: 0.4em;
  height: 0.4em;
  margin-right: 2px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
}

.optional-uploads[open] > summary::before {
  transform: rotate(45deg);
}

.optional-note {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.optional-uploads > .uploads {
  padding-top: 0;
}

.upload-step-optional {
  color: var(--muted);
  background: var(--surface-2);
  border-color: var(--line);
}

.pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

.pick-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.pick-hint {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.pick-hint.ready {
  color: var(--accent);
  font-weight: 600;
}

.preview-local-opts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 10px;
}

.option-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.8125rem;
  cursor: pointer;
}

.option-check input {
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.option-note {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted);
}

.preview-local-opts:has(#opt-append-leave:checked) .option-note {
  color: #854d0e;
}

button {
  appearance: none;
  border: 1px solid #334155;
  background: #334155;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

button:hover:not(:disabled):not(.ghost):not(.primary):not(.mode-tab):not(.view-tab):not(.store-picker-opt):not(.issue-item):not(.day-chip):not(.person-jump) {
  background: #1e293b;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

#convert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 8.5rem;
  padding: 9px 20px;
}

#convert .btn-spin {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
}

#convert.is-loading {
  cursor: wait;
}

#convert.is-loading:disabled {
  opacity: 1;
}

#convert.is-loading .btn-spin {
  display: block;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

button.ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

button.ghost:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.error {
  margin: 16px 0 0;
  padding: 10px 14px;
  color: var(--err);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 0.875rem;
}

.results {
  margin-top: 24px;
}

.result-card {
  padding: 16px 20px;
}

.result-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 0 0 12px;
}

.result-bar h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--muted);
}

.stat-warn {
  background: #fffbeb;
  border-color: #fde68a;
}

.stat-warn .stat-value {
  color: #b45309;
}

.stat-bad {
  background: #fef2f2;
  border-color: #fecaca;
}

.stat-bad .stat-value {
  color: #b91c1c;
}

.stat-ok .stat-value {
  color: var(--ok);
}

.preview-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 10px;
}

.legend-box {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border-radius: 3px;
  border: 1px solid var(--line);
}

.legend-box:first-child {
  margin-left: 0;
}

.legend-unmatched {
  background: var(--warn-bg);
  border-color: #fca5a5;
}

.legend-unknown {
  background: #f5f3ff;
  border-color: #c4b5fd;
}

.legend-skipped {
  background: #fff1f2;
  border-color: #fda4af;
}

.legend-conflict {
  position: relative;
  background: var(--surface);
  overflow: hidden;
}

.legend-conflict::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-top: 7px solid #f97316;
  border-left: 7px solid transparent;
}

.legend-cross {
  background: var(--surface);
  border: 1.5px dashed #6366f1;
}

.legend-diff {
  background: #fff7ed;
  border-color: #fb923c;
}

/* Person count follows the most urgent level in the card. */
.person-head .person-count.count-mid {
  background: #d97706;
}

.person-head .person-count.count-low {
  background: #6366f1;
}

button.issue-item.no-target,
button.day-chip.no-target {
  cursor: default;
}

.note-box.result-notes {
  margin: 10px 0 0;
}

/* Result overview: one row per store, chips count each kind of 請核對 item. */
.file-list {
  display: flex;
  flex-direction: column;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.file-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(12rem, 18rem) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.12s;
}

.file-row + .file-row {
  border-top: 1px solid var(--line-soft);
}

.file-row:hover {
  background: var(--surface-2);
}

.file-row:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: -2px;
}

.file-row.is-active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-row.is-disabled {
  cursor: default;
}

.file-count {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ok);
  background: var(--ok-bg);
}

.file-count.has-issues {
  color: var(--err);
  background: #fef2f2;
}

.file-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.file-name b {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name span {
  font-size: 0.8125rem;
  color: var(--muted);
}

/* Third line of a store row: counts as small pills. */
.file-name .file-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.file-name .meta-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 0 7px;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
}

.file-name .meta-pill b {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-ok {
  font-size: 0.8125rem;
  color: var(--ok);
}

.file-error {
  font-size: 0.8125rem;
  color: var(--err);
}

/* 要處理 count in the preview's store picker. */
.status-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.6;
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
  vertical-align: 1px;
}

.status-badge.has-issues {
  color: var(--err);
  background: #fef2f2;
  border-color: #fecaca;
}

.kind-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 10px;
  font-size: 0.8125rem;
  border-radius: 999px;
  border: 1px solid;
}

.kind-chip b {
  min-width: 1.4rem;
  padding: 0 6px;
  border-radius: 999px;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.kind-high {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}

.kind-high b {
  color: #fff;
  background: #dc2626;
}

.kind-mid {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.kind-mid b {
  color: #fff;
  background: #d97706;
}

.kind-low {
  color: #4338ca;
  background: #eef2ff;
  border-color: #c7d2fe;
}

.kind-low b {
  color: #fff;
  background: #6366f1;
}

/* Issue board above the roster preview: 請核對 items grouped by person. */
.issue-board {
  margin: 0 0 12px;
}

.note-box {
  margin: 0 0 10px;
  padding: 8px 12px;
  list-style: none;
  font-size: 0.8125rem;
  color: #78350f;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
}

.note-box li + li {
  margin-top: 4px;
}

.note-box .kind-tag {
  margin-right: 8px;
}

.person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding: 2px;
}

.person-card {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.person-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

button.person-jump {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.person-jump:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.person-head span {
  font-size: 0.8125rem;
  color: var(--muted);
}

.person-head .person-count {
  margin-left: auto;
  min-width: 1.5rem;
  padding: 0 6px;
  border-radius: 999px;
  text-align: center;
  font-weight: 600;
  color: #fff;
  background: #dc2626;
}

.person-card ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.issue-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
}

.issue-line + .issue-line {
  border-top: 1px dashed var(--line-soft);
}

.day-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

button.day-chip {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

button.day-chip:hover {
  color: var(--err);
  background: #fef2f2;
  border-color: #fca5a5;
}

/* Already opened: greyed with a tick, so a long list can be worked through. */
button.day-chip.is-visited,
button.issue-item.is-visited .issue-text {
  color: var(--muted);
}

button.day-chip.is-visited {
  background: var(--surface-2);
  border-style: dashed;
}

button.day-chip.is-visited::before,
button.issue-item.is-visited .issue-text::before {
  content: "✓ ";
  color: var(--ok);
}

.person-card.is-done {
  opacity: 0.6;
}

.person-card.is-done:hover {
  opacity: 1;
}

button.issue-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  margin: -2px -6px;
  padding: 2px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}

button.issue-item:hover {
  background: #fef2f2;
}

.kind-tag {
  flex-shrink: 0;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
}

.issue-text {
  line-height: 1.5;
}

.board-empty {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.875rem;
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
  border-radius: 8px;
}

@keyframes cell-pulse {
  from {
    outline: 3px solid #f59e0b;
    outline-offset: -3px;
    color: #92400e;
    background: #fef3c7;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35);
  }
  to {
    outline: 3px solid #ea580c;
    outline-offset: -3px;
    color: #fff;
    background: #f97316;
    box-shadow: 0 0 0 6px rgba(249, 115, 22, 0.45);
  }
}

@keyframes cell-fade {
  from {
    outline: 3px solid #f59e0b;
    outline-offset: -3px;
    color: #92400e;
    background: #fef3c7;
  }
  to {
    outline: 3px solid transparent;
  }
}

.warn-dot {
  flex-shrink: 0;
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  align-self: center;
}

.warn-dot-high {
  background: #dc2626;
}

.warn-dot-mid {
  background: #d97706;
}

.warn-dot-low {
  background: #6366f1;
}

.rules-panel {
  margin: 24px 0 0;
  overflow: hidden;
}

.rules-panel + .rules-panel {
  margin-top: 12px;
}

.rules-panel > summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink);
  padding: 14px 20px;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rules-panel > summary::-webkit-details-marker {
  display: none;
}

.rules-panel > summary::after {
  content: "";
  flex-shrink: 0;
  width: 0.4em;
  height: 0.4em;
  margin-left: auto;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg);
}

/* Which 班次管理 is in use, next to the 班次時間 title. */
.shift-source {
  margin-left: 10px;
  padding: 0 8px;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.6;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
}

.shift-source:empty {
  display: none;
}

.shift-source.is-upload {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.shift-source.is-error {
  color: var(--err);
  background: #fef2f2;
  border-color: #fecaca;
}

.rules-panel[open] > summary::after {
  transform: rotate(-135deg);
}

.rules-panel[open] > summary {
  border-bottom: 1px solid var(--line-soft);
}

.rules-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px 20px;
  padding: 16px;
  align-items: start;
}

.rules-panel > .rules-callout,
.rules-panel > .rules-callouts {
  margin: 16px 16px 0;
}

.rules-callouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

/* Notes beside the rules tables: a soft box with a short title and one line per point. */
.rules-callout {
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--line-strong);
  border-radius: 8px;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--muted);
}

.rules-callout p {
  margin: 0;
}

.rules-callout-title {
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--ink);
}

.rules-callout ul {
  margin: 0;
  padding-left: 1.1em;
}

.rules-callout li + li {
  margin-top: 2px;
}

.rules {
  min-width: 0;
}

.rules .plain {
  width: 100%;
}

.rules .plain th,
.rules .plain td {
  white-space: normal;
}

.rules .plain + .plain {
  margin-top: 12px;
}

.rules .plain + .rules-callout {
  margin-top: 10px;
}

.rules-shifts,
.rules-wide {
  grid-column: 1 / -1;
}

.rules-wide .plain th:first-child,
.rules-wide .plain td:first-child {
  white-space: nowrap;
}

.rules-shifts-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 0 0 8px;
}

.rules-shifts-wrap {
  overflow-x: auto;
}

.rules-shifts .plain th,
.rules-shifts .plain td {
  white-space: nowrap;
  vertical-align: top;
}

.rules-shifts .shift-dup {
  color: var(--line-strong);
  text-decoration: line-through;
}

.rules-shifts[data-shift-dept="F"] [data-dept]:not([data-dept="F"]),
.rules-shifts[data-shift-dept="K"] [data-dept]:not([data-dept="K"]),
.rules-shifts[data-shift-dept="S"] [data-dept]:not([data-dept="S"]) {
  display: none;
}

.rules-shifts[data-shift-dept="F"] tbody tr:not(:has([data-dept="F"])),
.rules-shifts[data-shift-dept="K"] tbody tr:not(:has([data-dept="K"])),
.rules-shifts[data-shift-dept="S"] tbody tr:not(:has([data-dept="S"])) {
  display: none;
}

.rules-shifts .shift-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.45;
}

.store-select-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.store-picker-host {
  flex: 1;
  min-width: 0;
  max-width: 280px;
}

.file-step {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.file-step button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
}

.file-step svg {
  width: 18px;
  height: 18px;
}

.store-picker {
  position: relative;
}

.store-picker-face {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1px;
  list-style: none;
  cursor: pointer;
  padding: 7px 32px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  min-width: 0;
}

.store-picker-face::-webkit-details-marker {
  display: none;
}

.store-picker[open] .store-picker-face {
  border-color: var(--accent-line);
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

.store-picker-face::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  width: 0.45em;
  height: 0.45em;
  margin-top: -0.3em;
  border-right: 1.5px solid #888;
  border-bottom: 1.5px solid #888;
  transform: rotate(45deg);
  pointer-events: none;
}

.store-picker[open] .store-picker-face::after {
  margin-top: -0.1em;
  transform: rotate(-135deg);
}

.store-picker-shop {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}

.store-picker-yoov {
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.3;
  color: var(--muted);
}

.store-picker-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px color-mix(in srgb, #1a1a1a 12%, transparent);
}

.store-picker-opt {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  cursor: pointer;
}

.store-picker-opt:hover {
  background: #f5f5f5;
  border-color: var(--line);
}

.store-picker-opt:hover .store-picker-shop {
  color: var(--ink);
}

.store-picker-opt:hover .store-picker-yoov {
  color: var(--muted);
}

.store-picker-opt.is-active,
.store-picker-opt.is-active:hover {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.roster-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.preview-dl {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin: 0 0 12px;
}

.preview-mode {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #eef2f6;
  border-radius: 8px;
}

button.mode-tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 14px;
  border-radius: 6px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

button.mode-tab:hover:not(:disabled) {
  color: var(--ink);
}

button.mode-tab:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

button.mode-tab.active,
button.mode-tab.active:hover:not(:disabled) {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.view-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 12px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

button.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 18px;
  border-radius: 7px;
  font-weight: 600;
}

button.view-tab:hover {
  color: var(--ink);
}

button.view-tab.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
}

.tab-count:not(:empty) {
  min-width: 1.5em;
  padding: 0 6px;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.view-panel {
  padding: 16px 20px;
}

.chip-check {
  position: relative;
  display: inline-flex;
  cursor: pointer;
}

.chip-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip-check span {
  padding: 3px 12px;
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip-check:hover span {
  border-color: var(--line-strong);
  color: var(--ink);
}

.chip-check input:checked + span {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
  font-weight: 500;
}

.chip-check input:checked + span::before {
  content: "✓ ";
}

.chip-check input:focus-visible + span {
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

.chip-preview-diff input:checked + span {
  color: #c2410c;
  background: #fff7ed;
  border-color: #fb923c;
}

.chip-preview-diff input:focus-visible + span {
  outline-color: #fb923c;
}

.chip-preview-unknown input:checked + span {
  color: #6d28d9;
  background: #f5f3ff;
  border-color: #c4b5fd;
}

.chip-preview-unknown input:focus-visible + span {
  outline-color: #c4b5fd;
}

.plain {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.previews table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.plain th,
.plain td,
.previews th,
.previews td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
}

.plain th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
}

.previews {
  margin-top: 20px;
  width: 100%;
}

.preview-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.previews article {
  min-width: 0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 460px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) #f4f4f4;
}

.table-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-wrap::-webkit-scrollbar-track {
  background: #f4f4f4;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 8px;
  border: 2px solid #f4f4f4;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: #737373;
}

.table-wrap::-webkit-scrollbar-corner {
  background: #f4f4f4;
}

.previews td.diff {
  background: #fff7ed;
  box-shadow: inset 0 0 0 1.5px #fb923c;
}

.previews td.leave-skipped {
  background: #fff1f2;
  color: #be123c;
  box-shadow: inset 0 0 0 1.5px #fda4af;
  font-weight: 600;
}

/* Red corner flag: roster filled (L / SH / NPSH) but the leave record was not written. */
.previews td.leave-skipped-filled {
  position: relative;
}

.previews td.leave-skipped-filled::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  border-bottom: 9px solid #e11d48;
  border-right: 9px solid transparent;
  pointer-events: none;
}

.chip-leave-skipped input:checked + span {
  color: #be123c;
  background: #fff1f2;
  border-color: #fda4af;
}

.previews td.cross-store {
  outline: 1.5px dashed #6366f1;
  outline-offset: -3px;
}

/* Orange corner flag: two rosters had different shifts on this day. */
.previews td.shift-conflict {
  position: relative;
}

.previews td.shift-conflict::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  border-top: 9px solid #f97316;
  border-left: 9px solid transparent;
  pointer-events: none;
}

.preview-tip {
  position: fixed;
  z-index: 1000;
  max-width: 320px;
  padding: 6px 9px;
  border-radius: 6px;
  background: #1f2937;
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-line;
  pointer-events: none;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.18);
}

.preview-tip[hidden] {
  display: none;
}

.previews td.unknown-code {
  background: #f5f3ff;
  color: #6d28d9;
  box-shadow: inset 0 0 0 1.5px #c4b5fd;
  font-weight: 600;
}

.previews td.rest.diff {
  background: #fff7ed;
  box-shadow: inset 0 0 0 1.5px #fb923c;
}

.previews td.shift-day {
  --shift-bg: #fef08a;
  --shift-bg-hot: #fde047;
  --shift-line: #eab308;
  --shift-line-hot: #ca8a04;
}

.previews td.shift-afternoon {
  --shift-bg: #bfdbfe;
  --shift-bg-hot: #93c5fd;
  --shift-line: #60a5fa;
  --shift-line-hot: #2563eb;
}

.previews td.shift-evening {
  --shift-bg: #bbf7d0;
  --shift-bg-hot: #86efac;
  --shift-line: #4ade80;
  --shift-line-hot: #16a34a;
}

.previews td.rest {
  --shift-bg: var(--rest);
  --shift-bg-hot: #d4d4d4;
  --shift-line: #a3a3a3;
  --shift-line-hot: #737373;
}

.previews td:is(.shift-day, .shift-afternoon, .shift-evening, .rest) {
  background: var(--shift-bg);
}

.previews td:is(.shift-day, .shift-afternoon, .shift-evening).diff {
  background: color-mix(in srgb, var(--shift-bg) 50%, #fff7ed);
  box-shadow: inset 0 0 0 1.5px #fb923c;
}

.previews th.unmatched,
.previews td.unmatched {
  background: var(--warn-bg);
  box-shadow: inset 0 0 0 1.5px #fca5a5;
}

.tag-unknown,
.tag-source {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 3px;
  padding: 0 4px;
  vertical-align: middle;
}

.tag-unknown {
  margin-left: 4px;
  color: var(--err);
  background: var(--warn-bg);
  border: 1px solid #fca5a5;
}

.dept-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-cross {
  color: #4338ca;
  background: #e0e7ff;
  border: 1px dashed #818cf8;
}

.tag-floor {
  color: #0f766e;
  background: #ccfbf1;
  border: 1px solid #5eead4;
}

.tag-kitchen {
  color: #1d4ed8;
  background: #dbeafe;
  border: 1px solid #93c5fd;
}

.tag-steward {
  color: #9a3412;
  background: #ffedd5;
  border: 1px solid #fdba74;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}

.site-footer p {
  margin: 0;
}

@media (max-width: 720px) {
  .page {
    padding: 20px 12px 48px;
  }

  .uploads {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .view-panel {
    padding: 14px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .pick-row {
    flex-direction: column;
    align-items: stretch;
  }

  .roster-preview-head {
    flex-wrap: wrap;
  }

  .store-select-wrap {
    flex-basis: 100%;
  }

  .store-picker-host {
    max-width: none;
  }

  .preview-dl {
    margin-left: 0;
  }

  .pick-actions {
    justify-content: flex-end;
  }

  .file-row {
    grid-template-columns: 2.25rem minmax(0, 1fr);
  }

  .file-chips {
    grid-column: 2;
  }
}

/* hailam-punch-check */

.limit-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  padding: 0 20px 14px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.limit-field input {
  width: 4.5em;
  margin: 0 4px;
  padding: 3px 6px;
  font: inherit;
  color: var(--ink);
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.limit-field input:focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 1px;
}

.check-range {
  margin: -4px 0 12px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.grid-wrap {
  max-height: 560px;
}

#punch-grid {
  border-collapse: separate;
  border-spacing: 0;
}

#punch-grid th,
#punch-grid td {
  border-width: 0 1px 1px 0;
}

#punch-grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: center;
  background: var(--surface-2);
}

#punch-grid thead th small {
  display: block;
  font-size: 0.6875rem;
  color: var(--muted);
  font-weight: 400;
}

#punch-grid th.g-off {
  color: var(--line-strong);
}

#punch-grid tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  font-weight: 500;
  cursor: default;
}

#punch-grid tbody th small {
  display: block;
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--muted);
}

#punch-grid thead th:first-child {
  left: 0;
  z-index: 3;
}

/* A darker edge marks where the frozen header and name column end. */
#punch-grid thead th {
  border-bottom: 1px solid var(--line-strong);
}

#punch-grid th:first-child {
  border-right: 1px solid var(--line-strong);
}

#punch-grid tbody th.g-missing {
  color: var(--muted);
  text-decoration: line-through;
}

#punch-grid td.g-cell {
  min-width: 78px;
  padding: 4px 6px;
  text-align: center;
  line-height: 1.25;
}

#punch-grid .g-top,
#punch-grid .g-bottom {
  display: block;
}

#punch-grid .g-top {
  font-weight: 600;
}

#punch-grid .g-bottom {
  font-size: 0.6875rem;
  color: var(--muted);
  min-height: 1em;
}

#punch-grid td.g-rest {
  background: #f4f4f5;
}

#punch-grid td.g-off {
  background: #f8fafc;
  color: var(--line-strong);
}

#punch-grid td.g-off .g-bottom {
  color: var(--line-strong);
}

#punch-grid td.g-high,
.legend-high {
  background: #fee2e2;
  border-color: #fca5a5;
}

#punch-grid td.g-mid,
.legend-mid {
  background: #fef3c7;
  border-color: #fcd34d;
}

#punch-grid td.g-low,
.legend-low {
  background: #e0f2fe;
  border-color: #7dd3fc;
}

#punch-grid td.g-high,
#punch-grid td.g-mid,
#punch-grid td.g-low {
  border-color: var(--line);
  box-shadow: inset 0 0 0 2px var(--cell-frame);
}

#punch-grid td.g-high {
  --cell-frame: #fca5a5;
}

#punch-grid td.g-mid {
  --cell-frame: #fcd34d;
}

#punch-grid td.g-low {
  --cell-frame: #7dd3fc;
}

#punch-grid td.g-high .g-bottom {
  color: var(--err);
}

#punch-grid td.g-fill {
  outline: 2px dashed #16a34a;
  outline-offset: -3px;
}

#punch-grid td.g-fill .g-top {
  color: #15803d;
}

.legend-fill {
  border: 2px dashed #16a34a;
}

.legend-off {
  background: #f8fafc;
}

/* The jumped-to cell blinks three times, then fades back. */
#punch-grid .pulse {
  animation: cell-pulse 0.6s ease-in-out 6 alternate, cell-fade 2.4s ease-out 3.6s;
}

/* Lifts a day cell's glow over its neighbours; the frozen name cell keeps its own sticky stacking. */
#punch-grid td.pulse {
  position: relative;
  z-index: 1;
}

#fill-preview tr.fill-loose td {
  background: var(--warn-bg);
}

.uploads-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 720px) {
  .uploads-two {
    grid-template-columns: 1fr;
  }
}

#punch-grid td.preview-empty {
  padding: 12px;
  text-align: left;
  color: var(--muted);
}

/* Store picker on the 補鐘記錄 / 補排班 tabs: how much each store has to import. */
.status-badge.has-output {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.status-badge.is-none {
  color: var(--muted);
  background: var(--surface-2);
  border-color: var(--line);
}
