:root {
  color-scheme: light;
  --ink: #1c2420;
  --muted: #5e6b65;
  --subtle: #7b8781;
  --paper: #fffdf8;
  --panel: #ffffff;
  --line: #d9ded8;
  --line-strong: #b9c4bd;
  --field: #f7f9f6;
  --accent: #196c5d;
  --accent-strong: #0f4f45;
  --accent-soft: #e3f2ec;
  --warn: #9a5a13;
  --danger: #a1372a;
  --danger-soft: #fae8e5;
  --ok: #247348;
  --ok-soft: #e5f5eb;
  --shadow: 0 18px 48px rgba(23, 37, 31, 0.14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #eef1ed;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #f6f7f3 0%, #eef1ed 48%, #e7ece8 100%);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
}

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

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 3px;
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

h3 {
  margin-bottom: 10px;
  font-size: 18px;
}

h4 {
  margin-bottom: 8px;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

.lede {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 9px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

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

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

.button-secondary {
  border-color: #9fc2b6;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.button-quiet {
  background: #fff;
}

.file-button {
  user-select: none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 22px;
  padding: 22px clamp(18px, 3vw, 36px) 36px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.controls-panel {
  position: sticky;
  top: 100px;
  align-self: start;
  max-height: calc(100vh - 124px);
  overflow: auto;
}

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

.status-pill,
.risk-pill {
  display: inline-flex;
  min-width: max-content;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.risk-nulo {
  background: #edf4ef;
  color: #315f42;
}

.risk-bajo {
  background: #e4f2ea;
  color: #1f7044;
}

.risk-medio {
  background: #fff3d7;
  color: #7d5511;
}

.risk-alto {
  background: #fde5d5;
  color: #934515;
}

.risk-muy-alto {
  background: var(--danger-soft);
  color: var(--danger);
}

.section-card {
  border-bottom: 1px solid var(--line);
}

.section-card:last-child {
  border-bottom: 0;
}

.section-card summary {
  padding: 15px 18px;
  cursor: pointer;
  font-weight: 800;
  list-style-position: outside;
}

.section-card[open] summary {
  border-bottom: 1px solid var(--line);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px 18px 18px;
}

.wide {
  grid-column: 1 / -1;
}

label span,
.field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(25, 108, 93, 0.14);
}

.compact-list,
.questionnaire,
.action-editor {
  padding: 16px 18px 18px;
}

.guide-note {
  margin: 14px 18px 0;
  padding: 10px 12px;
  border: 1px solid #d7e6de;
  border-radius: var(--radius);
  background: #f5fbf7;
  color: var(--muted);
  font-size: 13px;
}

.question-group {
  margin-bottom: 16px;
}

.question-group:last-child {
  margin-bottom: 0;
}

.question-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.question-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #eef1ed;
}

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

.question-text {
  color: var(--ink);
  font-size: 13px;
}

.question-meta {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 700;
}

.yes-no {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  width: 124px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
}

.segmented button,
.yes-no button {
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.segmented button.active,
.yes-no button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.test-output,
.validation-output {
  margin: 14px 18px 0;
  padding: 12px;
  border-radius: var(--radius);
  font-size: 13px;
}

.test-output {
  border: 1px solid #b9dec8;
  background: var(--ok-soft);
  color: var(--ok);
}

.test-output.fail,
.validation-output {
  border: 1px solid #e6b1a9;
  background: var(--danger-soft);
  color: var(--danger);
}

.test-output ul,
.validation-output ul {
  margin: 8px 0 0;
  padding-left: 19px;
}

.action-table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 8px;
  border: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  overflow-wrap: anywhere;
}

th {
  background: #f2f5f1;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.action-editor table input,
.action-editor table select,
.action-editor table textarea {
  min-width: 150px;
  padding: 7px;
  font-size: 13px;
}

.action-editor table textarea {
  min-width: 240px;
}

.document-stage {
  min-width: 0;
}

.document {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 42px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.doc-cover {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr;
  gap: 28px;
  align-items: end;
  padding-bottom: 26px;
  border-bottom: 3px solid var(--accent);
}

.doc-title {
  margin: 0 0 14px;
  font-size: 36px;
  line-height: 1.05;
}

.doc-subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
}

.doc-meta {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.doc-meta dl {
  display: grid;
  grid-template-columns: 105px 1fr;
  gap: 6px 10px;
  margin: 0;
  font-size: 13px;
}

.doc-meta dt {
  color: var(--muted);
  font-weight: 800;
}

.doc-meta dd {
  margin: 0;
}

.doc-section {
  margin-top: 28px;
}

.doc-section p {
  margin-bottom: 10px;
}

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

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

.metric-value {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 800;
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.policy-list {
  margin: 10px 0 0;
  padding-left: 20px;
}

.policy-list li {
  margin-bottom: 6px;
}

.notice {
  margin-top: 22px;
  padding: 12px 14px;
  border-left: 4px solid var(--warn);
  background: #fff7e8;
  color: #67400a;
}

.doc-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.doc-table-wrap table {
  min-width: 620px;
}

.doc-table-wrap-wide table {
  min-width: 980px;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  margin-top: 46px;
}

.signature {
  padding-top: 34px;
  border-top: 1px solid var(--ink);
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 14px;
  background: #fff;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .topbar,
  .workspace,
  .doc-cover {
    grid-template-columns: 1fr;
  }

  .topbar {
    position: static;
    align-items: flex-start;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .workspace {
    display: block;
  }

  .controls-panel {
    position: static;
    max-height: none;
    margin-bottom: 20px;
  }
}

@media (max-width: 720px) {
  h1 {
    font-size: 23px;
  }

  .top-actions,
  .button {
    width: 100%;
  }

  .workspace {
    padding: 14px;
  }

  .form-grid,
  .question-row,
  .doc-grid,
  .signature-grid {
    grid-template-columns: 1fr;
  }

  .segmented {
    grid-template-columns: repeat(5, minmax(38px, 1fr));
  }

  .document {
    padding: 22px;
  }

  .doc-title {
    font-size: 28px;
  }

  th,
  td {
    padding: 6px;
    font-size: 11px;
  }
}

@media print {
  @page {
    margin: 14mm;
  }

  html,
  body {
    background: #fff;
  }

  [data-print-hidden],
  .controls-panel {
    display: none !important;
  }

  .workspace {
    display: block;
    padding: 0;
  }

  .document {
    width: auto;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
  }

  .doc-cover {
    break-inside: avoid;
  }

  .doc-section,
  table,
  tr,
  .metric-card,
  .notice {
    break-inside: avoid;
  }

  .risk-pill,
  .status-pill {
    border: 1px solid currentColor;
    background: #fff !important;
    color: #000 !important;
  }
}
