:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --ink: #1d2528;
  --muted: #63706c;
  --line: #d7dfda;
  --green: #1d7a5f;
  --green-dark: #105c47;
  --blue: #2f6fa3;
  --amber: #b7791f;
  --red: #b33a2c;
  --slate: #40515a;
  --shadow: 0 14px 32px rgba(29, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 18px 18px 92px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(29, 122, 95, 0.28);
  border-radius: 8px;
  background: #e6f2ec;
  color: var(--green-dark);
  font-weight: 900;
}

.brand p,
.item-meta,
.checklist-head p,
.source-chip span,
.bottom-bar span,
.kpi-card span,
.kpi-card small,
.panel-head span,
.regulation {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  font-size: 18px;
  line-height: 1.45;
}

.source-chip {
  min-width: 280px;
  max-width: 460px;
  display: grid;
  justify-items: end;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.source-chip span,
.item-meta span,
.standard,
.regulation,
.equipment-row strong,
.abnormal-row strong {
  overflow-wrap: anywhere;
}

.source-chip strong {
  color: var(--blue);
}

.control-strip,
.kpi-grid,
.workspace {
  display: grid;
  gap: 12px;
}

.control-strip {
  grid-template-columns: 138px 150px minmax(150px, 180px) 120px 120px minmax(190px, 1fr);
  align-items: end;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

label {
  display: grid;
  gap: 6px;
  color: var(--slate);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 10px;
}

textarea {
  min-height: 74px;
  padding: 9px 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(47, 111, 163, 0.72);
  box-shadow: 0 0 0 3px rgba(47, 111, 163, 0.13);
}

.kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.kpi-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 6px solid var(--blue);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card strong {
  font-size: 34px;
  line-height: 1;
}

.kpi-card.good {
  border-left-color: var(--green);
}

.kpi-card.danger {
  border-left-color: var(--red);
}

.kpi-card.warn {
  border-left-color: var(--amber);
}

.workspace {
  grid-template-columns: 260px minmax(0, 1fr) 340px;
  align-items: start;
}

.filter-panel,
.checklist-panel,
.insight-panel > section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.filter-panel {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.panel-head,
.checklist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 21px;
}

.secondary-button {
  padding: 0 12px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.secondary-button:hover,
.icon-button:hover,
.ghost-button:hover {
  border-color: rgba(47, 111, 163, 0.45);
  background: #f7faf8;
}

#markVisibleNormal {
  width: 100%;
  background: #eef7f2;
  color: var(--green-dark);
}

.checklist-panel {
  min-width: 0;
  overflow: hidden;
}

.checklist-head {
  min-height: 72px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.view-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

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

.inspection-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 360px);
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.inspection-card.is-abnormal {
  border-left: 6px solid var(--red);
}

.inspection-card.is-normal {
  border-left: 6px solid var(--green);
}

.inspection-card.is-na {
  border-left: 6px solid var(--slate);
}

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

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.item-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--slate);
}

.standard {
  margin: 0;
  color: var(--ink);
}

.regulation {
  min-height: 20px;
}

.history-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 18px;
}

.history-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(64, 81, 90, 0.24);
  background: #d7dfda;
}

.history-dot.normal {
  background: var(--green);
}

.history-dot.abnormal {
  background: var(--red);
}

.history-dot.na {
  background: var(--slate);
}

.history-dot.pending {
  background: #eef1ef;
}

.item-entry {
  display: grid;
  align-content: start;
  gap: 10px;
}

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

.status-grid button {
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.status-grid button.is-selected[data-status="normal"] {
  border-color: rgba(29, 122, 95, 0.55);
  background: #e6f4ee;
  color: var(--green-dark);
}

.status-grid button.is-selected[data-status="abnormal"] {
  border-color: rgba(179, 58, 44, 0.55);
  background: #fff0ee;
  color: var(--red);
}

.status-grid button.is-selected[data-status="na"] {
  border-color: rgba(64, 81, 90, 0.45);
  background: #edf1f2;
  color: var(--slate);
}

.status-grid button.is-selected[data-status="pending"] {
  border-color: rgba(183, 121, 31, 0.58);
  background: #fff7e8;
  color: #87530c;
}

.action-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 138px;
  gap: 8px;
}

.action-fields[hidden] {
  display: none;
}

.insight-panel {
  display: grid;
  gap: 12px;
}

.insight-panel > section {
  padding: 12px;
}

.floor-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
}

.equipment-list,
.abnormal-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.equipment-row,
.abnormal-row,
.empty-state {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

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

.equipment-row strong,
.abnormal-row strong {
  display: block;
  line-height: 1.35;
}

.equipment-row small,
.abnormal-row small,
.empty-state {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.equipment-row button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(47, 111, 163, 0.36);
  border-radius: 8px;
  background: #eef5fb;
  color: var(--blue);
  cursor: pointer;
  font-weight: 900;
}

.abnormal-row {
  display: grid;
  gap: 5px;
  border-left: 5px solid var(--red);
}

.empty-state {
  text-align: center;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 68px;
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.bottom-summary {
  width: min(720px, 55vw);
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.bottom-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bottom-bar strong {
  color: var(--green-dark);
  font-size: 22px;
}

.ghost-button {
  padding: 0 12px;
  color: var(--red);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .insight-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px 10px 112px;
  }

  .app-header,
  .control-strip,
  .workspace,
  .insight-panel {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .source-chip {
    min-width: 0;
    max-width: none;
    justify-items: start;
  }

  .control-strip {
    padding: 10px;
  }

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

  .filter-panel {
    position: static;
  }

  .inspection-card {
    grid-template-columns: 1fr;
  }

  .checklist-head {
    align-items: start;
    flex-direction: column;
  }

  .view-actions {
    width: 100%;
    justify-content: stretch;
  }

  .view-actions button {
    flex: 1 1 130px;
  }

  .bottom-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .bottom-summary,
  .bottom-actions,
  .bottom-actions button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 17px;
  }

  h1 {
    font-size: 23px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

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

  .kpi-card {
    min-height: 94px;
  }

  .status-grid,
  .action-fields {
    grid-template-columns: 1fr;
  }
}

/* Simple field layout */
.app-shell {
  width: min(1180px, 100%);
}

.app-header {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.brand-mark {
  width: 44px;
  height: 44px;
  font-size: 14px;
}

h1 {
  font-size: 23px;
}

.source-chip {
  min-width: 220px;
  max-width: 360px;
  padding: 0;
  border: 0;
  background: transparent;
}

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

.flow-steps a {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--slate);
  text-decoration: none;
  font-weight: 900;
}

.flow-steps span,
.step-title span {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--slate);
  font-size: 13px;
  font-weight: 900;
  flex: 0 0 auto;
}

.flow-steps a.is-current {
  border-color: rgba(47, 111, 163, 0.44);
  background: #eef5fb;
  color: var(--blue);
}

.flow-steps a.is-complete span {
  background: var(--green);
  color: #fff;
}

.step-card {
  scroll-margin-top: 14px;
}

.step-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.control-strip {
  grid-template-columns: 138px 150px minmax(150px, 180px) 120px 120px minmax(190px, 1fr);
}

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

.kpi-card {
  min-height: 78px;
  box-shadow: none;
  border-left-width: 4px;
}

.kpi-card strong {
  font-size: 26px;
}

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

.filter-panel {
  position: static;
  grid-template-columns: auto repeat(6, minmax(0, 1fr)) auto;
  align-items: end;
}

.filter-panel .panel-head {
  align-self: stretch;
}

.filter-panel .panel-head h2 {
  display: block;
}

#markVisibleNormal {
  min-width: 148px;
}

.checklist-panel {
  overflow: visible;
}

.item-list {
  gap: 8px;
  padding: 10px;
}

.inspection-card {
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 12px;
  padding: 12px;
  box-shadow: none;
}

.inspection-card.is-abnormal,
.inspection-card.is-normal,
.inspection-card.is-na {
  border-left-width: 4px;
}

.item-meta {
  gap: 5px;
}

.item-meta span {
  min-height: 22px;
  padding: 1px 7px;
  border-radius: 8px;
}

.history-strip,
.regulation {
  display: none;
}

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

.status-grid button {
  min-height: 40px;
  padding: 0 4px;
  font-size: 14px;
}

textarea {
  min-height: 58px;
}

.insight-panel {
  grid-template-columns: 1fr;
}

.insight-panel .floor-panel,
.insight-panel > section:nth-child(2) {
  display: none;
}

.insight-panel > section {
  box-shadow: none;
}

.bottom-bar {
  min-height: 58px;
}

.upload-section,
.export-section {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

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

.upload-box {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.upload-head,
.export-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.upload-head h3 {
  font-size: 16px;
}

.upload-head small,
.export-actions small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.photo-upload {
  min-height: 74px;
  place-items: center;
  gap: 2px;
  border: 1px dashed rgba(29, 122, 95, 0.55);
  border-radius: 8px;
  background: #eef7f2;
  color: var(--green-dark);
  cursor: pointer;
  text-align: center;
}

.photo-upload span {
  color: var(--muted);
  font-size: 13px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  min-height: 0;
}

.photo-thumb {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.photo-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.photo-thumb button {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--red);
  cursor: pointer;
  font-weight: 800;
}

#signaturePad {
  width: 100%;
  height: 178px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

.primary-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 900;
}

.export-actions {
  justify-content: flex-start;
}

.export-actions > div {
  min-width: min(360px, 100%);
  margin-right: auto;
}

.cloud-storage {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid rgba(47, 111, 163, 0.24);
  border-radius: 8px;
  background: #eef5fb;
}

.cloud-storage strong {
  color: var(--blue);
}

.cloud-storage a {
  color: var(--green-dark);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.cloud-storage small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.submission-status {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.submission-status strong {
  color: var(--green-dark);
}

.submission-status small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 980px) {
  .control-strip,
  .filter-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-panel .panel-head {
    grid-column: auto;
  }

  #markVisibleNormal {
    min-width: 0;
  }

  .inspection-card {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 640px) {
  .app-shell {
    padding: 10px 10px 106px;
  }

  .app-header,
  .control-strip,
  .filter-panel {
    grid-template-columns: 1fr;
  }

  .flow-steps {
    grid-template-columns: 1fr;
  }

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

  .source-chip {
    min-width: 0;
    max-width: none;
    justify-items: start;
  }

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

  .upload-head,
  .export-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .export-actions > div {
    margin-right: 0;
  }

  .bottom-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .bottom-summary,
  .bottom-actions,
  .bottom-actions button {
    width: 100%;
  }
}
