/* ================================================
   Ornament Chatbot Styles
   ================================================ */

.chatbot-widget {
    --primary-color: #c9a961;
    --secondary-color: #f5f5f5;
    --text-color: #333;
    --border-color: #ddd;
    --bot-bg: #f0f0f0;
    --user-bg: #e8d4b8;
    --hover-color: #b8934e;
    
    position: fixed;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    z-index: 9999;
}

/* Position variants */
.chatbot-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.chatbot-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

.chatbot-widget.top-right {
    top: 20px;
    right: 20px;
}

.chatbot-widget.top-left {
    top: 20px;
    left: 20px;
}

/* Toggle Button */
.chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--hover-color) 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
}

.chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chatbot-toggle:active {
    transform: scale(0.95);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff6b6b;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}

/* Chat Window */
.chatbot-window {
    display: none;
    position: absolute;
    bottom: 90px;
    right: 0;
    width: 400px;
    height: 600px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    animation: slideUp 0.3s ease;
    flex-direction: column;
}

.chatbot-widget.open .chatbot-window {
    display: flex;
}

.chatbot-widget.bottom-left .chatbot-window {
    right: auto;
    left: 0;
}

.chatbot-widget.top-right .chatbot-window {
    bottom: auto;
    top: 90px;
}

.chatbot-widget.top-left .chatbot-window {
    bottom: auto;
    top: 90px;
    right: auto;
    left: 0;
}

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

/* Header */
.chatbot-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--hover-color) 100%);
    color: white;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--primary-color);
}

.chat-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-subtitle {
    margin: 4px 0 0 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Chat Message */
.chat-message {
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: fadeIn 0.3s ease;
}

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

.chat-message.bot {
    align-items: flex-start;
}

.chat-message.user {
    align-items: flex-end;
}

/* Message Content */
.message-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

.chat-message.bot .message-content {
    background: var(--bot-bg);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

.chat-message.user .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Message Time */
.message-time {
    font-size: 11px;
    color: #999;
    padding: 0 4px;
}

/* Typing Indicator */
.chat-message.typing .message-content {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.5;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

/* Example Queries */
.example-queries {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.query-button {
    background: white;
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-color);
    text-align: left;
    transition: all 0.2s ease;
}

.query-button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateX(4px);
}

/* Ornament Results */
.ornament-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.ornament-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
}

.ornament-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.ornament-header strong {
    color: var(--primary-color);
    flex: 1;
}

.ornament-code {
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    color: #666;
}

.ornament-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
}

.detail-item .label {
    color: #999;
    font-weight: 500;
}

.detail-item .value {
    color: var(--text-color);
    font-weight: 600;
}

/* Input Area */
.chatbot-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: white;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.1);
}

.chat-input::placeholder {
    color: #ccc;
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 18px;
}

.send-button:hover {
    background: var(--hover-color);
    transform: scale(1.05);
}

.send-button:active {
    transform: scale(0.95);
}

/* ================================================
   Mobile Responsive — ≤ 480px
   Strategy: when .open, expand the fixed widget to cover the
   full viewport so the chat window can use plain position:absolute.
   This avoids all "fixed-inside-fixed" rendering quirks.
   ================================================ */
@media (max-width: 480px) {

    /* --- Closed state: keep toggle pinned to bottom-right --- */
    .chatbot-widget {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        right:  calc(10px + env(safe-area-inset-right,  0px)) !important;
        left: auto !important;
        top:  auto !important;
    }

    /* --- Open state: widget becomes a full-screen overlay --- */
    .chatbot-widget.open {
        top:    0 !important;
        left:   0 !important;
        right:  0 !important;
        bottom: 0 !important;
        width:  100% !important;
        height: 100% !important;
        background: rgba(0, 0, 0, 0.35);
    }

    /* Re-anchor toggle button inside the expanded overlay */
    .chatbot-widget.open .chatbot-toggle {
        position: absolute;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        right:  calc(10px + env(safe-area-inset-right,  0px));
        left: auto;
        top:  auto;
    }

    /* Chat panel fills the overlay, leaving room for the toggle button */
    .chatbot-window {
        position: absolute !important;
        top:    10px !important;
        left:   10px !important;
        right:  10px !important;
        bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
        width:  auto !important;
        height: auto !important;
        max-width:  none !important;
        max-height: none !important;
        border-radius: 20px;
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
    }

    /* Header */
    .chatbot-header {
        padding: 14px 16px;
        align-items: center;
        gap: 10px;
    }

    .chat-title    { font-size: 16px; }
    .chat-subtitle { font-size: 11px; line-height: 1.35; }

    /* Messages */
    .chatbot-messages {
        padding: 12px 14px;
        gap: 10px;
    }

    .message-content {
        max-width: 100%;
        font-size: 13px;
        line-height: 1.45;
    }

    .message-time { font-size: 10px; }

    /* Quick-reply buttons — 2 columns */
    .example-queries {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        margin-top: 8px;
    }

    .query-button {
        padding: 10px 8px;
        font-size: 11px;
        border-radius: 10px;
        min-height: 40px;
        text-align: center;
    }

    /* Ornament result cards */
    .ornament-card        { padding: 10px; }
    .ornament-header      { gap: 8px; align-items: flex-start; }
    .ornament-code        { white-space: nowrap; }
    .ornament-details     { grid-template-columns: 1fr; }

    /* Input bar */
    .chatbot-input-area {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        gap: 6px;
    }

    .chat-input {
        padding: 10px 14px;
        font-size: 13px;
    }

    .send-button {
        width:  42px;
        height: 42px;
        flex: 0 0 42px;
    }
}

/* Extra-small phones (≤ 380px): tighten margins, single-column buttons */
@media (max-width: 380px) {
    .chatbot-widget.open .chatbot-toggle {
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        right:  calc(8px + env(safe-area-inset-right,  0px));
    }

    .chatbot-window {
        top:    8px !important;
        left:   8px !important;
        right:  8px !important;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
        border-radius: 18px;
    }

    .example-queries { grid-template-columns: 1fr; }
    .chat-title      { font-size: 15px; }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .chatbot-widget {
        --bot-bg: #2a2a2a;
        --text-color: #e0e0e0;
        --border-color: #444;
        --secondary-color: #1a1a1a;
    }

    .chatbot-window {
        background: #1a1a1a;
        color: #e0e0e0;
    }

    .chatbot-messages {
        background: #0a0a0a;
    }

    .chat-input {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #444;
    }

    .query-button {
        background: #2a2a2a;
        color: #e0e0e0;
        border-color: #444;
    }

    .query-button:hover {
        background: var(--primary-color);
        color: white;
    }

    .ornament-card {
        background: #2a2a2a;
        border-color: #444;
    }

    .ornament-code {
        background: #333;
    }

    .chatbot-input-area {
        background: #1a1a1a;
        border-color: #444;
    }
}
