:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #17201b;
  --muted: #66706a;
  --line: #d9ded8;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --danger: #b42318;
  --warn: #b25e09;
  --ok: #217a45;
  --soft-green: #e8f4ef;
  --soft-red: #fff0ed;
  --soft-amber: #fff5e5;
  --shadow: 0 18px 45px rgba(18, 31, 26, 0.11);
  --page-max: 1640px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, filter 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
  transform: translateY(0);
  -webkit-tap-highlight-color: transparent;
}

button:hover:not(:disabled) {
  filter: brightness(0.98);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
  box-shadow: inset 0 2px 5px rgba(15, 35, 29, 0.18);
}

button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.26);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
}

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

.sidebar {
  background: #10231d;
  color: #f7fbf8;
  padding: 24px 18px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: #d6efe4;
  color: #10231d;
  border-radius: 8px;
  font-weight: 800;
}

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

.brand span {
  color: #b8cbc4;
  font-size: 13px;
  margin-top: 2px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d7e3de;
  padding: 10px 12px;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-item span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
}

.main {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: 28px;
}

.topbar {
  width: 100%;
  max-width: var(--page-max);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

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

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

.topbar-actions,
.row-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
  font-weight: 650;
}

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

.ai-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  background: #0f766e;
  color: #ffffff;
  padding: 12px 18px;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.22);
}

.ai-button:hover {
  background: #0b5f59;
}

.primary-button:active:not(:disabled),
.ai-button:active:not(:disabled) {
  box-shadow: inset 0 2px 7px rgba(5, 46, 43, 0.34), 0 4px 10px rgba(15, 118, 110, 0.12);
}

.ai-button:disabled {
  cursor: wait;
  opacity: 0.82;
}

.button-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.38);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.ai-button.loading .button-spinner {
  display: inline-block;
}

.primary-button.loading {
  cursor: wait;
  opacity: 0.85;
}

.primary-button.loading .button-spinner {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

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

.danger-button {
  background: var(--soft-red);
  color: var(--danger);
  border-color: #ffd2ca;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}

.modal-close {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.modal-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.view {
  display: none;
}

.is-hidden {
  display: none !important;
}

.view.active {
  display: block;
  width: 100%;
  max-width: var(--page-max);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

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

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.deal-documents-layout {
  display: grid;
  grid-template-columns: minmax(760px, 1fr) 280px;
  gap: 18px;
  align-items: start;
}

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

.backup-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfa;
}

.backup-status {
  margin-top: 12px;
}

.section {
  margin-bottom: 18px;
}

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

.section-header > * {
  min-width: 0;
}

.section-header h2 {
  margin: 0;
  font-size: 18px;
}

.content-grid .section-header {
  min-height: 42px;
}

.compact-section-header {
  align-items: flex-start;
}

.compact-section-header h3 {
  margin: 0;
}

.contract-detail-actions {
  justify-content: space-between;
  gap: 12px;
}

.contract-detail-actions .row-actions {
  justify-content: flex-start;
}

.table-wrap,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

.contracts-table {
  table-layout: fixed;
  min-width: 1280px;
}

.contracts-table .contract-col-number { width: 13%; }
.contracts-table .contract-col-type { width: 9%; }
.contracts-table .contract-col-object { width: 26%; }
.contracts-table .contract-col-date { width: 7.8%; }
.contracts-table .contract-col-days { width: 6.8%; }
.contracts-table .contract-col-money { width: 7%; }
.contracts-table .contract-row { cursor: pointer; }
.contracts-table .contract-row > td { transition: background-color 140ms ease; }
.contracts-table .contract-row:hover > td,
.contracts-table .contract-row:focus-visible > td { background-color: #e8f3ef; }
.contracts-table .contract-row:focus-visible { outline: 2px solid #0d7b73; outline-offset: -2px; }

.documents-table {
  table-layout: fixed;
  min-width: 780px;
}

.documents-table th:nth-child(1),
.documents-table td:nth-child(1) {
  width: 32%;
}

.documents-table th:nth-child(2),
.documents-table td:nth-child(2) {
  width: 14%;
}

.documents-table th:nth-child(3),
.documents-table td:nth-child(3) {
  width: 20%;
}

.documents-table th:nth-child(4),
.documents-table td:nth-child(4) {
  width: 16%;
  text-align: left;
}

.documents-table th:nth-child(5),
.documents-table td:nth-child(5) {
  width: 18%;
  text-align: left;
}

.documents-table td:nth-child(5) .row-actions,
.documents-table .row-actions {
  justify-content: flex-start;
  flex-wrap: nowrap;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #fbfcfa;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
}

.table-sort-button span {
  color: var(--teal);
  font-size: 11px;
}

.table-sort-button:active {
  transform: translateY(1px);
}

tr:last-child td {
  border-bottom: 0;
}

.contract-name {
  display: grid;
  gap: 3px;
}

.contract-name strong {
  font-size: 14px;
}

.contract-name span {
  color: var(--muted);
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
}

.status.ok {
  background: var(--soft-green);
  color: var(--ok);
}

.status.warn {
  background: var(--soft-amber);
  color: var(--warn);
}

.status.danger {
  background: var(--soft-red);
  color: var(--danger);
}

.status.neutral {
  background: #eef1f0;
  color: #4f5b55;
}

.days-left-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.days-left-badge.ok {
  background: var(--soft-green);
  color: var(--ok);
}

.days-left-badge.warn {
  background: var(--soft-amber);
  color: var(--warn);
}

.days-left-badge.danger {
  background: var(--soft-red);
  color: var(--danger);
}

.document-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.file-badge-group,
.document-status-group {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: #ffffff;
}

.file-badge {
  min-height: 24px;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 900;
  background: #ffffff;
}

.file-badge:last-child {
  border-right: 0;
}

.file-badge.word {
  color: #1f5f9f;
}

.file-badge.pdf {
  color: #b42318;
}

.file-badge:hover {
  background: #f5f8f7;
}

.pdf-status-badge {
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 900;
}

.pdf-status-badge.unsigned {
  background: var(--soft-red);
  color: var(--danger);
}

.pdf-status-badge.partial {
  background: var(--soft-amber);
  color: var(--warn);
}

.pdf-status-badge.signed {
  background: var(--soft-green);
  color: var(--ok);
}

.pdf-status-badge.superseded {
  background: #eef1f0;
  color: #4f5b55;
}

.pdf-status-badge:hover {
  filter: brightness(0.97);
}

.modal.preview-modal {
  width: min(1280px, calc(100vw - 28px));
}

.document-preview-frame {
  width: 100%;
  height: min(72vh, 820px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.doc-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
}

.doc-badge.word {
  background: #e9f2ff;
  color: #1f5f9f;
}

.doc-badge.pdf {
  background: #fff0ed;
  color: #b42318;
}

.doc-badge.signed {
  background: var(--soft-green);
  color: var(--ok);
}

.doc-badge.partial-signed {
  background: var(--soft-amber);
  color: var(--warn);
}

.doc-badge.unsigned {
  background: #eef1f0;
  color: #4f5b55;
}

.compact-action {
  min-height: 32px;
  padding: 6px 10px;
}

.panel {
  padding: 16px;
}

.document-folder-panel {
  margin-top: 12px;
  padding: 12px;
}

.notes-panel {
  display: grid;
  gap: 12px;
  min-height: 320px;
}

.notes-list {
  display: grid;
  align-content: start;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.note-message {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
  padding: 10px 12px;
}

.note-message.is-editing {
  background: #fff;
}

.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.note-message p,
.notes-empty {
  margin: 0;
  line-height: 1.45;
  white-space: pre-wrap;
}

.note-actions {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.note-edit-form {
  display: grid;
  gap: 8px;
}

.note-edit-form textarea {
  min-height: 84px;
}

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

.note-form {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.note-form textarea {
  min-height: 84px;
}

.note-form button {
  justify-self: end;
}

.icon-text-button {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-weight: 700;
  padding: 0;
}

.icon-text-button.neutral {
  color: var(--accent);
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.timeline-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.timeline-date {
  color: var(--muted);
  font-size: 13px;
}

.timeline-title {
  font-weight: 700;
}

.timeline-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 300px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  padding: 30px;
}

.empty-state h3,
.empty-state p {
  margin: 0;
}

.empty-state p {
  color: var(--muted);
}

.modal {
  width: min(860px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(7, 19, 15, 0.55);
}

.modal-inner {
  padding: 22px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.modal h2,
.modal p {
  margin: 0;
}

.modal p {
  color: var(--muted);
  margin-top: 5px;
}

.confirm-modal {
  width: min(440px, calc(100vw - 32px));
}

.confirm-inner {
  display: grid;
  gap: 22px;
}

.confirm-inner h2 {
  font-size: 22px;
}

.confirm-inner p {
  color: var(--ink);
  line-height: 1.45;
}

.confirm-inner .modal-actions {
  justify-content: flex-end;
}

.prompt-field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  font-weight: 700;
}

.prompt-field input {
  width: 100%;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.settings-path-list {
  display: grid;
  gap: 14px;
}

.path-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.settings-path-row {
  padding: 0;
}

.path-picker-row label {
  min-width: 0;
}

.readonly-path-input {
  background: #f7faf8;
  color: var(--ink);
  cursor: default;
}

.readonly-path-input:focus {
  outline: none;
  border-color: var(--line);
  box-shadow: none;
}

.path-picker-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  padding-bottom: 0;
  width: 100%;
  justify-self: end;
}

.path-picker-actions .secondary-button,
.path-picker-actions .primary-button {
  white-space: nowrap;
}

.settings-subpanel {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 16px 0 16px 16px;
  border: 1px solid #b8ded7;
  border-radius: 8px;
  background: #eefaf7;
}

.settings-subpanel-title {
  font-size: 16px;
  font-weight: 800;
}

.settings-foot-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
  padding-right: 0;
}

.settings-foot-row .timeline-meta {
  margin: 0;
}

.settings-foot-row .primary-button {
  justify-self: end;
  min-width: 100px;
}

.database-files-grid {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.modal-actions.align-right {
  justify-content: flex-end;
}

.dialog-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.dialog-tab {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 800;
}

.dialog-tab.active {
  border-color: var(--accent);
  background: #eef8f5;
  color: var(--accent);
}

.contract-mode-pane {
  display: none;
}

.contract-mode-pane.active {
  display: block;
}

.template-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.template-tab {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 12px;
  font-weight: 800;
}

.template-tab.active {
  border-color: var(--accent);
  background: #eef8f5;
  color: var(--accent);
}

.template-header {
  display: grid;
  grid-template-columns: minmax(420px, 1.3fr) minmax(280px, 1fr) minmax(180px, auto);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
}

.template-title-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.template-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.template-name-line strong {
  overflow-wrap: anywhere;
}

.template-primary-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.85em;
  color: var(--text);
  min-height: 26px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.template-file-field {
  min-width: 0;
}

.template-file-meta {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

#draftContractPane,
#draftContractFields,
#draftContractFields .draft-section,
#draftContractFields label,
#draftContractFields textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

#draftContractFields textarea {
  min-width: 0;
  width: 100% !important;
  max-width: 100% !important;
  resize: vertical;
  display: block;
}

#contractDialog .form-grid,
#contractDialog .modal-inner {
  min-width: 0;
  overflow-x: hidden;
}

#amendmentDialog,
#amendmentDialog .modal-inner,
#amendmentDialog .draft-contract-fields,
#amendmentDialog .draft-section,
#amendmentDialog label,
#amendmentDialog textarea,
#amendmentDialog input,
#amendmentDialog select {
  max-width: 100%;
  min-width: 0;
}

#amendmentDialog .modal-inner {
  overflow-x: hidden;
}

#amendmentTemplateFields {
  width: 100%;
  overflow-x: hidden;
}

#amendmentTemplateFields textarea {
  width: 100% !important;
  max-width: 100% !important;
  resize: vertical;
  display: block;
}

.contract-upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  gap: 12px;
}

.contract-upload-row .ai-button {
  width: 100%;
  min-height: 46px;
}

.draft-contract-fields,
.ready-contract-fields,
.contract-settings-panel {
  display: grid;
  gap: 14px;
}

.draft-section,
.contract-settings-section {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.contract-settings-section.is-dragging,
.field-setting-row.is-dragging {
  opacity: 0.45;
}

.contract-settings-section.is-drop-target,
.field-setting-row.is-drop-target {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.contract-settings-section-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.drag-handle {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: #54635b;
  cursor: grab;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.draft-section h3,
.contract-settings-section h3 {
  margin: 0;
  font-size: 15px;
}

.field-setting-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.field-setting-row textarea,
.field-title-line {
  grid-column: 2 / -1;
}

.field-drag-handle {
  grid-row: span 3;
}

.field-title-line {
  display: grid;
  grid-template-columns: max-content max-content max-content minmax(16px, 1fr) 170px 560px;
  align-items: center;
  gap: 8px;
}

.field-title-line .field-toggle {
  width: max-content;
  max-width: 100%;
}

.header-field-row {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.header-field-row .field-title-line {
  grid-column: 2;
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(360px, 560px) auto;
  gap: 12px;
  align-items: center;
}

.header-field-row .field-toggle {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  align-items: center;
  width: 100%;
}

.header-field-row .field-variable-input {
  grid-column: auto;
  justify-self: stretch;
  width: 100%;
}

.header-field-row .danger-text-button {
  justify-self: start;
}

.header-label-input {
  min-width: 0;
}

.field-variable-input {
  grid-column: 6;
  font-family: Consolas, "Courier New", monospace;
  color: var(--accent);
  background: #eef8f5;
  border-color: #d8e8e3;
  justify-self: end;
  width: 560px;
  max-width: 100%;
}

.field-type-select {
  grid-column: 5;
  min-width: 150px;
}

.field-options-builder {
  grid-column: 2 / -1;
  display: grid;
  gap: 8px;
}

.field-options-list {
  display: grid;
  gap: 8px;
}

.field-option-row {
  display: grid;
  grid-template-columns: minmax(220px, 420px) auto;
  align-items: center;
  gap: 8px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
  cursor: pointer;
  padding: 4px 6px;
  justify-self: start;
  white-space: nowrap;
}

.danger-text-button {
  color: var(--danger);
}

.section-title-input,
.field-title-input {
  min-height: 30px;
  padding: 5px 8px;
  font-weight: 800;
}

.field-title-input {
  grid-column: 1 / 2;
}

.settings-help {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-toggle input {
  width: auto;
  min-height: 0;
}

label {
  display: grid;
  gap: 7px;
  color: #34413a;
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
  min-height: 36px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.money-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 120px;
  align-items: center;
  gap: 8px;
}

.date-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
}

.date-input input[type="date"] {
  width: 42px !important;
  min-width: 42px;
  height: 42px;
  padding: 0;
  color: transparent;
  caret-color: transparent;
  overflow: hidden;
  font-size: 0;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23071410' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 2v4'/%3E%3Cpath d='M16 2v4'/%3E%3Crect width='18' height='18' x='3' y='4' rx='2'/%3E%3Cpath d='M3 10h18'/%3E%3C/svg%3E");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 18px 18px;
}

.date-input input[type="date"]::-webkit-datetime-edit,
.date-input input[type="date"]::-webkit-datetime-edit-fields-wrapper,
.date-input input[type="date"]::-webkit-datetime-edit-text,
.date-input input[type="date"]::-webkit-datetime-edit-month-field,
.date-input input[type="date"]::-webkit-datetime-edit-day-field,
.date-input input[type="date"]::-webkit-datetime-edit-year-field {
  color: transparent;
}

.date-input input[type="date"]::-webkit-calendar-picker-indicator {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 10px;
  opacity: 0;
  cursor: pointer;
}

.money-input span {
  font-weight: 800;
  color: var(--accent);
}

.choice-list {
  display: grid;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.choice-item {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  font-weight: 650;
}

.choice-item input {
  width: auto;
  min-height: 0;
}

.text-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfa;
}

.text-details summary {
  cursor: pointer;
  font-weight: 700;
}

.text-details textarea {
  margin-top: 10px;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.ai-result {
  margin-top: 14px;
  border: 1px solid #b8d9d2;
  background: #eef9f6;
  border-radius: 8px;
  padding: 14px;
}

.ai-status {
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 14px;
  font-weight: 650;
}

.ai-status.neutral {
  background: #eef1f0;
  color: #4f5b55;
}

.ai-status.ok {
  background: var(--soft-green);
  color: var(--ok);
}

.ai-status.warn {
  background: var(--soft-amber);
  color: var(--warn);
}

.ai-result h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.ai-result ul {
  margin: 0;
  padding-left: 18px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.detail {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.detail span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail strong {
  display: block;
  margin-top: 3px;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.detail a {
  color: var(--accent);
  text-decoration: none;
}

.detail a:hover {
  text-decoration: underline;
}

.contact-link {
  color: var(--accent);
  text-decoration: none;
}

.contact-link:hover {
  text-decoration: underline;
}

.card-edit-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.searchbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.search-input-wrap {
  display: block;
  position: relative;
  width: min(520px, 100%);
}

.searchbar input,
.search-input-wrap input {
  width: 100%;
  max-width: 420px;
  padding-right: 42px;
}

.search-input-wrap input {
  max-width: none;
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 8px;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transform: translateY(-50%);
}

.search-clear:hover {
  color: var(--ink);
  background: #eef4f0;
}

.search-clear:active {
  transform: translateY(calc(-50% + 1px)) scale(0.96);
}

.integration-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
}

.settings-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  max-width: 100%;
}

.contract-nav-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.contract-nav-row .settings-tabs {
  margin-bottom: 0;
  border-bottom: 0;
}

.settings-tab {
  min-height: 42px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  font-weight: 800;
}

.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
}

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

.integration h3 {
  margin: 0 0 8px;
}

.integration p {
  color: var(--muted);
  margin: 0 0 14px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    overflow-x: auto;
  }

  .nav-item {
    justify-content: center;
    min-width: 118px;
  }

  .metric-grid,
  .content-grid,
  .deal-documents-layout,
  .backup-settings-grid,
  .integration-grid,
  .template-header {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .section-header {
    display: grid;
  }

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

  .contract-upload-row {
    grid-template-columns: 1fr;
  }

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

  th,
  td {
    white-space: nowrap;
  }
}
.compact-field {
  gap: 5px;
}

.compact-field textarea {
  min-height: 72px;
}

/* Unified modal layout: forms must never create horizontal scrolling. */
.modal {
  max-width: calc(100vw - 28px);
  overflow: hidden;
}

.modal-inner {
  width: 100%;
  max-width: 100%;
  max-height: min(88vh, 920px);
  overflow-y: auto;
  overflow-x: hidden;
}

.modal-inner *,
.modal-inner *::before,
.modal-inner *::after {
  min-width: 0;
}

.modal-inner label,
.modal-inner .form-grid,
.modal-inner .draft-contract-fields,
.modal-inner .ready-contract-fields,
.modal-inner .draft-section,
.modal-inner .contract-settings-panel,
.modal-inner .contract-settings-section,
.modal-inner .compact-field,
.modal-inner .choice-list,
.modal-inner .field-options-builder,
.modal-inner .field-options-list {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.modal-inner input,
.modal-inner select,
.modal-inner textarea {
  width: 100% !important;
  max-width: 100% !important;
}

.modal-inner textarea {
  min-height: 66px;
  resize: vertical;
}

.modal-inner .money-input,
.modal-inner .date-input {
  width: 100%;
  max-width: 100%;
}

.modal-inner .money-input input,
.modal-inner .date-input input {
  width: 100% !important;
}

.modal-inner .choice-item {
  width: 100%;
  max-width: 100%;
  justify-content: flex-start;
  overflow-x: visible;
}

.modal-inner .choice-item input[type="radio"],
.modal-inner .choice-item input[type="checkbox"] {
  flex: 0 0 auto;
  width: auto !important;
  min-width: 0;
  min-height: 0;
}

.modal-inner .modal-actions {
  max-width: 100%;
}
.amendment-ai-history { max-height: 420px; overflow-y: auto; margin: 16px 0; }
.amendment-ai-message { padding: 14px; margin-bottom: 10px; border: 1px solid #d5dfda; border-radius: 8px; }
.amendment-ai-message > div { margin: 8px 0; overflow-wrap: anywhere; }
#amendmentAiText { width: 100%; min-height: 160px; resize: vertical; }
.consultant-panel { margin-bottom: 24px; }
.consultant-panel .section-header { flex-wrap: wrap; gap: 10px; }
.consultant-history { max-height: 420px; overflow-y: auto; margin: 12px 0; }
.consultant-panel textarea { width: 100%; min-height: 120px; resize: vertical; margin-bottom: 10px; }
.consultant-dialog { width: min(900px, calc(100vw - 32px)); max-height: 90vh; }
.consultant-dialog-inner { padding: 24px; }
.consultant-dialog .consultant-panel { margin-bottom: 12px; }
.consultant-dialog .consultant-history { max-height: 45vh; }
.consultant-dialog { width: min(1180px, calc(100vw - 32px)); }
.auth-page { min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 48px 16px; }
.auth-card { width: min(560px, 100%); padding: 28px; }
.auth-card form { display: grid; gap: 16px; margin: 24px 0; }
.auth-card label { display: grid; gap: 6px; }
.auth-card [hidden] { display: none; }
.auth-card input { width: 100%; }
.user-editor-dialog .auth-card { width: 100%; }
.user-editor-dialog .form-grid { max-width: 504px; }
.user-editor-dialog .row-actions { display: flex; flex-wrap: nowrap; overflow-x: auto; }
.user-editor-dialog .row-actions button { flex-shrink: 0; white-space: nowrap; }
.auth-nav { display: grid; gap: 12px; margin-top: 24px; }
.auth-nav a { color: inherit; }
.consultant-workspace { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; }
.consultant-chat-list { display: flex; flex-direction: column; gap: 8px; max-height: 65vh; overflow-y: auto; }
.consultant-chat-choice { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 6px; overflow-wrap: anywhere; }
.consultant-chat-choice.active { background: #e8f3ef; border-color: #0d7b73; }
.consultant-chat-body { min-width: 0; }
@media (max-width: 720px) { .consultant-workspace { grid-template-columns: 1fr; } .consultant-chat-list { max-height: 180px; } }

.journal-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.journal-pagination label { display: flex; align-items: center; gap: 8px; }
.journal-pagination select { width: auto; min-width: 80px; }

[hidden] { display: none !important; }

.role-editor-dialog { width: min(760px, calc(100vw - 28px)); max-height: 90vh; padding: 0; overflow-y: auto; }
.role-editor-dialog .auth-card { width: 100%; margin: 0; padding: 24px; box-sizing: border-box; }
.role-editor-dialog h2 { margin: 0 0 20px; }
.role-editor-dialog fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 16px; min-width: 0; }
.role-editor-dialog .auth-card .role-permission { display: flex; align-items: center; gap: 10px; margin: 0; min-height: 42px; padding: 8px 12px; border: 1px solid #d6dfdb; border-radius: 8px; background: #f7faf9; }
.role-editor-dialog .auth-card input[type="checkbox"] { width: 18px; height: 18px; min-height: 18px; flex: 0 0 18px; margin: 0; padding: 0; accent-color: #0d7c76; }
.role-editor-dialog [data-role-sections] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.role-editor-dialog textarea { min-height: 70px; resize: vertical; }
.role-editor-dialog .row-actions { position: sticky; bottom: -24px; background: white; padding: 16px 0; margin-bottom: -24px; border-top: 1px solid #d6dfdb; }
.role-editor-dialog [role="status"]:empty { display: none; }
.role-editor-dialog fieldset:disabled { opacity: .8; }
@media (max-width: 580px) { .role-editor-dialog [data-role-sections] { grid-template-columns: 1fr; } .role-editor-dialog .auth-card { padding: 18px; } }

.content-grid.notes-only { grid-template-columns: minmax(0, 1fr); }
.notes-panel .notes-heading { margin: 0 0 16px; }

.role-editor-dialog .role-settings-group { border: 1px solid #b9d6ce; border-radius: 10px; background: #f4f9f7; overflow: hidden; }
.role-editor-dialog .auth-card .role-settings-parent { border: 0; border-bottom: 1px solid #cddfd9; border-radius: 0; background: #e5f1ed; padding: 12px 14px; }
.role-editor-dialog .role-settings-group [data-role-sections] { margin: 14px 14px 14px 24px; padding-left: 14px; border-left: 2px solid #b9d6ce; }
.role-editor-dialog .role-settings-group [data-role-sections] .role-permission { background: #fff; }
@media (max-width: 580px) { .role-editor-dialog .role-settings-group [data-role-sections] { margin-left: 14px; padding-left: 10px; } }

.role-editor-dialog .role-deals-options { margin: 14px 14px 14px 24px; padding-left: 14px; border-left: 2px solid #b9d6ce; }
@media (max-width: 580px) { .role-editor-dialog .role-deals-options { margin-left: 14px; padding-left: 10px; } }

.role-editor-dialog .role-deals-radios { display: grid; gap: 8px; }
.role-editor-dialog .auth-card input[type="radio"] { width: 18px; height: 18px; min-height: 18px; flex: 0 0 18px; margin: 0; padding: 0; accent-color: #0d7c76; }

.signing-action { display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.signing-action svg { flex: 0 0 14px; }

.elpako-signing-dialog p[data-control]:not(:empty),
.elpako-signing-dialog p[data-result]:not(:empty) {
  color: #0756a3;
  background: #edf6ff;
  border-left: 3px solid #1684e8;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 12px 0;
  font-weight: 600;
  line-height: 1.5;
}
.elpako-signing-dialog p[data-control]:empty,
.elpako-signing-dialog p[data-result]:empty { display: none; }

.elpako-appearance { border: 1px solid #cbdad5; border-radius: 8px; padding: 14px; margin: 16px 0; }
.elpako-appearance legend { font-weight: 700; padding: 0 6px; }
.elpako-appearance summary { cursor: pointer; margin-top: 12px; color: #0d7771; }

.role-editor-dialog .role-signature-heading { margin: 0; padding: 12px 14px; border-bottom: 1px solid #cddfd9; background: #e5f1ed; font-size: 14px; line-height: 20px; font-weight: 700; }
.role-editor-dialog .role-signature-options { display: grid; gap: 8px; margin: 14px 14px 14px 24px; padding-left: 14px; border-left: 2px solid #b9d6ce; }
.role-editor-dialog .auth-card .role-signature-options .role-permission { background: #fff; }
.role-editor-dialog .role-signature-options input { flex-shrink: 0; }
@media (max-width: 580px) { .role-editor-dialog .role-signature-options { margin-left: 14px; padding-left: 10px; } }
.signature-drop { border: 2px dashed #79aaa0; border-radius: 12px; padding: 26px; text-align: center; background: #f4f9f7; cursor: pointer; margin-bottom: 18px; } .signature-drop.dragover, .signature-drop:focus-visible { background: #e5f1ed; outline: 2px solid #087e78; } #signaturesView [data-sign-list] { overflow-x: auto; margin-top: 18px; }

.standalone-signing-toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.standalone-upload-dialog { width: min(760px, calc(100vw - 32px)); max-height: 90vh; overflow-y: auto; }
.standalone-upload-dialog .signature-drop { padding: 24px 16px; }

.standalone-file-action { display: inline-flex; align-items: center; justify-content: center; gap: 6px; vertical-align: middle; }
.standalone-preview-dialog { width: min(1280px, calc(100vw - 32px)); max-height: 92vh; padding: 20px; }
.standalone-preview-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.standalone-preview-header h2 { margin: 0; overflow-wrap: anywhere; }
.standalone-preview-dialog iframe { width: 100%; height: 72vh; border: 0; }
