/* =========================================================
   AI CHAT WIDGET - YADAK DENA BRANDED STYLE
   ========================================================= */

:root {
    --yd-red: #d71920;
    --yd-red-hover: #b81319;
    --yd-dark: #121417;
    --yd-dark-surface: #1e2227;
    --yd-emerald: #16A34A;
    --yd-emerald-dark: #15803D;
    --yd-gray-bg: #f8fafc;
    --yd-border: #e2e8f0;
    --yd-text-main: #0f172a;
    --yd-text-muted: #64748b;
    --yd-font: 'Vazirmatn', 'IRANSans', system-ui, -apple-system, sans-serif;
}

.ai-chat-widget {
    position: fixed;
    right: 20px; /* Switched to left for RTL layout convention (or right: 20px) */
    bottom: 20px;
    z-index: 9999;
    direction: rtl;
    font-family: var(--yd-font);
}

/* =========================================================
   PROACTIVE TEASER CALLOUT
   ========================================================= */

.ai-chat-teaser {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 240px;
    background: #ffffff;
    border: 1px solid var(--yd-border);
    border-right: 4px solid var(--yd-red);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12);
    animation: teaserFloat 3s ease-in-out infinite;
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.ai-chat-teaser.is-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    pointer-events: none;
}

@keyframes teaserFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.ai-chat-teaser-close {
    position: absolute;
    top: 6px;
    left: 8px;
    background: transparent;
    border: none;
    color: var(--yd-text-muted);
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
}

.ai-chat-teaser-title {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--yd-red);
    margin-bottom: 2px;
}

.ai-chat-teaser-text {
    margin: 0;
    font-size: 12px;
    color: var(--yd-text-main);
    line-height: 1.4;
    font-weight: 500;
}

/* =========================================================
   TOGGLE BUTTON
   ========================================================= */

.ai-chat-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: var(--yd-dark);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-toggle:hover {
    transform: scale(1.06);
    background: var(--yd-dark-surface);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
}

.ai-chat-toggle-svg {
    width: 28px;
    height: 28px;
    transition: transform 0.2s ease;
}

.ai-chat-badge-dot {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 12px;
    height: 12px;
    background-color: var(--yd-red);
    border: 2px solid #ffffff;
    border-radius: 50%;
}

/* =========================================================
   CHAT PANEL CONTAINER
   ========================================================= */

.ai-chat-panel {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 370px;
    height: 500px;
    background: #ffffff;
    border: 1px solid var(--yd-border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.22);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(15px) scale(0.95);
    transform-origin: bottom right;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-chat-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* =========================================================
   HEADER
   ========================================================= */

.ai-chat-header {
    flex-shrink: 0;
    padding: 14px 18px;
    background: var(--yd-dark);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--yd-red);
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat-avatar-wrapper {
    position: relative;
}

.ai-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--yd-red) 0%, #990f14 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
}

.ai-chat-avatar svg {
    width: 22px;
    height: 22px;
}

.ai-chat-status-dot {
    position: absolute;
    bottom: 1px;
    left: 1px;
    width: 10px;
    height: 10px;
    background-color: #10b981;
    border: 2px solid var(--yd-dark);
    border-radius: 50%;
}

.ai-chat-title-group h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
}

.ai-chat-title-group span {
    display: block;
    margin-top: 2px;
    color: #94a3b8;
    font-size: 11px;
}

.ai-chat-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.ai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* =========================================================
   MESSAGES AREA
   ========================================================= */

.ai-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--yd-gray-bg);
}

.ai-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.ai-chat-bubble {
    padding: 11px 15px;
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

/* AI Message: Align Right (RTL context) */
.ai-chat-message-ai {
    align-self: flex-start;
}

.ai-chat-message-ai .ai-chat-bubble {
    background: #ffffff;
    color: var(--yd-text-main);
    border: 1px solid var(--yd-border);
    border-radius: 16px 16px 16px 4px; /* Distinct corner on right bottom */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

/* User Message: Align Left (RTL context) */
.ai-chat-message-user {
    align-self: flex-end;
}

.ai-chat-message-user .ai-chat-bubble {
    background: var(--yd-emerald);
    color: #ffffff;
    border-radius: 16px 16px 4px 16px; /* Distinct corner on left bottom */
}

.ai-chat-time {
    font-size: 10px;
    color: var(--yd-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.ai-chat-bubble p {
    margin: 0 0 10px;
}

.ai-chat-bubble p:last-child {
    margin-bottom: 0;
}

.ai-chat-bubble strong {
    font-weight: 700;
}

.ai-chat-bubble em {
    font-style: italic;
}

.ai-chat-bubble ul,
.ai-chat-bubble ol {
    margin: 8px 0;
    padding-right: 22px;
}

.ai-chat-bubble li {
    margin: 4px 0;
}

.ai-chat-bubble a {
    color: inherit;
    text-decoration: underline;
}

.ai-chat-bubble code {
    direction: ltr;
    unicode-bidi: isolate;
    font-family: monospace;
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 0.9em;
}

.ai-phone-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    text-decoration: none;
}

.ai-phone-link::before {
    content: "📞";
}
.ai-chat-message-ai .ai-chat-time { align-self: flex-start; }
.ai-chat-message-user .ai-chat-time { align-self: flex-end; }

/* =========================================================
   INPUT AREA
   ========================================================= */

.ai-chat-input-area {
    flex-shrink: 0;
    padding: 12px;
    background: #ffffff;
    border-top: 1px solid var(--yd-border);
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.ai-chat-input-area textarea {
    flex: 1;
    min-width: 0;
    min-height: 42px;
    max-height: 100px;
    padding: 10px 14px;
    resize: none;
    border: 1px solid var(--yd-border);
    border-radius: 12px;
    outline: none;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    color: var(--yd-text-main);
    background: #ffffff;
    transition: border-color 0.2s ease;
}

.ai-chat-input-area textarea:focus {
    border-color: var(--yd-emerald);
}

.ai-chat-input-area button {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: var(--yd-emerald);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.ai-chat-input-area button:hover {
    background: var(--yd-emerald-dark);
}

.ai-chat-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =========================================================
   RESPONSIVE MEDIA QUERIES
   ========================================================= */

/* Mobile Portrait & Small Screens */
@media (max-width: 640px) {
    .ai-chat-widget {
        left: 12px;
        bottom: 70px;
    }
}

@media (max-width: 480px) and (orientation: portrait) {
    .ai-chat-panel {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 80px;
        width: calc(100vw - 20px);
        height: min(580px, calc(100vh - 140px));
        border-radius: 16px;
    }

    .ai-chat-teaser {
        width: 210px;
    }
}

/* =========================================================
   MOBILE LANDSCAPE / SHORT SCREEN FIX
   ========================================================= */
@media (max-height: 500px) and (orientation: landscape), (max-width: 900px) and (orientation: landscape) {
    .ai-chat-widget {
        left: 12px;
        bottom: 12px;
    }

    .ai-chat-panel {
        position: fixed;
        top: 10px;
        bottom: 10px;
        left: 10px;
        right: 10px;
        width: auto;
        height: auto; /* Allow top and bottom offsets to dictate height */
        max-height: calc(100vh - 20px);
        border-radius: 12px;
        z-index: 10000;
    }

    /* Reduce header and padding sizes to maximize message area */
    .ai-chat-header {
        padding: 8px 12px;
    }

    .ai-chat-avatar {
        width: 32px;
        height: 32px;
    }

    .ai-chat-messages {
        padding: 10px;
        gap: 8px;
    }

    .ai-chat-bubble {
        padding: 8px 12px;
        font-size: 12px;
    }

    .ai-chat-input-area {
        padding: 6px 10px;
    }

    .ai-chat-input-area textarea {
        min-height: 36px;
        padding: 6px 10px;
    }

    .ai-chat-input-area button {
        width: 36px;
        height: 36px;
    }

    /* Hide teaser popup in landscape to prevent screen clutter */
    .ai-chat-teaser {
        display: none !important;
    }
}

/* Input font-size lock to prevent iOS auto-zoom on input focus */
input,
textarea,
select {
    font-size: 16px;
}