/* Widget de suporte — tema claro iOS / laranja (novo-layout) */
:root {
    --ps-orange: #FF6B00;
    --ps-orange-soft: #FFF0E6;
    --ps-bg: #F2F2F7;
    --ps-card: #FFFFFF;
    --ps-text: #1C1C1E;
    --ps-muted: #8E8E93;
    --ps-sep: rgba(60, 60, 67, 0.18);
    --ps-green: #34C759;
}

#ps-support-root {
    touch-action: manipulation;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.ps-support-fab {
    position: fixed;
    right: 16px;
    /* acima do tab bar */
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 99990;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--ps-orange);
    color: #fff;
    box-shadow:
        0 4px 14px rgba(255, 107, 0, 0.35),
        0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.ps-support-fab:hover,
.ps-support-fab:active {
    transform: scale(1.05);
    box-shadow: 0 6px 18px rgba(255, 107, 0, 0.45);
}

.ps-support-fab svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.ps-support-fab .ps-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #FF3B30;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 2px solid #fff;
}

.ps-support-fab .ps-badge.show {
    display: flex;
}

.ps-support-panel {
    position: fixed;
    right: 16px;
    bottom: calc(140px + env(safe-area-inset-bottom, 0px));
    z-index: 99991;
    width: min(380px, calc(100% - 24px));
    max-width: calc(100% - 24px);
    height: min(560px, calc(100dvh - 160px));
    max-height: calc(100dvh - 160px);
    background: var(--ps-card);
    border: 0.5px solid var(--ps-sep);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: inherit;
    box-sizing: border-box;
    overscroll-behavior: contain;
    touch-action: pan-y;
    color: var(--ps-text);
}

.ps-support-panel.open {
    display: flex;
    animation: psSupportIn 0.22s ease;
}

@keyframes psSupportIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.ps-support-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px;
    background: #fff;
    border-bottom: 0.5px solid var(--ps-sep);
    flex-shrink: 0;
}

.ps-support-header h3 {
    margin: 0;
    color: var(--ps-text);
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.2px;
    text-transform: none;
}

.ps-support-header .ps-sub {
    display: block;
    color: var(--ps-muted);
    font-size: 12px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.ps-support-header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.ps-icon-btn {
    width: 32px;
    height: 32px;
    border: 0;
    background: var(--ps-bg);
    color: var(--ps-orange);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.ps-icon-btn:hover {
    background: var(--ps-orange-soft);
}

.ps-support-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--ps-bg);
}

.ps-view {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    padding: 16px;
    box-sizing: border-box;
}

.ps-view.active {
    display: flex;
}

.ps-auth-form label {
    color: var(--ps-muted);
    font-size: 13px;
    margin-bottom: 8px;
    display: block;
}

.ps-auth-form input[type="email"] {
    width: 100%;
    max-width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 0.5px solid var(--ps-sep);
    background: #fff;
    color: var(--ps-text);
    font-size: 16px;
    outline: none;
    margin-bottom: 12px;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.ps-auth-form input[type="email"]:focus {
    border-color: var(--ps-orange);
    box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.15);
}

.ps-btn {
    width: 100%;
    padding: 13px 16px;
    border: none;
    border-radius: 12px;
    background: var(--ps-orange);
    color: #fff;
    font-weight: 650;
    font-size: 15px;
    letter-spacing: 0;
    text-transform: none;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.ps-btn:hover {
    filter: brightness(1.05);
}

.ps-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ps-btn-ghost {
    background: transparent;
    border: 1px solid rgba(255, 107, 0, 0.4);
    color: var(--ps-orange);
}

.ps-hint {
    color: var(--ps-muted);
    font-size: 12px;
    line-height: 1.45;
    margin-top: 12px;
}

.ps-error {
    background: rgba(255, 59, 48, 0.08);
    border: 0.5px solid rgba(255, 59, 48, 0.3);
    color: #FF3B30;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    margin-bottom: 12px;
    display: none;
    word-break: break-word;
}

.ps-error.show {
    display: block;
}

.ps-messages {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 4px 2px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.ps-msg {
    max-width: 88%;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    box-sizing: border-box;
}

.ps-msg.user {
    align-self: flex-end;
    background: var(--ps-orange);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ps-msg.admin {
    align-self: flex-start;
    background: #fff;
    border: 0.5px solid var(--ps-sep);
    color: var(--ps-text);
    border-bottom-left-radius: 4px;
}

.ps-msg .ps-meta {
    display: block;
    margin-top: 6px;
    font-size: 10px;
    opacity: 0.7;
}

.ps-chat-link {
    color: #fff;
    text-decoration: underline;
    word-break: break-all;
    font-weight: 600;
}

.ps-msg.admin .ps-chat-link {
    color: #007AFF;
}

.ps-msg.user .ps-chat-link {
    color: #fff;
}

.ps-msg.system {
    align-self: center;
    max-width: 95%;
    background: var(--ps-orange-soft);
    border: 0.5px dashed rgba(255, 107, 0, 0.35);
    color: var(--ps-muted);
    text-align: center;
    font-size: 12px;
}

.ps-composer {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    border-top: 0.5px solid var(--ps-sep);
    flex-shrink: 0;
    min-width: 0;
}

.ps-composer textarea {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 110px;
    resize: none;
    border-radius: 12px;
    border: 0.5px solid var(--ps-sep);
    background: #fff;
    color: var(--ps-text);
    padding: 10px 12px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.ps-composer textarea:focus {
    border-color: var(--ps-orange);
    box-shadow: 0 0 0 3px rgba(255, 107, 0, 0.12);
}

.ps-composer button {
    width: 48px;
    border: none;
    border-radius: 12px;
    background: var(--ps-orange);
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ps-composer button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ps-status-bar {
    font-size: 12px;
    color: var(--ps-muted);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
}

.ps-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ps-green);
    display: inline-block;
    margin-right: 5px;
}

.ps-status-dot.off {
    background: #C7C7CC;
}

.ps-empty {
    color: var(--ps-muted);
    text-align: center;
    margin: auto;
    font-size: 13px;
    padding: 20px;
    line-height: 1.5;
}

html.ps-support-open,
html.ps-support-open body {
    overflow: hidden !important;
    overscroll-behavior: none;
    width: 100%;
    max-width: 100%;
    height: 100%;
}

html.ps-support-open #ps-support-root {
    touch-action: manipulation;
}

/* Login (sem tab bar) */
body.login-page .ps-support-fab {
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

body.login-page .ps-support-panel {
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

body.login-page.theme-pink .ps-support-fab,
body.login-page.theme-pink .ps-btn,
body.login-page.theme-pink .ps-composer button,
body.login-page.theme-pink .ps-msg.user {
    background: #ff0080;
}

body.login-page.theme-pink .ps-support-fab {
    box-shadow: 0 4px 14px rgba(255, 0, 128, 0.45);
}

body.login-page.theme-pink .ps-icon-btn {
    color: #ff0080;
}

body.login-page.theme-pink .ps-auth-form input[type="email"]:focus,
body.login-page.theme-pink .ps-composer textarea:focus {
    border-color: #ff0080;
    box-shadow: 0 0 0 3px rgba(255, 0, 128, 0.18);
}

@media (max-width: 640px) {
    .ps-support-fab {
        right: 14px;
        bottom: calc(70px + env(safe-area-inset-bottom, 0px));
        width: 54px;
        height: 54px;
    }

    body.login-page .ps-support-fab {
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .ps-support-panel {
        right: 0 !important;
        left: 0 !important;
        bottom: auto !important;
        top: var(--ps-panel-top, 0px) !important;
        width: 100% !important;
        max-width: 100% !important;
        height: var(--ps-panel-height, 100dvh) !important;
        max-height: var(--ps-panel-height, 100dvh) !important;
        border-radius: 16px 16px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        transform: none !important;
    }

    .ps-support-header .ps-sub {
        max-width: 55vw;
    }

    .ps-view {
        padding: 12px;
        min-height: 0;
    }

    .ps-view#ps-view-chat {
        padding-bottom: 8px;
    }

    .ps-composer {
        flex-shrink: 0;
        position: relative;
        z-index: 2;
        background: var(--ps-bg);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .ps-composer textarea,
    .ps-auth-form input[type="email"] {
        font-size: 16px !important;
        transform: translateZ(0);
    }
}
