/* NOTE: Contract Editor — A4 page styling
   Prefix: mw-ce-* (contract editor)
   Applied via ContainerClass when Mode == Contract */

.mw-ce-root {
    background: var(--mud-palette-background-grey);
    border: none;
    border-radius: 0;
    overflow: visible;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
}

.mw-ce-root .mw-text-editor-toolbar {
    width: 794px;
    border-radius: 4px 4px 0 0;
    border-bottom: none;
}

.mw-ce-root .mw-text-editor-content {
    width: 794px;
    min-height: 1123px;
    padding: 76px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-family: Arial, sans-serif;
    font-size: 11pt;
    color: #000;
}

.mw-ce-root .tiptap {
    min-height: auto;
}

/* NOTE: Page break marker */
.page-break-marker {
    border: none;
    border-top: 2px dashed var(--mud-palette-lines-default);
    text-align: center;
    color: var(--mud-palette-text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 8px 0;
    margin: 16px 0;
    user-select: none;
    cursor: default;
}

/* NOTE: Fillable field chip (author mode) */
.fillable-field-chip {
    display: inline-block;
    background-color: var(--mud-palette-warning-lighten);
    color: var(--mud-palette-warning-darken);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.85em;
    font-weight: 500;
    user-select: none;
    cursor: default;
    border: 1px solid var(--mud-palette-warning);
}

.fillable-field-required::after {
    content: ' *';
    color: var(--mud-palette-error);
}

/* NOTE: Fill mode — interactive input styling */
.mw-ce-fillable-input {
    border: none;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    background: transparent;
    font: inherit;
    color: inherit;
    min-width: 180px;
    padding: 2px 4px;
    outline: none;
}

.mw-ce-fillable-input:focus {
    border-bottom-color: var(--mud-palette-primary);
}

.mw-ce-fillable-input[data-required="true"] {
    border-bottom-color: var(--mud-palette-warning);
}

.mw-ce-fillable-input[data-required="true"]:focus {
    border-bottom-color: var(--mud-palette-primary);
}

/* NOTE: Signature field — block-level signing area */
.mw-ce-signature-area {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    min-width: 200px;
    max-width: 300px;
}

.mw-ce-signature-box {
    border: 1.5px dashed var(--mud-palette-primary);
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    padding: 12px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s;
}

.mw-ce-signature-box:hover {
    background: var(--mud-palette-primary-lighten);
}

.mw-ce-signature-label {
    color: var(--mud-palette-primary);
    font: inherit;
    font-weight: 500;
    user-select: none;
}

.mw-ce-signature-preview {
    max-height: 70px;
    max-width: 100%;
    object-fit: contain;
}

.mw-ce-signature-line {
    border-top: 1px solid #000;
    margin-top: 4px;
}

.mw-ce-signature-role {
    font-size: 0.8em;
    color: var(--mud-palette-text-secondary);
    margin-top: 2px;
}

/* NOTE: Fill mode — error highlight for invalid fields */
.mw-ce-fillable-input--error {
    border-bottom-color: var(--mud-palette-error) !important;
    background-color: rgba(244, 67, 54, 0.05);
}

/* NOTE: Fill mode — hide toolbar (safety net) */
.mw-ce-fill .mw-text-editor-toolbar {
    display: none;
}

/* NOTE: Line height — matches QuestPDF 11pt Arial inter-line spacing */
.mw-ce-root .mw-text-editor-content {
    line-height: 1.4;
}

/* NOTE: Table styling — base */
.mw-ce-root table {
    border-collapse: collapse;
    width: 100%;
    border: none;
}

/* NOTE: Fill mode — fixed table layout to match QuestPDF RelativeColumn() */
.mw-ce-fill table {
    table-layout: fixed;
}

/* NOTE: Table cells — author mode (subtle grid for editing visibility) */
.mw-ce-root th,
.mw-ce-root td {
    border: 1px dashed #E0E0E0;
    padding: 4px;
    vertical-align: top;
}

/* NOTE: Table cells — fill mode (matches PDF: bottom border only) */
.mw-ce-fill th,
.mw-ce-fill td {
    border: none;
    border-bottom: 0.5px solid #E0E0E0;
    padding: 4px;
    vertical-align: top;
}

/* NOTE: Column spacing — breathing room between adjacent cells */
.mw-ce-root td + td,
.mw-ce-root th + th {
    padding-left: 12px;
}

/* NOTE: Fill mode — tighter cell spacing to match QuestPDF PaddingHorizontal(4) */
.mw-ce-fill td + td,
.mw-ce-fill th + th {
    padding-left: 5px;
}

/* NOTE: Paragraph spacing — matches QuestPDF inter-block spacing */
.mw-ce-root .tiptap p {
    margin: 0 0 4px 0;
}

/* NOTE: Heading spacing */
.mw-ce-root .tiptap h1,
.mw-ce-root .tiptap h2,
.mw-ce-root .tiptap h3 {
    margin: 8px 0 4px 0;
}

/* NOTE: Hide table resize grips */
.mw-ce-root .column-resize-handle {
    opacity: 0.3;
    width: 2px;
}

.mw-ce-fill .column-resize-handle {
    display: none;
}

.mw-ce-fill .tableWrapper {
    overflow: visible;
}

/* NOTE: Paginated mode — when tiptap-pagination-plus is active,
   it handles page sizing and margins. Remove our own padding to avoid double spacing. */
.mw-ce-root .mw-text-editor-content:has(.rm-with-pagination) {
    padding: 0;
    box-shadow: none;
    background: transparent;
    min-height: auto;
}

.mw-ce-root .rm-with-pagination {
    font-family: Arial, sans-serif;
    font-size: 11pt;
    color: #000;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* NOTE: Mobile — responsive scaling for fill mode */
@media (max-width: 850px) {
    .mw-ce-fill .mw-text-editor-content {
        transform: scale(var(--mw-ce-scale, 1));
        transform-origin: top center;
        margin-bottom: calc((1 - var(--mw-ce-scale, 1)) * -1123px);
    }
    .mw-ce-fill {
        padding: 8px 0;
        overflow-x: hidden;
    }
    .mw-ce-fillable-input {
        min-height: 36px;
        font-size: 16px; /* prevents iOS zoom */
    }
    .mw-ce-signature-box {
        min-height: 80px;
        padding: 12px;
    }
}
