/* === Root variables === */
#ires-chat-root {
    /* Color Palette */
    --color-blue: #0d6efd;
    --color-blue-dark: #0b5ed7;
    --color-gray-light: #f8f9fa;
    --color-gray: #ddd;
    --color-gray-dark: #888;
    --color-white: #ffffff;
    --color-black: #000000;
    --ires-green: #67b516;
    --ires-blue: #1667b5;

    /* Spacing & Radii */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 0.75rem;
    --space-lg: 1rem;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    /* Dynamic Layout Variables (Controls states without !important) */
    --panel-pos: fixed;
    --panel-bottom: 5.5em;
    --panel-right: 1em;
    --panel-top: auto;
    --panel-left: auto;
    --panel-width: 380px;
    --panel-height: 560px;
    --panel-max-w: 80vw;
    --panel-max-h: 80vh;
    --panel-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    --panel-radius: var(--radius-lg);
    --panel-margin: 0 0 0 0.5em;

    font-family: "Roboto", sans-serif;
    font-size: 16px;
    position: relative;

    /* Global Box Sizing */
    & * {
        box-sizing: border-box;
        font-family: inherit;
    }
}

/* === Chat Button (Widget Toggle) === */
#ires-chat-root .ires-chat-button {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1050;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    background: var(--ires-blue);
    border: 1px solid var(--ires-blue);
    color: var(--ires-blue);
    cursor: pointer;
    transition: all 0.2s;

    &:hover {
        background: var(--ires-green);
        border-color: var(--ires-green);
    }

    & .chatIcon {
        width: 40px;
    }
}

/* === Main Chat Panel === */
#ires-chat-root .ires-chat-panel {
    display: none;
    /* Controlled by JS */
    z-index: 1040;
    position: var(--panel-pos);
    inset: var(--panel-top) var(--panel-right) var(--panel-bottom) var(--panel-left);
    width: var(--panel-width);
    height: var(--panel-height);
    max-width: var(--panel-max-w);
    max-height: var(--panel-max-h);
}

/* === Panel States (Embed & Fullscreen) === */
#ires-chat-root .ires-chat-panel {

    /* Embed Mode Overrides */
    &.ires-embed {
        --panel-pos: relative;
        --panel-top: auto;
        --panel-right: auto;
        --panel-bottom: auto;
        --panel-left: auto;
        --panel-width: 100%;
        --panel-max-w: 80em;
        --panel-shadow: none;
        --panel-margin: 0;
        display: block;

        /* Mobile adaptation for Embed */
        @media (max-width: 600px) {
            --panel-pos: fixed;
            --panel-top: 0;
            --panel-right: 0;
            --panel-bottom: 0;
            --panel-left: 0;
            --panel-width: 100vw;
            --panel-height: 100vh;
            --panel-max-w: none;
            --panel-max-h: none;
            --panel-radius: 0;
            z-index: 99999;
        }
    }

    /* Fullscreen Mode Overrides */
    &.ires-fullscreen {
        --panel-pos: fixed;
        --panel-top: 0;
        --panel-right: 0;
        --panel-bottom: 0;
        --panel-left: 0;
        --panel-width: 100vw;
        --panel-height: 100vh;
        --panel-max-w: none;
        --panel-max-h: none;
        --panel-radius: 0;
        --panel-margin: 0;
        z-index: 99999;
    }
}

/* === Chat Card Structure === */
#ires-chat-root .ires-chat-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--color-white);
    border: 1px solid var(--color-gray);
    overflow: hidden;

    /* Variables applied here */
    border-radius: var(--panel-radius);
    box-shadow: var(--panel-shadow);
    margin: var(--panel-margin);
}

/* === Header === */
#ires-chat-root .ires-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    background: var(--color-white);
    border-bottom: 1px solid var(--color-gray);

    & .ires-chat-controls {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
    }

    & .ires-chat-logo {
        width: 24px;
        height: 24px;
        object-fit: contain;
        margin-right: var(--space-sm);
    }

    & .ires-chat-header-title {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
        color: var(--ires-green);
        text-shadow: 0.5px 0.5px var(--color-gray-dark);
    }
}

/* === Interactive Elements (Buttons/Inputs) === */
#ires-chat-root {
    & .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius-sm);
        padding: var(--space-sm) var(--space-md);
        cursor: pointer;
        border: 1px solid transparent;
        background: var(--color-white);
        color: #333;
        transition: all 0.2s;

        &:hover {
            background: #f2f2f2;
        }
    }

    & .btn-outline-danger {
        border-color: #c00;
        color: #c00;

        &:hover {
            background: #fee;
        }
    }

    & .btn-primary {
        background: var(--ires-green);
        color: var(--color-white);
        border-color: var(--ires-green);

        &:hover {
            background: var(--ires-blue);
            border-color: var(--ires-blue);
        }
    }

    & .btn-close {
        width: 1em;
        height: 1em;
        padding: .25em;
        background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414'/%3e%3c/svg%3e") center/1em auto no-repeat;
        border: 0;
        opacity: 0.5;

        &:hover {
            opacity: 0.75;
        }
    }

    & .ires-fullscreen-btn {
        background: transparent;
        border: none;
        padding: 0;
        cursor: pointer;
        font-size: 1.2rem;
        opacity: 0.5;
        display: flex;
        align-items: center;

        &:hover {
            opacity: 0.75;
        }
    }

    & .form-control {
        flex: 1;
        border-radius: var(--radius-sm);
        border: 1px solid #ccc;
        padding: var(--space-sm) var(--space-md);
        font-size: 0.9rem;

        @media (max-width: 600px) {
            font-size: 16px;
            /* Prevents iOS zoom-on-focus */
        }
    }
}

/* === Chat Body & Messages === */
#ires-chat-root .ires-chat-body {
    padding: var(--space-md);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-white);

    & .ires-chat-messages {
        display: flex;
        flex: 1;
        flex-direction: column;
        overflow-y: auto;
        gap: var(--space-sm);
    }
}

#ires-chat-root .chat-msg {
    max-width: 80%;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    line-height: 1.4;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;

    &.bot {
        align-self: flex-start;
        background: #e9ecef;
        color: #111;
        border-top-left-radius: 0;
    }

    &.human {
        align-self: flex-end;
        background: var(--ires-blue);
        color: var(--color-white);
        border-top-right-radius: 0;
    }
}

/* === Footer === */
#ires-chat-root .card-footer {
    padding: var(--space-md) var(--space-lg);
    background: var(--color-gray-light);
    border-top: 1px solid var(--color-gray-light);

    & #iresChatForm {
        display: flex;
        align-items: flex-start;
        gap: var(--space-sm);
    }
}

/* === Animations === */
@keyframes typingPulse {

    0%,
    80%,
    100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

#ires-chat-root .bot-typing-indicator {
    display: none;
    align-items: center;
    gap: 0.3rem;
    background: #e9ecef;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    border-top-left-radius: 0;
    width: fit-content;

    & span {
        width: 6px;
        height: 6px;
        background-color: #555;
        border-radius: 50%;
        animation: typingPulse 1.5s infinite ease-in-out;

        &:nth-child(2) {
            animation-delay: 0.2s;
        }

        &:nth-child(3) {
            animation-delay: 0.4s;
        }
    }
}