:root {
  --agreement-blue: #075ca8;
  --agreement-blue-dark: #064c8a;
  --agreement-navy: #082f54;
  --agreement-line: #d8e2ea;
  --agreement-soft: #f4f7fa;
  --agreement-green: #16834a;
  --agreement-orange: #c65b08;
  --agreement-red: #b42318;
}

.agreement-page { min-height: 70vh; padding: 28px 0 56px; background: var(--page); }
.agreement-shell { display: grid; gap: 18px; max-width: 1240px; }
.agreement-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.agreement-heading-copy { display: flex; align-items: center; gap: 16px; }
.agreement-heading-icon { display: grid; flex: 0 0 64px; width: 64px; height: 64px; place-items: center; border-radius: 50%; color: var(--white); background: linear-gradient(145deg, #1677c5, #064b8a); font-family: Georgia, serif; font-size: 2rem; font-weight: 800; box-shadow: var(--shadow); }
.agreement-heading h1 { margin: 0 0 3px; font-size: clamp(1.85rem, 4vw, 2.55rem); }
.agreement-heading p { margin: 0; color: var(--muted); }
.agreement-eyebrow { margin: 0 0 4px; color: var(--agreement-blue); font-size: .78rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.agreement-primary, .agreement-secondary, .agreement-danger, .agreement-action { min-height: 44px; padding: 9px 14px; border-radius: var(--radius-small); font-weight: 800; }
.agreement-primary { border: 1px solid var(--agreement-blue); color: var(--white); background: linear-gradient(135deg, var(--agreement-blue), var(--agreement-blue-dark)); }
.agreement-primary:hover, .agreement-primary:focus-visible { background: var(--agreement-blue-dark); }
.agreement-secondary, .agreement-action { border: 1px solid var(--border-dark); color: var(--agreement-navy); background: var(--white); }
.agreement-secondary:hover, .agreement-secondary:focus-visible, .agreement-action:hover, .agreement-action:focus-visible { border-color: var(--agreement-blue); color: var(--agreement-blue); background: var(--blue-soft); }
.agreement-danger { border: 1px solid var(--agreement-red); color: var(--white); background: var(--agreement-red); }
.agreement-danger:hover, .agreement-danger:focus-visible { background: #8f1c13; }
.agreement-primary:disabled, .agreement-action:disabled, .agreement-danger:disabled { cursor: wait; opacity: .65; }

.agreement-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); overflow: hidden; border: 1px solid var(--agreement-line); border-radius: var(--radius-large); background: var(--white); box-shadow: var(--shadow); }
.agreement-summary article { display: grid; gap: 2px; min-height: 92px; padding: 16px 20px; align-content: center; text-align: center; border-left: 1px solid var(--agreement-line); }
.agreement-summary article:first-child { border-left: 0; }
.agreement-summary strong { color: var(--agreement-blue); font-size: 1.9rem; line-height: 1; }
.agreement-summary span { color: var(--agreement-navy); font-size: .88rem; font-weight: 800; }

.agreement-panel { overflow: hidden; border: 1px solid var(--agreement-line); border-radius: var(--radius-large); background: var(--white); box-shadow: var(--shadow); }
.agreement-panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--agreement-line); }
.agreement-panel-heading h2 { margin: 0 0 3px; color: var(--agreement-navy); font-size: 1.15rem; text-transform: uppercase; }
.agreement-panel-heading p { margin: 0; color: var(--muted); }
.agreement-filters { display: grid; grid-template-columns: minmax(290px, 1fr) 180px; gap: 10px; }
.agreement-filters input, .agreement-filters select, .agreement-form input, .agreement-form select, .agreement-form textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border-dark); border-radius: var(--radius-small); color: var(--agreement-navy); background: var(--white); }
.agreement-search-help { margin: 0; padding: 10px 20px; color: var(--muted); background: var(--agreement-soft); font-size: .88rem; border-bottom: 1px solid var(--agreement-line); }
.agreement-message { min-height: 24px; margin: 0; padding: 8px 20px 0; color: var(--muted); }
.agreement-message:empty { min-height: 0; padding-top: 0; }
.agreement-message.is-error { color: var(--danger); }
.agreement-message.is-success { padding-bottom: 8px; color: var(--success); font-weight: 700; }
.agreement-list { display: grid; gap: 14px; padding: 16px; background: #f7f9fb; }
.agreement-card { display: grid; gap: 15px; padding: 18px; border: 1px solid var(--agreement-line); border-radius: var(--radius-large); background: var(--white); box-shadow: 0 3px 12px rgba(4, 31, 56, .06); }
.agreement-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.agreement-title strong, .agreement-title small { display: block; }
.agreement-title strong { margin-bottom: 3px; color: var(--agreement-navy); font-size: 1.08rem; }
.agreement-title small { color: var(--muted); font-size: .84rem; overflow-wrap: anywhere; }
.agreement-statuses { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.agreement-badge, .agreement-index { display: inline-flex; width: fit-content; padding: 5px 9px; border-radius: 999px; font-size: .73rem; font-weight: 800; }
.agreement-badge { color: var(--agreement-blue); background: var(--blue-soft); text-transform: capitalize; }
.agreement-badge.archived, .agreement-badge.superseded { color: var(--muted); background: var(--agreement-soft); }
.agreement-index { color: var(--agreement-orange); background: #fff0e4; }
.agreement-index.searchable, .agreement-index.ocr_searchable { color: var(--agreement-green); background: #e5f6ec; }
.agreement-index.failed { color: var(--danger); background: #fdecec; }
.agreement-details { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.agreement-detail { padding: 10px 12px; border-radius: var(--radius-small); background: var(--agreement-soft); }
.agreement-detail small, .agreement-detail strong { display: block; }
.agreement-detail small { margin-bottom: 2px; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; }
.agreement-detail strong { color: var(--agreement-navy); font-size: .88rem; }
.agreement-description { margin: 0; color: var(--text); font-size: .9rem; }
.agreement-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.agreement-tag { padding: 4px 8px; border-radius: 999px; color: var(--agreement-navy); background: var(--blue-soft); font-size: .74rem; font-weight: 700; }
.agreement-match { display: grid; gap: 12px; min-width: 0; margin: 0; padding: 14px; border: 1px solid #c9def0; border-left: 4px solid var(--agreement-blue); border-radius: var(--radius-small); color: var(--text); background: #f0f7fd; font-size: .86rem; line-height: 1.6; }
.agreement-match p { min-width: 0; margin: 0; overflow-wrap: break-word; white-space: normal; }
.agreement-match strong { margin-bottom: 2px; color: var(--agreement-navy); }
.agreement-match mark { padding: 0 2px; color: var(--agreement-navy); background: #ffe08a; font-weight: 800; }
.agreement-match-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.agreement-match-summary strong { font-size: .95rem; }
.agreement-match-views { display: grid; gap: 12px; }
.agreement-match-view { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid #c9def0; }
.agreement-match-view[hidden] { display: none; }
.agreement-match-location { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.agreement-match-location a { color: var(--agreement-blue); font-weight: 800; text-decoration: none; }
.agreement-match-location a:hover, .agreement-match-location a:focus-visible { text-decoration: underline; }
.agreement-match-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.agreement-match-controls button { min-height: 40px; padding: 8px 12px; border: 1px solid var(--agreement-blue); border-radius: var(--radius-small); color: var(--agreement-blue); background: var(--white); font-weight: 800; cursor: pointer; }
.agreement-match-controls button:hover, .agreement-match-controls button:focus-visible { color: var(--white); background: var(--agreement-blue); }
.agreement-match-controls button:disabled { opacity: .45; cursor: not-allowed; color: var(--muted); background: var(--white); }
.agreement-match-controls [data-action="show-matches"] { margin-left: auto; }
.agreement-processing-error { display: block; color: var(--danger); font-size: .78rem; }
.agreement-card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; border-top: 1px solid var(--agreement-line); }
.agreement-card-actions a { text-decoration: none; }
.agreement-card-actions .agreement-danger { margin-left: auto; }
.agreement-empty { padding: 44px 20px; color: var(--muted); text-align: center; }
.management-only[hidden], .agreement-more[hidden] { display: none !important; }
.agreement-public-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.agreement-more { display: grid; gap: 14px; padding-top: 14px; border-top: 1px solid var(--agreement-line); }
.agreement-more-toggle[aria-expanded="true"] { color: var(--white); background: var(--agreement-navy); }

.agreement-dialog { width: min(94vw, 820px); max-height: 92vh; padding: 0; overflow: auto; border: 0; border-radius: var(--radius-large); box-shadow: 0 24px 70px rgba(4, 31, 56, .28); }
.agreement-dialog::backdrop { background: rgba(4, 31, 56, .68); }
.agreement-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--agreement-line); }
.agreement-dialog-header h2 { margin: 0 0 2px; color: var(--agreement-navy); }
.agreement-dialog-header p:last-child { margin: 0; color: var(--muted); font-size: .88rem; }
.dialog-close { flex: 0 0 44px; width: 44px; height: 44px; border: 0; border-radius: 50%; color: var(--agreement-navy); background: var(--agreement-soft); font-size: 1.4rem; }
.agreement-form { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding: 20px; }
.agreement-form label { display: grid; gap: 6px; color: var(--agreement-navy); font-weight: 800; }
.agreement-form textarea { resize: vertical; }
.full-field { grid-column: 1 / -1; }
.agreement-options { margin: 0; padding: 14px; border: 1px solid var(--agreement-line); border-radius: var(--radius-small); }
.agreement-options legend { padding: 0 6px; color: var(--agreement-navy); font-weight: 800; }
.agreement-options p { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.topic-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.option-item { display: flex !important; align-items: center; gap: 8px !important; min-height: 42px; padding: 8px 10px; border: 1px solid var(--agreement-line); border-radius: var(--radius-small); color: var(--agreement-navy); background: var(--white); font-weight: 700 !important; }
.option-item:has(input:checked) { border-color: var(--agreement-blue); background: var(--blue-soft); }
.option-item input { width: 18px; min-height: 18px; margin: 0; }
.file-field small { color: var(--muted); font-weight: 500; }
.agreement-form-actions { display: flex; justify-content: flex-end; gap: 10px; }
.delete-form p { margin: 0; }
.delete-warning { padding: 13px; border: 1px solid #efb3ad; border-radius: var(--radius-small); color: #7f1d1d; background: #fff1f0; }
.danger-text { color: var(--agreement-red); }

@media (max-width: 900px) {
  .agreement-panel-heading { align-items: stretch; flex-direction: column; }
  .agreement-filters { grid-template-columns: 1fr 1fr; }
  .agreement-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
  .agreement-page { padding-top: 20px; }
  .agreement-heading, .agreement-card-head { align-items: stretch; flex-direction: column; }
  .agreement-heading-copy { align-items: flex-start; }
  .agreement-heading-icon { flex-basis: 52px; width: 52px; height: 52px; font-size: 1.6rem; }
  .agreement-heading .agreement-primary { width: 100%; }
  .agreement-summary { grid-template-columns: 1fr 1fr; }
  .agreement-summary article { min-height: 72px; border-top: 1px solid var(--agreement-line); }
  .agreement-summary article:nth-child(odd) { border-left: 0; }
  .agreement-filters, .agreement-form, .option-grid, .topic-grid, .agreement-details { grid-template-columns: 1fr; }
  .agreement-statuses { justify-content: flex-start; }
  .agreement-card-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .agreement-match-location { align-items: flex-start; flex-direction: column; }
  .agreement-match-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .agreement-match-controls [data-action="show-matches"] { grid-column: 1 / -1; margin-left: 0; }
  .agreement-match-controls button { width: 100%; }
  .agreement-card-actions .agreement-danger { margin-left: 0; }
  .agreement-action, .agreement-card-actions a, .agreement-card-actions .agreement-danger { width: 100%; text-align: center; }
  .full-field { grid-column: auto; }
  .agreement-form-actions { display: grid; }
  .agreement-dialog { width: 96vw; max-height: 96vh; }
}


.agreement-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.agreement-heading-actions .agreement-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@media (max-width: 650px) {
  .agreement-heading-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .agreement-heading-actions > * {
    width: 100%;
  }
}
