:root {
  --bg: #f4f2ed;
  --panel: #ffffff;
  --panel-alt: #f7f8f5;
  --text: #20231f;
  --muted: #667064;
  --line: #d9ddd2;
  --brand-red: #d63c45;
  --brand-red-strong: #b92f3b;
  --accent: var(--brand-red);
  --accent-strong: var(--brand-red-strong);
  --deep: #1f2a24;
  --warn: #fff2b8;
  --danger: #a23b2a;
  --shadow: 0 16px 42px rgba(32, 35, 31, 0.09);
  --accent-shadow: rgba(214, 60, 69, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  background: linear-gradient(180deg, var(--brand-red) 0 5px, var(--deep) 5px 100%);
  color: #fff;
}

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

.brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  padding: 6px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #c8d0c5;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-button,
.ghost-button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  text-align: left;
  padding: 0 12px;
}

.nav-button.is-active,
.nav-button:hover,
.ghost-button:hover {
  background: rgba(214, 60, 69, 0.24);
  border-color: rgba(255, 255, 255, 0.28);
}

.sidebar-footer {
  display: grid;
  gap: 10px;
  margin-top: auto;
  color: #c8d0c5;
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 28px;
}

.standalone {
  min-height: 100vh;
  padding: 28px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
  padding: 18px;
  border-radius: 8px;
  background: var(--brand-red);
  color: #fff;
}

.brand-light img {
  background: #fff;
}

.site-header #storageStatus {
  color: #c8d0c5;
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.toolbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.form-intro {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.form-intro p {
  margin: 0;
}

.toolbar-actions,
.form-actions,
.panel-heading,
.document-tabs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.tab-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 0 14px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

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

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

.secondary-button,
.tab-button {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

.tab-button.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.form-grid {
  display: grid;
  gap: 16px;
}

.form-grid fieldset {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.form-grid.compact fieldset {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  box-shadow: none;
}

legend {
  padding: 0 8px;
  font-weight: 700;
}

.section-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.form-notice {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid rgba(28, 120, 75, 0.28);
  border-radius: 8px;
  background: #edf7f1;
  color: #1c5f3f;
  font-size: 14px;
  font-weight: 700;
}

.form-notice.is-error {
  border-color: rgba(166, 38, 48, 0.28);
  background: #fff1f2;
  color: #8f1f2d;
}

.form-notice[hidden] {
  display: none;
}

.public-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(31, 42, 36, 0.58);
}

.public-popup-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(31, 42, 36, 0.28);
  padding: 28px;
  text-align: center;
}

.public-popup-icon {
  display: inline-grid;
  place-items: center;
  min-width: 48px;
  height: 48px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: #edf7f1;
  color: #1c5f3f;
  font-size: 15px;
  font-weight: 800;
}

.public-popup-error .public-popup-icon {
  background: #fff1f2;
  color: #8f1f2d;
}

.public-popup-card h2 {
  margin: 0 0 12px;
  font-size: 26px;
  line-height: 1.2;
}

.public-popup-card p {
  margin: 0;
  color: #3d443d;
  font-size: 17px;
  line-height: 1.5;
  white-space: pre-line;
}

.public-popup-error .public-popup-card p {
  text-align: left;
}

.public-popup-close {
  margin-top: 22px;
  min-width: 150px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

input.field-error,
select.field-error {
  border-color: var(--danger);
  background: #fff5f5;
  box-shadow: 0 0 0 3px rgba(162, 59, 42, 0.16);
}

label.field-error-label {
  color: #8f1f2d;
  font-weight: 700;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(214, 60, 69, 0.22);
  outline-offset: 2px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

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

.summary-panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

dl {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.document-tabs {
  margin-bottom: 14px;
}

.document-preview {
  max-width: 920px;
  min-height: 720px;
  margin: 0 auto;
  padding: 54px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow);
  font-family: "Times New Roman", Times, serif;
  font-size: 16px;
  line-height: 1.65;
}

.document-preview h2,
.document-preview h3 {
  margin: 0 0 20px;
  text-align: center;
}

.document-preview .signature {
  width: 320px;
  margin-top: 56px;
  border-top: 1px solid #000;
  text-align: center;
  padding-top: 8px;
}

.placeholder {
  background: var(--warn);
  padding: 0 3px;
}

.list {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-alt);
}

.list-item button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

.field-note {
  display: grid;
  align-content: start;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  padding-top: 25px;
}

.field-note .secondary-button {
  width: 100%;
}

.property-card {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alt);
  color: var(--text);
  cursor: pointer;
  padding: 12px;
  text-align: left;
}

.property-card:hover,
.property-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-shadow);
}

.property-card span,
.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.property-card em {
  color: var(--accent-strong);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  text-transform: uppercase;
}

.detail-stack {
  display: grid;
  gap: 18px;
}

.detail-stack section {
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.detail-stack section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.detail-stack h3 {
  margin: 0;
  font-size: 15px;
}

.detail-stack p {
  margin: 0;
}

.detail-stack a:not(.link-button) {
  color: var(--accent-strong);
}

.raw-data-section {
  gap: 12px;
}

.raw-data-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.raw-data-heading p,
.raw-data-heading span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.raw-data-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.raw-data-tabs .tab-button[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.raw-data-panel[hidden] {
  display: none;
}

.raw-data-table-wrap {
  overflow-x: auto;
}

.raw-data-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 14px;
}

.raw-data-table th,
.raw-data-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.raw-data-table th {
  color: var(--muted);
  font-weight: 700;
}

.raw-data-table td:first-child {
  width: 42%;
  color: var(--muted);
}

.raw-data-table td:last-child {
  overflow-wrap: anywhere;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.actor-links a {
  display: grid;
  gap: 8px;
  min-height: 132px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.actor-links a:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-shadow), var(--shadow);
}

.actor-links strong {
  font-size: 18px;
}

.actor-links span {
  color: var(--muted);
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  font-family: "Times New Roman", Times, serif;
  line-height: 1.55;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 14px;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-button {
    text-align: center;
  }

  .toolbar,
  .split,
  .actor-links {
    display: grid;
    grid-template-columns: 1fr;
  }

  .form-grid fieldset,
  .form-grid.compact fieldset {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .main {
    padding: 16px;
  }

  .standalone {
    padding: 16px;
  }

  .site-header {
    display: grid;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid fieldset,
  .form-grid.compact fieldset {
    grid-template-columns: 1fr;
  }

  .public-popup {
    padding: 16px;
  }

  .public-popup-card {
    padding: 24px 18px;
  }

  .public-popup-card h2 {
    font-size: 22px;
  }

  .public-popup-card p {
    font-size: 16px;
  }

  .document-preview {
    padding: 28px 20px;
    min-height: 0;
  }

  dl {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .toolbar,
  .document-tabs,
  .view:not(#view-documentos) {
    display: none !important;
  }

  .shell,
  .main,
  #view-documentos {
    display: block;
    padding: 0;
  }

  .document-preview {
    max-width: none;
    min-height: 0;
    border: 0;
    box-shadow: none;
    padding: 0;
  }
}
