/* ═══════════════════════════════════════════════════
   Dawarly — Light Premium Theme (Amazon-inspired)
   3-Step Flow: Search → Product Detail → Price Compare
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Roboto:wght@500;700&display=swap');

/* --- Design Tokens --- */
:root {
    --bg-body: #eaeded;
    --bg-white: #ffffff;
    --bg-header: #131921;
    --text-dark: #0f1111;
    --text-secondary: #565959;
    --text-link: #007185;
    --text-link-hover: #c45500;
    --price-color: #b12704;
    --accent: #febd69;
    --accent-hover: #f3a847;
    --accent-focus: #e77600;
    --btn-primary: #ffd814;
    --btn-primary-hover: #f7ca00;
    --btn-primary-border: #fcd200;
    --green: #059669;
    --red: #cc0c39;
    --border: #dddddd;
    --border-light: #f0f0f0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.18);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 30px;
    --transition: 0.25s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-dark);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
header {
    background: linear-gradient(135deg, #131921 0%, #1a2332 100%);
    color: white;
    padding: 1.5rem 2rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -30%;
    width: 60%;
    height: 200%;
    background: radial-gradient(ellipse, rgba(254, 189, 105, 0.08) 0%, transparent 70%);
    pointer-events: none;
}

header h1 {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 700;
    margin-bottom: 0.3rem;
    position: relative;
}

header h1 .gradient-text {
    background: linear-gradient(90deg, #febd69, #f3a847);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: #b0b8c1;
    font-size: 0.95rem;
    font-weight: 400;
    position: relative;
}

/* Live badge */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.6rem;
    padding: 0.3rem 0.9rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--green);
    background: rgba(5, 150, 105, 0.1);
    border: 1px solid rgba(5, 150, 105, 0.2);
    border-radius: var(--radius-pill);
    letter-spacing: 0.5px;
}

.live-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--green);
    border-radius: 50%;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* --- Main Container --- */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* --- Search Section --- */
.search-container {
    background: var(--bg-white);
    padding: 1.2rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.8rem;
    border: 1px solid var(--border);
}

.search-container input {
    flex-grow: 1;
    max-width: 600px;
    padding: 0.85rem 1.2rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    color: var(--text-dark);
    outline: none;
    background: var(--bg-white);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search-container input::placeholder {
    color: #999;
}

.search-container input:focus {
    border-color: var(--accent-focus);
    box-shadow: 0 0 0 3px rgba(231, 118, 0, 0.15);
}

.search-container button {
    padding: 0.85rem 2rem;
    background: var(--accent);
    border: 1px solid var(--accent-hover);
    color: var(--text-dark);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
    white-space: nowrap;
}

.search-container button:hover {
    background: var(--accent-hover);
}

.search-container button:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* --- Dashboard Stats --- */
.dashboard-stats {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

#resultText {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 1.25rem;
}

/* --- Products Grid --- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.2rem;
}

/* --- Product Card --- */
.product-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0;
    display: flex;
    flex-direction: column;
    transition: all var(--transition);
    cursor: pointer;
    overflow: hidden;
    animation: cardFadeIn 0.4s ease forwards;
    opacity: 0;
}

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

.product-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-3px);
}

/* Card Image */
.card-image-container {
    position: relative;
    width: 100%;
    height: 200px;
    background: var(--bg-white);
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    padding: 1rem;
}

.product-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: 100%;
    object-fit: contain;
}

/* Stock Badges */
.stock-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 0.25rem 0.7rem;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    color: white;
    z-index: 2;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.stock-badge.in-stock {
    background: var(--green);
}

.stock-badge.out-of-stock {
    background: var(--red);
}

/* Card Content */
.card-body {
    padding: 1rem 1.2rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 0.95rem;
    color: var(--text-link);
    margin-bottom: 0.8rem;
    line-height: 1.5;
    font-weight: 500;
    height: 4.3em;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    transition: color var(--transition);
}

.product-card:hover .card-title {
    color: var(--text-link-hover);
}

.card-meta {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 1rem;
}

.card-stores {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.card-price {
    font-family: 'Roboto', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--price-color);
    letter-spacing: -0.5px;
}

.card-price .currency {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Card Button */
.card-btn {
    display: block;
    width: 100%;
    text-align: center;
    background: var(--btn-primary);
    border: 1px solid var(--btn-primary-border);
    color: var(--text-dark);
    padding: 0.7rem;
    border-radius: var(--radius-pill);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
    margin-top: auto;
}

.card-btn:hover {
    background: var(--btn-primary-hover);
}

/* --- Loader --- */
.loader-container {
    text-align: center;
    padding: 3.5rem 2rem;
    background: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--border-light);
    border-top: 4px solid var(--accent-focus);
    border-radius: 50%;
    margin: 0 auto 1.2rem;
    animation: spin 0.8s linear infinite;
}

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

.loader-container p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 360px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ═══════════════════════════════════════
   MODAL — Product Detail + Merchants
   ═══════════════════════════════════════ */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.show {
    display: flex;
    animation: modalFade 0.3s ease;
}

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

.modal-content {
    background: var(--bg-white);
    width: 92%;
    max-width: 800px;
    border-radius: var(--radius-lg);
    padding: 2rem;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalSlide 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.close-btn {
    position: absolute;
    top: 12px;
    right: 18px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    border-radius: 50%;
    transition: all var(--transition);
    background: transparent;
    line-height: 1;
}

.close-btn:hover {
    color: var(--red);
    background: rgba(204, 12, 57, 0.06);
}

/* --- Product Detail View (inside Modal) --- */
.product-detail-view {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
}

.product-detail-img {
    flex: 1;
    min-width: 220px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fafafa;
    border-radius: var(--radius-md);
    padding: 1.5rem;
    border: 1px solid var(--border-light);
}

.product-detail-img img {
    max-width: 100%;
    max-height: 280px;
    object-fit: contain;
}

.product-detail-info {
    flex: 1.2;
    min-width: 280px;
}

.product-detail-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 0.8rem;
    line-height: 1.45;
}

.product-detail-price {
    font-family: 'Roboto', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--price-color);
    margin: 0.6rem 0;
    letter-spacing: -1px;
}

.product-detail-stock {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.product-detail-stock.in-stock {
    color: var(--green);
}

.product-detail-stock.out-of-stock {
    color: var(--red);
}

.product-detail-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 1rem 0 1.5rem;
    line-height: 1.7;
}

.cheapest-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 1rem 1.5rem;
    background: var(--btn-primary);
    border: 1px solid var(--btn-primary-border);
    color: var(--text-dark);
    border-radius: var(--radius-pill);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.cheapest-btn:hover {
    background: var(--btn-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* --- Merchants List (inside Modal) --- */
.merchants-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-dark);
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--bg-body);
    margin-bottom: 1rem;
}

.merchant-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.merchant-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    transition: all var(--transition);
}

.merchant-row:hover {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.07);
}

.merchant-row.best-deal {
    border-color: var(--green);
    background: rgba(5, 150, 105, 0.03);
}

.merchant-row.best-deal::before {
    content: '🏆';
    font-size: 1.2rem;
    margin-right: 0.5rem;
}

.merchant-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.merchant-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-link);
}

.merchant-stock {
    font-size: 0.75rem;
    font-weight: 500;
}

.merchant-price {
    font-family: 'Roboto', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--price-color);
}

.merchant-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.merchant-buy-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--btn-primary);
    color: var(--text-dark);
    padding: 0.5rem 1.2rem;
    border-radius: var(--radius-pill);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all var(--transition);
    border: 1px solid var(--btn-primary-border);
}

.merchant-buy-btn:hover {
    background: var(--btn-primary-hover);
}

.merchant-buy-btn.disabled {
    background: #e5e7eb !important;
    border-color: #d1d5db !important;
    color: #9ca3af !important;
    cursor: not-allowed;
}

/* Back button in modal */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 1.2rem;
    background: none;
    border: none;
    color: var(--text-link);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    font-family: inherit;
    transition: color var(--transition);
    padding: 0;
}

.back-btn:hover {
    color: var(--text-link-hover);
}

/* --- Empty & Error States --- */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
    background: var(--bg-white);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.empty-state .emoji {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: block;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-body);
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .search-container {
        flex-direction: column;
    }

    .search-container input {
        max-width: 100%;
    }

    .search-container button {
        width: 100%;
    }

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

    .modal-content {
        width: 96%;
        padding: 1.5rem;
    }

    .product-detail-view {
        flex-direction: column;
    }

    .merchant-row {
        flex-wrap: wrap;
        gap: 0.6rem;
    }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 1.5rem;
    }
}
