﻿/* --- General & Layout --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100vh; width: 100vw; font-family: 'Vazirmatn', Arial, sans-serif; background-color: #f0f2f5; overflow: hidden; }

.screen { display: none; height: 100%; width: 100%; flex-direction: column; }
.screen.active { display: flex; }

.main-layout { display: flex; width: 100%; height: 100%; position: relative; }

/* --- Login Screen --- */
.login-container { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #5b21b6 0%, #312e81 100%); }
.login-box { background: white; padding: 3rem; border-radius: 20px; box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2); width: 90%; max-width: 400px; text-align: center; }
.welcome-title { color: #333; margin-bottom: 1rem; font-size: 1.8rem; }
.welcome-text { color: #666; margin-bottom: 2rem; }
#loginForm input { width: 100%; padding: 0.75rem 1rem; margin-bottom: 1rem; border: 2px solid #e0e0e0; border-radius: 10px; font-size: 1rem; transition: border-color 0.3s; font-family: 'Vazirmatn', Arial, sans-serif; text-align: center; }
#loginForm input:focus { outline: none; border-color: #5b21b6; }
#loginForm button { width: 100%; padding: 0.75rem; background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%); color: white; border: none; border-radius: 10px; font-size: 1.1rem; cursor: pointer; transition: transform 0.2s; font-family: 'Vazirmatn', Arial, sans-serif; }
#loginForm button:hover { transform: translateY(-2px); }

/* --- Mobile Toggle Button --- */
.mobile-toggle-btn {
    position: fixed;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 60px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

.mobile-toggle-btn:hover {
    background: #5a67d8;
    transform: translateY(-50%) translateX(2px);
}

.mobile-toggle-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

.mobile-toggle-btn.active svg {
    transform: rotate(180deg);
}

/* --- Panel Layout --- */
.left-panel {
    flex: 1 1 67%;
    min-width: 0;
    background: #f9f9f9;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid #e0e0e0;
    transition: transform 0.3s ease;
}

.right-panel {
    flex: 1 1 33%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: white;
}

.middle-panel { 
    display: none;
}

/* --- Right Panel Split: Avatar (top) and Chat (bottom) --- */
.avatar-section {
    flex: 0 0 250px;
    position: relative;
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #e0e0e0;
    overflow: hidden;
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

/* --- Avatar Section Styling --- */
.avatar-logo { 
    position: absolute;
    top: 60px;
    left: 1rem;
    width: 80px; 
    height: 80px; 
    object-fit: contain; 
    border-radius: 10px; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10;
}

#canvas { 
    position: absolute;
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%); /* Perfect centering */
    max-width: 90%; /* Allow 10% margin */
    max-height: 90%; /* Allow 10% margin */
    width: auto !important; 
    height: auto !important; 
}

/* --- User Avatar Selection --- */
.user-avatars {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.user-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.user-avatar:active {
    transform: scale(0.95);
}

.user-avatar.active {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
    transform: scale(1.05);
}

/* --- Voice Language Selection --- */
.voice-languages {
    position: absolute;
    top: 1rem;
    left: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
}

.voice-lang-btn {
    padding: 0.4rem 0.8rem;
    border: 2px solid white;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border-radius: 20px;
    font-family: 'Vazirmatn', Arial, sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    outline: none;
}

.voice-lang-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.voice-lang-btn:active {
    transform: translateY(0);
}

.voice-lang-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

/* --- Left Panel (Products) - Updated for Responsive Grid --- */
.panel-header { margin-bottom: 1rem; flex-shrink: 0; }
.products-section { 
    flex-grow: 1; 
    overflow-y: auto; 
    padding-left: 0.5rem; 
}

#productsContainer {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.filters-section { background: white; padding: 1rem; border-radius: 15px; box-shadow: 0 2px 10px rgba(0,0,0,0.08); margin-bottom: 1rem; }
.filters-section h3 { color: #333; margin-bottom: 0.5rem; font-size: 1.1rem; text-align: center; }
#filtersDisplay { color: #666; font-size: 0.9rem; line-height: 1.6; text-align: center; }
.clear-search-btn { display: block; width: 100%; padding: 0.6rem; margin-top: 1rem; border: 1px solid #ffb8b8; background-color: #ffeaea; color: #c0392b; border-radius: 8px; cursor: pointer; font-family: 'Vazirmatn', Arial, sans-serif; font-weight: 500; transition: all 0.2s; }
.clear-search-btn:hover { background-color: #e74c3c; color: white; }

/* --- Train Card Styles --- */
.train-card { 
    background: white; 
    border-radius: 15px; 
    padding: 1.2rem; 
    margin-bottom: 0; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.08); 
    border: 1px solid #f0f0f0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.train-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.train-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.train-company { display: flex; align-items: center; gap: 0.5rem; }
.train-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; }
.company-name { font-weight: 600; color: #1f2937; font-size: 1rem; }
.train-number { background: #3b82f6; color: white; padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.8rem; font-weight: 500; }
.route-info { background: #f8fafc; padding: 1rem; border-radius: 10px; margin-bottom: 1rem; }
.route-cities { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.city-name { font-weight: 600; color: #374151; }
.route-arrow { color: #6b7280; font-size: 1.2rem; }
.route-times { display: flex; justify-content: space-between; font-size: 0.9rem; color: #6b7280; }
.train-date-info { background: #e0f2fe; padding: 0.5rem; border-radius: 8px; margin-top: 0.5rem; font-size: 0.9rem; color: #01579b; text-align: center; }
.wagon-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.wagon-details { font-size: 0.9rem; color: #374151; }
.compartment-badge { background: #10b981; color: white; padding: 0.2rem 0.6rem; border-radius: 12px; font-size: 0.8rem; }
.train-pricing { display: flex; justify-content: space-between; align-items: center; }
.price-info { display: flex; flex-direction: column; }
.adult-price { font-weight: 700; color: #059669; font-size: 1.1rem; }
.child-price { font-size: 0.8rem; color: #6b7280; }
.seats-remaining { background: #fef3c7; color: #92400e; padding: 0.25rem 0.5rem; border-radius: 6px; font-size: 0.8rem; }

/* --- Hotel Card Styles --- */
.hotel-card { 
    background: white; 
    border-radius: 15px; 
    padding: 1.2rem; 
    margin-bottom: 0; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.08); 
    border: 1px solid #f0f0f0;
    transition: transform 0.2s, box-shadow 0.2s;
}

.hotel-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}

.hotel-header { display: flex; gap: 1rem; margin-bottom: 1rem; }
.hotel-logo { width: 80px; height: 80px; object-fit: cover; border-radius: 10px; }
.hotel-info { flex-grow: 1; }
.hotel-title { font-weight: 700; color: #1f2937; font-size: 1.2rem; margin-bottom: 0.5rem; }
.hotel-location { color: #6b7280; font-size: 0.9rem; margin-bottom: 0.5rem; }
.hotel-stars { color: #fbbf24; margin-bottom: 0.5rem; }
.hotel-type { background: #e0e7ff; color: #3730a3; padding: 0.2rem 0.6rem; border-radius: 12px; font-size: 0.8rem; display: inline-block; }
.hotel-pricing { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 1rem; }
.price-section { display: flex; flex-direction: column; }
.original-price { text-decoration: line-through; color: #9ca3af; font-size: 0.9rem; }
.final-price { font-weight: 700; color: #059669; font-size: 1.2rem; }
.discount-badge { background: #dc2626; color: white; padding: 0.25rem 0.5rem; border-radius: 6px; font-size: 0.8rem; }
.hotel-footer { display: flex; justify-content: space-between; align-items: center; }
.hotel-rating { display: flex; align-items: center; gap: 0.5rem; color: #374151; font-size: 0.9rem; }
.rating-star { color: #fbbf24; }
.instant-book { background: #10b981; color: white; padding: 0.3rem 0.7rem; border-radius: 6px; font-size: 0.8rem; }

/* --- Chat Section (Right Panel Bottom) --- */
.chat-messages { 
    flex: 1; 
    overflow-y: auto; 
    padding: 1rem; 
    display: flex; 
    flex-direction: column; 
    gap: 1rem; 
    background: #fafafa;
    min-height: 0;
}

.message { 
    padding: 0.75rem 1rem; 
    border-radius: 18px; 
    max-width: 85%; 
    word-wrap: break-word; 
    line-height: 1.5; 
}

/* --- Message Alignment --- */
.message.user { 
    background: #667eea; 
    color: white; 
    align-self: flex-start; 
    border-bottom-left-radius: 4px; 
}

.message.assistant { 
    background: #f0f0f0; 
    color: #333; 
    align-self: flex-end; 
    border-bottom-right-radius: 4px; 
}

.chat-input-container { 
    flex-shrink: 0;
    padding: 1rem; 
    border-top: 1px solid #e0e0e0; 
    background-color: white;
    position: sticky;
    bottom: 0;
    z-index: 100;
    width: 100%;
    box-sizing: border-box;
}

#messageForm { 
    display: flex; 
    gap: 0.5rem; 
    align-items: center; 
    width: 100%;
    max-width: 100%;
}

#messageInput { 
    flex: 1; 
    min-width: 0;
    padding: 0.75rem 1rem; 
    border: 2px solid #e0e0e0; 
    border-radius: 25px; 
    font-size: 1rem; 
    font-family: 'Vazirmatn', Arial, sans-serif; 
    transition: border-color 0.3s;
    box-sizing: border-box;
}

#messageInput:focus { 
    outline: none; 
    border-color: #667eea; 
}

#messageForm button[type="submit"] { 
    width: 44px;
    height: 44px;
    background: #f1f1f1;
    color: #555;
    border: 1px solid #ddd;
    border-radius: 50%; 
    cursor: pointer; 
    transition: all 0.3s; 
    font-family: 'Vazirmatn', Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#messageForm button[type="submit"]:hover { 
    background-color: #667eea;
    color: white;
    border-color: #667eea;
    transform: scale(1.05); 
}

#messageForm button[type="submit"]:active { 
    transform: scale(0.95); 
}

/* --- Control Buttons --- */
.control-btn { 
    background: #f1f1f1; 
    border: 1px solid #ddd; 
    color: #555; 
    width: 44px; 
    height: 44px; 
    border-radius: 50%; 
    cursor: pointer; 
    font-size: 1.2rem; 
    flex-shrink: 0; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.3s; 
}

.control-btn svg {
    width: 18px;
    height: 18px;
}

.control-btn#clearChatBtn:hover { 
    background-color: #e74c3c; 
    color: white; 
    border-color: #c0392b; 
}

/* --- Microphone Button States --- */
.control-btn#micToggleBtn { 
    transition: all 0.3s ease; 
}

.control-btn#micToggleBtn:not(.active) { 
    background-color: #f8f9fa; 
    border-color: #dee2e6; 
    color: #6c757d; 
}

.control-btn#micToggleBtn.active { 
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%); 
    border-color: #28a745; 
    color: white; 
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.4); 
}

.control-btn#micToggleBtn.active::before { 
    content: ""; 
    position: absolute; 
    top: -3px; 
    right: -3px; 
    width: 8px; 
    height: 8px; 
    background: #dc3545; 
    border-radius: 50%; 
    border: 2px solid white;
}

/* --- Pagination & Loading --- */
.pagination { 
    display: flex; 
    justify-content: center; 
    gap: 0.5rem; 
    margin-top: 1rem; 
}

.pagination button { 
    padding: 0.5rem 1rem; 
    background: white; 
    border: 1px solid #e0e0e0; 
    border-radius: 8px; 
    cursor: pointer; 
    transition: all 0.3s; 
    font-family: 'Vazirmatn', Arial, sans-serif; 
}

.pagination button:hover { 
    background: #f0f0f0; 
}

.pagination button.active { 
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
    color: white; 
    border: none; 
}

.loading { 
    display: inline-block; 
    width: 16px; 
    height: 16px; 
    border: 2px solid rgba(255,255,255,0.4); 
    border-top-color: #fff; 
    border-radius: 50%; 
    animation: spin 1s linear infinite; 
    margin-left: 8px; 
}

@keyframes spin { 
    0% { transform: rotate(0deg); } 
    100% { transform: rotate(360deg); } 
}

.seats-remaining.sold-out { 
    background: #fee2e2; 
    color: #dc2626; 
    border: 1px solid #fca5a5;
}

.buy-button {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-family: 'Vazirmatn', Arial, sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 0.5rem;
}

.buy-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* --- Glass Buttons for FAQ --- */
.glass-buttons-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
    width: 100%;
    animation: fadeInUp 0.3s ease-out;
}

.glass-button {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    padding: 0.75rem 1rem;
    color: #4f46e5;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Vazirmatn', Arial, sans-serif;
    font-size: 0.9rem;
    text-align: right;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    max-width: 85%;
    align-self: flex-start;
    word-wrap: break-word;
    line-height: 1.5;
    border-bottom-left-radius: 4px;
}

.glass-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.glass-button:active {
    transform: translateY(0);
}

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

/* --- RESPONSIVE BREAKPOINTS --- */

/* Large Desktop - 2 columns with 3 rows each (6 items total) */
@media (min-width: 1200px) {
    #productsContainer {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

/* Desktop - 2 columns if width allows, otherwise 1 column with 6 items */
@media (min-width: 992px) and (max-width: 1199px) {
    #productsContainer {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

/* Medium Desktop - Check if width is sufficient for 2 columns */
@media (min-width: 768px) and (max-width: 991px) {
    .left-panel {
        flex: 1 1 70%;
    }
    
    .right-panel {
        flex: 1 1 30%;
    }
    
    /* If enough space, use 2 columns, otherwise stick with 1 */
    #productsContainer {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
}

/* Small Tablet - 1 column with 6 items */
@media (min-width: 600px) and (max-width: 767px) {
    .left-panel {
        flex: 1 1 75%;
    }
    
    .right-panel {
        flex: 1 1 25%;
        min-width: 300px;
    }
    
    #productsContainer {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .avatar-section {
        flex: 0 0 180px;
    }
    
    #canvas {
        width: 100%;
        height: 100%;
    }
    
    .chat-input-container {
        padding: 0.75rem;
    }
    
    #messageForm {
        gap: 0.4rem;
    }
    
    .control-btn, #messageForm button[type="submit"] {
        width: 40px;
        height: 40px;
    }
    
    #messageInput {
        font-size: 0.9rem;
        padding: 0.6rem 0.8rem;
    }
}

/* Mobile - Hide left panel initially, show toggle button */
@media (max-width: 599px) {
    .mobile-toggle-btn {
        display: flex;
    }
    
    .left-panel {
        position: fixed;
        top: 0;
        left: 0;
        width: 85%;
        height: 100vh;
        z-index: 999;
        transform: translateX(-100%);
        border-left: none;
        border-right: 1px solid #e0e0e0;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .left-panel.mobile-open {
        transform: translateX(0);
    }
    
    .right-panel {
        flex: 1;
        width: 100%;
        min-width: 0;
    }
    
    .avatar-section {
        flex: 0 0 160px;
        min-height: 160px;
    }
    
    #canvas {
        width: 100%;
        height: 100%;
    }
    
    .chat-section {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }
    
    .chat-messages {
        flex: 1;
        min-height: 0;
        padding: 0.75rem;
    }
    
    .chat-input-container {
        flex-shrink: 0;
        padding: 0.75rem;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e0e0e0;
        z-index: 101;
    }
    
    #messageForm {
        gap: 0.4rem;
        width: 100%;
    }
    
    .control-btn, #messageForm button[type="submit"] {
        width: 38px;
        height: 38px;
        flex-shrink: 0;
    }
    
    .control-btn svg {
        width: 16px;
        height: 16px;
    }
    
    #messageInput {
        flex: 1;
        min-width: 0;
        font-size: 0.9rem;
        padding: 0.6rem 0.8rem;
    }
    
    .avatar-logo {
        width: 50px;
        height: 50px;
        top: 80px;
        left: 0.75rem;
    }
    
    .user-avatars {
        top: 0.5rem;
        right: 0.5rem;
    }
    
    .user-avatar {
        width: 32px;
        height: 32px;
    }
    
    .voice-languages {
        top: 0.5rem;
        left: 0.5rem;
    }
    
    .voice-lang-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.7rem;
    }
    
    #productsContainer {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Mobile backdrop when panel is open */
    .mobile-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .mobile-backdrop.active {
        opacity: 1;
        visibility: visible;
    }
}

/* Very small mobile phones */
@media (max-width: 400px) {
    .left-panel {
        width: 95%;
    }
    
    .login-box {
        padding: 2rem;
    }
    
    .avatar-section {
        flex: 0 0 140px;
        min-height: 140px;
    }
    
    #canvas {
        width: 100%;
        height: 100%;
    }
    
    .avatar-logo {
        width: 40px;
        height: 40px;
        top: 60px;
        left: 0.5rem;
    }
    
    .user-avatar {
        width: 28px;
        height: 28px;
    }
    
    .voice-lang-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .chat-input-container {
        padding: 0.5rem;
    }
    
    #messageForm {
        gap: 0.3rem;
    }
    
    .control-btn, #messageForm button[type="submit"] {
        width: 36px;
        height: 36px;
    }
    
    .control-btn svg {
        width: 14px;
        height: 14px;
    }
    
    #messageInput {
        font-size: 0.85rem;
        padding: 0.5rem 0.7rem;
    }
    
    .chat-messages {
        padding: 0.5rem;
        gap: 0.75rem;
    }
    
    .message {
        padding: 0.6rem 0.8rem;
        font-size: 0.9rem;
    }
}