/* --- Moteur de thèmes -------------------------------------------------
 *
 * Un thème ne change que l'ambiance : le dégradé de fond et la couleur
 * d'accent. Les couleurs de statut (vert / orange / rouge) sont sémantiques
 * et restent identiques d'un thème à l'autre — sinon la légende mentirait.
 */

:root {
    /* Ambiance par défaut : cendre */
    --tint-1: #7c2d12;
    --tint-2: #1a0d07;
    --tint-3: #08060a;
    --accent: #fb923c;

    /* Surfaces : translucides, posées sur le dégradé */
    --panel: rgba(12, 10, 14, .58);
    --panel-2: rgba(255, 255, 255, .07);
    --line: rgba(255, 255, 255, .13);
    --text: #f3f4f6;
    --muted: #a7a3ae;

    /* Sémantique — jamais redéfinies par un thème */
    --up: #4ade80;
    --warn: #fbbf24;
    --down: #f87171;

    --radius: 12px;
}

:root[data-theme="abysse"] {
    --tint-1: #0c4a6e; --tint-2: #06121c; --tint-3: #04070d; --accent: #38bdf8;
}
:root[data-theme="neon"] {
    --tint-1: #4c1d95; --tint-2: #150b2b; --tint-3: #07050f; --accent: #c084fc;
}
:root[data-theme="foret"] {
    --tint-1: #065f46; --tint-2: #06170f; --tint-3: #04090a; --accent: #34d399;
}
:root[data-theme="sang"] {
    --tint-1: #7f1d1d; --tint-2: #1c0808; --tint-3: #0a0405; --accent: #f87171;
}
:root[data-theme="encre"] {
    --tint-1: #1e293b; --tint-2: #0d1220; --tint-3: #070a10; --accent: #818cf8;
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background: linear-gradient(165deg, var(--tint-1) 0%, var(--tint-2) 48%, var(--tint-3) 100%)
                fixed no-repeat;
}

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

/* Grain généré : un feTurbulence en SVG intégré, donc aucun fichier à
   déployer et aucun appel réseau. Il casse le côté « aplat » du dégradé. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: .5;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)' opacity='.4'/%3E%3C/svg%3E");
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* --- Écrans de connexion et de configuration ------------------------- */

.centered {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.panel {
    background: var(--panel);
    backdrop-filter: blur(14px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 28px;
    max-width: 420px;
    width: 100%;
}

.panel h1 { margin: 0 0 16px; font-size: 20px; }
.panel pre {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    font-size: 13px;
}

.login label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.login .hint { margin: 14px 0 0; color: var(--muted); font-size: 12px; }
.login .error {
    background: rgba(248, 81, 73, .12);
    border: 1px solid rgba(248, 81, 73, .4);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 0 0 14px;
    font-size: 13px;
}

input[type="text"], input[type="password"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
    background: var(--accent);
    color: #0f1115;
    border: 0;
    border-radius: 6px;
    padding: 9px 14px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    font-weight: 500;
}
button.ghost:hover { color: var(--text); }
.login button { width: 100%; margin-top: 16px; }

/* --- Barre supérieure ------------------------------------------------ */

.bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.bar h1 { margin: 0; font-size: 17px; letter-spacing: .2px; }
.bar .counts { margin: 0; color: var(--muted); font-size: 13px; }
.bar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.bar-actions form { margin: 0; }

body.editing #edit-toggle { background: var(--up); }

/* --- Alertes --------------------------------------------------------- */

.alerts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 24px 0;
}
.alert {
    border: 1px solid var(--line);
    border-left-width: 3px;
    border-radius: 8px;
    background: var(--panel);
    backdrop-filter: blur(12px);
    padding: 10px 14px;
}
.alert.danger { border-left-color: var(--down); }
.alert.warning { border-left-color: var(--warn); }
.alert.info { border-left-color: var(--muted); }
.alert summary { cursor: pointer; display: flex; align-items: center; gap: 10px; }
.alert summary strong { font-weight: 600; font-size: 14px; }
.alert-count {
    background: var(--panel-2);
    border-radius: 20px;
    padding: 1px 9px;
    font-size: 12px;
    color: var(--muted);
}
.alert p { margin: 10px 0 6px; color: var(--muted); font-size: 13px; }
.alert ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; }

/* --- Plateau --------------------------------------------------------- */

#board { padding: 20px 24px 60px; }

.category { margin-bottom: 28px; }
.category-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.category-name {
    margin: 0;
    font-size: 13px;
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    padding: 2px 4px;
    border-radius: 4px;
}
body.editing .category-name[contenteditable="true"] {
    background: var(--panel-2);
    outline: 1px dashed var(--line);
    cursor: text;
}
.category-count {
    color: var(--muted);
    font-size: 11px;
    background: var(--panel-2);
    border-radius: 20px;
    padding: 0 8px;
}
.category-delete {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    padding: 0 8px;
    line-height: 20px;
    display: none;
}
body.editing .category-delete { display: block; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 12px;
    min-height: 64px;
    border-radius: var(--radius);
}
body.editing .grid {
    outline: 1px dashed var(--line);
    outline-offset: 6px;
}
.grid.drop-target { outline-color: var(--accent); background: rgba(124, 156, 255, .05); }

/* --- Cartes ---------------------------------------------------------- */

.card {
    background: var(--panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    transition: border-color .15s, transform .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

/* Un liseré d'accent sur la tranche gauche : c'est lui qui porte la couleur
   du thème sur le plateau, sans toucher aux pastilles de statut. */
.card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 2px;
    border-radius: 2px;
    background: var(--accent);
    opacity: .55;
}
.card.is-hidden { display: none; }
body.editing .card.is-hidden { display: flex; opacity: .45; }
body.editing .card { cursor: grab; user-select: none; }
.card.dragging { opacity: .35; }
.card.ghost {
    position: fixed;
    z-index: 100;
    pointer-events: none;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
    border-color: var(--accent);
    cursor: grabbing;
}
.card.vanished { border-style: dashed; opacity: .6; }

.card-head { display: flex; align-items: center; gap: 8px; }
.card-name {
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-desc { margin: 0; font-size: 12.5px; color: var(--muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.status-up .dot { background: var(--up); }
.status-protected .dot, .status-fallback .dot { background: var(--warn); }
.status-down .dot { background: var(--down); }

.card-edit {
    margin-left: auto;
    background: transparent;
    color: var(--muted);
    border: 0;
    padding: 0 2px;
    display: none;
}
body.editing .card-edit { display: block; }
.card-forget {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
    padding: 4px 8px;
    display: none;
}
body.editing .card-forget { display: block; }

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 11.5px;
    color: var(--muted);
    align-items: center;
}
.badge {
    border-radius: 20px;
    padding: 1px 8px;
    background: var(--panel-2);
}
.badge.up { color: var(--up); }
.badge.protected, .badge.fallback { color: var(--warn); }
.badge.down { color: var(--down); }
.cert.warn { color: var(--warn); }
.cert.bad { color: var(--down); }

.spark { width: 100%; height: 24px; }
.spark polyline { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark-ok polyline { stroke: var(--up); }
.spark-warn polyline { stroke: var(--warn); }
.spark-bad polyline { stroke: var(--down); }

.edit-only { display: none; }
body.editing .edit-only { display: inline-block; }

/* --- Boîte de dialogue ----------------------------------------------- */

dialog {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 16px; font-size: 16px; }
dialog label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
dialog label.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 22px 0 0; padding: 0; }

/* --- Notification discrète ------------------------------------------- */

#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 13px;
    opacity: 0;
    transition: opacity .18s, transform .18s;
    pointer-events: none;
    z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--down); color: var(--down); }

@media (max-width: 640px) {
    .bar { padding: 12px 14px; }
    #board { padding: 14px; }
    .alerts { padding: 14px 14px 0; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* En mode édition, le doigt fait glisser la carte et non défiler la page. */
body.editing .card { touch-action: none; }

/* --- Légende ---------------------------------------------------------- */

.legend {
    margin-top: 36px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    backdrop-filter: blur(12px);
    padding: 12px 18px;
    max-width: 780px;
}
.legend > summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .6px;
}
.legend[open] > summary { margin-bottom: 14px; }
.legend h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--muted);
    margin: 22px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
}
.legend h3:first-of-type { margin-top: 0; }
.legend dl { margin: 0; }
.legend dt {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 14px;
}
.legend dt .dot { display: inline-block; }
.legend dd {
    margin: 5px 0 0 0;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 1.55;
}
.legend dd strong, .legend dd em { color: var(--text); font-style: normal; }
.legend p { color: var(--muted); font-size: 13.5px; line-height: 1.55; }
.legend code {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 0 5px;
    font-size: 12px;
}
.legend .spark { width: 60px; height: 18px; }
.legend-dashed {
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 2px 10px;
    font-size: 12px;
    color: var(--muted);
    opacity: .75;
}

/* --- Sélecteur d'ambiance --------------------------------------------- */

.theme-picker { position: relative; }
#theme-toggle { font-size: 15px; line-height: 1; padding: 9px 12px; }

.theme-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--panel);
    backdrop-filter: blur(16px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 168px;
    z-index: 40;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
}
.theme-menu[hidden] { display: none; }
.theme-menu button {
    background: transparent;
    color: var(--text);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 7px;
    text-align: left;
}
.theme-menu button:hover { background: var(--panel-2); filter: none; }
.theme-menu button.active { color: var(--accent); }
.theme-menu .swatch {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex: 0 0 auto;
    background: linear-gradient(135deg, var(--a) 40%, var(--b) 100%);
    border: 1px solid rgba(255, 255, 255, .22);
}

/* --- Icône de service -------------------------------------------------- */

.card-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    border-radius: 5px;
    object-fit: contain;
}
.card-icon.fallback {
    display: grid;
    place-items: center;
    background: var(--panel-2);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
}

.badge.tech { color: var(--accent); }

.bar-link {
    color: var(--muted);
    font-size: 13px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
}
.bar-link:hover { color: var(--text); text-decoration: none; }
.back { color: var(--text); }
.back:hover { color: var(--accent); text-decoration: none; }

/* --- Favoris ----------------------------------------------------------- */

.card-fav {
    background: transparent;
    border: 0;
    color: var(--line);
    padding: 0 2px;
    font-size: 14px;
    display: none;
    margin-left: auto;
}
body.editing .card-fav { display: block; }
body.editing .card-edit { margin-left: 0; }
.card.favorite .card-fav { color: #eab308; }

/* Repris tel quel du site anime : même dégradé, même cadence. */
@keyframes rainbow {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.card.favorite {
    border: 2px solid transparent;
    background:
        linear-gradient(rgba(10, 8, 12, .74), rgba(10, 8, 12, .74)) padding-box,
        linear-gradient(270deg, #ff0000, #ff7f00, #eab308, #22c55e, #3b82f6, #a855f7, #ef4444) border-box;
    background-size: auto, 200% 200%;
    animation: rainbow 2s linear infinite;
}
/* Le liseré d'accent s'efface : le RGB tient déjà tout le contour. */
.card.favorite::before { display: none; }
.card.favorite:hover { border-color: transparent; }

@media (prefers-reduced-motion: reduce) {
    .card.favorite { animation: none; }
}

/* --- Page des certificats ---------------------------------------------- */

.cert-card {
    background: var(--panel);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
    border-left-width: 3px;
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 12px;
    max-width: 980px;
}
.cert-card.ok { border-left-color: var(--up); }
.cert-card.warn { border-left-color: var(--warn); }
.cert-card.bad { border-left-color: var(--down); }

.cert-card header { display: flex; align-items: baseline; gap: 12px; }
.cert-card h2 { margin: 0; font-size: 15px; font-weight: 600; }
.cert-extra {
    background: var(--panel-2);
    border-radius: 20px;
    padding: 1px 8px;
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
}
.cert-deadline { margin-left: auto; font-size: 13px; font-weight: 600; }
.cert-deadline.ok { color: var(--up); }
.cert-deadline.warn { color: var(--warn); }
.cert-deadline.bad { color: var(--down); }

.cert-meta { margin: 6px 0 12px; color: var(--muted); font-size: 12.5px; }
.cert-names { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    font-size: 12px;
    border-radius: 20px;
    padding: 2px 10px;
    border: 1px solid var(--line);
}
.chip.served { background: var(--panel-2); color: var(--text); }
.chip.unused { color: var(--muted); opacity: .6; border-style: dashed; }

/* --- Déplacement des catégories ---------------------------------------- */

.category-grip {
    display: none;
    cursor: grab;
    color: var(--muted);
    font-size: 15px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
    /* Au doigt, la poignée fait glisser la catégorie et non défiler la page. */
    touch-action: none;
    user-select: none;
}
body.editing .category-grip { display: inline-block; }
.category-grip:hover { color: var(--accent); background: var(--panel-2); }

.category.moving { opacity: .55; }
.category.moving .grid { outline-color: var(--accent); }
.category.moving .category-grip { cursor: grabbing; }
