:root {
  --bg: #f3efe7;
  --panel: rgba(255, 252, 246, 0.94);
  --panel-strong: #ffffff;
  --ink: #1f2933;
  --muted: #60716b;
  --line: #cfd7d2;
  --line-strong: #7f8c86;
  --accent: #2c6b59;
  --accent-soft: #e3f1ec;
  --accent-strong: #19493d;
  --danger: #b84d4d;
  --danger-soft: #f9e7e7;
  --gray-soft: #edf0f2;
  --blue-soft: #e9f3fb;
  --row-stripe-soft: #fffdf8;
  --line-divider-soft: rgba(31, 41, 51, 0.16);
  --shadow: 0 24px 60px rgba(35, 52, 45, 0.12);
  --name-font-scale: 1.24;
  --content-font-scale: 1.12;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(44, 107, 89, 0.11), transparent 32%),
    linear-gradient(180deg, #faf7f1 0%, var(--bg) 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(123, 143, 136, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123, 143, 136, 0.06) 1px, transparent 1px);
  background-size: 24px 24px;
  content: "";
  pointer-events: none;
}

.app-shell {
  width: min(1600px, calc(100vw - 12px));
  margin: 8px auto;
}

.toolbar,
.panel {
  padding: 18px;
  border: 1px solid rgba(127, 140, 134, 0.2);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 2vw, 2.3rem);
  letter-spacing: 0.04em;
}

.hero p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.55;
}

.status-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
.picker-manual label,
.picker-block h4 {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.field input,
.field select,
.table-input,
.picker-manual input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid rgba(127, 140, 134, 0.26);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font: inherit;
}

.field input:focus,
.field select:focus,
.picker-manual input:focus {
  outline: 2px solid rgba(44, 107, 89, 0.24);
  border-color: rgba(44, 107, 89, 0.48);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

button {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button.primary {
  background: var(--accent);
  color: #fff;
}

button.secondary {
  background: #edf2ef;
  color: var(--ink);
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.advanced-tools {
  margin-top: 12px;
  border: 1px solid rgba(127, 140, 134, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.advanced-tools summary {
  padding: 12px 14px;
  list-style: none;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 700;
}

.advanced-tools summary::-webkit-details-marker {
  display: none;
}

.advanced-body {
  padding: 0 14px 14px;
  border-top: 1px solid rgba(127, 140, 134, 0.14);
}

.advanced-body p,
.tap-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.advanced-body code {
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(44, 107, 89, 0.08);
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 700;
}

.advanced-actions {
  margin-top: 12px;
}

.tap-hint {
  margin-top: 14px;
}

.workspace {
  margin-top: 18px;
}

.sheet-panel {
  overflow: hidden;
}

.print-head {
  margin-bottom: 10px;
}

.print-head h2 {
  margin: 0;
  font-size: 1.26rem;
}

.table-shell {
  overflow: auto;
  border-radius: 22px;
  border: 1px solid rgba(127, 140, 134, 0.16);
  background: rgba(255, 255, 255, 0.76);
}

table {
  width: 100%;
  min-width: 1440px;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
}

th,
td {
  border: 1px solid var(--line-strong);
}

th {
  background: #f7f9f7;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
}

.month-head {
  width: 76px;
  min-width: 76px;
  background: #fffaf1;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.blank-head {
  width: 44px;
  min-width: 44px;
  background: #fff;
}

.section-cell {
  width: 44px;
  min-width: 44px;
  background: #eef4f1;
  font-size: 0.96rem;
  font-weight: 800;
  text-align: center;
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.18em;
}

.label-head,
.label-cell {
  width: 126px;
  min-width: 126px;
}

.label-head {
  padding: 0 12px;
  font-size: 0.92rem;
  text-align: right;
}

.label-cell {
  background: #fff;
}

.table-input {
  min-height: 38px;
  padding: 6px 8px;
  border: none;
  border-radius: 0;
  background: transparent;
  text-align: center;
  box-shadow: none;
  font-family: "BiauKai", "DFKai-SB", "KaiTi", "Noto Sans TC", serif;
  font-size: 0.98rem;
  line-height: 1.08;
}

.table-input:focus {
  outline: none;
}

.table-input[readonly] {
  cursor: pointer;
}

.label-input {
  font-size: calc(1.06rem * var(--name-font-scale));
  text-align: left;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.day-cell .table-input {
  font-size: calc(1.1rem * var(--content-font-scale));
  letter-spacing: 0.02em;
}

.day-cell {
  background: #fff;
}

tr.is-even-row .label-cell,
tr.is-even-row .day-cell {
  background: var(--row-stripe-soft);
}

.day-head.is-five-divider,
.weekday-head.is-five-divider,
.day-cell.is-five-divider {
  box-shadow: inset -1px 0 0 var(--line-divider-soft);
}

.day-cell.is-selected-day,
.day-head.is-selected-day,
.weekday-head.is-selected-day {
  background: var(--accent-soft);
}

.day-head.is-sunday,
.weekday-head.is-sunday {
  color: #a22a2a;
}

.day-head.is-saturday,
.weekday-head.is-saturday {
  color: #2f5b9c;
}

.day-head.is-outside-month,
.weekday-head.is-outside-month,
.day-cell.is-outside-month {
  background: #f1f3f2;
  color: #95a19b;
}

.table-input.bg-gray {
  background: var(--gray-soft);
}

.table-input.bg-blue {
  background: var(--blue-soft);
}

.mark-off {
  color: #475e91;
  font-size: calc(1rem * var(--content-font-scale));
}

.mark-off-red {
  color: #ba4b4b;
  font-size: calc(1rem * var(--content-font-scale));
  font-weight: 800;
}

.mark-hours {
  color: #6a645d;
  font-size: calc(0.98rem * var(--content-font-scale));
}

.mark-dot {
  color: #a02f2f;
  font-size: calc(1.35rem * var(--content-font-scale));
  font-weight: 800;
}

.mark-circle {
  color: #746b64;
  font-size: calc(1.2rem * var(--content-font-scale));
}

.mark-check {
  color: #2c6b59;
  font-size: calc(1.18rem * var(--content-font-scale));
}

.mark-cross {
  color: #675a52;
  font-size: calc(1.2rem * var(--content-font-scale));
  font-weight: 800;
}

.picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(27, 32, 30, 0.34);
  backdrop-filter: blur(4px);
}

.picker-sheet {
  position: fixed;
  top: 60px;
  left: 50%;
  z-index: 80;
  width: min(calc(100vw - 24px), 620px);
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 10px 16px 18px;
  border-radius: 24px;
  border: 1px solid rgba(127, 140, 134, 0.24);
  background: rgba(255, 251, 244, 0.98);
  box-shadow: 0 24px 60px rgba(35, 52, 45, 0.2);
  transform: translateX(-50%);
}

.picker-handle {
  width: 56px;
  height: 5px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: rgba(127, 140, 134, 0.4);
}

.picker-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.picker-head h3 {
  margin: 0;
  font-size: 1.08rem;
}

.picker-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.picker-close {
  white-space: nowrap;
}

.picker-block + .picker-block {
  margin-top: 14px;
}

.picker-block h4 {
  margin: 0 0 8px;
}

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

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

.preset-chip,
.color-chip {
  min-height: 50px;
  border: 1px solid rgba(127, 140, 134, 0.22);
  border-radius: 14px;
  background: #f4f7f5;
  color: var(--ink);
}

.preset-chip {
  padding: 10px 8px;
  font-family: "BiauKai", "DFKai-SB", "KaiTi", "Noto Sans TC", serif;
  font-size: 1.06rem;
  line-height: 1;
}

.preset-chip.mark-dot {
  font-size: 1.45rem;
}

.preset-chip.mark-off-red {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

.preset-chip.is-clear {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 0.92rem;
}

.preset-chip.is-active,
.color-chip.is-active {
  border-color: rgba(44, 107, 89, 0.56);
  box-shadow: inset 0 0 0 2px rgba(44, 107, 89, 0.12);
}

.color-chip {
  padding: 10px 12px;
  font-size: 0.92rem;
}

.color-chip.bg-gray {
  background: var(--gray-soft);
}

.color-chip.bg-blue {
  background: var(--blue-soft);
}

.picker-manual {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(127, 140, 134, 0.18);
}

.picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

body.picker-open {
  overflow: hidden;
}

.group-separator th {
  border-top-width: 3px;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100vw - 16px, 100%);
    margin: 8px auto;
  }

  .toolbar,
  .panel {
    padding: 16px;
    border-radius: 22px;
  }

  .hero h1 {
    font-size: 1.56rem;
  }

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

@media (max-width: 640px) {
  .picker-sheet {
    top: 44px;
    width: min(calc(100vw - 16px), 100%);
    max-height: calc(100vh - 64px);
    padding: 10px 14px 18px;
    border-radius: 22px;
  }

  .picker-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .picker-color-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

@page {
  size: A4 landscape;
  margin: 1.5mm 2mm;
}

@media print {
  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body::before,
  .toolbar,
  .picker-backdrop,
  .picker-sheet,
  .screen-only {
    display: none !important;
  }

  .app-shell,
  .workspace {
    width: auto;
    margin: 0;
  }

  .panel,
  .table-shell {
    padding: 0;
    border: none;
    border-radius: 0;
    background: #fff;
    box-shadow: none;
    overflow: visible;
  }

  .print-head {
    margin-bottom: 1mm;
  }

  .print-head h2 {
    font-size: 12pt;
  }

  table {
    min-width: 0;
  }

  th {
    font-size: 7pt;
  }

  .month-head {
    width: 60px;
    min-width: 60px;
    font-size: 11pt;
  }

  .label-head,
  .section-cell {
    font-size: 7.2pt;
  }

  .blank-head,
  .section-cell {
    width: 30px;
    min-width: 30px;
  }

  .label-head,
  .label-cell {
    width: 86px;
    min-width: 86px;
  }

  .table-input {
    min-height: 19px;
    padding: 1px 2px;
    font-size: 7.4pt;
  }

  .label-input {
    font-size: calc(8pt * var(--name-font-scale));
  }

  .day-cell .table-input {
    font-size: calc(8.2pt * var(--content-font-scale));
  }

  .day-cell.is-selected-day,
  .day-head.is-selected-day,
  .weekday-head.is-selected-day {
    background: transparent !important;
  }
}
