:root {
  --ink: #18212f;
  --muted: #657084;
  --line: #d9e0ea;
  --paper: #f6f8fb;
  --panel: #ffffff;
  --brand: #0f766e;
  --brand-dark: #0b5f59;
  --accent: #b45309;
  --danger: #b42318;
  --shadow: 0 16px 45px rgba(24, 33, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: Arial, Helvetica, sans-serif;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 52px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

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

.app-header h1,
.panel h2 {
  margin: 0;
}

.app-header h1 {
  font-size: clamp(1.4rem, 3vw, 2.15rem);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 54px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  padding: 6px;
  background: #e8edf3;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab-button {
  flex: 1;
  color: var(--ink);
  background: transparent;
}

.tab-button.active {
  color: #fff;
  background: var(--brand);
}

.app-view {
  display: none;
}

.app-view.active {
  display: block;
}

.panel {
  margin-bottom: 18px;
  padding: clamp(18px, 3vw, 28px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-panel,
.section-title,
.actions,
.signature-heading,
.photo-uploader,
.terms-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.intro-panel p {
  max-width: 720px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.status-card {
  min-width: 170px;
  padding: 18px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fffaf2;
}

.status-card.complete {
  border-left-color: var(--brand);
  background: #eefaf7;
}

.status-label,
.section-title span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.status-card strong {
  display: block;
  margin: 4px 0;
  font-size: 2rem;
}

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

label,
.check-item {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  margin-top: 8px;
  padding: 12px 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c8d1df;
  border-radius: 6px;
  font: inherit;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus,
canvas:focus {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  border-color: var(--brand);
}

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

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

.check-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  min-height: 58px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.check-item input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--brand);
}

.check-item span {
  color: var(--ink);
  line-height: 1.35;
}

.check-item em,
.check-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.8rem;
  font-style: normal;
  font-weight: 400;
}

.photo-uploader {
  align-items: stretch;
  margin-top: 18px;
}

.file-drop {
  flex: 1;
  min-height: 92px;
  padding: 16px;
  color: var(--ink);
  background: #fbfcfe;
  border: 1px dashed #9aa8ba;
  border-radius: 8px;
  cursor: pointer;
}

.file-drop input {
  display: none;
}

.file-drop span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.4;
}

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

.photo-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

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

.photo-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
  border-top: 1px solid var(--line);
}

.photo-card input {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.photo-remove {
  min-height: 0;
  padding: 0 12px;
  color: var(--danger);
  background: #fff4f2;
  border-left: 1px solid var(--line);
  border-radius: 0;
  font-size: 0.82rem;
}

.terms-actions {
  justify-content: flex-start;
  margin-top: 16px;
}

.acceptance {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  margin-top: 14px;
  padding: 13px;
  color: var(--ink);
  background: #eefaf7;
  border: 1px solid #b7ded7;
  border-radius: 8px;
}

.acceptance input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: var(--brand);
}

.acceptance span {
  line-height: 1.4;
}

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

.signature-box {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

canvas {
  width: 100%;
  height: 160px;
  margin-top: 12px;
  background: #fff;
  border: 1px dashed #9aa8ba;
  border-radius: 6px;
  touch-action: none;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.primary-button {
  padding: 0 18px;
  color: #fff;
  background: var(--brand);
}

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

.secondary-button {
  padding: 0 14px;
  color: var(--ink);
  background: #e8edf3;
}

.secondary-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  color: var(--ink);
  background: #e8edf3;
  border-radius: 6px;
  font-weight: 700;
  text-decoration: none;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(460px, 100%);
}

.public-report {
  padding-top: 24px;
}

.auth-panel h1 {
  margin: 0 0 18px;
}

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

.alert {
  padding: 12px 14px;
  border-radius: 6px;
}

.alert.error {
  color: var(--danger);
  background: #fff4f2;
  border: 1px solid #ffd0c8;
}

.alert.success {
  color: var(--brand-dark);
  background: #eefaf7;
  border: 1px solid #b7ded7;
}

.compact-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.records-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.record-with-thumb,
.selected-article {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  align-items: center;
}

.record-with-thumb img,
.selected-article img {
  width: 84px;
  height: 64px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #e8edf3;
}

.article-preview {
  margin-top: 16px;
}

.selected-article {
  padding: 12px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.selected-article span {
  display: block;
  color: var(--muted);
  line-height: 1.4;
}

.record-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.record-row strong,
.detail-panel strong {
  display: block;
}

.record-row span,
.detail-panel span,
.empty-state {
  color: var(--muted);
  line-height: 1.45;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.mini-button {
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink);
  background: #e8edf3;
  font-size: 0.86rem;
}

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

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

.detail-item {
  padding: 13px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-list {
  margin: 8px 0 0;
  padding-left: 18px;
  line-height: 1.5;
}

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

.signature-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.signature-preview {
  padding: 12px;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.signature-preview img {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: contain;
  margin-top: 8px;
  background: #fff;
  border: 1px dashed #9aa8ba;
  border-radius: 6px;
}

.certificate {
  display: none;
  border-left: 5px solid var(--brand);
}

.certificate.visible {
  display: block;
}

.invalid {
  border-color: var(--danger);
}

@media (max-width: 760px) {
  .app-header,
  .header-actions,
  .intro-panel,
  .section-title,
  .actions,
  .photo-uploader,
  .terms-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .checklist,
  .signature-grid,
  .photo-grid,
  .detail-grid,
  .signature-preview-grid {
    grid-template-columns: 1fr;
  }

  .tabs,
  .record-row,
  .row-actions,
  .record-with-thumb,
  .selected-article {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button,
  .mini-button,
  .secondary-link {
    width: 100%;
  }
}

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

  .app-header,
  .tabs,
  .actions,
  [data-clear],
  .terms-actions,
  #clearPhotosBtn,
  .photo-remove,
  .row-actions {
    display: none;
  }

  .shell {
    width: 100%;
    margin: 0;
  }

  .panel {
    box-shadow: none;
    break-inside: avoid;
  }
}
