/**
 * Dimitra AI Widget Styles
 */

:root {
    --dimitra-primary: #2563eb;
    --dimitra-primary-dark: #1d4ed8;
    --dimitra-bg: #ffffff;
    --dimitra-text: #1f2937;
    --dimitra-text-light: #6b7280;
    --dimitra-border: #e5e7eb;
    --dimitra-user-bg: var(--dimitra-primary);
    --dimitra-user-text: #ffffff;
    --dimitra-bot-bg: #f3f4f6;
    --dimitra-bot-text: #1f2937;
    --dimitra-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    --dimitra-radius: 16px;
}

/* Reset */
.dimitra-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Widget Container */
.dimitra-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.dimitra-bottom-right {
    bottom: 20px;
    right: 20px;
}

.dimitra-bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chat Button */
.dimitra-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--dimitra-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--dimitra-shadow);
    transition: all 0.3s ease;
}

.dimitra-chat-button:hover {
    transform: scale(1.05);
    background: var(--dimitra-primary-dark);
}

.dimitra-chat-button svg {
    width: 28px;
    height: 28px;
    color: white;
}

.dimitra-chat-button .dimitra-icon-close {
    display: none;
}

.dimitra-widget.open .dimitra-chat-button .dimitra-icon-chat {
    display: none;
}

.dimitra-widget.open .dimitra-chat-button .dimitra-icon-close {
    display: block;
}

/* Chat Window */
.dimitra-chat-window {
    position: absolute;
    bottom: 75px;
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 100px);
    background: var(--dimitra-bg);
    border-radius: var(--dimitra-radius);
    box-shadow: var(--dimitra-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.dimitra-bottom-right .dimitra-chat-window {
    right: 0;
}

.dimitra-bottom-left .dimitra-chat-window {
    left: 0;
}

.dimitra-widget.open .dimitra-chat-window {
    display: flex;
    animation: dimitra-slide-up 0.3s ease;
}

@keyframes dimitra-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.dimitra-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--dimitra-primary);
    color: white;
}

.dimitra-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dimitra-bot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.dimitra-bot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.dimitra-bot-avatar svg {
    width: 24px;
    height: 24px;
}

.dimitra-bot-name {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.dimitra-bot-status {
    font-size: 12px;
    opacity: 0.9;
}

.dimitra-header-buttons {
    display: flex;
    gap: 8px;
}

.dimitra-header-button {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.dimitra-header-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.dimitra-header-button svg {
    width: 18px;
    height: 18px;
    color: white;
}

/* Messages Area */
.dimitra-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message Bubbles */
.dimitra-message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    animation: dimitra-fade-in 0.3s ease;
}

@keyframes dimitra-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dimitra-message.user {
    align-self: flex-end;
}

.dimitra-message.bot {
    align-self: flex-start;
}

.dimitra-message-content {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.dimitra-message.user .dimitra-message-content {
    background: var(--dimitra-user-bg);
    color: var(--dimitra-user-text);
    border-bottom-right-radius: 4px;
}

.dimitra-message.bot .dimitra-message-content {
    background: var(--dimitra-bot-bg);
    color: var(--dimitra-bot-text);
    border-bottom-left-radius: 4px;
}

.dimitra-message-time {
    font-size: 11px;
    color: var(--dimitra-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.dimitra-message.user .dimitra-message-time {
    text-align: right;
}

/* Typing Indicator */
.dimitra-typing {
    display: flex;
    gap: 4px;
    padding: 16px;
    background: var(--dimitra-bot-bg);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.dimitra-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--dimitra-text-light);
    border-radius: 50%;
    animation: dimitra-bounce 1.4s infinite ease-in-out both;
}

.dimitra-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dimitra-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes dimitra-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Product Cards */
.dimitra-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.dimitra-product-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: white;
    border: 1px solid var(--dimitra-border);
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.2s;
}

.dimitra-product-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.dimitra-product-image {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--dimitra-bot-bg);
}

.dimitra-product-info {
    flex: 1;
    min-width: 0;
}

.dimitra-product-name {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dimitra-product-price {
    font-weight: 700;
    color: var(--dimitra-primary);
}

.dimitra-product-stock {
    font-size: 11px;
    color: var(--dimitra-text-light);
}

.dimitra-product-stock.in-stock {
    color: #10b981;
}

.dimitra-product-stock.out-of-stock {
    color: #ef4444;
}

/* Quick Replies */
.dimitra-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}

.dimitra-quick-replies:empty {
    display: none;
}

.dimitra-quick-reply {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--dimitra-primary);
    border-radius: 20px;
    color: var(--dimitra-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.dimitra-quick-reply:hover {
    background: var(--dimitra-primary);
    color: white;
}

/* Input Area */
.dimitra-chat-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--dimitra-border);
    background: var(--dimitra-bg);
}

.dimitra-chat-input textarea {
    flex: 1;
    border: 1px solid var(--dimitra-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.2s;
}

.dimitra-chat-input textarea:focus {
    border-color: var(--dimitra-primary);
}

.dimitra-send-button {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--dimitra-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.dimitra-send-button:hover {
    background: var(--dimitra-primary-dark);
}

.dimitra-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dimitra-send-button svg {
    width: 20px;
    height: 20px;
    color: white;
}

/* Powered By */
.dimitra-powered-by {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: var(--dimitra-text-light);
    background: var(--dimitra-bg);
}

/* ===========================================
   RESPONSIVE DESIGN
   - Desktop: > 1024px (default styles above)
   - Tablet: 768px - 1024px
   - Mobile: < 768px
   =========================================== */

/* Tablet Responsive */
@media (max-width: 1024px) and (min-width: 768px) {
    .dimitra-chat-window {
        width: 350px;
        height: 500px;
    }

    .dimitra-chat-button {
        width: 56px;
        height: 56px;
    }

    .dimitra-chat-button svg {
        width: 26px;
        height: 26px;
    }

    .dimitra-message-content {
        padding: 10px 14px;
    }

    .dimitra-product-card {
        padding: 10px;
    }

    .dimitra-product-image {
        width: 50px;
        height: 50px;
    }
}

/* Mobile Responsive - Fullscreen chat */
@media (max-width: 767px) {
    .dimitra-widget {
        bottom: 16px;
        right: 16px;
    }

    .dimitra-bottom-left {
        left: 16px;
        right: auto;
    }

    .dimitra-chat-button {
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }

    .dimitra-chat-button svg {
        width: 26px;
        height: 26px;
    }

    /* Fullscreen chat window on mobile */
    .dimitra-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 9999999;
    }

    .dimitra-widget.open .dimitra-chat-window {
        animation: dimitra-slide-up-mobile 0.3s ease;
    }

    @keyframes dimitra-slide-up-mobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Hide chat button when open on mobile */
    .dimitra-widget.open .dimitra-chat-button {
        display: none;
    }

    /* Header adjustments for mobile */
    .dimitra-chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .dimitra-bot-avatar {
        width: 36px;
        height: 36px;
    }

    .dimitra-bot-name {
        font-size: 15px;
    }

    /* Messages area with safe areas */
    .dimitra-messages {
        padding: 12px;
        padding-bottom: 8px;
    }

    .dimitra-message {
        max-width: 90%;
    }

    .dimitra-message-content {
        padding: 10px 14px;
        font-size: 15px;
    }

    /* Input area with safe areas */
    .dimitra-chat-input {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .dimitra-chat-input textarea {
        padding: 10px 14px;
        font-size: 16px; /* Prevents iOS zoom */
    }

    .dimitra-send-button {
        width: 44px;
        height: 44px;
    }

    /* Quick replies - horizontal scroll on mobile */
    .dimitra-quick-replies {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding: 8px 12px;
    }

    .dimitra-quick-replies::-webkit-scrollbar {
        display: none;
    }

    .dimitra-quick-reply {
        flex-shrink: 0;
        padding: 10px 16px;
        font-size: 14px;
    }

    /* Product cards - stacked layout */
    .dimitra-product-card {
        padding: 10px;
    }

    .dimitra-product-image {
        width: 55px;
        height: 55px;
    }

    .dimitra-product-name {
        font-size: 14px;
    }

    /* Powered by */
    .dimitra-powered-by {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
}

/* Extra small devices (small phones) */
@media (max-width: 374px) {
    .dimitra-widget {
        bottom: 12px;
        right: 12px;
    }

    .dimitra-bottom-left {
        left: 12px;
    }

    .dimitra-chat-button {
        width: 50px;
        height: 50px;
    }

    .dimitra-chat-button svg {
        width: 24px;
        height: 24px;
    }

    .dimitra-message-content {
        padding: 8px 12px;
        font-size: 14px;
    }

    .dimitra-quick-reply {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 767px) and (orientation: landscape) {
    .dimitra-chat-window {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .dimitra-chat-header {
        width: 100%;
        padding: 8px 16px;
    }

    .dimitra-messages {
        flex: 1;
        height: calc(100% - 120px);
    }

    .dimitra-chat-input {
        width: 100%;
    }

    .dimitra-quick-replies {
        width: 100%;
    }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
    .dimitra-chat-button:hover {
        transform: none;
        background: var(--dimitra-primary);
    }

    .dimitra-chat-button:active {
        transform: scale(0.95);
        background: var(--dimitra-primary-dark);
    }

    .dimitra-quick-reply:hover {
        background: white;
        color: var(--dimitra-primary);
    }

    .dimitra-quick-reply:active {
        background: var(--dimitra-primary);
        color: white;
    }

    .dimitra-send-button:hover {
        background: var(--dimitra-primary);
    }

    .dimitra-send-button:active {
        background: var(--dimitra-primary-dark);
    }

    .dimitra-product-card:hover {
        box-shadow: none;
    }

    .dimitra-product-card:active {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        background: #f9fafb;
    }

    .dimitra-header-button:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    .dimitra-header-button:active {
        background: rgba(255, 255, 255, 0.4);
    }
}
