@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@400;500;600;700&display=swap');

/**
 * حوار (Hiwar) - AI Voice Support CSS
 * 
 * Modern glassmorphism design with RTL/LTR support.
 * Features gradient accents, smooth animations, and mobile-first responsive design.
 * 
 * @version 5.0.0 - Hiwar Theme
 */

/* ============================================================
   CSS VARIABLES - Modern Hiwar Palette
   ============================================================ */
:root {
    /* Modal Specific Variables - Syncs with index.html */
    --ai-modal-bg: rgba(20, 20, 40, 0.65);
    --ai-modal-border: rgba(255, 255, 255, 0.15);
    --ai-modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --ai-text: #ffffff;
    --ai-text-muted: rgba(255, 255, 255, 0.7);
    --ai-status-bg: rgba(255, 255, 255, 0.1);
    --ai-status-border: rgba(255, 255, 255, 0.2);
    --ai-glass: rgba(255, 255, 255, 0.05);
    
    --ai-accent: #00d2ff;
    --ai-accent-end: #3a7bd5;
    --ai-accent-glow: rgba(0, 210, 255, 0.4);
    
    --ai-error: #ef4444;
    --ai-success: #10b981;
    --ai-warning: #f59e0b;
    
    --ai-border-radius: 16px;
    --ai-border-radius-lg: 24px;
    --ai-touch-target: 44px;
}

body.light-theme {
    --ai-modal-bg: rgba(255, 255, 255, 0.85);
    --ai-modal-border: rgba(0, 0, 0, 0.1);
    --ai-modal-shadow: 0 25px 50px -12px rgba(31, 38, 135, 0.15);
    --ai-text: #1a1a2e;
    --ai-text-muted: rgba(26, 26, 46, 0.7);
    --ai-status-bg: rgba(0, 0, 0, 0.05);
    --ai-status-border: rgba(0, 0, 0, 0.1);
    --ai-glass: rgba(0, 0, 0, 0.03);
}

/* ============================================================
   MODAL OVERLAY - Divine Backdrop
   ============================================================ */
.ai-voice-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg,
            rgba(26, 26, 62, 0.95) 0%,
            rgba(74, 31, 110, 0.92) 50%,
            rgba(45, 16, 66, 0.95) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease;
}

.ai-voice-modal.active {
    opacity: 1;
    visibility: visible;
}

/* ============================================================
   MODAL CONTAINER - Sacred Scroll Style
   ============================================================ */
.ai-voice-container {
    width: 90%;
    max-width: 480px;
    background: var(--ai-modal-bg);
    border: 1px solid var(--ai-modal-border);
    border-radius: 32px;
    padding: 45px 35px;
    position: relative;
    overflow: hidden;
    color: var(--ai-text);
    box-shadow: var(--ai-modal-shadow);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    transform: translateY(50px) scale(0.95);
    opacity: 0;
    transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.5s ease;
}

.ai-voice-modal.active .ai-voice-container {
    transform: translateY(0) scale(1);
    opacity: 1;
}



/* ============================================================
   DIVINE GLOW EFFECT
   ============================================================ */
.ai-voice-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 250px;
    height: 250px;
    background: radial-gradient(circle,
            var(--ai-accent-glow) 0%,
            rgba(0, 210, 255, 0.1) 40%,
            transparent 70%);
    border-radius: 50%;
    filter: blur(50px);
    transition: all 0.5s ease;
    pointer-events: none;
    z-index: 0;
}

.ai-voice-modal.active .ai-voice-glow {
    animation: divine-glow 3s ease-in-out infinite;
}

@keyframes divine-glow {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.4;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.4);
        opacity: 0.7;
    }
}

/* ============================================================
   CLOSE BUTTON
   ============================================================ */
.ai-voice-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--ai-glass);
    border: 1px solid var(--ai-modal-border);
    color: var(--ai-text);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.ai-voice-close:hover {
    background: var(--ai-accent);
    color: #fff;
    transform: rotate(90deg) scale(1.1);
    box-shadow: 0 0 20px var(--ai-accent-glow);
}

/* ============================================================
   HEADER - Sacred Title
   ============================================================ */
.ai-voice-header {
    margin-bottom: 25px;
    position: relative;
    z-index: 1;
}

.ai-voice-header h3 {
    font-size: 26px;
    font-weight: 700;
    color: var(--ai-text);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent-end));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
}

.ai-voice-header h3 img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid var(--ai-accent);
    box-shadow: 0 0 15px var(--ai-accent-glow);
}

.ai-voice-header p {
    font-size: 14px;
    color: var(--ai-text-muted);
    margin: 0;
}

/* Bible Verse Quote */
.ai-voice-verse {
    font-size: 13px;
    color: var(--ai-accent);
    font-style: italic;
    margin-top: 8px;
    padding: 0 20px;
    opacity: 0.9;
}

/* ============================================================
   STATUS DISPLAY
   ============================================================ */
.ai-status {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 28px;
    background: var(--ai-status-bg);
    border: 1px solid var(--ai-status-border);
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 40px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 380px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    color: var(--ai-text);
}

.ai-status::before {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ai-accent);
    display: inline-block;
    transition: background 0.3s ease;
    box-shadow: 0 0 10px var(--ai-accent);
}

/* Animations for Status Indicator */
@keyframes pulse-dot {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 15px var(--ai-accent); }
    100% { transform: scale(0.8); opacity: 0.5; }
}

@keyframes spin-ring {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Status States */
.ai-status.connecting::before {
    background: var(--ai-warning);
    animation: pulse-dot 1s infinite ease-in-out;
    box-shadow: 0 0 10px var(--ai-warning);
}

.ai-status.searching::before {
    background: transparent;
    width: 14px;
    height: 14px;
    border: 2px solid var(--ai-accent);
    border-top-color: transparent;
    animation: spin-ring 0.8s linear infinite;
    box-shadow: none;
}

.ai-status.listening::before {
    background: var(--ai-success);
    box-shadow: 0 0 12px var(--ai-success);
}

.ai-status.speaking::before {
    background: var(--ai-accent);
    box-shadow: 0 0 12px var(--ai-accent);
    animation: pulse-dot 0.8s infinite alternate;
}

.ai-status.error::before {
    background: var(--ai-error);
    box-shadow: 0 0 12px var(--ai-error);
}

/* ============================================================
   CANVAS VISUALIZER
   ============================================================ */
.ai-voice-visualizer {
    width: 100%;
    height: 100px;
    margin-bottom: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border-radius: 20px;
    background: var(--ai-status-bg);
    border: 1px solid var(--ai-status-border);
    overflow: hidden;
    box-shadow: none;
}

.ai-voice-visualizer canvas {
    width: 100%;
    height: 100%;
    display: block;
    filter: drop-shadow(0 0 8px var(--ai-accent-glow));
}

/* ============================================================
   WAVE ANIMATION (Fallback)
   ============================================================ */
.ai-voice-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 50px;
    margin: 15px 0;
    position: relative;
    z-index: 1;
}

.ai-voice-wave span {
    width: 5px;
    height: 20px;
    background: linear-gradient(180deg, var(--ai-gold-light), var(--ai-gold-dark));
    border-radius: 3px;
    animation: wave-idle 1.8s ease-in-out infinite;
}

.ai-voice-modal.active .ai-voice-wave span {
    animation: wave-active 0.6s ease-in-out infinite;
}

.ai-voice-wave span:nth-child(1) {
    animation-delay: 0s;
}

.ai-voice-wave span:nth-child(2) {
    animation-delay: 0.12s;
}

.ai-voice-wave span:nth-child(3) {
    animation-delay: 0.24s;
}

.ai-voice-wave span:nth-child(4) {
    animation-delay: 0.36s;
}

.ai-voice-wave span:nth-child(5) {
    animation-delay: 0.48s;
}

.ai-voice-wave span:nth-child(6) {
    animation-delay: 0.36s;
}

.ai-voice-wave span:nth-child(7) {
    animation-delay: 0.24s;
}

.ai-voice-wave span:nth-child(8) {
    animation-delay: 0.12s;
}

.ai-voice-wave span:nth-child(9) {
    animation-delay: 0s;
}

@keyframes wave-idle {

    0%,
    100% {
        height: 18px;
        opacity: 0.5;
    }

    50% {
        height: 28px;
        opacity: 0.8;
    }
}

@keyframes wave-active {

    0%,
    100% {
        height: 12px;
    }

    50% {
        height: 45px;
    }
}

/* ============================================================
   CONTROL BUTTONS
   ============================================================ */
.ai-voice-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin: 25px 0;
    position: relative;
    z-index: 1;
}

.ai-voice-end-btn,
.ai-voice-retry-btn {
    padding: 14px 30px;
    border-radius: 30px;
    border: 2px solid;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: inherit;
}

.ai-voice-end-btn {
    background: var(--ai-glass);
    color: var(--ai-text);
    border-color: var(--ai-modal-border);
}

.ai-voice-end-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--ai-error);
    border-color: var(--ai-error);
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(239, 68, 68, 0.2);
}

.ai-voice-retry-btn {
    background: var(--ai-glass);
    color: var(--ai-accent);
    border-color: var(--ai-modal-border);
    display: none;
}

.ai-voice-retry-btn.visible {
    display: flex;
}

.ai-voice-retry-btn:hover {
    border-color: var(--ai-accent);
    background: rgba(0, 210, 255, 0.1);
    transform: scale(1.05);
    box-shadow: 0 5px 20px var(--ai-accent-glow);
}

/* ============================================================
   CONTACT LINK
   ============================================================ */
.ai-voice-contact {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ai-purple);
    text-decoration: none;
    font-size: 13px;
    padding: 10px 20px;
    border-radius: 20px;
    background: rgba(74, 31, 110, 0.1);
    border: 1px solid rgba(74, 31, 110, 0.2);
    transition: all 0.3s ease;
    margin-top: 10px;
    position: relative;
    z-index: 1;
}

.ai-voice-contact:hover {
    color: var(--ai-gold-dark);
    background: rgba(212, 168, 75, 0.15);
    border-color: var(--ai-gold);
}

/* ============================================================
   FLOATING TRIGGER BUTTON - Biblical Style
   ============================================================ */
.ai-floating-wrapper {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Speech Bubble Label */
.ai-floating-label {
    background: linear-gradient(135deg, var(--ai-purple), var(--ai-purple-light));
    color: var(--ai-gold-light);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 5px 20px rgba(74, 31, 110, 0.5);
    animation: labelFloat 3.5s ease-in-out infinite;
    position: relative;
    border: 2px solid var(--ai-gold);
}

.ai-floating-label::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid var(--ai-purple-light);
}

@keyframes labelFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

/* Floating Trigger Tooltip container */
.ai-floating-btn {
    position: relative;
    width: 85px;
    height: 85px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-purple), var(--ai-purple-dark));
    border: 3px solid var(--ai-gold);
    outline: none;
    box-shadow:
        0 8px 35px rgba(74, 31, 110, 0.5),
        0 0 30px var(--ai-gold-glow);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible; /* changed from hidden to allow tooltip */
    padding: 0;
    animation: divineFloat 4.5s ease-in-out infinite;
}

.ai-floating-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    position: relative;
    z-index: 2;
}

/* Tooltip on Hover */
.ai-floating-btn::before {
    content: "تحتاج التحدث معي؟"; /* Arabic tooltip */
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--ai-modal-bg);
    color: var(--ai-text);
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    border: 1px solid var(--ai-gold);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 10;
    pointer-events: none;
}

.ltr .ai-floating-btn::before {
   content: "Need to talk?";
}

.ai-floating-btn:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

@keyframes divineFloat {

    0%,
    100% {
        transform: translateY(0) scale(1);
        box-shadow:
            0 8px 35px rgba(74, 31, 110, 0.5),
            0 0 30px var(--ai-gold-glow);
    }

    50% {
        transform: translateY(-10px) scale(1.03);
        box-shadow:
            0 15px 45px rgba(74, 31, 110, 0.6),
            0 0 50px var(--ai-gold-glow);
    }
}

.ai-floating-btn:hover {
    transform: scale(1.15);
    box-shadow:
        0 15px 50px rgba(74, 31, 110, 0.7),
        0 0 60px var(--ai-gold-glow);
    animation-play-state: paused;
}

/* Pulse Ring Effect */
.ai-floating-btn .pulse-ring {
    position: absolute;
    top: -5px;
    left: -5px;
    width: calc(100% + 10px);
    height: calc(100% + 10px);
    border-radius: 50%;
    border: 2px solid var(--ai-accent);
    animation: divine-pulse 2.5s cubic-bezier(0.21, 0.47, 0.32, 0.98) infinite;
    z-index: 1;
}

@keyframes divine-pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* ============================================================
   RESPONSIVE STYLES - Mobile First
   ============================================================ */

/* Tablets */
@media (max-width: 1024px) {
    .ai-voice-container {
        width: 92%;
        max-width: 450px;
        padding: 45px 35px;
    }
}

/* Large Phones */
@media (max-width: 768px) {
    .ai-voice-container {
        width: 94%;
        padding: 40px 30px;
        border-radius: var(--ai-border-radius);
    }

    .ai-voice-header h3 {
        font-size: 24px;
    }

    .ai-voice-visualizer {
        height: 80px;
    }

    .ai-floating-btn {
        width: 75px;
        height: 75px;
    }
}

/* Small Phones */
@media (max-width: 480px) {
    .ai-voice-modal {
        align-items: flex-end;
        padding-bottom: 0;
    }

    .ai-voice-container {
        width: 100%;
        max-width: 100%;
        padding: 35px 20px 40px;
        border-radius: var(--ai-border-radius-lg) var(--ai-border-radius-lg) 0 0;
        max-height: 90vh;
        overflow-y: auto;
    }

    .ai-voice-header h3 {
        font-size: 20px;
        gap: 10px;
    }

    .ai-voice-header h3 img {
        width: 36px;
        height: 36px;
    }

    .ai-status {
        font-size: 14px;
        padding: 12px 20px;
        max-width: 100%;
    }

    .ai-voice-controls {
        flex-direction: column;
        gap: 12px;
    }

    .ai-voice-end-btn,
    .ai-voice-retry-btn {
        width: 100%;
        justify-content: center;
        min-height: var(--ai-touch-target);
        padding: 14px 25px;
    }

    .ai-floating-wrapper {
        bottom: 15px;
        right: 15px;
    }

    .ai-floating-btn {
        width: 65px;
        height: 65px;
    }

    .ai-floating-label {
        font-size: 11px;
        padding: 8px 14px;
    }

    .ai-voice-contact {
        font-size: 12px;
        padding: 12px 16px;
    }

    .ai-voice-visualizer {
        height: 70px;
        max-width: 100%;
    }
}

/* Touch-friendly interactions */
@media (hover: none) and (pointer: coarse) {

    .ai-voice-end-btn,
    .ai-voice-retry-btn,
    .ai-voice-close,
    .ai-floating-btn {
        min-height: var(--ai-touch-target);
        min-width: var(--ai-touch-target);
    }

    .ai-voice-end-btn:active,
    .ai-voice-retry-btn:active {
        transform: scale(0.98);
    }

    .ai-floating-btn:active {
        transform: scale(0.95);
    }
}

/* ============================================================
   RTL SUPPORT (Arabic)
   ============================================================ */
[dir="rtl"] .ai-floating-wrapper {
    right: auto;
    left: 25px;
}

[dir="rtl"] .ai-voice-close {
    right: auto;
    left: 15px;
}

[dir="rtl"] .ai-voice-container::before {
    left: 20px;
    right: auto;
}

[dir="rtl"] .ai-voice-container::after {
    right: 20px;
    left: auto;
}

[dir="rtl"] .ai-voice-controls {
    flex-direction: row-reverse;
}

@media (max-width: 480px) {
    [dir="rtl"] .ai-floating-wrapper {
        left: 15px;
    }

    [dir="rtl"] .ai-voice-controls {
        flex-direction: column;
    }
}

/* LTR Support (when switched from RTL) */
.ltr .ai-floating-wrapper {
    left: auto;
    right: 25px;
}

.ltr .ai-voice-close {
    left: auto;
    right: 15px;
}