:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef4f7;
  --ink: #17202b;
  --muted: #607080;
  --line: #d9e2ea;
  --brand: #0f7a45;
  --brand-2: #105f84;
  --warn: #b7791f;
  --bad: #b42318;
  --ok: #167348;
  --shadow: 0 16px 40px rgba(20, 34, 52, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.app { min-width: 0; min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { min-width: 0; background: #111a23; color: #eef7f2; padding: 22px 18px; display: flex; flex-direction: column; gap: 22px; }
.brand { min-width: 0; display: flex; align-items: center; gap: 12px; }
.brand img { width: 46px; height: 46px; object-fit: contain; background: white; border-radius: 8px; padding: 5px; }
.brand h1 { font-size: 18px; line-height: 1.1; margin: 0; }
.brand p { margin: 3px 0 0; color: #abc2d0; font-size: 12px; }
.nav { min-width: 0; max-width: 100%; display: grid; gap: 8px; }
.nav button { color: #dce8ef; background: transparent; border-radius: 8px; padding: 11px 12px; text-align: left; display: flex; gap: 10px; align-items: center; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.1); color: white; }
.sidebar-footer { margin-top: auto; color: #abc2d0; font-size: 12px; line-height: 1.5; }
.main { min-width: 0; padding: 28px; overflow: hidden; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 22px; }
.topbar h2 { margin: 0; font-size: 28px; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.hero { position: relative; min-height: 230px; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow); margin-bottom: 18px; background: #18342d; }
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .38; }
.hero-content { position: relative; padding: 28px; max-width: 740px; color: white; }
.hero h3 { margin: 0 0 10px; font-size: 34px; line-height: 1.05; }
.hero p { color: #e5f1ec; line-height: 1.5; margin: 0 0 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.panel, .card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 22px rgba(30, 45, 60, .06); }
.panel { padding: 18px; }
.card { padding: 16px; }
.metric { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.metric strong { display: block; font-size: 28px; }
.metric span { color: var(--muted); font-size: 13px; }
.icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); color: var(--brand-2); }
.btn { min-height: 40px; border-radius: 8px; padding: 0 14px; background: var(--brand); color: white; font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.secondary { background: #e6eef3; color: #183242; }
.btn.warn { background: var(--warn); }
.btn.bad { background: var(--bad); }
.btn.ghost { background: transparent; color: var(--brand-2); border: 1px solid var(--line); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.list { display: grid; gap: 10px; }
.survey-row { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.row-title { font-weight: 750; margin-bottom: 4px; }
.row-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 10px; }
.badge { display: inline-flex; align-items: center; min-height: 24px; border-radius: 999px; padding: 0 9px; font-size: 12px; font-weight: 700; background: #e7f1eb; color: var(--ok); }
.badge.warn { background: #fff4dc; color: #946200; }
.badge.bad { background: #fee4e2; color: var(--bad); }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.full-field { margin-top: 14px; }
label { color: #34495b; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; background: white; color: var(--ink); }
textarea { min-height: 92px; resize: vertical; }
.table-editor { display: grid; gap: 8px; margin: 10px 0 18px; overflow-x: auto; }
.table-head, .table-row { display: grid; gap: 8px; min-width: 760px; align-items: center; }
.table-head { color: var(--muted); font-size: 12px; font-weight: 800; }
.table-head.four, .table-row.four { grid-template-columns: 1.3fr 1fr 1fr 1fr; }
.table-head.three, .table-row.three { grid-template-columns: 1.2fr 110px 1.5fr; }
.table-head.measurement, .table-row.measurement { grid-template-columns: 1.1fr 1.8fr 1fr 1fr 1fr 1.1fr 1.5fr; }
.table-head.boards, .table-row.boards { grid-template-columns: 52px repeat(6, 120px) 160px; }
.table-row { padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fbfdff; }
.table-row strong { font-size: 12px; color: #273849; }
.table-row input, .table-row select { min-height: 34px; padding: 7px 8px; font-size: 12px; }
.inventory-alert { min-height: 34px; border-radius: 8px; padding: 6px 8px; display: grid; gap: 2px; border: 1px solid var(--line); }
.inventory-alert strong { font-size: 10px; }
.inventory-alert span { font-size: 11px; line-height: 1.2; }
.inventory-alert.ok { background: #f0f7f3; border-color: #cfe7d8; color: var(--ok); }
.inventory-alert.bad { background: #fff4f2; border-color: #f2b8b3; color: var(--bad); }
.diagram-upload { margin: 18px 0; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #f8fbfc; }
.diagram-upload-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.diagram-upload-head h3 { margin: 0; font-size: 17px; }
.diagram-upload-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.diagram-file-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; margin-top: 14px; }
.diagram-file-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; margin-top: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.diagram-file-summary strong, .diagram-file-summary span { display: block; overflow-wrap: anywhere; }
.diagram-file-summary span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.diagram-file-summary .toolbar { margin: 0; justify-content: flex-end; }
.diagram-quality { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.diagram-quality strong { font-size: 13px; }
.diagram-quality ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.diagram-quality.ok { border-color: #cfe7d8; background: #f7fbf8; }
.diagram-quality.warn { border-color: #ecd6a5; background: #fffaf0; }
.diagram-quality.bad { border-color: #f2b8b3; background: #fff7f6; }
.compact-empty { padding: 16px; margin-top: 12px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 12px; }
.tab { white-space: nowrap; border-radius: 8px; padding: 10px 12px; background: #e9f0f5; color: #355064; font-weight: 700; }
.tab.active { background: var(--brand-2); color: white; }
.step-body { min-height: 420px; }
.check-row { display: grid; grid-template-columns: minmax(220px, 1fr) 100px minmax(180px, .9fr) minmax(210px, .8fr); gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check-evidence { min-width: 0; display: grid; gap: 7px; }
.check-evidence-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.check-evidence-actions .btn { min-height: 32px; padding: 4px 7px; font-size: 11px; }
.check-evidence small { color: var(--muted); font-size: 11px; }
.check-photo-preview { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; align-items: center; gap: 7px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #f8fbfc; }
.check-photo-preview img { width: 54px; height: 42px; object-fit: cover; border-radius: 5px; }
.check-photo-preview span { color: var(--muted); font-size: 11px; }
.check-photo-preview .btn { min-height: 30px; padding: 3px 7px; font-size: 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.photo-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photo-card .mini { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.35; }
.photo-card-title { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-top: 8px; }
.technical-photo-capture { margin: 18px 0; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #f8fbfc; }
.technical-photo-head { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.technical-photo-head h3 { margin: 0; font-size: 17px; }
.technical-photo-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.technical-photo-form { margin-top: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.technical-photo-form .toolbar { margin: 14px 0 0; }
.technical-photo-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.technical-photo-slot { min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: white; }
.technical-photo-slot img, .technical-photo-placeholder { width: 100%; aspect-ratio: 4/3; border-radius: 6px; border: 1px solid var(--line); }
.technical-photo-slot img { object-fit: cover; }
.technical-photo-placeholder { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.technical-photo-caption { display: grid; gap: 6px; margin-top: 8px; }
.technical-photo-caption strong { font-size: 12px; line-height: 1.25; }
.technical-photo-caption .badge { justify-self: start; }
.technical-photo-slot small { display: block; margin-top: 6px; color: var(--muted); line-height: 1.3; }
.linked-photo-button { min-height: 30px; margin-top: 7px; padding: 4px 8px; font-size: 11px; text-align: left; justify-content: flex-start; }
.existence-label { min-width: 0; display: grid; align-content: center; }
.summary { background: #f0f7f3; border: 1px solid #cfe7d8; color: #183f2b; padding: 14px; border-radius: 8px; }
.summary-list { display: grid; gap: 8px; margin: 14px 0; }
.summary-list div { display: grid; gap: 2px; padding: 10px; background: #f7fafc; border: 1px solid var(--line); border-radius: 8px; }
.summary-list span, .mini-warning { color: var(--muted); font-size: 12px; }
.export-card p { color: var(--muted); line-height: 1.45; }
.validation-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.validation-list div { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 3px; background: #fbfdff; }
.validation-list div.ok { border-color: #cfe7d8; background: #f7fbf8; }
.validation-list div.bad { border-color: #f4c7c3; background: #fff7f6; }
.validation-list strong { font-size: 12px; color: var(--brand); }
.validation-list .bad strong { color: var(--bad); }
.validation-list span { color: var(--muted); font-size: 12px; }
.backend-grid { margin-top: 16px; }
.backend-list { display: grid; gap: 10px; }
.backend-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; }
.backend-error { border-color: #f2b8b3; background: #fff7f6; color: var(--bad); margin-bottom: 16px; }
.signature-panel { margin-top: 16px; }
.signature-box { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.signature-box canvas { width: 100%; height: 220px; display: block; touch-action: none; cursor: crosshair; }
.signed-preview { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px; border: 1px solid #cfe7d8; border-radius: 8px; background: #f7fbf8; }
.signed-preview img { width: 180px; height: 54px; object-fit: contain; background: white; border: 1px solid var(--line); border-radius: 6px; }
.report-preview { max-height: 620px; overflow: auto; background: white; border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.report-preview .report { max-width: 980px; margin: 0 auto; color: #17202b; font-family: Arial, sans-serif; }
.report-preview .report-header-table { width: 100%; table-layout: fixed; border-collapse: collapse; border-bottom: 3px solid var(--brand); margin-bottom: 14px; }
.report-preview .report-header-table td { border: 0; padding: 0 0 12px; vertical-align: middle; background: white; }
.report-preview .report-logo-cell { width: 174px; }
.report-preview .report-logo { width: 154px; height: 50px; display: block; object-fit: contain; }
.report-preview .report-title-cell { padding-left: 10px !important; }
.report-preview .report-title-cell p { margin: 5px 0 0; }
.report-preview .report-folio-cell { width: 120px; text-align: right; white-space: nowrap; }
.report-preview h1 { margin: 0; font-size: 22px; }
.report-preview h2 { margin: 18px 0 9px; font-size: 16px; color: var(--brand-2); }
.report-preview p { line-height: 1.45; }
.report-preview .report-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.report-preview .report-grid div { border: 1px solid var(--line); padding: 8px; border-radius: 6px; }
.report-preview span, .report-preview small { display: block; color: var(--muted); font-size: 11px; }
.report-preview table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-preview th, .report-preview td { border: 1px solid var(--line); padding: 7px; text-align: left; vertical-align: top; }
.report-preview th { background: var(--surface-2); }
.report-preview .photo-strip { display: none; }
.report-preview .signature-line { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 18px; }
.report-preview .signature-line > div { border-top: 1px solid var(--ink); padding-top: 8px; text-align: center; min-height: 100px; }
.report-preview .signature-line img { max-width: 100%; height: 72px; object-fit: contain; display: block; margin: 0 auto 8px; }
.report-preview .blank-signature { height: 72px; }
.report-preview footer { margin-top: 18px; color: var(--muted); font-size: 11px; }
.hidden { display: none !important; }
.empty { color: var(--muted); text-align: center; padding: 30px; border: 1px dashed var(--line); border-radius: 8px; }
.portal { min-height: 100vh; padding: 28px; display: grid; align-content: start; gap: 18px; background: linear-gradient(180deg, #edf5f2 0%, #f7fafc 48%, #eef4f7 100%); }
.portal-hero { min-height: 220px; border-radius: 8px; background: #111a23; color: white; padding: 28px; display: flex; align-items: center; gap: 22px; box-shadow: var(--shadow); }
.portal-hero.compact { min-height: 120px; justify-content: space-between; }
.portal-hero img { width: 86px; height: 86px; object-fit: contain; background: white; border-radius: 8px; padding: 9px; flex: 0 0 auto; }
.portal-hero h1 { margin: 0; font-size: 38px; line-height: 1.05; }
.portal-hero p { margin: 8px 0 0; color: #dbe9ef; max-width: 680px; line-height: 1.45; }
.portal-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.portal-card { min-height: 122px; text-align: left; background: white; border: 1px solid var(--line); border-radius: 8px; padding: 18px; display: grid; align-content: start; gap: 8px; box-shadow: 0 8px 22px rgba(30, 45, 60, .06); color: var(--ink); }
.portal-card strong { font-size: 18px; }
.portal-card span { color: var(--muted); line-height: 1.4; }
.portal-card.active, .portal-card:hover { border-color: var(--brand); box-shadow: 0 12px 28px rgba(15, 122, 69, .14); }
.portal-login { max-width: 960px; width: 100%; justify-self: center; }
.portal-login h2 { margin: 0 0 6px; }
.portal-login p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }
.portal-submit { margin-top: 16px; }
.report-access { background: var(--bg); }

@media (max-width: 900px) {
  .app { width: 100%; grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; z-index: 2; padding: 12px; }
  .brand p, .sidebar-footer { display: none; }
  .nav { width: 100%; grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; }
  .nav button { white-space: nowrap; }
  .main { padding: 16px; }
  .topbar { align-items: start; flex-direction: column; }
  .grid.cols-3, .grid.cols-2, .form-grid, .photo-grid { grid-template-columns: 1fr; }
  .report-preview .report-grid, .report-preview .signature-line { grid-template-columns: 1fr; }
  .report-preview .report-logo-cell { width: 120px; }
  .report-preview .report-logo { width: 108px; height: 35px; }
  .report-preview .report-folio-cell { width: 86px; }
  .validation-list { grid-template-columns: 1fr; }
  .backend-row { grid-template-columns: 1fr; }
  .survey-row, .check-row { grid-template-columns: 1fr; }
  .hero h3 { font-size: 28px; }
  .portal { padding: 14px; }
  .portal-hero { min-height: auto; align-items: flex-start; flex-direction: column; padding: 20px; }
  .portal-hero.compact { align-items: flex-start; }
  .portal-hero h1 { font-size: 30px; }
  .portal-options { grid-template-columns: 1fr; }
  .technical-photo-head { flex-direction: column; }
  .technical-photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .diagram-upload-head, .diagram-file-summary { grid-template-columns: 1fr; display: grid; }
  .diagram-file-control { grid-template-columns: 1fr; }
  .diagram-file-summary .toolbar { justify-content: flex-start; }
}

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