:root {
    /* Default - Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-card: rgba(255, 255, 255, 0.7);
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #007aff;
    --accent-gradient: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
    --border: rgba(0, 0, 0, 0.1);
    --success: #34c759;
    --error: #ff3b30;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --radius-lg: 16px;
    --radius-md: 12px;
    --spacing-unit: 8px;
}

/* Automatic Dark Mode */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #000000;
        --bg-secondary: #1c1c1e;
        --bg-card: rgba(28, 28, 30, 0.7);
        --text-primary: #f5f5f7;
        --text-secondary: #a1a1a6;
        --accent: #0a84ff;
        --accent-gradient: linear-gradient(135deg, #0a84ff 0%, #5e5ce6 100%);
        --border: rgba(255, 255, 255, 0.1);
        --success: #32d74b;
        --error: #ff453a;
        --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    }
}

/* Explicit Themes */
[data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-card: rgba(28, 28, 30, 0.7);
    --text-primary: #f5f5f7;
    --text-secondary: #a1a1a6;
    --accent: #0a84ff;
    --accent-gradient: linear-gradient(135deg, #0a84ff 0%, #5e5ce6 100%);
    --border: rgba(255, 255, 255, 0.1);
    --success: #32d74b;
    --error: #ff453a;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-card: rgba(255, 255, 255, 0.7);
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #007aff;
    --accent-gradient: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
    --border: rgba(0, 0, 0, 0.1);
    --success: #34c759;
    --error: #ff3b30;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background-color 0.3s, color 0.3s;
}

.mesh-bg {
    display: none; /* Clean Notion/Apple style doesn't need heavy mesh */
}

@keyframes pulse {
    0% { opacity: 0.5; }
    100% { opacity: 1; }
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: calc(var(--spacing-unit) * 6) calc(var(--spacing-unit) * 3);
}

/* Header */
.hero {
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

.header-top {
    position: absolute;
    top: -20px;
    right: 0;
}

.theme-switcher {
    padding: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.theme-switcher .moon { display: none; }
.theme-switcher .sun { display: block; }

[data-theme="dark"] .theme-switcher .sun { display: none; }
[data-theme="dark"] .theme-switcher .moon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-switcher .sun { display: none; }
    :root:not([data-theme="light"]) .theme-switcher .moon { display: block; }
}

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.gradient-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    max-width: 600px;
    margin: 0 auto;
}

/* Glass Cards */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: calc(var(--spacing-unit) * 4);
    box-shadow: var(--shadow);
}

.glass-card:hover {
    transform: translateY(-4px);
}

/* Inputs (Supabase/Notion Style) */
.input-group {
    margin-bottom: calc(var(--spacing-unit) * 2.5);
}

label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: calc(var(--spacing-unit) * 0.75);
    letter-spacing: 0.02em;
}

input, select {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 2);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-wrapper input {
    padding-right: calc(var(--spacing-unit) * 6); /* Space for the eye icon */
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
}

.models-status-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: calc(var(--spacing-unit) * 1) calc(var(--spacing-unit) * 1.5);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.text-link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    transition: opacity 0.2s;
}

.text-link-btn:hover {
    opacity: 0.8;
}

.icon-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: color 0.2s;
}

.icon-btn:hover {
    color: white;
}

.grid-inputs {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* Buttons */
.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: calc(var(--spacing-unit) * 1.5);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1);
}

.secondary-btn {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: calc(var(--spacing-unit) * 1.5);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
    .secondary-btn:hover {
        background: rgba(255, 255, 255, 0.05);
    }
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}
.status-dot.success { background: var(--success); box-shadow: 0 0 10px var(--success); }
.status-dot.error { background: var(--error); }
.status-dot.loading { background: var(--accent); animation: pulse-dot 1s infinite; }

@keyframes pulse-dot {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

.reasoning-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.75rem;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: #a5b4fc;
}

.reasoning-box summary {
    cursor: pointer;
    font-weight: 600;
    margin-bottom: 0.5rem;
    user-select: none;
}

audio {
    width: 100%;
    height: 32px;
    margin-top: 1rem;
    border-radius: 8px;
    filter: invert(1) hue-rotate(180deg); /* Style it for dark mode */
}

.model-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: calc(var(--spacing-unit) * 3);
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 2);
    transition: box-shadow 0.2s;
    box-shadow: var(--shadow);
}

.model-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.model-card.success { border-top: 3px solid var(--success); }
.model-card.error { border-top: 3px solid var(--error); }
.model-card.loading { border-top: 3px solid var(--accent); opacity: 0.7; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.model-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.latency-badge {
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
}

.card-body {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.card-footer {
    margin-top: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 4px;
    max-height: 100px;
    overflow-y: auto;
}

.result-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: calc(var(--spacing-unit) * 3);
    margin-top: calc(var(--spacing-unit) * 4);
    width: 100%;
}

.empty-state-full {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem;
    color: var(--text-secondary);
    border: 2px dashed var(--border);
    border-radius: 24px;
}

/* Loader */
.loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    display: none;
}

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

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

/* Responsive */
@media (max-width: 1000px) {
    .result-cards-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .grid-inputs {
        grid-template-columns: 1fr;
    }
    h1 { font-size: 2.5rem; }
}

/* Glass Modal */
.glass-modal {
    border: none;
    background: none;
    padding: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

.glass-modal::backdrop {
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    backdrop-filter: blur(32px);
    -webkit-backdrop-filter: blur(32px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 440px;
    max-height: 70vh;
    padding: calc(var(--spacing-unit) * 3);
    display: flex;
    flex-direction: column;
    box-shadow: 0 32px 64px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: calc(var(--spacing-unit) * 3);
    padding-bottom: calc(var(--spacing-unit) * 2);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
}

#close-modal {
    position: relative;
    right: 0;
    top: 0;
    transform: none;
    font-size: 1.5rem;
    padding: 0;
    width: 32px;
    height: 32px;
    justify-content: center;
}

.modal-body {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 1.5);
    padding-right: 8px; /* Space for scrollbar */
}

/* Custom Scrollbar */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.model-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: calc(var(--spacing-unit) * 2);
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: default;
}

.model-item:hover {
    background: var(--bg-primary);
    border-color: var(--accent);
    transform: translateX(4px);
    box-shadow: var(--shadow);
}

[data-theme="dark"] .model-item {
    background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .model-item:hover {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.model-item .m-id {
    font-family: 'SF Mono', 'Courier New', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.03em;
    text-transform: lowercase;
}

[data-theme="light"] .model-item .m-id {
    color: #0056b3; /* Deeper blue for better light-mode contrast */
}

.model-item .m-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    margin-top: 2px;
}

.footer {
    margin-top: auto;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}
