/**
 * ChatPop Next - Frontend Styles
 * Version: 1.0.0
 * RTL-first design with responsive support
 */

/* ==========================================================================
   CSS Variables (set via inline styles from PHP)
   ========================================================================== */
:root {
    --chatpop-primary: #0073aa;
    --chatpop-secondary: #23282d;
    --chatpop-button-size: 60px;
    --chatpop-border-radius: 12px;
    --chatpop-z-index: 9999;
    --chatpop-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --chatpop-whatsapp: #25D366;
    --chatpop-error: #dc3545;
    --chatpop-success: #28a745;
}

/* ==========================================================================
   Launcher Button
   ========================================================================== */
.chatpop-launcher {
    position: fixed;
    bottom: 20px;
    z-index: var(--chatpop-z-index);
    width: var(--chatpop-button-size);
    height: var(--chatpop-button-size);
    border-radius: 50%;
    background: var(--chatpop-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--chatpop-shadow);
    padding: 0;
    outline: none;
}

.chatpop-launcher.chatpop-position-right {
    right: 20px;
}

.chatpop-launcher.chatpop-position-left {
    left: 20px;
}

.chatpop-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

.chatpop-launcher:focus {
    outline: 2px solid var(--chatpop-primary);
    outline-offset: 2px;
}

.chatpop-launcher__icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.chatpop-launcher__text {
    position: absolute;
    bottom: calc(100% + 8px);
    background: var(--chatpop-secondary);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chatpop-launcher__text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--chatpop-secondary);
}

.chatpop-launcher:hover .chatpop-launcher__text {
    opacity: 1;
    visibility: visible;
}

/* Pulse animation for launcher */
.chatpop-launcher--pulse {
    animation: chatpop-pulse 2s infinite;
}

@keyframes chatpop-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(var(--chatpop-primary-rgb, 0, 115, 170), 0.4);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(var(--chatpop-primary-rgb, 0, 115, 170), 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(var(--chatpop-primary-rgb, 0, 115, 170), 0);
    }
}

/* ==========================================================================
   Widget Modal
   ========================================================================== */
.chatpop-widget {
    position: fixed;
    z-index: calc(var(--chatpop-z-index) + 1);
    background: #fff;
    border-radius: var(--chatpop-border-radius);
    box-shadow: var(--chatpop-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.chatpop-widget[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

.chatpop-widget[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

.chatpop-widget--open {
    display: flex;
    animation: chatpop-slideUp 0.3s ease;
}

/* Desktop positioning */
@media (min-width: 768px) {
    .chatpop-widget {
        bottom: 100px;
        width: 380px;
        max-height: 550px;
    }
    
    .chatpop-widget.chatpop-position-right {
        right: 20px;
    }
    
    .chatpop-widget.chatpop-position-left {
        left: 20px;
    }
}

/* Mobile - drawer from bottom */
@media (max-width: 767px) {
    .chatpop-widget {
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 85vh;
        border-radius: var(--chatpop-border-radius) var(--chatpop-border-radius) 0 0;
    }
    
    .chatpop-widget--open {
        animation: chatpop-slideUpMobile 0.3s ease;
    }
}

@keyframes chatpop-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes chatpop-slideUpMobile {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

/* ==========================================================================
   Widget Header
   ========================================================================== */
.chatpop-widget__header {
    background: var(--chatpop-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatpop-widget__title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.chatpop-widget__close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chatpop-widget__close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chatpop-widget__close svg {
    width: 20px;
    height: 20px;
}

/* ==========================================================================
   Widget Content
   ========================================================================== */
.chatpop-widget__content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Steps */
.chatpop-step {
    display: none;
}

.chatpop-step--active {
    display: block;
    animation: chatpop-fadeIn 0.3s ease;
}

@keyframes chatpop-fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* ==========================================================================
   Greeting Step
   ========================================================================== */
.chatpop-greeting__title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: var(--chatpop-secondary);
}

.chatpop-greeting__text {
    color: #666;
    margin: 0 0 24px 0;
}

/* ==========================================================================
   Services Step
   ========================================================================== */
.chatpop-services__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--chatpop-secondary);
}

.chatpop-services__list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chatpop-service {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 14px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chatpop-service:hover {
    border-color: var(--chatpop-primary);
    background: #f0f7ff;
}

.chatpop-service--selected {
    border-color: var(--chatpop-primary);
    background: #f0f7ff;
}

.chatpop-service__name {
    font-weight: 500;
    color: var(--chatpop-secondary);
}

.chatpop-service__arrow {
    width: 16px;
    height: 16px;
    color: #999;
    transition: transform 0.2s ease;
}

[dir="rtl"] .chatpop-service__arrow {
    transform: rotate(180deg);
}

.chatpop-service:hover .chatpop-service__arrow {
    color: var(--chatpop-primary);
}

[dir="rtl"] .chatpop-service:hover .chatpop-service__arrow {
    transform: rotate(180deg) translateX(-4px);
}

[dir="ltr"] .chatpop-service:hover .chatpop-service__arrow {
    transform: translateX(4px);
}

/* Sub-services */
.chatpop-subservices {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e9ecef;
}

.chatpop-subservices__title {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: #666;
}

.chatpop-subservices__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chatpop-subservice {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
}

.chatpop-subservice:hover {
    border-color: var(--chatpop-primary);
    color: var(--chatpop-primary);
}

/* ==========================================================================
   Calendar Step
   ========================================================================== */
.chatpop-calendar__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--chatpop-secondary);
}

.chatpop-calendar__date {
    margin-bottom: 20px;
}

.chatpop-calendar__date label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: #666;
}

.chatpop-calendar__date select {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 15px;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 12px center;
}

[dir="ltr"] .chatpop-calendar__date select {
    background-position: right 12px center;
}

.chatpop-calendar__date select:focus {
    outline: none;
    border-color: var(--chatpop-primary);
}

.chatpop-calendar__times {
    display: none;
}

.chatpop-calendar__times--visible {
    display: block;
}

.chatpop-calendar__times-label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 12px;
    color: #666;
}

.chatpop-calendar__slots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.chatpop-time-slot {
    padding: 10px 8px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    background: #fff;
}

.chatpop-time-slot:hover {
    border-color: var(--chatpop-primary);
    color: var(--chatpop-primary);
}

.chatpop-time-slot--selected {
    background: var(--chatpop-primary);
    border-color: var(--chatpop-primary);
    color: #fff;
}

.chatpop-time-slot--disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.chatpop-calendar__loading {
    text-align: center;
    padding: 20px;
    color: #666;
}

.chatpop-calendar__no-slots {
    text-align: center;
    padding: 20px;
    color: #666;
    background: #f8f9fa;
    border-radius: 8px;
}

/* ==========================================================================
   Form Step
   ========================================================================== */
.chatpop-form__title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--chatpop-secondary);
}

.chatpop-form__group {
    margin-bottom: 16px;
}

.chatpop-form__label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--chatpop-secondary);
}

.chatpop-form__required {
    color: var(--chatpop-error);
    margin-inline-start: 2px;
}

.chatpop-form__input,
.chatpop-form__textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.chatpop-form__input:focus,
.chatpop-form__textarea:focus {
    outline: none;
    border-color: var(--chatpop-primary);
}

.chatpop-form__input--error,
.chatpop-form__textarea--error {
    border-color: var(--chatpop-error);
}

.chatpop-form__input[dir="ltr"],
.chatpop-form__textarea[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

.chatpop-form__textarea {
    min-height: 80px;
    resize: vertical;
}

.chatpop-form__error {
    display: none;
    font-size: 13px;
    color: var(--chatpop-error);
    margin-top: 4px;
}

.chatpop-form__error--visible {
    display: block;
}

.chatpop-form__privacy {
    font-size: 13px;
    color: #666;
    margin-bottom: 16px;
}

.chatpop-form__privacy a {
    color: var(--chatpop-primary);
    text-decoration: none;
}

.chatpop-form__privacy a:hover {
    text-decoration: underline;
}

.chatpop-form__global-error {
    display: none;
    background: #fff5f5;
    border: 1px solid var(--chatpop-error);
    color: var(--chatpop-error);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.chatpop-form__global-error--visible {
    display: block;
}

/* Honeypot */
.chatpop-form__hp {
    position: absolute;
    left: -9999px;
    opacity: 0;
    height: 0;
    width: 0;
    pointer-events: none;
}

/* ==========================================================================
   Thank You Step
   ========================================================================== */
.chatpop-thankyou {
    text-align: center;
    padding: 20px 0;
}

.chatpop-thankyou__icon {
    width: 64px;
    height: 64px;
    background: var(--chatpop-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    animation: chatpop-scaleIn 0.3s ease;
}

@keyframes chatpop-scaleIn {
    from {
        transform: scale(0);
    }
    to {
        transform: scale(1);
    }
}

.chatpop-thankyou__icon svg {
    width: 32px;
    height: 32px;
    color: #fff;
}

.chatpop-thankyou__title {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: var(--chatpop-secondary);
}

.chatpop-thankyou__text {
    color: #666;
    margin: 0 0 24px 0;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.chatpop-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    text-decoration: none;
}

.chatpop-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chatpop-btn--primary {
    background: var(--chatpop-primary);
    color: #fff;
    width: 100%;
}

.chatpop-btn--primary:hover:not(:disabled) {
    filter: brightness(1.1);
}

.chatpop-btn--secondary {
    background: #f8f9fa;
    color: var(--chatpop-secondary);
    border: 1px solid #dee2e6;
}

.chatpop-btn--secondary:hover:not(:disabled) {
    background: #e9ecef;
}

.chatpop-btn--whatsapp {
    background: var(--chatpop-whatsapp);
    color: #fff;
    width: 100%;
}

.chatpop-btn--whatsapp:hover:not(:disabled) {
    background: #20bd5a;
}

.chatpop-btn--whatsapp svg {
    width: 20px;
    height: 20px;
}

.chatpop-btn--link {
    background: transparent;
    color: var(--chatpop-secondary);
    padding: 8px 16px;
}

.chatpop-btn--link:hover {
    color: var(--chatpop-primary);
}

/* Button row */
.chatpop-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.chatpop-buttons--single {
    justify-content: center;
}

.chatpop-buttons .chatpop-btn--primary {
    flex: 1;
}

/* Loading spinner */
.chatpop-btn__spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: chatpop-spin 0.8s linear infinite;
}

@keyframes chatpop-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   Widget Footer
   ========================================================================== */
.chatpop-widget__footer {
    padding: 10px 20px;
    text-align: center;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.chatpop-branding {
    font-size: 12px;
    color: #999;
}

.chatpop-branding a {
    color: #666;
    text-decoration: none;
}

.chatpop-branding a:hover {
    color: var(--chatpop-primary);
}

/* ==========================================================================
   Overlay
   ========================================================================== */
.chatpop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--chatpop-z-index);
    display: none;
}

.chatpop-overlay--visible {
    display: block;
    animation: chatpop-fadeIn 0.3s ease;
}

/* Only show overlay on mobile */
@media (min-width: 768px) {
    .chatpop-overlay {
        display: none !important;
    }
}

/* ==========================================================================
   Popup Modal
   ========================================================================== */
.chatpop-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: calc(var(--chatpop-z-index) + 10);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chatpop-popup-overlay--visible {
    display: flex;
    animation: chatpop-fadeIn 0.3s ease;
}

.chatpop-popup {
    background: #fff;
    border-radius: var(--chatpop-border-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: chatpop-popupIn 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chatpop-popup[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

.chatpop-popup[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

@keyframes chatpop-popupIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.chatpop-popup__close {
    position: absolute;
    top: 12px;
    background: rgba(0, 0, 0, 0.1);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 1;
}

[dir="rtl"] .chatpop-popup__close {
    left: 12px;
}

[dir="ltr"] .chatpop-popup__close {
    right: 12px;
}

.chatpop-popup__close:hover {
    background: rgba(0, 0, 0, 0.2);
}

.chatpop-popup__close svg {
    width: 16px;
    height: 16px;
    color: #666;
}

.chatpop-popup__content {
    padding: 32px 24px;
}

.chatpop-popup__title {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 12px 0;
    color: var(--chatpop-secondary);
    padding-inline-end: 32px;
}

.chatpop-popup__text {
    font-size: 15px;
    color: #666;
    margin: 0 0 20px 0;
    line-height: 1.6;
}

.chatpop-popup__benefits {
    list-style: none;
    padding: 0;
    margin: 0 0 24px 0;
}

.chatpop-popup__benefit {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    font-size: 14px;
    color: var(--chatpop-secondary);
}

.chatpop-popup__benefit-icon {
    width: 20px;
    height: 20px;
    color: var(--chatpop-success);
    flex-shrink: 0;
    margin-top: 2px;
}

.chatpop-popup__cta {
    width: 100%;
    padding: 14px 24px;
    font-size: 16px;
}

.chatpop-popup__terms {
    font-size: 12px;
    color: #999;
    text-align: center;
    margin-top: 16px;
}

.chatpop-popup__terms a {
    color: #666;
    text-decoration: none;
}

.chatpop-popup__terms a:hover {
    text-decoration: underline;
}

/* Popup Form (after CTA click) */
.chatpop-popup__form {
    display: none;
    padding: 24px;
    border-top: 1px solid #e9ecef;
}

.chatpop-popup__form--visible {
    display: block;
    animation: chatpop-fadeIn 0.3s ease;
}

.chatpop-popup__form .chatpop-form__group {
    margin-bottom: 14px;
}

/* Popup Thank You */
.chatpop-popup__thankyou {
    display: none;
    text-align: center;
    padding: 40px 24px;
}

.chatpop-popup__thankyou--visible {
    display: block;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */
.chatpop-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible for keyboard navigation */
.chatpop-widget *:focus-visible,
.chatpop-popup *:focus-visible {
    outline: 2px solid var(--chatpop-primary);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .chatpop-launcher,
    .chatpop-widget,
    .chatpop-popup,
    .chatpop-step,
    .chatpop-overlay,
    .chatpop-popup-overlay {
        animation: none !important;
        transition: none !important;
    }
    
    .chatpop-launcher--pulse {
        animation: none !important;
    }
}

/* ==========================================================================
   Print - Hide widget/popup
   ========================================================================== */
@media print {
    .chatpop-launcher,
    .chatpop-widget,
    .chatpop-overlay,
    .chatpop-popup-overlay {
        display: none !important;
    }
}
