:root {
    /* Day Theme (Default) */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #ec4899;
    --bg-color: #f8fafc;
    --card-bg: rgba(255, 255, 255, 0.8);
    --text-main: #0f172a;
    --text-muted: #475569;
    --border-color: rgba(0, 0, 0, 0.08);
    --glass-blur: blur(12px);
    --transition-speed: 0.3s;
    --input-bg: rgba(255, 255, 255, 0.9);
    --radial-start: #f1f5f9;
    --radial-end: #e2e8f0;
}

[data-theme="dark"] {
    /* Night Theme */
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --input-bg: rgba(15, 23, 42, 0.6);
    --radial-start: #1e293b;
    --radial-end: #0f172a;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    overflow-x: hidden;
}

/* Background animation */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, var(--radial-start) 0%, var(--radial-end) 100%);
    z-index: -1;
    transition: background 0.5s ease;
}

.header-top {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.theme-toggle {
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.3s ease;
    padding: 0;
    border-radius: 50%;
}

.theme-toggle:hover {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
}

.sun-icon {
    display: block;
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

.container {
    width: 100%;
    max-width: 900px;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.8s ease-out;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Search Section */
.search-box {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    margin-bottom: 2rem;
    animation: fadeInUp 0.8s ease-out;
}

.input-container {
    position: relative;
    margin-bottom: 1.5rem;
}

input[type="text"] {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    color: var(--text-main);
    font-size: 1.1rem;
    outline: none;
    transition: var(--transition-speed);
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Autocomplete dropdown */
.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 0.8rem;
    margin-top: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.autocomplete-item {
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 0.9rem;
}

.autocomplete-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Filters */
.filters {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
}

.select-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

select {
    flex: 1;
    min-width: 200px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 0.8rem 1rem;
    border-radius: 0.8rem;
    outline: none;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

select:hover {
    border-color: var(--primary);
    background: var(--card-bg);
}

.checkbox-group {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.checkbox-container {
    display: flex;
    align-items: center;
    position: relative;
    padding-left: 2rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    user-select: none;
    transition: color 0.3s;
}

.checkbox-container:hover {
    color: var(--text-main);
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 1.2rem;
    width: 1.2rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 0.3rem;
    transition: all 0.3s;
}

.checkbox-container:hover input~.checkmark {
    border-color: var(--primary);
}

.checkbox-container input:checked~.checkmark {
    background-color: var(--primary);
    border-color: var(--primary);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.checkbox-container input:checked~.checkmark:after {
    display: block;
}

/* Results Grid */
#results-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    animation: fadeIn 1s ease-in;
}

.medicine-card {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    border-radius: 1.2rem;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
    position: relative;
    overflow: hidden;
}

.medicine-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    border-color: rgba(99, 102, 241, 0.4);
}

.medicine-card h3 {
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
    color: var(--text-main);
}

.medicine-card .tag {
    display: inline-block;
}

.card-badges {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    min-height: 1.5rem;
}

.badges-left,
.badges-right {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.badges-right {
    justify-content: flex-end;
}

.cn-badge {
    position: absolute;
    bottom: 0.8rem;
    right: 0.8rem;
    font-size: 0.6rem;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    padding: 0.2rem 0.5rem;
    border-radius: 0.4rem;
    border: 1px solid var(--border-color);
    z-index: 5;
}

.tag {
    padding: 0.3rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 5;
}

.tag.generico {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.tag.marca {
    background: rgba(236, 72, 153, 0.2);
    color: #f472b6;
}

.cheapest-badge {
    font-size: 0.7rem;
    font-weight: 800;
    background: #22c55e;
    color: white;
    padding: 0.3rem 0.6rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
    z-index: 10;
}

.source-badge {
    font-size: 0.6rem;
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    border: 1px solid rgba(99, 102, 241, 0.3);
    z-index: 5;
}

.cheapest-option {
    border: 2px solid #22c55e !important;
    background: linear-gradient(145deg, rgba(34, 197, 94, 0.1) 0%, var(--card-bg) 100%) !important;
}

.med-thumb {
    width: 100%;
    height: 120px;
    object-fit: contain;
    background: white;
    border-radius: 0.8rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
}

.cima-link {
    display: inline-block;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.cima-link:hover {
    text-decoration: underline;
}

.med-info {
    margin: 1rem 0;
}

.med-info p {
    margin: 0.2rem 0;
    line-height: 1.4;
}

.price-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.success-pill,
.warning-pill {
    font-size: 0.6rem;
    font-weight: 800;
    padding: 0.2rem 0.5rem;
    border-radius: 0.4rem;
    text-transform: uppercase;
}

.success-pill {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.warning-pill {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.price-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.price-warning {
    font-size: 0.75rem;
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    border: 1px solid rgba(251, 191, 36, 0.2);
    font-weight: 500;
}

.medicine-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.price-tag {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
}

.price-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 2rem;
    }

    body {
        padding: 1rem;
    }

    .search-box {
        padding: 1rem;
    }

    #results-list {
        grid-template-columns: 1fr;
    }
}