:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #637168;
  --line: #d9e0dc;
  --blue: #0b4f8a;
  --accent: #0f766e;
  --aqua: #22c7b8;
  --accent-dark: #0b5d57;
  --warning: #b45309;
  --soft: #e8f3f1;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(16px, 4vw, 42px);
  background: #f8fffe;
  color: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 26px rgba(11, 79, 138, 0.08);
}

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

.brand-logo {
  display: block;
  width: clamp(160px, 22vw, 160px);
  height: auto;
  flex: 0 0 auto;
}

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

h1 {
  margin-bottom: 0;
  color: var(--blue);
  font-size: clamp(18px, 3vw, 18px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 2px;
  font-size: 18px;
}

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

.header-actions,
.items-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-status {
  min-width: 86px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 16px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

button.primary {
  background: var(--blue);
  color: #fff;
}

button.primary:hover {
  background: #073d6b;
}

button.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 34px);
}

.form-panel,
.summary-panel {
  min-width: 0;
}

.form-panel > section,
.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.form-panel > section + section,
.summary-card + .summary-card {
  margin-top: 16px;
}

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

.section-heading span,
.summary-label,
.summary-card span {
  color: var(--muted);
  font-size: 13px;
}

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

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

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

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

label {
  display: grid;
  gap: 6px;
  color: #26322d;
  font-size: 13px;
  font-weight: 700;
}

label.wide {
  grid-column: 1 / -1;
}

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.summary-panel {
  position: sticky;
  top: 106px;
  align-self: start;
}

.summary-card {
  padding: 16px;
}

.summary-card strong {
  display: block;
  margin: 3px 0 4px;
  font-size: 30px;
}

.history-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.signature-heading,
.photos-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.signature-heading h2,
.photos-heading h2 {
  margin-bottom: 0;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

#photoCount {
  min-width: 42px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--blue);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

#photoInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.photo-note {
  margin: 9px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

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

#signaturePad {
  display: block;
  width: 100%;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.photo-preview {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f6faf9;
  aspect-ratio: 1;
}

.photo-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.photo-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.92);
  color: #8a1f11;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}

.history-heading h2 {
  margin-bottom: 0;
}

#historyCount {
  min-width: 30px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--blue);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.history-tools {
  display: flex;
  align-items: center;
  gap: 7px;
}

.history-status {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #f7fffe 0%, #edf5fa 100%);
}

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

.login-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 18px 50px rgba(11, 79, 138, 0.12);
}

.login-logo {
  display: block;
  width: 210px;
  height: auto;
  margin-bottom: 18px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.login-error {
  margin: 0;
  border: 1px solid #f1c5bd;
  border-radius: var(--radius);
  background: #fff7f5;
  color: #8a1f11;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
}

.history-search-label {
  margin-bottom: 12px;
}

.history-list {
  display: grid;
  gap: 9px;
  max-height: 460px;
  overflow: auto;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
  padding: 10px;
}

.history-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

.history-title span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.history-meta {
  margin: 5px 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.history-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 42px;
  gap: 6px;
}

.history-actions button {
  min-height: 34px;
  padding: 0 8px;
  font-size: 12px;
}

.check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  margin-top: 9px;
  font-weight: 600;
}

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

.items-toolbar {
  justify-content: space-between;
  margin: 18px 0 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 82px 110px 110px 42px;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfb;
}

.item-row + .item-row {
  margin-top: 8px;
}

.remove-item {
  width: 42px;
  min-height: 42px;
  padding: 0;
  color: #8a1f11;
  border-color: #f1c5bd;
  background: #fff7f5;
}

.print-area {
  display: none;
}

.report-page {
  color: #111;
  background: #fff;
  font-family: Arial, Helvetica, sans-serif;
}

.report-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  border-bottom: 3px solid #22c7b8;
  padding-bottom: 14px;
  margin-bottom: 16px;
}

.report-logo {
  display: block;
  width: 240px;
  height: auto;
  margin-bottom: 8px;
}

.report-top h1 {
  color: #0b4f8a;
  font-size: 23px;
}

.report-meta {
  text-align: right;
  font-size: 12px;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.report-box {
  border: 1px solid #cfd8d4;
  border-radius: 6px;
  padding: 10px;
}

.report-box h2 {
  color: #0b4f8a;
  font-size: 14px;
  text-transform: uppercase;
}

.report-box p {
  margin-bottom: 5px;
}

.report-box.full {
  grid-column: 1 / -1;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}

.report-table th,
.report-table td {
  border: 1px solid #cfd8d4;
  padding: 7px;
  text-align: left;
}

.report-table th {
  background: #e8f7f5;
}

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

.report-photo {
  border: 1px solid #cfd8d4;
  border-radius: 6px;
  overflow: hidden;
  background: #f6faf9;
}

.report-photo img {
  display: block;
  width: 100%;
  height: 118px;
  object-fit: cover;
}

.numeric {
  text-align: right;
}

.totals {
  margin-left: auto;
  width: min(360px, 100%);
}

.signature-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 26px;
}

.signature-line {
  border-top: 1px solid #222;
  padding-top: 6px;
  font-size: 12px;
  text-align: center;
}

.signature-box {
  min-height: 82px;
  border-bottom: 1px solid #222;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px 8px;
}

.signature-box img {
  max-width: 100%;
  max-height: 76px;
  display: block;
}

.technician-signature-box {
  align-items: center;
}

.technician-signature {
  color: #10231f;
  font-family: "Brush Script MT", "Segoe Script", "Snell Roundhand", cursive;
  font-size: 31px;
  line-height: 1;
}

.signature-caption {
  padding-top: 6px;
  font-size: 12px;
  text-align: center;
}

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

  .summary-panel {
    position: static;
    order: -1;
  }
}

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

  .brand-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions button {
    flex: 1;
  }

  .header-actions {
    flex-wrap: wrap;
  }

  .grid.two,
  .grid.three,
  .grid.four {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .item-row label:first-child {
    grid-column: 1 / -1;
  }
}

@media print {
  @page {
    margin: 12mm;
    size: A4;
  }

  body {
    background: #fff;
  }

  .app-header,
  .layout {
    display: none;
  }

  .print-area {
    display: block;
  }

  .report-page {
    font-size: 12px;
  }
}
