:root {
    --bg: #f0f2f5; --card: #ffffff; --text: #1c1e21; --accent: #e63946;
    --border: #dddfe2; --sub: #65676b; --chip-bg: #e4e6eb; --radar: #007bff;
    --bookmark: #f1c40f;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0d1117; --card: #161b22; --text: #c9d1d9; --accent: #ff4d5a;
        --border: #30363d; --sub: #8b949e; --chip-bg: #21262d; --radar: #58a6ff;
        --bookmark: #f39c12;
    }
}

* { box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background-color: var(--bg); color: var(--text); margin: 0; padding: 15px; display: flex; flex-direction: column; align-items: center; }
.container { width: 100%; max-width: 1400px; }

/* Barre de contrôles — auto-hide au scroll */
.controls {
    position: sticky; top: 10px; z-index: 1000; background: var(--card);
    padding: 15px; border-radius: 18px; border: 1px solid var(--border);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12); margin-bottom: 25px; width: 100%;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.controls.hidden {
    transform: translateY(-110%); opacity: 0; pointer-events: none;
}

/* Barre d'info (compteur + tri) */
.info-bar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px dashed var(--border);
    flex-wrap: wrap; gap: 8px;
}
.info-left { display: flex; align-items: center; gap: 8px; }
.article-count { font-size: 0.75rem; font-weight: 700; color: var(--sub); }
.sort-group { display: flex; align-items: center; gap: 6px; }
.sort-group label { font-size: 0.7rem; font-weight: 700; color: var(--sub); text-transform: uppercase; }
.sort-group select {
    padding: 4px 8px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 0.75rem; cursor: pointer;
}
.btn-bookmarks, .btn-settings {
    padding: 5px 12px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 0.75rem; font-weight: 700;
    cursor: pointer; transition: 0.2s;
}
.btn-bookmarks:hover { border-color: var(--bookmark); color: var(--bookmark); }
.btn-bookmarks.active { background: var(--bookmark); color: #000; border-color: var(--bookmark); }
.btn-settings:hover { border-color: var(--radar); color: var(--radar); }

/* Toggle hamburger (masqué desktop) */
.controls-toggle { display: none; }

/* Radar dynamique */
.radar-group { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--border); align-items: center; }
.radar-label { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; color: var(--radar); margin-right: 10px; display: flex; align-items: center; gap: 4px; }
.radar-chip {
    padding: 4px 10px; background: var(--bg); border-radius: 8px;
    cursor: pointer; font-size: 0.75rem; font-weight: 600; transition: 0.2s; border: 1px solid var(--border);
}
.radar-chip:hover { border-color: var(--radar); color: var(--radar); }
.radar-chip.active { background: var(--radar); color: white; border-color: var(--radar); }

/* Recherche */
.search-bar {
    width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); margin-bottom: 15px; font-size: 1rem;
}

/* Chips sources — scroll horizontal */
.chip-group {
    display: flex; flex-wrap: nowrap; gap: 8px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin; padding-bottom: 4px;
}
.chip-group::-webkit-scrollbar { height: 4px; }
.chip-group::-webkit-scrollbar-track { background: transparent; }
.chip-group::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chip-group::-webkit-scrollbar-thumb:hover { background: var(--sub); }
.chip {
    padding: 6px 10px 6px 12px; background: var(--chip-bg); border-radius: 25px;
    cursor: pointer; font-size: 0.8rem; font-weight: 700; display: flex;
    align-items: center; gap: 8px; transition: 0.2s; border: 1px solid transparent;
    white-space: nowrap; flex-shrink: 0;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); color: white; }
.chip img { width: 16px; height: 16px; border-radius: 3px; }
.chip-count { font-size: 0.65rem; opacity: 0.7; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: #ccc; border: 1.5px solid transparent; flex-shrink: 0; }
.dot.loading { background: #f1c40f; animation: pulse 1s infinite; }
.dot.ok { background: #2ecc71; }
.dot.err { background: #e63946; }
@keyframes pulse { 0% { opacity: 0.4; } 50% { opacity: 1; } 100% { opacity: 0.4; } }

.chip-refresh { background: rgba(0,0,0,0.05); border-radius: 50%; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; margin-left: 4px; transition: 0.2s; color: inherit; border: none; cursor: pointer; }

/* Grille d'articles */
#feed { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; width: 100%; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; height: 100%; transition: 0.3s; animation: fadeIn 0.4s ease; position: relative; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.card-img-container { position: relative; width: 100%; height: 190px; background: #222; }
.card-img { width: 100%; height: 100%; object-fit: cover; }

/* Boutons sur image (bookmark + share) */
.card-bookmark, .card-share {
    position: absolute; top: 10px; background: rgba(0,0,0,0.5); border: none;
    border-radius: 50%; width: 32px; height: 32px; cursor: pointer; display: flex;
    align-items: center; justify-content: center; font-size: 1rem; transition: 0.2s;
    color: white; backdrop-filter: blur(4px);
}
.card-bookmark { right: 10px; }
.card-share { right: 52px; }
.card-bookmark:hover, .card-share:hover { background: rgba(0,0,0,0.7); }
.card-bookmark.saved { color: var(--bookmark); background: rgba(0,0,0,0.7); }

/* Menu partage */
.share-menu {
    position: absolute; top: 50px; right: 10px; z-index: 100;
    background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    display: flex; flex-direction: column; min-width: 170px;
}
.share-option {
    padding: 8px 12px; border: none; background: none; cursor: pointer;
    color: var(--text); font-size: 0.8rem; text-align: left; border-radius: 8px;
    display: flex; align-items: center; gap: 8px;
}
.share-option:hover { background: var(--chip-bg); }

.card-body { padding: 18px; flex-grow: 1; display: flex; flex-direction: column; }
.card-source { font-size: 0.7rem; font-weight: 900; color: var(--accent); text-transform: uppercase; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.card-title { font-size: 1.1rem; font-weight: bold; text-decoration: none; color: var(--text); line-height: 1.4; margin-bottom: 15px; display: block; cursor: pointer; }
.card-title:hover { color: var(--accent); }
.card-date { font-size: 0.8rem; color: var(--sub); margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }

/* Sentinel / loader */
#sentinel { padding: 40px; text-align: center; font-weight: bold; opacity: 0.5; }

/* Notification nouveaux articles */
.new-articles-banner {
    display: none; position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--radar); color: white; padding: 10px 24px; border-radius: 25px;
    font-size: 0.85rem; font-weight: 700; cursor: pointer; z-index: 2000;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3); animation: fadeIn 0.3s ease;
}
.new-articles-banner:hover { filter: brightness(1.1); }

/* Placeholder image */
.card-img-placeholder {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--chip-bg), var(--border));
    color: var(--sub); font-size: 2rem;
}

/* === READER MODAL === */
.reader-overlay {
    display: none; position: fixed; inset: 0; z-index: 3000;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
    overflow-y: auto; padding: 20px;
}
.reader-overlay.active { display: flex; justify-content: center; align-items: flex-start; }
.reader-modal {
    background: var(--card); border-radius: 16px; max-width: 720px; width: 100%;
    padding: 32px; margin: 40px auto; position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.reader-header {
    display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
    padding-bottom: 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.reader-close {
    background: var(--chip-bg); border: none; border-radius: 50%;
    width: 40px; height: 40px; font-size: 1.5rem; cursor: pointer;
    color: var(--text); display: flex; align-items: center; justify-content: center;
    transition: 0.2s;
}
.reader-close:hover { background: var(--accent); color: white; }
.reader-source { font-size: 0.75rem; font-weight: 900; color: var(--accent); text-transform: uppercase; }
.reader-original { margin-left: auto; font-size: 0.8rem; color: var(--radar); text-decoration: none; white-space: nowrap; }
.reader-original:hover { text-decoration: underline; }
.reader-title { font-size: 1.6rem; line-height: 1.3; margin: 0 0 12px; }
.reader-date { font-size: 0.8rem; color: var(--sub); display: block; margin-bottom: 24px; }
.reader-content { line-height: 1.8; font-size: 1.05rem; }
.reader-content img { max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0; }
.reader-content a { color: var(--radar); }
.reader-content p { margin: 0 0 16px; }
.reader-content blockquote { border-left: 3px solid var(--accent); padding-left: 16px; margin: 16px 0; color: var(--sub); font-style: italic; }
.reader-content h2, .reader-content h3, .reader-content h4 { margin: 24px 0 12px; }
.reader-content figure { margin: 16px 0; }
.reader-content figcaption { font-size: 0.8rem; color: var(--sub); text-align: center; margin-top: 8px; }

/* === SETTINGS MODAL === */
.settings-overlay {
    display: none; position: fixed; inset: 0; z-index: 3000;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
    overflow-y: auto; padding: 20px;
}
.settings-overlay.active { display: flex; justify-content: center; align-items: flex-start; }
.settings-modal {
    background: var(--card); border-radius: 16px; max-width: 520px; width: 100%;
    padding: 28px; margin: 40px auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.settings-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.settings-header h2 { font-size: 1.1rem; margin: 0; }
.settings-close {
    background: var(--chip-bg); border: none; border-radius: 50%;
    width: 36px; height: 36px; font-size: 1.3rem; cursor: pointer;
    color: var(--text); display: flex; align-items: center; justify-content: center;
}
.settings-close:hover { background: var(--accent); color: white; }
.settings-hint { font-size: 0.8rem; color: var(--sub); margin-bottom: 16px; line-height: 1.5; }
.add-feed-form {
    display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px;
    padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.add-feed-form input {
    padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 0.9rem;
}
.btn-add-feed {
    padding: 10px; border-radius: 10px; border: none; background: var(--radar);
    color: white; font-weight: 700; font-size: 0.85rem; cursor: pointer; transition: 0.2s;
}
.btn-add-feed:hover { filter: brightness(1.1); }
.custom-feeds-list { display: flex; flex-direction: column; gap: 8px; }
.custom-feed-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; background: var(--bg); border-radius: 10px;
    border: 1px solid var(--border);
}
.custom-feed-info { flex: 1; min-width: 0; }
.custom-feed-name { font-weight: 700; font-size: 0.85rem; }
.custom-feed-url { font-size: 0.7rem; color: var(--sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-feed-delete {
    background: none; border: none; color: var(--accent); cursor: pointer;
    font-size: 1.1rem; padding: 4px 8px; flex-shrink: 0;
}

/* === MOBILE === */
@media (max-width: 768px) {
    body { padding: 8px; }

    .controls { padding: 10px; border-radius: 12px; top: 5px; }

    .controls-toggle {
        display: flex; flex-direction: column; gap: 4px;
        background: none; border: none; cursor: pointer; padding: 8px;
        width: 36px; height: 36px; align-items: center; justify-content: center;
    }
    .controls-toggle span {
        display: block; width: 20px; height: 2px; background: var(--text);
        border-radius: 2px; transition: 0.3s;
    }

    .controls.collapsed .collapsible-controls { display: none; }
    .controls.collapsed .info-bar { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

    .chip-group { scrollbar-width: none; }
    .chip-group::-webkit-scrollbar { display: none; }
    .chip { padding: 8px 12px; min-height: 40px; }

    .radar-chip { padding: 6px 12px; min-height: 36px; display: inline-flex; align-items: center; }

    #feed { grid-template-columns: 1fr; gap: 12px; }
    .card-img-container { height: 160px; }

    .card-bookmark, .card-share { width: 40px; height: 40px; }
    .card-share { right: 58px; }

    .btn-bookmarks, .btn-settings { min-height: 36px; padding: 6px 10px; }
    .sort-group select { min-height: 36px; padding: 6px 10px; }
    .chip-refresh { width: 28px; height: 28px; }

    .reader-overlay { padding: 0; }
    .reader-modal { border-radius: 16px 16px 0 0; min-height: 100vh; padding: 20px; margin: 40px 0 0; }
    .reader-title { font-size: 1.3rem; }
    .reader-content { font-size: 0.95rem; }

    .settings-overlay { padding: 0; }
    .settings-modal { border-radius: 16px 16px 0 0; margin: 40px 0 0; padding: 20px; }
}
