/* =========================================================
   Conex Mailer — Templates Page
   Clean consolidated stylesheet (one page / one CSS file)
   ========================================================= */

#templatesPage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 440px;
    gap: 24px;
    align-items: start;
    width: 100%;
    min-width: 0;
}

#templatesPage,
#templatesPage * {
    box-sizing: border-box;
}

#templatesPage > .template-card {
    width: 100%;
    min-width: 0;
    padding: 28px;
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

#templatesPage > .template-card:last-child {
    padding: 28px 20px 24px;
}

.template-header,
.saved-templates-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
}

.template-title,
.saved-templates-header h2 {
    margin: 0;
    color: #111827;
    font-weight: 800;
    line-height: 1.2;
}

.template-title {
    color: #2563eb;
    font-size: 24px;
}

.saved-templates-header h2 {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 22px;
    white-space: nowrap;
}

.new-template-btn,
.save-template-btn,
.test-template-btn,
.edit-btn,
.delete-btn {
    border: 0;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
}

.new-template-btn {
    flex: 0 0 auto;
    min-height: 48px;
    padding: 12px 20px;
    border-radius: 14px;
    background: #2563eb;
    color: #fff;
    font-size: 15px;
}

#templateName,
#templateSubject,
#templateReplyTo {
    display: block;
    width: 100%;
    min-height: 56px;
    margin: 0 0 18px;
    padding: 15px 16px;
    border: 1px solid #dbe1ea;
    border-radius: 14px;
    outline: 0;
    background: #fff;
    color: #0f172a;
    font: inherit;
    font-size: 15px;
}

#templateName:focus,
#templateSubject:focus,
#templateReplyTo:focus,
#testEmailAddress:focus,
#templateSearch:focus {
    border-color: #7aa2ff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
}

/* ---------- Editor ---------- */

#editorContainer {
    overflow: visible;
    border: 0;
    border-radius: 16px;
    background: #fff;
}

#toolbar.ql-toolbar.ql-snow {
    display: block;
    padding: 0;
    overflow: visible;
    border: 1px solid #d8e1ee;
    border-radius: 16px 16px 0 0;
    background: #f8fafc;
}

#toolbar .template-toolbar-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    width: 100%;
    min-height: 52px;
    padding: 10px 12px 8px;
}

#toolbar .ql-formats {
    float: none;
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-width: 0;
    margin: 0;
    padding-right: 5px;
    border-right: 1px solid #dbe4ef;
}

#toolbar .ql-formats:last-child {
    padding-right: 0;
    border-right: 0;
}

#toolbar button,
#toolbar .ql-picker-label {
    width: 28px;
    height: 28px;
}

#toolbar .ql-picker.ql-font {
    width: 122px;
}

#toolbar .ql-picker.ql-size {
    width: 64px;
}

#toolbar .ql-picker.ql-color,
#toolbar .ql-picker.ql-background,
#toolbar .ql-picker.ql-align {
    width: 30px;
}

#toolbar .template-spacing-select {
    width: 96px;
    min-width: 96px;
    height: 31px;
    padding: 0 9px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    outline: 0;
    background: #fff;
    color: #334155;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
}

#toolbar .template-personalize-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    width: 100%;
    min-height: 47px;
    margin: 0;
    padding: 8px 12px 10px;
    border-top: 1px solid #dbe4ef;
    background: #f8fafc;
}

#toolbar .template-personalize-row strong {
    margin-right: 2px;
    color: #334155;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

#toolbar .template-personalize-row button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 0;
    height: 32px;
    padding: 0 12px;
    border: 1px solid #bdd0ff;
    border-radius: 9px;
    background: #eef4ff;
    color: #2458d3;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
}

#toolbar .template-personalize-row button:hover {
    border-color: #2563eb;
    background: #2563eb;
    color: #fff;
}

#templateEditor.ql-container.ql-snow {
    height: auto;
    min-height: 520px;
    border: 1px solid #d8e1ee;
    border-top: 0;
    border-radius: 0 0 16px 16px;
    background: #fff;
    font-family: Arial, sans-serif;
    font-size: 14px;
}

#templateEditor .ql-editor {
    min-height: 520px;
    padding: 24px 26px;
    line-height: 1.35;
}

#templateEditor .ql-editor.ql-blank::before {
    left: 26px;
    right: 26px;
    color: #64748b;
}

#templateEditor .ql-editor img {
    max-width: 100%;
    height: auto;
}

/* Do not allow global styles to hide or deform the image resize overlay. */
#templatesPage .image-resize-toolbar,
#templatesPage .template-image-resize-toolbar,
#templatesPage .ql-image-resize-toolbar {
    z-index: 50;
    white-space: nowrap;
}

.template-editor-note,
.template-image-note {
    display: block;
    width: auto;
    margin: 8px 4px 0;
    padding: 10px 13px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.5;
}

.template-editor-note {
    background: #eff6ff;
    color: #334155;
}

.template-editor-note strong {
    color: #1d4ed8;
}

.template-image-note {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #334155;
}

.template-image-note strong {
    color: #15803d;
}

/* ---------- Bottom actions ---------- */

.template-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-top: 20px;
}

.save-template-btn {
    flex: 0 0 auto;
    min-height: 52px;
    margin: 0;
    padding: 14px 22px;
    border-radius: 14px;
    background: #0f172a;
    color: #fff;
    font-size: 15px;
}

.test-email-box {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
}

#testEmailAddress {
    flex: 0 1 230px;
    min-width: 170px;
    height: 52px;
    padding: 14px 16px;
    border: 1px solid #dbe1ea;
    border-radius: 14px;
    outline: 0;
    background: #fff;
    color: #0f172a;
    font: inherit;
    font-size: 15px;
}

.test-template-btn {
    flex: 0 0 auto;
    min-height: 52px;
    padding: 14px 20px;
    border-radius: 14px;
    background: #22c55e;
    color: #fff;
    font-size: 15px;
}

/* ---------- Saved templates ---------- */

.saved-templates-header input,
#templateSearch {
    flex: 0 0 142px;
    width: 142px;
    height: 40px;
    padding: 9px 11px;
    border: 1px solid #dbe1ea;
    border-radius: 10px;
    outline: 0;
    background: #fff;
    font: inherit;
    font-size: 13px;
}

#templatesList {
    width: 100%;
    height: 650px;
    min-height: 650px;
    max-height: 650px;
    padding-right: 5px;
    overflow-x: hidden;
    overflow-y: auto;
}

.template-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 104px;
    margin: 0 0 14px;
    padding: 15px 14px;
    border: 1px solid #e7edf5;
    border-radius: 18px;
    background: #fff;
}

.template-left {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.template-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: #eef2ff;
    font-size: 20px;
}

.template-info {
    min-width: 0;
}

.template-info h3 {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: #111827;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.18;
    overflow-wrap: break-word;
    word-break: normal;
    hyphens: none;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.template-date {
    margin-top: 5px;
    color: #6b7280;
    font-size: 12px;
    line-height: 1.25;
    overflow-wrap: normal;
    word-break: normal;
}

.template-creator-label {
    display: block;
    margin-top: 3px;
    color: #a16207;
}

.template-buttons {
    display: flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
}

.edit-btn,
.delete-btn {
    min-height: 42px;
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 13px;
    white-space: nowrap;
}

.edit-btn {
    background: #0f172a;
    color: #fff;
}

.delete-btn {
    background: #ef4444;
    color: #fff;
}

/* ---------- Responsive ---------- */

@media (max-width: 1380px) {
    #templatesPage {
        grid-template-columns: minmax(0, 1fr) 410px;
    }

    #toolbar .ql-picker.ql-font {
        width: 112px;
    }

    #toolbar .template-spacing-select {
        width: 88px;
        min-width: 88px;
    }
}

@media (max-width: 1120px) {
    #templatesPage {
        grid-template-columns: 1fr;
    }

    #templatesList {
        height: 520px;
        min-height: 520px;
        max-height: 520px;
    }
}

@media (max-width: 720px) {
    #templatesPage > .template-card,
    #templatesPage > .template-card:last-child {
        padding: 20px 16px;
    }

    .template-header,
    .saved-templates-header,
    .template-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .saved-templates-header input,
    #templateSearch,
    #testEmailAddress {
        width: 100%;
        min-width: 0;
        flex-basis: auto;
    }

    .test-email-box {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .template-item {
        grid-template-columns: 1fr;
    }

    .template-buttons {
        justify-content: flex-end;
        padding-left: 60px;
    }
}
