/* Main Variables & Reset */
:root {
    --ai-primary: #4ca1af;
    --ai-primary-gradient: linear-gradient(135deg, #4ca1af 0%, #357ABD 100%);
    --ai-secondary: #2C3E50;
    --ai-accent: #00D2D3;
    --ai-bg: #F5F7FA;
    --ai-surface: #FFFFFF;
    --ai-text-main: #2C3E50;
    --ai-text-muted: #7F8C8D;
    --ai-border: #E1E8ED;
    --ai-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --ai-radius-lg: 16px;
    --ai-radius-md: 12px;
    --ai-radius-sm: 8px;
    --ai-danger: #ef4444;
    --ai-danger-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

/* Container Adjustments */
.ai-chat-container {
    background-color: var(--ai-bg);
    min-height: calc(100vh - 150px); /* Adjust based on header/footer height */
    padding: 20px 0;
    display: flex;
    flex-direction: column;
}

.ai-chat-container .container {
    max-width: 1000px; /* Optimal reading width */
    height: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Header Section */
.ai-chat-header {
    background: var(--ai-surface);
    padding: 20px;
    border-radius: var(--ai-radius-lg);
    box-shadow: var(--ai-shadow);
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    border: 1px solid white;
}

.ai-header-icon {
    width: 60px;
    height: 60px;
    background: var(--ai-primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3);
}

.ai-header-text h1 {
    font-size: 1.5rem;
    color: var(--ai-text-main);
    margin: 0 0 5px 0;
    font-weight: 700;
}

.ai-header-text p {
    margin: 0;
    color: var(--ai-text-muted);
    font-size: 1.2rem;
}

/* Chat Box Area */
.ai-chat-box {
    background: var(--ai-surface);
    border-radius: var(--ai-radius-lg);
    box-shadow: var(--ai-shadow);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 1px solid white;
    /* Determine height dynamically */
    height: 65vh;
}

/* Messages Area */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.ai-message {
    display: flex;
    gap: 15px;
    max-width: 85%;
    animation: slideIn 0.3s ease-out;
}

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

.ai-message.bot {
    align-self: flex-start;
}

.ai-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-message-avatar {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.ai-message.bot .ai-message-avatar {
    background: var(--ai-primary-gradient);
}

.ai-message.user .ai-message-avatar {
    background: linear-gradient(135deg, #1abc9c 0%, #16a085 100%);
}

.ai-message-content {
    padding: 16px 20px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-break: break-word;
}

.ai-message.bot .ai-message-content {
    background: #F8F9FA;
    color: var(--ai-text-main);
    border-top-left-radius: 4px;
    border: 1px solid var(--ai-border);
}

.ai-message.user .ai-message-content {
    background: var(--ai-primary-gradient);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.2);
}

.ai-message-content p {
    margin-bottom: 10px;
}

.ai-message-content p:last-of-type {
    margin-bottom: 0;
}

/* Hints/Suggestions */
.ai-hint {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(0,0,0,0.05);
    font-size: 1.1rem;
    color: var(--ai-text-muted);
}

.ai-hint strong {
    color: var(--ai-primary);
    display: block;
    margin-bottom: 5px;
}

/* Book/Result Cards */
.ai-book-list-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    margin-top: 20px;
    width: 100%;
}

.ai-book-list-container .modern-list-item {
    margin: 0;
}

.book-list-card {
    background: var(--ai-surface);
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius-md);
    padding: 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: all 0.2s ease;
}

.book-list-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
    border-color: var(--ai-primary);
}

.book-list-header {
    border-bottom: 1px solid var(--ai-bg);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.list-book-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 5px;
    line-height: 1.4;
}

.list-book-title a {
    color: var(--ai-text-main);
    text-decoration: none;
    transition: color 0.2s;
}

.list-book-title a:hover {
    color: var(--ai-primary);
}

.list-arabic-title {
    font-family: 'Amiri', 'Traditional Arabic', serif;
    color: var(--ai-text-muted);
    font-size: 1.2rem;
    margin: 5px 0 0;
    text-align: right;
    direction: rtl;
}

.book-list-meta {
    font-size: 0.9rem;
    flex: 1;
}

.meta-row {
    display: flex;
    align-items: flex-start; /* Aligns icons with first line of text */
    margin-bottom: 6px;
    color: #636e72;
}

.meta-col {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.meta-col i {
    color: var(--ai-primary);
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

.book-list-footer {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--ai-bg);
    text-align: right;
}

.book-list-footer .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--ai-bg);
    color: var(--ai-text-main);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.book-list-footer .btn:hover {
    background: var(--ai-primary);
    color: white;
}

/* Typing Indicator */
.ai-typing {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 10px 25px;
    opacity: 0.8;
}

.ai-typing-dots {
    background: #E8EEF2;
    padding: 12px 18px;
    border-radius: 20px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 5px;
}

.ai-typing-dots span {
    width: 8px;
    height: 8px;
    background: #95A5A6;
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}

.ai-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-8px); }
}

/* Input Area */
.ai-input-area {
    background: white;
    padding: 20px;
    border-top: 1px solid var(--ai-bg);
    border-radius: 0 0 var(--ai-radius-lg) var(--ai-radius-lg);
}

.ai-input-wrapper {
    display: flex;
    gap: 15px;
    position: relative;
    background: white;
    border: 2px solid var(--ai-border);
    border-radius: 30px;
    padding: 5px;
    transition: all 0.3s ease;
}

.ai-input-wrapper:focus-within {
    border-color: var(--ai-primary);
    box-shadow: 0 0 0 4px rgba(74, 144, 226, 0.1);
}

.ai-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 12px 20px;
    font-size: 1.5rem;
    outline: none;
    color: var(--ai-text-main);
}

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

.ai-send-btn:hover:not(:disabled) {
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.4);
}

.ai-send-btn:disabled {
    opacity: 0.6;
    cursor: default;
    background: var(--ai-text-muted);
}

.ai-input-hint {
    text-align: center;
    font-size: 1.1rem;
    color: var(--ai-text-muted);
    margin-top: 10px;
}

.ai-clear-btn {
    background: var(--ai-danger-gradient) !important;
    margin-right: 8px;
}

.ai-clear-btn:hover:not(:disabled) {
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
    filter: brightness(1.1);
}

/* Error State */
.ai-error .ai-message-content {
    background: #FEE2E2 !important;
    color: #D63031 !important;
    border: 1px solid #FAB1A0;
}

/* Scrollbar Styling */
.ai-messages::-webkit-scrollbar {
    width: 6px;
}

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

.ai-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 10px;
}

.ai-messages::-webkit-scrollbar-thumb:hover {
    background: #9CA3AF;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .ai-chat-container {
        padding: 0; /* Full width on mobile */
        height: calc(100vh - 120px); /* Adjust dynamically */
        min-height: auto;
    }

    .ai-chat-container .container {
        padding: 0;
        max-width: 100%;
    }

    .ai-chat-header {
        border-radius: 0;
        margin-bottom: 0;
        padding: 15px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .ai-header-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .ai-header-text h1 {
        font-size: 1.5rem;
    }

    .ai-header-text p {
        font-size: 1.2rem; /* Simplify header on mobile */
    }

    .ai-chat-box {
        border-radius: 0;
        height: auto;
        flex: 1;
        box-shadow: none;
        border: none;
        background: var(--ai-bg);
    }
    
    .ai-messages {
        padding: 15px 15px 0 15px;
    }

    .ai-message {
        max-width: 90%;
    }

    .ai-message-content {
        padding: 12px 16px;
        font-size: 14px;
    }

    .ai-book-list-container {
        grid-template-columns: 1fr; /* Stack cards on mobile */
    }

    .ai-input-area {
        position: sticky;
        bottom: 0;
        padding: 10px 15px 15px 15px;
        border-top: 1px solid #E1E8ED;
        border-radius: 0;
        z-index: 10;
    }

    .ai-input-hint {
        font-size: 1.1rem;
        margin-top: 10px;
        margin-bottom: 10px;
    }


    /* Adjust modal z-index if overlaying */
}

/* Custom Modal Styles */
.ai-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.ai-modal {
    background: white;
    width: 90%;
    max-width: 400px;
    border-radius: var(--ai-radius-lg);
    padding: 30px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transform: translateY(0);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-modal-icon {
    width: 60px;
    height: 60px;
    background: #FEE2E2;
    color: var(--ai-danger);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: 20px;
}

.ai-modal-content h3 {
    margin: 0 0 10px 0;
    color: var(--ai-text-main);
    font-size: 1.25rem;
}

.ai-modal-content p {
    margin: 0 0 25px 0;
    color: var(--ai-text-muted);
    line-height: 1.5;
}

.ai-modal-actions {
    display: flex;
    gap: 15px;
    width: 100%;
}

.ai-modal-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: var(--ai-radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.ai-btn-secondary {
    background: #F3F4F6;
    color: var(--ai-text-main);
}

.ai-btn-secondary:hover {
    background: #E5E7EB;
}

.ai-btn-danger {
    background: var(--ai-danger);
    color: white;
}

.ai-btn-danger:hover {
    background: #dc2626;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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