:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --surface-2: #f2f4f7;
    --text: #14161a;
    --muted: #5f6672;
    --faint: #c9ced6;
    --border: #e1e4ea;
    --accent: #4f46e5;
    --accent-2: #06b6d4;
    --on-accent: #ffffff;
    --score-high-bg: #eeedfe;
    --score-high-text: #3c3489;
    --score-medium-bg: #e1f5ee;
    --score-medium-text: #085041;
    --grid: #d9dde4;
    --radius: 10px;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --surface: #171a20;
        --surface-2: #1e222a;
        --text: #e8eaee;
        --muted: #9aa1ad;
        --faint: #3a404b;
        --border: #2a2f38;
        --accent: #818cf8;
        --accent-2: #22d3ee;
        --on-accent: #0f1115;
        --score-high-bg: #3c3489;
        --score-high-text: #cecbf6;
        --score-medium-bg: #085041;
        --score-medium-text: #9fe1cb;
        --grid: #232831;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

.container {
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 16px;
    flex: 1;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.icon {
    flex: none;
    vertical-align: -1px;
}

/* En-tête et logo */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1040px;
    width: 100%;
    margin: 0 auto;
    padding: 16px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.brand-org {
    font-family: var(--mono);
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    padding-right: 10px;
    border-right: 1px solid var(--border);
}

.brand-name {
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: -0.01em;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.lang-switch a {
    margin-left: 12px;
    color: var(--muted);
    text-decoration: none;
    font-family: var(--mono);
    font-size: 0.8rem;
}

.lang-switch a[aria-current="true"] {
    color: var(--text);
    font-weight: 600;
}

/* Accueil */

.hero {
    position: relative;
    isolation: isolate;
    padding: 56px 0 40px;
    text-align: center;
}

.hero::before {
    content: "";
    position: absolute;
    inset: 0 -16px;
    z-index: -1;
    background-image: radial-gradient(var(--grid) 1px, transparent 1px);
    background-size: 20px 20px;
    -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
    mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
}

.hero h1 {
    font-size: clamp(1.6rem, 5vw, 2.4rem);
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 0 0 12px;
}

.lead {
    color: var(--muted);
    max-width: 60ch;
    margin: 0 auto 32px;
}

/* Formulaire de recherche */

.search-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 680px;
    margin: 0 auto;
}

.search-form input,
.search-form select,
.search-form button,
.filter-text {
    font: inherit;
    padding: 11px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.search-form input {
    flex: 1;
}

.search-form button {
    background: linear-gradient(90deg, var(--accent), #3b82f6);
    border: 0;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.search-form button:hover {
    filter: brightness(1.08);
}

@media (min-width: 640px) {
    .search-form {
        flex-direction: row;
    }
}

/* Résultats */

.results-header {
    padding: 8px 0;
}

.results h1 {
    font-size: 1.2rem;
    margin: 24px 0 4px;
}

.results-meta {
    color: var(--muted);
    font-size: 0.875rem;
    margin: 0 0 12px;
}

.notice {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid #d97706;
    border-radius: 0;
    padding: 10px 14px;
    margin: 16px 0 0;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 16px 0 10px;
}

.toolbar-sep {
    width: 1px;
    height: 22px;
    background: var(--border);
}

.filter-text {
    padding: 6px 12px;
    font-size: 0.875rem;
    flex: 0 1 220px;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Filtre inactif : neutre et discret. Actif : rempli de l'accent, avec une coche. */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-size: 0.82rem;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

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

.chip-count {
    font-family: var(--mono);
    font-size: 0.75rem;
    opacity: 0.75;
}

.chip-check {
    display: none;
}

.chip[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.chip[aria-pressed="true"] .chip-check {
    display: inline;
}

.actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.actions-spacer {
    flex: 1;
}

.selection-status {
    font-size: 0.8rem;
    color: var(--muted);
    font-family: var(--mono);
}

.link-button {
    font: inherit;
    font-size: 0.8rem;
    color: var(--accent);
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.link-button:hover {
    text-decoration: underline;
}

.button-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

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

.table-wrap {
    /* Défilement interne : l'en-tête du tableau reste visible. */
    max-height: 75vh;
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.results-table th,
.results-table td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.results-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.results-table tbody tr:last-child td {
    border-bottom: 0;
}

.results-table tbody tr[data-row]:hover {
    background: var(--surface-2);
}

.results-table tr.is-selected,
.results-table tr.is-selected:hover {
    background: color-mix(in srgb, var(--accent) 9%, transparent);
}

.sort {
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.sort[data-direction="asc"]::after {
    content: " ↑";
}

.sort[data-direction="desc"]::after {
    content: " ↓";
}

.col-check {
    width: 32px;
}

.col-score {
    width: 64px;
}

.col-intent {
    white-space: nowrap;
    width: 1%;
}

/* Score : badge à chasse fixe, teinté selon trois niveaux (voir Keyword::getScoreLevel()). */
.score {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 26px;
    padding: 0 6px;
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 0.9rem;
    font-weight: 600;
}

.score-high { background: var(--score-high-bg); color: var(--score-high-text); }
.score-medium { background: var(--score-medium-bg); color: var(--score-medium-text); }
.score-low { background: var(--surface-2); color: var(--muted); }

.kw-seed {
    color: var(--muted);
}

.kw-new {
    font-weight: 600;
}

.place {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 10px;
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
}

/* Intention : une pastille de couleur et un libellé, plus discrets que le score. */
.intent {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.intent::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--intent-color);
}

.intent-informational { --intent-color: #1d9e75; }
.intent-commercial { --intent-color: #ba7517; }
.intent-transactional { --intent-color: #7f77dd; }
.intent-navigational { --intent-color: #888780; }

.discarded {
    margin: 24px 0 8px;
}

.discarded summary {
    cursor: pointer;
    color: var(--muted);
    margin-bottom: 8px;
}

@media (max-width: 640px) {
    .results-table th,
    .results-table td {
        padding: 6px 8px;
    }

    .filter-text {
        max-width: none;
    }
}

/* Pages de contenu */

.prose {
    max-width: 720px;
    padding: 24px 0 40px;
}

.prose h1 {
    font-size: 1.6rem;
    letter-spacing: -0.01em;
}

.prose h2 {
    font-size: 1.05rem;
    margin-top: 28px;
}

.prose p,
.prose li {
    color: var(--muted);
}

/* Pied de page */

.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
    padding: 24px 16px;
}

.site-footer a {
    color: inherit;
}

/* Structure suggérée */

.toolbar-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-right: 4px;
}

.structure {
    margin: 32px 0 8px;
}

.structure h2 {
    font-size: 1.1rem;
    margin: 0 0 4px;
}

.tree {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
}

.tree-root {
    margin: 0 0 8px;
    font-weight: 700;
    font-size: 1rem;
}

.tree ul {
    list-style: none;
    margin: 0;
    padding-left: 18px;
    border-left: 1px solid var(--border);
}

.tree > ul {
    margin-left: 6px;
}

.tree li {
    margin: 6px 0;
}

.tree li li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.tree summary {
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.tree-topic {
    font-weight: 600;
}

.tree-meta {
    font-size: 0.8rem;
    color: var(--muted);
    font-family: var(--mono);
}

.tree .score {
    min-width: 34px;
    height: 22px;
    font-size: 0.8rem;
}

.chip-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--intent-color);
}

.chip[aria-pressed="true"] .chip-dot {
    display: none;
}

/* Cartes de thème : compactes, cliquables comme les filtres. */

.topics {
    margin: 4px 0 12px;
}

.topics-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: 8px;
}

.topic-card {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font: inherit;
    text-align: left;
    padding: 8px 11px 9px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.topic-card:hover {
    border-color: var(--faint);
}

.topic-card[aria-pressed="true"] {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.topic-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.topic-name {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topic-count,
.topic-stats {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--muted);
}

.topic-stats {
    display: flex;
    gap: 10px;
    white-space: nowrap;
}

.topic-bar {
    display: flex;
    height: 4px;
    border-radius: 2px;
    overflow: hidden;
    background: var(--surface-2);
}

.topic-bar span {
    background: var(--intent-color);
}

/* Structure suggérée : les scores faibles sont estompés, et peuvent être masqués. */

.structure-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.structure-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--muted);
    cursor: pointer;
}

.tree li.is-low {
    opacity: 0.5;
}

.tree.hide-low li.is-low,
.tree.hide-low li[data-strong="0"] {
    display: none;
}

/* Chargement : barre de progression, indicateur sur le bouton, résultats actuels estompés. */

body.is-loading::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;
    width: 35%;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    animation: loading-bar 1.4s ease-in-out infinite;
}

body.is-loading .results,
body.is-loading .notice {
    filter: blur(2px);
    opacity: 0.45;
    pointer-events: none;
    transition: filter 0.3s, opacity 0.3s;
}

.search-form button.is-loading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    opacity: 0.9;
    cursor: progress;
}

.search-form button.is-loading::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgb(255 255 255 / 0.35);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

@keyframes loading-bar {
    from { transform: translateX(-100%); }
    to { transform: translateX(300%); }
}

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

@media (prefers-reduced-motion: reduce) {
    body.is-loading::before,
    .search-form button.is-loading::before {
        animation: none;
    }

    body.is-loading::before {
        width: 100%;
    }
}
