:root {
  --ink: #111827;
  --muted: #667085;
  --line: #d8dee9;
  --line-strong: #b8c2d3;
  --paper: #ffffff;
  --wash: #f3f6fb;
  --soft: #eef3f9;
  --brand: #155eef;
  --brand-dark: #103db7;
  --ok: #087443;
  --warn: #b54708;
  --bad: #b42318;
  --shadow: 0 18px 42px rgba(16, 24, 40, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 980px;
  color: var(--ink);
  background: var(--wash);
}

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

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.app-header {
  height: 64px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

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

.logo {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #102a43;
  color: white;
  font-weight: 850;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  width: 300px;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #344054;
  font-weight: 700;
}

.tab.active {
  background: var(--paper);
  color: var(--brand);
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.12);
}

.header-actions,
.row-actions,
.panel-actions,
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-status {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.btn,
.btn-primary,
.btn-danger,
.icon-btn {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 13px;
  background: var(--paper);
  color: #344054;
  font-weight: 750;
}

.btn-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-danger {
  border-color: #f2b8b5;
  background: #fff5f5;
  color: var(--bad);
}

.icon-btn {
  width: 36px;
  padding: 0;
}

.main {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 18px;
  padding: 18px;
}

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

.sidebar,
.panel,
.report-paper {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.sidebar {
  min-height: calc(100vh - 100px);
  padding: 14px;
}

.sidebar h2,
.panel h2 {
  margin: 0;
  font-size: 17px;
}

.sidebar-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.template-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.template-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  padding: 11px;
  text-align: left;
}

.template-card.active {
  border-color: var(--brand);
  background: #f4f7ff;
}

.template-card strong {
  display: block;
  margin-bottom: 4px;
  line-height: 1.25;
}

.template-card span,
.meta,
.hint,
small {
  color: var(--muted);
}

.content {
  min-width: 0;
}

.home-grid,
.inspection-list {
  display: grid;
  gap: 12px;
}

.home-grid {
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}

.home-card,
.inspection-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  background: white;
}

.home-card h3,
.inspection-card h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

.home-card p,
.inspection-card p {
  min-height: 40px;
  margin: 0 0 12px;
  color: #475467;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.card-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--soft);
  color: #344054;
  font-size: 12px;
  font-weight: 750;
}

.card-actions,
.inspection-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.inspection-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
}

.inspection-main {
  min-width: 0;
}

.panel {
  overflow: hidden;
}

.panel-head {
  padding: 16px;
}

.panel-body {
  padding: 16px;
}

.template-form {
  display: grid;
  grid-template-columns: 1fr 180px 170px 140px;
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 9px 10px;
  background: white;
  color: var(--ink);
}

textarea {
  min-height: 76px;
  resize: vertical;
}

.section {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
  overflow: hidden;
}

.section-title {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.question {
  display: grid;
  grid-template-columns: 34px minmax(260px, 1fr) 230px 92px 128px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.question.dragging {
  opacity: 0.5;
}

.question.drag-over {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
  background: #f4f7ff;
}

.question.logic-child {
  margin-left: 28px;
  border-left: 3px solid var(--brand);
  background: #fbfdff;
}

.question:last-child {
  border-bottom: 0;
}

.required-row {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

.required-row input {
  width: auto;
}

.question-list {
  display: grid;
}

.drag-handle {
  width: 34px;
  height: 38px;
  border: 0;
  background: transparent;
  color: #8290a6;
  font-weight: 900;
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.compact-actions {
  justify-content: flex-end;
  gap: 5px;
}

.compact-actions .icon-btn {
  width: 34px;
}

.logic-rule {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 28px;
  padding: 9px 12px 9px 48px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  background: #f8fbff;
  color: #344054;
  font-size: 13px;
}

.logic-rule select {
  width: auto;
  min-width: 92px;
  padding: 5px 8px;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 750;
}

.conduct-layout {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 360px;
  gap: 18px;
}

.inspection-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.answer-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  background: white;
}

.answer-card.missing {
  border-left: 4px solid var(--bad);
}

.answer-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  margin-bottom: 10px;
}

.answer-top strong {
  line-height: 1.35;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--soft);
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.badge.fail {
  background: #fff1f0;
  color: var(--bad);
}

.badge.pass {
  background: #ecfdf3;
  color: var(--ok);
}

.answer-controls {
  display: grid;
  gap: 8px;
}

.location-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.checkbox-answer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

.checkbox-answer input {
  width: auto;
}

.instruction {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #f8fafc;
  color: #344054;
}

.notice {
  border: 1px solid #b8d7ff;
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: #f2f7ff;
  color: #1849a9;
  font-weight: 700;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
}

.choice {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: white;
  font-weight: 800;
}

.choice.active {
  border-color: var(--brand);
  background: #edf3ff;
  color: var(--brand);
}

.summary {
  position: sticky;
  top: 18px;
  align-self: start;
  padding: 16px;
}

.score {
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 14px;
  align-items: center;
}

.score-ring {
  width: 94px;
  height: 94px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--brand) var(--score), #e8edf5 0);
  font-size: 22px;
  font-weight: 900;
}

.score-ring span {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: white;
}

.summary-list {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: white;
}

.report-card h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.report-paper {
  max-width: 920px;
  margin: 0 auto;
  padding: 34px;
  box-shadow: var(--shadow);
}

.report-cover {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  border-bottom: 3px solid #102a43;
  padding-bottom: 18px;
  margin-bottom: 20px;
}

.report-cover h1 {
  margin: 0 0 10px;
  font-size: 28px;
  letter-spacing: 0;
}

.report-logo {
  width: 94px;
  height: 94px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #102a43;
  color: white;
  font-weight: 900;
}

.report-facts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.fact {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #f8fafc;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.fact strong {
  display: block;
  margin-top: 4px;
}

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

.report-section h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
}

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

.report-table th {
  background: #f1f5f9;
}

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

.hidden {
  display: none;
}

@media print {
  body {
    min-width: 0;
    background: white;
  }

  .app-header,
  .sidebar,
  .panel-head,
  .no-print {
    display: none !important;
  }

  .main,
  .content {
    display: block;
    padding: 0;
  }

  .panel,
  .report-paper {
    border: 0;
    box-shadow: none;
  }

  .panel-body {
    padding: 0;
  }

  .report-paper {
    max-width: none;
    margin: 0;
    padding: 0;
  }
}

/* Feature pass: template controls, response sets, signatures, locations, and completion/score split */
.tabs {
  grid-template-columns: repeat(3, 1fr);
  width: 420px;
}

.sync-status.ok,
.save-status.ok {
  color: var(--ok);
}

.sync-status.bad,
.save-status.bad {
  color: var(--bad);
}

.sync-status.warn,
.save-status.warn {
  color: var(--warn);
}

.save-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

button:disabled,
.btn:disabled,
.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

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

.question {
  grid-template-columns: 34px minmax(240px, 1.2fr) 190px 180px 92px 138px;
}

.logic-rule {
  flex-wrap: wrap;
}

.logic-rule strong {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logic-rule input,
.logic-rule select,
.logic-value-input {
  width: auto;
  min-width: 140px;
  padding: 5px 8px;
}

.response-set-grid {
  display: grid;
  gap: 14px;
}

.response-set-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.response-set-head {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 12px;
}

.response-values {
  display: grid;
  gap: 8px;
}

.response-value-row {
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 8px;
}

.score-stack {
  display: grid;
  gap: 14px;
}

.small-score .score-ring {
  width: 72px;
  height: 72px;
  font-size: 17px;
}

.small-score .score-ring span {
  width: 54px;
  height: 54px;
}

.notice.warn {
  border-color: #fedf89;
  background: #fffaeb;
  color: var(--warn);
}

.signature-field,
.media-field,
.location-answer {
  display: grid;
  gap: 8px;
}

.signature-pad-wrap {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.signature-pad-wrap canvas {
  width: 100%;
  height: 180px;
  display: block;
  touch-action: none;
  background: #fff;
}

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

.media-preview,
.location-preview,
.report-media,
.report-location,
.report-signature {
  display: grid;
  gap: 7px;
}

.media-preview img,
.location-preview img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.location-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.location-preview span,
.report-location small,
.report-signature small {
  color: var(--muted);
  font-size: 12px;
}

.report-signature img {
  width: 220px;
  max-height: 90px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.report-media img,
.report-location img {
  width: 240px;
  max-height: 140px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 24, 40, 0.42);
}

.modal-card {
  width: min(480px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 8px;
}

.modal-card p {
  margin: 0 0 18px;
  color: #475467;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1180px) {
  .app-header {
    grid-template-columns: 1fr;
    height: auto;
    padding: 14px;
  }

  .tabs {
    width: 100%;
  }

  .header-actions,
  .panel-actions {
    flex-wrap: wrap;
  }

  .main {
    grid-template-columns: 1fr;
  }

  .question,
  .response-set-head {
    grid-template-columns: 1fr;
  }

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

  .summary {
    position: static;
  }
}

@media print {
  .report-signature img,
  .report-media img,
  .report-location img {
    break-inside: avoid;
  }
}
