/* BatForge — style */
:root {
    --bg: #f3f4f1;
    --panel: #ffffff;
    --line: #dcdfd8;
    --ink: #1d211c;
    --muted: #6b7166;
    --accent: #1f6f5c;
    --accent-ink: #ffffff;
    --accent-soft: #e2efe9;
    --flow: #6a4fb3;
    --flow-soft: #efeafa;
    --danger: #b3261e;
    --danger-soft: #fbeceb;
    --warn-bg: #fff4e0;
    --warn-ink: #7a4a00;
    --ok-bg: #e6f4ea;
    --ok-ink: #1e5b2e;
    --code-bg: #0f1412;
    --code-ink: #d7e2dc;
    --code-c: #6f8a7f;
    --code-k: #7fd1b5;
    --code-v: #f0c674;
    --code-l: #e88f8f;
    --radius: 10px;
    --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
    --sans: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121513; --panel: #1a1e1c; --line: #2c322f; --ink: #e5e9e6; --muted: #929a95;
        --accent: #4fb596; --accent-ink: #0d1411; --accent-soft: #1e2d27;
        --flow: #a78bfa; --flow-soft: #241f33; --danger: #f2877f; --danger-soft: #3a1f1d;
        --warn-bg: #3a2c12; --warn-ink: #f3cf8a; --ok-bg: #173022; --ok-ink: #9ee2b4; --code-bg: #0b0e0d;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 10px; }
[hidden] { display: none !important; }
code { font-family: var(--mono); font-size: 12.5px; }

/* Barre du haut */
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
.brand small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.logo { font-family: var(--mono); font-weight: 700; background: var(--code-bg); color: var(--code-k); padding: 6px 8px; border-radius: 8px; flex: none; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Boutons et champs */
.btn {
    display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
    border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: inherit; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=email], select, textarea {
    width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea, .mono { font-family: var(--mono); font-size: 13px; }
#templates { width: auto; max-width: 180px; }
.badge { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 1px 8px; font-size: 11.5px; font-weight: 600; text-transform: none; letter-spacing: 0; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.muted-badge { background: var(--bg); color: var(--muted); }

/* Menus déroulants */
.split { display: inline-flex; }
.split > .btn { border-radius: 8px 0 0 8px; }
.split .menu > summary { border-radius: 0 8px 8px 0; border-left: 0; padding: 7px 9px; }
details.menu { position: relative; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
    position: absolute; top: calc(100% + 4px); left: 0; min-width: 220px; z-index: 30;
    background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 5px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.menu-list.right { left: auto; right: 0; }
.menu-list button, .menu-list a {
    display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: inherit; text-decoration: none;
}
.menu-list button:hover, .menu-list a:hover { background: var(--accent-soft); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu-list form { margin: 0; }

/* Mise en page 3 colonnes */
.layout {
    display: grid; grid-template-columns: 280px minmax(0, 1.1fr) minmax(0, 1fr); gap: 14px;
    padding: 14px; height: calc(100vh - 62px);
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; overflow: auto; min-height: 0; }

/* Bibliothèque d'actions */
.lib-group summary { cursor: pointer; font-size: 12px; color: var(--muted); font-weight: 600; margin: 12px 0 4px; list-style-position: inside; }
.lib-item {
    display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left;
    background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; cursor: pointer;
}
.lib-item:hover { background: var(--accent-soft); border-color: var(--line); }
.lib-item strong { display: block; font-weight: 600; }
.lib-item small { display: block; color: var(--muted); font-size: 12px; }
.ico { width: 22px; text-align: center; flex: none; }

/* Paramètres */
.settings { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }
.settings > summary { cursor: pointer; font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0; overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 7px 12px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.grid2 label, .grid3 label, .stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid2 .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; }
.checks label { display: flex; gap: 6px; align-items: center; }
.sim-toggle { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; padding: 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0 0; padding: 10px 12px; }
legend { font-size: 12.5px; color: var(--muted); padding: 0 4px; }

/* Étapes */
.steps-head { display: flex; align-items: center; justify-content: space-between; }
#steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.step { border: 1px solid var(--line); border-radius: 9px; background: var(--panel); margin-left: calc(var(--depth, 0) * 22px); position: relative; }
.step::before {
    content: ""; position: absolute; left: -12px; top: -7px; bottom: -7px; width: 2px; background: var(--flow-soft);
    display: none;
}
.step[style*="--depth:1"]::before, .step[style*="--depth:2"]::before, .step[style*="--depth:3"]::before, .step[style*="--depth:4"]::before, .step[style*="--depth:5"]::before { display: block; }
.step.open { border-color: var(--accent); }
.step.kind-start, .step.kind-mid, .step.kind-end { border-color: color-mix(in srgb, var(--flow) 35%, var(--line)); background: var(--flow-soft); }
.step.kind-start.open { border-color: var(--flow); }
.step.kind-start .num, .step.kind-mid .num, .step.kind-end .num { background: var(--flow); color: #fff; }
.step.kind-mid .step-head, .step.kind-end .step-head { padding-top: 3px; padding-bottom: 3px; }
.step.disabled { opacity: .45; }
.step.dragging { opacity: .4; }
.step.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.step.drop-after { box-shadow: 0 3px 0 var(--accent); }
.step-head { display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.grip { cursor: grab; color: var(--muted); user-select: none; letter-spacing: -2px; padding: 0 2px; }
.num { flex: none; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.step-title { flex: 1; min-width: 0; text-align: left; background: none; border: 0; cursor: pointer; padding: 2px 0; }
.step-title:disabled { cursor: default; color: inherit; }
.step-title small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 12px; }
.step-tools { display: flex; gap: 2px; flex: none; }
.step-tools button { width: 28px; height: 28px; border: 1px solid transparent; background: none; border-radius: 6px; cursor: pointer; color: var(--muted); }
.step-tools button:hover:not(:disabled) { border-color: var(--line); color: var(--ink); background: var(--panel); }
.step-tools button:disabled { opacity: .3; cursor: default; }
.step-tools .danger:hover { color: var(--danger) !important; }
.step-body { display: none; padding: 4px 12px 12px 40px; }
.step.open .step-body { display: block; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
.field.full, .check, .info { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.info { margin: 0; padding: 8px 10px; border-radius: 7px; background: var(--panel); border: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); }
.req { color: var(--danger); font-style: normal; }
.help { color: var(--muted); font-size: 12px; }
.help.ok { color: var(--ok-ink); }
.with-btn { display: flex; gap: 4px; }
.with-btn input { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; border: 1px dashed var(--line); border-radius: 9px; }

/* Aperçu */
.preview { display: flex; flex-direction: column; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.preview-head h2 { margin: 0; }
.preview-head div { display: flex; gap: 6px; flex-wrap: wrap; }
.errors { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 8px 12px 8px 28px; margin: 0 0 10px; font-size: 13px; }
#code { flex: 1; margin: 0; background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 14px; font: 12.5px/1.55 var(--mono); overflow: auto; white-space: pre; tab-size: 4; min-height: 300px; }
#code .c { color: var(--code-c); }
#code .k { color: var(--code-k); font-weight: 600; }
#code .v { color: var(--code-v); }
#code .l { color: var(--code-l); font-weight: 600; }

/* Dialogues */
.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: var(--panel); color: var(--ink); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
.dialog.wide { width: min(820px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dlg-head h2 { margin: 0; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.close { background: none; border: 0; font-size: 16px; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.rows { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; }
.row.current { border-color: var(--accent); background: var(--accent-soft); }
.row-main { min-width: 0; flex: 1 1 260px; }
.row-main small { display: block; font-size: 12px; }
.row-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.row-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }

/* Alertes, pages de compte et d'installation */
.alert { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin: 0 0 12px; }
.alert.ok { background: var(--ok-bg); color: var(--ok-ink); }
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 16px; }
.auth-card.wide { width: min(620px, 100%); }
.auth-card .brand small { max-width: none; }
.radio-row { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 10px; }
.radio-row label { display: flex; gap: 6px; align-items: center; }
.page { max-width: 1100px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table input[type=text], .table input[type=password], .table select { min-width: 120px; }
.table form { margin: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 50; max-width: calc(100vw - 32px); }

/* Responsive */
@media (max-width: 1200px) {
    .layout { grid-template-columns: 250px minmax(0, 1fr); height: auto; }
    .preview { grid-column: 1 / -1; min-height: 460px; }
}
@media (max-width: 760px) {
    .layout { grid-template-columns: 1fr; padding: 10px; }
    .library { max-height: 340px; }
    .fields, .grid2 { grid-template-columns: 1fr; }
    .step { margin-left: calc(var(--depth, 0) * 12px); }
    .step-body { padding-left: 12px; }
    .step-tools button[data-act=dup], .grip { display: none; }
    .topbar { padding: 8px 10px; }
    .brand small { max-width: 70vw; }
    #templates { max-width: 130px; }
}
