:root {
    /* macOS Sequoia / Big Sur System Colors */
    --system-blue: #007AFF;
    --system-orange: #FF9500;
    /* Warm Orange */
    --system-red: #FF3B30;
    /* Warm Red */
    --system-gray: #8E8E93;
    --system-gray2: #AEAEB2;
    --system-gray3: #C7C7CC;
    --system-gray4: #D1D1D6;
    --system-gray5: #E5E5EA;
    --system-gray6: #F2F2F7;

    /* Materials & Backgrounds */
    --bg-color: #F5F5F7;
    /* Light Mode Desktop Tint */
    --card-bg: #FFFFFF;
    --header-bg: rgba(255, 255, 255, 0.8);
    /* Lighter, more translucent */
    --control-track: rgba(118, 118, 128, 0.12);
    /* Segmented Control Track */

    /* Text */
    --text-main: #1D1D1F;
    --text-secondary: #86868B;

    /* Borders & Shadows */
    --border-color: rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
    --shadow-floating: 0 2px 5px rgba(0, 0, 0, 0.1);
    /* For segmented control thumb */

    /* Radii (Squircle-ish) */
    --radius-lg: 18px;
    --radius-md: 10px;
    --radius-sm: 6px;
    --radius-pill: 999px;

    /* Transitions */
    --transition-speed: 0.2s;
    --ease-apple: cubic-bezier(0.2, 0, 0, 1);
    /* Snappier Apple ease */
}

[data-theme="dark"] {
    --bg-color: #000000;
    --card-bg: #1C1C1E;
    --header-bg: rgba(30, 30, 30, 0.7);
    --control-track: rgba(118, 118, 128, 0.24);

    --text-main: #F5F5F7;
    --text-secondary: #98989D;

    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-floating: 0 2px 5px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color var(--transition-speed) var(--ease-apple), color var(--transition-speed) var(--ease-apple);
}

/* Unified Toolbar Header */
header {
    background-color: var(--header-bg);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 12px 0;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (min-width: 768px) {
    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        height: 44px;
        /* Standard Toolbar Height */
    }
}

.logo-area h1 {
    font-size: 20px;
    font-weight: 700;
    /* Bold for impact */
    letter-spacing: -0.01em;
    margin: 0;

    /* Bio-Gradient Flow Animation */
    background: linear-gradient(90deg,
            var(--text-main) 0%,
            var(--system-blue) 25%,
            #AF52DE 50%,
            /* System Purple */
            var(--system-blue) 75%,
            var(--text-main) 100%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    animation: gradient-flow 8s linear infinite;
}

.subtitle {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 400;
    margin-top: 2px;

    /* Assembly Fade Animation */
    opacity: 0;
    animation: slide-up-fade 0.8s var(--ease-apple) 0.2s forwards;
}

/* Animations */
@keyframes gradient-flow {
    0% {
        background-position: 0% center;
    }

    100% {
        background-position: 200% center;
    }
}

@keyframes slide-up-fade {
    0% {
        opacity: 0;
        transform: translateY(4px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Controls Area */
.controls-area {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 600px;
}

/* Finder-style Search */
.search-wrapper {
    position: relative;
    flex: 1;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: var(--text-secondary);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 6px 12px 6px 30px;
    /* Compact padding */
    border: 1px solid transparent;
    border-radius: 6px;
    /* Slightly tighter radius for inputs */
    background-color: rgba(118, 118, 128, 0.12);
    /* Standard Field Gray */
    color: var(--text-main);
    font-size: 13px;
    font-family: inherit;
    transition: all 0.2s var(--ease-apple);
}

#searchInput:focus {
    outline: none;
    background-color: var(--card-bg);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.3);
    /* Focus Ring */
}

/* Pull-down Button Style Select */
.filters-row {
    display: flex;
    gap: 8px;
}

select {
    padding: 4px 24px 4px 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    /* Subtle border */
    border-radius: 6px;
    background-color: var(--card-bg);
    /* White background for push buttons */
    color: var(--text-main);
    font-size: 13px;
    font-weight: 400;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%238E8E93'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
    /* Slight lift */
    transition: all 0.1s;
    height: 28px;
}

select:active {
    background-color: var(--system-gray6);
    box-shadow: none;
}

select:focus {
    outline: none;
}

.theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.1s;
}

.theme-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Main Content */
main {
    max-width: 1200px;
    margin: 32px auto;
    padding: 0 24px;
}

/* Stats Section */
.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-speed) var(--ease-apple), box-shadow var(--transition-speed) var(--ease-apple);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

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

.stat-value {
    font-size: 34px;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: -0.02em;
    margin-bottom: 2px;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Top Regions List */
.top-regions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.region-stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.region-name {
    font-weight: 400;
    color: var(--text-main);
    font-size: 14px;
}

.region-count {
    background-color: var(--system-gray6);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 500;
}

/* Segmented Control Tabs */
.region-tabs {
    display: inline-flex;
    background-color: var(--control-track);
    padding: 2px;
    border-radius: 8px;
    /* Standard segmented control radius */
    margin-bottom: 32px;
    overflow-x: auto;
    max-width: 100%;
    scrollbar-width: none;
}

.region-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 4px 12px;
    border-radius: 6px;
    /* Inner radius */
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    transition: all 0.2s var(--ease-apple);
    font-family: inherit;
    position: relative;
}

.tab-btn:hover {
    opacity: 0.8;
}

.tab-btn.active {
    background-color: var(--card-bg);
    color: var(--text-main);
    box-shadow: var(--shadow-floating);
    font-weight: 600;
}

[data-theme="dark"] .tab-btn.active {
    background-color: #636366;
    /* Dark mode selected state */
    color: white;
}

/* Lab Grid */
.labs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.lab-card {
    background-color: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-speed) var(--ease-apple);
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--border-color);
}

.lab-card:hover {
    transform: scale(1.01);
    box-shadow: var(--shadow-md);
}

.lab-header {
    margin-bottom: 12px;
}

.lab-institution {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    color: var(--system-blue);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.lab-pi {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.lab-details {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.lab-country {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 6px;
}

.lab-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--system-orange);
    /* Warm Orange Text */
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background-color: rgba(255, 149, 0, 0.1);
    /* Warm Orange Background */
    transition: all 0.2s;
}

.lab-link:hover {
    background-color: var(--system-orange);
    color: white;
    box-shadow: 0 2px 8px rgba(255, 149, 0, 0.3);
    /* Warm Glow */
}

.lab-link i {
    font-size: 14px;
    /* Slightly larger icon */
}

.lab-link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--system-gray6);
    color: var(--text-secondary);
    box-shadow: none;
}

/* Footer */
footer {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 40px;
}

/* No Results */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
    background-color: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.no-results p {
    font-size: 15px;
    font-weight: 500;
}