/* Contract template library */
.template-library-page,
.template-preview-page {
    width: min(1320px, 100%);
    margin-inline: auto;
}

.template-library-hero {
    position: relative;
    display: flex;
    min-height: 250px;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
    margin-bottom: 22px;
    padding: clamp(30px, 5vw, 58px);
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 83% 18%, rgba(103, 232, 249, .3), transparent 28%),
        linear-gradient(132deg, #0b1e43 0%, #17477e 58%, #1188a5 100%);
    border-radius: 26px;
    box-shadow: 0 22px 50px rgba(10, 39, 80, .2);
}

.template-library-hero::after {
    position: absolute;
    right: -70px;
    bottom: -120px;
    width: 330px;
    height: 330px;
    content: "";
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 50%;
}

.template-library-hero__content {
    position: relative;
    z-index: 1;
    max-width: 760px;
}

.template-library-hero h1 {
    margin: 8px 0 14px;
    font-size: clamp(2rem, 4vw, 3.4rem);
    font-weight: 850;
    letter-spacing: -.035em;
}

.template-library-hero p {
    max-width: 680px;
    margin: 0;
    color: rgba(255, 255, 255, .82);
    font-size: clamp(1rem, 1.8vw, 1.14rem);
}

.template-library-hero .page-hero-eyebrow {
    color: #a5f3fc;
}

.template-library-hero__visual {
    position: relative;
    z-index: 1;
    display: grid;
    width: 132px;
    height: 156px;
    flex: 0 0 132px;
    color: #123668;
    place-items: center;
    background: linear-gradient(145deg, #fff, #dff8ff);
    border-radius: 18px 18px 30px 18px;
    box-shadow: 0 18px 34px rgba(3, 20, 48, .25);
    transform: rotate(4deg);
}

.template-library-hero__visual::before,
.template-library-hero__visual::after {
    position: absolute;
    left: 24px;
    width: 84px;
    height: 5px;
    content: "";
    background: #c5d9ec;
    border-radius: 999px;
}

.template-library-hero__visual::before {
    bottom: 40px;
}

.template-library-hero__visual::after {
    bottom: 25px;
}

.template-library-hero__visual span {
    margin-top: -22px;
    font-family: Georgia, serif;
    font-size: 58px;
    font-weight: 700;
}

.template-library-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--app-slate-200);
    border-radius: 18px;
    box-shadow: var(--app-shadow-sm);
}

.template-library-search {
    display: flex;
    width: min(760px, 100%);
    align-items: center;
    gap: 10px;
}

.template-library-search > span {
    color: var(--app-blue-600);
    font-size: 26px;
}

.template-library-search .form-control {
    min-width: 180px;
    border-color: transparent;
    background: var(--app-slate-100);
}

.template-library-add-section {
    flex: 0 0 auto;
    border-color: var(--app-slate-200);
    font-weight: 750;
}

.template-library-empty {
    display: grid;
    min-height: 360px;
    padding: 48px 24px;
    text-align: center;
    place-content: center;
    justify-items: center;
    background:
        radial-gradient(circle at center, rgba(219, 234, 254, .65), transparent 55%),
        #fff;
    border: 1px dashed #bdd0e7;
    border-radius: 24px;
}

.template-library-empty__icon {
    display: grid;
    width: 70px;
    height: 70px;
    margin-bottom: 18px;
    color: #fff;
    font-size: 30px;
    place-items: center;
    background: linear-gradient(135deg, var(--app-blue-600), var(--app-cyan-500));
    border-radius: 22px;
    box-shadow: 0 14px 28px rgba(37, 99, 235, .2);
}

.template-library-empty h2 {
    margin-bottom: 8px;
    color: var(--app-slate-900);
    font-weight: 800;
}

.template-library-empty p {
    max-width: 580px;
    color: var(--app-slate-500);
}

.template-section-list {
    display: grid;
    gap: 24px;
}

.template-section-card {
    overflow: hidden;
    background: #fff;
    border: 1px solid #dbe5f0;
    border-radius: 22px;
    box-shadow: 0 14px 34px rgba(15, 42, 75, .075);
}

.template-section-card__header {
    position: relative;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 24px 26px 20px 32px;
    background: linear-gradient(105deg, #f7faff, #eef8fb);
    border-bottom: 1px solid #dfebf4;
}

.template-section-card__header::before {
    position: absolute;
    top: 22px;
    bottom: 22px;
    left: 0;
    width: 6px;
    content: "";
    background: linear-gradient(var(--app-blue-600), var(--app-cyan-500));
    border-radius: 0 8px 8px 0;
}

.template-section-card__header h2 {
    margin: 2px 0 4px;
    color: var(--app-navy-900);
    font-size: clamp(1.25rem, 2vw, 1.6rem);
    font-weight: 850;
}

.template-section-card__label {
    color: var(--app-blue-600);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.template-section-card__count {
    color: var(--app-slate-500);
    font-size: 13px;
}

.template-section-card__actions,
.template-document-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
}

.template-section-card__actions form,
.template-document-actions form {
    margin: 0;
}

.template-section-card__empty {
    padding: 34px 26px;
    color: var(--app-slate-500);
    text-align: center;
}

.template-document-list {
    display: grid;
}

.template-document-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    border-bottom: 1px solid #edf1f6;
    transition: background-color 150ms ease;
}

.template-document-row:hover {
    background: #f9fbff;
}

.template-document-main {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 14px;
    padding: 17px 0;
    color: inherit;
    text-decoration: none;
}

.template-document-main:hover {
    color: inherit;
}

.template-document-icon {
    display: grid;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    color: #17518f;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .04em;
    place-items: center;
    background: linear-gradient(145deg, #e4f2ff, #d8f7fa);
    border: 1px solid #c9e4f1;
    border-radius: 14px;
}

.template-document-info {
    display: block;
    min-width: 0;
    flex: 1;
}

.template-document-info strong,
.template-document-info small {
    display: block;
    overflow-wrap: anywhere;
}

.template-document-info strong {
    color: var(--app-slate-900);
    font-size: 15px;
}

.template-document-info small {
    margin-top: 4px;
    color: var(--app-slate-500);
    font-size: 12px;
}

.template-document-open {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    color: var(--app-blue-600);
    font-size: 13px;
    font-weight: 750;
}

.template-upload-form {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    padding: 20px 24px;
    background: #f8fafc;
}

.template-upload-form label {
    margin-bottom: 3px;
    color: var(--app-slate-900);
    font-weight: 800;
}

.template-upload-form small {
    display: block;
    color: var(--app-slate-500);
    font-size: 11px;
}

.template-upload-form__controls {
    display: flex;
    width: min(620px, 100%);
    align-items: center;
    gap: 10px;
}

.template-upload-form__controls .form-control[type="file"] {
    min-width: 0;
    height: 42px;
    flex: 1 1 auto;
    padding: 0 .75rem 0 0;
    overflow: hidden;
    line-height: 40px;
}

.template-upload-form__controls .form-control[type="file"]::file-selector-button {
    height: 40px;
    margin: 0 .75rem 0 0;
    padding: 0 .9rem;
    color: var(--app-slate-900);
    background: var(--app-slate-100);
    border: 0;
    border-inline-end: 1px solid var(--app-slate-300);
    border-radius: 9px 0 0 9px;
    box-shadow: none;
}

.template-upload-form__controls .form-control[type="file"]:hover:not(:disabled)::file-selector-button {
    background: #e7eef7;
}

.template-preview-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
    padding: 28px 30px;
    color: #fff;
    background: linear-gradient(125deg, #10264f, #18567f);
    border-radius: 22px;
    box-shadow: 0 16px 36px rgba(15, 42, 75, .16);
}

.template-preview-header .request-back-link,
.template-preview-header .page-hero-eyebrow,
.template-preview-header p {
    color: rgba(255, 255, 255, .76);
}

.template-preview-header h1 {
    max-width: 920px;
    margin: 8px 0 5px;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    overflow-wrap: anywhere;
}

.template-preview-header p {
    margin: 0;
}

.template-preview-surface {
    min-height: 560px;
    padding: 18px;
    background: #e9eef5;
    border: 1px solid #d5dfeb;
    border-radius: 22px;
}

.template-preview-frame {
    width: 100%;
    height: min(78vh, 950px);
    min-height: 620px;
    background: #fff;
    border: 0;
    border-radius: 14px;
}

.template-preview-image {
    display: grid;
    min-height: 520px;
    place-items: center;
}

.template-preview-image img {
    max-width: 100%;
    max-height: 80vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--app-shadow-md);
}

.template-preview-text {
    width: min(920px, 100%);
    min-height: 520px;
    margin-inline: auto;
    padding: clamp(28px, 6vw, 72px);
    color: #172033;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 12px 34px rgba(15, 23, 42, .13);
}

.template-preview-text pre,
.template-preview-text--word > div {
    margin: 0;
    color: inherit;
    font: 16px/1.75 Georgia, "Times New Roman", serif;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.template-preview-note {
    width: min(920px, 100%);
    margin: 0 auto 12px;
    padding: 12px 16px;
    color: #365e75;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    border-radius: 12px;
}

.template-docx-viewer {
    overflow: hidden;
    background: #dce4ed;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
}

.template-docx-toolbar {
    display: flex;
    position: relative;
    z-index: 3;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 14px;
    color: #16253d;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid #d7e0ea;
    box-shadow: 0 4px 15px rgba(15, 23, 42, .08);
}

.template-docx-toolbar__title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.template-docx-toolbar__title > span {
    display: grid;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    color: #fff;
    place-items: center;
    background: linear-gradient(135deg, #2563eb, #0891b2);
    border-radius: 11px;
}

.template-docx-toolbar__title strong,
.template-docx-toolbar__title small {
    display: block;
}

.template-docx-toolbar__title strong {
    font-size: 14px;
}

.template-docx-toolbar__title small {
    margin-top: 1px;
    color: var(--app-slate-500);
    font-size: 11px;
}

.template-docx-toolbar__controls {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
}

.template-docx-control,
.template-docx-zoom-value,
.template-docx-fullscreen {
    min-height: 38px;
    color: #233451;
    font-weight: 750;
    background: #f8fafc;
    border: 1px solid #d5deea;
    border-radius: 10px;
    transition:
        color .16s ease,
        background .16s ease,
        border-color .16s ease,
        transform .16s ease;
}

.template-docx-control {
    width: 38px;
    padding: 0;
    font-size: 21px;
    line-height: 1;
}

.template-docx-zoom-value {
    min-width: 68px;
    padding: 0 10px;
    font-size: 12px;
}

.template-docx-fullscreen {
    display: grid;
    width: 38px;
    margin-left: 4px;
    padding: 0;
    place-items: center;
    font-family: "Segoe UI Symbol", "Arial Unicode MS", sans-serif;
    font-size: 20px;
    line-height: 1;
}

.template-docx-control:hover:not(:disabled),
.template-docx-zoom-value:hover,
.template-docx-fullscreen:hover:not(:disabled) {
    color: #164b9b;
    background: #eff6ff;
    border-color: #93c5fd;
    transform: translateY(-1px);
}

.template-docx-control:focus-visible,
.template-docx-zoom-value:focus-visible,
.template-docx-fullscreen:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .25);
    outline-offset: 2px;
}

.template-docx-control:disabled,
.template-docx-fullscreen:disabled {
    cursor: not-allowed;
    opacity: .42;
}

.template-docx-viewer > .template-preview-note {
    width: auto;
    margin: 12px 14px 0;
    font-size: 12px;
}

.template-docx-stage {
    position: relative;
    min-height: 560px;
    max-height: min(78vh, 980px);
    overflow: auto;
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, .52), transparent 38%),
        #c8d2de;
    scrollbar-color: #8393a8 #e8edf3;
    scrollbar-width: thin;
}

.template-docx-pages {
    --docx-preview-scale: 1;
    min-width: 100%;
}

.template-docx-pages .docx-wrapper {
    min-height: 540px;
    padding: 26px !important;
    background: transparent !important;
}

.template-docx-pages .docx-wrapper > section.docx {
    margin-bottom: 24px !important;
    border-radius: 2px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .2) !important;
    zoom: var(--docx-preview-scale);
}

.template-docx-pages .docx-wrapper > section.docx-auto-page {
    overflow: hidden !important;
}

.template-docx-loading {
    display: flex;
    position: absolute;
    z-index: 2;
    inset: 0;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: #284362;
    background: rgba(225, 232, 240, .92);
    backdrop-filter: blur(4px);
}

.template-docx-loading[hidden] {
    display: none;
}

.template-docx-loading > span {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(37, 99, 235, .2);
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: template-docx-spin .8s linear infinite;
}

.template-docx-error {
    margin: 12px 14px 0;
    padding: 13px 15px;
    color: #8a3a3a;
    background: #fff1f2;
    border: 1px solid #fecdd3;
    border-radius: 12px;
}

.template-docx-error strong,
.template-docx-error span {
    display: block;
}

.template-docx-error span {
    margin-top: 2px;
    font-size: 12px;
}

.template-docx-viewer > .template-preview-text--word {
    margin: 14px auto;
}

.template-docx-viewer:fullscreen {
    display: flex;
    height: 100%;
    flex-direction: column;
    background: #c8d2de;
    border: 0;
    border-radius: 0;
}

.template-docx-viewer:fullscreen > .template-preview-note {
    display: none;
}

.template-docx-viewer:fullscreen .template-docx-stage {
    flex: 1;
    min-height: 0;
    max-height: none;
}

@keyframes template-docx-spin {
    to {
        transform: rotate(360deg);
    }
}

.template-preview-unavailable {
    display: grid;
    min-height: 520px;
    text-align: center;
    place-content: center;
    justify-items: center;
}

.template-preview-unavailable > span {
    display: grid;
    width: 72px;
    height: 72px;
    margin-bottom: 16px;
    color: #fff;
    font-size: 30px;
    place-items: center;
    background: linear-gradient(135deg, #3156b7, #0ea5b7);
    border-radius: 22px;
}

.template-preview-unavailable p {
    max-width: 560px;
    color: var(--app-slate-500);
}

.request-admin-danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin: 0 0 16px;
    padding: 18px 20px;
    background: linear-gradient(105deg, #fff, #fff7f7);
    border: 1px solid #fecaca;
    border-radius: 16px;
}

.request-admin-danger-zone strong,
.request-admin-danger-zone p {
    display: block;
}

.request-admin-danger-zone p {
    margin: 3px 0 0;
    color: #7f4b4b;
    font-size: 13px;
}

.request-admin-danger-zone__eyebrow {
    display: block;
    margin-bottom: 2px;
    color: #dc2626;
    font-size: 10px;
    font-weight: 850;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.error-visual--access {
    background: linear-gradient(145deg, #fff1f2, #ffe4e6);
}

.error-visual--access span {
    color: #e11d48;
}

@media (max-width: 991.98px) {
    .template-library-toolbar,
    .template-upload-form,
    .template-preview-header {
        align-items: stretch;
        flex-direction: column;
    }

    .template-library-add-section,
    .template-preview-header > .btn {
        width: 100%;
    }

    .template-upload-form__controls {
        width: 100%;
    }

    .template-document-open {
        display: none;
    }
}

@media (max-width: 767.98px) {
    .template-library-hero {
        min-height: 220px;
    }

    .template-library-hero__visual {
        display: none;
    }

    .template-library-search,
    .template-upload-form__controls {
        align-items: stretch;
        flex-direction: column;
    }

    .template-library-search > span {
        display: none;
    }

    .template-section-card__header,
    .template-document-row,
    .request-admin-danger-zone {
        align-items: stretch;
        flex-direction: column;
    }

    .template-section-card__actions,
    .template-document-actions {
        width: 100%;
    }

    .template-section-card__actions > *,
    .template-section-card__actions .btn {
        flex: 1;
    }

    .template-document-actions {
        padding-bottom: 15px;
    }

    .template-document-actions .btn {
        flex: 1;
    }

    .template-preview-surface {
        min-height: 460px;
        padding: 8px;
    }

    .template-preview-frame {
        min-height: 520px;
    }

    .template-docx-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .template-docx-toolbar__controls {
        width: 100%;
    }

    .template-docx-fullscreen {
        flex: 0 0 38px;
    }

    .template-docx-stage {
        min-height: 500px;
    }

    .template-docx-pages .docx-wrapper {
        padding: 14px !important;
    }

    .request-admin-danger-zone .btn {
        width: 100%;
    }
}
