:root {
  --ink: #14110c;
  --ink-soft: #3a342c;
  --paper: #f4efe4;
  --paper-2: #ebe3d2;
  --cream: #fbf7ef;
  --line: #d7ccb6;
  --line-strong: #b9ab90;
  --ember: #c2410c;
  --ember-deep: #9a3412;
  --copper: #b45309;
  --gold: #d4a017;
  --forest: #3f6b4a;
  --slate: #2c3539;
  --hazard: #e11d48;
  --warn: #ca8a04;
  --ok: #15803d;
  --low: #4d7c0f;
  --med: #ca8a04;
  --high: #c2410c;
  --crit: #9f1239;
  --shadow: 0 18px 50px rgba(40, 28, 12, 0.18);
  --radius: 14px;
  --mono: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Barlow Condensed", "Barlow", sans-serif;
  --body: "Barlow", "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(212, 160, 23, 0.16), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(194, 65, 12, 0.12), transparent 50%),
    linear-gradient(180deg, #1c1914 0%, #2a241c 40%, #1a1713 100%);
  min-height: 100vh;
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 22px 22px 48px;
}

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 18px 24px;
  align-items: center;
  background: linear-gradient(135deg, #241e16 0%, #3a3226 55%, #2a2218 100%);
  color: #f6edd8;
  border: 1px solid rgba(212, 160, 23, 0.28);
  border-radius: 18px;
  padding: 18px 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.app-header::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: repeating-linear-gradient(
    135deg,
    #111 0 10px,
    #d4a017 10px 20px
  );
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 46px; height: 46px;
  position: relative;
}
.mark-ring {
  position: absolute; inset: 0;
  border: 3px solid #d4a017;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(212, 160, 23, 0.15);
}
.mark-core {
  position: absolute; inset: 12px;
  background: #c2410c;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.brand-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #d4a017;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 32px;
  letter-spacing: 0.14em;
  font-weight: 800;
}
.header-tagline {
  margin: 0;
  font-size: 15px;
  color: #e8dcc0;
  align-self: end;
}
.header-meta {
  display: grid;
  grid-template-columns: 1fr 1fr 110px;
  gap: 8px;
}
.header-meta label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #cbb892;
}
.header-meta input,
.header-meta select {
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(212,160,23,0.3);
  color: #f6edd8;
  border-radius: 8px;
  padding: 7px 9px;
  font: 500 13px var(--body);
}
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  appearance: none;
  border: 0;
  background: #d4a017;
  color: #1a140c;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn.ghost {
  background: transparent;
  color: #f6edd8;
  border: 1px solid rgba(246, 237, 216, 0.28);
}
.btn.accent { background: #c2410c; color: #fff7ed; }
.btn.full { width: 100%; }
.btn.tiny {
  padding: 6px 9px;
  font-size: 11px;
  background: transparent;
  color: var(--ember-deep);
  border: 1px solid var(--line);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  gap: 18px;
  margin-top: 18px;
}

.entry-panel,
.preview-panel,
.register-panel {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.entry-panel { padding: 16px 16px 20px; }
.preview-panel { padding: 16px 16px 22px; overflow: hidden; }
.register-panel { margin-top: 18px; padding: 16px 16px 8px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--paper-2);
}
.panel-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: #c2410c;
  color: #fff7ed;
  padding: 5px 9px;
  border-radius: 999px;
}
.chip.quiet {
  background: var(--paper-2);
  color: var(--ink-soft);
}
.chip.saved { background: var(--forest); }

.field, .field-row { margin-bottom: 12px; }
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > span, .photo-field > span, .scale-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.field-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
input, select, textarea {
  font: 500 14px var(--body);
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(194, 65, 12, 0.35);
  border-color: var(--ember);
}

.risk-block {
  background:
    linear-gradient(180deg, #fff 0%, #f7f1e4 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
}
.risk-block-head h3 {
  margin: 0;
  font-family: var(--display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 16px;
}
.risk-block-head p {
  margin: 4px 0 10px;
  font-size: 12px;
  color: var(--ink-soft);
}
.scale-group { margin-bottom: 10px; }
.scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.scale button {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 10px;
  padding: 8px 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink);
}
.scale button.active {
  background: var(--ember);
  color: #fff7ed;
  border-color: var(--ember);
}
.risk-readout {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  margin: 8px 0 12px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
}
.risk-readout.low { background: #ecfccb; border-color: #65a30d; }
.risk-readout.medium { background: #fef3c7; border-color: #ca8a04; }
.risk-readout.high { background: #ffedd5; border-color: #c2410c; }
.risk-readout.critical { background: #ffe4e6; border-color: #9f1239; }
.risk-score {
  font-family: var(--display);
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  min-width: 42px;
}
.risk-level {
  margin: 0;
  font-family: var(--display);
  font-size: 20px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.risk-formula { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }

.matrix-wrap { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.risk-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  text-align: center;
}
.risk-matrix th, .risk-matrix td {
  border: 1px solid #fff;
  padding: 5px 0;
  font-weight: 700;
}
.risk-matrix th { background: var(--slate); color: #f6edd8; font-size: 10px; }
.cell-low { background: #84cc16; color: #1a2e05; }
.cell-med { background: #facc15; color: #422006; }
.cell-high { background: #fb923c; color: #431407; }
.cell-crit { background: #e11d48; color: #fff; }
.risk-matrix td.hot {
  outline: 2px solid #111;
  outline-offset: -2px;
}
.matrix-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 11px;
  color: var(--ink-soft);
}
.matrix-legend li { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.lg { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.lg.low { background: #84cc16; }
.lg.med { background: #facc15; }
.lg.high { background: #fb923c; }
.lg.crit { background: #e11d48; }

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.photo-field { display: flex; flex-direction: column; gap: 6px; }
.dropzone {
  position: relative;
  min-height: 128px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background:
    repeating-linear-gradient(45deg, #f7f1e4, #f7f1e4 8px, #efe6d4 8px, #efe6d4 16px);
  overflow: hidden;
  cursor: pointer;
}
.dropzone.filled { background: #111; border-style: solid; }
.drop-preview {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}
.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  color: var(--ink-soft);
  padding: 8px;
}
.drop-hint strong { font-size: 12px; }
.drop-hint small { font-size: 11px; opacity: 0.8; }
.dropzone.filled .drop-hint { display: none; }

.a4-stage {
  background:
    radial-gradient(circle at 20% 0, rgba(255,255,255,0.5), transparent 40%),
    #d9d0bc;
  border-radius: 14px;
  padding: 18px 0 28px;
  overflow: auto;
  display: flex;
  justify-content: center;
}
.a4-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #1a1713;
  padding: 12mm 12mm 10mm;
  position: relative;
  box-shadow: 0 20px 50px rgba(40, 28, 12, 0.28);
  transform-origin: top center;
}
.a4-stripe {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7mm;
  background: repeating-linear-gradient(
    135deg,
    #111 0 8px,
    #d4a017 8px 16px
  );
}
.a4-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 3px solid #1a1713;
  margin-left: 4mm;
}
.a4-brand { display: flex; gap: 10px; align-items: center; }
.a4-mark {
  width: 34px; height: 34px;
  background: #c2410c;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  box-shadow: 0 0 0 4px #d4a017;
}
.a4-kicker {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #9a3412;
  font-weight: 700;
}
.a4-header h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.05;
}
.a4-ref {
  text-align: right;
  min-width: 42mm;
}
.a4-ref p {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6b6254;
}
.a4-ref strong {
  display: block;
  margin-top: 4px;
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.06em;
  background: #1a1713;
  color: #f6edd8;
  padding: 6px 8px;
}

.a4-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 8px 0 10px 4mm;
  border: 1px solid #1a1713;
}
.a4-meta div {
  padding: 6px 8px;
  border-right: 1px solid #1a1713;
  border-bottom: 1px solid #1a1713;
}
.a4-meta div:nth-child(3n) { border-right: 0; }
.a4-meta span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6b6254;
}
.a4-meta strong { font-size: 13px; }

.a4-block {
  margin: 0 0 8px 4mm;
  break-inside: avoid;
}
.a4-block h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: #1a1713;
  color: #f6edd8;
  padding: 4px 8px;
}
.a4-kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid #d6ccb8;
  margin-bottom: 6px;
}
.a4-kv div { padding: 6px 8px; border-right: 1px solid #d6ccb8; border-bottom: 1px solid #d6ccb8; }
.a4-kv .span-2 { grid-column: 1 / -1; border-right: 0; }
.a4-kv span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6b6254;
}
.a4-label {
  margin: 0 0 2px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #6b6254;
}
.a4-body {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  min-height: 28px;
  white-space: pre-wrap;
}

.a4-risk-nums {
  display: grid;
  grid-template-columns: 28mm 28mm 1fr;
  gap: 8px;
  margin-bottom: 6px;
}
.a4-risk-nums > div {
  border: 1px solid #1a1713;
  padding: 6px 8px;
  text-align: center;
}
.a4-risk-nums span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.a4-risk-nums strong { font-family: var(--display); font-size: 26px; }
.a4-risk-badge { background: #facc15; }
.a4-risk-badge.low { background: #84cc16; }
.a4-risk-badge.medium { background: #facc15; }
.a4-risk-badge.high { background: #fb923c; color: #fff; }
.a4-risk-badge.critical { background: #e11d48; color: #fff; }
.a4-risk-note { margin: 0; font-size: 10px; color: #6b6254; }

.photo-frames {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.photo-frame {
  margin: 0;
  border: 1px solid #1a1713;
  background: #f6f1e6;
}
.frame-img {
  height: 52mm;
  background: #ece4d2 center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b6254;
  font-size: 12px;
  overflow: hidden;
}
.frame-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-frame figcaption {
  text-align: center;
  font-family: var(--display);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  padding: 4px;
  background: #1a1713;
  color: #f6edd8;
}

.a4-signoff {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin: 10px 0 0 4mm;
}
.a4-signoff p {
  margin: 0 0 18px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b6254;
}
.sign-line {
  border-bottom: 1px solid #1a1713;
  height: 22px;
}
.a4-signoff small { font-size: 10px; color: #6b6254; }
.a4-foot {
  margin: 10px 0 0 4mm;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8a8070;
  border-top: 1px solid #d6ccb8;
  padding-top: 6px;
}

.register-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.register-tools input, .register-tools select {
  width: auto;
  min-width: 160px;
}
.table-wrap { overflow: auto; }
.register {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.register th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6b6254;
  padding: 8px 8px;
  border-bottom: 2px solid var(--ink);
}
.register td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.register tr:hover td { background: #f7f1e4; }
.risk-pill, .status-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.risk-pill.low { background: #d9f99d; color: #365314; }
.risk-pill.medium { background: #fef08a; color: #713f12; }
.risk-pill.high { background: #fed7aa; color: #9a3412; }
.risk-pill.critical { background: #fecdd3; color: #9f1239; }
.status-pill.open { background: #fee2e2; color: #9f1239; }
.status-pill.inprogress { background: #ffedd5; color: #9a3412; }
.status-pill.closed { background: #dcfce7; color: #166534; }
.status-pill.verified { background: #dbeafe; color: #1e40af; }
.status-pill.overdue { background: #1a1713; color: #f6edd8; }
.row-actions { display: flex; gap: 4px; }
.empty-note {
  text-align: center;
  color: var(--ink-soft);
  padding: 18px;
}

.print-stack { display: none; }

@media (max-width: 1180px) {
  .app-header { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .a4-page { transform: scale(0.72); margin-bottom: -80mm; }
}
@media (max-width: 720px) {
  .field-row.two, .photo-grid, .header-meta { grid-template-columns: 1fr; }
  .a4-page { transform: scale(0.48); margin-bottom: -155mm; }
}

@page { size: A4 portrait; margin: 0; }

@media print {
  body {
    background: #fff !important;
  }
  .app-header, .entry-panel, .register-panel, .preview-panel .panel-head {
    display: none !important;
  }
  .app-shell, .workspace, .preview-panel, .a4-stage {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    box-shadow: none !important;
    border: 0 !important;
    overflow: visible !important;
    max-width: none !important;
  }
  .a4-page {
    box-shadow: none !important;
    transform: none !important;
    margin: 0 !important;
    width: 210mm;
    min-height: 297mm;
  }
  .printing-stack .preview-panel {
    display: none !important;
  }
  .printing-stack .print-stack {
    display: block;
  }
  .print-stack .a4-page {
    page-break-after: always;
    box-shadow: none;
    transform: none !important;
  }
}
