:root {
  --bg: #f5f2ed;
  --paper: #fffdf8;
  --surface: #ffffff;
  --surface-soft: #f8f6f1;
  --ink: #24211d;
  --muted: #6f675c;
  --line: #d8d0c3;
  --line-strong: #aa9e8d;
  --brand: #375f7f;
  --brand-dark: #24445e;
  --brand-soft: #e8f0f5;
  --ok: #2f6d4f;
  --danger: #a33c37;
  --warning: #8a6426;
  --shadow: 0 16px 42px rgba(60, 48, 32, 0.1);
  --radius: 8px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  background:
    linear-gradient(180deg, rgba(55, 95, 127, 0.08), rgba(55, 95, 127, 0) 320px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
}

button {
  cursor: pointer;
}

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

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 32px;
  line-height: 1.15;
}

.header-note {
  margin-bottom: 0;
  color: var(--muted);
}

.header-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto 42px;
}

.progress-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 10px;
}

.progress-card,
.save-state,
.section-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.progress-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
}

.step-index,
.section-heading > span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-weight: 800;
}

.progress-card strong {
  display: block;
  margin-bottom: 2px;
}

.progress-card p,
.section-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.save-state {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 14px;
}

.save-state.is-saved {
  color: var(--ok);
}

.form-surface {
  display: grid;
  gap: 18px;
}

.section-block {
  padding: 22px;
}

.section-heading {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin-bottom: 2px;
  font-size: 22px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  grid-column: span 4;
  min-width: 0;
}

.field.half {
  grid-column: span 6;
}

.field.third {
  grid-column: span 4;
}

.field span,
.choice-field legend,
.venue-fieldset legend,
.signature-card label {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.field small {
  color: var(--muted);
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(55, 95, 127, 0.12);
}

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

.date-range label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.date-range small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.choice-field,
.venue-fieldset {
  margin: 18px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

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

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

.choice-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  font-weight: 700;
}

.choice-pill input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand);
}

.other-venue-field {
  display: none;
  gap: 7px;
  margin-top: 12px;
}

.other-venue-field.is-visible {
  display: grid;
}

.other-venue-field span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.item-list {
  display: grid;
  gap: 12px;
}

.handover-item {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 14px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}

.item-main {
  display: grid;
  gap: 8px;
  align-content: start;
}

.item-title {
  margin: 0;
  font-weight: 800;
}

.item-controls {
  display: grid;
  gap: 10px;
  min-width: 0;
}

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

.segmented label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  color: var(--ink);
  background: var(--surface-soft);
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented label.is-selected {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.quantity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 8px;
  align-items: center;
}

.quantity-row span {
  color: var(--muted);
  font-weight: 800;
}

.note-field textarea {
  min-height: 68px;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.signature-grid-single {
  grid-template-columns: minmax(0, 1fr);
}

.signature-card {
  display: grid;
  gap: 10px;
}

.signature-pad {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}

.signature-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  touch-action: none;
}

.preview-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
}

.preview-empty {
  color: var(--muted);
  font-weight: 700;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
}

.preview-grid div {
  display: grid;
  gap: 2px;
}

.preview-grid strong {
  color: var(--muted);
  font-size: 13px;
}

.primary-button,
.secondary-button,
.ghost-button,
.mini-button {
  min-height: 44px;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--brand);
  color: #fff;
  background: var(--brand);
}

.secondary-button,
.ghost-button,
.mini-button {
  border: 1px solid var(--line-strong);
  color: var(--brand-dark);
  background: #fff;
}

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

.mini-button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.submit-status {
  margin-top: 12px;
  color: var(--muted);
  font-weight: 700;
}

.submit-status a {
  color: var(--brand-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.submit-status.is-success {
  color: var(--ok);
}

.submit-status.is-error {
  color: var(--danger);
}

.print-document {
  display: none;
}

@media screen {
  body.is-print-preview-open .print-document {
    grid-column: 1 / -1;
    display: block;
    width: min(900px, 100%);
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    background: #fff;
    box-shadow: var(--shadow);
  }

  .print-preview-toolbar {
    display: none;
  }

  body.is-print-preview-open .print-preview-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 14px;
  }

  body.is-print-preview-open .print-header {
    margin-bottom: 10px;
    text-align: center;
  }

  body.is-print-preview-open .print-header p {
    margin-bottom: 4px;
    color: var(--muted);
    font-weight: 800;
  }

  body.is-print-preview-open .print-header h2 {
    margin-bottom: 0;
    font-size: 24px;
  }

  body.is-print-preview-open .print-summary,
  body.is-print-preview-open .print-record-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }

  body.is-print-preview-open .print-summary {
    margin-bottom: 12px;
  }

  body.is-print-preview-open .print-summary th,
  body.is-print-preview-open .print-summary td,
  body.is-print-preview-open .print-record-table th,
  body.is-print-preview-open .print-record-table td {
    border: 1px solid #1f1f1f;
    padding: 7px 8px;
    vertical-align: top;
    word-break: break-word;
  }

  body.is-print-preview-open .print-summary th,
  body.is-print-preview-open .print-record-table th {
    background: #f2f2f2;
    font-weight: 800;
    text-align: center;
  }

  body.is-print-preview-open .print-summary th {
    width: 14%;
  }

  body.is-print-preview-open .print-summary td {
    width: 36%;
  }

  body.is-print-preview-open .print-table-group {
    margin-top: 14px;
  }

  body.is-print-preview-open .print-table-group h3 {
    margin: 0;
    border: 1px solid #1f1f1f;
    border-bottom: 0;
    padding: 7px 8px;
    text-align: center;
    font-size: 16px;
  }

  body.is-print-preview-open .print-record-table th:first-child,
  body.is-print-preview-open .print-record-table td:first-child {
    width: 50%;
  }

  body.is-print-preview-open .print-record-table th:nth-child(2),
  body.is-print-preview-open .print-record-table td:nth-child(2) {
    width: 22%;
    text-align: center;
  }

  body.is-print-preview-open .print-record-table th:nth-child(3),
  body.is-print-preview-open .print-record-table td:nth-child(3) {
    width: 28%;
  }

  body.is-print-preview-open .print-signatures {
    margin-top: 16px;
    border: 1px solid #1f1f1f;
  }

  body.is-print-preview-open .print-sign-box {
    min-height: 110px;
    padding: 10px;
    text-align: center;
  }

  body.is-print-preview-open .print-signature-image {
    display: grid;
    place-items: center;
    min-height: 64px;
    margin: 6px 0;
  }

  body.is-print-preview-open .print-signature-image img {
    max-width: 100%;
    max-height: 72px;
    object-fit: contain;
  }

  body.is-print-preview-open .print-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 12px;
  }
}

@media screen and (max-width: 980px) {
  .app-header,
  .app-shell {
    width: min(100% - 24px, 780px);
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .progress-panel {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .save-state {
    grid-column: 1 / -1;
  }

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

  .date-field {
    grid-column: span 6;
  }

  .date-range-field {
    grid-column: 1 / -1;
  }
}

@media screen and (max-width: 720px) {
  body {
    font-size: 15px;
  }

  .app-header {
    display: grid;
    gap: 14px;
    padding-top: 18px;
  }

  h1 {
    font-size: 27px;
  }

  .progress-panel {
    display: none;
  }

  .section-block {
    padding: 16px;
  }

  .field,
  .field.half,
  .field.third {
    grid-column: 1 / -1;
  }

  .choice-grid,
  .date-range,
  .signature-grid,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .handover-item {
    grid-template-columns: 1fr;
  }

  .segmented label {
    min-height: 48px;
  }

  .action-row,
  .header-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  body.is-print-preview-open .print-document {
    padding: 12px;
    overflow-x: auto;
  }

  body.is-print-preview-open .print-preview-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  body.is-print-preview-open .print-summary,
  body.is-print-preview-open .print-record-table {
    min-width: 620px;
  }
}
