:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --ink: #172033;
  --muted: #65726e;
  --line: #d9e1de;
  --teal: #0b1f3a;
  --teal-dark: #07162a;
  --blue: #183b66;
  --amber: #a96f00;
  --red: #b42318;
  --green: #2f7d32;
  --shadow: 0 16px 40px rgba(23, 32, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

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

.brand-logo {
  display: block;
  flex: 0 0 auto;
  width: 82px;
  height: 26px;
  object-fit: contain;
  object-position: left center;
}

.brand h1,
.section-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.15rem, 2vw, 1.55rem);
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.icon-button,
.primary-action,
.file-action,
.tab-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
}

.icon-button:hover,
.tab-button:hover,
.file-action:hover {
  border-color: var(--teal);
  color: var(--teal-dark);
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover {
  background: var(--teal-dark);
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 20px;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.side-panel {
  position: sticky;
  top: 92px;
  align-self: start;
  display: grid;
  gap: 16px;
}

.inspection-status,
.quick-summary,
.main-panel,
.room-panel,
.report-output,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.inspection-status {
  display: grid;
  gap: 8px;
  padding: 16px;
}

.inspection-status span {
  color: var(--muted);
  font-size: 0.9rem;
}

.inspection-status strong {
  width: fit-content;
}

.tab-list {
  display: grid;
  gap: 8px;
}

.tab-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  text-align: left;
}

.tab-button.active {
  border-color: var(--teal);
  background: var(--surface-2);
  color: var(--teal-dark);
  font-weight: 700;
}

.quick-summary {
  padding: 16px;
}

.summary-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.summary-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.summary-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.summary-list dt {
  color: var(--muted);
}

.summary-list dd {
  margin: 0;
  font-weight: 800;
}

.main-panel {
  min-width: 0;
  overflow: hidden;
}

.pane {
  display: none;
  padding: 22px;
}

.pane.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-heading h2 {
  font-size: 1.35rem;
}

.soft-badge,
.risk-pill,
.report-risk {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.soft-badge {
  background: #edf1f5;
  color: #39464f;
}

.risk-ok {
  background: #e9f6ed;
  color: var(--green);
}

.risk-low {
  background: #eff6ff;
  color: var(--blue);
}

.risk-medium {
  background: #fff5dc;
  color: var(--amber);
}

.risk-high,
.risk-critical {
  background: #fff0ee;
  color: var(--red);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

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

.field-wide {
  grid-column: span 2;
}

.field span,
.select-group legend,
.check-list legend {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea,
.image-caption,
.image-select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input,
.field select,
.image-select {
  min-height: 42px;
  padding: 0 10px;
}

.field textarea,
.image-caption {
  resize: vertical;
  padding: 10px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.image-caption:focus,
.image-select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 115, 0.14);
}

.rooms-grid {
  display: grid;
  gap: 16px;
}

.room-panel {
  padding: 18px;
}

.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.room-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-number {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #edf1f5;
  color: var(--teal-dark);
  font-weight: 800;
}

.room-head h3 {
  margin: 0;
  font-size: 1.08rem;
}

.room-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.field-textarea {
  grid-column: span 3;
}

.check-list {
  grid-column: span 3;
  display: grid;
  gap: 10px;
  margin: 0;
  border: 0;
  padding: 0;
}

.pathology-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.check-tile {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
}

.check-tile input {
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
}

.check-tile span {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 600;
}

.room-media {
  display: grid;
  grid-column: span 3;
  gap: 12px;
}

.file-action {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 40px;
  padding: 0 12px;
  color: var(--teal-dark);
  font-weight: 800;
  overflow: hidden;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-strip,
.gallery-grid,
.report-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.image-tile {
  display: grid;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.image-tile img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  object-fit: cover;
  background: #edf1f5;
}

.image-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.image-actions small {
  color: var(--muted);
  font-weight: 700;
}

.danger-action {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #f3c7c1;
  border-radius: 8px;
  background: #fff7f6;
  color: var(--red);
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 34px;
  height: 34px;
}

.report-tools {
  align-items: start;
}

.report-output {
  padding: 28px;
  background: #fff;
}

.report-document {
  display: grid;
  gap: 24px;
  position: relative;
  isolation: isolate;
}

.report-document > :not(.report-watermark) {
  position: relative;
  z-index: 1;
}

.report-watermark {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 0;
  width: min(46%, 460px);
  max-width: 100%;
  height: auto;
  opacity: 0.055;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.report-cover {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  border-bottom: 3px solid var(--teal);
  padding-bottom: 20px;
}

.report-logo {
  display: block;
  width: min(132px, 36vw);
  height: auto;
  margin-bottom: 12px;
}

.report-cover h2 {
  margin: 0;
  color: var(--teal);
  font-size: 1.8rem;
  letter-spacing: 0;
}

.report-cover p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.report-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 20px;
  margin: 14px 0 0;
}

.report-meta div,
.photo-meta {
  display: grid;
  gap: 2px;
}

.report-meta dt,
.photo-meta dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.report-meta dd,
.photo-meta dd {
  margin: 0;
}

.report-section {
  break-inside: avoid;
}

.report-section h3 {
  margin: 0 0 12px;
  border-left: 4px solid var(--teal);
  padding-left: 10px;
  color: var(--teal);
  font-size: 1.18rem;
  letter-spacing: 0;
}

.report-section h4 {
  margin: 18px 0 8px;
  font-size: 1rem;
}

.report-section p {
  margin: 0 0 10px;
}

.report-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
}

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

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

.report-table th {
  background: var(--teal);
  color: #fff;
  font-size: 0.82rem;
}

.room-report {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.room-report:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.room-report ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.room-report li {
  margin-bottom: 4px;
}

.photo-card {
  break-inside: avoid;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
}

.photo-card figcaption {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.signature-grid {
  display: grid;
  grid-template-columns: minmax(260px, 420px);
  justify-content: center;
  gap: 24px;
  margin-top: 40px;
}

.signature-line {
  border-top: 1px solid var(--ink);
  padding-top: 8px;
  text-align: center;
}

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

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

  .side-panel {
    position: static;
  }

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

  .tab-button {
    justify-content: center;
  }

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

  .room-fields,
  .pathology-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-textarea,
  .check-list,
  .room-media {
    grid-column: span 2;
  }

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

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .brand-logo {
    width: 76px;
    height: 24px;
  }

  .top-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .primary-action {
    flex: 1 1 auto;
  }

  .workspace {
    padding: 12px;
  }

  .pane,
  .report-output {
    padding: 16px;
  }

  .tab-list,
  .form-grid,
  .room-fields,
  .pathology-options,
  .report-cover,
  .report-meta,
  .report-summary-grid,
  .signature-grid {
    grid-template-columns: 1fr;
  }

  .field-wide,
  .field-textarea,
  .check-list,
  .room-media {
    grid-column: auto;
  }

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

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  body {
    background: #fff;
    color: #000;
  }

  .topbar,
  .side-panel,
  .section-heading,
  .pane:not(#relatorio) {
    display: none !important;
  }

  .workspace {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .main-panel,
  .pane,
  .report-output,
  .inspection-status,
  .quick-summary {
    display: block !important;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
  }

  .report-document {
    gap: 18px;
    min-height: 269mm;
  }

  .report-watermark {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 128mm;
    opacity: 0.075;
    transform: translate(-50%, -50%);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .report-output {
    font-size: 11pt;
    padding: 14mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .report-cover h2 {
    font-size: 20pt;
  }

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

  .report-section {
    break-inside: avoid;
  }

  .photo-card {
    break-inside: avoid;
  }
}
