/*
	HTML App Creator — éditeur, page publique d'une app, galerie, administration.
	Mêmes couleurs et polices que walter.tw (style « Bento aéré »), thème clair/sombre.
*/
@font-face { font-family: "Plus Jakarta Sans"; src: url("/assets/fonts/plus-jakarta-sans.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Open Sans"; src: url("/assets/fonts/open-sans.woff2") format("woff2"); font-weight: 300 800; font-display: swap; }

:root {
	--bg: #F4F9FC; --surface: #FFFFFF; --surface-2: #EEF5FA; --ink: #3E4753; --heading: #1C2A35; --muted: #6A7581;
	--line: #DFE8EF; --accent: #1E8FC2; --accent-ink: #FFFFFF; --brand: #43B3E0; --band: #E6F3FA;
	--danger: #C93C3C; --warn: #B7791F; --success: #1F8A5B;
	--display: "Plus Jakarta Sans", "Open Sans", system-ui, sans-serif;
	--body: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
	--mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
	--radius: 16px; --radius-sm: 10px;
	--shadow: 0 14px 34px -18px rgba(30, 90, 130, .35);
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #0F151A; --surface: #172028; --surface-2: #1C2731; --ink: #C3CCD4; --heading: #F0F5F8; --muted: #8B96A0;
		--line: #26323C; --accent: #5BC2EA; --accent-ink: #0E1418; --band: #142029; --danger: #F07070; --warn: #E6B450; --success: #4CC38A;
		--shadow: 0 14px 34px -18px rgba(0, 0, 0, .8); color-scheme: dark;
	}
}
:root[data-theme="dark"] {
	--bg: #0F151A; --surface: #172028; --surface-2: #1C2731; --ink: #C3CCD4; --heading: #F0F5F8; --muted: #8B96A0;
	--line: #26323C; --accent: #5BC2EA; --accent-ink: #0E1418; --band: #142029; --danger: #F07070; --warn: #E6B450; --success: #4CC38A;
	--shadow: 0 14px 34px -18px rgba(0, 0, 0, .8); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 14px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.ic { width: 18px; height: 18px; flex: none; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Boutons ---------- */
.hbtn {
	display: inline-flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px;
	border: 1px solid var(--line); background: var(--surface); color: var(--heading); font-weight: 600; font-size: 13px;
	white-space: nowrap; text-decoration: none; line-height: 1.2;
}
.hbtn:hover { background: var(--band); }
.hbtn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.hbtn.primary:hover { filter: brightness(1.07); }
.hbtn.danger { color: var(--danger); }
.hbtn.subtle { border-color: transparent; background: transparent; color: var(--muted); }
.hbtn.icon { padding: 7px; }
.hbtn[disabled] { opacity: .5; pointer-events: none; }
.hbtn .kbd { font-size: 11px; opacity: .65; font-weight: 500; }
input[type="text"], input[type="url"], input[type="password"], textarea, select {
	width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); color: var(--heading);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
label { font-weight: 600; font-size: 13px; color: var(--heading); }
.field { display: grid; gap: 5px; }

/* ---------- Éditeur : structure ---------- */
body.editor { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
	display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
	background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.logo { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-family: var(--display); font-weight: 800; font-size: 13px; text-decoration: none; flex: none; }
.app-title { flex: 1 1 180px; min-width: 120px; display: flex; align-items: center; gap: 8px; }
.app-title input { border-color: transparent; background: transparent; font-family: var(--display); font-weight: 700; font-size: 16px; padding: 6px 8px; }
.app-title input:hover { border-color: var(--line); }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state.dirty { color: var(--warn); }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.banner { padding: 6px 14px; background: var(--band); color: var(--heading); font-size: 13px; line-height: 1.5; border-bottom: 1px solid var(--line); }
.banner > button, .banner > a { margin: 2px 0 2px 8px; vertical-align: middle; }
.banner.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--left, 50%) 6px 1fr; }
.workspace.layout-bottom { grid-template-columns: 1fr; grid-template-rows: var(--top, 50%) 6px 1fr; }
.workspace.layout-code { grid-template-columns: 1fr; }
.workspace.layout-code .right-col, .workspace.layout-code > .gutter { display: none; }
.workspace.layout-preview { grid-template-columns: 1fr; }
.workspace.layout-preview .editors, .workspace.layout-preview > .gutter { display: none; }

.editors { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.workspace.layout-bottom .editors { flex-direction: row; }
.pane { flex: 1 1 0; min-height: 60px; min-width: 0; display: flex; flex-direction: column; border-bottom: 1px solid var(--line); position: relative; }
.workspace.layout-bottom .pane { border-bottom: 0; border-right: 1px solid var(--line); }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; color: var(--heading); text-transform: uppercase; letter-spacing: .05em; min-height: 32px; }
.pane-head select { width: auto; padding: 2px 6px; font-size: 12px; text-transform: none; letter-spacing: 0; border-radius: 6px; background: var(--surface); }
.pane-head .spacer { flex: 1; }
.pane-btn { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 6px; padding: 1px 7px; font: 700 12px var(--mono); cursor: pointer; }
.pane-btn:hover, .pane-btn:focus-visible { color: var(--accent); border-color: var(--accent); }
.pane-head .err { color: var(--danger); text-transform: none; letter-spacing: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code { flex: 1; min-height: 0; font-size: 13px; }
.gutter { background: var(--line); cursor: col-resize; touch-action: none; }
.workspace.layout-bottom > .gutter { cursor: row-resize; }
.gutter:hover, .gutter.drag { background: var(--accent); }
.pane-gutter { height: 5px; background: var(--line); cursor: row-resize; flex: none; touch-action: none; }
.workspace.layout-bottom .pane-gutter { width: 5px; height: auto; cursor: col-resize; }
.pane-gutter:hover, .pane-gutter.drag { background: var(--accent); }

.right-col { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.preview-head { display: flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); min-height: 38px; flex-wrap: wrap; }
.preview-head .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--heading); }
.preview-head .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--surface); }
.seg button { border: 0; background: none; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--band); color: var(--accent); }
.toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.preview-wrap { flex: 1; min-height: 0; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--bg) 0 50%) 0 0 / 20px 20px; display: grid; place-items: center; overflow: auto; position: relative; }
.preview-wrap iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.preview-wrap.device iframe { box-shadow: var(--shadow); border-radius: 12px; }
.console { height: var(--console, 160px); min-height: 34px; display: flex; flex-direction: column; border-top: 1px solid var(--line); background: var(--surface); }
.console.collapsed { height: 34px !important; }
.console-head { display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); min-height: 33px; cursor: row-resize; touch-action: none; }
.console-head .label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--heading); }
.console-head .count { font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 99px; background: var(--danger); color: #fff; }
.console-head .spacer { flex: 1; }
.console-head button { cursor: pointer; }
.console-out { flex: 1; overflow: auto; font-family: var(--mono); font-size: 12px; padding: 4px 0; }
.log { padding: 3px 12px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); white-space: pre-wrap; word-break: break-word; display: flex; gap: 8px; }
.log .args { flex: 1; min-width: 0; }
.log.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); }
.log.error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); }
.log.info .lvl::before { content: "ℹ"; }
.log.result { color: var(--muted); }
.log.input { color: var(--accent); }
.log .where { color: var(--muted); font-size: 11px; flex: none; }
.log details { display: inline-block; vertical-align: top; }
.log summary { cursor: pointer; color: var(--heading); }
.log .kv { padding-left: 16px; }
.log .k { color: #A0569E; }
.log .s { color: #2E8B57; }
.log .args > .s { color: inherit; } /* texte simple, comme la console du navigateur */
.log .n { color: #2F6FD1; }
.log table { border-collapse: collapse; margin: 4px 0; }
.log td, .log th { border: 1px solid var(--line); padding: 2px 8px; text-align: left; }
.repl { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); padding: 0 10px; }
.repl span { color: var(--accent); font-family: var(--mono); font-weight: 700; }
.repl input { border: 0; background: transparent; font-family: var(--mono); font-size: 12px; padding: 7px 0; box-shadow: none !important; }

/* Onglets mobiles */
.mobile-tabs { display: none; }
@media (max-width: 820px) {
	.topbar .hide-sm { display: none; }
	.hbtn .lbl { display: none; }
	.workspace, .workspace.layout-bottom { grid-template-columns: 1fr; grid-template-rows: 1fr; }
	.workspace > .gutter, .pane-gutter { display: none; }
	.editors, .workspace.layout-bottom .editors { flex-direction: column; }
	.workspace .pane { display: none; border: 0; }
	.workspace[data-tab="html"] .pane[data-pane="html"], .workspace[data-tab="css"] .pane[data-pane="css"], .workspace[data-tab="js"] .pane[data-pane="js"] { display: flex; }
	.workspace[data-tab="preview"] .editors, .workspace:not([data-tab="preview"]) .right-col { display: none; }
	.workspace[data-tab="preview"] .right-col { display: flex; }
	.mobile-tabs { display: flex; border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom, 0px); }
	.mobile-tabs button { flex: 1; border: 0; background: none; padding: 10px 4px; font-weight: 700; font-size: 12px; color: var(--muted); }
	.mobile-tabs button[aria-pressed="true"] { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
}

/* ---------- Tiroir (historique) et boîtes de dialogue ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 40; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-family: var(--display); font-size: 17px; color: var(--heading); flex: 1; }
.drawer-body { flex: 1; overflow: auto; padding: 8px; }
.version { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; display: grid; gap: 6px; }
.version.current { border-color: var(--accent); }
.version-top { display: flex; gap: 8px; align-items: baseline; }
.version-top strong { color: var(--heading); }
.version-top .muted { font-size: 12px; margin-left: auto; white-space: nowrap; }
.version .msg { font-size: 13px; }
.badge { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 99px; background: var(--success); color: #fff; }
.badge.grey { background: var(--muted); }
.version .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.version .acts .hbtn { padding: 4px 10px; font-size: 12px; }
.diff { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: auto; max-height: 60vh; }
.diff div { padding: 0 10px; white-space: pre-wrap; word-break: break-word; }
.diff .add { background: color-mix(in srgb, var(--success) 16%, transparent); }
.diff .del { background: color-mix(in srgb, var(--danger) 14%, transparent); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.diff .ctx { color: var(--muted); }
.diff .file { background: var(--surface-2); font-weight: 700; color: var(--heading); padding: 4px 10px; }

dialog { border: 0; padding: 0; background: transparent; color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog.wide { width: min(860px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 20, 30, .45); }
.dlg { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; display: grid; gap: 14px; max-height: calc(100vh - 24px); overflow: auto; }
.dlg h2 { margin: 0; font-family: var(--display); font-size: 19px; color: var(--heading); }
.dlg p { margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.row { display: flex; gap: 6px; }
.row input { flex: 1; min-width: 0; }
.libs-list { display: grid; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.chips button:hover { background: var(--band); }
.radio-cards { display: grid; gap: 8px; }
.radio-cards label { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font-weight: 500; cursor: pointer; }
.radio-cards label:has(input:checked) { border-color: var(--accent); background: var(--band); }
.radio-cards strong { display: block; color: var(--heading); }
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.templates button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); padding: 14px 12px; text-align: left; display: grid; gap: 4px; }
.templates button:hover { border-color: var(--accent); background: var(--band); }
.templates strong { color: var(--heading); }
.key { font-family: var(--mono); font-size: 13px; word-break: break-all; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--line); }
.qr { width: 120px; height: 120px; background: #fff; padding: 6px; border-radius: 10px; }
.menu { position: fixed; z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 230px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 10px; border-radius: 8px; text-align: left; font-size: 13px; color: var(--heading); }
.menu button:hover, .menu button:focus-visible { background: var(--band); outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .danger { color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 160%); visibility: hidden; background: var(--heading); color: var(--bg); padding: 9px 16px; border-radius: 14px; font-weight: 600; z-index: 60; transition: transform .25s, visibility 0s .25s; max-width: calc(100% - 32px); }
.toast.on { transform: translate(-50%, 0); visibility: visible; transition: transform .25s; }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Page publique d'une app ---------- */
body.viewer-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.appbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.appbar-brand { font-family: var(--mono); font-weight: 800; color: var(--accent-ink); background: var(--accent); border-radius: 8px; padding: 4px 8px; text-decoration: none; font-size: 12px; }
.appbar-title { flex: 1 1 140px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--heading); }
.app-stage { flex: 1; position: relative; display: flex; min-height: 0; }
.app-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.sound-gate { position: absolute; inset: 0; border: 0; padding: 0; background: rgba(10, 16, 20, .35); cursor: pointer; display: grid; place-items: center; font: inherit; }
.sound-gate[hidden] { display: none; }
.sound-gate span { display: inline-flex; align-items: center; gap: 10px; padding: 14px 24px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
.sound-gate:hover span, .sound-gate:focus-visible span { filter: brightness(1.08); }
body.embed .app-frame { height: 100%; }

/* ---------- Galerie et administration ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 16px; }
.gcard { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-decoration: none; color: inherit; box-shadow: var(--shadow); transition: transform .15s; }
.gcard:hover { transform: translateY(-3px); }
.gcard img { width: 100%; aspect-ratio: 1200 / 630; object-fit: cover; border-radius: 10px; background: var(--band); }
.gcard strong { color: var(--heading); font-family: var(--display); }
.gcard p { margin: 0; color: var(--muted); font-size: 13px; }
table.admin { width: 100%; border-collapse: collapse; font-size: 13px; }
table.admin th, table.admin td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; vertical-align: top; }

/* ---------- Mes apps ---------- */
.mylist { display: grid; gap: 8px; max-height: min(60vh, 520px); overflow: auto; }
.myapp { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.myapp.current { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.myapp-info { display: grid; gap: 2px; min-width: 0; }
.myapp-info a { color: var(--heading); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.myapp-info a:hover { color: var(--accent); }
.myapp-info .muted { font-size: 12px; }
.myapp .row { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.mybadge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.mybadge.ok { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.mybadge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

/* ---------- Bannière (réglages) ---------- */
.banner-pick { display: grid; gap: 8px; }
.banner-pick img { width: 100%; max-width: 360px; aspect-ratio: 1200 / 630; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--band); }
