.contract-composer {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.contract-composer-bar {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding-bottom: 11px;
  margin-bottom: 3px;
  border-bottom: 1px solid var(--line);
}

.contract-composer-bar .field {
  flex: 1 1 12rem;
  max-width: 23rem;
}

#full-contract-text {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 16rem;
  height: clamp(20rem, 56vh, 38rem);
  padding: 1rem;
  resize: vertical;
  direction: rtl;
  overflow-wrap: anywhere;
  border: 1px solid #424242;
  border-radius: 12px;
  background: #151515;
  color: var(--text);
  font-size: 1rem;
  line-height: 2;
  text-align: right;
}

#full-contract-text::placeholder {
  color: var(--muted);
}

#contract-text-help {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.6;
}

@media (max-width: 680px) {
  .contract-composer-bar .field {
    flex-basis: 9rem;
  }

  #full-contract-text {
    height: clamp(16rem, 51vh, 30rem);
    padding: .7rem;
  }
}

.payment-editor { display: grid; gap: 12px; margin-block: 12px; container-type: inline-size; }
.payment-editor h3 { margin: 0; font-size: 1rem; }
.payment-editor > .btn { justify-self: start; }
.contract-field-row { display: grid; gap: 9px; min-inline-size: 0; margin: 0; border: 1px solid var(--line); padding: 10px 12px 12px; border-radius: 10px; }
.contract-field-row legend { padding-inline: 5px; margin-block-end: 0; }
.custom-table-fields { display: grid; gap: 8px; margin-block-end: 8px; }
.payment-fields, .payment-footer { display: grid; gap: 8px 12px; }
.payment-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.payment-fields > :only-child { grid-column: 1 / -1; }
.payment-footer { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
.payment-remove-row { grid-column: 2; }
.payment-fields .segmented-date { grid-template-columns: minmax(0, 1.5fr) auto minmax(0, 1fr) auto minmax(0, 1fr); }
@container (max-width: 300px) {
  .payment-fields { grid-template-columns: minmax(0, 1fr); }
}
.paper-preview .office-document { display: grid; gap: 8px; }
.paper-preview .office-document:has(.office-document-table) { min-inline-size: 315px; }
.paper-preview .office-document:has(.office-document-table th:nth-child(6)) { min-inline-size: 510px; }
.paper-preview .office-document:has(.office-document-table th:nth-child(9)) { min-inline-size: 570px; }
.paper-preview .office-document :is(p, h4, h5) { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.paper-preview .office-document .heading { margin-block-start: 10px; }
.paper-preview .office-document .eyebrow { text-align: center; }
.paper-preview .office-document .small { font-size: .82em; }
.paper-preview .office-document-table { width: 100%; border-collapse: collapse; table-layout: fixed; color: #242424; font-size: .8em; }
.paper-preview .office-document-table :is(td, th) { padding: 5px; border: 1px solid #a1a1a1; text-align: right; vertical-align: top; background: white; white-space: pre-wrap; overflow-wrap: anywhere; }
.paper-preview .office-document-table th { background: #ececec; color: #242424; }
.office-paper .office-signatures :is(th, td) { text-align: center; vertical-align: top; }
.office-paper .office-signatures td { height: 70px; }

@font-face {
  font-family: ContractNazanin;
  src: url('/fonts/contract-nazanin-regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: ContractNazanin;
  src: url('/fonts/contract-nazanin-bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

.office-logo-settings { max-width: 36rem; }
.office-logo-settings .panel-body { display: grid; gap: 20px; }
.office-brand-preview { display: grid; justify-items: start; gap: 8px; font-size: .84rem; color: var(--muted); }
.office-brand-preview img { width: 158px; height: 120px; object-fit: contain; border-radius: 7px; background: white; filter: grayscale(1); }
.office-logo-form { display: grid; gap: 10px; }
.office-paper .office-document { display: block; }
.office-preview-header { display: grid; grid-template-columns: 22% 50% 28%; border: 1px solid #444; align-items: stretch; }
.office-preview-header > * { padding: 4px; min-width: 0; }
.office-preview-header > * + * { border-inline-start: 1px solid #444; }
.office-preview-title { text-align: center; align-content: center; }
.office-preview-title p { font-size: .68em; }
.office-preview-title h3 { font-size: .94em; margin: 3px 0 0; line-height: 1.45; }
.office-preview-logo { display: grid; place-content: center; }
.office-preview-logo img { width: 100%; max-height: 74px; object-fit: contain; filter: grayscale(1); }
.office-preview-header dl { margin: 0; font-size: .63em; }
.office-preview-header dl div { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 4px; overflow-wrap: anywhere; }
.office-preview-header dd { margin: 0; font-weight: 700; }
.office-paper .office-paper-section { margin: 0; padding: 4px; border: 1px solid #444; border-block-start: 0; }
.office-paper .office-paper-section.office-article-shaded { background: #f1f1f1; }
.office-paper .office-paper-section .heading { margin: 0 0 2px; font-size: .87em; }
.office-paper .office-paper-section .body-text { text-align: justify; font-size: .85em; }
.office-paper .office-paper-section .agency { font-size: .76em; }
.office-paper .office-paper-section .office-table-wrap { margin-block: 2px 5px; }

.contract-composer-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.contract-composer-actions .btn[aria-pressed="true"], .contract-composer-actions .btn[aria-expanded="true"] { border-color: var(--green-text); }
.contract-composer-search { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: 7px 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.contract-composer-search [role="status"] { grid-column: 1 / -1; margin: 0; }
.contract-composer-search [role="status"]:empty { display: none; }
.editor-grid.expanded-contract-editor { grid-template-columns: minmax(0, 1fr); }
.expanded-contract-editor #full-contract-text { min-height: 58vh; }
.office-preview-title img { display: block; width: 100%; max-height: 72px; object-fit: contain; }

.editor-grid.office-document-layout { grid-template-columns: minmax(0, 1fr); }
.document-views { margin-bottom: 14px; }
.document-controls { display: grid; gap: 9px; margin: 0 auto 14px; max-width: 56rem; }
.document-controls p { margin: 0; }
.document-toolbar, .document-actions, .document-view-controls { display: flex; flex-wrap: wrap; align-items: center; }
.document-toolbar { justify-content: space-between; gap: 8px 16px; }
.document-actions { gap: 6px; }
.document-actions .btn { min-height: 36px; padding: 5px 10px; white-space: nowrap; }
.document-view-controls { gap: 8px 16px; padding-block-start: 8px; border-block-start: 1px solid var(--line); }
.document-view-controls .document-help { margin-inline-start: auto; }
.document-view-controls .document-help[open] { flex-basis: 100%; }
.office-edit-sheet { color: #1a1a1a; background: #fefefd; max-width: 56rem; margin-inline: auto; padding: clamp(8px, 3vw, 25px); border-radius: 3px; box-shadow: 0 15px 30px #0004; line-height: 1.8; }
.office-edit-sheet .office-preview-header { min-height: 98px; }
.office-edit-sheet .office-preview-header dl { font-size: clamp(.58rem, 1.1vw, .74rem); }
.office-edit-sheet .office-paper-section { padding: 7px 8px; }
.office-edit-sheet .office-document-table { width: 100%; min-width: 365px; border-collapse: collapse; table-layout: fixed; font-size: .75rem; color: #222; }
.office-edit-sheet .office-document-table:has(th:nth-child(8)) { min-width: 510px; }
.office-edit-sheet .office-table-wrap { overflow-x: auto; }
.office-edit-sheet .office-document-table :is(td,th) { border: 1px solid #666; padding: 3px; text-align: center; background: #fff; white-space: pre-wrap; overflow-wrap: anywhere; }
.office-edit-sheet .office-document-table th { background: #eee; }
.office-edit-sheet :is(h4,h5,p) { margin: 0; }
.office-edit-sheet .document-heading, .office-edit-sheet .document-body { color: #171717; background: transparent; border: 1px solid transparent; border-radius: 3px; width: 100%; padding: 4px; margin: 0; }
.office-edit-sheet .document-heading { font-size: .91rem; font-weight: 750; }
.office-edit-sheet .document-body { font-size: .87rem; white-space: pre-wrap; overflow-wrap: anywhere; text-align: justify; line-height: 1.95; }
.office-edit-sheet .document-body:empty:not(:focus) { display: none; }
.office-edit-sheet .document-article .document-body[data-empty-slot]:empty, .office-edit-sheet .document-article:focus-within .document-body:empty { display: block; }
.office-edit-sheet .document-body:empty::before { content: attr(data-placeholder); color: #626262; pointer-events: none; }
.office-edit-sheet :is(.document-body,.document-heading):is(:hover,:focus) { border-color: #72907b; outline: none; background: #fbfff8; }
.document-variable { background: #e5eee6; border-radius: 3px; padding: 1px 2px; }
.document-article-tools { display: flex; align-items: center; justify-content: flex-end; gap: 7px; margin-block-start: 4px; }
.document-tool { background: #ededed; color: #323232; border: 1px solid #bbb; border-radius: 5px; min-height: 30px; padding: 3px 8px; font-size: .73rem; cursor: pointer; }
.document-tool:focus-visible { outline: 2px solid #397751; outline-offset: 2px; }
.document-remove { color: #6d302a; }
@media (max-width: 560px) {
  .office-edit-sheet .office-paper-section { padding: 3px; }
  .office-edit-sheet .document-heading { font-size: .81rem; }
  .document-tool { min-height: 42px; }
}
.office-paper .office-document-table { display: table; }
.office-paper .office-document-table thead { display: table-header-group; }
.office-paper .office-document-table tbody { display: table-row-group; }
.office-paper .office-document-table tr { display: table-row; }
.office-document-layout .editor-main > .editor-panel:first-child { overflow: visible; }
.office-document-layout .document-controls { position: sticky; top: 5px; z-index: 2; padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }

.document-variable, .document-cell-edit { color: #255038; border: 0; text-align: inherit; cursor: pointer; font: inherit; }
.document-variable:focus-visible, .document-cell-edit:focus-visible { outline: 2px solid #397751; outline-offset: 1px; }
.document-cell-edit { background: #edf4ed; width: 100%; min-height: 25px; border-radius: 3px; padding: 1px; white-space: pre-wrap; overflow-wrap: anywhere; }
.document-help { color: var(--muted); font-size: .83rem; }
.document-help summary { cursor: pointer; }
.document-help ol { margin: 5px 0 0; padding-inline-start: 22px; }
.document-article-tools { flex-wrap: wrap; }
.variable-dialog, .variable-new-fields, .custom-field { display: grid; gap: 10px; }
.variable-dialog { margin-block-start: 12px; }
.variable-dialog .inline-actions { flex-wrap: wrap; }
.custom-field .btn { justify-self: start; }
.office-edit-sheet :is(button, [data-office-body]) { scroll-margin-block-start: 125px; }
.document-cell-edit { box-sizing: border-box; display: block; min-width: 0; cursor: text; text-align: center; }
.document-cell-edit::placeholder { color: #637468; }

.office-paper { font-family: ContractNazanin, Vazirmatn, sans-serif; }
.office-preview-title p { font-size: .88em; font-weight: 700; }
.office-preview-title h3 { font-size: 1.22em; }

.office-preview-title p { line-height: 1.55; }
.office-preview-title h3 { margin-block-start: .4em; line-height: 1.25; }

.segmented-date {
  display: grid;
  grid-template-columns: minmax(48px, 1.5fr) auto minmax(30px, 1fr) auto minmax(30px, 1fr);
  gap: 3px;
  align-items: center;
  min-width: 0;
}
.segmented-date input[data-date-part] { padding-inline: 2px; text-align: center; }
.office-edit-sheet .segmented-date { gap: 1px; grid-template-columns: minmax(0, 1.5fr) auto minmax(0, 1fr) auto minmax(0, 1fr); }
.office-edit-sheet .segmented-date input[data-date-part] {
  width: 100%; min-width: 0; border: 1px solid transparent; padding: 0; color: #161616; background: transparent; font: inherit;
}

.editable-variable { position: relative; min-width: 0; }
.editable-variable.wide { grid-column: 1 / -1; }
.field-label { display: block; }
.editable-variable .field-label { min-block-size: 20px; padding-inline-end: 24px; }
:is(.field-remove, .cell-remove) {
  display: grid; place-items: center; position: absolute; inset-inline-end: 0; inset-block-start: 0;
  border: 0; border-radius: 4px; background: transparent; cursor: pointer; padding: 0;
}
.field-remove { inline-size: 22px; block-size: 20px; color: #b22635; }
.field-remove .icon { width: 12px; height: 12px; }
[data-theme="dark"] .field-remove { color: #ff9aa1; }
:is(.field-remove, .cell-remove):hover { background: #b226351a; }
:is(.field-remove, .cell-remove):focus-visible { outline: 2px solid currentColor; }
.add-form-field { margin-block-start: 10px; }
.document-cell-control { position: relative; display: block; min-width: 0; }
.document-cell-control + .document-cell-control { margin-block-start: 2px; }
.document-cell-control .document-cell-edit { padding-inline: 3px 15px; }
.cell-remove { inline-size: 14px; block-size: 17px; color: #ad2433; font: 700 12px/1 system-ui, sans-serif; }
.document-table-tools { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 5px; padding: 3px; }

.office-paper .office-document-table td,
.office-paper .office-document-table th { color: #1b1b1b; }
.office-edit-sheet .office-document-table { font-size: .9rem; }
.office-edit-sheet .office-document-table :is(.document-cell-edit, [data-date-part]) { font-weight: 700; }
.office-edit-sheet .office-document-table .payment-currency { flex: none; font-weight: 700; }
.office-edit-sheet .payment-row-action .document-tool { padding-inline: 3px; min-width: 0; }
.paper-preview .office-document-table[data-office-table="payment"] { font-size: .95em; }

.document-zoom, .document-font-label { display: inline-flex; align-items: center; gap: .45rem; }
.document-zoom input { width: clamp(65px, 10vw, 112px); }
.document-zoom output { min-inline-size: 3em; }
.document-font-label input { inline-size: 4em; min-block-size: 30px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); font: inherit; padding-inline: 6px; }
.office-paper, .paper-preview { user-select: text; }
button.document-cell-edit { font-size: inherit; line-height: 1.5; text-align: start; min-inline-size: 0; overflow-wrap: anywhere; }
.anchored-cell-editor[open] {
  position: fixed;
  inset: auto;
  left: var(--cell-editor-left);
  top: var(--cell-editor-top);
  margin: 0;
  width: min(380px, calc(100vw - 24px));
  max-height: min(70vh, calc(100vh - var(--cell-editor-top) - 12px));
  z-index: 20;
  overflow: auto;
}
.anchored-cell-editor textarea { field-sizing: content; max-height: 33vh; overflow: auto; }
.cell-font-actions { margin-block: .5rem; }
.amount-words { display: block; min-block-size: 1.45em; overflow-wrap: anywhere; }
.quick-current-value { justify-self: start; }
.backup-selection { display: grid; gap: .5rem; min-inline-size: 0; margin: 0; padding: .6rem; border: 1px solid var(--line); border-radius: 8px; }
.backup-selection-list { display: grid; gap: .25rem; max-block-size: 14rem; overflow: auto; }
.backup-selection-list label { display: flex; align-items: start; gap: .45rem; padding: .25rem; }
[data-amount-words] { font-weight: 400; }
