:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1d1f23;
  --muted: #6b6f76;
  --line: #dedbd4;
  --accent: #d2421f;
  --accent-ink: #ffffff;
  --accent-soft: #fbe7e1;
  --focus: #1f6fd2;
  --radius: 8px;
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

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

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

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

[hidden] {
  display: none !important;
}

/* ---- Buttons ---------------------------------------------------------- */

.btn {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  border-color: #b9b5ab;
}

.btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
.editable:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  border-color: #a8341a;
  background: #b9391b;
}

.btn-primary.active {
  background: #8f2b14;
}

.btn-icon {
  width: 34px;
  justify-content: center;
  padding: 7px 0;
  font-size: 18px;
  line-height: 1;
}

.btn-danger {
  color: #a1260c;
}

.btn-small {
  font-size: 13px;
  padding: 4px 9px;
}

/* ---- Header ----------------------------------------------------------- */

.topbar {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 20px 24px 12px;
}

.topbar h1 {
  font-size: 24px;
  line-height: 1.2;
}

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

.banner {
  margin: 0 24px 12px;
  padding: 8px 12px;
  background: #fff6d6;
  border: 1px solid #ecd98b;
  border-radius: var(--radius);
  font-size: 14px;
}

.description-wrap {
  margin: 0 24px 12px;
}

.description {
  max-width: 80ch;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.5;
}

.editing .editable {
  border-radius: 4px;
  cursor: text;
  min-height: 1.2em;
}

.editing .editable:hover {
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}

.editing .editable:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

/* ---- Layout ----------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  padding: 0 24px 24px;
  align-items: start;
}

.viewer,
.points {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.viewer {
  position: sticky;
  top: 12px;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 6px 6px 0;
}

.tab {
  font: inherit;
  font-size: 14px;
  border: 1px solid transparent;
  border-bottom: none;
  background: none;
  padding: 8px 12px;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  white-space: nowrap;
  color: var(--muted);
}

.tab.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  margin-bottom: -1px;
  font-weight: 600;
}

.tab .count {
  font-weight: 400;
  color: var(--muted);
  margin-left: 4px;
}

.tab-add {
  color: var(--accent);
}

.viewer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.viewer-tools .spacer {
  flex: 1;
}

.zoom-label {
  min-width: 46px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.stage {
  overflow: auto;
  max-height: calc(100vh - 150px);
  background: #eceae5;
}

.sheet {
  position: relative;
  width: 100%;
  margin: 0 auto;
  user-select: none;
}

.sheet img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

.placing .sheet {
  cursor: crosshair;
}

.markers {
  position: absolute;
  inset: 0;
}

.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
  font:
    600 11px/20px system-ui,
    sans-serif;
  text-align: center;
  cursor: pointer;
  touch-action: none;
}

.marker.selected {
  background: #1d1f23;
  transform: translate(-50%, -50%) scale(1.2);
  z-index: 2;
}

.editing .marker {
  cursor: grab;
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* ---- Points ----------------------------------------------------------- */

.points-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.points-head h2 {
  font-size: 16px;
}

.point-list {
  display: flex;
  flex-direction: column;
}

.point {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 12px;
}

.point:last-child {
  border-bottom: none;
}

.point.selected {
  background: var(--accent-soft);
}

.point-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.badge {
  flex: none;
  min-width: 30px;
  height: 24px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font:
    600 13px/24px system-ui,
    sans-serif;
  text-align: center;
  cursor: pointer;
  border: none;
  padding: 0 6px;
}

.point-text {
  flex: 1;
  min-width: 0;
}

.point-title {
  font-size: 15px;
  font-weight: 600;
}

.point-construction {
  font-size: 14px;
  margin-top: 2px;
}

.point-construction .label,
.field-label {
  color: var(--muted);
  font-size: 12px;
}

.point-comment {
  font-size: 14px;
  margin-top: 6px;
  white-space: pre-wrap;
}

.field {
  display: block;
  margin-top: 6px;
}

.field input,
.field textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.field textarea {
  min-height: 52px;
  resize: vertical;
}

.photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: #e9e7e2;
}

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

.photo .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border-radius: 11px;
  border: none;
  background: rgb(0 0 0 / 0.6);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 22px;
  padding: 0;
}

.point-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  align-items: center;
}

.point-actions .spacer {
  flex: 1;
}

.upload-status {
  font-size: 13px;
  color: var(--muted);
}

/* ---- Lightbox --------------------------------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgb(15 15 17 / 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 50;
  padding: 16px;
}

.lightbox figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: min(1400px, calc(100vw - 120px));
}

.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 110px);
  object-fit: contain;
  background: #222;
}

.lightbox figcaption {
  display: flex;
  gap: 10px;
  align-items: center;
  color: #eee;
  font-size: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.lightbox .lb-caption {
  font: inherit;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #222;
  color: #eee;
  min-width: 260px;
}

.lb-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

/* ---- Toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #1d1f23;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 60;
  max-width: calc(100vw - 32px);
}

/* ---- Small screens ---------------------------------------------------- */

@media (max-width: 900px) {
  .topbar {
    padding: 14px 16px 10px;
  }
  .banner,
  .description-wrap {
    margin-left: 16px;
    margin-right: 16px;
  }
  .layout {
    grid-template-columns: 1fr;
    padding: 0 16px 16px;
  }
  .viewer {
    position: static;
  }
  .stage {
    max-height: 70vh;
  }
  .marker {
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 16px;
  }
  .lightbox .lb-prev,
  .lightbox .lb-next {
    position: absolute;
    bottom: 16px;
  }
  .lightbox .lb-prev {
    left: 16px;
  }
  .lightbox .lb-next {
    right: 16px;
  }
  .lightbox figure {
    max-width: 100%;
  }
}

/* ---- Print / PDF ------------------------------------------------------ */

.print-view {
  display: none;
}

@page {
  size: A4;
  margin: 14mm 12mm;
}

@media print {
  body {
    background: #fff;
  }
  #app,
  .lightbox,
  .toast {
    display: none !important;
  }
  .print-view {
    display: block;
    font-size: 11pt;
    color: #000;
  }
  .pv-cover h1 {
    font-size: 20pt;
  }
  .pv-cover p {
    margin-top: 4pt;
  }
  .pv-meta {
    color: #555;
  }
  .pv-description {
    white-space: pre-wrap;
    margin-top: 10pt;
  }
  .pv-drawing {
    break-before: page;
  }
  .pv-drawing h2,
  .pv-point h3 {
    font-size: 13pt;
    margin-bottom: 6pt;
  }
  .pv-drawing .sheet {
    width: 100%;
    border: 0.5pt solid #999;
  }
  .pv-drawing .marker {
    min-width: 18px;
    height: 18px;
    font-size: 9px;
    line-height: 14px;
    border-width: 1.5px;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .pv-legend {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8pt;
    font-size: 9.5pt;
  }
  .pv-legend th,
  .pv-legend td {
    text-align: left;
    border-bottom: 0.5pt solid #bbb;
    padding: 3pt 4pt;
    vertical-align: top;
  }
  .pv-points-start {
    break-before: page;
  }
  .pv-point {
    break-inside: avoid-page;
    margin-bottom: 14pt;
    padding-bottom: 10pt;
    border-bottom: 0.5pt solid #bbb;
  }
  .pv-point p {
    margin-top: 2pt;
  }
  .pv-photos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6pt;
    margin-top: 6pt;
  }
  .pv-photos figure {
    margin: 0;
    break-inside: avoid;
  }
  .pv-photos img {
    width: 100%;
    max-height: 90mm;
    object-fit: contain;
    background: #f2f2f2;
  }
  .pv-photos figcaption {
    font-size: 8.5pt;
    color: #444;
  }
}
