:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #65717a;
  --line: #d7e0e5;
  --soft: #f4f7f6;
  --panel: #ffffff;
  --brand: #1d716d;
  --brand-strong: #135653;
  --accent: #b76d2e;
  --accent-soft: #fff2e6;
  --danger: #9b2c2c;
  --danger-soft: #fff1f1;
  --done: #166534;
  --shadow: 0 14px 38px rgba(20, 35, 43, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: #edf3f2;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0.68rem 0.84rem;
  cursor: pointer;
  min-height: 40px;
}

button:hover {
  border-color: var(--brand);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(43, 127, 255, 0.24);
  outline-offset: 2px;
}

.app-shell {
  width: min(1720px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.workspace {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(215, 224, 229, 0.9);
  box-shadow: var(--shadow);
}

.topbar,
.controls-band,
.main-grid {
  padding: 16px;
}

.topbar,
.controls-band,
.header-tools,
.quick-actions,
.delivery-strip {
  display: flex;
  gap: 10px;
}

.topbar {
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.header-tools,
.controls-band {
  align-items: center;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--brand-strong);
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.6rem, 3.5vw, 2.35rem);
}

h2 {
  font-size: 1rem;
}

.status-pill,
.panel-title span {
  border: 1px solid #a5cdc9;
  color: var(--brand-strong);
  background: #e7f5f2;
  padding: 0.48rem 0.72rem;
  border-radius: 7px;
  font-weight: 800;
  white-space: nowrap;
}

.controls-band {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  flex-wrap: wrap;
}

.segmented,
.role-switch {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

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

.role-switch {
  grid-template-columns: repeat(3, minmax(90px, 1fr));
}

.segment,
.role {
  border: 0;
  border-radius: 0;
  min-width: 0;
}

.segment.active,
.role.active {
  background: var(--brand);
  color: #fff;
}

.quick-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

#copyBtn,
#saveDraftBtn {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

#copyBtn:hover,
#saveDraftBtn:hover {
  background: var(--brand-strong);
}

#deleteDraftBtn {
  color: var(--danger);
  border-color: #e6b6b6;
  background: var(--danger-soft);
}

.main-grid {
  display: grid;
  grid-template-columns: 260px minmax(390px, 0.9fr) minmax(430px, 1.1fr);
  gap: 14px;
  align-items: start;
}

.side-panel {
  display: grid;
  gap: 14px;
}

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

.compact-panel {
  padding: 14px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.draft-list,
.checklist {
  display: grid;
  gap: 8px;
}

.draft-group {
  display: grid;
  gap: 8px;
}

.draft-group h3 {
  margin: 8px 0 0;
  padding: 6px 8px;
  border-radius: 6px;
  background: #eef3f2;
  color: var(--brand-strong);
  font-size: 0.78rem;
  letter-spacing: 0;
}

.draft-card,
.quality-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #fbfdfd;
}

.draft-card {
  cursor: pointer;
}

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

.draft-card strong,
.quality-item strong {
  display: block;
  font-size: 0.9rem;
}

.draft-card span,
.quality-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  margin-top: 3px;
}

.quality-item.done {
  border-color: #9bd1ad;
  background: #f1fbf4;
}

.quality-item.done strong {
  color: var(--done);
}

.quality-item.missing strong {
  color: var(--danger);
}

.form-panel {
  padding: 16px;
  max-height: calc(100vh - 172px);
  overflow: auto;
}

.role-helper {
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid #bdd8d5;
  border-radius: 8px;
  background: #eef9f6;
  color: #244844;
  font-size: 0.9rem;
  line-height: 1.4;
}

.import-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #d6dfd1;
  border-radius: 8px;
  background: #fbfdf8;
}

.file-drop {
  margin: 0;
}

.file-drop input {
  background: #fff;
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.import-actions button:first-child {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 800;
}

#importStatus {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.import-preview summary {
  cursor: pointer;
  color: var(--brand-strong);
  font-weight: 800;
  font-size: 0.88rem;
}

.import-preview textarea {
  margin-top: 8px;
  min-height: 130px;
}

fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 22px;
}

legend {
  font-weight: 800;
  margin-bottom: 12px;
}

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

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: #2d3b42;
  font-weight: 700;
  font-size: 0.9rem;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.72rem 0.78rem;
  background: #fbfdfd;
  color: var(--ink);
  font-weight: 400;
}

textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.45;
}

.snippet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.snippet-grid button,
.option-card {
  text-align: left;
  min-height: 48px;
  background: #fffaf5;
  border-color: #f0d0af;
}

.assist-panel {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid #c8d9d7;
  border-radius: 8px;
  background: #f7fbfa;
}

.assist-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.assist-note {
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.assist-header button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
}

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

.option-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  margin: 0;
  padding: 10px;
  border: 1px solid #d7e0e5;
  border-radius: 7px;
  color: #2d3b42;
  cursor: pointer;
}

.option-card:has(input:checked) {
  border-color: var(--brand);
  background: #eef9f6;
}

.option-card input {
  width: auto;
  margin-top: 2px;
}

.option-card strong {
  display: block;
  font-size: 0.88rem;
}

.option-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  margin-top: 2px;
}

.quality-item.blocking {
  border-color: #e6b6b6;
  background: var(--danger-soft);
}

.output-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 172px);
}

.output-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

#savedState {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

#reportOutput {
  border: 0;
  border-radius: 0;
  min-height: 520px;
  padding: 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1.62;
  background: #fff;
}

.print-document {
  display: none;
}

.delivery-strip {
  padding: 12px 16px;
  background: var(--accent-soft);
  border-top: 1px solid #f1d1b7;
  color: #67401f;
  align-items: center;
  flex-wrap: wrap;
}

.check-row {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
}

.check-row input {
  width: auto;
}

.print-help {
  color: #67401f;
  font-size: 0.82rem;
  line-height: 1.35;
}

.publish-panel {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--line);
  background: #f7fbfa;
}

.publish-header,
.publish-actions {
  display: flex;
  gap: 10px;
}

.publish-header {
  justify-content: space-between;
  align-items: start;
}

#publishState {
  border: 1px solid #c8d9d7;
  border-radius: 7px;
  padding: 0.44rem 0.6rem;
  color: var(--brand-strong);
  background: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.publish-note {
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.publish-actions {
  flex-wrap: wrap;
  margin-bottom: 8px;
}

#publishDriveBtn {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 800;
}

.publish-settings summary {
  cursor: pointer;
  color: var(--brand-strong);
  font-size: 0.86rem;
  font-weight: 800;
}

.publish-settings label {
  margin-top: 10px;
}

body[data-role="recepcion"] .clinical-fields,
body[data-role="recepcion"] .snippet-grid {
  display: none;
}

body[data-role="recepcion"] .main-grid {
  grid-template-columns: 300px minmax(430px, 0.85fr) minmax(430px, 1.15fr);
}

body[data-role="gestion"] .clinical-fields,
body[data-role="gestion"] .notes-fields {
  display: none;
}

body[data-role="gestion"] .main-grid {
  grid-template-columns: 340px minmax(360px, 0.75fr) minmax(480px, 1.25fr);
}

body[data-role="clinica"] .admin-fields {
  border-left: 4px solid #dce8e7;
  padding-left: 12px;
}

body[data-role="clinica"] .side-panel {
  order: 0;
}

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

  .side-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .output-header {
    align-items: stretch;
    flex-direction: column;
  }

  .main-grid,
  .side-panel,
  .field-grid,
  .snippet-grid,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .form-panel,
  .output-panel {
    max-height: none;
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .segmented,
  .role-switch {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .quick-actions,
  .header-tools {
    width: 100%;
  }

  .quick-actions button,
  .header-tools button {
    flex: 1 1 120px;
  }
}

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

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

  .topbar,
  .controls-band,
  .side-panel,
  .form-panel,
  #reportOutput,
  .output-header,
  .delivery-strip {
    display: none;
  }

  .publish-panel {
    display: none;
  }

  .app-shell,
  .main-grid,
  .workspace,
  .output-panel {
    display: block;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .print-document {
    display: block;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10.5pt;
    line-height: 1.42;
  }

  .print-cover {
    border-bottom: 3px solid var(--brand);
    padding-bottom: 12px;
    margin-bottom: 16px;
  }

  .print-brand-row {
    display: grid;
    grid-template-columns: 62px 1fr;
    gap: 14px;
    align-items: center;
    margin-bottom: 10px;
  }

  .print-logo {
    width: 58px;
    height: 58px;
    object-fit: contain;
  }

  .print-brand {
    color: var(--brand-strong);
    font-size: 10pt;
    font-weight: 800;
    text-transform: uppercase;
  }

  .print-title {
    margin: 4px 0 8px;
    font-size: 21pt;
    line-height: 1.1;
  }

  .print-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 18px;
    padding: 10px;
    border: 1px solid #cfdcda;
    background: #f5faf9;
  }

  .print-meta div {
    break-inside: avoid;
  }

  .print-meta strong {
    display: block;
    color: #45605d;
    font-size: 8.2pt;
    text-transform: uppercase;
  }

  .print-section {
    margin: 0 0 12px;
    break-inside: avoid;
  }

  .print-section h3 {
    margin: 0 0 5px;
    padding-bottom: 3px;
    border-bottom: 1px solid #cfdcda;
    color: var(--brand-strong);
    font-size: 11.5pt;
  }

  .print-section p {
    margin: 0;
    white-space: pre-wrap;
  }

  .print-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 26px;
    padding-top: 14px;
    border-top: 1px solid #cfdcda;
  }

  .signature-line {
    min-height: 42px;
    border-bottom: 1px solid #72817f;
    margin-bottom: 6px;
  }

  .print-signature {
    display: block;
    width: 210px;
    max-width: 100%;
    height: auto;
    margin: 0 0 6px;
    mix-blend-mode: multiply;
  }
}
