/**
 * WizQuoteResubmit v2 — two right-side drawers (buyer → rep)
 *   A: "Resubmit quote to your rep"  (To, Subject, message preview card)
 *   B: "Edit Email Message"          (full-width TinyMCE editor, no API)
 *
 * NOTE: both drawers are portaled to <body> at runtime, so drawer rules are
 * scoped to the drawer's own custom classes (NOT the .wiz-quote-resubmit
 * ancestor) and CSS variables are declared on the drawers themselves.
 */

/* Design tokens — declared on every surface that survives portaling */
.wiz-quote-resubmit,
.wiz-quote-resubmit-drawer,
.wiz-quote-resubmit-editor-drawer {
    --wqr-primary: #000000;
    --wqr-border: #e5e5e5;
    --wqr-text: #000000;
    --wqr-muted: #6b7280;
    --wqr-field-bg: #fff;
}

/* ── Overlays / stacking (matched by id prefix, survives portaling) ── */
[id^="wiz-quote-resubmit-drawer-"].drawer-overlay {
    z-index: 1000000 !important;
}

[id^="wiz-quote-resubmit-editor-drawer-"].drawer-overlay {
    z-index: 1000002 !important;
}

.wiz-quote-resubmit-drawer.drawer {
    z-index: 1000001 !important;
}

.wiz-quote-resubmit-editor-drawer.drawer {
    z-index: 1000003 !important;
}

/* ── Shared drawer shell ── */
.wiz-quote-resubmit-drawer.drawer,
.wiz-quote-resubmit-editor-drawer.drawer {
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    font-family: var(--wiz-body-font, Brother1816, sans-serif);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
}

.wiz-quote-resubmit-drawer.drawer.open,
.wiz-quote-resubmit-editor-drawer.drawer.open {
    display: flex !important;
    flex-direction: column !important;
}

.wiz-quote-resubmit-drawer .drawer-content,
.wiz-quote-resubmit-editor-drawer .drawer-content,
.wqr__shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.wiz-quote-resubmit--body-locked {
    overflow: hidden;
}

/* Quote-flow only: hide trigger outside quote mode */
body:not(.wiz-quote-mode) .wiz-quote-resubmit-trigger-wrap {
    display: none !important;
}

/* ── Header ── */
.wqr__header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--wqr-border);
    flex: 0 0 auto;
}

.wqr__header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.wqr__header-row .wqr__title {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    padding-right: 8px;
}

.wqr__title {
    font-size: 22px;
    font-weight: 500;
    line-height: 1.25;
    color: var(--wqr-text);
    font-family: var(--wiz-heading-font, Georgia, 'Times New Roman', serif);
}

.wqr__subtitle {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--wqr-muted);
}

.wqr__editor-hint {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 8px 0 0;
    font-size: 14px;
    line-height: 1.5;
    color: rgba(0, 0, 0, 0.55);
}

.wqr__editor-hint-icon {
    flex: 0 0 auto;
    margin-top: 2px;
    color: rgba(0, 0, 0, 0.55);
}

.wqr__scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px;
}

.wqr__close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-top: 1px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--wqr-text);
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.wqr__close:hover {
    background: #f3f4f6;
}

.wqr__close svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* ── Fields ── */
.wqr__body {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.wqr__field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.wqr__field--inline {
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
}

.wqr__field--inline > .wqr__label {
    flex: 0 0 48px;
    margin: 0;
    padding-top: 11px;
}

.wqr__label {
    font-size: 13px;
    font-weight: 600;
    color: #000000;
    letter-spacing: 0.02em;
}

.wqr__input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--wqr-border);
    background: var(--wqr-field-bg);
    padding: 11px 13px;
    font-size: 14px;
    line-height: 1.45;
    color: var(--wqr-text);
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.wqr__input:focus {
    outline: none;
    border-color: var(--wqr-primary);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.wqr__input--error {
    border-color: #dc2626;
}

.wqr__input--error:focus {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* ── CC emails ── */
.wqr__cc-row {
    display: flex;
    align-items: stretch;
    gap: 10px;
}

.wqr__cc-row .wqr__cc-input {
    flex: 1 1 auto;
    min-width: 0;
}

.wqr__cc-add {
    flex: 0 0 auto;
    align-self: stretch;
    min-height: 42px;
    padding: 0 14px;
    border: none;
    background: transparent;
    color: var(--wqr-primary);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}

.wqr__cc-add:disabled {
    color: rgba(0, 0, 0, 0.35);
    cursor: not-allowed;
}

.wqr__cc-error {
    margin: 6px 0 0;
    font-size: 12px;
    line-height: 1.4;
    color: #dc2626;
}

.wqr__cc-error[hidden] {
    display: none;
}

.wqr__cc-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.wqr__cc-chips:empty {
    display: none;
}

.wqr__cc-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 6px 10px 6px 12px;
    border: 1px solid var(--wqr-border);
    border-radius: 20px;
    background: #f9fafb;
    font-size: 13px;
    line-height: 1.3;
    color: var(--wqr-text);
}

.wqr__cc-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wqr__cc-chip-remove {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    background: transparent;
    color: rgba(0, 0, 0, 0.55);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.wqr__cc-chip-remove:hover {
    color: #000;
}

/* ── Message preview card (Drawer A) → opens Drawer B ── */
.wqr__preview-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    text-align: left;
    box-sizing: border-box;
    border: 1px solid var(--wqr-border);
    background: #f9fafb;
    padding: 14px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    text-transform: none;
    letter-spacing: normal;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.wqr__preview-card:hover {
    border-color: #cfcfcf;
    background: #f3f4f6;
}

.wqr__preview-card:focus-visible {
    outline: none;
    border-color: var(--wqr-primary);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

.wqr__preview-icon {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--wqr-border);
    color: var(--wqr-muted);
}

.wqr__preview-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1 1 auto;
}

.wqr__preview-title,
.wqr__preview-sub,
.wqr__preview-edit,
.wqr__preview-edit span {
    font-size: 14px;
    line-height: 1.45;
    text-transform: none;
    letter-spacing: normal;
}

.wqr__preview-title {
    font-weight: 600;
    color: var(--wqr-text);
}

.wqr__preview-sub {
    font-weight: 400;
    color: var(--wqr-muted);
}

.wqr__preview-edit {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--wqr-primary);
    font-weight: 600;
    white-space: nowrap;
}

/* ── Editor drawer (Drawer B) ── */
.wqr__scroll--editor {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
}

.wqr__shell--editor .wqr__field--body,
.wqr__shell--editor .wqr__editor-mount {
    flex: 1 1 auto;
    min-height: 0;
}

/* Fallback textarea (before TinyMCE mounts) */
.wqr__body-editor.wqr__body-fallback {
    width: 100%;
    min-height: 360px;
    border: 1px solid var(--wqr-border);
    background: #fff;
    padding: 11px 13px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    resize: vertical;
    box-sizing: border-box;
}

/* Email body — wp_editor (TinyMCE) inside Drawer B */
.wqr__field--body .wp-editor-wrap,
.wqr__field--body .wp-editor-container,
.wqr__field--body .mce-tinymce,
.wqr__field--body .mce-container-body {
    width: 100% !important;
    max-width: 100%;
    box-sizing: border-box;
}

.wqr__field--body .wp-editor-wrap {
    border: 1px solid var(--wqr-border);
    overflow: visible;
    position: relative;
}

.wqr__field--body .mce-tinymce.mce-panel,
.wqr__field--body .mce-tinymce.mce-container {
    visibility: visible !important;
    opacity: 1 !important;
    border: 1px solid var(--wqr-border) !important;
    box-sizing: border-box;
}

.wqr__field--body .mce-edit-area {
    min-height: 360px !important;
}

.wqr__field--body .mce-edit-area iframe,
.wqr__field--body #wqr_body_editor_ifr {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
    min-height: 360px !important;
    box-sizing: border-box;
}

/* TinyMCE popovers above drawers */
.mce-window,
.mce-panel.mce-floatpanel,
.mce-menu {
    z-index: 1000010 !important;
}

/* Hide toolbars/menubar/statusbar/quicktags — content-only editor */
.wqr__field--body .wp-editor-tabs,
.wqr__field--body #wp-wqr_body_editor-editor-tools,
.wqr__field--body .mce-toolbar-grp,
.wqr__field--body .mce-top-part,
.wqr__field--body .mce-statusbar,
.wqr__field--body .quicktags-toolbar {
    display: none !important;
}

/* ── Recipient (To) — label above, name + email stacked in card ── */
.wqr__field--to > .wqr__label {
    margin: 0;
}

.wqr__recipient {
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--wqr-border);
    padding: 10px 12px;
    background: #f9fafb;
    min-width: 0;
}

.wqr__avatar {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--wqr-primary);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.wqr__recipient-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    min-width: 0;
}

.wqr__recipient-name,
.wqr__recipient-email {
    font-size: 14px;
    line-height: 1.35;
}

.wqr__recipient-name {
    font-weight: 600;
    color: var(--wqr-text);
}

.wqr__recipient-email {
    font-weight: 400;
    color: var(--wqr-muted);
    word-break: break-all;
}

/* ── Footer ── */
.wqr__footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 16px 24px 24px;
    border-top: 1px solid var(--wqr-border);
    background: #fff;
    flex: 0 0 auto;
    margin-top: auto;
    width: 100%;
    box-sizing: border-box;
}

.wqr__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 18px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.wqr__btn--cancel {
    background: #ffffff;
    border: 1px solid #000000;
    color: #000000;
}

.wqr__btn--cancel:hover {
    background: #f5f5f5;
}

.wqr__btn--submit {
    background: var(--wqr-primary);
    border: 1px solid var(--wqr-primary);
    color: #ffffff;
}

.wqr__btn--submit:hover:not(:disabled):not(.loading) {
    opacity: 0.92;
}

.wqr__btn--submit:disabled:not(.loading) {
    opacity: 0.5;
    cursor: not-allowed;
}

.wqr__btn--submit.loading {
    opacity: 0.85;
    pointer-events: none;
    position: relative;
    padding-right: 40px;
    cursor: wait;
}

.wqr__btn--submit.loading .wqr__btn-icon {
    opacity: 0.35;
}

.wqr__btn--submit.loading::after {
    content: "";
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    position: absolute;
    right: 14px;
    top: 50%;
    margin-top: -8px;
    animation: wqr-spin 0.8s linear infinite;
}

@keyframes wqr-spin {
    to {
        transform: rotate(360deg);
    }
}

.wqr__btn-icon {
    flex: 0 0 auto;
}

/* ── Elementor editor preview (drawer stays in-root, not portaled) ── */
.wiz-quote-resubmit--editor-preview .drawer-overlay {
    position: relative;
    visibility: visible;
    opacity: 1;
    display: block;
    height: 0;
}

.wiz-quote-resubmit--editor-preview .wiz-quote-resubmit-drawer.drawer {
    position: relative;
    right: auto !important;
    height: auto;
    min-height: 520px;
    margin-top: 12px;
}

@media (max-width: 767px) {
    .wqr__footer {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .wqr__btn {
        flex: 1 1 calc(50% - 6px);
        min-width: 140px;
    }
}
