:root {
  --ink: #1b1f24;
  --muted: #4f5b66;
  --accent: #1b3a55;
  --accent-dark: #142b3f;
  --paper: #ffffff;
  --paper-alt: #f3f5f7;
  --line: #cfd6de;
  --shadow: 0 10px 22px rgba(17, 27, 35, 0.08);
  --brand-blue: #1C4D8C;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Serif 4", serif;
  color: var(--ink);
  background-color: #f6f6f4;
  line-height: 1.5;
}

/* User Bar */
.user-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  padding: 8px 24px;
  background: var(--brand-blue);
  color: white;
  font-family: "Source Sans 3", system-ui, sans-serif;
  font-size: 13px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-name {
  font-weight: 600;
}

.user-role {
  opacity: 0.8;
  font-size: 12px;
  padding: 2px 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
  text-transform: capitalize;
}

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

.admin-link {
  color: white;
  text-decoration: none;
  opacity: 0.9;
  transition: opacity 0.2s;
}

.admin-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.logout-btn {
  padding: 4px 12px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}

.logout-btn:hover {
  background: rgba(255,255,255,0.25);
}

.background {
  display: none;
}

.page {
  max-width: 1100px;
  margin: 32px auto 64px;
  padding: 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  counter-reset: section;
}

.doc-header {
  display: grid;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.header-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 300px);
  gap: 18px;
  align-items: stretch;
}

.header-row.single {
  grid-template-columns: 1fr;
}

.letterhead {
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
  padding-top: 0;
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  align-content: center;
  align-self: stretch;
}

.logo-lockup {
  display: grid;
  gap: 6px;
  align-content: start;
  --logo-width: 180px;
  --logo-text-offset: 10%;
  width: var(--logo-width);
}

.logo-lockup img {
  width: 100%;
  height: auto;
}

.logo-meta {
  display: grid;
  gap: 2px;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: var(--logo-text-offset);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.6rem;
  color: var(--muted);
  margin: 0 0 3px;
}

h1 {
  font-family: "Source Serif 4", serif;
  font-weight: 600;
  font-size: 2.05rem;
  line-height: 1.1;
  margin: 0;
}

.subhead {
  margin: 2px 0 0;
  color: var(--muted);
  max-width: 580px;
  font-size: 0.88rem;
  line-height: 1.35;
}

.subhead a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

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

.meta-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  padding: 10px;
  background: var(--paper-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.meta-grid.letterhead-grid {
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 8px 10px;
  min-width: 220px;
  height: 100%;
  align-content: center;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 18px;
  padding: 10px 14px;
  background: var(--paper-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
}

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

.actions-row-secondary {
  justify-content: center;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.pdf-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

.pdf-controls .mode-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.pdf-controls select {
  padding: 5px 8px;
  font-size: 0.72rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  margin-right: 8px;
}

button {
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 6px 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button.secondary {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}

button.secondary:hover {
  background: var(--paper-alt);
}

.section {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  margin-bottom: 14px;
}

.section-header {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.section-header::before {
  counter-increment: section;
  content: "Section " counter(section, decimal-leading-zero);
  font-family: "Source Sans 3", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.58rem;
  color: var(--muted);
}

.section-header h2 {
  font-family: "Source Serif 4", serif;
  margin: 0;
  font-size: 1.2rem;
}

.section-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.grid {
  display: grid;
  gap: 10px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid.compact {
  gap: 8px;
}

.split-columns {
  gap: 16px;
}

.column-title {
  margin: 0 0 2px;
  font-family: "Source Sans 3", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.65rem;
  color: var(--muted);
}

.table-block {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.span-2 {
  grid-column: span 2;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
}

.field span {
  color: var(--muted);
  font-weight: 500;
  font-family: "Source Sans 3", sans-serif;
}

.field input,
.field select,
textarea,
.table-wrapper input {
  font-family: "Source Sans 3", sans-serif;
  padding: 7px 8px;
  border: 1px solid #c7ced6;
  border-radius: 4px;
  background: #fff;
  font-size: 0.86rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
textarea:focus,
.table-wrapper input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(27, 58, 85, 0.12);
  outline: none;
}

.field-inline {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

textarea {
  resize: none;
  min-height: 52px;
  width: 100%;
}

input::placeholder,
textarea::placeholder {
  color: #8e99a4;
}

.hidden {
  display: none;
}

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

.list-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1.2fr 1fr auto;
  align-items: center;
}

.list-row input {
  width: 100%;
}

.list-row .remove-row,
.pricing-table .remove-row {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
}

.list-row .remove-row:hover,
.pricing-table .remove-row:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.pricing-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}

.pricing-table.compact {
  min-width: 520px;
}

.pricing-table th,
.pricing-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
}

.pricing-table th {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  background: var(--paper-alt);
  font-family: "Source Sans 3", sans-serif;
}

.pricing-table td input {
  width: 100%;
}

.pricing-table.compact th,
.pricing-table.compact td {
  padding: 6px 8px;
}

.pricing-table.compact input {
  padding: 5px 6px;
  font-size: 0.82rem;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: "Source Sans 3", sans-serif;
}

.checkbox-group.inline {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.signature-block {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  background: #fdfdfb;
}

.signature-block h3 {
  margin: 0 0 8px;
  font-family: "Source Serif 4", serif;
  font-size: 0.98rem;
}

.add-row {
  margin-top: 8px;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
}

.table-actions .add-row {
  margin-top: 0;
}

.workspace-panel .section-header::before {
  content: "Workspace";
  counter-increment: none;
}

.workspace-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.workspace-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 12px;
  background: var(--paper-alt);
  display: grid;
  gap: 8px;
}

.workspace-card h3 {
  margin: 0;
  font-size: 0.95rem;
}

.workspace-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.workspace-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  justify-content: space-between;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-lines {
  display: grid;
  gap: 6px;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
}

.meta-lines span {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.6rem;
}

.meta-lines strong {
  display: block;
  font-size: 0.82rem;
  color: var(--ink);
  font-weight: 600;
}

.archive-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.archive-controls .field {
  min-width: 200px;
}

.archive-list,
.audit-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.archive-item,
.audit-item {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  background: #fff;
}

.archive-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.archive-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(27, 58, 85, 0.12);
}

.archive-main {
  display: grid;
  gap: 2px;
}

.archive-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.archive-title {
  font-size: 0.86rem;
  font-weight: 600;
}

.archive-meta {
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
}

.audit-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.7rem;
  color: var(--muted);
}

.audit-type {
  font-weight: 600;
  color: var(--ink);
}

.audit-detail {
  margin-top: 4px;
  font-size: 0.74rem;
  color: var(--muted);
  font-family: "Source Sans 3", sans-serif;
}

.helper {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: "Source Sans 3", sans-serif;
}

.archive-empty,
.audit-empty {
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 780px) {
  .page {
    margin: 20px 14px 32px;
    padding: 16px;
  }

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

  .letterhead {
    justify-content: flex-start;
    padding-top: 0;
  }

  .meta-grid.letterhead-grid {
    width: 100%;
    min-width: 0;
    height: auto;
    align-content: start;
  }

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

  .actions {
    gap: 8px;
  }

  .actions-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .pdf-controls {
    flex-direction: column;
    justify-content: center;
    gap: 8px;
  }

  .pdf-controls select {
    margin-right: 0;
  }

  .actions-row-secondary {
    padding-top: 8px;
  }

  .list-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .field-inline {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: legal;
    margin: 0.45in;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 11px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .actions,
  button {
    display: none !important;
  }

  .workspace-panel {
    display: none !important;
  }

  .page {
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    border: none;
    max-width: 100%;
  }

  .section {
    break-inside: avoid;
    padding: 10px 12px;
    margin-bottom: 10px;
  }

  .section-header {
    margin-bottom: 8px;
    padding-bottom: 4px;
  }

  .table-wrapper {
    overflow: visible;
  }

  .pricing-table {
    min-width: 0;
  }

  .pricing-table th,
  .pricing-table td {
    padding: 6px 8px;
  }

  .pricing-table.compact th,
  .pricing-table.compact td {
    padding: 5px 6px;
  }

  input,
  select,
  textarea {
    color: #000;
    background: #fff;
    border-color: #9aa4af;
    box-shadow: none;
  }
}

/* Toggle Lock Styles */
.toggle-lock {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  margin-top: 0.25rem;
}

.toggle-lock input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-lock span {
  font-weight: 500;
}

textarea[readonly] {
  background-color: var(--paper-alt);
  cursor: not-allowed;
  opacity: 0.85;
}

textarea:not([readonly]) {
  background-color: var(--paper);
}

/* Signing Modal Styles */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--paper);
  border-radius: 0.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.125rem;
  color: var(--ink);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem;
  line-height: 1;
}

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

.modal-body {
  margin-bottom: 1rem;
}

.modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.signing-options {
  display: grid;
  gap: 1rem;
}

.signing-option {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.signing-option:hover {
  border-color: var(--accent);
  background-color: rgba(27, 58, 85, 0.03);
}

.signing-option.selected {
  border-color: var(--accent);
  background-color: rgba(27, 58, 85, 0.06);
}

.signing-option h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  color: var(--ink);
}

.signing-option p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.share-link-container {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.share-link-container input {
  flex: 1;
  font-family: monospace;
  font-size: 0.8rem;
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-badge.draft {
  background: #e3e8ed;
  color: #4f5b66;
}

.status-badge.sent,
.status-badge.pending,
.status-badge.awaiting {
  background: #fff3cd;
  color: #856404;
}

.status-badge.completed,
.status-badge.signed {
  background: #d4edda;
  color: #155724;
}

.status-badge.error,
.status-badge.failed {
  background: #f8d7da;
  color: #721c24;
}

/* Agreement Viewer Styles */
.agreement-viewer {
  background: var(--paper-alt);
  border: 1px solid var(--line);
  border-radius: 0.375rem;
  padding: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.agreement-viewer .field-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.agreement-viewer .field-row:last-child {
  border-bottom: none;
}

.agreement-viewer .field-label {
  font-weight: 600;
  color: var(--muted);
}

.agreement-viewer .field-value {
  color: var(--ink);
}
