/* ============================================================
   Winning Products Finder - Distinctive Editorial Aesthetic
   Mixing refined editorial typography with bold geometric accents
   ============================================================ */

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

/* ===== Theme Variables ===== */
[data-theme="dark"] {
    --bg-primary: #0a0a0b;
    --bg-secondary: #131316;
    --bg-tertiary: #1c1c21;
    --bg-elevated: #232329;
    --bg-card: #18181d;

    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --text-muted: #52525b;

    --border-subtle: #27272a;
    --border-strong: #3f3f46;

    --accent: #f97316;
    --accent-hover: #fb923c;
    --accent-soft: rgba(249, 115, 22, 0.12);

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

    --grain-opacity: 0.03;
}

[data-theme="light"] {
    --bg-primary: #fafaf7;
    --bg-secondary: #f4f4ed;
    --bg-tertiary: #eaeae0;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;

    --text-primary: #18181b;
    --text-secondary: #3f3f46;
    --text-tertiary: #71717a;
    --text-muted: #a1a1aa;

    --border-subtle: #e4e4e0;
    --border-strong: #d4d4d0;

    --accent: #ea580c;
    --accent-hover: #c2410c;
    --accent-soft: rgba(234, 88, 12, 0.08);

    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);

    --grain-opacity: 0.02;
}

/* ===== Base ===== */
html {
    font-size: 16px;
}

body {
    font-family: 'Outfit', system-ui, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Subtle grain texture for depth */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1000;
    opacity: var(--grain-opacity);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

h1 { font-size: 3rem; font-weight: 300; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }

.mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
    letter-spacing: -0.01em;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--accent-hover);
}

/* ===== Layout ===== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.main-content {
    margin-left: 240px;
    padding: 2.5rem 3rem;
    min-height: 100vh;
    max-width: 1400px;
}

/* ===== Sidebar ===== */
.sidebar-header {
    padding: 0.5rem 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 1.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
}

.logo-mark {
    font-size: 1.5rem;
    color: var(--accent);
    transform: rotate(45deg);
    display: inline-block;
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.logo-text strong {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.logo-text em {
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-weight: 300;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem 0.875rem;
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 400;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.nav-item-primary {
    background: var(--accent-soft);
    color: var(--accent);
    margin: 0.25rem 0;
}

.nav-item-primary:hover {
    background: var(--accent);
    color: white;
}

.nav-item-primary.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.nav-icon {
    font-size: 1.1rem;
    width: 1.25rem;
    text-align: center;
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: none; }

.logout-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* ===== Page Header ===== */
.page-header {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
}

.page-eyebrow {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

.page-title {
    font-size: 2.5rem;
    font-weight: 300;
    line-height: 1.1;
    margin-bottom: 0.5rem;
}

.page-title em {
    font-style: italic;
    font-weight: 400;
    color: var(--accent);
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: 600px;
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
    pointer-events: none;
}

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

.stat-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-tertiary);
    margin-bottom: 0.75rem;
}

.stat-value {
    font-family: 'Fraunces', serif;
    font-size: 2.5rem;
    font-weight: 300;
    line-height: 1;
    color: var(--text-primary);
}

.stat-trend {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-tertiary);
}

/* ===== Cards & Sections ===== */
.section {
    margin-bottom: 2.5rem;
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.section-title {
    font-family: 'Fraunces', serif;
    font-size: 1.25rem;
    font-weight: 500;
}

.section-title em {
    font-style: italic;
    color: var(--text-tertiary);
    font-weight: 400;
}

.section-link {
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

.section-link:hover {
    color: var(--accent);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.btn-secondary:hover {
    border-color: var(--border-strong);
    background: var(--bg-elevated);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1rem;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* ===== Source Cards (checkbox style) ===== */
.source-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.source-card {
    cursor: pointer;
    user-select: none;
}

.source-card input {
    display: none;
}

.source-card-inner {
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    transition: all 0.2s ease;
    height: 100%;
}

.source-card:hover .source-card-inner {
    border-color: var(--border-strong);
}

.source-card input:checked + .source-card-inner {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.source-card-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.source-card-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.source-card-desc {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* ===== Product Cards ===== */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
}

.product-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.product-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--bg-tertiary);
}

.product-body {
    padding: 1.25rem;
}

.product-source {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-tertiary);
    padding: 0.25rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
    margin-bottom: 0.75rem;
}

.product-title {
    font-family: 'Fraunces', serif;
    font-size: 1.05rem;
    font-weight: 500;
    line-height: 1.3;
    margin-bottom: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-score {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.score-value {
    font-family: 'Fraunces', serif;
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1;
}

.score-value.high { color: var(--success); }
.score-value.medium { color: var(--warning); }
.score-value.low { color: var(--text-tertiary); }

.score-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
}

.product-pricing {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 1rem;
}

.price-block {
    display: flex;
    flex-direction: column;
}

.price-label {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.price-value {
    font-family: 'Fraunces', serif;
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 0.25rem;
}

.price-value.success { color: var(--success); }

.product-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.action-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.action-btn.favorited {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
}

/* ===== Tables ===== */
.data-table {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: hidden;
}

.data-table table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-tertiary);
    text-align: left;
    padding: 1rem;
    background: var(--bg-tertiary);
    font-weight: 500;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.9rem;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover {
    background: var(--bg-tertiary);
}

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 100px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-neutral {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* ===== Flash Messages ===== */
.flash {
    padding: 1rem 1.25rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid;
}

.flash-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    color: var(--danger);
}

.flash-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success);
    color: var(--success);
}

/* ===== Auth (Login Page) ===== */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: "";
    position: absolute;
    top: -10%;
    right: -10%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, var(--accent-soft) 0%, transparent 60%);
    pointer-events: none;
}

.auth-container::after {
    content: "";
    position: absolute;
    bottom: -10%;
    left: -10%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, var(--accent-soft) 0%, transparent 60%);
    pointer-events: none;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    padding: 3rem 2.5rem;
    position: relative;
    z-index: 2;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
}

.auth-logo-mark {
    font-size: 2.5rem;
    color: var(--accent);
    transform: rotate(45deg);
    margin-bottom: 1rem;
}

.auth-title {
    font-family: 'Fraunces', serif;
    font-size: 1.75rem;
    font-weight: 300;
    margin-bottom: 0.25rem;
}

.auth-title em {
    font-style: italic;
    color: var(--accent);
}

.auth-subtitle {
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

/* ===== Progress Bar ===== */
.progress-container {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
}

.progress-bar-wrap {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 100px;
    overflow: hidden;
    margin: 1.5rem 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover));
    transition: width 0.5s ease;
    border-radius: 100px;
}

.progress-percentage {
    font-family: 'Fraunces', serif;
    font-size: 3rem;
    font-weight: 300;
    color: var(--accent);
}

/* ===== Animations ===== */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeUp 0.5s ease forwards;
}

.animate-in:nth-child(1) { animation-delay: 0.05s; }
.animate-in:nth-child(2) { animation-delay: 0.1s; }
.animate-in:nth-child(3) { animation-delay: 0.15s; }
.animate-in:nth-child(4) { animation-delay: 0.2s; }
.animate-in:nth-child(5) { animation-delay: 0.25s; }
.animate-in:nth-child(6) { animation-delay: 0.3s; }

/* ===== Empty States ===== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-tertiary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.empty-title {
    font-family: 'Fraunces', serif;
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }

    .main-content {
        margin-left: 0;
        padding: 1.5rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .page-title {
        font-size: 2rem;
    }
}
