:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #eef2f5;
    --text: #17202a;
    --muted: #64748b;
    --line: #d9e0e7;
    --accent: #c9252d;
    --accent-dark: #9f1f26;
    --ok: #16834a;
    --warn: #b45309;
    --shadow: 0 10px 30px rgba(31, 41, 55, 0.08);
}

.account-bar { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; font-size: 13px; }
.account-bar a { color: var(--text); }
.account-bar > span { min-width: 0; overflow-wrap: anywhere; }
.account-bar form { margin: 0; }
.account-bar button { padding: 6px 10px; min-height: 34px; }
.auth-page { display: grid; gap: 18px; max-width: 1000px; overflow-wrap: anywhere; }
.auth-page .brand { padding: 8px; }
.auth-login { width: min(100%, 460px); margin-inline: auto; }
.auth-page form { display: grid; gap: 16px; margin-top: 16px; }
.auth-page label { display: flex; flex-direction: column; gap: 7px; font-weight: 600; }
.auth-page input:not([type="checkbox"]) { min-width: 0; width: 100%; padding: 11px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.auth-page button { min-height: 44px; padding: 10px 16px; }
.auth-fields, .auth-users { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 18px; }
.auth-permissions { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
.auth-permissions label, .auth-page .auth-check { flex-direction: row; align-items: center; gap: 10px; }
.auth-permissions input, .auth-check input { width: 20px; height: 20px; flex-shrink: 0; }
.auth-error { padding: 12px; background: #fff0f0; color: #9f1f26; border-radius: 7px; }
.auth-page .auth-delete { background: white; color: #9f1f26; border: 1px solid #9f1f26; }
.cycle-readonly .cycle-run-actions, .cycle-readonly #newProgram, .cycle-readonly #programDialog,
.cycle-card-actions button[hidden], .gateway-files[hidden], #refresh-files[hidden] { display: none; }
#control-status:empty { display: none; }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: Avenir, "Segoe UI", Arial, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
}

.status-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 16px 0;
}

.status-pill,
#connect_http,
#connect_can {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 5px 10px;
    border-radius: 999px;
    background: #475569;
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 700;
}

.brand {
    display: flex;
    justify-content: center;
    padding: 8px 16px 12px;
}

.logo_dalby {
    display: block;
    width: min(280px, 68vw);
    height: auto;
}

nav {
    width: 100%;
    background: var(--surface-soft);
}

nav ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    list-style: none;
    max-width: 980px;
    margin: 0 auto;
}

nav li {
    text-align: center;
}

nav a {
    display: block;
    min-height: 44px;
    padding: 13px 8px 10px;
    border-bottom: 3px solid transparent;
    color: var(--text);
    text-decoration: none;
    font-weight: 800;
}

nav a:hover,
nav a:focus-visible,
.selected {
    color: var(--accent);
    border-bottom-color: var(--accent);
    outline: none;
}

.page-shell {
    width: min(1160px, calc(100% - 24px));
    margin: 20px auto 36px;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.toolbar h1 {
    font-size: 1.45rem;
    line-height: 1.2;
}

.toolbar p,
.panel-heading span,
.param-type {
    color: var(--muted);
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.panel {
    margin-bottom: 18px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel h2 {
    font-size: 1.1rem;
}

.counter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 24px;
    border-radius: 999px;
    background: var(--surface-soft);
    font-weight: 800;
}

.param-layout {
    display: grid;
    gap: 18px;
}

.file-groups {
    display: grid;
    gap: 16px;
}

.file-group h3 {
    margin-bottom: 8px;
    font-size: 1rem;
}

.file-table {
    width: 100%;
    border-collapse: collapse;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.file-table th,
.file-table td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.file-table th {
    background: var(--surface-soft);
    font-size: 0.86rem;
    color: var(--muted);
}

.file-table tr:last-child td {
    border-bottom: 0;
}

.file-table input {
    min-height: auto;
}

.upload-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(180px, 260px) auto;
    gap: 10px;
    align-items: end;
}

.upload-form label {
    display: block;
    grid-row: 1;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.upload-form input,
.upload-form select,
.upload-form button {
    grid-row: 2;
}

.muted {
    color: var(--muted);
}

.param-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 12px;
}

.param-field {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.param-field label {
    font-weight: 800;
    line-height: 1.25;
}

.param-type {
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.param-control,
select,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"] {
    width: 100%;
    min-height: 42px;
    grid-column: 1 / -1;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font-size: 1rem;
}

.param-control:focus,
select:focus,
input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(201, 37, 45, 0.16);
    outline: none;
}

button,
input[type="submit"],
.download_button {
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    padding: 10px 16px;
    color: #ffffff;
    background: var(--accent);
    font-size: 1rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
input[type="submit"]:hover,
.download_button:hover {
    background: var(--accent-dark);
}

.buttonRAF {
    background: var(--ok);
}

.buttonRAF:hover,
.buttonRAF:active {
    background: #0f6b3b;
}

.buttonECR,
.buttonLogErreur {
    background: var(--accent);
}

.centered {
    text-align: center;
}

#infos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
    width: min(1160px, calc(100% - 24px));
    margin: 0 auto 32px;
}

#infos label {
    display: block;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: left;
}

.in-block,
.out-block {
    list-style: none;
    margin-top: 8px;
    line-height: 1.55;
}

#commandes {
    width: min(780px, calc(100% - 24px));
    margin: 18px auto 32px;
}

.btn-double {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 16px minmax(0, 1fr);
    align-items: stretch;
    margin: 0 auto 12px;
}

.h-space {
    width: 16px;
}

.boutton-fonction {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 72px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform 0.08s ease, border-color 0.08s ease;
}

.boutton-fonction:active {
    transform: scale(0.98);
    border-color: var(--accent);
}

.img-cmd {
    width: 100%;
    height: 100%;
    max-height: 90px;
    object-fit: contain;
    pointer-events: none;
}

fieldset {
    width: min(680px, calc(100% - 24px));
    margin: 0 auto;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

legend {
    padding: 0 8px;
}

legend h1 {
    font-size: 1.05rem;
}

#ssid-error,
#mdp-error,
#ssid-error-WIFI,
#mdp-error-WIFI {
    color: var(--accent);
    font-size: 0.9rem;
}

.download_button,
.upload_button {
    display: none;
    margin-top: 8px;
    margin-bottom: 8px;
}

#alert-popup {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    background-color: rgba(15, 23, 42, 0.42);
}

#alert-content {
    width: min(360px, calc(100% - 32px));
    padding: 18px 20px;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 22px 50px rgba(15, 23, 42, 0.25);
    text-align: center;
}

hr {
    display: none;
}

br + br {
    display: none;
}

@media (max-width: 720px) {
    .status-bar {
        justify-content: center;
        flex-wrap: wrap;
    }

    .toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-actions {
        justify-content: stretch;
    }

    .toolbar-actions button {
        flex: 1 1 140px;
    }

    nav a {
        font-size: 0.92rem;
    }

    .file-table {
        display: block;
        overflow-x: auto;
    }

    .upload-form {
        grid-template-columns: 1fr;
    }

    .upload-form label,
    .upload-form input,
    .upload-form select,
    .upload-form button {
        grid-row: auto;
    }
}


.loading-indicator {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-weight: 800;
}

.loading-indicator[hidden] {
    display: none;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.param-section {
    padding: 0;
    overflow: hidden;
}

.param-section > summary {
    cursor: pointer;
    padding: 18px;
    margin: 0;
    list-style: none;
}

.param-section > summary::-webkit-details-marker,
.function-group > summary::-webkit-details-marker {
    display: none;
}

.param-section-heading {
    justify-content: flex-start;
}

.param-section-heading::after,
.function-group > summary::after {
    content: "+";
    color: var(--accent);
    font-weight: 900;
    margin-left: auto;
}

.param-section[open] > .param-section-heading::after,
.function-group[open] > summary::after {
    content: "-";
}

.param-section-body {
    display: grid;
    gap: 14px;
    padding: 0 18px 18px;
}

.function-group {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.function-group > summary {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    font-weight: 900;
    list-style: none;
}

.function-group .param-grid {
    padding: 0 12px 12px;
}

.param-code {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.mapping-list-heading {
    gap: 14px;
}

.mapping-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.mapping-form label {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.mapping-editor-modal {
    width: min(560px, 100%);
}

.mapping-editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

.inner-modal-overlay {
    z-index: 1010;
}

.mapping-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.mapping-actions button {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.88rem;
}

@media (max-width: 820px) {
    .mapping-editor-actions {
        flex-direction: column-reverse;
    }
}


body.modal-open {
    overflow: hidden;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(15, 23, 42, 0.36);
    backdrop-filter: blur(4px);
}

.modal-overlay[hidden] {
    display: none;
}

.modal-panel {
    position: relative;
    width: min(1120px, 100%);
    max-height: min(86vh, 920px);
    overflow: auto;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin: 0 48px 18px 0;
}

.modal-header h2 {
    margin: 0 0 6px;
    font-size: 1.25rem;
}

.modal-header p {
    margin: 0;
    color: var(--muted);
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.35rem;
    line-height: 1;
}

.mapping-modal .panel:last-child {
    margin-bottom: 0;
}

@media (max-width: 700px) {
    .modal-overlay {
        padding: 10px;
    }

    .modal-panel {
        max-height: 92vh;
        padding: 16px;
    }
}

.param-type-unknown {
    color: #b91c1c;
}


.summary-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}


.control-grid {
    display: grid;
    gap: 14px;
}

.control-row {
    display: grid;
    grid-template-columns: minmax(120px, 180px) 1fr 1fr;
    gap: 12px;
    align-items: stretch;
}

.control-title {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font-weight: 800;
}

.boutton-fonction.is-locked,
.boutton-fonction.is-master-locked {
    background: gray;
    cursor: not-allowed;
    opacity: 0.72;
}

.boutton-fonction.is-active {
    background: #8dff93;
}

.command-empty {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-weight: 800;
}

@media (max-width: 760px) {
    .control-row {
        grid-template-columns: 1fr 1fr;
    }

    .control-title {
        grid-column: 1 / -1;
    }
}

/* Local cycle editor */
.cycle-page { display: grid; gap: 20px; }
.app-masthead { background: var(--surface); }
.app-compact-header nav a { display: flex; justify-content: center; align-items: center; gap: 8px; }
.nav-icon { display: block; flex: 0 0 24px; width: 24px; height: 24px; }
@media (max-width: 720px) {
    .app-compact-header nav ul { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .app-compact-header nav a { min-height: 48px; padding: 10px 4px 7px; }
    .app-compact-header .nav-label { display: none; }
}
.cycle-page label { display: flex; flex-direction: column; gap: 7px; font-weight: 600; }
.cycle-page input, .cycle-page select, .cycle-page textarea { width: 100%; min-width: 0; box-sizing: border-box; padding: 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: white; }
.cycle-page button { min-height: 42px; padding: 10px 16px; border-radius: 7px; cursor: pointer; }
.cycle-page button:disabled { opacity: .5; cursor: default; }
.cycle-page fieldset { min-width: 0; border: 0; padding: 0; display: grid; gap: 18px; }
.cycle-run { display: grid; grid-template-columns: 1fr minmax(220px,1fr); gap: 18px; border-top: 4px solid #218451; }
.cycle-progress { display: grid; gap: 7px; }
.cycle-progress strong { font-size: 38px; font-variant-numeric: tabular-nums; }
.cycle-progress progress { width: 100%; accent-color: #218451; }
.cycle-run-actions { display: grid; gap: 12px; align-content: center; }
.cycle-run-actions #startCycle { background: #176a40; color: white; font-weight: 700; }
.cycle-page .cycle-stop { background: #c41924; color: white; min-height: 84px; font-size: 20px; font-weight: 800; border: 3px solid #8e1018; }
.cycle-run > p { grid-column: 1 / -1; }
.cycle-help { color: var(--muted); font-size: 13px; line-height: 1.5; }
#cycleStatus, #editorStatus { font-weight: 650; overflow-wrap: anywhere; }
.cycle-programs, .cycle-metadata, .cycle-step-fields { display: grid; grid-template-columns: repeat(auto-fit,minmax(200px,1fr)); align-items: end; gap: 14px; margin-bottom: 18px; }
.cycle-step { padding: 18px; border: 1px solid var(--line); border-left: 4px solid #377cab; border-radius: 9px; margin-bottom: 14px; background: #f5f8fb; }
.cycle-step-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.cycle-step-head h3 { margin: 0; }
.cycle-step-head button { margin-left: 5px; }
.cycle-editor-actions { display: flex; gap: 12px; flex-wrap: wrap; }
@media(max-width:700px) { .cycle-run { grid-template-columns: 1fr; } .cycle-step-fields { grid-template-columns: 1fr; } }
.cycle-page { padding-bottom: 120px; }
.cycle-page .cycle-stop { position: fixed; bottom: 18px; right: 22px; z-index: 30; max-width: calc(100vw - 44px); box-shadow: 0 4px 20px #0004; }
@media(max-width:700px) { .cycle-page .cycle-stop { left: 16px; right: 16px; max-width: none; min-height: 68px; font-size: 17px; } }
.cycle-choice { border: 2px solid #377cab; }
.cycle-camera-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cycle-camera-view { display: grid; place-items: center; width: 100%; max-width: 960px; margin: 0 auto; aspect-ratio: 4 / 3; background: #142533; color: #fff; border-radius: 10px; overflow: hidden; }
.cycle-camera-view img { width: 100%; height: 100%; object-fit: contain; }
.cycle-camera-view p { padding: 24px; text-align: center; }
.cycle-camera-view [hidden] { display: none; }
.cycle-choice .cycle-help { margin-top: 10px; }
.cycle-mode { font-size: 13px; font-weight: 800; padding: 8px 12px; background: #e6ebf0; border-radius: 7px; }
.cycle-mode.running { color: #12582e; background: #d7f2df; }
#runName { font-size: 24px; font-weight: 800; overflow-wrap: anywhere; }
#runName.cycle-selection-prompt { font-size: clamp(14px, 4vw, 18px); white-space: nowrap; }
#runDescription { color: var(--muted); }
.cycle-library-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.cycle-library-head h2 { margin: 0; }
.cycle-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cycle-program-card { display: grid; align-content: start; gap: 12px; padding: 20px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); overflow-wrap: anywhere; }
.cycle-program-card.is-selected { border-color: #176a40; background: #effaf3; }
.cycle-program-card h3, .cycle-program-card p { margin: 0; }
.cycle-program-card p { color: var(--muted); white-space: pre-wrap; }
.cycle-program-card progress { width: 100%; accent-color: #218451; }
.cycle-program-details { border-top: 1px solid var(--line); padding-top: 10px; }
.cycle-program-details summary { min-height: 44px; padding: 10px 0; cursor: pointer; font-weight: 700; }
.cycle-program-details summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.cycle-program-details ol { padding-left: 24px; }
.cycle-program-details li { padding: 8px 0 8px 4px; line-height: 1.5; }
.cycle-card-actions:empty, .cycle-card-actions[hidden] { display: none; }
.cycle-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cycle-card-actions button[aria-pressed="true"] { background: #176a40; color: white; }
.cycle-page .cycle-delete { color: #a31721; }
.cycle-dialog { box-sizing: border-box; margin: auto; width: min(960px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow-y: auto; padding: 24px; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: white; box-shadow: 0 20px 70px #0005; }
.cycle-dialog::backdrop { background: #142533a8; }
body:has(.cycle-dialog[open]) { overflow: hidden; }
.cycle-page #resetProgram { background: #f4f6f8; color: #17202a; font-weight: 700; border: 1px solid #64748b; }
@media(max-width:700px) { .cycle-cards { grid-template-columns: 1fr; } .cycle-dialog { padding: 16px; } }
