:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius: 0.75rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 600px;
    /* Mobile focused width */
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.app-header {
    background-color: var(--surface-color);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 1rem 0;
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border-color);
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    text-align: center;
}

.search-container {
    position: relative;
    display: flex;
    gap: 0.5rem;
}

#searchInput {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    background-color: var(--background-color);
    transition: all 0.2s;
}

#searchInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    background-color: var(--surface-color);
}

#searchBtn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

#searchBtn:hover {
    background-color: var(--primary-dark);
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    padding: 1.5rem 0;
}

.product-card {
    background: var(--surface-color);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.product-card:active {
    transform: scale(0.98);
}

.product-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    background-color: white;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

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

.product-name {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-top: auto;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    /* Center vertically */
    justify-content: center;
    /* Center horizontally */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    backdrop-filter: blur(4px);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--surface-color);
    width: 100%;
    max-width: 500px;
    height: auto;
    max-height: 90vh;
    /* Max height 90% of viewport */
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow-y: auto;
    /* Scrollable content */
    margin: 1rem;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

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

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    z-index: 10;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Product Detail Styles */
.detail-image-container {
    width: 100%;
    background: white;
    padding: 2rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.detail-image {
    max-width: 100%;
    max-height: 300px;
    object-fit: contain;
}

.detail-content {
    padding: 1.5rem;
}

.detail-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.detail-brand {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.detail-price {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.detail-meta {
    display: grid;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--background-color);
    padding: 1rem;
    border-radius: var(--radius);
}

.meta-item {
    display: flex;
    justify-content: space-between;
}

.meta-label {
    font-weight: 500;
}

/* Loading Spinner */
.spinner {
    border: 3px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Comparison Styles */
.comparison-section {
    margin: 1.5rem 0;
    padding: 1rem;
    background: #f1f5f9;
    border-radius: var(--radius);
}

.comparison-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.price-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.5rem;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.stat-item .label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.stat-item .value {
    font-weight: 700;
    font-size: 0.9rem;
}

.stat-item .market {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.stat-item.cheap .value {
    color: #16a34a;
}

.stat-item.expensive .value {
    color: #dc2626;
}

.stat-item.avg .value {
    color: #2563eb;
}

.markets-list h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.market-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 0.9rem;
}

.market-item:last-child {
    border-bottom: none;
}

.market-price {
    font-weight: 600;
}