
* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d8dee8;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #b91c1c;
  --disabled: #9ca3af;
  --footer-h: 74px;
  font-family: Arial, Helvetica, sans-serif;
}

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

.app-shell {
  min-height: 100vh;
  padding: 16px 16px calc(var(--footer-h) + 16px);
}

.top-tabs {
  display: flex;
  justify-content: flex-start; /* Keeps everything to the left */
  gap: 22px; /* Standard spacing between all items */
  align-items: center; /* Vertically centers the button with the tabs */
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  padding: 14px 0 12px;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab.active {
  color: var(--text);
  font-weight: 700;
  border-bottom-color: var(--accent);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: stretch;
  margin-bottom: 12px;
}

.row:last-child {
  margin-bottom: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
}

.wide-1 { flex: 1 1 160px; }
.wide-2 { flex: 2 1 260px; }
.wide-3 { flex: 3 1 10px; }

label {
  font-size: 13px;
  font-weight: 700;
  color: #374151;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  min-height: 12px;
  background: #fff;
}

textarea {
  resize: vertical;
}

.inline-fields {
  display: flex;
  gap: 8px;
}

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

.person-pair-grid select {
  min-width: 0;
}

.compact-address input:nth-child(2) {
  max-width: 72px;
}

.compact-address input:nth-child(3) {
  max-width: 120px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  min-height: 4px;
}

.check-row label,
.damage-check,
.confirm-line {
  display: flex;
  gap: 6px;
  align-items: center;
  font-weight: 400;
}

.required {
  color: var(--danger);
  font-weight: 700;
  font-size: 12px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.section-title h2 {
  margin: 0;
  font-size: 20px;
}

.piece-totals {
  color: var(--muted);
  font-weight: 700;
}

.pieces-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.piece-card {
  display: grid;
  grid-template-columns: 110px 1.1fr 1.6fr 2fr 180px;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
}

.piece-title {
  font-weight: 800;
  padding-top: 26px;
}

.marks-field textarea {
  min-height: 88px;
}

.damage-photo {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 26px;
}

.photo-status {
  font-size: 12px;
  color: var(--muted);
}

.add-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-top: 12px;
}

button {
  border: 0;
  border-radius: 9px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
}

.primary,
.submit {
  background: var(--accent);
  color: #fff;
}

.primary:hover,
.submit:hover {
  background: var(--accent-dark);
}

.secondary {
  background: #e8eefc;
  color: #14316f;
}

.ghost {
  background: transparent;
  color: #374151;
  border: 1px solid var(--line);
}

button:disabled,
.submit:disabled {
  cursor: not-allowed;
  background: var(--disabled);
  color: #eef2f7;
}

.sticky-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-h);
  background: rgba(255,255,255,0.94);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 12px 20px;
  z-index: 20;
}

.submit {
  min-width: 190px;
  min-height: 46px;
}

.history-search {
  display: flex;
  gap: 10px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(15,23,42,0.55);
}

.dialog-card {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.28);
  width: min(980px, 94vw);
}

.dialog-card.narrow {
  width: min(460px, 92vw);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.dialog-header h2,
.small-dialog h2 {
  margin: 0;
}

.icon-button {
  background: #f3f4f6;
  color: #111827;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.camera-layout {
  display: grid;
  grid-template-columns: 1.6fr 320px;
  gap: 16px;
}

.camera-box {
  position: relative;
}

#cameraPreview {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #111827;
  border-radius: 12px;
  object-fit: cover;
}

.camera-prompt {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 15%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(0,0,0,0.45);
  border-radius: 12px 12px 0 0;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.camera-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.file-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  background: #e8eefc;
  color: #14316f;
  border-radius: 9px;
  padding: 10px 16px;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.thumbnail-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thumb-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 110px;
  background: repeating-linear-gradient(
    45deg,
    #f3f4f6,
    #f3f4f6 10px,
    #e5e7eb 10px,
    #e5e7eb 20px
  );
  overflow: hidden;
}

.thumb-wrap img {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: cover;
}

.thumb-delete {
  position: absolute;
  right: 6px;
  top: 6px;
  background: rgba(185,28,28,0.9);
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  padding: 0;
  line-height: 1;
}

.full-width {
  width: 100%;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 800px) {
  .tab#tabHistory {
    display: none;
  }

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

  .piece-title,
  .damage-photo {
    padding-top: 0;
  }

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

  .inline-fields {
    flex-direction: column;
  }

  .person-pair-grid {
    grid-template-columns: 1fr;
  }

  .sticky-footer {
    justify-content: stretch;
  }

  .submit {
    width: 100%;
  }
}

@media print {
  body:not(.printing-report),
  body:not(.printing-report) .app-shell,
  body:not(.printing-report) .detail-view,
  body:not(.printing-report) #historyView {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    display: block !important;
  }

  body:not(.printing-report) .top-tabs,
  body:not(.printing-report) .search-container,
  body:not(.printing-report) .history-search,
  body:not(.printing-report) .sticky-footer,
  body:not(.printing-report) .add-row,
  body:not(.printing-report) .add-photo,
  body:not(.printing-report) .photo-status,
  body:not(.printing-report) .icon-button,
  body:not(.printing-report) #btnOpenInfo,
  body:not(.printing-report) dialog {
    display: none !important;
  }

  body:not(.printing-report) .panel,
  body:not(.printing-report) .piece-card {
    box-shadow: none !important;
    border-color: #222 !important;
  }

  body:not(.printing-report) .piece-card {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 20px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
  }

  body:not(.printing-report) .piece-photo {
    max-height: 3.5in !important;
    width: auto !important;
    object-fit: contain;
    margin-top: 10px;
    border: 1px solid #eee;
  }

  body:not(.printing-report) h2,
  body:not(.printing-report) h3 {
    color: #000 !important;
    margin-top: 0;
  }
}
.history-table-wrap {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: white;
}

.history-header-row,
.history-row {
  display: grid;
  grid-template-columns: 110px 110px 1.35fr 145px 205px 1.4fr 130px 36px;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.history-header-row {
  font-weight: 700;
  background: #e8eefc;
  border-bottom: 1px solid var(--line);
}

.history-results {
  max-height: calc(100vh - 240px);
  overflow-y: auto;
}

.history-row {
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.history-row.alt {
  background: #f7f9fc;
}

.history-row:hover {
  background: #dfe9ff;
}

.history-row > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron {
  font-size: 22px;
  font-weight: 700;
  text-align: right;
  color: var(--accent);
}
.history-results .history-row:nth-child(even) {
  background: #bdd7ff !important;
}

.history-results .history-row:nth-child(odd) {
  background: #ffffff !important;
}

.history-results .history-row:hover {
  background: #dfe9ff !important;
}

.history-modal {
  width: 90vw;
  max-width: none;
  height: 90vh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.history-modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.history-modal-shell {
  --preview-page-width: min(80vw, 850px);
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 16px 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.history-modal-toolbar {
  width: var(--preview-page-width);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0 0 8px;
}

.history-detail {
  width: 100%;
  flex: 1;
  overflow-y: auto;
  padding: 0 0 20px;
}

.print-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.report-page {
  width: var(--preview-page-width);
  aspect-ratio: 8.5 / 11;
  background: white;
  color: black;
  padding: 28px;
  box-shadow: 0 10px 35px rgba(0,0,0,0.4);
  position: relative;
}

.report-title {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 8px;
}

.report-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #111;
  margin-bottom: 12px;
}

.report-cell {
  border: 1px solid #111;
  padding: 5px 7px;
  min-height: 28px;
  font-size: 12px;
}

.report-label {
  font-weight: 800;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.report-table th,
.report-table td {
  border: 1px solid #111;
  padding: 4px 6px;
  height: 24px;
  text-align: left;
  vertical-align: top;
}

.report-photo-box {
  position: absolute;
  right: 28px;
  bottom: 28px;
  width: 32%;
  height: 22%;
  border: 1px solid #111;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  font-weight: 800;
  cursor: default;
  overflow: hidden;
}

.report-photo-box.can-fetch {
  cursor: pointer;
  color: #1d4ed8;
}

.report-photo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.report-page-2 .photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  height: calc(100% - 45px);
}

.report-page-2 .report-photo-box {
  position: static;
  width: 100%;
  height: 100%;
}


.print-root {
  display: none;
}

body.printing-report > :not(#printRoot) {
  display: none !important;
}

@page {
  size: letter portrait;
  margin: 0;
}

@media print {
  html,
  body {
    margin: 0;
    padding: 0;
    background: #fff;
  }

  body.printing-report {
    display: block;
  }

  body.printing-report > #printRoot {
    display: block !important;
  }

  #printRoot {
    width: 8in;
    margin: 0 auto;
  }

  #printRoot .print-preview {
    display: block;
  }

  #printRoot .report-page {
    width: 7in;
    height: 9in;
    aspect-ratio: auto;
    padding: 24px;
    box-shadow: none;
    margin: 0 auto;
    overflow: hidden;
    break-after: page;
    page-break-after: always;
  }

  #printRoot .report-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  #printRoot .report-page .report-photo-box {
    right: 24px;
    bottom: 44px;
  }

  #printRoot .history-modal-toolbar,
  #printRoot .icon-button {
    display: none !important;
  }
}
.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  font-size: 14px;
}

.check-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
}
@media (max-width: 480px) {
  .check-row {
    gap: 6px 8px;
  }

  .check-row label {
    font-size: 13px;
  }
}
/* Position the Info button */
.info-trigger {
  width: 28px; /* Slightly smaller for a tighter fit */
  height: 28px;
  font-size: 16px;
  margin-bottom: 4px; /* Aligns visually with the tab text baseline */
  background: var(--line);
  color: var(--text);
}

/* Modal positioning and width */
.info-modal {
  border: 0;
  padding: 0;
  background: transparent;
  padding-top: 8vh; /* Positioned in the top third */
}

.info-card {
  width: 75vw; /* Sets width to 75% of the viewport width */
  max-width: 1100px; /* Safety cap for ultra-wide monitors */
  margin: 0 auto;
  border-radius: 16px;
  background: white;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  padding: 24px;
}

/* Reduced Font Sizes */
.qa-pair h3 {
  margin: 0 0 4px 0;
  font-size: 16pt; /* Reduced from 18pt */
  font-weight: 800;
  color: var(--text);
}

.qa-pair p {
  margin: 0 0 14px 0;
  font-size: 12pt; /* Reduced from 14pt */
  line-height: 1.5;
  color: #374151;
}

/* Ensure the content is scannable */
.info-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}
/* Hidden by default, toggled via JS */
.help-section {
  display: none;
}

/* Fix for checkboxes expanding to 100% width */
input[type="checkbox"] {
  width: auto; /* Overrides the global 100% width */
  height: 18px;
  width: 18px;
  margin: 0;
  cursor: pointer;
}

/* Specific fix for the Damaged label container */
.damage-check {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start; /* Keeps the checkbox and text snug */
  white-space: nowrap;
}
