:root {
  --ink: #18222d;
  --muted: #637083;
  --line: #d7e0e9;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --brand: #176b87;
  --brand-dark: #11566c;
  --soft: #e9f5f7;
  --ok: #2f855a;
  --warn: #b7791f;
  --bad: #c53030;
  --disabled: #8a94a3;
  --shadow: 0 8px 22px rgba(24, 34, 45, .07);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

header {
  background: linear-gradient(90deg, #f9fbfc 0%, #e7f3f5 48%, #f7faf2 100%);
  border-bottom: 1px solid var(--line);
}

.shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 4px;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
}

.subtitle,
.hint,
.note {
  color: var(--muted);
}

.subtitle {
  margin-bottom: 0;
  font-size: 14px;
}

.hint,
.note {
  margin-bottom: 0;
  font-size: 13px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #ffffff;
  background: var(--brand);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--brand-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

button.secondary {
  color: var(--brand);
  background: #ffffff;
  border-color: #94c8d2;
}

button.secondary:hover,
button.neutral:hover,
.tab-button.neutral:hover {
  background: #eef6f8;
}

button.neutral,
.tab-button.neutral {
  color: var(--ink);
  background: #eef2f6;
  border-color: var(--line);
}

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

button.danger:hover {
  background: #a62222;
}

.link-button {
  min-height: auto;
  padding: 4px 0;
  color: var(--brand);
  background: transparent;
  border: 0;
}

.link-button:hover {
  color: var(--brand-dark);
  background: transparent;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid #c6d2dd;
  border-radius: 6px;
}

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

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
}

main {
  padding: 20px 0 42px;
}

.hidden {
  display: none !important;
}

.auth-wrap {
  width: min(520px, calc(100% - 32px));
  margin: 34px auto;
}

.panel,
.auth-card,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-card {
  overflow: hidden;
}

.stack {
  display: grid;
  gap: 14px;
  padding: 16px 18px 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.section-head.compact {
  padding: 16px 18px 10px;
  border-bottom: 0;
}

.actions,
.user-tools,
.auth-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.auth-links {
  justify-content: space-between;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab-button[aria-selected="true"] {
  color: #ffffff;
  background: var(--brand);
  border-color: var(--brand);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 92px;
  padding: 14px;
}

.metric span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 30px;
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
  gap: 18px;
  align-items: start;
}

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

.choice-field {
  display: grid;
  gap: 8px;
}

.choice-label {
  font-size: 14px;
  font-weight: 900;
}

.option-grid {
  display: grid;
  gap: 8px;
}

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

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

.option-button {
  width: 100%;
  min-height: 46px;
  padding: 9px 10px;
  color: var(--ink);
  background: #ffffff;
  border-color: #b8c7d5;
  white-space: normal;
}

.option-button:hover {
  background: #f4f8fb;
}

.option-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--brand);
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(23, 107, 135, .15);
}

.missing-photo-alert {
  padding: 10px 12px;
  color: var(--bad);
  background: #fde8e8;
  border: 1px solid #f3b5b5;
  border-radius: 6px;
  font-weight: 800;
}

.checklist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #f7fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.checklist {
  display: grid;
  gap: 10px;
}

.empty-state {
  padding: 22px 16px;
  color: var(--muted);
  text-align: center;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
}

.item-card {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(260px, 1.4fr);
  gap: 10px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.item-title {
  display: grid;
  gap: 5px;
  align-content: start;
  min-width: 0;
}

.item-name {
  font-size: 15px;
  font-weight: 900;
  word-break: break-word;
}

.item-section {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.item-controls {
  display: grid;
  gap: 8px;
}

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

.status-button {
  width: 100%;
  min-height: 36px;
  padding: 6px;
  color: var(--ink);
  background: #ffffff;
  border-color: #b9c6d4;
  font-size: 13px;
  white-space: normal;
}

.status-button:hover {
  background: #f4f8fb;
}

.status-button[aria-pressed="true"] {
  color: #ffffff;
}

.status-button[data-status="正常"][aria-pressed="true"] {
  background: var(--ok);
  border-color: var(--ok);
}

.status-button[data-status="需改善"][aria-pressed="true"] {
  background: var(--warn);
  border-color: var(--warn);
}

.status-button[data-status="異常"][aria-pressed="true"] {
  background: var(--bad);
  border-color: var(--bad);
}

.status-button[data-status="未檢"][aria-pressed="true"] {
  background: var(--disabled);
  border-color: var(--disabled);
}

.photo-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.photo-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 11px;
  overflow: hidden;
  color: #ffffff;
  background: var(--brand);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.photo-label input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  opacity: .001;
  cursor: pointer;
}

.photo-preview {
  width: 72px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.empty-preview {
  background:
    linear-gradient(135deg, transparent 48%, #d7e0e9 49%, #d7e0e9 51%, transparent 52%),
    #f8fafc;
}

.photo-required {
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  background: #e5f3eb;
}

.badge.warn {
  color: var(--warn);
  background: #fff3d9;
}

.badge.bad {
  color: var(--bad);
  background: #fde8e8;
}

.badge.neutral {
  color: var(--ink);
  background: #eef2f6;
}

.record-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.record-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.record-card strong {
  font-size: 15px;
}

.record-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.record-meta {
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: grid;
  grid-template-columns: 1.35fr repeat(5, minmax(120px, 1fr));
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.table-wrap {
  max-height: 690px;
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #44566b;
  background: #f8fafc;
}

.summary-list {
  display: grid;
  gap: 4px;
  min-width: 260px;
}

.thumb-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 220px;
}

.thumb {
  width: 56px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.empty {
  padding: 30px 18px;
  color: var(--muted);
  text-align: center;
}

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

.reference-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.reference-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.image-fallback {
  display: none;
  margin: 0;
  color: var(--bad);
  font-weight: 800;
}

.reference-card.image-error .image-fallback {
  display: block;
}

.admin-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 18px 18px;
}

.user-form {
  padding: 0;
}

.user-list {
  display: grid;
  gap: 10px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(120px, 1.1fr) minmax(120px, 1.1fr) minmax(130px, 1fr) 120px 100px auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.editable-user-row label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.editable-user-row input,
.editable-user-row select {
  min-height: 38px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.user-actions {
  justify-content: end;
}

.print-area {
  display: none;
}

@media (max-width: 1060px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

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

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

  main {
    padding: 14px 0 30px;
  }

  .shell {
    width: min(100% - 16px, 1240px);
  }

  .topbar,
  .section-head,
  .checklist-head {
    align-items: stretch;
    flex-direction: column;
  }

  .user-tools,
  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .user-tools .badge {
    min-height: 40px;
  }

  button {
    width: 100%;
  }

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

  .metrics,
  .field-grid,
  .filters,
  .reference-grid,
  .admin-layout,
  .item-card,
  .photo-line {
    grid-template-columns: 1fr;
  }

  .template-options,
  .area-options {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 80px;
  }

  .stack,
  .section-head,
  .record-list,
  .filters,
  .reference-grid,
  .admin-layout {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .photo-preview {
    width: 100%;
    max-width: 160px;
  }

  .user-row {
    grid-template-columns: 1fr;
  }
}

@media print {
  body > :not(.print-area) {
    display: none !important;
  }

  .print-area {
    display: block;
    color: #000000;
    background: #ffffff;
    font-family: "Microsoft JhengHei", Arial, sans-serif;
  }

  .print-sheet {
    page-break-after: always;
    padding: 18mm 14mm;
  }

  .print-sheet:last-child {
    page-break-after: auto;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #333333;
    padding: 6px;
    font-size: 12px;
  }

  .print-photos {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 10px;
  }

  .print-photo {
    display: grid;
    gap: 4px;
    break-inside: avoid;
  }

  .print-photo img {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    border: 1px solid #333333;
  }
}
