:root {
  --viewer-bg: #f5f1e8;
  --viewer-card: #fffdf8;
  --viewer-border: rgba(73, 55, 29, 0.14);
  --viewer-accent: #6a4a22;
  --viewer-accent-2: #8b6330;
  --viewer-text: #2a2118;
  --viewer-muted: #70614f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: linear-gradient(180deg, #f7f3eb 0%, #efe6d8 100%);
  color: var(--viewer-text);
  font-family: "Tahoma", "Arial", sans-serif;
}

.viewer-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: #20170f;
  color: #fff;
}
.viewer-brand a {
  color: #fff;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 700;
}
.viewer-brand small {
  display: block;
  color: rgba(255,255,255,.8);
  margin-top: 4px;
}
.viewer-nav { display: flex; gap: 12px; flex-wrap: wrap; }
.viewer-nav a {
  color: #fff;
  text-decoration: none;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  padding: 10px 14px;
  border-radius: 12px;
}

.viewer-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}
.viewer-hero,
.viewer-card {
  background: var(--viewer-card);
  border: 1px solid var(--viewer-border);
  border-radius: 24px;
  box-shadow: 0 18px 45px rgba(41, 26, 11, 0.08);
}
.viewer-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 24px;
  margin-bottom: 18px;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--viewer-accent-2);
  font-weight: 700;
}
#contractTitle {
  margin: 0 0 10px;
  font-size: 1.9rem;
  line-height: 1.5;
}
#contractIntro {
  margin: 0;
  color: var(--viewer-muted);
  line-height: 1.9;
}
.viewer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
button {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 1rem;
  cursor: pointer;
  background: var(--viewer-accent);
  color: #fff;
}
button.secondary {
  background: #e9dfd0;
  color: var(--viewer-text);
}
button:disabled { opacity: .65; cursor: not-allowed; }

.viewer-card { padding: 18px; }
.viewer-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  color: var(--viewer-muted);
  font-size: .98rem;
}
#slotCount {
  background: #f2eadf;
  border: 1px solid var(--viewer-border);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--viewer-accent);
  font-weight: 700;
}
.contract-paper {
  background: #fff;
  border: 1px solid rgba(90, 72, 44, 0.12);
  border-radius: 18px;
  min-height: 60vh;
  padding: 24px;
  font-size: 1.1rem;
  line-height: 2.1;
  white-space: normal;
}
.paper-placeholder { color: var(--viewer-muted); }
.contract-slot {
  display: inline-flex;
  align-items: center;
  min-width: 96px;
  max-width: 100%;
  margin: 0 3px;
  padding: 3px 10px;
  border-radius: 10px;
  border: 1px dashed var(--viewer-accent-2);
  background: #fff7ea;
  color: var(--viewer-text);
  font: inherit;
  line-height: 1.9;
  vertical-align: baseline;
}
.contract-slot.empty {
  color: var(--viewer-accent-2);
  font-weight: 700;
}
.contract-slot.filled {
  background: #f3ede2;
  border-style: solid;
}

.field-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.48);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 999;
}
.field-modal.hidden,
.hidden { display: none !important; }
.field-modal-box {
  width: min(680px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 22px 60px rgba(0,0,0,.25);
}
.field-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.field-modal-head h2 { margin: 0; font-size: 1.3rem; }
.modal-close {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  padding: 0;
  font-size: 1.4rem;
  background: #efe6d8;
  color: #3a2c19;
}
.field-modal-hint {
  margin: 0 0 12px;
  color: var(--viewer-muted);
  line-height: 1.9;
}
.field-control {
  width: 100%;
  border: 1px solid #d7c7b4;
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  color: var(--viewer-text);
  background: #fffdfa;
}
textarea.field-control { resize: vertical; min-height: 140px; }
.field-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.loading-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #20170f;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  z-index: 999;
}

@media (max-width: 820px) {
  .viewer-topbar,
  .viewer-hero,
  .viewer-status,
  .field-modal-actions { flex-direction: column; align-items: stretch; }
  .viewer-actions { width: 100%; }
  .viewer-actions button,
  .field-modal-actions button { width: 100%; }
  #contractTitle { font-size: 1.45rem; }
  .contract-paper { padding: 16px; font-size: 1rem; }
}

@media print {
  body { background: #fff; }
  .no-print, .viewer-topbar { display: none !important; }
  .viewer-shell { max-width: none; padding: 0; }
  .viewer-hero, .viewer-card {
    box-shadow: none;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
    background: #fff;
  }
  .contract-paper {
    border: 0;
    min-height: 0;
    padding: 0;
    font-size: 16px;
    line-height: 2;
  }
  .contract-slot {
    border: 0;
    background: transparent;
    padding: 0;
    min-width: 0;
    margin: 0;
  }
}
