:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #697386;
    --border: #e1e4ea;
    --primary: #ea4b71;
    --primary-hover: #d63a60;
    --success-bg: #e3f6ea;
    --success-text: #1b7a43;
    --error-bg: #fdeaea;
    --error-text: #b42323;
    --warning-bg: #fff4dc;
    --warning-text: #8a5a00;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .08);
    --json-key: #7a3e9d;
    --json-string: #1b7a43;
    --json-value: #b3541e;
    --tone-conf: #0f766e;
    --tone-stats: #4338ca;
    --series-success: #2a78d6;
    --series-error: #eb6834;
    --tone-triggers: #be123c;
    --tone-rules: #7c3aed;
    --tone-prompts: #b45309;
    --tone-logs: #0369a1;
    color-scheme: light;
}

/* Thème sombre : choix explicite (data-theme, posé par le bouton de la barre du haut), sinon préférence du système */
:root[data-theme="dark"] {
    --bg: #14161b;
    --surface: #1d2027;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --border: #2f333d;
    --success-bg: #173826;
    --success-text: #7fd6a2;
    --error-bg: #401c1c;
    --error-text: #f19b9b;
    --warning-bg: #3d3014;
    --warning-text: #f0c46a;
    --shadow: none;
    --json-key: #d7a6f5;
    --json-string: #8fd6a8;
    --json-value: #f5b27a;
    --tone-conf: #5fd4c4;
    --tone-stats: #a5b4fc;
    --series-success: #3987e5;
    --series-error: #d95926;
    --tone-triggers: #fb8fa4;
    --tone-rules: #b39afd;
    --tone-prompts: #f5b660;
    --tone-logs: #6cc4f5;
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14161b;
        --surface: #1d2027;
        --text: #e6e8ec;
        --muted: #9aa3b2;
        --border: #2f333d;
        --success-bg: #173826;
        --success-text: #7fd6a2;
        --error-bg: #401c1c;
        --error-text: #f19b9b;
        --warning-bg: #3d3014;
        --warning-text: #f0c46a;
        --shadow: none;
        --json-key: #d7a6f5;
        --json-string: #8fd6a8;
        --json-value: #f5b27a;
        --tone-conf: #5fd4c4;
        --tone-stats: #a5b4fc;
        --series-success: #3987e5;
        --series-error: #d95926;
        --tone-triggers: #fb8fa4;
        --tone-rules: #b39afd;
        --tone-prompts: #f5b660;
    --tone-logs: #6cc4f5;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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); }
h1 { font-size: 1.5rem; margin: 0 0 1.25rem; }
h2 { font-size: 1.1rem; margin: 0 0 1rem; }
.muted { color: var(--muted); }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
code { font-size: .9em; }
.nowrap { white-space: nowrap; }

/* En-tête */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: .75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand span { color: var(--primary); }
.topbar-end { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    color: var(--muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--bg); }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
/* Icône du thème vers lequel on bascule : lune en clair, soleil en sombre */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
    :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
.nav form { margin: 0; }
.nav a, .nav-button {
    padding: .4rem .75rem;
    border-radius: var(--radius);
    color: var(--muted);
    text-decoration: none;
    font: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}
.nav a:hover, .nav-button:hover { color: var(--text); background: var(--bg); }
.nav a[aria-current="page"] { color: var(--text); background: var(--bg); font-weight: 600; }

/* Menu déroulant de la navigation (Admin) */
.icon { width: 1rem; height: 1rem; flex: none; }
.nav-menu { position: relative; }
.nav-menu summary {
    display: flex;
    align-items: center;
    gap: .3rem;
    padding: .4rem .75rem;
    color: var(--muted);
    list-style: none;
    border-radius: var(--radius);
    cursor: pointer;
}
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-menu summary:hover, .nav-menu[open] summary { color: var(--text); background: var(--bg); }
.nav-menu summary.is-active { color: var(--text); background: var(--bg); font-weight: 600; }
.nav-menu-chevron { width: .9rem; height: .9rem; transition: transform .15s; }
.nav-menu[open] .nav-menu-chevron { transform: rotate(180deg); }
.nav-menu-list {
    position: absolute;
    top: calc(100% + .35rem);
    right: 0;
    z-index: 10;
    display: grid;
    min-width: 12rem;
    padding: .35rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
}
.nav .nav-menu-list a { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; }

/* Mise en page */
.container { max-width: 1100px; margin: 2rem auto; padding: 0 1.5rem; }
.container-narrow { max-width: 440px; margin-top: 4rem; }
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
}
.card-wide { max-width: 560px; }
.card-footer { margin: 1.25rem 0 0; font-size: .9rem; }
.breadcrumb { margin: 0 0 .5rem; font-size: .9rem; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.empty {
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

/* Formulaires */
.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: .35rem; font-weight: 500; }
.form small { font-weight: 400; }
.form input {
    width: 100%;
    padding: .6rem .75rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.form label.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 400; cursor: pointer; }
.form label.checkbox input { width: auto; margin: 0; accent-color: var(--primary); }
.form select {
    width: 100%;
    padding: .6rem .75rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.form select:disabled { opacity: .6; }
.form-wide { max-width: 760px; gap: 0; }
.form-actions { display: flex; gap: .75rem; margin-bottom: 1.5rem; }
.checklist {
    display: grid;
    gap: .5rem;
    max-height: 22rem;
    overflow-y: auto;
    padding: .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.checklist small { display: inline; margin-left: .35rem; }
.form select:focus,
.form input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }

.btn {
    display: inline-block;
    padding: .6rem 1rem;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-small { padding: .3rem .7rem; font-size: .85rem; white-space: nowrap; }
.btn-icon { display: inline-flex; align-items: center; justify-content: center; min-width: 2rem; padding-inline: .5rem; }
.btn-icon .icon { width: .95rem; height: .95rem; }
.btn-danger { color: var(--error-text); }
.btn-danger:hover { background: var(--error-bg); }
.btn:disabled { opacity: .4; cursor: default; background: var(--surface); }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-header h1 { margin: 0; }

/* Messages */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1.25rem; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }

.badge {
    display: inline-block;
    padding: .1rem .55rem;
    font-size: .78rem;
    font-weight: 600;
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.badge-primary { background: var(--primary); color: #fff; border-color: transparent; }
.badge-success { background: var(--success-bg); color: var(--success-text); border-color: transparent; }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); border-color: transparent; }
.badge-level-error { background: var(--error-bg); color: var(--error-text); border-color: transparent; }
.badge-level-warn, .badge-level-warning { background: var(--warning-bg); color: var(--warning-text); border-color: transparent; }

/* Tableaux */
.table-wrapper {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .75rem 1rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td small { display: block; }
.col-actions { width: 1%; white-space: nowrap; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
@media (min-width: 900px) {
    .col-actions .actions { flex-wrap: nowrap; }
}

/* Actions des workflows : une couleur et une icône par type (classe action-{type}) */
.action-chip {
    --tone: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .3rem .75rem .3rem .6rem;
    font-size: .85rem;
    font-weight: 600;
    color: var(--tone);
    text-decoration: none;
    white-space: nowrap;
    background: color-mix(in srgb, var(--tone) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--tone) 30%, transparent);
    border-radius: 999px;
    transition: background-color .15s, border-color .15s;
}
.action-chip:hover { background: color-mix(in srgb, var(--tone) 18%, transparent); border-color: color-mix(in srgb, var(--tone) 55%, transparent); }
.action-chip:focus-visible { outline: 2px solid var(--tone); outline-offset: 2px; }
.action-conf { --tone: var(--tone-conf); }
.action-stats { --tone: var(--tone-stats); }
.action-triggers { --tone: var(--tone-triggers); }
.action-rules { --tone: var(--tone-rules); }
.action-prompts { --tone: var(--tone-prompts); }
.action-logs { --tone: var(--tone-logs); }
a.action-chip[aria-current="page"] { color: var(--surface); background: var(--tone); border-color: var(--tone); }

/* Navigation entre les pages d'un workflow (mêmes pastilles que la liste des workflows) */
.workflow-nav { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.5rem; }
.table-logs td { font-size: .9rem; }

/* Règles d'un workflow */
/* Largeurs fixes : le tableau tient dans la page, les règles et actions longues passent à la ligne */
.table-rules { table-layout: fixed; }
.table-rules th, .table-rules td { padding: .6rem .75rem; }
.table-rules td { font-size: .9rem; overflow-wrap: anywhere; }
.table-rules .col-handle { width: 2rem; }
.table-rules .col-position { width: 2.75rem; }
.table-rules .col-rule-action { width: 28%; }
.table-rules .col-extra { width: 11%; }
.table-rules .col-status { width: 5.75rem; }
.table-rules .col-actions { width: 6.5rem; }
.table-rules .col-actions-sortable { width: 10.75rem; }
.table-rules .actions { gap: .35rem; flex-wrap: nowrap; }
@media (max-width: 1000px) {
    /* Écran étroit : boutons sur deux lignes, la place va à la règle */
    .table-rules .col-actions-sortable { width: 6.5rem; }
    .table-rules .actions { flex-wrap: wrap; }
}
.rule-code { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }
.rule-inactive td:not(.col-actions):not(.col-handle) { opacity: .55; }
.col-position { width: 1%; text-align: right; }
.col-handle { width: 1%; padding-right: 0 !important; }
.drag-handle { display: inline-block; padding: 0 .15rem; color: var(--muted); cursor: grab; user-select: none; }
.drag-handle:hover { color: var(--text); }
.table-rules tr.dragging { background: var(--bg); opacity: .7; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.details { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.5rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

.tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.tabs a {
    padding: .35rem .8rem;
    font-size: .88rem;
    color: var(--muted);
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}
.tabs a[aria-current="page"] { color: #fff; background: var(--primary); border-color: var(--primary); }

/* Logs */
.subnav { display: flex; gap: 1.5rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.subnav a { padding: .5rem 0; margin-bottom: -1px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; }
.subnav a:hover { color: var(--text); }
.subnav a[aria-current="page"] { color: var(--text); font-weight: 600; border-bottom-color: var(--primary); }

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: .75rem 1rem;
    padding: 1rem;
    margin-bottom: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.filters label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
.filters input, .filters select {
    padding: .5rem .65rem;
    font: inherit;
    font-size: .95rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.filters input:focus, .filters select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.filters .btn { padding: .5rem 1rem; }
.filters-grow { flex: 1 1 16rem; }
.filters-nav { display: flex; gap: .5rem; margin-left: auto; }
.log-details { display: block; margin-top: .25rem; white-space: pre-line; }

/* Modale JSON */
.dialog {
    width: min(900px, calc(100vw - 2rem));
    max-height: calc(100vh - 4rem);
    padding: 0;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.dialog::backdrop { background: rgba(10, 12, 16, .55); }
.dialog-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.dialog-header h2 { margin: 0; font-size: 1rem; }
.json {
    margin: 0;
    padding: 1.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .85rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.json-key { color: var(--json-key); }
.json-string { color: var(--json-string); }
.json-value { color: var(--json-value); }


/* Éditeur de règle : groupes de conditions ET / OU imbriqués et liste d'actions */
.rule-form { gap: 0; }
.rule-form .card > h2 { margin-bottom: .25rem; }
.rule-form .card > .muted { margin: 0 0 1rem; font-size: .9rem; }
.cond-group {
    --depth-color: var(--primary);
    padding: .75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--depth-color);
    border-radius: var(--radius);
}
.cond-group[data-depth="1"] { --depth-color: #3b82f6; background: var(--bg); }
.cond-group[data-depth="2"] { --depth-color: #10b981; }
.cond-group[data-depth="3"] { --depth-color: #f59e0b; background: var(--bg); }
.cond-group-negate { border-left-style: dashed; }
.cond-group-header { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-bottom: .75rem; }
.cond-summary { font-size: .85rem; }
.rule-form label.cond-negate { font-size: .85rem; }
.cond-tools { display: flex; gap: .35rem; margin-left: auto; }
.segmented { display: inline-flex; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); }
.segment { padding: .3rem .7rem; font: inherit; font-size: .85rem; color: var(--muted); background: var(--surface); border: 0; cursor: pointer; }
.segment + .segment { border-left: 1px solid var(--border); }
.segment[aria-pressed="true"] { font-weight: 600; color: #fff; background: var(--depth-color, var(--primary)); }
.cond-children { display: grid; gap: .4rem; }
.cond-connector { justify-self: start; padding: 0 .6rem; font-size: .72rem; font-weight: 700; letter-spacing: .06em; color: var(--depth-color); }
.cond-item, .action-item { padding: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.cond-row { display: flex; align-items: flex-start; gap: .5rem; }
.cond-body { display: flex; flex: 1 1 auto; flex-wrap: wrap; align-items: center; gap: .5rem; min-width: 0; }
.rule-form .cond-body select,
.rule-form .cond-body input:not([type="checkbox"]),
.rule-form .action-row select { width: auto; padding: .4rem .6rem; }
.rule-form .cond-body .cond-value { flex: 1 1 14rem; min-width: 10rem; }
.rule-form .cond-body .cond-custom { width: 11rem; }
.rule-form label.cond-option { font-size: .85rem; }
.cond-ai-fields { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin-top: .6rem; font-size: .85rem; }
.cond-add { display: flex; gap: .5rem; margin-top: .75rem; }
.field-error { margin: .4rem 0 0; font-size: .85rem; color: var(--error-text); }
.field-warning { margin: .4rem 0 0; font-size: .85rem; color: var(--warning-text); }
.field-hint { margin: .4rem 0 0; font-size: .85rem; color: var(--muted); }
.action-fields .field-hint, .action-fields .field-warning { flex-basis: 100%; margin: 0; }
.action-list { display: grid; gap: .5rem; }
.action-row { display: flex; align-items: center; gap: .5rem; }
.action-index {
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border-radius: 50%;
}
.action-fields { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem 1rem; margin: .6rem 0 0 2.1rem; }
.rule-form .action-fields label:not(.checkbox) { flex: 1 1 14rem; gap: .25rem; font-size: .85rem; }
.rule-form .action-fields input:not([type="checkbox"]) { padding: .4rem .6rem; }
.raw-editor { margin-top: 1rem; }
.raw-editor summary { font-size: .9rem; cursor: pointer; }
.raw-editor textarea {
    width: 100%;
    margin-top: .5rem;
    padding: .6rem .75rem;
    font-size: .85rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
}
.raw-editor textarea:not([readonly]) { background: var(--surface); }
.raw-editor .raw-toggle { margin-top: .5rem; font-size: .9rem; }

/* Prompts */
.prompt-excerpt {
    display: -webkit-box;
    max-width: 38rem;
    overflow: hidden;
    font-size: .9rem;
    white-space: pre-line;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}
.usage-list, .prompt-usage { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; }
.usage-list .badge, .prompt-usage .badge { text-decoration: none; white-space: nowrap; }
.usage-list .badge:hover, .prompt-usage .badge:hover { color: var(--text); border-color: var(--muted); }
.prompt-form { gap: 0; }
.prompt-form textarea {
    width: 100%;
    padding: .6rem .75rem;
    font: inherit;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
}
.prompt-form textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.prompt-help summary { font-size: .9rem; cursor: pointer; }
.prompt-help ul { margin: .5rem 0 0; padding-left: 1.25rem; font-size: .9rem; color: var(--muted); }
.prompt-help li + li { margin-top: .4rem; }

/* Configuration d'un workflow */
.conf-form { gap: 0; }
.conf-list { display: grid; }
.conf-item { padding: .9rem 0; border-top: 1px solid var(--border); }
.conf-item:first-child { padding-top: 0; border-top: 0; }
.conf-item:last-child { padding-bottom: 0; }
.conf-form label.conf-switch { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; cursor: pointer; }
.conf-form label.conf-input { display: grid; grid-template-columns: minmax(0, 1fr) minmax(12rem, 22rem); align-items: center; gap: .5rem 1.5rem; }
.conf-text { display: grid; gap: .15rem; }
.conf-text strong { font-weight: 600; }
.conf-text .badge { margin-left: .4rem; font-size: .7rem; vertical-align: middle; }
.conf-text small { font-size: .85rem; }
.conf-item-error input { border-color: var(--error-text); }
@media (max-width: 640px) {
    .conf-form label.conf-input { grid-template-columns: 1fr; }
}

/* Interrupteur (case à cocher role="switch") */
.form input.switch {
    position: relative;
    flex: none;
    width: 2.6rem;
    height: 1.5rem;
    margin: 0;
    padding: 0;
    appearance: none;
    background: var(--border);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color .15s;
}
.form input.switch::after {
    content: "";
    position: absolute;
    top: .2rem;
    left: .2rem;
    width: 1.1rem;
    height: 1.1rem;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .25);
    transition: transform .15s;
}
.form input.switch:checked { background: var(--tone-conf); }
.form input.switch:checked::after { transform: translateX(1.1rem); }
.form input.switch:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Exécution à la demande */
.trigger-list { display: grid; gap: 0; }
.trigger h2 { margin-bottom: .25rem; }
.trigger .muted { margin: 0; }
.trigger-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem; }
.trigger-run { display: inline-flex; flex: none; align-items: center; gap: .45rem; }
.trigger-run .icon { width: .9rem; height: .9rem; fill: currentColor; }
.trigger-run:disabled { opacity: .45; cursor: not-allowed; }
.trigger-params { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem 1rem; margin-top: 1.25rem; }
.trigger-params label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
.trigger-params input {
    padding: .45rem .7rem;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.trigger-params input:disabled { opacity: .6; }
.trigger-presets { display: flex; flex-wrap: wrap; gap: .4rem; }
.trigger-problem { margin: 1.25rem 0 0; }
.trigger-unavailable h2 { color: var(--muted); }

/* Stats d'un workflow */
.stats-filters { align-items: end; }
.stats-presets { display: flex; flex-wrap: wrap; gap: .35rem; flex-basis: 100%; }
.stats-presets a {
    padding: .25rem .65rem;
    font-size: .85rem;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 999px;
}
.stats-presets a:hover { color: var(--text); }
.stats-presets a[aria-current] { color: var(--text); font-weight: 600; border-color: var(--text); }
.stats-period { margin: 0 0 1rem; }
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-tile {
    display: grid;
    gap: .2rem;
    padding: 1.1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-label { display: flex; align-items: center; gap: .45rem; font-size: .85rem; color: var(--muted); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.15; }
.stat-tile .muted { font-size: .8rem; }
.stat-key { width: .7rem; height: .7rem; border-radius: 50%; }
.stat-key-success { background: var(--series-success); }
.stat-key-error { background: var(--series-error); }
.num, .table .num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 0 1.5rem; }

/* Barres horizontales (bar-list) */
.bar-list { display: grid; gap: .6rem; margin: 0; padding: 0; list-style: none; }
.bar-list { gap: .85rem; }
.bar-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: .3rem .75rem; }
.bar-label { font-size: .9rem; overflow-wrap: anywhere; }
.bar-list code.bar-label { min-width: 0; font-size: .8rem; }
.bar-track { display: block; grid-column: 1 / -1; grid-row: 2; height: 10px; }
.bar { display: block; width: 0; height: 100%; border-radius: 0 4px 4px 0; }
.bar-success { background: var(--series-success); }
.bar-error { background: var(--series-error); }
.bar-value { min-width: 2.5rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* Courbes */
.stats-chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1.5rem; margin-bottom: .75rem; }
.stats-chart-head h2 { margin: 0; }
.chart-legend { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; margin: 0; padding: 0; font-size: .85rem; color: var(--muted); list-style: none; }
.chart-legend li { display: flex; align-items: center; gap: .4rem; }
.legend-line { display: inline-block; width: 1rem; height: 2px; border-radius: 1px; }
.legend-success { background: var(--series-success); }
.legend-error { background: var(--series-error); }
.line-chart { position: relative; }
.line-chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.line-chart svg:focus-visible { outline: 2px solid var(--primary); outline-offset: 4px; border-radius: 2px; }
.chart-grid { stroke: var(--border); stroke-width: 1; opacity: .6; }
.chart-baseline { stroke: var(--border); stroke-width: 1; }
.chart-tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-end-label { font-size: 12px; font-weight: 600; fill: var(--text); }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.series-success { stroke: var(--series-success); }
.chart-line.series-error { stroke: var(--series-error); }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-dot.series-success { fill: var(--series-success); }
.chart-dot.series-error { fill: var(--series-error); }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-tooltip {
    position: absolute;
    z-index: 5;
    min-width: 11rem;
    padding: .55rem .7rem;
    font-size: .8rem;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 20px rgba(16, 24, 40, .16);
}
.chart-tooltip-title { margin-bottom: .3rem; color: var(--muted); }
.chart-tooltip-row { display: flex; align-items: center; gap: .45rem; }
.chart-tooltip-row strong { min-width: 2rem; font-size: .95rem; font-variant-numeric: tabular-nums; }
.chart-tooltip-row span:last-child { color: var(--muted); }
.chart-table { margin-top: 1rem; }
.chart-table summary { font-size: .9rem; color: var(--muted); cursor: pointer; }
.chart-table .table-wrapper { max-height: 22rem; margin-top: .5rem; overflow-y: auto; }

/* Projets n8n (administration) */
.project-list { display: grid; gap: .35rem; margin: 0; padding: 0; list-style: none; }
.project-list code { font-size: .8rem; }
.project-note { margin: .75rem 0 0; font-size: .85rem; }
.section-title { margin-top: 2rem; }
.table-projects td { font-size: .9rem; }
.owned-list { display: grid; gap: .35rem; margin: 0; padding: 0; list-style: none; }
.owned-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.owned-list form { margin: 0; }
.project-select { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }
.project-select label { display: grid; gap: .35rem; font-weight: 500; }
.project-select small { font-weight: 400; }
.checklist .field-warning { display: block; margin-top: .2rem; }

/* ============================================================================================================
   Mobile
   ============================================================================================================ */
.nav-toggle { display: none; }
.nav-toggle .icon { width: 1.1rem; height: 1.1rem; }
.nav-toggle .icon-close, .nav-open .nav-toggle .icon-menu { display: none; }
.nav-open .nav-toggle .icon-close { display: block; }

@media (max-width: 720px) {
    .topbar { padding: .6rem 1rem; gap: .5rem; }
    /* Barre : marque à gauche, thème et menu à droite, navigation dépliée en dessous sur toute la largeur */
    .topbar-end { display: contents; }
    .topbar .theme-toggle:not(.nav-toggle) { margin-left: auto; }
    .nav-toggle { display: inline-flex; }
    .topbar .nav {
        order: 3;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: .1rem;
        padding-top: .5rem;
        border-top: 1px solid var(--border);
    }
    .nav-collapsible:not(.nav-open) .nav { display: none; }
    .nav a, .nav-button, .nav form, .nav-menu summary { width: 100%; padding: .6rem .75rem; text-align: left; }
    .nav form { padding: 0; }
    .nav-menu-list { position: static; min-width: 0; padding: 0 0 0 1rem; background: none; border: 0; box-shadow: none; }

    .container { margin: 1.25rem auto; padding: 0 1rem; }
    .container-narrow { margin-top: 2rem; }
    h1 { font-size: 1.3rem; }
    .card { padding: 1.25rem; }
    .page-header { margin-bottom: 1rem; }
    .table th, .table td { padding: .55rem .6rem; }
}

/* Tableaux .table-stack : une carte par ligne, chaque valeur précédée du titre de sa colonne (data-label, cf. app.js) */
@media (max-width: 640px) {
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: auto; }
    .table-stack { table-layout: auto; }
    .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table-stack tr { padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
    .table-stack tbody tr:last-child { border-bottom: 0; }
    .table-stack td, .table-stack th { padding: .25rem 0; border: 0; }
    .table-stack td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: .1rem;
        font-size: .7rem;
        font-weight: 600;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--muted);
    }
    .table-stack td.col-actions { width: auto; padding-top: .6rem; white-space: normal; }
    .table-stack td.col-actions::before { display: none; }
    .table-stack .actions { flex-wrap: wrap; }
    .table-stack td.num { text-align: left; }
}

/* Éditeur de règle sur mobile : champs en pleine largeur, outils sous la condition, groupes moins indentés */
@media (max-width: 640px) {
    .rule-form > *, .rule-form .card, .cond-group, .cond-item, .action-item { min-width: 0; }
    .cond-group { padding: .6rem; }
    .cond-group-header { gap: .4rem .6rem; }
    .cond-summary { flex-basis: 100%; }
    .cond-row { flex-wrap: wrap; }
    .cond-body { flex-basis: 100%; }
    .rule-form .cond-body select,
    .rule-form .cond-body input:not([type="checkbox"]),
    .rule-form .cond-body .cond-value,
    .rule-form .cond-body .cond-custom { width: 100%; min-width: 0; flex: 1 1 100%; }
    .cond-tools { margin-left: 0; flex-wrap: wrap; }
    .cond-row > .cond-tools { width: 100%; justify-content: flex-end; }
    .action-row { flex-wrap: wrap; }
    .rule-form .action-row select { flex: 1 1 10rem; }
    .action-fields { margin-left: 0; }
    .rule-form .action-fields label:not(.checkbox) { flex-basis: 100%; }
    .form-actions { flex-wrap: wrap; }
}

/* Règles : cartes dès 900px (contenu long) ; n°, statut et boutons sur la première ligne, puis la règle, l'action et les colonnes supplémentaires */
@media (max-width: 900px) {
    .table-rules, .table-rules tbody, .table-rules tr, .table-rules td { display: block; width: auto; }
    .table-rules { table-layout: auto; }
    .table-rules thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table-rules tr { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .3rem .75rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
    .table-rules tbody tr:last-child { border-bottom: 0; }
    .table-rules td { padding: .25rem 0; border: 0; }
    .table-rules td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: .1rem;
        font-size: .7rem;
        font-weight: 600;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--muted);
    }
    .table-rules td.col-handle { display: none; } /* glisser-déposer inutilisable au toucher : boutons ↑ ↓ */
    .table-rules td.col-position { grid-row: 1; grid-column: 1; width: auto; font-weight: 600; text-align: left; }
    .table-rules td.col-position::before { content: "#"; display: inline; margin: 0; font-size: inherit; font-weight: inherit; letter-spacing: 0; text-transform: none; color: inherit; }
    .table-rules td.col-status { grid-row: 1; grid-column: 2; width: auto; }
    .table-rules td.col-actions { grid-row: 1; grid-column: 3; width: auto; padding-top: .25rem; }
    .table-rules td.col-status::before, .table-rules td.col-actions::before { display: none; }
    .table-rules .actions { flex-wrap: nowrap; }
    .table-rules td.col-rule, .table-rules td.col-rule-action, .table-rules td.col-extra { grid-column: 1 / -1; width: auto; }
}
