/* =========================================================
   THEME VARIABLES (LIGHT MODE DEFAULT)
   ========================================================= */

:root {
    --bg: #f5f7fb;
    --bg-alt: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-soft: #e0edff;
    --border: #e5e7eb;
    --card-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

/* =========================================================
   MANUAL DARK MODE
   ========================================================= */

body.dark {
    --bg: #0f172a;
    --bg-alt: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --accent: #3b82f6;
    --accent-soft: #1e293b;
    --border: #1f2937;
    --card-shadow: 0 10px 24px rgba(0, 0, 0, 0.6);
}

/* =========================================================
   AUTO DARK MODE
   ========================================================= */

@media (prefers-color-scheme: dark) {
    body:not(.light) {
        --bg: #0f172a;
        --bg-alt: #111827;
        --text: #e5e7eb;
        --muted: #9ca3af;
        --accent: #3b82f6;
        --accent-soft: #1e293b;
        --border: #1f2937;
        --card-shadow: 0 10px 24px rgba(0, 0, 0, 0.6);
    }
}

/* =========================================================
   MANUAL LIGHT MODE OVERRIDE
   ========================================================= */

body.light {
    --bg: #f5f7fb;
    --bg-alt: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-soft: #e0edff;
    --border: #e5e7eb;
    --card-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

/* =========================================================
   GLOBAL
   ========================================================= */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* =========================================================
   HEADER (sticky desktop)
   ========================================================= */

.sticky-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--bg);
}

.header {
    padding: 1.8rem 1.5rem 1rem;
    max-width: 1100px;
    margin: 0 auto;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-top {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.2rem;
    margin-bottom: 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.9;
    white-space: nowrap; /* desktop */
}

.header-top .stat {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.stats-badge {
    margin-bottom: 10px;
    padding: 6px 10px;
    border-radius: 6px;
    background: #1e293b;
    color: #e5e7eb;
    font-size: 0.9rem;
}

.header h1 {
    margin: 0;
    font-size: 1.8rem;
    letter-spacing: 0.03em;
}

.subtitle {
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

/* =========================================================
   CONTROLS
   ========================================================= */

.controls {
    max-width: 1100px;
    margin: 0 auto 0.5rem;
    padding: 0 1.5rem 0.8rem;
    border-bottom: 1px solid var(--border);
}

.controls-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 0.6rem;
}

.control-group {
    flex: 1 1 260px;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.control-group label,
.control-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

/* =========================================================
   INPUTS & SELECTS
   ========================================================= */

input[type="text"],
select {
    padding: 0.45rem 0.6rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    color: var(--text);
    font-size: 0.9rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-soft);
}

select:hover {
    border-color: var(--accent);
}

/* =========================================================
   CHIPS
   ========================================================= */

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.2rem;
}

.chip {
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    color: var(--muted);
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

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

.chip-active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

/* =========================================================
   BUTTONS
   ========================================================= */

.topbar-buttons {
    display: flex;
    gap: 0.5rem;
}

.lang-btn {
    padding: 8px 14px;
    background-color: #333;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.lang-btn:hover {
    background-color: #444;
}

/* =========================================================
   CONTAINER & GRID
   ========================================================= */

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.8rem 1.5rem 2rem;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

/* =========================================================
   PAPER CARDS
   ========================================================= */

.paper-card {
    background: var(--bg-alt);
    border-radius: 0.9rem;
    padding: 1.8rem 0.9rem 0.8rem;
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(148, 163, 184, 0.25);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    position: relative;
    overflow: hidden;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.paper-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
    border-color: rgba(59, 130, 246, 0.4);
}

.paper-card h2 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.3;
}

.paper-card .date {
    font-size: 0.8rem;
    color: var(--muted);
}

.paper-card p {
    margin: 0.2rem 0 0;
    font-size: 0.9rem;
    color: var(--text);
}

.paper-card a {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
}

.paper-card a:hover {
    text-decoration: underline;
}

/* =========================================================
   BADGES
   ========================================================= */

.source-badge {
    position: absolute;
    top: 0.6rem;
    right: 0.7rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(248, 250, 252, 0.9);
    color: var(--muted);
}

body.dark .source-badge {
    background: rgba(15, 23, 42, 0.9);
}

.subject-badge {
    position: absolute;
    top: 0.6rem;
    left: 0.7rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    color: var(--muted);
}

body.dark .subject-badge {
    background: rgba(15, 23, 42, 0.9);
}

/* =========================================================
   FOOTER
   ========================================================= */

.footer {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.5rem 1.5rem 1.2rem;
    font-size: 0.8rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

/* =========================================================
   RESPONSIVE — MOBIEL VS DESKTOP
   ========================================================= */

@media (max-width: 640px) {

    .sticky-header {
        position: static !important;
    }

    .header-top {
        flex-wrap: wrap;
		flex-direction: row;
        white-space: normal;
    }

    .controls,
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .content {
        margin-top: 0;
    }
}

@media (min-width: 641px) {
    .sticky-header {
        position: sticky;
        top: 0;
    }

    .header-top {
        flex-direction: row;
        white-space: nowrap;
    }
}

.category-link {
    cursor: pointer;
    user-select: none;
}

.category-link:hover {
    opacity: 0.7;
}

.hidden {
    display: none !important;
}

/* =========================================================
   COMPACT HEADER (mechanism stats)
   ========================================================= */

#mechanism-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    font-size: 0.9rem;
    line-height: 1.3;
    padding: 0.4rem 0 0.2rem;
    opacity: 0.95;
}

/* Stats badge (updated + total) */
.stats-badge {
    font-size: 0.85rem;
    margin-top: 0.2rem;
    opacity: 0.85;
}

/* Header row (title + buttons) */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.4rem;
}

/* Subtitle */
.subtitle {
    margin-top: 0.3rem;
    font-size: 0.85rem;
    opacity: 0.8;
}

/* Sticky header */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--bg);
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}

/* Mobile tweaks */
@media (max-width: 640px) {
    #mechanism-stats {
        font-size: 0.85rem;
        gap: 0.4rem;
    }

    .header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .topbar-buttons {
        align-self: flex-end;
    }
}
