/* ============================================================
   Global responsive safety net — loaded last so it wins where
   page stylesheets don't already handle small screens.
   ============================================================ */
img, svg, video { max-width: 100%; }
iframe { max-width: 100%; }

/* ============================================================
   Global flash messages — floating toast, colour-coded by level.
   (The full-screen sign page keeps its own centred variant.)
   ============================================================ */
body:not([data-page="sign"]):not([data-page="sign-certificate"]) .site-messages {
    position: fixed;
    top: 18px;
    right: 18px;
    left: auto;
    z-index: 1400;
    margin: 0;
    width: min(400px, calc(100vw - 32px));
    display: grid;
    gap: 10px;
    transition: opacity .35s ease, transform .35s ease;
}
body:not([data-page="sign"]):not([data-page="sign-certificate"]) .site-messages.is-dismissed {
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
}
.site-message {
    padding: 13px 16px;
    border-radius: 12px;
    border: 1px solid var(--sf-line, #e2ded4);
    border-left-width: 4px;
    background: #fbfaf7;
    color: #211f1b;
    font-size: 13.5px;
    line-height: 1.4;
    box-shadow: 0 14px 40px rgba(33, 31, 27, 0.14);
}
.site-message--success { border-left-color: #1f8a5b; background: #f0f7f2; color: #1a5e43; }
.site-message--error   { border-left-color: #b0492f; background: #f8e7e2; color: #8f3a24; }
.site-message--warning { border-left-color: #b07a16; background: #faf3e2; color: #815812; }
.site-message--info    { border-left-color: #3f6fb0; background: #eaf0f8; color: #2f5286; }
.site-message--debug   { border-left-color: #8c877d; }

@media (max-width: 640px) {
    body:not([data-page="sign"]):not([data-page="sign-certificate"]) .site-messages {
        top: 12px;
        right: 12px;
        left: 12px;
        width: auto;
    }
}

/* Global pending-account-deletion bar (authenticated pages) */
.account-deletion-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 10px 18px;
    background: #f8e7e2;
    border-bottom: 1px solid rgba(176, 73, 47, 0.28);
    color: #8f3a24;
    font-size: 13.5px;
    text-align: center;
}
.account-deletion-bar strong { color: #7a3120; }
.account-deletion-bar button {
    border: 1px solid rgba(176, 73, 47, 0.4);
    border-radius: 8px;
    background: #fff;
    color: #8f3a24;
    padding: 6px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.account-deletion-bar button:hover { background: #fdf3f0; }
.account-deletion-bar form { margin: 0; }
.public-mobile-nav { display: none; }

@media (max-width: 1080px) {
    .public-mobile-nav { display: flex; align-items: center; gap: 10px; margin-left: auto; }
    .public-mobile-nav > a { color: var(--sf-ink, #211f1b); text-decoration: none; font-size: 13px; font-weight: 700; }
    .public-mobile-nav .public-mobile-nav__cta { padding: 8px 12px; border-radius: 9px; background: var(--sf-accent, #1f6e5b); color: #fff; }
    .public-mobile-nav .language-switcher { display: flex; }
}

/* Tablet */
@media (max-width: 900px) {
    .contact-card { grid-template-columns: 1fr; }
    .signflow-branding-layout { grid-template-columns: 1fr; }
    .signflow-email-preview__frame { height: 460px; }
}

/* Phones */
@media (max-width: 640px) {
    /* Public marketing header wraps instead of overflowing */
    .topbar { flex-wrap: wrap; row-gap: 8px; padding: 12px 16px; }
    .topbar .desktop-nav { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 12px 14px; }
    .public-mobile-nav { gap: 8px; }
    .public-mobile-nav > a:first-child { display: none; }

    /* Modals fit the viewport and scroll internally */
    .picker-modal { padding: 10px; }
    .picker-modal .picker-dialog,
    .signflow-share-modal .picker-dialog,
    .picker-form-dialog {
        width: calc(100vw - 64px) !important;
        max-width: calc(100vw - 64px) !important;
        max-height: 90vh;
        overflow-y: auto;
    }
    .signflow-method-grid { grid-template-columns: 1fr; }

    /* Support chat + cookie banner fit small screens */
    .support-chat { right: 14px; bottom: 14px; }
    .support-chat__panel { width: calc(100vw - 28px); }
    .cookie-consent { left: 10px; right: 10px; bottom: 10px; padding: 14px; gap: 12px; }
    .cookie-consent__actions { width: 100%; }
    .cookie-consent__btn { flex: 1; text-align: center; }

    /* Auth cards use full width */
    .auth-shell, .auth-shell-wide { width: 100%; }

    /* App header on phones: drop the inline search, keep burger left and the
       primary action + avatar grouped on the right. */
    .signflow-app .signflow-top-search { display: none; }
    .signflow-app .signflow-new-button { margin-left: auto; }
    .signflow-app .signflow-topbar__actions { margin-left: auto; }
}

/* ============================================================
   Mobile/tablet: hamburger + off-canvas sidebar drawer
   ============================================================ */
.signflow-drawer-toggle { display: none; }
.signflow-drawer-backdrop { display: none; }
/* The drawer footer (language + logout) only appears inside the mobile drawer. */
.signflow-sidebar__footer { display: none; }

@media (max-width: 900px) {
    .signflow-app { display: block; }
    .signflow-main { width: 100%; }

    .signflow-drawer-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 42px; height: 42px; flex: none; order: -1;
        border: 1px solid var(--sf-line); border-radius: 12px;
        background: var(--sf-panel, #fbfaf7); color: var(--sf-text, #211f1b); cursor: pointer;
    }
    .signflow-drawer-toggle svg { width: 21px; height: 21px; }

    /* --- Clean mobile header: burger · search/gap · primary action · avatar --- */
    .signflow-app .signflow-topbar {
        flex-wrap: nowrap; gap: 10px; align-items: center;
        padding-top: 12px; padding-bottom: 12px;
    }
    .signflow-app .signflow-topbar__spacer { display: none; }
    .signflow-app .signflow-top-search { flex: 1 1 auto; min-width: 0; }

    /* Compact primary action so it never overflows the row */
    .signflow-app .signflow-new-button {
        flex: none; white-space: nowrap; padding: 9px 14px; font-size: 13px;
    }

    /* Right-side actions collapse to just the avatar; language + logout
       move into the drawer footer where there's room. */
    .signflow-app .signflow-topbar__actions { flex: none; gap: 8px; }
    .signflow-app .signflow-topbar__actions .language-switcher,
    .signflow-app .signflow-topbar__actions .signflow-logout-form { display: none; }
    .signflow-app .signflow-avatar { flex: none; }

    /* Drawer footer: show the language switch + logout at the bottom of the drawer */
    .signflow-app .signflow-sidebar .signflow-sidebar__footer {
        display: flex; flex-direction: column; gap: 12px;
        margin-top: auto; padding: 16px; border-top: 1px solid var(--sf-line);
    }

    /* Sidebar becomes an off-canvas drawer that slides in from the left */
    .signflow-app .signflow-sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; height: 100vh;
        width: 86vw; max-width: 320px;
        display: flex; flex-direction: column;
        transform: translateX(-100%); transition: transform .25s ease;
        z-index: 1300; overflow-y: auto;
        border-right: 1px solid var(--sf-line); border-bottom: 0;
        box-shadow: 0 0 44px rgba(33, 31, 27, .28);
    }
    .signflow-app .signflow-sidebar.is-open { transform: translateX(0); }

    .signflow-drawer-backdrop {
        display: block; position: fixed; inset: 0; background: rgba(33, 31, 27, .45);
        z-index: 1290; opacity: 0; visibility: hidden; transition: opacity .25s ease;
    }
    .signflow-drawer-backdrop.is-open { opacity: 1; visibility: visible; }
    body.drawer-open { overflow: hidden; }
}

@media (min-width: 901px) {
    .signflow-drawer-toggle, .signflow-drawer-backdrop { display: none !important; }
}
