/* PWA / iPhone home screen fixes */
html {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

html,
body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
}

body.is-standalone {
    overscroll-behavior-y: none;
}

.admin-header {
    padding-top: env(safe-area-inset-top, 0px);
}

.admin-header__inner {
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

main.pb-safe {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
}

/* Chat page — full mobile height */
body:has(.chat-page),
body.is-chat-page {
    overflow: hidden;
    height: 100dvh;
    max-height: 100dvh;
}

body:has(.chat-page) > .min-h-dvh,
body.is-chat-page > .min-h-dvh {
    height: 100%;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

main.pb-safe:has(.chat-page),
body.is-chat-page main.pb-safe {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0;
}

.chat-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 0;
}

.chat-page__header {
    flex-shrink: 0;
}

.chat-app {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.chat-conversation {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.chat-messages-pane {
    flex: 1 1 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-messages-pane::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

#chat-sidebar .overflow-y-auto {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#chat-sidebar .overflow-y-auto::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.chat-form {
    flex-shrink: 0;
}

#chat-sidebar {
    min-height: 0;
}

/* Chat page — full viewport below site header (all screen sizes) */
body.is-chat-page .chat-page__header {
    display: none;
}

body.is-chat-page .chat-page {
    margin: 0;
    max-width: none;
    width: 100%;
    padding: 0;
}

body.is-chat-page .chat-app {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: none;
}

body.is-chat-page #chat-sidebar,
body.is-chat-page .chat-conversation {
    min-height: 0;
    height: 100%;
}

@media (min-width: 768px) {
    body.is-chat-page #chat-sidebar {
        flex: 0 0 auto;
    }

    body.is-chat-page .chat-conversation {
        flex: 1 1 0;
    }
}

@media (max-width: 767px) {
    body.is-chat-list-view #chat-sidebar,
    .chat-page:not(:has(.chat-conversation.flex)) #chat-sidebar {
        flex: 1 1 0;
    }

    body.is-chat-thread-view .chat-page,
    .chat-page:has(.chat-conversation.flex) {
        margin: 0;
        padding: 0;
    }

    body.is-chat-thread-view .chat-conversation,
    .chat-page:has(.chat-conversation.flex) .chat-conversation {
        flex: 1 1 0;
    }

    .chat-form {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    }
}

.chat-load-more-wrap {
    display: flex;
    justify-content: center;
    padding-bottom: 0.75rem;
}

.chat-load-more-wrap.hidden {
    display: none !important;
}

.chat-load-more {
    border: 1px solid #334155;
    border-radius: 999px;
    background: #020617;
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.375rem 0.875rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.chat-load-more:hover:not(:disabled) {
    border-color: #f9b17a;
    color: #f9b17a;
}

.chat-load-more:disabled {
    opacity: 0.6;
    cursor: wait;
}

#chat-messages-list {
    min-height: 0;
}

@media (min-width: 768px) {
    .chat-form {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    }
}

/* Prevent iOS zoom on input focus */
@media (max-width: 767px) {
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

.push-enable-banner {
    position: fixed;
    left: max(0.75rem, env(safe-area-inset-left, 0px));
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    z-index: 1200;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    background: #111827;
    color: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.push-enable-banner__body {
    flex: 1;
    min-width: 0;
}

.push-enable-banner[hidden] {
    display: none !important;
}

.push-enable-banner__text {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.4;
}

.push-enable-banner__link {
    display: inline-block;
    margin-top: 0.35rem;
    color: #93c5fd;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: underline;
    word-break: break-all;
}

.push-enable-banner__link[hidden] {
    display: none !important;
}

.push-enable-banner__btn {
    flex-shrink: 0;
    border: 0;
    border-radius: 999px;
    padding: 0.5rem 0.9rem;
    background: #2563eb;
    color: #fff;
    font: inherit;
    cursor: pointer;
}

.push-enable-banner__btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

.push-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    border: 0;
    border-radius: 0.5rem;
    padding: 0.65rem 0.75rem;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}

.push-menu-btn[hidden] {
    display: none !important;
}
