/**
 * WP AJAX Gruppenchat - Responsive (Mobile-First)
 * Breakpoints: < 480px (Smartphones), 480–768px (Large phones), > 768px (Tablets/Desktop)
 */

/* ========== Base: Mobile (< 480px) ========== */
.wagc-chat {
    box-sizing: border-box;
    padding: 0 8px;
    margin: 0 auto;
    max-width: 100%;
    overflow-x: hidden;
}

.wagc-chat-body {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px);
    position: relative;
}

.wagc-sidebar-toggle {
    position: fixed;
    bottom: 80px;
    right: 16px;
    z-index: 100;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
.wagc-sidebar-toggle svg {
    width: 24px;
    height: 24px;
}

.wagc-sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.wagc-sidebar-backdrop.wagc-visible {
    display: block;
    opacity: 1;
}

.wagc-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    background: #fff;
    z-index: 9999;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    overflow-y: auto;
    padding: 56px 16px 24px 16px;
    -webkit-overflow-scrolling: touch;
}
.wagc-sidebar.wagc-open {
    transform: translateX(0);
}
.wagc-sidebar-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    line-height: 1;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
}
.wagc-sidebar-close:hover {
    color: #333;
}

.wagc-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.wagc-top-notices .wagc-notice {
    padding: 10px 12px;
    font-size: 0.9rem;
}

.wagc-whisper-mode-cancel-btn {
    min-height: 44px;
    padding: 8px 14px;
}
.wagc-notice-dismiss {
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
}

.wagc-messages-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 150px;
    overflow: hidden;
}

.wagc-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 10px;
    max-height: none;
    min-height: 120px;
}

.wagc-msg-wrap {
    max-width: 92%;
    margin-bottom: 10px;
}
.wagc-msg-bubble {
    padding: 10px 12px;
    font-size: 1rem;
    line-height: 1.4;
}

.wagc-input-area {
    flex-shrink: 0;
    padding: 10px 12px;
    background: #fafafa;
    border-top: 1px solid #ddd;
    -webkit-user-select: none;
    user-select: none;
}

/* Nur schmale Viewports: Chat füllt die Höhe, Eingabe bleibt unten, nur Nachrichten scrollen */
@media (max-width: 767px) {
    .wagc-chat {
        display: flex;
        flex-direction: column;
        height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px));
        max-height: calc(100vh - var(--wp-admin--admin-bar--height, 0px));
        max-height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px));
        overflow: hidden;
        box-sizing: border-box;
    }
    .wagc-chat-body {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow: hidden;
    }
    .wagc-main {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }
    .wagc-top-notices {
        flex-shrink: 0;
    }
    .wagc-messages-wrapper {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }
    .wagc-messages {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .wagc-input-area {
        flex-shrink: 0;
        position: relative;
        z-index: 5;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    }
}

.wagc-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-bottom: 8px;
}
.wagc-input-row textarea {
    flex: 1;
    min-height: 44px;
    padding: 12px 14px;
    font-size: 16px; /* prevents zoom on iOS */
    -webkit-appearance: none;
    appearance: none;
}
.wagc-emoji-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.wagc-emoji-picker {
    max-height: 40vh;
    padding: 12px;
    gap: 6px;
}
.wagc-emoji-picker.wagc-emoji-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: none;
    height: 100%;
    z-index: 10050;
    background: #fff;
    border-radius: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    gap: 8px;
}
.wagc-emoji-item {
    font-size: 1.4rem;
    padding: 8px 10px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
body.wagc-sidebar-open,
body.wagc-actions-sidebar-open {
    overflow: hidden;
}

.wagc-input-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.wagc-input-actions .wagc-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
    font-size: 1rem;
}

/* Berater-Aktionen: auf schmalen Viewports per FAB + Overlay von rechts */
.wagc-actions-sidebar-toggle {
    position: fixed;
    bottom: 144px;
    right: 16px;
    z-index: 100;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #50575e;
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
.wagc-actions-sidebar-toggle svg {
    width: 24px;
    height: 24px;
}

.wagc-actions-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.wagc-actions-backdrop.wagc-visible {
    display: block;
    opacity: 1;
}

.wagc-actions-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(280px, 88vw);
    max-width: 100%;
    margin: 0;
    border-left: 1px solid #ddd;
    border-top: none;
    padding: 56px 16px 24px 16px;
    background: #f9f9f9;
    z-index: 10001;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}
.wagc-actions-sidebar.wagc-open {
    transform: translateX(0);
}

.wagc-actions-sidebar-close {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    line-height: 1;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
}
.wagc-actions-sidebar-close:hover {
    color: #333;
}

.wagc-msg-action-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
}

.wagc-scroll-anchor-wrap {
    bottom: 8px;
}
.wagc-btn-scroll {
    min-height: 44px;
    padding: 10px 16px;
}

/* Modals: full width on mobile */
.wagc-modal {
    padding: 12px;
    align-items: flex-end;
}
.wagc-modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
    padding: 20px 16px;
    -webkit-overflow-scrolling: touch;
}

.wagc-inactivity-modal .wagc-modal-content {
    margin-bottom: 20px;
}
.wagc-inactivity-ja {
    min-height: 48px;
    width: 100%;
}

.wagc-edit-details-modal .wagc-modal-content,
.wagc-blacklist-modal .wagc-modal-content {
    max-height: 90vh;
}

.wagc-blacklist-modal .wagc-blacklist-word-chip {
    min-height: 44px;
    padding: 8px 12px;
}
.wagc-blacklist-modal .wagc-blacklist-actions .wagc-btn {
    min-height: 48px;
    flex: 1;
}

/* Termin-Liste */
.wagc-termine-liste {
    box-sizing: border-box;
    max-width: 100%;
    overflow-x: hidden;
}
.wagc-termine {
    list-style: none;
    margin: 0;
    padding: 0;
}
.wagc-termine-item {
    padding: 14px 10px;
    border-bottom: 1px solid #eee;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.wagc-termine-item .wagc-btn {
    display: block;
    margin: 8px 0 0;
    padding: 12px 16px;
    min-height: 44px;
    min-width: 44px;
    text-align: center;
    box-sizing: border-box;
}
.wagc-termine-item .wagc-date,
.wagc-termine-item .wagc-duration {
    display: block;
    margin-top: 4px;
}

/* ========== 480px – 768px (Large phones / small tablets) ========== */
@media (min-width: 480px) {
    .wagc-chat {
        padding: 0 16px;
    }

    .wagc-sidebar {
        width: 260px;
    }

    .wagc-messages {
        padding: 14px 12px;
    }

    .wagc-input-area {
        padding: 12px 16px;
    }

    .wagc-msg-action-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .wagc-modal {
        align-items: center;
    }
    .wagc-modal-content {
        max-height: 80vh;
        border-radius: 12px;
        max-width: 400px;
    }
}

/* ========== > 768px (Tablets / Desktop) ========== */
@media (min-width: 768px) {
    .wagc-chat {
        padding: 0 2rem;
        border-radius: 8px;
    }

    .wagc-chat-body {
        flex-direction: row;
        min-height: 500px;
    }

    .wagc-sidebar-toggle,
    .wagc-sidebar-backdrop,
    .wagc-sidebar-close,
    .wagc-actions-sidebar-toggle,
    .wagc-actions-backdrop,
    .wagc-actions-sidebar-close {
        display: none !important;
    }

    .wagc-actions-backdrop.wagc-visible {
        display: none !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }

    .wagc-sidebar {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        z-index: auto;
        width: 220px;
        max-width: none;
        transform: none;
        box-shadow: none;
        flex-shrink: 0;
        border-right: 1px solid #ddd;
        padding: 16px;
        background: #f9f9f9;
    }
    .wagc-sidebar.wagc-open {
        transform: none;
    }

    .wagc-main {
        flex: 1;
        min-width: 0;
    }

    .wagc-messages-wrapper {
        min-height: 350px;
    }

    .wagc-messages {
        max-height: 400px;
        padding: 16px;
    }

    .wagc-msg-wrap {
        max-width: 90%;
    }
    .wagc-msg-bubble {
        padding: 8px 12px;
        font-size: 0.95rem;
    }

    .wagc-input-area {
        padding: 12px 16px;
    }

    .wagc-input-row textarea {
        min-height: auto;
        font-size: 0.95rem;
    }

    .wagc-emoji-btn {
        width: auto;
        height: auto;
        min-width: auto;
        min-height: auto;
        padding: 8px 12px;
    }

    .wagc-emoji-picker {
        max-height: 120px;
        padding: 8px;
    }
    .wagc-emoji-item {
        font-size: 1.2rem;
        padding: 2px 4px;
        min-width: auto;
        min-height: auto;
    }

    .wagc-input-actions .wagc-btn {
        min-height: auto;
        min-width: auto;
        padding: 8px 16px;
    }

    .wagc-actions-sidebar {
        display: flex;
        position: relative;
        top: auto;
        right: auto;
        bottom: auto;
        left: auto;
        width: 180px;
        flex-shrink: 0;
        transform: none !important;
        border-left: 1px solid #ddd;
        padding: 16px;
        background: #f9f9f9;
        flex-direction: column;
        box-shadow: none;
        overflow-y: visible;
    }
    .wagc-actions-sidebar.wagc-open {
        transform: none !important;
    }

    .wagc-msg-action-btn {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }

    .wagc-modal-content {
        max-width: 560px;
    }

    .wagc-termine-item .wagc-btn {
        display: inline-block;
        margin: 0 0 0 10px;
        padding: 6px 12px;
        min-height: auto;
    }
    .wagc-termine-item .wagc-date,
    .wagc-termine-item .wagc-duration {
        display: inline;
        margin-top: 0;
    }
}

/* Reduce motion on user preference */
@media (prefers-reduced-motion: reduce) {
    .wagc-sidebar,
    .wagc-sidebar-backdrop,
    .wagc-actions-sidebar,
    .wagc-actions-backdrop {
        transition: none;
    }
}

/* ========== Einzelchat: „Beratung beenden“ rechts in der unteren Button-Leiste ========== */
#sprechstunde-chat-wrap.wagc-chat .wagc-input-actions {
    justify-content: flex-start;
    width: 100%;
    box-sizing: border-box;
}

#sprechstunde-chat-wrap.wagc-chat .wagc-input-actions #sc-end-chat {
    margin-left: auto;
}
