:root {
    color-scheme: light;
    --bg: #f3f6fb;
    --surface: #ffffff;
    --card: #ffffff;
    --border: #ccd5e2;
    --text: #172033;
    --muted: #526176;
    --accent: #4338ca;
    --accent-hover: #3730a3;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --green: #166534;
    --red: #b91c1c;
    --yellow: #854d0e;
    --blue: #1d4ed8;
    --tint: #6366f110;
    --shadow: 0 8px 28px #17203320;
    --radius: 10px;
    --page-gutter: clamp(12px, 2vw, 32px);
    --nav-height: 64px;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        color-scheme: dark;
        --bg: #0b1020;
        --surface: #11192c;
        --card: #192338;
        --border: #334158;
        --text: #e7edf7;
        --muted: #a9b6ca;
        --accent: #a5a7ff;
        --accent-hover: #c1c3ff;
        --primary: #5456d9;
        --primary-hover: #4547bd;
        --green: #4ade80;
        --red: #fb7185;
        --yellow: #facc15;
        --blue: #60a5fa;
        --tint: #a5a7ff18;
        --shadow: 0 8px 28px #0006;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1020;
    --surface: #11192c;
    --card: #192338;
    --border: #334158;
    --text: #e7edf7;
    --muted: #a9b6ca;
    --accent: #a5a7ff;
    --accent-hover: #c1c3ff;
    --primary: #5456d9;
    --primary-hover: #4547bd;
    --green: #4ade80;
    --red: #fb7185;
    --yellow: #facc15;
    --blue: #60a5fa;
    --tint: #a5a7ff18;
    --shadow: 0 8px 28px #0006;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}
.app-nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .65rem var(--page-gutter);
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 64px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
}
.app-nav .logo {
    font-weight: 750;
    font-size: 1.15rem;
    color: var(--accent);
    letter-spacing: -.03em;
}
.app-nav .nav-links {
    display: flex;
    flex: 1;
    align-items: center;
    flex-wrap: wrap;
    gap: .2rem;
    min-width: 0;
}
.app-nav .nav-links a {
    color: var(--muted);
    font-size: .82rem;
    font-weight: 550;
    padding: .5rem;
    border-radius: 6px;
}
.app-nav .nav-links a:hover, .app-nav .nav-links a.active {
    color: var(--accent);
    background: var(--tint);
    text-decoration: none;
}
.app-nav .nav-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 .2rem;
}
.app-nav .user-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: .65rem;
    min-width: 0;
    font-size: .8rem;
    color: var(--muted);
}
.app-nav .user-info .avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
}
.app-nav .user-info a {
    font-size: .75rem;
    white-space: nowrap;
}
.app-nav .user-info .profile-link {
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.theme-control {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .75rem;
    color: var(--muted);
}
.theme-control select {
    padding: .4rem .3rem;
    width: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
.guest-appearance {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10;
}
.notif-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    border-radius: 999px;
    background: var(--red);
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0 4px;
    margin-left: 3px;
    vertical-align: middle;
    line-height: 1;
}
main {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: var(--page-gutter);
}
h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    letter-spacing: -0.02em;
}
h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
}
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th {
    text-align: left;
    padding: 0.6rem 1rem;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 0.7rem 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}
tr:last-child td {
    border-bottom: none;
}
tr:hover td {
    background: rgba(99,102,241,0.04);
}
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-done, .badge-DONE {
    background: rgba(34,197,94,0.12);
    color: var(--green);
}
.badge-running, .badge-RUNNING {
    background: rgba(99,102,241,0.12);
    color: var(--accent);
}
.badge-preparing, .badge-PREPARING {
    background: rgba(59,130,246,0.12);
    color: var(--blue);
}
.badge-queued, .badge-QUEUED {
    background: rgba(234,179,8,0.12);
    color: var(--yellow);
}
.badge-pending, .badge-PENDING {
    background: rgba(113,115,138,0.15);
    color: var(--muted);
}
.badge-failed, .badge-FAILED, .badge-stalled, .badge-STALLED {
    background: rgba(239,68,68,0.12);
    color: var(--red);
}
.badge-aborted, .badge-ABORTED {
    background: rgba(113,115,138,0.12);
    color: var(--muted);
}
.badge-archived, .badge-ARCHIVED {
    background: rgba(113,115,138,0.08);
    color: var(--muted);
}
.badge-admin {
    background: rgba(99,102,241,0.12);
    color: var(--accent);
}
.badge-user {
    background: rgba(113,115,138,0.12);
    color: var(--muted);
}
a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid var(--border);
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
    transition: all 0.15s;
}
.btn:hover {
    background: var(--card);
    border-color: var(--accent);
    text-decoration: none;
}
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
}
.btn-danger {
    border-color: var(--red);
    color: var(--red);
}
.btn-danger:hover {
    background: rgba(239,68,68,0.1);
}
.empty {
    text-align: center;
    padding: 3rem;
    color: var(--muted);
}
.grid-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.stat-card .label {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}
.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
}
.text-muted {
    color: var(--muted);
}
.text-sm {
    font-size: 0.8rem;
}
.mt-1 {
    margin-top: 0.5rem;
}
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
}
.login-box {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 3rem 2.5rem;
    text-align: center;
    max-width: 400px;
    width: 100%;
}
.login-box h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}
.login-box p {
    color: var(--muted);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}
.login-box .btn {
    font-size: 0.9rem;
    padding: 0.6rem 1.5rem;
}
.hamburger {
    display: none;
    padding: .6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    margin: 4px 0;
    background: currentColor;
}
@media (max-width: 1280px) {
    .app-nav {
        flex-wrap: wrap;
        gap: .5rem;
    }
    .js .hamburger {
        display: block;
    }
    .app-nav .nav-links {
        width: 100%;
        flex-basis: 100%;
    }
    .js .app-nav .nav-links {
        display: none;
        position: fixed;
        top: var(--nav-height);
        left: 0;
        right: 0;
        max-height: calc(100dvh - var(--nav-height));
        overflow-y: auto;
        overscroll-behavior: contain;
        padding: .75rem var(--page-gutter);
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow);
        grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    }
    .js .app-nav .nav-links.open {
        display: grid;
    }
    .app-nav .nav-links a {
        padding: .8rem;
    }
    .app-nav .nav-sep {
        display: none;
    }
}
@media (max-width: 600px) {
    .app-nav .user-info {
        flex-basis: 100%;
        justify-content: flex-end;
        gap: .6rem;
    }
    .app-nav .user-info .profile-link {
        max-width: 7rem;
    }
    .app-nav .user-info .avatar, .app-nav .theme-control > span {
        display: none;
    }
    .hamburger {
        margin-left: auto;
    }
    .card {
        padding: 1rem;
    }
    .login-container {
        padding: 4rem 1rem 1rem;
    }
    .login-box {
        padding: 2rem 1.25rem;
    }
}
/* ── Pages sans footer (chat) ───────────────── */
html.chat-page footer {
    display: none !important;
}
html.chat-page body {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}
html.chat-page main {
    max-width: none !important;
    width: 100% !important;
    min-height: 0;
    padding: 0.5rem 0.75rem;
    margin: 0;
}
/* ── Toasts ───────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
    color: var(--text);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: 360px;
    animation: toast-in 0.2s ease;
}
.toast-error {
    border-left: 3px solid var(--red);
    color: var(--red);
}
.toast-success {
    border-left: 3px solid var(--green);
    color: var(--green);
}
.toast-warning {
    border-left: 3px solid var(--yellow);
    color: var(--yellow);
}
.toast-info {
    border-left: 3px solid var(--accent);
    color: var(--accent);
}
@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
/* ── Rendu Markdown (marked.js) ────────────────────────── */
.md-content h1, .md-content h2, .md-content h3, .md-content h4 {
    color: var(--text);
    margin: 0.9rem 0 0.4rem;
    line-height: 1.3;
    font-weight: 600;
}
.md-content h1 {
    font-size: 1.3rem;
}
.md-content h2 {
    font-size: 1.15rem;
}
.md-content h3 {
    font-size: 1.05rem;
}
.md-content h4 {
    font-size: 0.95rem;
}
.md-content p {
    margin: 0.4rem 0;
    line-height: 1.65;
}
.md-content ul, .md-content ol {
    margin: 0.4rem 0 0.4rem 1.4rem;
    padding: 0;
}
.md-content li {
    margin: 0.2rem 0;
    line-height: 1.6;
}
.md-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.6rem 0;
    padding: 0.3rem 0.8rem;
    color: var(--muted);
    font-style: italic;
}
.md-content code {
    background: rgba(99,102,241,0.12);
    color: var(--accent);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'Fira Code', 'Cascadia Code', monospace;
}
.md-content pre {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.8rem 1rem;
    overflow-x: auto;
    margin: 0.6rem 0;
}
.md-content pre code {
    background: none;
    color: var(--text);
    padding: 0;
    font-size: 0.85em;
    line-height: 1.6;
}
.md-content a {
    color: var(--accent);
    text-decoration: underline;
}
.md-content a:hover {
    color: var(--accent-hover);
}
.md-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.8rem 0;
}
.md-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6rem 0;
    font-size: 0.9em;
}
.md-content th, .md-content td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.7rem;
    text-align: left;
}
.md-content th {
    background: var(--card);
    font-weight: 600;
}
.md-content strong {
    color: var(--text);
    font-weight: 600;
}
/* Shared bounds keep large tables and auxiliary panels inside the viewport. */
main > *, .card, form {
    min-width: 0;
}
input, select, textarea {
    max-width: 100%;
}
img, video {
    max-width: 100%;
}
.table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
}
.table-scroll:focus-visible {
    outline-offset: -2px;
}
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}
body .logs-panel, body .opt-panel {
    top: var(--nav-height);
}
body .logs-panel:not(.open), body .opt-panel:not(.open) {
    display: none;
}
#toast-container {
    max-width: calc(100vw - 2rem);
    right: 1rem;
}
.toast {
    max-width: 100%;
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}
.stat-card .value {
    overflow-wrap: anywhere;
}
.page-heading, .action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
}
.form-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.tab-nav {
    max-width: 100%;
    overflow-x: auto;
}
.tab-nav > * {
    flex-shrink: 0;
}
.step-row > * {
    min-width: 0;
}
@media (max-width: 700px) {
    .form-columns {
        grid-template-columns: minmax(0, 1fr);
    }
    .step-row {
        grid-template-columns: 2.8rem minmax(0, 1fr) auto auto !important;
    }
    .step-row > :nth-child(2) {
        grid-column: 2 / -1;
    }
    .step-row > :nth-child(3) {
        grid-column: 2;
    }
}
