/* Workflow letter / approval — A4 print layout */

@import url('https://fonts.googleapis.com/css2?family=Amiri+Quran&family=Tajawal:wght@400;500;700&display=swap');

:root {
    --letter-green: #0a4d42;
    --letter-gold: #b8922a;
    --letter-text: #1f2933;
    --letter-muted: #5c6670;
    --letter-font: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
    --letter-quran: 'Amiri Quran', 'Amiri', 'Scheherazade New', serif;
    --letter-seal-size: 62mm;
    --letter-seal-opacity: 0.34;
    --letter-seal-overlay-ratio: 28%;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: #eef1f3;
    color: var(--letter-text);
    font-family: var(--letter-font);
    font-size: 14px;
    line-height: 1.75;
}

body.letter-print-body {
    padding: 1rem;
}

.letter-print-toolbar {
    text-align: center;
    margin-bottom: 1rem;
}

.letter-print-toolbar button {
    background: var(--letter-green);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: .55rem 1.25rem;
    font-family: var(--letter-font);
    font-size: 14px;
    cursor: pointer;
}

.letter-print-toolbar button:hover {
    filter: brightness(1.05);
}

.letter-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 12mm 14mm 16mm;
    background: #fff;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .08);
    position: relative;
}

.letter-head {
    border-bottom: 2px double var(--letter-green);
    padding-bottom: 4mm;
    margin-bottom: 6mm;
}

.letter-head-triple {
    display: grid;
    grid-template-columns: 30mm minmax(0, 1fr) 30mm;
    align-items: center;
    column-gap: 4mm;
    direction: rtl;
    min-height: 28mm;
}

.letter-head-col--logo {
    display: flex;
    align-items: center;
    justify-content: center;
}

.letter-head-col--logo img {
    max-height: 28mm;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.letter-head-col--uni {
    justify-content: flex-start;
}

.letter-head-col--org {
    justify-content: flex-end;
}

.letter-head-col--center {
    text-align: center;
    padding: 0 1mm;
}

.letter-head-center-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    line-height: 1.2;
}

.letter-head-bismillah {
    font-family: var(--letter-quran);
    font-size: 12px;
    color: var(--letter-green);
    margin: 0 0 1mm;
    letter-spacing: .02em;
}

.letter-head-republic {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--letter-text);
    margin: 0;
}

.letter-head-university {
    font-size: 13px;
    font-weight: 700;
    color: var(--letter-green);
    margin: 0.8mm 0 0;
}

.letter-head-org-name {
    font-size: 13px;
    font-weight: 800;
    color: #111;
    margin: 0.8mm 0 0;
}

.letter-head-org-fallback {
    font-size: 10px;
    font-weight: 700;
    color: var(--letter-green);
    text-align: center;
    line-height: 1.25;
}

.letter-head-personal {
    text-align: center;
}

.letter-head-personal .letter-head-center-text {
    margin-bottom: 3mm;
}

.letter-head-personal .letter-logo--single img {
    max-height: 30mm;
}

.letter-head-logos {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8mm;
    min-height: 22mm;
}

.letter-head-logos--center {
    justify-content: center;
}

.letter-logo {
    flex: 0 0 auto;
    max-width: 34mm;
    text-align: center;
}

.letter-logo img {
    max-height: 22mm;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.letter-logo--single img {
    max-height: 26mm;
}

.letter-head-center {
    text-align: center;
}

.letter-head-leadership {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 6mm;
    margin-top: 2mm;
}

.letter-uni-block {
    font-size: 11px;
    line-height: 1.55;
}

.letter-uni-block--ar {
    text-align: right;
}

.letter-uni-block--en {
    text-align: left;
    direction: ltr;
    font-family: 'Segoe UI', Arial, sans-serif;
}

.letter-uni-block strong {
    display: block;
    font-size: 13px;
    color: var(--letter-green);
    margin-bottom: 1mm;
}

.letter-unit-name {
    margin-top: 4mm;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: #111;
}

.letter-org-caption {
    margin-top: 3mm;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--letter-green);
}

.letter-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 3mm;
    margin-bottom: 6mm;
    font-size: 12px;
}

.letter-meta-item strong {
    color: var(--letter-green);
}

.letter-subject {
    font-size: 16px;
    font-weight: 700;
    color: var(--letter-green);
    margin: 0 0 5mm;
    text-align: center;
}

.letter-body {
    min-height: 90mm;
    font-size: 14px;
    text-align: justify;
    white-space: pre-wrap;
    margin-bottom: 8mm;
}

.letter-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--letter-green);
    border-bottom: 1px solid rgba(10, 77, 66, .18);
    padding-bottom: 2mm;
    margin: 0 0 4mm;
}

.letter-approvals {
    margin-top: 14mm;
    margin-bottom: 8mm;
    clear: both;
}

.letter-approvals-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 5mm;
}

.letter-approval {
    flex: 1 1 calc(33.333% - 4mm);
    min-width: 56mm;
    min-height: 42mm;
    border: 1px solid rgba(10, 77, 66, .12);
    border-radius: 4px;
    padding: 3mm;
    text-align: center;
    page-break-inside: avoid;
}

.letter-owner-block {
    position: relative;
    overflow: visible;
}

.letter-owner-info {
    position: relative;
    z-index: 1;
    padding-bottom: clamp(26mm, var(--letter-seal-overlay-ratio), var(--letter-seal-size));
}

.letter-sign-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: clamp(26mm, var(--letter-seal-overlay-ratio), var(--letter-seal-size));
    z-index: 2;
    pointer-events: none;
    overflow: visible;
}

.letter-seal {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: auto;
    height: 100%;
    max-width: var(--letter-seal-size);
    max-height: var(--letter-seal-size);
    object-fit: contain;
    opacity: var(--letter-seal-opacity);
    filter: grayscale(12%);
}

.letter-signature {
    position: absolute;
    left: 50%;
    bottom: calc(100% - 2mm);
    transform: translateX(-50%);
    z-index: 3;
    max-height: 14mm;
    max-width: 72%;
    width: auto;
    object-fit: contain;
    opacity: 1;
}

.letter-approval-name {
    font-size: 11px;
    font-weight: 700;
    color: #111;
    margin-bottom: 1mm;
}

.letter-approval-title {
    font-size: 10px;
    color: var(--letter-muted);
    margin-bottom: 2mm;
    min-height: 2.4em;
}

.letter-approval-action {
    font-size: 10px;
    font-weight: 700;
    color: var(--letter-green);
    margin-bottom: 1mm;
}

.letter-approval-comment {
    font-size: 10px;
    color: var(--letter-text);
    margin-bottom: 2mm;
    min-height: 2em;
    text-align: justify;
}

.letter-approval-date {
    font-size: 9px;
    color: var(--letter-muted);
    margin-bottom: 0;
}

.letter-requester-row {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10mm;
    margin-top: 10mm;
    direction: ltr;
    page-break-inside: avoid;
}

.letter-requester {
    margin-top: 0;
    flex: 0 0 auto;
    direction: ltr;
    text-align: left;
    page-break-inside: avoid;
}

.letter-attachments {
    flex: 1 1 auto;
    max-width: 48%;
    direction: rtl;
    text-align: right;
    align-self: flex-start;
}

.letter-attachments-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--letter-green);
    margin: 0 0 3mm;
    padding-bottom: 1.5mm;
    border-bottom: 1px solid rgba(10, 77, 66, .15);
}

.letter-attachments-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.letter-attachments-list li + li {
    margin-top: 2mm;
}

.letter-attachment-link {
    display: inline-block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    font-size: 12px;
    color: var(--letter-green);
    text-align: right;
    text-decoration: underline;
    cursor: pointer;
    line-height: 1.5;
    word-break: break-word;
}

.letter-attachment-link:hover {
    color: #063830;
}

.letter-requester-block {
    display: inline-block;
    direction: rtl;
    text-align: right;
    min-width: 58mm;
    max-width: 88mm;
}

.letter-requester-name {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 1mm;
}

.letter-requester-duty {
    font-size: 12px;
    color: var(--letter-muted);
}

.letter-verify {
    margin-top: 8mm;
    padding-top: 4mm;
    border-top: 1px solid rgba(10, 77, 66, .12);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4mm;
    font-size: 10px;
    color: var(--letter-muted);
    page-break-inside: avoid;
}

.letter-verify img {
    width: 22mm;
    height: 22mm;
}

.letter-verify-url {
    direction: ltr;
    word-break: break-all;
    max-width: 110mm;
}

body.letter-modal-open {
    overflow: hidden;
}

.letter-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.letter-modal[hidden] {
    display: none !important;
}

.letter-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .62);
}

.letter-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(920px, 96vw);
    max-height: 92vh;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.letter-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1rem;
    border-bottom: 1px solid rgba(10, 77, 66, .12);
    background: #f8faf9;
}

.letter-modal-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--letter-green);
    word-break: break-word;
}

.letter-modal-close {
    border: 0;
    background: none;
    font-size: 1.6rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0 .25rem;
}

.letter-modal-body {
    flex: 1 1 auto;
    min-height: 320px;
    max-height: calc(92vh - 120px);
    overflow: auto;
    background: #f1f5f4;
    padding: .75rem;
}

.letter-modal-image {
    display: block;
    max-width: 100%;
    max-height: calc(92vh - 140px);
    margin: 0 auto;
    object-fit: contain;
    background: #fff;
    border-radius: 6px;
}

.letter-modal-frame {
    width: 100%;
    height: calc(92vh - 150px);
    min-height: 320px;
    border: 0;
    background: #fff;
    border-radius: 6px;
}

.letter-modal-note {
    margin: .75rem 0 0;
    font-size: 12px;
    color: var(--letter-muted);
    text-align: center;
}

.letter-modal-footer {
    padding: .65rem 1rem;
    border-top: 1px solid rgba(10, 77, 66, .12);
    text-align: center;
}

.letter-modal-open-link {
    font-size: 13px;
    color: var(--letter-green);
    text-decoration: none;
    font-weight: 600;
}

.letter-modal-open-link:hover {
    text-decoration: underline;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 10mm 12mm;
    }

    html,
    body {
        background: #fff;
    }

    body.letter-print-body {
        padding: 0;
    }

    .letter-print-toolbar {
        display: none !important;
    }

    .letter-page {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .letter-modal {
        display: none !important;
    }

    .letter-attachment-link {
        text-decoration: none;
        color: var(--letter-text);
        cursor: default;
        pointer-events: none;
    }

    .letter-attachments-list li::before {
        content: '• ';
        color: var(--letter-green);
    }

    .letter-seal {
        opacity: var(--letter-seal-opacity);
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
}

@media (max-width: 820px) {
    .letter-page {
        width: 100%;
        min-height: auto;
        padding: 1rem;
    }

    .letter-head-triple {
        grid-template-columns: 1fr;
        row-gap: 3mm;
        direction: rtl;
    }

    .letter-head-col--uni,
    .letter-head-col--org {
        justify-content: center;
    }

    .letter-head-leadership {
        flex-direction: column;
    }

    .letter-head-logos {
        flex-direction: column;
    }

    .letter-approval {
        flex: 1 1 100%;
    }

    .letter-requester-row {
        flex-direction: column;
        gap: 6mm;
    }

    .letter-attachments {
        max-width: 100%;
    }

    .letter-requester-block {
        max-width: 100%;
    }
}
