:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e1e6ef;
  --text: #17202e;
  --muted: #64708a;
  --primary: #5277c3;
  --primary-2: #3f5fa6;
  --primary-soft: #e8eefb;
  --accent: #7ebae4;
  --ok: #138a52;
  --ok-soft: #e3f6ec;
  --warn: #a8640b;
  --warn-soft: #fdf2df;
  --err: #c0322b;
  --err-soft: #fdeaea;
  --code-bg: #0f1726;
  --code-fg: #d7e0f0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 16px rgba(20, 30, 60, .05);
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1320;
    --surface: #141c2c;
    --surface-2: #1b2538;
    --border: #26324a;
    --text: #e4eaf5;
    --muted: #8e9ab3;
    --primary: #7ea2e8;
    --primary-2: #9ab6ee;
    --primary-soft: #1d2b48;
    --ok: #4cc58a;
    --ok-soft: #12301f;
    --warn: #e7a84a;
    --warn-soft: #33270f;
    --err: #ef6b62;
    --err-soft: #3a1717;
    --code-bg: #0a0f1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-2); padding: .08rem .35rem; border-radius: 5px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .86rem; margin: .5rem 0 0; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ layout */

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 2rem;
  padding: .7rem 1.5rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .3rem; }
.topbar nav a { color: var(--muted); padding: .4rem .8rem; border-radius: 8px; font-weight: 500; }
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.topbar nav a.active { color: var(--primary); background: var(--primary-soft); }

main { max-width: 1440px; margin: 0 auto; padding: 1.5rem; }

.hero {
  padding: 2rem 2.2rem; margin-bottom: 1.5rem;
  border-radius: 18px;
  background: linear-gradient(135deg, #5277c3 0%, #6c95d6 55%, #7ebae4 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 .4rem; font-size: 1.8rem; letter-spacing: -.01em; }
.hero p { margin: 0; max-width: 60rem; opacity: .95; }
.hero code { background: rgba(255, 255, 255, .18); color: #fff; }

.section-title { font-size: 1.1rem; margin: 2rem 0 .8rem; display: flex; align-items: center; gap: .5rem; }
.count {
  display: inline-grid; place-items: center; min-width: 1.6rem; height: 1.6rem; padding: 0 .45rem;
  border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 600;
}

.banner { padding: .85rem 1.1rem; border-radius: var(--radius); margin: 0 0 1rem; border: 1px solid; font-size: .92rem; }
.banner.info { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }

.footer { max-width: 1440px; margin: 0 auto; padding: 1rem 1.5rem 2rem; color: var(--muted); font-size: .8rem; }

.note { margin: 0 0 1rem; font-size: .82rem; color: var(--muted); }
.note code { font-size: .9em; }

.empty {
  padding: 2.5rem; text-align: center; color: var(--muted);
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface);
}

/* ------------------------------------------------------------------ boutons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); }
.btn.small { padding: .3rem .65rem; font-size: .84rem; border-radius: 7px; }
.btn small { opacity: .75; font-weight: 400; }

/* ------------------------------------------------------------------ images de base */

.bases { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.base-card {
  display: flex; gap: 1rem; padding: 1.1rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.base-card:hover { border-color: var(--primary); transform: translateY(-2px); text-decoration: none; }
.base-body { display: flex; flex-direction: column; gap: .2rem; }
.base-body small { color: var(--muted); }
.base-meta { font-size: .78rem; color: var(--muted); margin-top: .3rem; }

.base-icon {
  flex: none; width: 44px; height: 44px; border-radius: 11px;
  background: var(--primary-soft) center / 24px no-repeat;
}
.base-minimal { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235277c3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m4 17 6-5-6-5M12 19h8'/%3E%3C/svg%3E"); }
.base-web { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235277c3' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18'/%3E%3C/svg%3E"); }
.base-docker { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235277c3' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='m12 3 8 4.5v9L12 21l-8-4.5v-9z'/%3E%3Cpath d='m4 7.5 8 4.5 8-4.5M12 12v9'/%3E%3C/svg%3E"); }
.base-kubernetes { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235277c3' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='m12 2 8.5 4.5 2 9-6 7h-9l-6-7 2-9z'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E"); }
.base-dev { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235277c3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m8 8-4 4 4 4M16 8l4 4-4 4M14 5l-4 14'/%3E%3C/svg%3E"); }
.base-desktop { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235277c3' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='4' width='18' height='12' rx='2'/%3E%3Cpath d='M8 20h8M12 16v4'/%3E%3C/svg%3E"); }

/* ------------------------------------------------------------------ liste VMs */

.vm-list { display: flex; flex-direction: column; gap: .6rem; }
.vm-row {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 1.2rem;
  padding: .9rem 1.1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.vm-name { font-weight: 600; font-size: 1.02rem; color: var(--text); }
.vm-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.tag { font-size: .76rem; padding: .1rem .5rem; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.svc { background: var(--primary-soft); color: var(--primary); }
.vm-status { display: flex; flex-direction: column; align-items: flex-end; gap: .15rem; }
.vm-status small { color: var(--muted); }
.vm-actions { display: flex; gap: .3rem; }

.status {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .78rem; font-weight: 600; padding: .15rem .6rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.success { background: var(--ok-soft); color: var(--ok); }
.status.failed { background: var(--err-soft); color: var(--err); }
.status.running, .status.queued { background: var(--primary-soft); color: var(--primary); }
.status.running::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ------------------------------------------------------------------ éditeur */

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(380px, 46%); gap: 1.5rem; align-items: start; }
.editor-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 1rem; }
.title-input {
  flex: 1; font: 700 1.6rem/1.2 inherit; color: var(--text);
  border: 0; border-bottom: 2px solid transparent; background: transparent; padding: .2rem 0; outline: none;
}
.title-input:focus { border-bottom-color: var(--primary); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem 1.3rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 1rem; font-size: 1.02rem; display: flex; align-items: center; gap: .55rem; }
.step {
  display: inline-grid; place-items: center; width: 1.55rem; height: 1.55rem; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: .78rem;
}
details summary { list-style: none; cursor: pointer; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { margin: 0; }
details summary h2::after { content: "▸"; color: var(--muted); margin-left: auto; transition: transform .15s; }
details[open] summary h2 { margin-bottom: 1rem; }
details[open] summary h2::after { transform: rotate(90deg); }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .86rem; font-weight: 500; color: var(--muted); margin-bottom: .8rem; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; font: inherit; font-size: .93rem; color: var(--text);
  padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.invalid { border-color: var(--err) !important; box-shadow: 0 0 0 3px var(--err-soft) !important; }
.code-input { font-family: var(--mono); font-size: .85rem; }

.grid-2, .grid-3 { display: grid; gap: 0 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; margin-bottom: .8rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); font-weight: 400; margin: 0; }
label.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.base-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.base-option {
  flex-direction: row; align-items: center; gap: .7rem; margin: 0; cursor: pointer;
  padding: .65rem; border: 1.5px solid var(--border); border-radius: 10px; color: var(--text); font-weight: 400;
}
.base-option input { position: absolute; opacity: 0; pointer-events: none; }
.base-option .base-icon { width: 36px; height: 36px; background-size: 20px; }
.base-option strong { display: block; font-size: .9rem; }
.base-option small { display: block; color: var(--muted); font-size: .76rem; line-height: 1.3; }
.base-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.base-option:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--primary-soft); }

.segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface-2); margin-bottom: 1rem; }
.segmented label { margin: 0; flex-direction: row; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { padding: .35rem 1rem; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 500; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* paquets */
.pkg-selected { display: flex; flex-wrap: wrap; gap: .35rem; min-height: 2rem; margin-bottom: .8rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .22rem .6rem; border-radius: 99px; font: inherit; font-size: .82rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.chip.selected { background: var(--primary-soft); border-color: transparent; cursor: default; padding-right: .25rem; }
.chip.selected.warn { background: var(--warn-soft); color: var(--warn); }
.chip.selected button {
  border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 1rem; line-height: 1;
  width: 1.3rem; height: 1.3rem; border-radius: 50%; opacity: .6;
}
.chip.selected button:hover { opacity: 1; background: rgba(0, 0, 0, .08); }
.badge { font-size: .66rem; font-weight: 700; text-transform: uppercase; padding: .05rem .35rem; border-radius: 4px; letter-spacing: .03em; }
.badge.unfree { background: var(--warn-soft); color: var(--warn); }

.pkg-search { position: relative; }
.pkg-results {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 360px; overflow: auto; padding: .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(20, 30, 60, .18);
}
.result {
  display: grid; grid-template-columns: 1fr auto; gap: 0 .8rem; width: 100%; text-align: left;
  padding: .5rem .65rem; border: 0; border-radius: 7px; background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.result:hover { background: var(--surface-2); }
.r-main { font-weight: 600; font-size: .9rem; }
.r-main small { color: var(--muted); font-weight: 400; }
.r-desc { grid-column: 1; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-add { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: .8rem; color: var(--primary); font-weight: 600; }
.result.on .r-add { color: var(--ok); }
.r-info { padding: .7rem; color: var(--muted); font-size: .88rem; }
.r-info.error { color: var(--err); }

.pkg-groups { display: grid; gap: .7rem; margin-top: 1rem; }
.pkg-group h4 { margin: 0 0 .35rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.pkg-group > div { display: flex; flex-wrap: wrap; gap: .3rem; }

/* services */
.services { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .55rem; }
.service {
  flex-direction: row; align-items: flex-start; gap: .6rem; margin: 0; cursor: pointer;
  padding: .7rem; border: 1.5px solid var(--border); border-radius: 10px; color: var(--text); font-weight: 400;
}
.service input { margin-top: .2rem; accent-color: var(--primary); }
.service strong { display: block; font-size: .9rem; }
.service small { display: block; color: var(--muted); font-size: .78rem; line-height: 1.35; }
.service em { display: block; font-style: normal; font-size: .72rem; color: var(--primary); margin-top: .2rem; }
.service.on { border-color: var(--primary); background: var(--primary-soft); }

/* panneau latéral */
.editor-side { min-width: 0; }
.side-sticky { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 1rem; max-height: calc(100vh - 92px); }
.actions { display: flex; flex-direction: column; gap: .5rem; }
.actions .btn.primary { padding: .8rem; font-size: 1rem; }
.actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.errors { background: var(--err-soft); color: var(--err); border-radius: var(--radius); padding: .8rem 1rem; font-size: .88rem; }
.errors ul { margin: .3rem 0 0; padding-left: 1.2rem; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.panel-head h3 { margin: 0; font-size: .95rem; }
#builds { max-height: 260px; overflow: auto; }
.build { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.build:last-child { border-bottom: 0; }
.build-head { display: flex; align-items: center; gap: .6rem; }
.build-error { color: var(--err); font-size: .84rem; margin-top: .4rem; padding: 0 1rem 0 0; }
.build-files, .build-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.pad { padding: 1rem; }

.preview { position: relative; display: flex; flex-direction: column; min-height: 320px; flex: 1; background: var(--code-bg); border-color: var(--code-bg); }
.tabs { display: flex; overflow-x: auto; background: rgba(255, 255, 255, .04); border-bottom: 1px solid rgba(255, 255, 255, .08); }
.tab {
  padding: .6rem .9rem; border: 0; background: transparent; color: #8c9ab5; font: 500 .82rem var(--mono);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: #d7e0f0; }
.tab.active { color: #fff; border-bottom-color: var(--accent); }
.code { margin: 0; padding: 1rem 1.1rem; overflow: auto; flex: 1; color: var(--code-fg); font: .8rem/1.6 var(--mono); tab-size: 2; }
.code code { background: none; padding: 0; font-size: inherit; }
.copy { position: absolute; top: 2.9rem; right: .8rem; color: #aab6cc; border-color: rgba(255, 255, 255, .15); }
.copy:hover { background: rgba(255, 255, 255, .08); }
.t-c { color: #6c7a96; font-style: italic; }
.t-s { color: #a5d6a7; }
.t-k { color: #c792ea; }
.t-b { color: #f78c6c; }
.t-n { color: #f78c6c; }
.t-a { color: #82aaff; }

/* journal */
.log-dialog {
  width: min(1100px, 94vw); height: min(80vh, 900px); padding: 0; border: 0; border-radius: 14px;
  background: var(--code-bg); color: var(--code-fg); box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}
.log-dialog[open] { display: flex; flex-direction: column; }
.log-dialog::backdrop { background: rgba(10, 15, 26, .6); backdrop-filter: blur(2px); }
.log-head { display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.log-head h3 { margin: 0; font-size: .95rem; }
.log-head .btn { color: #c6d0e2; border-color: rgba(255, 255, 255, .15); }
.log { flex: 1; margin: 0; padding: 1rem; overflow: auto; font: .78rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; z-index: 100; transform: translate(-50%, 1rem);
  padding: .7rem 1.1rem; border-radius: 10px; background: #17202e; color: #fff; font-size: .9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: min(640px, 92vw);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: var(--ok); }
.toast.error { background: var(--err); }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .side-sticky { position: static; max-height: none; }
  .preview { max-height: 70vh; }
}
@media (max-width: 720px) {
  main { padding: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .vm-row { grid-template-columns: 1fr; }
  .vm-status { align-items: flex-start; }
  .vm-actions { flex-wrap: wrap; }
  .topbar { gap: 1rem; padding: .6rem 1rem; }
}
