:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f2;
  --ink: #1f2428;
  --muted: #64707a;
  --line: #d8dee4;
  --accent: #126b61;
  --accent-2: #1d4f91;
  --warn: #b26200;
  --bad: #b42318;
  --good: #1f7a4d;
  --shadow: 0 14px 40px rgba(24, 33, 45, 0.1);
  color-scheme: light;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.svg-sprite {
  display: none;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px clamp(16px, 4vw, 40px);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.brand-mark {
  background:
    linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  display: inline-block;
  flex: 0 0 38px;
  height: 38px;
  position: relative;
  width: 38px;
}

.brand-mark::after {
  border: 2px solid #fff;
  border-left: 0;
  border-top: 0;
  content: "";
  height: 17px;
  left: 13px;
  position: absolute;
  top: 7px;
  transform: rotate(42deg);
  width: 8px;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
  margin: 0;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

.top-actions,
.item-toolbar {
  align-items: end;
  display: flex;
  gap: 8px;
}

.tool-button,
.icon-button {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: inline-flex;
  font-weight: 700;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.tool-button:hover,
.icon-button:hover {
  background: var(--surface-2);
  border-color: #bcc7cf;
}

.tool-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.tool-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.tool-button.primary:hover {
  background: #0d5b52;
  border-color: #0d5b52;
}

.icon-button {
  justify-content: center;
  padding: 0;
  width: 42px;
}

.danger {
  color: var(--bad);
}

.tool-button svg,
.icon-button svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(420px, 1.08fr) minmax(360px, 0.92fr);
  margin: 0 auto;
  max-width: 1440px;
  padding: 18px clamp(16px, 4vw, 40px) 40px;
}

.work-panel,
.report-pane {
  min-width: 0;
}

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

.tabs {
  background: #f9fafb;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 800;
  min-height: 48px;
}

.tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}

.panel {
  display: none;
  padding: 18px;
}

.panel.active {
  display: block;
}

.field-group {
  margin-bottom: 18px;
}

.field-group > label,
.field span,
.check-field span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 7px;
}

.segmented {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  padding: 3px;
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  min-height: 38px;
}

.segmented button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 8px rgba(25, 37, 45, 0.08);
}

.form-grid {
  display: grid;
  gap: 14px;
}

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

.span-two {
  grid-column: 1 / -1;
}

.field {
  min-width: 0;
}

.field input,
.field textarea,
.condition-card select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  outline: none;
  padding: 9px 11px;
  width: 100%;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.condition-card select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 107, 97, 0.12);
}

.reading-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.item-toolbar {
  align-items: end;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 12px;
}

.field.compact span {
  margin-bottom: 5px;
}

.field.compact input {
  min-height: 38px;
}

.grow {
  flex: 1;
}

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

.condition-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(120px, 0.72fr) minmax(150px, 0.88fr) minmax(120px, 0.65fr);
  padding: 12px;
}

.condition-card header {
  min-width: 0;
}

.condition-card h3 {
  font-size: 16px;
  line-height: 1.35;
  margin: 0;
}

.condition-card small {
  color: var(--muted);
  display: block;
  font-weight: 800;
  margin-bottom: 4px;
}

.condition-main {
  display: grid;
  gap: 8px;
}

.condition-actions {
  align-content: start;
  display: grid;
  gap: 8px;
}

.upload-button {
  align-items: center;
  border: 1px dashed #aeb8c2;
  border-radius: 8px;
  color: var(--accent-2);
  display: inline-flex;
  font-weight: 800;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 0 10px;
}

.upload-button svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.upload-button input {
  display: none;
}

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

.photo-chip {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.photo-chip img {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.photo-chip button {
  align-items: center;
  background: rgba(31, 36, 40, 0.82);
  border: 0;
  border-radius: 999px;
  color: #fff;
  display: flex;
  height: 24px;
  justify-content: center;
  padding: 0;
  position: absolute;
  right: 5px;
  top: 5px;
  width: 24px;
}

.photo-chip svg {
  fill: none;
  height: 14px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 14px;
}

.check-field {
  align-items: center;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  min-height: 70px;
  padding: 12px;
}

.check-field input {
  height: 18px;
  width: 18px;
}

.check-field span {
  color: var(--ink);
  margin: 0;
}

.signing-grid {
  display: grid;
  gap: 14px;
}

.sign-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

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

.sign-card-head h2 {
  font-size: 17px;
  line-height: 1.3;
  margin: 0;
}

.sign-state {
  background: #f3f4f6;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding: 4px 9px;
  white-space: nowrap;
}

.sign-state.signed {
  background: #e8f5ee;
  border-color: #b7dcc9;
  color: var(--good);
}

.signature-pad-wrap {
  margin-top: 12px;
}

.signature-pad {
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(0deg, transparent 0 42px, #eef1f4 42px 43px);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  height: 150px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  width: 100%;
}

.signature-pad:active,
.signature-modal-pad:active {
  cursor: crosshair;
}

.signature-pad-wrap p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin: 6px 0 0;
}

.sign-actions {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  margin-top: 10px;
}

.compact-check {
  min-height: 46px;
}

.sign-note-grid {
  margin-top: 14px;
}

.report-pane {
  position: sticky;
  top: 90px;
  align-self: start;
}

.report {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.report-sheet {
  padding: 22px;
}

.report-cover {
  border-bottom: 3px solid var(--ink);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding-bottom: 16px;
}

.report-cover h2 {
  font-size: 24px;
  margin: 0 0 6px;
}

.report-cover p,
.report-note,
.empty-copy {
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.report-badge {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  padding: 0 12px;
  white-space: nowrap;
}

.report-section {
  margin-top: 18px;
}

.report-section h3 {
  border-bottom: 1px solid var(--line);
  font-size: 16px;
  margin: 0 0 10px;
  padding-bottom: 8px;
}

.meta-table,
.item-table {
  border-collapse: collapse;
  width: 100%;
}

.meta-table th,
.meta-table td,
.item-table th,
.item-table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.meta-table th,
.item-table th {
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  padding: 4px 9px;
  white-space: nowrap;
}

.status-normal {
  background: #e8f5ee;
  color: var(--good);
}

.status-existing {
  background: #eef3fb;
  color: var(--accent-2);
}

.status-repair {
  background: #fff1dd;
  color: var(--warn);
}

.status-dispute {
  background: #fdecec;
  color: var(--bad);
}

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

.report-photo {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.report-photo img {
  aspect-ratio: 4 / 3;
  display: block;
  object-fit: cover;
  width: 100%;
}

.report-photo figcaption {
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  min-height: 48px;
  padding: 7px;
}

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

.signature-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 128px;
  padding: 12px;
}

.signature-box strong {
  display: block;
  font-size: 20px;
  margin-top: 16px;
}

.signature-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.signature-image {
  border-bottom: 1px solid var(--line);
  display: block;
  height: 64px;
  margin-top: 10px;
  object-fit: contain;
  object-position: left center;
  width: 100%;
}

.signature-line {
  border-bottom: 1px solid var(--line);
  height: 64px;
  margin-top: 10px;
}

.signature-modal {
  align-items: center;
  background: rgba(22, 28, 33, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 20;
}

.signature-modal[hidden] {
  display: none;
}

.signature-modal-card {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 36px);
  max-width: 1000px;
  padding: 16px;
  width: min(100%, 1000px);
}

.signature-modal-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.signature-modal-head h2 {
  font-size: 20px;
  margin: 0;
}

.signature-modal-head p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin: 4px 0 0;
}

.signature-modal-pad {
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(0deg, transparent 0 56px, #eef1f4 56px 57px);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  height: min(48vh, 420px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  width: 100%;
}

.signature-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

@media (max-width: 1000px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .report-pane {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 42px;
  }

  .tool-button {
    justify-content: center;
  }

  .form-grid.two,
  .reading-grid,
  .condition-card,
  .sign-row,
  .sign-actions {
    grid-template-columns: 1fr;
  }

  .item-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs {
    grid-template-columns: repeat(4, minmax(68px, 1fr));
  }

  .signature-pad {
    height: 190px;
  }

  .signature-modal {
    padding: 10px;
  }

  .signature-modal-card {
    max-height: calc(100vh - 20px);
  }

  .signature-modal-pad {
    height: min(54vh, 460px);
  }

  .signature-modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .work-panel {
    display: none !important;
  }

  .workspace {
    display: block;
    max-width: none;
    padding: 0;
  }

  .report-pane {
    position: static;
  }

  .report {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .report-sheet {
    padding: 0;
  }

  .report-photo,
  .signature-box,
  .meta-table tr,
  .item-table tr {
    break-inside: avoid;
  }
}
