/* ==========================================================================
   Chronos — modèles : liste, éditeur visuel, écran d'application (préfixe `tb-`)
   ========================================================================== */

/* ---------- conteneurs ---------- */
#modal-scroll-container:has(#manage-templates-modal-content),
#modal-scroll-container:has(#tpl-builder),
#modal-scroll-container:has(#apply-template-modal) {
    max-width: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #14161b;
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 22px;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8);
}
#modal-scroll-container:has(#manage-templates-modal-content) { width: min(760px, calc(100vw - 40px)); max-height: min(88vh, 820px); }
#modal-scroll-container:has(#tpl-builder) { width: min(1340px, calc(100vw - 32px)); height: min(92vh, 920px); max-height: none; margin: 0 16px; }
#modal-scroll-container:has(#apply-template-modal) { width: min(900px, calc(100vw - 40px)); max-height: min(90vh, 820px); }
#modal-scroll-container:has(#manage-templates-modal-content) #modal-content,
#modal-scroll-container:has(#tpl-builder) #modal-content,
#modal-scroll-container:has(#apply-template-modal) #modal-content { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#modal-scroll-container:has(#tpl-builder) *, #modal-scroll-container:has(#apply-template-modal) * { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.14) transparent; }

#manage-templates-modal-content { --mp-line: rgba(255, 255, 255, 0.09); --mp-muted: #9aa1ad; --mp-faint: #6b7280; --mp-text: #e6e9ef; --mp-accent: #7aa7ff; }
#manage-templates-modal-content .mp-item { border-left-color: #7aa7ff; }
#manage-templates-modal-content .mp-acts-main { opacity: 1; }
.tb-var { display: inline-block; padding: 0 7px; font: 12px/1.6 ui-monospace, Consolas, monospace; color: #dcc8ff; background: rgba(189, 147, 249, 0.16); border: 1px solid rgba(189, 147, 249, 0.5); border-radius: 6px; }
button.tb-var { cursor: pointer; }
button.tb-var:hover { background: rgba(189, 147, 249, 0.3); }

/* ---------- coque commune ---------- */
.tb {
    --tb-line: rgba(255, 255, 255, 0.09);
    --tb-muted: #9aa1ad;
    --tb-faint: #6b7280;
    --tb-text: #e6e9ef;
    --tb-accent: #7aa7ff;
    --mp-line: var(--tb-line); --mp-muted: var(--tb-muted); --mp-faint: var(--tb-faint); --mp-text: var(--tb-text); --mp-accent: var(--tb-accent);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    color: var(--tb-text);
    font-size: 14px;
}
.tb *, .tb *::before, .tb *::after { box-sizing: border-box; }
.tb-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--tb-line); }
.tb-badge { display: grid; place-items: center; flex: none; width: 42px; height: 42px; font-size: 21px; color: var(--tb-accent); background: rgba(122, 167, 255, 0.14); border: 1px solid rgba(122, 167, 255, 0.32); border-radius: 13px; }
.tb-name { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.tb-name > span { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tb-faint); }
.tb-name > b { font-size: 1.15rem; color: #fff; }
.tb-name input { width: 100%; padding: 2px 0; font-size: 1.2rem; font-weight: 700; color: #fff; background: transparent; border: 0; border-bottom: 1px dashed transparent; outline: none; }
.tb-name input:hover { border-bottom-color: var(--tb-line); }
.tb-name input:focus { border-bottom-color: var(--tb-accent); }
.tb-x { display: grid; place-items: center; width: 36px; height: 36px; font-size: 20px; color: var(--tb-muted); background: transparent; border: 0; border-radius: 10px; cursor: pointer; }
.tb-x:hover { color: #fff; background: rgba(255, 255, 255, 0.09); }

.tb-seg { display: inline-flex; padding: 3px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--tb-line); border-radius: 12px; }
.tb-seg button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 13px; font-size: 13px; font-weight: 600; color: var(--tb-muted); background: none; border: 0; border-radius: 9px; cursor: pointer; }
.tb-seg button:hover { color: #fff; }
.tb-seg button.on { color: #0b1220; background: var(--tb-accent); }

.tb-notice { margin: 12px 20px 0; padding: 9px 13px; font-size: 13px; color: #fde68a; background: rgba(251, 191, 36, 0.1); border: 1px solid rgba(251, 191, 36, 0.4); border-radius: 11px; }
.tb-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr) 310px; }
.tb-apply-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.tb-col { min-width: 0; min-height: 0; overflow-y: auto; padding: 16px 18px; }
.tb-col + .tb-col { border-left: 1px solid var(--tb-line); }
.tb-side { background: rgba(0, 0, 0, 0.16); }
@media (max-width: 1100px) { .tb-body { grid-template-columns: 260px minmax(0, 1fr); } .tb-side { display: none; } }
@media (max-width: 760px) { .tb-body, .tb-apply-body { grid-template-columns: 1fr; overflow-y: auto; } .tb-col { overflow: visible; } .tb-col + .tb-col { border-left: 0; border-top: 1px solid var(--tb-line); } }

.tb-h { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; padding: 0; font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--tb-muted); border: 0; }
.tb-h i { font-size: 16px; color: var(--tb-accent); }
.tb-pill { padding: 1px 9px; font-size: 10.5px; letter-spacing: 0; text-transform: none; color: var(--tb-text); background: rgba(255, 255, 255, 0.08); border-radius: 999px; }
.tb-count { margin-left: auto; padding: 1px 9px; font-size: 11px; letter-spacing: 0; text-transform: none; background: rgba(255, 255, 255, 0.08); border-radius: 999px; }
.tb-hint { margin: 0 0 12px; font-size: 12.5px; line-height: 1.5; color: var(--tb-muted); }
.tb-hint code { color: #dcc8ff; }
.tb-foot { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--tb-line); background: rgba(0, 0, 0, 0.22); }
.tb-foot-msg { flex: 1; font-size: 13px; color: var(--tb-muted); }
.tb-foot-msg.err { color: #fca5a5; }
.tb .mp-primary:disabled { opacity: 0.5; cursor: wait; }

/* ---------- champs ---------- */
.tb-f { display: block; margin-bottom: 12px; }
.tb-f > span { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600; color: var(--tb-muted); }
.tb-f > span em { font-style: normal; font-weight: 400; color: var(--tb-faint); }
.tb-in { width: 100%; height: 36px; padding: 0 11px; font: inherit; font-size: 13.5px; color: var(--tb-text); background: #0e1014; border: 1px solid var(--tb-line); border-radius: 10px; outline: none; transition: border-color 0.15s, box-shadow 0.15s; }
.tb-in:focus { border-color: var(--tb-accent); box-shadow: 0 0 0 3px rgba(122, 167, 255, 0.18); }
textarea.tb-in { height: auto; padding: 8px 11px; resize: vertical; }
.tb-code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
select.tb-in { cursor: pointer; }
.tb-range { width: 100%; accent-color: var(--tb-accent); margin-top: 8px; }
.tb-g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tb-g3 { display: grid; grid-template-columns: 90px 1fr 1fr; gap: 12px; }
.tb-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--tb-text); background: rgba(255, 255, 255, 0.07); border: 1px solid var(--tb-line); border-radius: 9px; cursor: pointer; }
.tb-btn:hover { background: rgba(255, 255, 255, 0.13); }
.tb-ib { display: inline-grid; place-items: center; width: 26px; height: 26px; font-size: 14px; color: var(--tb-muted); background: transparent; border: 0; border-radius: 7px; cursor: pointer; }
.tb-ib:hover:not(:disabled) { color: #fff; background: rgba(255, 255, 255, 0.12); }
.tb-ib:disabled { opacity: 0.3; cursor: default; }
.tb-ib.tb-del:hover { color: #fecaca; background: rgba(248, 113, 113, 0.2); }
.tb-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tb-chips .tb-in { width: 160px; height: 28px; font-size: 12.5px; }
.tb-tag { display: inline-flex; align-items: center; gap: 2px; padding: 1px 3px 1px 10px; font-size: 12.5px; background: rgba(122, 167, 255, 0.14); border: 1px solid rgba(122, 167, 255, 0.4); border-radius: 999px; }
.tb-tag.ro { padding: 0 9px; font-size: 11.5px; }
.tb-tag button { padding: 0 5px; color: var(--tb-muted); background: none; border: 0; cursor: pointer; }
.tb-tag button:hover { color: #fca5a5; }

/* ---------- arbre ---------- */
.tb-tree { display: flex; flex-direction: column; gap: 2px; }
.tb-tn { display: flex; align-items: center; gap: 7px; width: calc(100% - 0px); padding: 5px 8px; text-align: left; font: inherit; color: var(--tb-text); background: transparent; border: 1px solid transparent; border-radius: 10px; cursor: pointer; }
.tb-tn:hover { background: rgba(255, 255, 255, 0.06); }
.tb-tn.sel { background: rgba(122, 167, 255, 0.15); border-color: rgba(122, 167, 255, 0.5); }
.tb-ic { width: 22px; flex: none; text-align: center; }
.tb-nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-nm i { color: var(--tb-faint); }
.tb-dot { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; }
.tb-warn { color: #fbbf24; }
.tb-acts { display: none; flex: none; }
.tb-tn:hover .tb-acts, .tb-tn.sel .tb-acts, .tb-tn:focus-within .tb-acts { display: inline-flex; }
.tb-addroot { margin-top: 6px; color: var(--tb-accent); border: 1px dashed rgba(122, 167, 255, 0.4); }
.tb-addroot:hover { background: rgba(122, 167, 255, 0.1); }

/* ---------- fiche ---------- */
.tb-varbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 14px; padding: 8px 10px; background: rgba(189, 147, 249, 0.07); border: 1px dashed rgba(189, 147, 249, 0.4); border-radius: 11px; }
.tb-varbar > span { font-size: 12px; color: var(--tb-muted); }
.tb-varbar .tb-in { width: 210px; height: 28px; font-size: 12.5px; }
.tb-tabs { display: flex; gap: 4px; margin: 4px 0 10px; padding-top: 12px; border-top: 1px solid var(--tb-line); }
.tb-tab { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--tb-muted); background: transparent; border: 1px solid transparent; border-radius: 10px; cursor: pointer; }
.tb-tab:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.tb-tab.on { color: #fff; background: rgba(122, 167, 255, 0.16); border-color: rgba(122, 167, 255, 0.35); }
.tb-dot2 { width: 7px; height: 7px; background: var(--tb-accent); border-radius: 50%; }
.tb-cnt { padding: 0 6px; font-size: 11px; background: rgba(255, 255, 255, 0.12); border-radius: 99px; }
.tb-tabbody { min-height: 260px; }
.tb-tabbody .dsc { min-height: 240px; padding: 10px 12px; background: rgba(0, 0, 0, 0.18); border: 1px solid var(--tb-line); border-radius: 12px; }
.tb-tabbody .sf-stage { min-height: 260px; }
.tb-arow { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }

/* ---------- aperçu / résultat ---------- */
.tb-preview { padding: 10px 12px; font-size: 13px; background: rgba(0, 0, 0, 0.22); border: 1px solid var(--tb-line); border-radius: 12px; }
.tb-pr { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.tb-pr .mut { width: 12px; color: var(--tb-faint); }
.tb-pre { margin: 10px 0 0; padding: 10px; max-height: 280px; overflow: auto; font: 11.5px/1.5 ui-monospace, Consolas, monospace; color: #c8d0e0; white-space: pre-wrap; word-break: break-word; background: #0e1014; border: 1px solid var(--tb-line); border-radius: 10px; }

/* suppression d'une variable */
.tb-vw { display: inline-flex; align-items: center; }
.tb-vw .tb-var { border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: 0; }
.tb-vx { display: inline-grid; place-items: center; height: 21.6px; width: 20px; padding: 0; font-size: 12px; color: #dcc8ff; background: rgba(189, 147, 249, 0.16); border: 1px solid rgba(189, 147, 249, 0.5); border-left: 0; border-radius: 0 6px 6px 0; cursor: pointer; }
.tb-vx:hover { color: #fff; background: rgba(248, 113, 113, 0.5); border-color: rgba(248, 113, 113, 0.7); }
.tb-vx-side { float: right; width: 22px; height: 20px; border: 0; border-radius: 6px; background: transparent; color: var(--tb-muted); }

/* ---------- thème de l'éditeur ---------- */
#modal-scroll-container:has(#editor-theme-modal) { max-width: none; width: min(1000px, calc(100vw - 40px)); max-height: min(90vh, 860px); display: flex; flex-direction: column; overflow: hidden; background: #14161b; border: 1px solid rgba(255, 255, 255, 0.11); border-radius: 22px; box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8); }
#modal-scroll-container:has(#editor-theme-modal) #modal-content { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.et-body { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
@media (max-width: 760px) { .et-body { grid-template-columns: 1fr; } }
.et-controls .tb-h { margin-top: 14px; }
.et-controls .tb-h:first-of-type { margin-top: 4px; }
.et-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }
.et-row input[type="color"] { flex: none; width: 38px; height: 32px; padding: 2px; background: #0e1014; border: 1px solid var(--tb-line); border-radius: 9px; cursor: pointer; }
.et-lbl { flex: 1; font-size: 13.5px; }
.et-state { font-size: 11px; color: var(--tb-faint); }
.et-row.is-set .et-state { color: var(--tb-accent); font-weight: 700; }
.et-row:not(.is-set) [data-reset] { visibility: hidden; }
.et-preview { padding: 14px 18px; background: #14161b; border: 1px solid var(--tb-line); border-radius: 14px; }
.et-preview .rich h1, .et-preview .rich h2, .et-preview .rich h3, .et-preview .rich h4 { color: var(--ed-h1, inherit); }
.et-preview .rich h2 { color: var(--ed-h2, inherit); }
.et-preview .rich h3 { color: var(--ed-h3, inherit); }
.et-preview .rich h4 { color: var(--ed-h4, #b9c0cf); }
.et-preview .rich table { width: 100%; }
.et-preview .rich thead th { text-align: left; }
.et-preview .rich pre { margin: .5em 0 0; color: #d6dbe6; font: 13px/1.5 Consolas, monospace; }
.et-preview .todo { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.tb-foot .mp-ghost i { margin-right: 4px; }
.et-preview .rich h1, .et-preview .rich h2, .et-preview .rich h3, .et-preview .rich h4 { padding: 0; border: 0; background: none; }

/* ---------- webhooks ---------- */
#modal-scroll-container:has(#manage-webhooks-modal-content), #modal-scroll-container:has(#edit-webhook-modal) { max-width: none; display: flex; flex-direction: column; overflow: hidden; background: #14161b; border: 1px solid rgba(255, 255, 255, 0.11); border-radius: 22px; box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8); }
#modal-scroll-container:has(#manage-webhooks-modal-content) { width: min(780px, calc(100vw - 40px)); max-height: min(88vh, 820px); }
#modal-scroll-container:has(#edit-webhook-modal) { width: min(1120px, calc(100vw - 32px)); height: min(92vh, 900px); }
#modal-scroll-container:has(#manage-webhooks-modal-content) #modal-content, #modal-scroll-container:has(#edit-webhook-modal) #modal-content { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#manage-webhooks-modal-content { --mp-line: rgba(255, 255, 255, 0.09); --mp-muted: #9aa1ad; --mp-faint: #6b7280; --mp-text: #e6e9ef; --mp-accent: #7aa7ff; }
#manage-webhooks-modal-content .mp-item { border-left-color: #38bdf8; }
#manage-webhooks-modal-content code { color: #dcc8ff; }
.wh-body { grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); }
@media (max-width: 800px) { .wh-body { grid-template-columns: 1fr; } }
.wh-presets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.wh-presets .small { color: var(--tb-muted); font-size: 12px; }
.wh-url { display: grid; grid-template-columns: 110px 1fr; gap: 8px; margin-bottom: 6px; }
.wh-conf .tb-h { margin-top: 18px; }
.wh-conf .tb-h:first-of-type { margin-top: 8px; }
.wh-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; margin-bottom: 6px; align-items: center; }
.wh-arow { display: grid; grid-template-columns: 1fr 1.2fr 90px auto; gap: 8px; margin-bottom: 6px; align-items: center; }
.wh-ahead { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--tb-faint); margin-bottom: 2px; }
.wh-chk { display: flex; justify-content: center; }
.wh-chk input { width: 16px; height: 16px; accent-color: var(--tb-accent); }
.wh-res { margin-top: 10px; padding: 10px 12px; border: 1px solid; border-radius: 12px; font-size: 13px; }
.wh-res b { display: block; }
.wh-res span { display: block; margin-top: 2px; color: var(--tb-muted); }
.wh-res.ok { background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.45); }
.wh-res.ok b { color: #6ee7b7; }
.wh-res.bad { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.5); }
.wh-res.bad b { color: #fca5a5; }
.tb [hidden], .wh [hidden] { display: none !important; }
