/* Kalkeo — atelier sombre aux couleurs de la marque : encre, klein, pervenche.
   Klein = action. Vert d'eau = « réglé ici » et sélection dans la page :
   il se distingue du bleu d'action, et un filet d'encre le garde visible par-dessus un site clair. */

:root {
	/* Neutres tirés de l'encre (#0b1440), désaturés : le cadre ne doit pas teinter le site qu'on modifie. */
	--bg: #0a0d1c;
	--stage: #070914;
	--panel: #10142a;
	--raised: #191e3a;
	--raised-hover: #20264a;
	--field: #070916;
	--line: #272d52;
	--line-strong: #3a4275;
	--line-soft: #1c2140;
	--scrim: rgb(5 7 18 / 0.7);
	--text: #eef3ff;
	--muted: #a2abcf;
	--faint: #737ba3;
	/* Klein porte les boutons d'action (texte blanc : 6,3:1). Sur fond sombre il ne fait que 2,9:1 :
	   le texte, les icônes et les filets d'action prennent la pervenche (9:1). */
	--accent: #2643ff;
	--accent-hover: #3d57ff;
	--accent-ink: #9db6ff;
	--accent-soft: rgb(91 120 255 / 0.18);
	--set: #8df0b8;
	--set-soft: rgb(141 240 184 / 0.14);
	--set-ink: #0b1440;
	--danger: #ff7566;
	--ok: #7bd494;

	--font: 'Instrument Sans', system-ui, sans-serif;
	--mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
	--text-xs: 11px;
	--text-sm: 12px;
	--text-md: 13px;

	--space-1: 4px;
	--space-2: 8px;
	--space-3: 12px;
	--space-4: 16px;
	--radius: 6px;
	--topbar: 48px;
	--fast: 120ms;
}

* {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
	margin: 0;
}

body {
	display: flex;
	flex-direction: column;
	background: var(--bg);
	color: var(--text);
	font: 400 var(--text-md) / 1.4 var(--font);
	-webkit-font-smoothing: antialiased;
	overflow: hidden;
}

button,
input,
select,
textarea {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
}

button:disabled {
	cursor: default;
	opacity: 0.4;
}

:focus-visible {
	outline: 2px solid var(--accent-ink);
	outline-offset: 1px;
}

[hidden] {
	display: none !important;
}

.icon {
	fill: none;
	stroke: currentColor;
	stroke-width: 1.7;
	stroke-linecap: round;
	stroke-linejoin: round;
	flex: none;
}

/* ---- Champs ------------------------------------------------------------------ */

input[type='text'],
input[type='search'],
input[type='email'],
input[type='password'],
select,
textarea {
	width: 100%;
	min-width: 0;
	height: 28px;
	padding: 0 var(--space-2);
	background: var(--field);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	font-family: var(--mono);
	font-size: var(--text-sm);
	transition: border-color var(--fast);
}

textarea {
	height: auto;
	padding: var(--space-2);
	line-height: 1.5;
	resize: vertical;
}

textarea.code {
	white-space: pre;
	tab-size: 2;
}

input::placeholder,
textarea::placeholder {
	color: var(--faint);
}

input:hover,
select:hover,
textarea:hover {
	border-color: var(--line-strong);
}

input[type='checkbox'] {
	accent-color: var(--accent);
	width: 14px;
	height: 14px;
	margin: 0;
	flex: none;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	height: 30px;
	padding: 0 var(--space-3);
	background: var(--raised);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	font-weight: 500;
	white-space: nowrap;
	transition:
		background var(--fast),
		border-color var(--fast),
		transform var(--fast);
}

a.btn {
	color: var(--text);
	text-decoration: none;
}

.btn:hover:not(:disabled) {
	background: var(--raised-hover);
	border-color: var(--line-strong);
}

.btn:active:not(:disabled) {
	transform: translateY(1px);
}

.btn.is-small {
	height: 26px;
	padding: 0 var(--space-2);
	font-size: var(--text-sm);
}

.btn.is-primary {
	background: var(--accent);
	border-color: var(--accent);
	color: #fff;
	font-weight: 600;
}

.btn.is-primary:hover:not(:disabled) {
	background: var(--accent-hover);
	border-color: var(--accent-hover);
}

.btn.is-danger {
	color: var(--danger);
}

.btn.is-danger:hover:not(:disabled) {
	background: rgb(255 117 102 / 0.12);
	border-color: var(--danger);
}

.btn.is-on {
	background: var(--set-soft);
	border-color: var(--set);
	color: var(--set);
}

.icon-btn {
	display: grid;
	place-items: center;
	width: 30px;
	height: 30px;
	padding: 0;
	background: none;
	border: 0;
	border-radius: var(--radius);
	color: var(--muted);
	transition:
		background var(--fast),
		color var(--fast);
}

.icon-btn:hover:not(:disabled) {
	background: var(--raised);
	color: var(--text);
}

.icon-btn.is-danger:hover {
	color: var(--danger);
}

.badge {
	min-width: 18px;
	padding: 0 5px;
	border-radius: 9px;
	background: rgb(0 0 0 / 0.28);
	font: 600 var(--text-xs) / 18px var(--mono);
	text-align: center;
}

.row {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2);
}

.stack {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.hint {
	margin: 0;
	color: var(--faint);
	font-size: var(--text-xs);
	line-height: 1.45;
}

.empty {
	margin: var(--space-4) 0;
	color: var(--muted);
	line-height: 1.5;
}

/* ---- Barre du haut ------------------------------------------------------------ */

.topbar {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	height: var(--topbar);
	padding: 0 var(--space-3);
	background: var(--panel);
	border-bottom: 1px solid var(--line);
	flex: none;
}

.brand {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	color: var(--text);
	font-weight: 500;
	font-size: 17px;
	letter-spacing: -0.04em;
	text-decoration: none;
}

.page-button {
	display: flex;
	align-items: baseline;
	gap: var(--space-2);
	max-width: 340px;
	height: 30px;
	padding: 0 var(--space-3);
	background: var(--field);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	overflow: hidden;
}

.page-button strong {
	overflow: hidden;
	font-weight: 500;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.page-button span {
	color: var(--faint);
	font: var(--text-xs) var(--mono);
	white-space: nowrap;
}

.devices {
	display: flex;
	padding: 2px;
	background: var(--field);
	border: 1px solid var(--line);
	border-radius: var(--radius);
}

.device {
	display: grid;
	place-items: center;
	width: 34px;
	height: 24px;
	padding: 0;
	background: none;
	border: 0;
	border-radius: 4px;
	color: var(--muted);
}

.device:hover {
	color: var(--text);
}

.device.is-on {
	background: var(--raised);
	color: var(--set);
}

.zoom,
.status {
	color: var(--faint);
	font: var(--text-xs) var(--mono);
	white-space: nowrap;
}

.status.is-saving {
	color: var(--accent-ink);
}

.spacer {
	flex: 1;
}

.top-actions {
	display: flex;
	align-items: center;
	gap: var(--space-1);
}

.top-actions .btn {
	margin-left: var(--space-1);
}

/* ---- Espace de travail ---------------------------------------------------------- */

.workspace {
	display: grid;
	grid-template-columns: 48px 288px minmax(0, 1fr) 328px;
	flex: 1;
	min-height: 0;
}

.rail {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-1);
	padding: var(--space-2) 0;
	background: var(--panel);
	border-right: 1px solid var(--line-soft);
}

.rail-btn {
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	padding: 0;
	background: none;
	border: 0;
	border-radius: var(--radius);
	color: var(--faint);
	transition:
		background var(--fast),
		color var(--fast);
}

.rail-btn:hover {
	color: var(--text);
}

.rail-btn.is-on {
	background: var(--accent-soft);
	color: var(--accent-ink);
}

.panel {
	display: flex;
	flex-direction: column;
	min-height: 0;
	background: var(--panel);
}

.panel.is-left {
	border-right: 1px solid var(--line);
}

.panel.is-right {
	border-left: 1px solid var(--line);
}

.panel-page {
	display: flex;
	flex-direction: column;
	min-height: 0;
	flex: 1;
}

.panel-title {
	margin: 0;
	padding: var(--space-3) var(--space-3) var(--space-2);
	font-size: var(--text-xs);
	font-weight: 600;
	letter-spacing: 0.09em;
	text-transform: uppercase;
	color: var(--muted);
}

.panel-body {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
	flex: 1;
	min-height: 0;
	padding: var(--space-2) var(--space-3) var(--space-4);
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--line) transparent;
}

.panel-tools {
	display: flex;
	gap: var(--space-2);
}

.tabs {
	display: flex;
	padding: 0 var(--space-3);
	border-bottom: 1px solid var(--line-soft);
	flex: none;
}

.tab {
	position: relative;
	height: 40px;
	padding: 0 var(--space-3);
	background: none;
	border: 0;
	color: var(--faint);
	font-weight: 500;
}

.tab:hover {
	color: var(--text);
}

.tab.is-on {
	color: var(--text);
}

.tab.is-on::after {
	content: '';
	position: absolute;
	inset: auto var(--space-3) -1px;
	height: 2px;
	background: var(--accent-ink);
}

/* ---- Scène -------------------------------------------------------------------- */

.stage {
	display: flex;
	flex-direction: column;
	min-width: 0;
	min-height: 0;
	background-color: var(--stage);
	background-image: radial-gradient(rgb(255 255 255 / 0.045) 1px, transparent 1px);
	background-size: 16px 16px;
}

.canvas-wrap {
	position: relative;
	flex: 1;
	min-height: 0;
	overflow: hidden;
}

#canvas {
	position: absolute;
	top: 0;
	border: 0;
	background: #fff;
	transform-origin: 0 0;
	box-shadow:
		0 0 0 1px var(--line),
		0 24px 60px rgb(0 0 0 / 0.5);
}

.overlay {
	position: absolute;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
}

.box {
	position: absolute;
	outline: 1px solid var(--set);
	outline-offset: -1px;
	/* Le vert d'eau seul disparaîtrait sur une page blanche : un filet d'encre le double. */
	box-shadow: 0 0 0 1px rgb(11 20 64 / 0.55);
}

.box.is-hover {
	outline-style: dashed;
}

.box.is-select {
	outline-width: 2px;
	outline-offset: -2px;
}

.box-label,
.box-tools {
	position: absolute;
	bottom: 100%;
	display: flex;
	align-items: center;
	height: 20px;
	background: var(--set);
	color: var(--set-ink);
	font: 600 var(--text-xs) / 1 var(--mono);
	white-space: nowrap;
}

.box-label {
	left: 0;
	padding: 0 6px;
	border-radius: 4px 4px 0 0;
}

.box.is-hover .box-label {
	background: rgb(141 240 184 / 0.85);
}

.box-tools {
	right: 0;
	border-radius: 4px 4px 0 0;
	pointer-events: auto;
	overflow: hidden;
}

/* Élément collé en haut de l'écran : l'étiquette passe à l'intérieur. */
.box.is-low .box-label,
.box.is-low .box-tools {
	top: 0;
	bottom: auto;
	border-radius: 0 0 4px 4px;
}

.box-tool {
	display: grid;
	place-items: center;
	width: 22px;
	height: 20px;
	padding: 0;
	background: none;
	border: 0;
	color: inherit;
}

.box-tool:hover {
	background: rgb(255 255 255 / 0.35);
}

.box-tool.is-danger:hover {
	background: var(--danger);
}

.crumbs {
	display: flex;
	align-items: center;
	gap: 2px;
	height: 30px;
	padding: 0 var(--space-3);
	background: var(--panel);
	border-top: 1px solid var(--line);
	overflow-x: auto;
	scrollbar-width: none;
	flex: none;
}

.crumb {
	padding: 2px 6px;
	background: none;
	border: 0;
	border-radius: 4px;
	color: var(--faint);
	font: var(--text-xs) var(--mono);
	white-space: nowrap;
}

.crumb + .crumb::before {
	content: '›';
	margin-right: 8px;
	color: var(--line);
}

.crumb:hover,
.crumb.is-last {
	color: var(--text);
}

.crumb-empty {
	color: var(--faint);
	font-size: var(--text-xs);
}

/* ---- Dialogues et messages --------------------------------------------------------- */

.modal {
	width: min(440px, calc(100vw - 32px));
	max-height: calc(100vh - 64px);
	padding: 0;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 10px;
	color: var(--text);
	box-shadow: 0 30px 80px rgb(0 0 0 / 0.6);
}

.modal[open] {
	display: flex;
	flex-direction: column;
}

.modal.is-wide {
	width: min(820px, calc(100vw - 32px));
}

.modal::backdrop {
	background: var(--scrim);
}

.modal-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
	border-bottom: 1px solid var(--line-soft);
}

.modal-head h2 {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
}

.modal-body {
	padding: var(--space-4);
	overflow-y: auto;
}

.modal-body p {
	margin: 0;
	line-height: 1.5;
}

.modal-foot {
	display: flex;
	justify-content: flex-end;
	gap: var(--space-2);
	padding: var(--space-3) var(--space-4);
	border-top: 1px solid var(--line-soft);
}

.changes {
	display: flex;
	flex-direction: column;
	gap: 2px;
	max-height: 220px;
	margin: 0;
	padding: var(--space-2);
	background: var(--field);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	list-style: none;
	overflow-y: auto;
	font-size: var(--text-sm);
}

.changes li {
	display: flex;
	gap: var(--space-2);
}

.change-kind {
	width: 64px;
	color: var(--accent-ink);
	flex: none;
}

.log {
	max-height: 160px;
	margin: 0;
	padding: var(--space-2);
	background: var(--field);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	font: var(--text-xs) / 1.5 var(--mono);
	white-space: pre-wrap;
	overflow-y: auto;
}

.toasts {
	position: fixed;
	bottom: 44px;
	left: 50%;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--space-2);
	transform: translateX(-50%);
	z-index: 10;
	pointer-events: none;
}

.toast {
	padding: var(--space-2) var(--space-3);
	background: var(--raised);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: 0 12px 30px rgb(0 0 0 / 0.5);
	animation: toast-in 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.is-error {
	border-color: var(--danger);
	color: var(--danger);
}

@keyframes toast-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
}

/* En aperçu, les panneaux d'édition s'effacent derrière la page. */
body.is-preview .panel.is-right,
body.is-preview .panel-body {
	opacity: 0.45;
}

@media (prefers-reduced-motion: reduce) {
	* {
		transition: none !important;
		animation: none !important;
	}
}
