:root {
  --blue: #123d84;
  --border: #909090;
  --paper-width: 8.5in;
  --paper-height: 11in;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #e9edf2;
  color: #111;
}

.app-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid #ccd3dc;
}

.status {
  margin-left: 14px;
  color: #67717e;
  font-size: 13px;
}

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

.document-type-control,
.legend-toggle-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #3f4b59;
}

.legend-toggle-control {
  white-space: nowrap;
}

.legend-toggle-control input {
  margin: 0;
}

.document-type-control select {
  border: 1px solid #aeb6c2;
  border-radius: 5px;
  background: #fff;
  padding: 7px 9px;
  font: inherit;
}

button,
.upload-prompt {
  border: 1px solid #aeb6c2;
  border-radius: 5px;
  background: #fff;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}

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

.editor-shell {
  padding: 24px;
  overflow: auto;
}

.report-page {
  width: var(--paper-width);
  min-height: var(--paper-height);
  margin: 0 auto;
  padding: .12in;
  background: #fff;
  border: 1px solid #555;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .15);
  font-size: 11.5px;
}

.report-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.brand-block {
  display: flex;
  align-items: center;
}

.brand-logo {
  width: 150px;
  height: auto;
  display: block;
}

.report-title-block {
  text-align: right;
  line-height: 1.65;
}

h1 {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 18px;
}

h2 {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 12.5px;
}

.two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.two-column>article {
  padding: 9px 16px;
}

.two-column>article+article {
  border-left: 1px solid #d3d3d3;
}

.info-section {
  min-height: 178px;
  border-bottom: 1px solid var(--border);
}

.field-grid {
  display: grid;
  grid-template-columns: 135px 1fr;
  gap: 7px 8px;
  line-height: 1.3;
}

.overview-section {
  padding-top: 7px;
  border-bottom: 1px solid var(--border);
}

.overview-section>h2 {
  padding-left: 8px;
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 245px;
  gap: 8px;
  padding: 0 0 6px;
}

.map-panel {
  position: relative;
  min-height: 405px;
}

#mapUpload {
  position: absolute;
  left: 12px;
  top: 12px;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.upload-prompt {
  position: absolute;
  z-index: 3;
  left: 12px;
  top: 12px;
  background: rgba(255, 255, 255, .92);
}

.map-stage {
  position: relative;
  height: 405px;
  overflow: hidden;
  border: 1px solid #c5c5c5;
  background: #eef2f5 center / cover no-repeat;
}

.map-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: #66717d;
}

.photo-panel {
  border: 1px solid #b8b8b8;
  padding: 8px;
  background: #fff;
}

.photo-panel>h2 {
  margin-bottom: 6px;
}

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.photo-card {
  margin: 0;
  border: 1px solid #b8b8b8;
  background: #f7f7f7;
  min-width: 0;
}

.photo-select {
  position: relative;
  display: block;
  width: 100%;
  height: 92px;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: #eef2f5;
}

.photo-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #6b7480;
  font-size: 10px;
}

.photo-image {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card.has-photo .photo-image {
  display: block;
}

.photo-card.has-photo .photo-placeholder {
  display: none;
}

.photo-upload {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.photo-card figcaption {
  min-height: 28px;
  padding: 5px;
  background: #fff;
  border-top: 1px solid #d4d4d4;
  font-size: 9.5px;
  line-height: 1.15;
  text-align: center;
}

.compact-legend[hidden] {
  display: none !important;
}

.compact-legend {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 4px;
  padding: 5px 8px 7px;
  border-top: 1px solid #d2d2d2;
}

.compact-legend h2 {
  margin: 0;
}

.legend-items {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 14px;
  font-size: 9.5px;
}

.legend-items span {
  white-space: nowrap;
}

ul {
  margin: 0;
  padding-left: 19px;
  line-height: 1.38;
}

li {
  margin-bottom: 5px;
}

.lower-section {
  min-height: 160px;
  border-bottom: 1px solid var(--border);
}

.report-footer {
  display: grid;
  grid-template-columns: 1fr 225px;
  gap: 14px;
  padding: 10px 8px 4px;
  line-height: 2.15;
}

.company-footer {
  border-left: 1px solid #ddd;
  padding-left: 18px;
  color: var(--blue);
  line-height: 1.55;
}

[contenteditable="true"] {
  outline: none;
  border-radius: 2px;
}

[contenteditable="true"]:focus {
  box-shadow: 0 0 0 2px rgba(18, 61, 132, .18);
  background: #f7faff;
}

@media (max-width: 900px) {
  .editor-shell {
    padding: 10px;
  }

  .report-page {
    transform-origin: top left;
  }
}

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

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

  .no-print {
    display: none !important;
  }

  .editor-shell {
    padding: 0;
  }

  .report-page {
    width: 8.5in;
    min-height: 11in;
    margin: 0;
    border: 0;
    box-shadow: none;
  }
}

.lower-section.single-section {
  grid-template-columns: 1fr;
}

.lower-section.single-section > article {
  border-left: 0;
}

.lower-section article.is-hidden {
  display: none;
}

@media print {
  .document-type-control,
.legend-toggle-control {
    display: none !important;
  }
}


.snapshot-reference {
  color: #657184;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .25px;
}

.project-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(22, 31, 44, .58);
}

.project-modal.is-open {
  display: grid;
}

.project-modal-card {
  width: min(620px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .28);
}

.project-modal-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid #d7dde5;
}

.project-modal-header h2 {
  margin: 0 0 5px;
  font-size: 16px;
}

.project-modal-header p {
  margin: 0;
  color: #657184;
  font-size: 13px;
  line-height: 1.4;
}

.modal-close {
  flex: 0 0 auto;
  border: 0;
  padding: 0 4px;
  color: #5e6876;
  font-size: 25px;
  line-height: 1;
}

.project-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 20px 22px 12px;
}

.project-form label {
  display: grid;
  gap: 6px;
  color: #26364a;
  font-size: 12px;
  font-weight: 700;
}

.project-form label:nth-child(-n+3) {
  grid-column: 1 / -1;
}

.project-form select,
.project-form input {
  width: 100%;
  border: 1px solid #abb5c3;
  border-radius: 5px;
  background: #fff;
  padding: 9px 10px;
  color: #111;
  font: inherit;
  font-weight: 400;
}

.project-form select:disabled {
  background: #edf1f5;
  color: #7a8491;
}

.project-modal-status {
  min-height: 20px;
  padding: 0 22px 12px;
  color: #657184;
  font-size: 12px;
}

.project-modal-status.error {
  color: #a11d1d;
}

.project-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px 20px;
  border-top: 1px solid #e0e5eb;
}

.project-modal-actions button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

@media (max-width: 1100px) {
  .app-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (max-width: 620px) {
  .project-form {
    grid-template-columns: 1fr;
  }

  .project-form label {
    grid-column: 1 / -1;
  }
}


/* Project photo library */
.photo-library {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 90;
  width: min(390px, 94vw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-left: 1px solid #c9d1dc;
  box-shadow: -12px 0 40px rgba(18, 30, 48, .22);
  transform: translateX(105%);
  transition: transform .22s ease;
}

.photo-library.is-open {
  transform: translateX(0);
}

.photo-library-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid #d8dee7;
}

.photo-library-header h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.photo-library-header p {
  margin: 0;
  color: #657184;
  font-size: 12px;
  line-height: 1.35;
}

.photo-library-close {
  align-self: flex-start;
  border: 0;
  padding: 0 4px;
  color: #5e6876;
  font-size: 25px;
  line-height: 1;
}

.photo-library-target {
  margin: 12px 18px 0;
  padding: 9px 10px;
  border: 1px solid #cfd7e2;
  border-radius: 5px;
  background: #f5f8fc;
  color: #34445a;
  font-size: 12px;
  line-height: 1.35;
}

.photo-library-actions {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
}

.photo-library-actions button {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
}

.photo-library-status {
  min-height: 20px;
  padding: 0 18px 10px;
  color: #657184;
  font-size: 12px;
}

.photo-library-status.error {
  color: #a11d1d;
}

.drive-photo-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  padding: 0 18px 20px;
}

.drive-photo-item {
  min-width: 0;
  overflow: hidden;
  border: 1px solid #c9d1dc;
  border-radius: 6px;
  background: #fff;
  cursor: grab;
}

.drive-photo-item:active {
  cursor: grabbing;
}

.drive-photo-item img {
  display: block;
  width: 100%;
  height: 105px;
  object-fit: cover;
  background: #edf1f5;
}

.drive-photo-item-name {
  padding: 6px 7px 2px;
  overflow: hidden;
  color: #24354a;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-photo-item-meta {
  padding: 0 7px 7px;
  overflow: hidden;
  color: #778291;
  font-size: 9.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-card {
  transition: box-shadow .15s ease, border-color .15s ease;
}

.photo-card.is-target {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(18, 61, 132, .2);
}

.photo-card.is-drag-over {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(18, 61, 132, .28);
}

.photo-card .photo-select {
  cursor: pointer;
}

@media (max-width: 700px) {
  .drive-photo-grid {
    grid-template-columns: 1fr;
  }
}


/* Interactive map equipment markers */
.map-tools {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
  padding: 6px;
  border: 1px solid rgba(125, 138, 154, .6);
  border-radius: 6px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 3px 10px rgba(18, 30, 48, .12);
}

.map-tools button {
  min-height: 28px;
  padding: 4px 7px;
  font-size: 10px;
  line-height: 1;
}

.map-tools button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.upload-prompt {
  position: relative;
  left: auto;
  top: auto;
  display: inline-block;
  margin: 0 0 6px;
}

.marker-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.map-marker {
  position: absolute;
  display: grid;
  place-items: center;
  min-width: 31px;
  height: 31px;
  padding: 0 5px;
  border: 2px solid #fff;
  border-radius: 7px;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  box-shadow: 0 2px 7px rgba(0, 0, 0, .4);
  cursor: grab;
  user-select: none;
  touch-action: none;
  pointer-events: auto;
}

.map-marker:active {
  cursor: grabbing;
}

.map-marker.is-selected {
  outline: 3px solid rgba(255, 210, 0, .95);
  outline-offset: 2px;
}

.map-marker[data-marker-type="camera"] {
  background: #17469b;
}

.map-marker[data-marker-type="nvr"] {
  background: #ef6c28;
}

.map-marker[data-marker-type="switch"] {
  background: #2f6677;
}

.map-marker[data-marker-type="buzzer"] {
  background: #7951b5;
}

.map-marker[data-marker-type="lock"] {
  background: #3da55b;
}

.map-marker[data-marker-type="note"] {
  background: #5f6670;
}

.map-marker[data-marker-type="accessPoint"] {
  background: #287f8f;
}

.map-marker[data-marker-type="rack"] {
  background: #405a78;
}

.map-marker[data-marker-type="router"] {
  background: #4f6f52;
}

.map-marker[data-marker-type="reader"] {
  background: #8a5a2b;
}

.map-marker[data-marker-type="door"] {
  background: #82653d;
}

.map-marker[data-marker-type="custom"] {
  background: #596275;
}

.map-marker-svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.map-marker-svg .icon-fill {
  fill: currentColor;
  stroke: none;
}

.map-marker-label {
  position: absolute;
  left: 50%;
  top: calc(100% + 3px);
  transform: translateX(-50%);
  max-width: 92px;
  padding: 2px 4px;
  border: 1px solid rgba(70, 78, 88, .45);
  border-radius: 3px;
  background: rgba(255, 255, 255, .94);
  color: #111;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.1;
  text-shadow: none;
  white-space: nowrap;
}

@media print {
  .map-marker {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .map-marker.is-selected {
    outline: none;
  }
}


.map-marker-edit {
  position: absolute;
  top: -9px;
  right: -9px;
  display: none;
  width: 18px;
  height: 18px;
  min-width: 18px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 50%;
  background: #123d84;
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

.map-marker.is-selected .map-marker-edit {
  display: block;
}


.map-marker-camera-graphic {
  position: relative;
  width: 26px;
  height: 18px;
  transform: rotate(var(--marker-rotation, 0deg));
  transform-origin: 50% 50%;
}

.map-marker-camera-body {
  position: absolute;
  left: 2px;
  top: 4px;
  width: 17px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 3px;
  background: #17469b;
}

.map-marker-camera-lens {
  position: absolute;
  right: 0;
  top: 6px;
  width: 7px;
  height: 7px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #17469b;
}

.map-marker-camera-direction {
  position: absolute;
  left: 25px;
  top: 5px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 14px solid rgba(255, 210, 0, .92);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35));
}

.map-marker[data-marker-type="camera"] {
  min-width: 38px;
  width: 38px;
  height: 34px;
  padding: 0;
  overflow: visible;
}

.map-marker[data-marker-type="camera"] .map-marker-label {
  top: calc(100% + 5px);
}

.save-error-detail {
  display: inline-block;
  margin-left: 8px;
  color: #a11d1d;
  font-size: 11px;
}


/* Print fix: keep selected report photos visible in PDF output. */
@media print {
  .photo-card .photo-select.no-print {
    display: block !important;
  }

  .photo-card .photo-image {
    display: block;
  }

  .photo-card:not(.has-photo) .photo-image {
    display: none;
  }

  .photo-card.has-photo .photo-placeholder {
    display: none;
  }
}


/* Print-safe aerial map image */
.map-print-image {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.marker-layer {
  z-index: 4;
}

@media print {
  .map-stage {
    background-image: none !important;
  }

  .map-print-image.has-image {
    display: block !important;
  }
}


/* Selected map-marker appearance controls */
.marker-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 3px 6px;
  border: 1px solid rgba(125, 138, 154, .5);
  border-radius: 4px;
  background: #fff;
  color: #26364a;
  font-size: 10px;
  font-weight: 700;
}

.marker-control select {
  height: 22px;
  border: 1px solid #aeb8c5;
  border-radius: 3px;
  font-size: 10px;
}

.marker-opacity-control input[type="range"] {
  width: 76px;
}

.marker-opacity-control output {
  min-width: 30px;
  text-align: right;
  font-size: 10px;
}

.marker-control:has(:disabled) {
  opacity: .55;
}

/* Straight cable-path drawing */
.cable-color-control input[type="color"] {
  width: 30px;
  height: 22px;
  padding: 0;
  border: 1px solid #aeb8c5;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}

.cable-edit-controls {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.cable-edit-controls.is-hidden,
.marker-edit-control.is-hidden {
  display: none !important;
}

#cableDrawBtn {
  min-width: 30px;
  padding-left: 8px;
  padding-right: 8px;
  font-weight: 800;
}

#cableDrawBtn.is-active {
  background: #17469b;
  color: #fff;
  border-color: #17469b;
}

.map-stage.is-drawing-cable {
  cursor: crosshair;
  touch-action: none;
}

.cable-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.cable-path-hit {
  pointer-events: stroke;
  cursor: pointer;
}

.cable-path {
  pointer-events: stroke;
  cursor: pointer;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .45));
}

.cable-path.is-selected {
  filter: drop-shadow(0 0 4px rgba(255, 210, 0, 1));
}

@media print {
  .cable-path {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}


.cable-label-control input[type="text"] {
  width: 78px;
  height: 26px;
  padding: 3px 6px;
  border: 1px solid #aeb8c5;
  border-radius: 4px;
  font: inherit;
}

.cable-label-toggle {
  gap: 4px;
}

.cable-label {
  pointer-events: none;
  overflow: visible;
}

.cable-label-pill {
  display: inline-block;
  transform: translate(-50%, -50%);
  max-width: 120px;
  padding: 3px 7px;
  border: 1px solid rgba(45, 55, 70, .35);
  border-radius: 8px;
  background: rgba(255, 255, 255, .84);
  color: #1f2937;
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}

/* Compact SVG map toolbar */
.map-tools .icon-tool {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 6px;
  border-radius: 5px;
  line-height: 1;
}

.map-tools .icon-tool svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.map-tools .icon-tool svg .icon-fill {
  fill: currentColor;
  stroke: none;
}

.map-tools .icon-tool:hover:not(:disabled),
.map-tools .icon-tool:focus-visible:not(:disabled) {
  background: #e8eef8;
  border-color: #7891b8;
  color: #123d84;
}

#cableDrawBtn {
  min-width: 34px;
  padding: 6px;
  font-weight: inherit;
}


.jobs-modal {
  position: fixed; inset: 0; z-index: 1200; display: none;
  align-items: center; justify-content: center; padding: 24px;
  background: rgba(15, 23, 42, .62);
}
.jobs-modal.is-open { display: flex; }
.jobs-modal-card {
  width: min(820px, 96vw); max-height: 90vh; overflow: auto;
  background: #fff; border-radius: 14px; box-shadow: 0 22px 65px rgba(0,0,0,.28); padding: 22px;
}
.job-save-form {
  display: grid; grid-template-columns: 1.2fr 1fr 1.2fr auto; gap: 10px; align-items: end; margin: 18px 0;
}
.job-save-form label { display: grid; gap: 5px; font-size: 12px; font-weight: 700; color: #334155; }
.job-save-form input { min-width: 0; padding: 9px 10px; border: 1px solid #cbd5e1; border-radius: 7px; }
.jobs-modal-status { padding: 10px 0; color: #475569; font-size: 13px; }
.saved-jobs-list { display: grid; gap: 9px; margin: 4px 0 18px; }
.saved-job-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid #dbe3ec; border-radius: 9px; background: #f8fafc; }
.saved-job-row.is-active { border-color: #2563eb; box-shadow: inset 3px 0 #2563eb; }
.saved-job-title { font-weight: 800; color: #0f172a; }
.saved-job-meta { margin-top: 3px; color: #64748b; font-size: 12px; }
.saved-job-actions { display: flex; gap: 7px; }
@media (max-width: 800px) { .job-save-form { grid-template-columns: 1fr; } .saved-job-row { grid-template-columns: 1fr; } }
