/**
 * Bates frontend integration for The Newsletter Plugin.
 *
 * The plugin stylesheet remains enabled for compatibility. These rules are
 * intentionally scoped to Newsletter's public forms/page wrapper and are
 * loaded afterwards, so updates of the plugin do not overwrite the design.
 */

.tb-newsletter-content,
.tnp-subscription,
.tnp-form.tnp-profile,
form.tnp-profile,
.tnp-button-form {
    --tb-newsletter-black: #000000;
    --tb-newsletter-text: var(--tb-color-text, #222222);
    --tb-newsletter-headline: var(--tb-font-headline, "ThemeWebfontHeadline", sans-serif);
    --tb-newsletter-content: var(--tb-font-content, "ThemeWebfontContent", sans-serif);
    color: var(--tb-newsletter-text);
    font-family: var(--tb-newsletter-content);
}

/* The Gutenberg content itself should use the normal page width. */
.tb-newsletter-content {
    width: 100%;
    max-width: 100%;
}

/* Remove Newsletter's 500px form restriction so forms behave like the
 * existing Bates/Gwolle forms inside Gutenberg columns. */
div.tnp-subscription,
form.tnp-subscription,
div.tnp-form.tnp-profile,
form.tnp-profile {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    margin: 1.15rem 0;
    padding: 0;
}

.tnp-subscription .tnp-field,
.tnp-form.tnp-profile .tnp-field,
form.tnp-profile .tnp-field {
    float: none;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0 0 1.15rem;
    padding: 0;
    border: 0;
}

/* Labels follow the same language as the Gwolle form: content font, black,
 * bold, compact spacing. */
.tnp-subscription label,
.tnp-form.tnp-profile label,
form.tnp-profile label {
    display: block;
    margin: 0 0 0.28rem;
    padding: 0;
    color: #000000;
    font-family: var(--tb-newsletter-content) !important;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
}

/* Text/select fields mirror the Bates/Gwolle underline-style fields. */
.tnp-subscription input[type="text"],
.tnp-subscription input[type="email"],
.tnp-subscription input[type="url"],
.tnp-subscription input[type="tel"],
.tnp-subscription input[type="number"],
.tnp-subscription input[type="password"],
.tnp-subscription select,
.tnp-form.tnp-profile input[type="text"],
.tnp-form.tnp-profile input[type="email"],
.tnp-form.tnp-profile input[type="url"],
.tnp-form.tnp-profile input[type="tel"],
.tnp-form.tnp-profile input[type="number"],
.tnp-form.tnp-profile input[type="password"],
.tnp-form.tnp-profile select,
form.tnp-profile input[type="text"],
form.tnp-profile input[type="email"],
form.tnp-profile input[type="url"],
form.tnp-profile input[type="tel"],
form.tnp-profile input[type="number"],
form.tnp-profile input[type="password"],
form.tnp-profile select {
    display: block;
    width: 100% !important;
    max-width: 100%;
    height: auto;
    box-sizing: border-box;
    margin: 0;
    padding: 0.12rem 0 0.22rem;
    color: var(--tb-newsletter-text);
    background: #ffffff;
    background-image: none;
    border: 0;
    border-bottom: 1px solid var(--tb-newsletter-text);
    border-radius: 0;
    box-shadow: none;
    font-family: var(--tb-newsletter-content);
    font-size: 1.06rem;
    line-height: 1.35;
    outline: none;
    text-shadow: none;
}

.tnp-subscription textarea,
.tnp-form.tnp-profile textarea,
form.tnp-profile textarea {
    display: block;
    width: 100% !important;
    max-width: 100%;
    min-height: 150px;
    box-sizing: border-box;
    margin: 0;
    padding: 0.55rem 0.65rem;
    color: var(--tb-newsletter-text);
    background: #ffffff;
    border: 1px solid var(--tb-newsletter-text);
    border-radius: 0;
    box-shadow: none;
    font-family: var(--tb-newsletter-content);
    font-size: 1.06rem;
    line-height: 1.4;
    outline: none;
    resize: vertical;
}

.tnp-subscription input:not([type="checkbox"]):not([type="radio"]):focus,
.tnp-subscription select:focus,
.tnp-form.tnp-profile input:not([type="checkbox"]):not([type="radio"]):focus,
.tnp-form.tnp-profile select:focus,
form.tnp-profile input:not([type="checkbox"]):not([type="radio"]):focus,
form.tnp-profile select:focus {
    border-bottom-color: var(--tb-newsletter-black);
    box-shadow: none;
    outline: none;
}

.tnp-subscription textarea:focus,
.tnp-form.tnp-profile textarea:focus,
form.tnp-profile textarea:focus {
    border-color: var(--tb-newsletter-black);
    box-shadow: none;
    outline: none;
}

/* Checkbox/list/privacy fields stay compact and readable. */
.tnp-subscription .tnp-field-checkbox,
.tnp-form.tnp-profile .tnp-field-checkbox,
form.tnp-profile .tnp-field-checkbox,
.tnp-subscription .tnp-field-privacy,
.tnp-form.tnp-profile .tnp-field-privacy,
form.tnp-profile .tnp-field-privacy {
    margin-bottom: 0.75rem;
}

.tnp-subscription .tnp-field-checkbox label,
.tnp-form.tnp-profile .tnp-field-checkbox label,
form.tnp-profile .tnp-field-checkbox label,
.tnp-subscription .tnp-field-privacy label,
.tnp-form.tnp-profile .tnp-field-privacy label,
form.tnp-profile .tnp-field-privacy label {
    display: inline;
    margin: 0;
    font-weight: 400;
}

.tnp-subscription input[type="checkbox"],
.tnp-subscription input[type="radio"],
.tnp-form.tnp-profile input[type="checkbox"],
.tnp-form.tnp-profile input[type="radio"],
form.tnp-profile input[type="checkbox"],
form.tnp-profile input[type="radio"] {
    width: auto !important;
    max-width: none;
    margin: 0 0.45rem 0 0;
    vertical-align: -0.1em;
}

/* Privacy uses input + label as siblings in Newsletter. */
.tnp-subscription .tnp-field-privacy,
.tnp-form.tnp-profile .tnp-field-privacy,
form.tnp-profile .tnp-field-privacy {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
}

.tnp-subscription .tnp-field-privacy input[type="checkbox"],
.tnp-form.tnp-profile .tnp-field-privacy input[type="checkbox"],
form.tnp-profile .tnp-field-privacy input[type="checkbox"] {
    flex: 0 0 auto;
    margin: 0.2em 0 0;
}

/* Buttons use the same rounded Bates treatment used for Gwolle. */
.tnp-subscription input.tnp-submit,
.tnp-form.tnp-profile input.tnp-submit,
form.tnp-profile input.tnp-submit,
.tnp-button-form button.tnp-submit,
.tnp-button-form input.tnp-submit,
.tnp-unsubscribe button.tnp-submit,
.tnp-reactivate button.tnp-submit {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    float: none !important;
    width: auto !important;
    min-width: 0;
    min-height: 44px;
    height: auto;
    box-sizing: border-box;
    margin: 0;
    padding: 0.65rem 1.15rem;
    color: #ffffff !important;
    background: var(--tb-color-link, #000000) !important;
    background-image: none !important;
    border: 2px solid var(--tb-color-link, #000000) !important;
    border-radius: 20px !important;
    box-shadow: none !important;
    font-family: var(--tb-newsletter-headline) !important;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    text-decoration: none !important;
    text-shadow: none !important;
    cursor: pointer;
    appearance: none;
}

.tnp-subscription input.tnp-submit:hover,
.tnp-subscription input.tnp-submit:focus,
.tnp-form.tnp-profile input.tnp-submit:hover,
.tnp-form.tnp-profile input.tnp-submit:focus,
form.tnp-profile input.tnp-submit:hover,
form.tnp-profile input.tnp-submit:focus,
.tnp-button-form button.tnp-submit:hover,
.tnp-button-form button.tnp-submit:focus,
.tnp-button-form input.tnp-submit:hover,
.tnp-button-form input.tnp-submit:focus,
.tnp-unsubscribe button.tnp-submit:hover,
.tnp-unsubscribe button.tnp-submit:focus,
.tnp-reactivate button.tnp-submit:hover,
.tnp-reactivate button.tnp-submit:focus {
    color: var(--tb-color-link, #000000) !important;
    background: #ffffff !important;
    border-color: var(--tb-color-link, #000000) !important;
    box-shadow: none !important;
    outline: none;
}

.tnp-button-form {
    margin: 0.75rem 0;
}

/* Per-page button alignment. Newsletter writes an inline text-align value on
 * subscription button containers, therefore the theme setting intentionally
 * uses !important. Center is the default for existing and new pages. */
.tb-newsletter-content .tnp-field-button,
.tb-newsletter-content .tnp-button-form {
    text-align: center !important;
}

.tb-newsletter-content.tb-newsletter-buttons--left .tnp-field-button,
.tb-newsletter-content.tb-newsletter-buttons--left .tnp-button-form {
    text-align: left !important;
}

.tb-newsletter-content.tb-newsletter-buttons--center .tnp-field-button,
.tb-newsletter-content.tb-newsletter-buttons--center .tnp-button-form {
    text-align: center !important;
}

.tb-newsletter-content.tb-newsletter-buttons--right .tnp-field-button,
.tb-newsletter-content.tb-newsletter-buttons--right .tnp-button-form {
    text-align: right !important;
}

/* Newsletter's visible notices/errors should use the same restrained red
 * warning language as the guestbook form. */
.tb-newsletter-content .tnp-error,
.tb-newsletter-content .tnp-warning,
.tnp-subscription .tnp-error,
.tnp-subscription .tnp-warning,
.tnp-form.tnp-profile .tnp-error,
.tnp-form.tnp-profile .tnp-warning {
    box-sizing: border-box;
    margin: 0.9rem 0;
    padding: 10px;
    color: #b70000;
    background: transparent;
    border: 1px solid #b70000;
    font-family: var(--tb-newsletter-content);
    line-height: 1.45;
}

.tb-newsletter-preview-note {
    box-sizing: border-box;
    margin: 0 0 1rem;
    padding: 10px;
    color: var(--tb-newsletter-text);
    background: #e1e1e1;
    border: 0;
    font-family: var(--tb-newsletter-content);
    line-height: 1.45;
}

@media (max-width: 767px) {
    .tnp-subscription input.tnp-submit,
    .tnp-form.tnp-profile input.tnp-submit,
    form.tnp-profile input.tnp-submit,
    .tnp-button-form button.tnp-submit,
    .tnp-button-form input.tnp-submit {
        width: auto !important;
        max-width: 100%;
    }
}

/* -------------------------------------------------------------------------
 * Newsletter acceptance/privacy page lightbox
 * ---------------------------------------------------------------------- */

.tb-newsletter-page-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: max(30px, env(safe-area-inset-top)) max(30px, env(safe-area-inset-right)) max(30px, env(safe-area-inset-bottom)) max(30px, env(safe-area-inset-left));
}

.tb-newsletter-page-lightbox[hidden] {
    display: none !important;
}

.tb-newsletter-page-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
}

.tb-newsletter-page-lightbox__dialog {
    position: relative;
    z-index: 1;
    width: min(1100px, 100%);
    height: min(88vh, 900px);
    height: min(88dvh, 900px);
    max-width: 100%;
    max-height: 100%;
    box-sizing: border-box;
    background: #ffffff;
    border: 0;
    border-radius: 20px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
    overflow: visible;
}

.tb-newsletter-page-lightbox__content {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: clamp(28px, 5vw, 64px);
    overflow: auto;
    overscroll-behavior: contain;
    color: var(--tb-color-text, #222222);
    background: var(--tb-color-content-bg, #ffffff);
    border-radius: 20px;
    font-family: var(--tb-font-content, "ThemeWebfontContent", sans-serif);
    scrollbar-gutter: stable;
}

/* The fetched page keeps the same content wrapper/classes as on its normal
 * frontend page. We only neutralize the outer page width because the modal
 * itself already defines the available width. */
.tb-newsletter-page-lightbox__page-content.tb-entry-content {
    width: 100%;
    max-width: var(--tb-content-width, 1400px);
    margin: 0 auto;
    padding: 0;
}

.tb-newsletter-page-lightbox__page-content > :first-child {
    margin-top: 0;
}

.tb-newsletter-page-lightbox__page-content > :last-child {
    margin-bottom: 0;
}

.tb-newsletter-page-lightbox__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    font-family: var(--tb-font-content, "ThemeWebfontContent", sans-serif);
    font-size: 1.1rem;
    text-align: center;
}

.tb-newsletter-page-lightbox__close {
    position: absolute;
    z-index: 3;
    top: 0;
    right: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    margin: 0;
    padding: 0;
    color: #ffffff;
    background: #b70000;
    border: 0;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
    font-family: Arial, sans-serif;
    font-size: 32px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    transform: translate(32%, -32%);
}

.tb-newsletter-page-lightbox__close:hover,
.tb-newsletter-page-lightbox__close:focus {
    color: #ffffff;
    background: #8f0000;
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

html.tb-newsletter-page-lightbox-open,
body.tb-newsletter-page-lightbox-open {
    overflow: hidden !important;
}

@media (max-width: 767px) {
    .tb-newsletter-page-lightbox {
        padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
    }

    .tb-newsletter-page-lightbox__dialog {
        height: 92vh;
        height: 92dvh;
    }

    .tb-newsletter-page-lightbox__content {
        padding: 24px 18px;
    }

    .tb-newsletter-page-lightbox__close {
        width: 44px;
        height: 44px;
        font-size: 30px;
        transform: translate(25%, -25%);
    }
}
