/* V86 surgical fixes — loaded AFTER portal-v84e-final.css.
   ONLY targets specific broken elements. Does NOT touch global layout. */

/* =====================================================================
   FIX 0 (CRITICAL): Templates-container visibility override
   portal-facelift.css line 6546 sets .tt-template-app { display: block !important }
   which OVERRIDES .hidden { display: none !important } because it loads later
   with the same specificity. We need higher specificity (2 classes > 1 class).
   ===================================================================== */

.tt-template-app.hidden,
#templates-container.hidden {
  display: none !important;
}

/* =====================================================================
   FIX 1: Contract template text classes
   When extractEditableTemplateHtml() strips <style> from template HTML,
   these classes lose all styling. We re-provide them scoped under
   .tt-paper-content (the editor's contenteditable wrapper).
   ===================================================================== */

/* V94r: title sized for visual hierarchy (16px / 1.33em) — matches the
   PDF after we also bump the PDF title to 16px in admin/modules/pdf.js. */
.tt-paper-content .contract-title {
  text-align: center !important;
  margin-top: 0 !important;
  margin-bottom: 1rem !important;
}

.tt-paper-content .contract-title h1 {
  font-size: 16px !important;
  font-weight: 700 !important;
  margin: 0 !important;
  letter-spacing: 0.02em !important;
  line-height: 1.3 !important;
}

.tt-paper-content .preamble {
  text-align: center !important;
  margin-top: 0 !important;
  margin-bottom: 1rem !important;
}

.tt-paper-content .preamble p {
  margin: 0 0 0.25rem !important;
}

.tt-paper-content .party-block {
  text-align: left !important;
  margin: 1rem 0 !important;
  padding: 0.5rem 0 !important;
}

.tt-paper-content .party-block p {
  margin: 0 0 0.25rem !important;
}

.tt-paper-content .section-heading {
  font-weight: 700 !important;
  margin: 1.5rem 0 0.5rem !important;
  letter-spacing: 0.03em !important;
  page-break-after: avoid !important;
  break-after: avoid !important;
}

.tt-paper-content .clauses,
.tt-paper-content .subclauses {
  list-style: none !important;
  padding-left: 0 !important;
  margin: 0 !important;
}

.tt-paper-content .clauses > li {
  margin-bottom: 1rem !important;
}

.tt-paper-content .subclauses > li {
  margin-bottom: 0.5rem !important;
}

.tt-paper-content .subclauses > li:last-child {
  margin-bottom: 0 !important;
}

.tt-paper-content .clause-text {
  margin: 0 !important;
}

.tt-paper-content .list-inline {
  margin: 0.25rem 0 1rem !important;
  padding-left: 1.4rem !important;
}

.tt-paper-content .list-inline li {
  margin-bottom: 0.5rem !important;
}

.tt-paper-content .note-text {
  font-size: 0.92em !important;
}

.tt-paper-content .closing-block {
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

.tt-paper-content .page-break-before {
  break-before: page !important;
  page-break-before: always !important;
}

/* V95e: <section class="page-break"> wraps the Anlage. Force it onto a new
   page (both in PDF print AND visually in the editor — the JS paginator
   reads this rule via the data-page-break attribute marker below). */
.tt-paper-content .page-break,
.tt-paper-content section.page-break {
  break-before: page !important;
  page-break-before: always !important;
  margin-top: 2rem !important;
}
.tt-paper-content section.page-break[data-section="annex-agency"] {
  break-before: page !important;
  page-break-before: always !important;
}

.tt-paper-content .annex-title {
  margin-top: 2rem !important;
  margin-bottom: 0.5rem !important;
  font-weight: 700 !important;
  letter-spacing: 0.03em !important;
}

.tt-paper-content .contract-body {
  display: block !important;
  width: 100% !important;
}

/* Signature layout — override the facelift's display:block to use
   the original flex layout from the template */
/* V95c: signature widow protection in the editor view too. */
.tt-paper-content .signature-block,
.tt-paper-content .signature-block.rv-signature-block {
  margin-top: 2rem !important;
  break-before: avoid !important;
  page-break-before: avoid !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

.tt-paper-content .signature-container,
.tt-paper-content .signature-container.rv-signature-container {
  display: flex !important;
  justify-content: space-between !important;
  gap: 1rem !important;
  margin-bottom: 1.5rem !important;
  break-inside: avoid !important;
  page-break-inside: avoid !important;
}

.tt-paper-content .signature-column {
  flex: 1 !important;
  min-width: 0 !important;
  display: block !important;
  width: auto !important;
  margin: 0 !important;
}

.tt-paper-content .signature-column p {
  margin: 0 0 0.5rem !important;
  font-size: 0.9em !important;
}

/* V96l: surgical .tt-paper-content sig-line — legacy 80px / e0e0e0 / 2px
   gray border replaced with the V93 V96l look (120px, soft grey #fafbfc
   surface, 1px #d1d5db border, 8px radius). Keeps the !important so the
   tt-paper-content scope keeps overriding any inherited template CSS. */
/* V101b: Box-Höhe 120 → 160px damit die Signatur mehr Platz hat. Plus
   overflow visible (war hidden → konnte injizierte sig-date-row clippen). */
.tt-paper-content .signature-line,
.tt-paper-content .signature-line.rv-signature-line {
  margin-top: auto !important;
  background-color: #fafbfc !important;
  border: 1px solid #d1d5db !important;
  border-radius: 8px !important;
  /* V101h: fixe Höhe 200px (statt 160) damit alle 3 Boxen uniform */
  height: 160px !important;
  min-height: 160px !important;
  max-height: 160px !important;
  width: 100% !important;
  max-width: none !important;
  position: relative !important;
  padding: 10px 12px !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  overflow: visible !important;
}

.tt-paper-content .signature-date {
  margin-top: 0.25rem !important;
  font-size: 0.85em !important;
  color: #666 !important;
}

.tt-paper-content .signature-label {
  font-size: 0.85em !important;
  color: #666 !important;
}

.tt-paper-content .rv-address-placeholder {
  font-style: italic !important;
  color: #888 !important;
}

.tt-paper-content .rv-signer-name {
  font-weight: 600 !important;
}

.tt-paper-content .rv-signer-role {
  font-size: 0.9em !important;
  color: #555 !important;
}

/* Force all direct children of .tt-paper-content to flow as block,
   preventing any multi-column or inline chaos */
.tt-paper-content > * {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
  columns: unset !important;
  column-count: auto !important;
}

/* Exception: signature containers need flex, not block */
.tt-paper-content > .signature-container,
.tt-paper-content > .signature-block .signature-container {
  display: flex !important;
  width: 100% !important;
}

/* =====================================================================
   FIX 2: Hide card-header when Template-Verwaltung is active
   The .card-header shows "Template-Verwaltung" title, but the
   template views have their OWN headers — causing duplication.
   JS toggles .tt-templates-active on the card-header.
   ===================================================================== */

.card-header.tt-templates-active {
  display: none !important;
}

/* =====================================================================
   FIX 3: Sidebar gap prevention
   Ensure sidebar and header stay flush at all times.
   Uses same selectors as V84e but reinforces key positioning rules.
   ===================================================================== */

@media (min-width: 1080px) {
  #dashboard-view header {
    left: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  #dashboard-view main > .admin-main-nav,
  #dashboard-view .admin-main-nav {
    left: 0 !important;
    border-radius: 0 !important;
    margin-left: 0 !important;
    margin-top: 0 !important;
  }
}
