/**
 * ============================================
 * 💻 Global & Reset Styles
 * ============================================
 */

/* Box-Sizing Reset: Inherit box-sizing globally for simpler component styling */
html {
    box-sizing: border-box;
}

*,
*::before,
*::after {
    box-sizing: inherit;
}

/* Base Document Setup */
html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}


/**
 * ============================================
 * 🎨 Body & Background
 * ============================================
 */

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #ffffff;
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    padding-bottom: 20px;

    /* Animated Gradient Background */
    background: linear-gradient(135deg, #ff00e0, #ff6a00, #00c3ff, #7b2fff);
    background-size: 500% 500%;
    animation: bgGradient 40s ease infinite;
}

/* Background Animation Keyframes */
@keyframes bgGradient {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}


/**
 * ============================================
 * ✨ Utility & General Animations
 * ============================================
 */

/* Card Fade-In Animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading Pulse Animation */
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5; /* Corrected typo: opacity .5 -> opacity: 0.5; */
    }
}

/* Spinner Animation */
@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Glassmorphism Effect */
.glass {
    background: rgba(255, 255, 255, 0.12);
    border: 1.5px solid rgba(255, 255, 255, 0.28);
    border-radius: 18px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.25);
    color: black;
}

/* Utility Classes */
.loading-pulse {
    animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.loader-spinner {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-left-color: #ffffff;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    margin-right: 6px;
    vertical-align: middle;
}


/**
 * ============================================
 * 🏗️ Main Layout & Header
 * ============================================
 */

main {
    flex: 1;
    width: 100%;
    max-width: 1500px;
    padding: 0 15px;
    display: flex;
    flex-direction: column;
}

.page-header {
    text-align: center;
    margin: 30px auto 20px auto;
    color: #ffffff;
    width: 95%;
    max-width: 900px;
}

.page-header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin: 0;
    color: #ffffff;
}
.page-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #ffffff;
    margin: 5px 0 0 0;
}
.page-header h3 {
    font-style: italic;
    font-size: 0.9rem;
    color: #f0f0f0;
    opacity: 0.9;
    margin: 5px 0 0 0;
}


/**
 * ============================================
 * 💬 Chat & Input Elements
 * ============================================
 */

/* Input Fields */
#chat-input,
#searchInput {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    color: #ffffff;
    border-radius: 14px;
    padding: 12px;
    width: 100%;
    font-size: 0.95rem;
    transition: all 0.25s ease;
    resize: vertical;
    min-height: 50px;
}

#chat-input::placeholder,
#searchInput::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

#chat-input:focus,
#searchInput:focus {
    border-color: #ffffff;
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.2);
}

/* Send Button */
#chat-send {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 14px;
    padding: 0 24px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    min-height: 50px;
}

#chat-send:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

/* Chat Log Container */
#chat-log {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 16px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
    margin: 20px 0;
    max-height: 600px;
    overflow-y: auto;
    scroll-behavior: smooth;
    color: #ffffff;
}


/**
 * ============================================
 * 📊 Trend Cards & Card Grid
 * ============================================
 */

.trend-card-row {
    display: grid;
    /* Default: 1 column for mobile, auto-fill for larger screens */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
    margin-top: 15px;
    width: 100%;
}

/* Desktop: Force 3 columns */
@media (min-width: 1024px) {
    .trend-card-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

.trend-card {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.25s ease, background 0.25s ease;
    color: #ffffff;
    position: relative;
    opacity: 0;
    animation: fadeInUp 0.5s ease forwards;
}

.trend-card:hover {
    transform: translateY(-4px);
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.trend-card img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.2);
}

.score-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    font-weight: 800;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    z-index: 20;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.trend-title a {
    color: #ffffff;
    font-weight: 700;
    text-decoration: none;
    font-size: 1rem;
    display: block;
    margin-bottom: 8px;
    line-height: 1.3;
}
.trend-title a:hover {
    text-decoration: underline;
}

/* Card Buttons */
.trend-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: auto;
}

.trend-btn {
    font-size: 0.75rem;
    border-radius: 20px;
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    background: rgba(0, 0, 0, 0.4);
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-grow: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.trend-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #ffffff;
}

.trend-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.compare-active {
    border-color: #f97316 !important;
    background: rgba(249, 115, 22, 0.4) !important;
}


/**
 * ============================================
 * ✍️ Manual Trend Section (Specific Overrides)
 * ============================================
 */

#manual-trends-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    height: 280px; /* Limit visible height (Mobile) */
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    padding: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 20px;
}

/* Scrollbar for Manual Trends Section */
#manual-trends-section::-webkit-scrollbar {
    width: 8px;
}
#manual-trends-section::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}
#manual-trends-section::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Override specifically for the manual trend cards */
#manual-trends-section .trend-card {
    width: 250px !important;
    height: 300px !important;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Adjust image height inside fixed cards */
#manual-trends-section .trend-card img {
    height: 120px !important;
    flex-shrink: 0;
}

/* Adjust button font size for smaller card width */
#manual-trends-section .trend-btn {
    font-size: 0.65rem;
    padding: 4px 6px;
    min-height: 24px;
}

#manual-trends-section .manual-desc {
    font-size: 0.75rem;
    line-height: 1.2;
    margin-bottom: 5px;
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    opacity: 0.8;
}

/* Desktop overrides for the manual section */
@media (min-width: 768px) {
    #manual-trends-section {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        /* Fixed height allowing overflow */
        height: 650px;
        max-height: 650px;
        overflow-y: auto;
    }
}


/**
 * ============================================
 * ⬇️ Bottom Interaction Elements
 * ============================================
 */

/* Main Bottom Buttons */
.bottom-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    width: 100%;
    margin-top: 30px;
    margin-bottom: 30px;
}

.bottom-buttons a,
.bottom-buttons button {
    flex: 1 1 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 600;
    border-radius: 12px;
    padding: 15px;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    transition: all 0.3s ease;
    min-height: 60px;
    cursor: pointer;
}

.bottom-buttons a:hover,
.bottom-buttons button:hover {
    transform: translateY(-3px);
    background: rgba(255, 255, 255, 0.25);
}

/* Inline Results (Tags/Links) */
#inlineResults {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 10px 0;
}
#inlineResults a {
    background: rgba(255, 255, 255, 0.15);
    padding: 5px 12px;
    border-radius: 20px;
    color: #ffffff;
    text-decoration: none;
    font-size: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}
#inlineResults a:hover {
    background: rgba(255, 255, 255, 0.3);
}


/**
 * ============================================
 * 🔍 Search Dropdown (White Background)
 * ============================================
 */

#searchResults {
    background: #ffffff !important;
    border: 1px solid #ccc;
    color: #000000 !important;
    border-radius: 12px;
    padding: 0;
    list-style: none;
    position: absolute;
    z-index: 999;
    max-height: 250px;
    overflow-y: auto;
    width: 90%;
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

#searchResults li {
    padding: 10px 15px;
    border-bottom: 1px solid #eeeeee;
    cursor: pointer;
    color: #000000 !important;
}

#searchResults li:last-child {
    border-bottom: none;
}

#searchResults li:hover {
    background: #f3f4f6; /* Light Gray Hover */
    color: #000000 !important;
}

#searchResults a {
    color: #000000 !important;
    text-decoration: none;
    display: block;
}


/**
 * ============================================
 * 🖼️ Modals (AI, Custom, App/Iframe)
 * ============================================
 */

.custom-modal,
#ai-modal,
#app-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.custom-modal-content,
#ai-modal-content {
    background: #0f172a; /* Dark background for Modals */
    padding: 25px;
    width: 90%;
    max-width: 700px;
    border-radius: 16px;
    border: 1px solid #38bdf8;
    color: #ffffff;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    position: relative;
}

/* Special style for App Modal (Iframe) */
.app-modal-content {
    background: #ffffff; /* White bg for apps generally */
    width: 95%;
    height: 95%;
    max-width: 1200px;
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
}

.app-iframe {
    flex: 1;
    width: 100%;
    border: none;
}

/* Close Buttons */
.modal-close,
.ai-close {
    position: absolute;
    top: 15px;
    right: 20px;
    cursor: pointer;
    color: #38bdf8;
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1;
    z-index: 20;
}

.app-modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    cursor: pointer;
    color: #000;
    background: rgba(255, 255, 255, 0.8);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.modal-close:hover {
    color: #ffffff;
}

/* Modal Headers */
.custom-modal h2,
#ai-modal h2 {
    margin-top: 0;
    color: #00e0ff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
    margin-bottom: 15px;
    padding-right: 30px;
}

.ai-summary-text {
    white-space: pre-wrap;
    font-size: 1rem;
    line-height: 1.6;
    color: #e2e8f0;
}


/**
 * ============================================
 * 🧮 Calculator Specifics
 * ============================================
 */

.calc-inputs,
.money-calc-inputs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.calc-inputs input,
.money-calc-inputs input,
.money-calc-inputs select {
    background: #1b222c;
    color: #ffffff;
    border: 1px solid #00e0ff;
    border-radius: 6px;
    padding: 10px;
    flex: 1 1 45%;
    min-width: 120px;
}

.calc-btn {
    background: #00e0ff;
    color: #000000;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    width: 100%;
    margin-top: 10px;
}
.calc-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}
.calc-cell {
    background: #161b22;
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    border: 1px solid rgba(0, 255, 255, 0.2);
}
.calc-metric {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 5px;
    color: #ffffff;
}

/* Color Utilities for Calc */
.txt-green {
    color: #00ff9d;
}
.txt-red {
    color: #ff4d4d;
}
.txt-amber {
    color: #ffd166;
}

/* Money Calculator Output */
.money-section {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.money-output {
    font-size: 2rem;
    color: #00ff9d;
    font-weight: bold;
    margin-top: 10px;
    text-shadow: 0 0 10px rgba(0, 255, 157, 0.3);
}


/**
 * ============================================
 * 🎥 Video Modal Specific Styles
 * ============================================
 */

.video-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}
.video-card {
    position: relative;
    background: #1e293b;
    border-radius: 10px;
    overflow: hidden;
    transition: transform 0.2s;
}
.video-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}
.video-card-image {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #0f172a;
}
.video-card-title {
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.3;
    color: #cbd5e1;
}
.video-card-source {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #000;
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.6rem;
}


/**
 * ============================================
 * 📱 Responsive Tweaks
 * ============================================
 */

@media (max-width: 768px) {
    .page-header h1 {
        font-size: 1.8rem;
    }
    #chat-log {
        padding: 10px;
    }
    /* Force 1 column on mobile for better usability */
    .trend-card-row {
        grid-template-columns: 1fr;
    }
    .calc-inputs input {
        flex: 1 1 100%;
    }
    .bottom-buttons a,
    .bottom-buttons button {
        flex: 1 1 100%;
    }
    .glass {
        border-radius: 12px;
    }
}