/*
 * Shalizar AI Widget — Frontend CSS
 * Scoped: only affects elements inside #shalizar-ai-widget-root
 * Mirrors CRM PublicAiWidget styling.
 */

#shalizar-ai-widget-root {
    font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    direction: rtl;
    text-align: right;
    --shalizar-offset-x: 24px;
    --shalizar-offset-y: 24px;
}

/* ===== Launcher ===== */

#shalizar-ai-launcher.shalizar-ai-launcher {
    position: fixed;
    bottom: var(--shalizar-offset-y);
    right: var(--shalizar-offset-x);
    z-index: 999999;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 9999px;
    background-color: var(--shalizar-button-color, #000000);
    color: var(--shalizar-icon-color, #ffffff);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    user-select: none;
    box-sizing: border-box;
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

/* Direction modifiers set by widget.js */
#shalizar-ai-widget-root.shalizar-ai-pos-bottom-left #shalizar-ai-launcher {
    right: auto;
    left: var(--shalizar-offset-x);
}

#shalizar-ai-widget-root.shalizar-ai-pos-bottom-left .shalizar-ai-tooltip {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

#shalizar-ai-launcher.shalizar-ai-launcher:hover {
    transform: scale(1.06);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

#shalizar-ai-launcher.shalizar-ai-launcher:focus-visible {
    outline: 3px solid #3b82f6;
    outline-offset: 3px;
}

/* While the popup is open the launcher is hidden (it sits under the popup).
   widget.js also sets an inline display:none, this rule covers the case
   where only the class is present. */
#shalizar-ai-launcher.shalizar-ai-hidden,
#shalizar-ai-widget-root #shalizar-ai-launcher.shalizar-ai-hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ===== Icon ===== */

.shalizar-ai-launcher .shalizar-ai-icon {
    width: 55%;
    height: 55%;
    display: block;
    /* The icon is a line (stroke) drawing: filling it would merge the shape. */
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

/* ===== Tooltip ===== */

.shalizar-ai-launcher .shalizar-ai-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 50%;
    transform: translateX(50%);
    padding: 6px 12px;
    border-radius: 8px;
    background-color: #111827;
    color: #ffffff;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

#shalizar-ai-launcher.shalizar-ai-launcher:hover .shalizar-ai-tooltip,
#shalizar-ai-launcher.shalizar-ai-launcher:focus-visible .shalizar-ai-tooltip {
    opacity: 1;
    visibility: visible;
}

/* ===== Popup ===== */

#shalizar-ai-popup.shalizar-ai-popup {
    position: fixed;
    bottom: calc(var(--shalizar-offset-y) + 72px);
    right: var(--shalizar-offset-x);
    z-index: 999998;
    display: none;
    flex-direction: column;
    width: 380px;
    height: min(620px, 75vh);
    max-width: calc(100vw - 32px);
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
    box-sizing: border-box;
}

#shalizar-ai-popup.shalizar-ai-visible {
    animation: shalizar-ai-popup-in 0.22s ease both;
}

#shalizar-ai-widget-root.shalizar-ai-pos-bottom-left #shalizar-ai-popup {
    right: auto;
    left: var(--shalizar-offset-x);
}

@keyframes shalizar-ai-popup-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===== Header ===== */

.shalizar-ai-popup__header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background-color: var(--shalizar-header-color, #000000);
    color: #ffffff;
}

.shalizar-ai-popup__title {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shalizar-ai-popup__actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 4px;
}

.shalizar-ai-popup__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    cursor: pointer;
    transition: background 0.15s ease;
}

.shalizar-ai-popup__btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.shalizar-ai-popup__btn:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* ===== Body / iframe ===== */

.shalizar-ai-popup__body {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #f4f6f9;
}

#shalizar-ai-frame.shalizar-ai-popup__frame {
    display: block;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: none;
    background: #ffffff;
}

/* ===== Error / retry ===== */

#shalizar-ai-error.shalizar-ai-popup__error {
    display: none;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 240px;
    padding: 24px;
    text-align: center;
    font-size: 14px;
    color: #4b5563;
}

#shalizar-ai-error.shalizar-ai-popup__error p {
    margin: 0;
}

#shalizar-ai-retry {
    padding: 8px 18px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #ffffff;
    font-size: 13px;
    cursor: pointer;
}

#shalizar-ai-retry:hover {
    background: #f3f4f6;
}

/* ===== Mobile: full-width bottom sheet ===== */

@media (max-width: 640px) {
    #shalizar-ai-popup.shalizar-ai-popup {
        right: 8px;
        left: 8px;
        bottom: 8px;
        width: auto;
        max-width: none;
        height: min(85dvh, 640px);
    }
}

@media (prefers-reduced-motion: reduce) {
    #shalizar-ai-popup.shalizar-ai-visible {
        animation: none;
    }
}
