:root {
    --bg-main: #F9FAFB;
    --text-primary: #111827;
    --text-secondary: #4B5563;
    --border-color: #E5E7EB;
    --price-green: #10B981;
    --btn-bg: #F1F5F9;
    --btn-hover: #E2E8F0;
    --header-bg: #FFFFFF;
}

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

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    /* Ensure minimum text size for mobile accessibility */
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

/* ─── Header Sticky & Search ─── */
/* ─── Header Sticky & Search ─── */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logo-container {
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800; /* Extra bold for brand weight */
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 14px;
    color: var(--text-secondary);
}

#searchInput {
    width: 100%;
    padding: 14px 40px 14px 40px;
    font-size: 16px; /* Prevents iOS zoom */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-main);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

#searchInput:focus {
    border-color: var(--text-primary);
}

#searchInput::placeholder {
    font-size: 0.875rem;
    color: #9CA3AF;
}

@media (min-width: 768px) {
    #searchInput::placeholder {
        font-size: 1rem;
    }
}

.clear-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    padding: 4px;
    cursor: pointer;
}

.hidden {
    display: none !important;
}

@media (min-width: 768px) {
    .sticky-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 24px;
        padding: 20px 0;
    }
    
    .search-container {
        max-width: 450px;
    }
}

/* ─── Layout Utils ─── */
.max-w-4xl {
    max-width: 896px; /* 56rem */
    width: 100%;
}
.mx-auto {
    margin-left: auto;
    margin-right: auto;
}
.px-4 {
    padding-left: 16px;
    padding-right: 16px;
}

/* ─── Main Container ─── */
.container {
    padding: 16px 0;
    width: 100%;
}

/* ─── Filters ─── */
.filters-section {
    margin-left: -16px;
    margin-right: -16px;
    margin-bottom: 24px;
    overflow: hidden;
    width: calc(100% + 32px);
}

.pharmacy-filters {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    gap: 8px;
    padding: 4px 16px 12px 16px; /* Align with container margins */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
}

.pharmacy-filters::after {
    content: '';
    display: block;
    width: 16px;
    flex-shrink: 0;
}

.pharmacy-filters::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
}

@media (min-width: 768px) {
    .filters-section {
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }
    
    .pharmacy-filters {
        flex-wrap: wrap;
        overflow-x: visible;
        padding: 4px 0 0 0;
    }
    
    .pharmacy-filters::after {
        display: none;
    }
}

/* ─── Utility Classes ─── */
.text-center {
    text-align: center;
}
.mt-12 {
    margin-top: 48px;
}
.px-6 {
    padding-left: 24px;
    padding-right: 24px;
}
.text-sm {
    font-size: 0.875rem;
}
.text-gray-400 {
    color: #9CA3AF;
}

.pharmacy-checkbox {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: #F3F4F6; /* Gray 100 */
    border: 1px solid transparent;
    padding: 8px 16px;
    border-radius: 9999px; /* Pill shape */
    font-size: 0.875rem;
    font-weight: 500;
    color: #4B5563; /* Gray 600 */
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.pharmacy-checkbox:hover {
    background-color: #E5E7EB; /* Gray 200 */
}

.pharmacy-checkbox:has(input:checked) {
    background-color: #1E293B; /* Slate 800 */
    color: #FFFFFF;
    font-weight: 600;
}

.pharmacy-checkbox:has(input:checked):hover {
    background-color: #0F172A; /* Slate 900 */
}

/* ─── Correction Banner ─── */
.correction-banner {
    background-color: #FEF3C7;
    color: #92400E;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Results Section ─── */
.results-info {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.results-count {
    font-weight: 600;
    font-size: 1.125rem;
}

.sort-indicator {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ─── Result Card ─── */
.result-card {
    background-color: #FFFFFF;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    display: grid;
    /* Grid Mobile-first: Logo+Name top, Price+Btn bottom */
    grid-template-columns: 1fr;
    gap: 12px;
}

/* Tablet & Desktop Grid */
@media (min-width: 600px) {
    .result-card {
        grid-template-columns: auto 1fr auto auto;
        align-items: center;
        gap: 16px;
    }
}

.pharmacy-brand {
    width: 208px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-shrink: 0;
    gap: 8px;
}

.pharmacy-logo {
    width: 24px;
    height: 24px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
}

.fallback-badge {
    width: 40px;
    height: 40px;
    background-color: #F1F5F9;
    border-radius: 8px;
    border: 1px solid #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    color: #374151;
    flex-shrink: 0;
}

.pharmacy-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6B7280;
    line-height: 1.2;
}

.product-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.price-container {
    text-align: left;
}

@media (min-width: 600px) {
    .price-container {
        text-align: right;
    }
}

.original-price {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-decoration: line-through;
    display: block;
}

.final-price {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--price-green);
}

.btn-buy {
    background-color: #FFFFFF;
    color: #1F2937;
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
    padding: 10px 16px;
    border-radius: 6px;
    text-align: center;
    border: 1px solid #9CA3AF;
    transition: background-color 0.2s;
    white-space: nowrap;
}

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

/* ─── Best Price Highlight ─── */
.result-card.best-price {
    border: 2px solid var(--price-green);
    background-color: #F0FDF4; /* Very light green */
}

.result-card.best-price .final-price {
    font-size: 1.5rem;
}

.result-card.best-price .btn-buy {
    background-color: var(--price-green);
    color: #FFFFFF;
    border-color: var(--price-green);
}

.result-card.best-price .btn-buy:hover {
    background-color: #059669; /* Darker green */
}

/* ─── Loading & Empty States ─── */
#loadingState, #emptyState {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

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

.empty-icon {
    font-size: 48px;
    color: var(--border-color);
    margin-bottom: 16px;
}

#emptyState h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

/* ─── Checkbox Pill States ─── */
.pharmacy-filters label {
    background-color: #F3F4F6 !important;
    border-color: #E5E7EB !important;
    color: #9CA3AF !important;
}

.pharmacy-filters label .check-icon {
    display: none !important;
}

.pharmacy-filters label .cross-icon {
    display: inline !important;
    color: #9CA3AF !important;
}

.pharmacy-filters label:has(input:checked) {
    background-color: #FFFFFF !important;
    border-color: #10B981 !important;
    color: #0F172A !important;
    text-decoration: none !important;
}

.pharmacy-filters label:has(input:checked) .check-icon {
    display: inline !important;
    color: #10B981 !important;
}

.pharmacy-filters label:has(input:checked) .cross-icon {
    display: none !important;
}

.pharmacy-filters label:not(:has(input:checked)) {
    background-color: #F3F4F6 !important;
    border-color: #E5E7EB !important;
    color: #9CA3AF !important;
    text-decoration: line-through !important;
}

.pharmacy-filters label:not(:has(input:checked)) span {
    color: #9CA3AF !important;
}

/* Desaturate custom brand logo images when label is unchecked */
.pharmacy-filters label:not(:has(input:checked)) img {
    filter: grayscale(100%) opacity(50%) !important;
}

/* Hide generic check/cross icons on individual pharmacy pills to avoid double-icon clutter */
.pharmacy-filters label:not(#chk-all-label) .check-icon,
.pharmacy-filters label:not(#chk-all-label) .cross-icon {
    display: none !important;
}

/* Hide native scrollbar for pharmacy-filters */
.scrollbar-none::-webkit-scrollbar {
    display: none !important;
}
.scrollbar-none {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}
