:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --ink: #1f2726;
  --muted: #697672;
  --line: #d7dfdc;
  --brand-blue: #202986;
  --brand-blue-strong: #151b66;
  --brand-steel: #91b5c0;
  --accent: var(--brand-blue);
  --accent-strong: var(--brand-blue-strong);
  --accent-soft: #e5edf7;
  --warning: #b74e2a;
  --shadow: 0 18px 50px rgba(22, 35, 33, 0.12);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(32, 41, 134, 0.08), transparent 310px),
    var(--bg);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 42vw);
  gap: 20px;
  width: min(1580px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.workspace {
  min-width: 0;
}

.topbar,
.preview-toolbar,
.panel,
.report-preview {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(215, 223, 220, 0.9);
  box-shadow: var(--shadow);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  min-height: 90px;
  padding: 18px 20px;
  border-radius: 8px;
}

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

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

.eyebrow,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.eyebrow {
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

h1 {
  margin-top: 4px;
  font-size: clamp(1.55rem, 2.3vw, 2.25rem);
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 0.95rem;
}

.topbar-actions,
.row-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  justify-self: end;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.ghost-button,
.file-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 14px;
  font-weight: 700;
  text-decoration: none;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.file-button {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: #bddfd8;
}

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

.compact {
  min-height: 36px;
  padding-inline: 12px;
  font-size: 0.9rem;
}

.icon-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  color: var(--muted);
  background: #fff;
  border-color: var(--line);
}

.icon-button:hover,
.ghost-button:hover {
  border-color: #aebbb7;
}

.danger:hover {
  color: #fff;
  background: var(--warning);
  border-color: var(--warning);
}

.signature-panel,
.history-panel,
.integration-panel {
  grid-column: 1 / -1;
}

.form-grid {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.panel {
  min-width: 0;
  padding: 18px;
  border-radius: 8px;
}

.project-panel,
.panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.section-heading {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding-bottom: 2px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.span-2,
.actions-panel,
.photos-panel {
  grid-column: 1 / -1;
}

label,
th {
  color: #33403d;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
}

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

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
.photo-stage:focus-visible,
button:focus-visible,
.file-button:focus-within {
  outline: 3px solid rgba(32, 41, 134, 0.22);
  outline-offset: 2px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.range-row input {
  padding: 0;
}

.range-row output {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 7px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 800;
}

.table-wrap {
  grid-column: 1 / -1;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.action-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
}

.action-table th,
.action-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.action-table tr:last-child td {
  border-bottom: 0;
}

.action-table th:nth-child(1) {
  width: 36%;
}

.action-table th:nth-child(2) {
  width: 22%;
}

.action-table th:nth-child(3) {
  width: 18%;
}

.action-table th:nth-child(4) {
  width: 18%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.photo-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 16px;
}

.signature-pad-wrap {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, transparent calc(100% - 42px), rgba(32, 41, 134, 0.08) calc(100% - 42px)),
    #fff;
  overflow: hidden;
}

.signature-canvas {
  display: block;
  width: 100%;
  height: 180px;
  touch-action: none;
  cursor: crosshair;
}

.history-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.history-empty,
.integration-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.history-title strong,
.history-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-card {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(240px, 0.65fr);
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.photo-header {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: center;
}

.photo-title {
  font-weight: 800;
}

.photo-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 280px;
  overflow: hidden;
  border: 1px solid #c7d2cf;
  border-radius: 8px;
  padding: 0;
  background: #dfe7e4;
}

.image-wrap {
  position: relative;
  display: block;
  max-width: 100%;
}

.photo-stage img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  pointer-events: none;
}

.marker-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: var(--warning);
  box-shadow: 0 6px 18px rgba(31, 39, 38, 0.26);
  font-size: 0.78rem;
  font-weight: 900;
}

.photo-meta {
  display: grid;
  gap: 12px;
  align-content: start;
}

.photo-meta label {
  display: grid;
  gap: 7px;
}

.annotation-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.annotation-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: center;
}

.annotation-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #fff;
  background: var(--warning);
  font-weight: 900;
}

.report-preview {
  position: sticky;
  top: 18px;
  align-self: start;
  height: calc(100vh - 36px);
  overflow: auto;
  border-radius: 8px;
}

.preview-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-width: 0 0 1px;
  box-shadow: none;
}

.report-document {
  width: min(100%, 900px);
  margin: 0 auto;
  padding: 26px;
  background: #fff;
}

.report-cover {
  display: grid;
  gap: 10px;
  padding-bottom: 20px;
  border-bottom: 3px solid var(--accent);
}

.report-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.report-brand img {
  display: block;
  width: min(260px, 55%);
  height: auto;
  object-fit: contain;
}

.report-cover h2 {
  font-size: 1.8rem;
}

.report-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.meta-box {
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.meta-box span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-box strong {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 5px;
  word-break: break-word;
}

.health-pill {
  width: fit-content;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.health-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
}

.health-green .health-dot {
  background: #1f8a4c;
}

.health-yellow .health-dot {
  background: #d39b15;
}

.health-red .health-dot {
  background: #c43c32;
}

.report-section {
  margin-top: 22px;
  break-inside: avoid;
}

.report-section h3 {
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
  color: var(--accent-strong);
}

.report-text {
  margin: 10px 0 0;
  white-space: pre-wrap;
}

.empty-text {
  color: var(--muted);
  font-style: italic;
}

.report-table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.report-table th,
.report-table td {
  padding: 8px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.report-photo {
  margin-top: 16px;
  break-inside: avoid;
}

.report-photo-frame {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  background: #f2f5f4;
}

.report-photo-frame img {
  display: block;
  max-width: 100%;
  max-height: 520px;
}

.report-photo-frame .marker {
  width: 24px;
  height: 24px;
  font-size: 0.72rem;
}

.report-annotations {
  margin: 8px 0 0;
  padding-left: 22px;
}

.report-annotations li {
  margin: 4px 0;
}

.report-signature-image {
  display: block;
  width: min(360px, 100%);
  height: auto;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .report-preview {
    position: static;
    height: auto;
  }
}

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

  .topbar,
  .row-heading,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .row-heading {
    width: 100%;
  }

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

  .brand-logo {
    width: min(280px, 80vw);
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .file-button {
    width: 100%;
  }

  .project-panel,
  .panel {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

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

  .report-meta {
    grid-template-columns: 1fr;
  }

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

@page {
  size: letter;
  margin: 0.45in;
}

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

  .workspace,
  .preview-toolbar {
    display: none !important;
  }

  .app-shell {
    display: block;
    width: auto;
    min-height: 0;
    padding: 0;
  }

  .report-preview {
    position: static;
    height: auto;
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .report-document {
    width: 100%;
    padding: 0;
  }

  .report-cover h2 {
    font-size: 1.45rem;
  }

  .report-section {
    margin-top: 16px;
  }
}
