:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #637083;
  --line: #d9e0e8;
  --soft: #f3f6f8;
  --panel: #ffffff;
  --accent: #176b5d;
  --accent-dark: #0f4d43;
  --focus: #c67a2c;
  --paper: #fffdf8;
  --shadow: 0 18px 48px rgba(30, 42, 56, .14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(23, 107, 93, .08), rgba(198, 122, 44, .05) 42%, transparent 42%),
    #e9eef2;
  color: var(--ink);
}

.adminGate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 32, 42, .72);
  backdrop-filter: blur(12px);
}

.adminGate.isUnlocked {
  display: none;
}

.adminBox {
  width: min(100%, 760px);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 8px;
  padding: 24px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

.adminBox h2 {
  margin: 0 0 18px;
  font-size: 22px;
}

.homeButton {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.homeButton:hover {
  background: var(--accent-dark);
}

.gateHomeButton {
  float: right;
  margin: 0 0 12px 12px;
}

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

.accessCard {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.accessCard h3 {
  margin: 0;
  font-size: 16px;
}

.adminBox button,
.accessManager button {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.adminBox button:hover,
.accessManager button:hover {
  background: var(--accent-dark);
  color: #fff;
}

.adminError {
  min-height: 18px;
  margin: 8px 0 0;
  color: #a33a26;
  font-size: 13px;
  font-weight: 700;
}

.accessModeBadge {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

body[data-access-mode="admin"] .accessModeBadge {
  color: var(--accent-dark);
}

body[data-access-mode="user"] .accessModeBadge {
  color: #795314;
}

body:not([data-access-mode="admin"]) .adminOnly {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 14px clamp(18px, 3vw, 36px);
  border-bottom: 1px solid rgba(24, 32, 42, .1);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

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

button {
  min-height: 36px;
  border: 1px solid #b8c4cf;
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

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

#exportBtn,
#printBtn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

#exportBtn:hover,
#printBtn:hover {
  background: var(--accent-dark);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(420px, 1fr);
  gap: 24px;
  align-items: start;
  padding: 24px clamp(18px, 3vw, 36px) 36px;
}

.editor {
  display: grid;
  gap: 14px;
}

.editor section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 10px 24px rgba(30, 42, 56, .08);
}

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

.editor h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.editor section > h2 {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.fileButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.fileButton:hover {
  background: var(--accent-dark);
  color: #fff;
}

.fileInput {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.fileList {
  display: none;
  margin: 0;
  padding: 10px 16px 0 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.fileList.hasFiles {
  display: grid;
  gap: 5px;
}

.grid {
  display: grid;
  gap: 12px;
  padding: 14px 16px 16px;
}

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

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

label {
  display: grid;
  gap: 6px;
  color: #344252;
  font-size: 12px;
  font-weight: 700;
}

.fieldGroup {
  display: grid;
  gap: 6px;
  color: #344252;
  font-size: 12px;
  font-weight: 700;
}

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

.customRate {
  display: none;
}

.customRate.isVisible {
  display: block;
}

input,
textarea,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #c5ced8;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(198, 122, 44, .28);
  border-color: var(--focus);
}

.checks {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  font-size: 13px;
}

.checks input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.paymentPanel {
  display: grid;
  gap: 12px;
  padding: 14px 16px 16px;
}

.paymentAmount {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(23, 107, 93, .26);
  border-radius: 8px;
  background: rgba(23, 107, 93, .08);
}

.paymentAmount span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.paymentAmount strong {
  color: var(--accent-dark);
  font-size: 24px;
  line-height: 1;
}

#paymentBtn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

#paymentBtn:hover {
  background: var(--accent-dark);
  color: #fff;
}

.paymentNote {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.accessManager {
  display: grid;
  gap: 12px;
  padding: 14px 16px 16px;
}

.generatedCode {
  min-height: 22px;
  margin: 0;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.smsLink {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.smsLink.isVisible {
  display: inline-flex;
}

.smsLink:hover {
  background: var(--accent-dark);
  color: #fff;
}

.previewWrap {
  position: sticky;
  top: 100px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.paperTools {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.paper {
  width: min(100%, 820px);
  min-height: 1100px;
  margin: 0 auto;
  padding: 64px 72px;
  border: 1px solid #d8d1c5;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13.5px;
  line-height: 1.48;
}

.paper h1 {
  margin: 0 0 30px;
  text-align: center;
  font-size: 24px;
  text-decoration: underline;
}

.paper h2 {
  margin: 22px 0 8px;
  font-size: 15px;
  line-height: 1.25;
  text-transform: none;
}

.paper h3 {
  margin: 16px 0 7px;
  font-size: 14px;
}

.paper p {
  margin: 0 0 8px;
}

.paper strong {
  font-weight: 700;
}

.emptyField {
  display: inline-block;
  min-width: 90px;
  padding: 0 3px;
  border-bottom: 1px dotted #8d7864;
  color: #8d5a2f;
}

.signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 64px;
  min-height: 120px;
  margin-top: 32px;
}

.signatures p {
  padding-top: 12px;
  border-top: 1px solid #2d2d2d;
  font-weight: 700;
}

@media (max-width: 980px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

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

  .sectionHeader {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .previewWrap {
    position: static;
  }
}

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

  .grid.two {
    grid-template-columns: 1fr;
  }

  .paper {
    min-height: auto;
    padding: 34px 24px;
    font-size: 12.5px;
  }

  .signatures {
    grid-template-columns: 1fr;
    gap: 36px;
  }
}

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

  .topbar,
  .editor,
  .paperTools {
    display: none !important;
  }

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

  .previewWrap {
    position: static;
  }

  .paper {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: #fff;
    color: #000;
  }

  @page {
    size: A4;
    margin: 18mm;
  }
}
