:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #dde1e8;
    --text: #1c2230;
    --muted: #677084;
    --primary: #4f6bed;
    --primary-text: #ffffff;
    --danger: #c9354a;
    --warn: #b76a00;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);

    --st-en_cours: #4f6bed;
    --st-test: #8b5cf6;
    --st-idee: #0e9f9a;
    --st-production: #1f9d55;
    --st-pause: #c98a00;
    --st-archive: #8a93a5;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151c;
        --surface: #1b1f28;
        --surface-2: #242a35;
        --border: #313846;
        --text: #e4e7ee;
        --muted: #98a0b3;
        --primary: #7189ff;
        --primary-text: #0d1020;
        --danger: #ff6b81;
        --warn: #f0a940;
        --shadow: none;

        --st-en_cours: #7189ff;
        --st-test: #a78bfa;
        --st-idee: #2cc6c0;
        --st-production: #3fc27a;
        --st-pause: #e0a526;
        --st-archive: #8a93a5;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; margin-bottom: .6rem; }
h3 { font-size: .98rem; }
h1 small, h2 small { font-size: .6em; color: var(--muted); font-weight: 500; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 48px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text { overflow-wrap: anywhere; }
.text p { margin: 0 0 .5em; }

/* ---------------------------------------------------------------- Barre du haut */

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.search { flex: 1; min-width: 140px; }
.search input { width: 100%; max-width: 320px; }
.logout { color: var(--muted); font-size: .9rem; }

/* ---------------------------------------------------------------- Formulaires et boutons */

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 7px 10px;
    min-width: 0;
}
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }

.btn {
    display: inline-block;
    font: inherit;
    font-weight: 600;
    font-size: .9rem;
    padding: 7px 14px;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; font-size: .85rem; color: var(--primary); cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }
form.inline { display: inline; margin: 0; }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }
.form .span-2 { grid-column: span 2; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; margin-bottom: 20px; }
.inline-form .grow { flex: 1 1 220px; }
.inline-form .full { flex: 1 1 100%; }

.flash { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); padding: 10px 14px; border-radius: 7px; margin-bottom: 20px; }
.error { color: var(--danger); }

/* ---------------------------------------------------------------- Cartes et mise en page */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }

.page-head { margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.project-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; align-items: center; }
.breadcrumb { font-size: .85rem; color: var(--muted); margin: 0 0 4px !important; }
.objective { color: var(--muted); margin: 6px 0 0; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .btn { margin-top: 8px; }

/* ---------------------------------------------------------------- Badges */

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; white-space: nowrap; border: 1px solid currentColor; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: currentColor; }

.st-en_cours { color: var(--st-en_cours); }
.st-test { color: var(--st-test); }
.st-idee { color: var(--st-idee); }
.st-production { color: var(--st-production); }
.st-pause { color: var(--st-pause); }
.st-archive { color: var(--st-archive); }

.prio { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }
.prio-1 { background: var(--danger); color: var(--surface); }
.prio-3 { opacity: .7; }
.kind { font-size: .75rem; color: var(--muted); }
.kind-bug { color: var(--danger); font-weight: 600; }

.tag { display: inline-block; font-size: .8rem; padding: 1px 8px; border-radius: 5px; background: var(--surface-2); margin: 0 4px 4px 0; }
.count { font-size: .78rem; color: var(--muted); font-weight: 500; }

/* ---------------------------------------------------------------- Tableau de bord */

.filters { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .85rem; }
.chip:hover { text-decoration: none; background: var(--surface-2); }
.chip.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.project-card { display: flex; flex-direction: column; gap: 8px; color: var(--text); border-top: 4px solid; transition: transform .12s, box-shadow .12s; }
.project-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 6px 18px rgba(20, 30, 50, .1); }
.st-border-en_cours { border-top-color: var(--st-en_cours); }
.st-border-test { border-top-color: var(--st-test); }
.st-border-idee { border-top-color: var(--st-idee); }
.st-border-production { border-top-color: var(--st-production); }
.st-border-pause { border-top-color: var(--st-pause); }
.st-border-archive { border-top-color: var(--st-archive); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.type { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.project-card h2 { margin: 0; font-size: 1.15rem; }
.project-card .objective { margin: 0; font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .82rem; flex-wrap: wrap; }
.stale { color: var(--warn); font-weight: 600; }
.indicators { display: flex; gap: 6px; }
.ind { padding: 1px 7px; border-radius: 5px; font-weight: 600; font-size: .75rem; }
.ind-urgent { background: var(--danger); color: var(--surface); }
.ind-bug { border: 1px solid var(--danger); color: var(--danger); }

/* <progress> stylé pour Chrome, Firefox et Safari */
.progress { flex: 1; height: 8px; border: 0; border-radius: 99px; background: var(--surface-2); overflow: hidden; appearance: none; -webkit-appearance: none; min-width: 60px; }
.progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 99px; }
.progress::-webkit-progress-value { background: var(--primary); border-radius: 99px; }
.progress::-moz-progress-bar { background: var(--primary); border-radius: 99px; }
.progress-label { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ---------------------------------------------------------------- Fiche projet */

.tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }

.overview { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.facts dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: .9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; overflow-wrap: anywhere; }
.facts dd.tags { display: block; }
.plain-list { margin: 0 0 8px; padding: 0; list-style: none; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.danger-zone { margin-top: 32px; text-align: right; }

.kanban { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: 12px; min-height: 120px; }
.column h2 { font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.task { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.task h3 { margin: 4px 0; overflow-wrap: anywhere; }
.task-done h3 { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; gap: 8px; align-items: center; }
.task-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.task p { margin: 4px 0 0; }

.link-group { margin-bottom: 24px; }
.links { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.links li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.links li:last-child { border-bottom: 0; }
.links p { margin: 2px 0 0; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 20px 14px; }
.timeline li::before { content: ""; position: absolute; left: -25px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid var(--bg); }
.timeline time { font-weight: 700; font-size: .9rem; display: block; margin-bottom: 2px; }

.notes { columns: 3 280px; column-gap: 16px; }
.note { break-inside: avoid; margin-bottom: 16px; }
.note footer { display: flex; justify-content: space-between; margin-top: 10px; }

/* ---------------------------------------------------------------- Aujourd'hui et recherche */

.today-group { margin-bottom: 24px; }
.today-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.today-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.today-list li:last-child { border-bottom: 0; }
.today-list p { margin: 4px 0 0; }
.today-list .task-actions { margin: 0; }

/* ---------------------------------------------------------------- Connexion */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 1.3rem; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .9rem; }

/* ---------------------------------------------------------------- Mobile */

@media (max-width: 800px) {
    .overview, .kanban { grid-template-columns: 1fr; }
    .form { grid-template-columns: 1fr; }
    .form .span-2 { grid-column: auto; }
    .grid { grid-template-columns: 1fr; }
    .search { order: 10; flex-basis: 100%; }
    .search input { max-width: none; }
    h1 { font-size: 1.35rem; }
}

/* ---------------------------------------------------------------- Icônes et liens externes */

.icon { width: 1.1em; height: 1.1em; flex-shrink: 0; vertical-align: -.2em; }
.btn .icon { margin-right: 6px; }
.type { display: inline-flex; align-items: center; gap: 6px; }
.type .icon { width: 18px; height: 18px; color: var(--text); }
.breadcrumb .type { text-transform: none; letter-spacing: 0; font-size: inherit; }

/* Toute la carte est cliquable via le titre ; les liens externes passent au-dessus. */
.project-card { position: relative; }
.card-link { color: inherit; }
.card-link:hover { text-decoration: none; }
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.project-card:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }

.ext-links { display: flex; flex-wrap: wrap; gap: 6px; }
.ext-link { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; font-weight: 600; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--primary); }
.ext-link:hover { background: var(--surface-2); text-decoration: none; }
.ext-link .icon { width: 13px; height: 13px; }

/* ---------------------------------------------------------------- Import */

.import-form { max-width: 720px; }
.modes { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.modes legend { font-weight: 600; font-size: .9rem; padding: 0 6px; }
.form .mode, .form .confirm { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
.mode input, .confirm input { margin-top: 4px; }
.confirm { font-size: .88rem; padding-top: 10px; border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- Surveillance */

:root { --ok: #1f9d55; }
@media (prefers-color-scheme: dark) { :root { --ok: #3fc27a; } }

.health { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill .icon { width: 12px; height: 12px; }
.pill-ok { color: var(--ok); }
.pill-lent, .pill-warn { color: var(--warn); }
.pill-panne, .pill-danger { color: var(--surface); background: var(--danger); }
.hdot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.h-ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.h-inconnu { background: var(--st-archive); }

.alerts { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alert { padding: 9px 14px; border-radius: 7px; border: 1px solid; background: var(--surface); font-size: .9rem; }
.alert::before { content: "⚠ "; }
.alert-danger { border-color: var(--danger); color: var(--danger); }
.alert-warn { border-color: var(--warn); color: var(--warn); }

.span-all { grid-column: 1 / -1; }
.monitor { display: flex; flex-direction: column; gap: 12px; }
.monitor h2 { margin: 0; }
.monitor-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.monitor p { margin: 0; }
.btn-small { padding: 4px 10px; font-size: .82rem; }
.monitor-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 0; }
.monitor-stats div { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; }
.monitor-stats dt { font-size: .78rem; color: var(--muted); }
.monitor-stats dd { margin: 2px 0 0; font-weight: 700; font-size: 1.05rem; }
.monitor-stats dd .small { font-weight: 400; }
.monitor-stats dd.bad { color: var(--danger); }

/* ---------------------------------------------------------------- Réglages */

.settings-card { max-width: 720px; margin-bottom: 20px; }
.settings-card > p { margin: 0 0 14px; }
.settings-card .form { margin-top: 8px; }
.form p.small { margin: 0; }
.ok-text { color: var(--ok); font-weight: 600; }
.settings-remove { margin-top: 12px; text-align: right; }

/* ---------------------------------------------------------------- Réorganisation des tuiles */

.card-top-right { display: inline-flex; align-items: center; gap: 6px; }
.drag-handle { position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; margin-right: -6px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: grab; touch-action: none; }
.drag-handle:hover, .drag-handle:focus-visible { background: var(--surface-2); color: var(--text); }
.drag-handle .icon { width: 18px; height: 18px; }
.project-card.dragging { opacity: .35; outline: 2px dashed var(--primary); outline-offset: -2px; transform: none; }
.drag-ghost { transition: none; position: fixed; top: 0; left: 0; z-index: 100; pointer-events: none; margin: 0; opacity: .95; box-shadow: 0 12px 32px rgba(20, 30, 50, .25); cursor: grabbing; }
body:has(.drag-ghost) { cursor: grabbing; user-select: none; }

.order-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.order-bar .icon { width: 14px; height: 14px; }
.save-status { color: var(--ok); font-weight: 600; }
.save-status.error { color: var(--danger); }

/* ---------------------------------------------------------------- Modification en place */

.edit-form { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.edit-form input[type="text"], .edit-form textarea { width: 100%; }
.edit-row { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-row > * { flex: 1 1 120px; }
.edit-row .grow { flex: 3 1 220px; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.editing { outline: 2px solid var(--primary); outline-offset: -1px; }
.links li.editing, .timeline li.editing { display: block; }
.timeline li.editing { padding: 10px 12px 12px; border-radius: 8px; background: var(--surface); margin-bottom: 16px; }
.item-actions { display: inline-flex; gap: 12px; align-items: center; white-space: nowrap; }
.timeline .item-actions { margin-top: 4px; }
[id^="item-"] { scroll-margin-top: 90px; }

/* ---------------------------------------------------------------- Mise en forme des notes */

.format-toolbar { display: flex; align-items: center; gap: 4px; flex: 1 1 100%; flex-wrap: wrap; }
.format-toolbar button { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; }
.format-toolbar button:hover { background: var(--surface-2); }
.format-toolbar .icon { width: 16px; height: 16px; }
.format-hint { font-size: .78rem; color: var(--muted); margin-left: 6px; }
.text ul { margin: .3em 0; padding-left: 1.4em; }
.text li { margin: .1em 0; }
.text strong { font-weight: 700; }

/* ---------------------------------------------------------------- Surveillance production / test */

.health-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); align-self: center; min-width: 32px; }

/* ---------------------------------------------------------------- Filtre « avec tâches à faire » */

.filter-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip.toggle .check { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border: 1.5px solid var(--muted); border-radius: 4px; font-size: .7rem; line-height: 1; margin-right: 2px; }
.chip.toggle.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); box-shadow: none; }
.chip.toggle.active .check { border-color: var(--primary-text); }
.chip.toggle.active .count { color: inherit; opacity: .85; }

/* ---------------------------------------------------------------- Tâches à faire sur les cartes */

.card-tasks { background: color-mix(in srgb, var(--warn) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border)); border-radius: 8px; padding: 8px 10px; }
.card-tasks-title { margin: 0 0 4px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--warn); }
.card-tasks-title .count { color: var(--warn); font-weight: 700; }
.card-tasks ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.ct { display: flex; align-items: center; gap: 6px; padding: 3px 0 3px 8px; border-left: 3px solid var(--warn); font-size: .86rem; line-height: 1.3; }
.ct-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ct-prio-1 { border-left-color: var(--danger); }
.ct-prio-1 .ct-title { font-weight: 700; }
.ct-prio-3 { border-left-color: var(--st-archive); }
.ct-prio-3 .ct-title { color: var(--muted); }
.ct-bug .ct-title { color: var(--danger); }
.ct-tag { flex-shrink: 0; font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 5px; border-radius: 4px; }
.ct-tag-bug { background: var(--danger); color: var(--surface); }
.ct-tag-doing { background: var(--primary); color: var(--primary-text); }
.ct-more { position: relative; z-index: 1; display: inline-block; margin-top: 4px; font-size: .78rem; font-weight: 600; }
