/* ==============================================
   Royal Chat — Floating Button + Popup
   ============================================== */

#rchat-root *,
#rchat-root *::before,
#rchat-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---- Floating Button ---- */
#rchat-btn {
    position: fixed;
    bottom: 80px;
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 9px;
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 13px 20px 13px 16px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

#rchat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.35);
}

#rchat-btn:active {
    transform: translateY(0);
}

#rchat-btn.rchat-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
}

#rchat-btn svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    fill: #fff;
}

/* ---- Inline Shortcode Button ---- */
.rchat-inline-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #25D366;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 12px 22px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    transition: background 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.rchat-inline-btn:hover {
    background: #20bc5a;
    transform: translateY(-1px);
}

.rchat-inline-btn:active {
    transform: translateY(0);
}

.rchat-inline-btn svg {
    width: 20px;
    height: 20px;
    fill: #fff;
    flex-shrink: 0;
}

/* ---- Popup Backdrop ---- */
#rchat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99998;
    background: rgba(0,0,0,0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#rchat-backdrop.rchat-open {
    opacity: 1;
    pointer-events: all;
}

/* ---- Popup Panel ---- */
#rchat-popup {
    position: fixed;
    bottom: 140px;
    z-index: 99999;
    width: 370px;
    max-width: calc(100vw - 32px);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 12px 48px rgba(0,0,0,0.35);
    transform: translateY(16px) scale(0.97);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

#rchat-popup.rchat-open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Popup Header */
#rchat-popup-header {
    background: #1a1a1a;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rchat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.rchat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #b8986a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #000;
    font-weight: 700;
    flex-shrink: 0;
}

.rchat-avatar-img img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.rchat-studio-name {
    font-size: 13px;
    font-weight: 600;
    color: #f5efe6;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rchat-online {
    font-size: 11px;
    color: #25D366;
    margin-top: 2px;
}

#rchat-close {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 6px 8px;
    transition: color 0.15s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

#rchat-close:hover { color: #999; }

/* Popup Body */
#rchat-popup-body {
    background: #111;
    padding: 22px 22px 24px;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.rchat-intro {
    font-size: 13.5px;
    color: #9a9088;
    margin-bottom: 20px;
    line-height: 1.6;
}

/* Form Fields */
.rchat-field {
    margin-bottom: 18px !important;
    padding-bottom: 0;
}

.rchat-field:last-child {
    margin-bottom: 0 !important;
}

.rchat-label {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #5a5248;
    margin-bottom: 6px;
    display: block;
}

.rchat-select,
.rchat-input {
    width: 100%;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 4px;
    padding: 13px 16px;
    color: #d8d0c0;
    font-size: 16px; /* Prevents iOS zoom on focus */
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    outline: none;
    transition: border-color 0.15s;
    cursor: pointer;
    text-indent: 2px;
}

.rchat-select-wrap {
    position: relative;
}

.rchat-select-wrap::after {
    content: '\25BE';
    position: absolute;
    right: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: #5a5248;
    font-size: 12px;
    pointer-events: none;
}

.rchat-select:focus,
.rchat-input:focus {
    border-color: #b8986a;
}

.rchat-select option { background: #1a1a1a; }

/* Date row */
.rchat-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Send Button */
#rchat-send {
    width: 100%;
    margin-top: 20px;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 14px 12px;
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    letter-spacing: 0.05em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: filter 0.15s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

#rchat-send:hover {
    filter: brightness(0.9);
    transform: translateY(-1px);
}

#rchat-send:active {
    transform: translateY(0);
}

#rchat-send svg {
    width: 16px;
    height: 16px;
    fill: #fff;
    flex-shrink: 0;
}

.rchat-skip {
    font-size: 12px;
    color: #3a3530;
    text-align: center;
    margin-top: 14px;
    cursor: pointer;
    text-decoration: underline;
    background: none !important;
    background-color: transparent !important;
    border: none;
    width: 100%;
    font-family: inherit;
    padding: 8px 0;
    -webkit-tap-highlight-color: transparent;
}

.rchat-skip:hover,
.rchat-skip:focus,
.rchat-skip:active {
    color: #5a5048;
    background: none !important;
    background-color: transparent !important;
}

/* ---- Mobile Responsiveness ---- */

/* Tablets and small laptops */
@media (max-width: 768px) {
    #rchat-popup {
        width: calc(100vw - 32px);
        bottom: 100px;
    }

    #rchat-btn {
        bottom: 50px;
    }

    #rchat-popup-body {
        max-height: 55vh;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    #rchat-popup {
        position: fixed;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 85vh;
        max-height: 85dvh;
    }

    #rchat-popup.rchat-open {
        transform: translateY(0) scale(1);
    }

    #rchat-popup-header {
        padding: 14px 16px;
    }

    #rchat-popup-body {
        max-height: calc(85vh - 70px);
        max-height: calc(85dvh - 70px);
        padding: 18px 16px 24px;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    #rchat-btn {
        bottom: 24px;
        padding: 11px 16px 11px 13px;
        font-size: 13px;
    }

    #rchat-btn svg {
        width: 20px;
        height: 20px;
    }

    #rchat-send {
        padding: 16px 12px;
        font-size: 15px;
    }

    .rchat-skip {
        padding: 12px 0;
        font-size: 13px;
    }

    .rchat-select,
    .rchat-input {
        padding: 14px 16px;
    }

    /* Full-width dates on very small screens */
    .rchat-dates {
        grid-template-columns: 1fr;
    }
}

/* ---- Light Theme ---- */
.rchat-theme-light #rchat-popup-header {
    background: #f5f5f5;
}

.rchat-theme-light .rchat-studio-name {
    color: #1a1a1a;
}

.rchat-theme-light .rchat-online {
    color: #25D366;
}

.rchat-theme-light #rchat-close {
    color: #999;
}

.rchat-theme-light #rchat-close:hover {
    color: #555;
}

.rchat-theme-light #rchat-popup-body {
    background: #fff;
}

.rchat-theme-light .rchat-intro {
    color: #555;
}

.rchat-theme-light .rchat-label {
    color: #888;
}

.rchat-theme-light .rchat-select,
.rchat-theme-light .rchat-input {
    background: #f9f9f9;
    border-color: #ddd;
    color: #333;
}

.rchat-theme-light .rchat-select:focus,
.rchat-theme-light .rchat-input:focus {
    border-color: #b8986a;
}

.rchat-theme-light .rchat-select option {
    background: #fff;
}

.rchat-theme-light .rchat-select-wrap::after {
    color: #999;
}

.rchat-theme-light .rchat-skip {
    color: #aaa;
}

.rchat-theme-light .rchat-skip:hover,
.rchat-theme-light .rchat-skip:focus,
.rchat-theme-light .rchat-skip:active {
    color: #666;
    background: none !important;
    background-color: transparent !important;
}

.rchat-theme-light #rchat-popup {
    box-shadow: 0 12px 48px rgba(0,0,0,0.15);
}

.rchat-theme-light .rchat-avatar {
    background: #e8dcc8;
    color: #5a4a2a;
}

/* Very small phones (iPhone SE, etc.) */
@media (max-width: 360px) {
    #rchat-popup-body {
        padding: 14px 12px 20px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    .rchat-intro {
        font-size: 13px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #rchat-popup {
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        max-height: 100vh;
        max-height: 100dvh;
    }

    #rchat-popup-body {
        max-height: calc(100vh - 70px);
        max-height: calc(100dvh - 70px);
    }
}
