:root {
    --primary-color: #3498db;
    --secondary-color: #2c3e50;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333;
    --amazon-color: #ff9900;
    --rakuten-color: #bf0000;
    --success-color: #2ecc71;
    --warning-color: #f1c40f;
    --danger-color: #e74c3c;
    --radar-color: rgba(52, 152, 219, 0.2);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    min-height: 100vh;
}

.container {
    width: 100%;
    max-width: 1400px;
    padding: 2rem;
    box-sizing: border-box;
}

/* Responsive Layout Wrapper */
.main-layout {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.left-panel {
    width: 100%;
}

.right-panel {
    width: 100%;
}

@media (min-width: 992px) {
    .main-layout {
        flex-direction: row;
        align-items: flex-start;
    }

    .left-panel {
        flex: 0 0 380px; /* Fixed width for chat sidebar */
        position: sticky;
        top: 20px;
        height: calc(100vh - 40px);
        display: flex;
        flex-direction: column;
    }

    .chat-wrapper {
        flex: 1; /* Chat fills the available height in the sticky panel */
        margin-bottom: 0;
        height: auto;
    }

    .right-panel {
        flex: 1;
        min-width: 0; /* Prevents flex overflow issues */
    }
}

header {
    text-align: center;
    margin-bottom: 1rem;
}

/* Reset Button */
.reset-btn {
    background: transparent;
    border: 1px solid #ddd;
    padding: 5px 15px;
    border-radius: 15px;
    color: #666;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 10px;
}

.reset-btn:hover {
    background-color: #fee;
    color: #c00;
    border-color: #eaa;
}

/* Toggle Switch */
.search-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #2196F3;
}

input:focus + .slider {
    box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.toggle-label {
    font-size: 0.9rem;
    color: #555;
    font-weight: 500;
}

header h1 {
    font-size: 2.5rem;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
}

/* Chat Styles */
.chat-wrapper {
    max-width: 800px;
    margin: 0 auto 30px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 400px;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: #fcfcfc;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.user-message {
    align-self: flex-end;
    background-color: #007bff;
    color: white;
    border-bottom-right-radius: 4px;
}

.assistant-message {
    align-self: flex-start;
    background-color: #e9ecef;
    color: #333;
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    display: flex;
    padding: 15px;
    border-top: 1px solid #eee;
    background: white;
    gap: 10px;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-size: 15px;
}

.chat-input-area input:focus {
    border-color: #007bff;
}

.chat-input-area button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.chat-input-area button:hover {
    background-color: #0056b3;
}

.chat-input-area button:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Global Hidden State */
.hidden {
    display: none !important;
}

/* Main Search Loading Animation */
.search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    width: 100%;
    min-height: 300px;
}

.radar-container {
    position: relative;
    width: 200px;
    height: 200px;
    margin-bottom: 30px;
}

.radar-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid var(--radar-color);
    border-radius: 50%;
}

.radar-circle::after, .radar-circle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 1px solid var(--radar-color);
    border-radius: 50%;
}

.radar-circle::after { width: 66%; height: 66%; }
.radar-circle::before { width: 33%; height: 33%; }

.radar-beam {
    position: absolute;
    width: 50%;
    height: 50%;
    top: 0;
    left: 50%;
    background: conic-gradient(from 0deg, var(--primary-color), transparent 90deg);
    transform-origin: bottom left;
    border-radius: 100% 0 0 0;
    animation: rotate 2s linear infinite;
}

.radar-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: var(--primary-color);
    border-radius: 50%;
    opacity: 0;
    animation: blip 2s infinite;
}

.dot-1 { top: 30%; left: 70%; animation-delay: 0.5s; }
.dot-2 { top: 60%; left: 20%; animation-delay: 1.2s; }
.dot-3 { top: 80%; left: 50%; animation-delay: 1.8s; }

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes blip {
    0% { opacity: 0; transform: scale(1); }
    10% { opacity: 1; transform: scale(1.5); }
    100% { opacity: 0; transform: scale(1); }
}

.loading-text {
    font-size: 1.1rem;
    color: var(--secondary-color);
    font-weight: 500;
    animation: pulse 1.5s infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 10px;
}

.filter-group, .sort-group {
    display: flex;
    gap: 10px;
}

.filter-btn, .sort-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    border-radius: 20px;
    background: white;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.filter-btn:hover, .sort-btn:hover {
    background-color: #e9ecef;
}

.filter-btn.active, .sort-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
}

.product-card {
    background-color: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    cursor: pointer; /* Indicate clickability */
}

.product-card:hover {
    transform: translateY(-5px);
}

.product-image {
    width: 100%;
    height: 200px;
    object-fit: contain;
    background-color: #fff;
    padding: 10px;
    box-sizing: border-box;
}

.product-info {
    padding: 1.5rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.product-source {
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.source-amazon { color: var(--amazon-color); }
.source-rakuten { color: var(--rakuten-color); }

.product-name {
    font-size: 1rem;
    margin: 0 0 0.5rem 0;
    line-height: 1.4;
    flex-grow: 1;
}

.product-price {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.buy-btn {
    display: inline-block;
    text-align: center;
    background-color: var(--secondary-color);
    color: white;
    text-decoration: none;
    padding: 8px 20px;
    border-radius: 5px;
    transition: background-color 0.2s;
}

.buy-btn:hover {
    background-color: #1a252f;
}

/* Load More Button */
.load-more-container {
    display: flex;
    justify-content: center;
    padding: 30px 0;
}

.load-more-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: background-color 0.3s, transform 0.2s;
}

.load-more-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.load-more-btn:active {
    transform: translateY(0);
}

.load-more-btn:disabled {
    background-color: #ccc;
    cursor: wait;
}

/* Modal Styles Refactored */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: #fff;
    border-radius: 12px;
    width: 95%;
    max-width: 1000px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 5px 30px rgba(0,0,0,0.3);
    position: relative;
    animation: modalFadeIn 0.3s;
}

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

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
}

.modal-main-content {
    padding: 40px;
}

.modal-header-row {
    display: flex;
    gap: 30px;
    margin-bottom: 30px;
    align-items: center;
}

@media (max-width: 600px) {
    .modal-header-row {
        flex-direction: column;
        text-align: center;
    }
}

.modal-image-container {
    flex: 0 0 150px;
}

.modal-image-container img {
    width: 100%;
    height: 150px;
    object-fit: contain;
}

.modal-title-container {
    flex: 1;
}

.modal-title-container h2 {
    margin: 5px 0 10px 0;
    font-size: 1.4rem;
}

.ai-analysis-section {
    background-color: #f0f7ff;
    border-left: 4px solid #3498db;
    padding: 25px;
    border-radius: 4px;
}

.ai-analysis-section h4 {
    margin: 0 0 15px 0;
    color: #3498db;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.2rem;
}

/* Funny AI Loading */
.ai-loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    text-align: center;
    color: #555;
}

.bouncing-robot {
    font-size: 4rem;
    margin-bottom: 15px;
    animation: bounce 0.6s infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

.ai-overview {
    font-size: 1rem;
    line-height: 1.6;
    color: #444;
    margin-bottom: 25px;
}

.pros-cons-grid {
    display: flex;
    gap: 30px;
    margin-bottom: 25px;
}

@media (max-width: 600px) {
    .pros-cons-grid {
        flex-direction: column;
    }
}

.pros-col, .cons-col {
    flex: 1;
}

.pros-col h5, .cons-col h5, .verdict-box h5 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pros-col h5 { color: var(--success-color); }
.cons-col h5 { color: var(--danger-color); }

.pros-col ul, .cons-col ul {
    margin: 0;
    padding-left: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
}

.verdict-box {
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    padding: 20px;
    border: 1px solid #e1e8ed;
}

.verdict-box h5 {
    color: #f39c12;
}

.verdict-box p {
    margin: 0;
    font-weight: 500;
    font-size: 1rem;
    line-height: 1.6;
    color: #2c3e50;
}