/* ==========================================================================
   Keroshe Smart Assistant & Live Support
   Refined Modern UI - Clean, Minimalist, Native Experience
   ========================================================================== */

:root {
    --ka-primary: #2563eb;
    --ka-primary-hover: #1d4ed8;
    --ka-dark-header: #0f172a;
    --ka-card-bg: #ffffff;
    --ka-body-bg: #f8fafc;
    --ka-bot-bubble: #ffffff;
    --ka-bot-text: #1e293b;
    --ka-user-bubble: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --ka-user-text: #ffffff;
    --ka-border-color: #e2e8f0;
    --ka-chip-bg: #ffffff;
    --ka-chip-border: #cbd5e1;
    --ka-chip-hover-bg: #eff6ff;
    --ka-chip-hover-border: #3b82f6;
    --ka-shadow: 0 20px 45px -12px rgba(15, 23, 42, 0.22), 0 0 1px 1px rgba(15, 23, 42, 0.06);
}

/* 1. Floating Trigger Button */
.keroshe-assistant-trigger {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9998;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #0f172a;
    color: #ffffff;
    padding: 8px 16px 8px 12px;
    border-radius: 30px;
    box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.3), 0 0 1px rgba(255, 255, 255, 0.15) inset;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
    direction: rtl;
    user-select: none;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    text-decoration: none;
}

.keroshe-assistant-trigger:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 14px 30px -6px rgba(15, 23, 42, 0.4);
    background: #1e293b;
    color: #ffffff;
}

.keroshe-assistant-trigger:active {
    transform: translateY(0) scale(0.98);
}

.keroshe-assistant-trigger .ka-trigger-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: right;
    line-height: 1.35;
}

.keroshe-assistant-trigger .ka-text-main {
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: -0.2px;
}

.keroshe-assistant-trigger .ka-text-sub {
    font-size: 11px;
    font-weight: 500;
    color: #94a3b8;
}

.keroshe-assistant-trigger .ka-trigger-icon {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    color: #ffffff;
    flex-shrink: 0;
}

.keroshe-assistant-trigger .ka-trigger-icon svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.keroshe-assistant-trigger .ka-pulse-dot {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    border: 1.5px solid #0f172a;
    box-shadow: 0 0 6px #10b981;
    animation: kaPulse 2s infinite ease-in-out;
}

@keyframes kaPulse {
    0% { transform: scale(0.9); opacity: 0.8; }
    50% { transform: scale(1.25); opacity: 1; box-shadow: 0 0 8px #10b981; }
    100% { transform: scale(0.9); opacity: 0.8; }
}

/* 2. Main Chat Window */
.keroshe-assistant-modal {
    position: fixed;
    bottom: 84px;
    left: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 105px);
    background: var(--ka-card-bg);
    border-radius: 20px;
    box-shadow: var(--ka-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    direction: rtl;
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, sans-serif;
    border: 1px solid rgba(226, 232, 240, 0.9);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom left;
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.keroshe-assistant-modal.ka-active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.ka-modal-header {
    background: var(--ka-dark-header);
    color: #ffffff;
    padding: 13px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ka-header-info {
    display: flex;
    align-items: center;
    gap: 11px;
}

.ka-avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.ka-avatar svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.ka-avatar .ka-online-badge {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    background-color: #10b981;
    border-radius: 50%;
    border: 1.5px solid var(--ka-dark-header);
}

.ka-header-text {
    display: flex;
    flex-direction: column;
}

.ka-title {
    font-size: 13.5px;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
    line-height: 1.4;
}

.ka-status {
    font-size: 11px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.25;
    margin-top: 2px;
}

.ka-status-indicator {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
}

.ka-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ka-btn-icon {
    background: transparent;
    border: none;
    color: #94a3b8;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
}

.ka-btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.ka-btn-icon svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

/* Chat Body */
.ka-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--ka-body-bg);
    scroll-behavior: smooth;
}

.ka-modal-body::-webkit-scrollbar {
    width: 4px;
}
.ka-modal-body::-webkit-scrollbar-track {
    background: transparent;
}
.ka-modal-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 8px;
}

/* Message Groups */
.ka-msg-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 88%;
    animation: kaFadeIn 0.22s ease-out;
}

@keyframes kaFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.ka-msg-group.ka-bot {
    align-self: flex-start;
}

.ka-msg-group.ka-user {
    align-self: flex-end;
}

.ka-msg-bubble {
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.65;
    word-break: break-word;
}

.ka-bot .ka-msg-bubble {
    background: var(--ka-bot-bubble);
    color: var(--ka-bot-text);
    border-radius: 14px 14px 14px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    border: 1px solid #e2e8f0;
}

.ka-user .ka-msg-bubble {
    background: var(--ka-user-bubble);
    color: var(--ka-user-text);
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.22);
}

.ka-msg-time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 1px;
    padding: 0 4px;
}

.ka-bot .ka-msg-time {
    align-self: flex-start;
}

.ka-user .ka-msg-time {
    align-self: flex-end;
}

/* Quick Action Chips */
.ka-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.ka-chip-btn {
    background: var(--ka-chip-bg);
    border: 1px solid var(--ka-chip-border);
    color: #1e3a8a;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s ease;
    text-align: right;
    line-height: 1.35;
    user-select: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.ka-chip-btn:hover {
    background: var(--ka-chip-hover-bg);
    border-color: var(--ka-chip-hover-border);
    color: var(--ka-primary);
    transform: translateY(-1px);
}

.ka-chip-btn:active {
    transform: translateY(0);
}

/* Typing Indicator */
.ka-typing-box {
    display: none;
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px 14px 14px 4px;
    padding: 9px 13px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    margin-bottom: 2px;
}

.ka-typing-box.ka-show {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    animation: kaFadeIn 0.2s ease-out;
}

.ka-typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: kaDotBounce 1.4s infinite ease-in-out both;
}

.ka-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ka-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes kaDotBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Footer & Input Area */
.ka-modal-footer {
    padding: 11px 14px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
}

.ka-input-form {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 24px;
    padding: 3px 5px 3px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ka-input-form:focus-within {
    border-color: var(--ka-primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.ka-input-field {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    color: #1e293b;
    direction: rtl;
}

.ka-input-field::placeholder {
    color: #94a3b8;
    font-size: 12.5px;
}

.ka-send-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ka-primary);
    border: none;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.18s, transform 0.15s;
    padding: 0;
}

.ka-send-btn:hover {
    background: var(--ka-primary-hover);
    transform: scale(1.04);
}

.ka-send-btn:active {
    transform: scale(0.96);
}

.ka-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

.ka-send-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    transform: rotate(180deg);
}

.ka-footer-note {
    text-align: center;
    font-size: 10.5px;
    color: #94a3b8;
    margin-top: 5px;
}

/* Direct Call Button inside Chat */
.ka-direct-call-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ef4444;
    color: #ffffff !important;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.25);
    margin: 6px 0;
}

.ka-direct-call-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* Mobile Optimizations */
@media (max-width: 480px) {
    .keroshe-assistant-trigger {
        bottom: 16px;
        left: 16px;
        padding: 6px 14px 6px 12px;
    }
    .keroshe-assistant-trigger .ka-text-main {
        font-size: 12.5px;
    }
    .keroshe-assistant-trigger .ka-text-sub {
        font-size: 10px;
    }
    .keroshe-assistant-modal {
        left: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 85vh;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        transform-origin: bottom center;
    }
}
