/* AECO.dev playground: Monaco on the left, the viewer on the right. */

@font-face {
	font-family: "Inter";
	font-weight: 400;
	font-display: swap;
	src: url("https://cdn.jsdelivr.net/npm/@fontsource/inter@5.2.8/files/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
	font-family: "Inter";
	font-weight: 500;
	font-display: swap;
	src: url("https://cdn.jsdelivr.net/npm/@fontsource/inter@5.2.8/files/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
	font-family: "Inter";
	font-weight: 600;
	font-display: swap;
	src: url("https://cdn.jsdelivr.net/npm/@fontsource/inter@5.2.8/files/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
	font-family: "Space Grotesk";
	font-weight: 600;
	font-display: swap;
	src: url("https://cdn.jsdelivr.net/npm/@fontsource/space-grotesk@5.2.8/files/space-grotesk-latin-600-normal.woff2") format("woff2");
}

:root {
	--bg: #0f1117;
	--panel: #151821;
	--panel-raised: #1b1f2a;
	--line: #262b38;
	--line-strong: #353b4b;
	--text: #e6e8ee;
	--muted: #9aa1b2;
	--dim: #6b7285;
	--brand: lab(44.4871% -41.0396 11.0361);
	--brand-hi: lab(58% -46 14);
	--brand-soft: color-mix(in srgb, var(--brand) 22%, transparent);
	--warn: #e7b553;
	--error: #f07178;
	--info: #82aaff;
	--radius: 7px;
	--bar-h: 52px;
	--left-w: 46%;
	--console-h: 34%;
	--font: "Inter", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
	--display: "Space Grotesk", "Inter", ui-sans-serif, system-ui, sans-serif;
	--mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
	color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.45 var(--font);
	overflow: hidden;
}

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

.pg {
	display: flex;
	height: 100%;
}

.pg-shell {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-width: 0;
}

/* Toolbar: full height on the left of the page. */

.pg-toolbar {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	flex: 0 0 48px;
	padding: 0 0 10px;
	border-right: 1px solid var(--line);
	background: var(--panel);
}
.pg-toolbar-logo {
	display: grid;
	place-items: center;
	width: 100%;
	height: var(--bar-h);
	margin-bottom: 6px;
	border-bottom: 1px solid var(--line);
}
.pg-toolbar-sep {
	width: 22px;
	height: 1px;
	margin: 4px 0;
	background: var(--line-strong);
}
.pg-tool { width: 34px; height: 34px; border-radius: 6px; }
.pg-tool svg { width: 17px; height: 17px; }
.pg-tool.is-active { background: var(--brand-soft); color: var(--brand-hi); }

/* Top bar */

.pg-bar {
	display: flex;
	align-items: center;
	gap: 14px;
	height: var(--bar-h);
	padding: 0 14px;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
	flex: 0 0 auto;
	min-width: 0;
}

.pg-brand {
	display: flex;
	align-items: center;
	gap: 9px;
	color: var(--text);
	text-decoration: none;
	font: 600 15px/1 var(--display);
	letter-spacing: 0.01em;
	margin-right: 6px;
}

.pg-model-chip {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: 32px;
	min-width: 0;
	max-width: 280px;
	padding: 0 12px;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: var(--panel-raised);
	color: var(--text);
	cursor: pointer;
}
.pg-model-chip:hover { border-color: var(--muted); }
.pg-model-chip svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--muted); }
.pg-model-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pg-model-chip:focus-visible,
.pg-btn:focus-visible,
.pg-icon:focus-visible {
	outline: 2px solid var(--brand-hi);
	outline-offset: 1px;
}

.pg-spacer { flex: 1 1 auto; }

.pg-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	height: 32px;
	padding: 0 12px;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: var(--panel-raised);
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.12s, border-color 0.12s;
}

.pg-btn svg { width: 14px; height: 14px; }
.pg-btn:hover:not(:disabled) { border-color: var(--muted); }
.pg-btn:disabled { opacity: 0.45; cursor: default; }

.pg-btn--primary {
	background: var(--brand);
	border-color: var(--brand);
	color: #fff;
	font-weight: 500;
}
.pg-btn--primary:hover:not(:disabled) { background: var(--brand-hi); border-color: var(--brand-hi); }

.pg-btn--sm { height: 24px; padding: 0 9px; gap: 5px; font-size: 12px; text-transform: none; letter-spacing: 0; }
.pg-btn--sm svg { width: 11px; height: 11px; }

.pg-btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.pg-btn--ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-strong); }

/* Workspace */

.pg-main {
	position: relative;
	display: flex;
	flex: 1 1 auto;
	min-height: 0;
}

.pg-left {
	display: flex;
	flex-direction: column;
	width: var(--left-w);
	min-width: 280px;
	background: var(--panel);
}

/* Editor tabs, one per open script. */

.pg-tabbar {
	display: flex;
	align-items: stretch;
	flex: 0 0 auto;
	height: 36px;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
}
.pg-tabbar .pg-btn { align-self: center; margin: 0 6px; }

.pg-tabs {
	display: flex;
	flex: 1 1 auto;
	min-width: 0;
	overflow-x: auto;
	scrollbar-width: none;
}

.pg-tab {
	position: relative;
	display: flex;
	align-items: center;
	gap: 6px;
	flex: 0 0 auto;
	padding: 0 6px 0 14px;
	border-right: 1px solid var(--line);
	color: var(--muted);
	font: 13px var(--mono);
	cursor: pointer;
	user-select: none;
}
.pg-tab:hover { color: var(--text); }
.pg-tab.is-active {
	background: var(--panel);
	color: var(--text);
	box-shadow: inset 0 2px 0 var(--brand-hi);
}
.pg-tab.is-active::after {
	content: "";
	position: absolute;
	left: 0;
	right: 0;
	bottom: -1px;
	height: 1px;
	background: var(--panel);
}
.pg-tab:focus-visible { outline: 2px solid var(--brand-hi); outline-offset: -2px; }
.pg-tab:not(:has(.pg-tab-close)) { padding-right: 14px; }

.pg-tab-close {
	display: grid;
	place-items: center;
	width: 20px;
	height: 20px;
	padding: 0;
	border: 0;
	border-radius: 4px;
	background: transparent;
	color: var(--muted);
	cursor: pointer;
	visibility: hidden;
}
.pg-tab-close svg { width: 11px; height: 11px; }
.pg-tab-close:hover { background: var(--panel-raised); color: var(--text); }
.pg-tab.is-active .pg-tab-close,
.pg-tab:hover .pg-tab-close { visibility: visible; }

/* Edited: a dot after the name until Revert. */
.pg-tab.is-edited .pg-tab-name::after { content: " •"; color: var(--warn); }

.pg-editor {
	position: relative;
	flex: 1 1 auto;
	min-height: 120px;
}

.pg-editor-loading {
	margin: 0;
	padding: 14px;
	color: var(--dim);
	font: 13px var(--mono);
}

.pg-console {
	display: flex;
	flex-direction: column;
	height: var(--console-h);
	min-height: 64px;
	background: var(--bg);
}

.pg-console-head {
	display: flex;
	align-items: center;
	gap: 10px;
	height: 32px;
	padding: 0 6px 0 14px;
	border-bottom: 1px solid var(--line);
	color: var(--muted);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	flex: 0 0 auto;
}

.pg-console-meta {
	flex: 1;
	color: var(--dim);
	text-transform: none;
	letter-spacing: 0;
	font-family: var(--mono);
}

.pg-icon {
	display: grid;
	place-items: center;
	width: 26px;
	height: 26px;
	border: 0;
	border-radius: 5px;
	background: transparent;
	color: var(--muted);
	cursor: pointer;
}
.pg-icon:hover { background: var(--panel-raised); color: var(--text); }
.pg-icon svg { width: 15px; height: 15px; }

.pg-console-body {
	flex: 1 1 auto;
	overflow: auto;
	padding: 8px 0;
	font: 12.5px/1.55 var(--mono);
}

.pg-line {
	display: flex;
	gap: 8px;
	padding: 1px 14px;
	white-space: pre-wrap;
	word-break: break-word;
}
.pg-line::before {
	content: "›";
	color: var(--dim);
	flex: 0 0 auto;
}
.pg-line--info { color: var(--info); }
.pg-line--warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 7%, transparent); }
.pg-line--error { color: var(--error); background: color-mix(in srgb, var(--error) 8%, transparent); }
.pg-line--sys { color: var(--dim); }
.pg-line--sys::before { content: "·"; }
.pg-line--ok { color: var(--brand-hi); }
.pg-line--ok::before { content: "✓"; }

.pg-table {
	margin: 4px 14px 6px;
	border-collapse: collapse;
	font: inherit;
}
.pg-table th,
.pg-table td {
	padding: 2px 12px 2px 0;
	text-align: left;
	border-bottom: 1px solid var(--line);
	white-space: nowrap;
}
.pg-table th { color: var(--muted); font-weight: 500; }
.pg-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Splitters */

.pg-vsplit {
	flex: 0 0 5px;
	cursor: col-resize;
	background: var(--line);
	border-left: 2px solid var(--panel);
	border-right: 2px solid var(--bg);
}
.pg-hsplit {
	flex: 0 0 5px;
	cursor: row-resize;
	background: var(--line);
	border-top: 2px solid var(--panel);
	border-bottom: 2px solid var(--bg);
}
.pg-vsplit:hover, .pg-hsplit:hover, .is-dragging { background: var(--brand); }
body.is-resizing { user-select: none; }
body.is-resizing .pg-viewport { pointer-events: none; }

/* Viewer */

.pg-right {
	position: relative;
	flex: 1 1 auto;
	min-width: 0;
	background: #1a1a1a;
}

.pg-viewport {
	position: absolute;
	inset: 0;
}

.pg-status {
	position: absolute;
	top: 12px;
	left: 12px;
	display: flex;
	align-items: center;
	gap: 9px;
	max-width: calc(100% - 24px);
	padding: 7px 12px;
	border: 1px solid var(--line-strong);
	border-radius: 999px;
	background: color-mix(in srgb, var(--panel) 88%, transparent);
	backdrop-filter: blur(6px);
	font-size: 12.5px;
	color: var(--muted);
	pointer-events: none;
	transition: opacity 0.3s;
}
.pg-status.is-idle { opacity: 0; }
.pg-status.is-error { color: var(--error); border-color: color-mix(in srgb, var(--error) 50%, transparent); }
.pg-status.is-error .pg-spinner { display: none; }

.pg-spinner {
	width: 12px;
	height: 12px;
	border: 2px solid var(--line-strong);
	border-top-color: var(--brand-hi);
	border-radius: 50%;
	animation: pg-spin 0.8s linear infinite;
	flex: 0 0 auto;
}
@keyframes pg-spin { to { transform: rotate(360deg); } }

.pg-pick {
	position: absolute;
	right: 12px;
	top: 12px;
	max-width: min(320px, calc(100% - 24px));
	padding: 9px 12px;
	border-radius: var(--radius);
	backdrop-filter: blur(6px);
	font-size: 12.5px;
	pointer-events: none;
}
.pg-pick strong { display: block; font-weight: 600; margin-bottom: 2px; }
.pg-pick code { color: var(--muted); font: 11.5px var(--mono); word-break: break-all; }

.pg-hint {
	position: absolute;
	right: 12px;
	bottom: 10px;
	margin: 0;
	color: var(--dim);
	font-size: 12px;
	pointer-events: none;
}

/* The script tree the toolbar opens, floating over the workspace. */

.pg-panel {
	position: absolute;
	top: 10px;
	left: 10px;
	bottom: 10px;
	z-index: 20;
	display: flex;
	flex-direction: column;
	width: min(300px, calc(100% - 20px));
	max-height: 560px;
	border: 1px solid var(--line-strong);
	border-radius: 9px;
	background: color-mix(in srgb, var(--panel) 96%, transparent);
	backdrop-filter: blur(8px);
	box-shadow: 0 12px 32px rgb(0 0 0 / 0.45);
}
.pg-panel[hidden] { display: none; }
.pg-panel--models { bottom: auto; max-height: 420px; }
.pg-panel--models .pg-tree { padding-top: 4px; }

.pg-panel-head {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 6px 4px 12px;
	color: var(--muted);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

.pg-scripts-filter {
	flex: 0 0 auto;
	margin: 4px 10px 8px;
	height: 30px;
	padding: 0 10px;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius);
	background: var(--bg);
	color: var(--text);
	font: inherit;
	font-size: 13px;
}
.pg-scripts-filter:focus-visible { outline: 2px solid var(--brand-hi); outline-offset: -1px; }

.pg-tree {
	flex: 1 1 auto;
	overflow: auto;
	padding: 0 6px 8px;
}

.pg-tree-group,
.pg-tree-item {
	display: flex;
	align-items: center;
	gap: 6px;
	width: 100%;
	border: 0;
	border-radius: 6px;
	background: transparent;
	text-align: left;
	cursor: pointer;
}
.pg-tree-group:focus-visible,
.pg-tree-item:focus-visible { outline: 2px solid var(--brand-hi); outline-offset: -2px; }

.pg-tree-group {
	padding: 6px 6px;
	color: var(--muted);
	font-size: 12px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}
.pg-tree-group:hover { color: var(--text); }
.pg-tree-group svg { width: 12px; height: 12px; flex: 0 0 auto; transition: transform 0.12s; }
.pg-tree-group[aria-expanded="true"] svg { transform: rotate(90deg); }
.pg-tree-count {
	margin-left: auto;
	color: var(--dim);
	font-weight: 500;
	font-variant-numeric: tabular-nums;
}

.pg-tree-items { padding: 0 0 6px 12px; }
.pg-tree-items[hidden] { display: none; }

.pg-tree-item {
	padding: 6px 10px;
	border-left: 2px solid var(--line);
	border-radius: 0 6px 6px 0;
	color: var(--text);
	font-size: 13px;
}
.pg-tree-item:hover { background: var(--panel-raised); }
.pg-tree-item > svg { width: 14px; height: 14px; flex: 0 0 auto; color: var(--muted); }
.pg-tree-action { margin-top: 6px; border-left-color: transparent; color: var(--muted); }
.pg-tree-action:hover { color: var(--text); }
.pg-tree-item.is-active {
	border-left-color: var(--brand-hi);
	background: var(--brand-soft);
	color: #fff;
}
.pg-tree-edited { margin-left: auto; color: var(--warn); }

.pg-tree-empty {
	margin: 8px 6px;
	color: var(--dim);
	font-size: 13px;
}

/* The viewer shows and places both by id. */
#marquee {
	position: absolute;
	display: none;
	z-index: 5;
	pointer-events: none;
	border: 1px solid var(--brand-hi);
	background: var(--brand-soft);
}

#origin-readout {
	position: fixed;
	z-index: 12;
	pointer-events: none;
	transform: translate(10px, -50%);
	font: 11px/1.2 var(--mono);
	color: #d7dbe3;
	background: rgba(15, 17, 23, .72);
	border-radius: 3px;
	padding: 2px 6px;
	white-space: pre;
}
#origin-readout.moved { color: #f6e05e; }
#origin-readout.docked { transform: none; }

/* Library name next to the logo. */
.pg-brand-lib {
	padding: 3px 7px;
	border: 1px solid var(--line-strong);
	border-radius: 999px;
	color: var(--muted);
	font: 500 11.5px/1 var(--font);
	letter-spacing: 0.02em;
	white-space: nowrap;
}
.pg-brand:hover .pg-brand-lib { color: var(--text); border-color: var(--muted); }

/* No viewport (ifcopenshell-js): the output fills the right-hand pane. */
.pg-right--output {
	display: flex;
	flex-direction: column;
	background: var(--bg);
}
.pg-right--output .pg-console {
	flex: 1 1 auto;
	height: auto;
}
.pg-right--output .pg-status {
	top: auto;
	bottom: 12px;
	left: auto;
	right: 12px;
}

/* Toolbar pane toggles. With a viewport the output sits under the editor. */
.is-editor-hidden .pg-tabbar,
.is-editor-hidden .pg-editor,
.is-editor-hidden .pg-hsplit,
.is-output-hidden .pg-hsplit,
.is-output-hidden .pg-console { display: none; }
.is-editor-hidden .pg-console { flex: 1 1 auto; height: auto; }
.is-editor-hidden.is-output-hidden .pg-left,
.is-editor-hidden.is-output-hidden .pg-vsplit { display: none; }

/* Without one, each owns a side of the workspace. */
.pg--no-viewport.is-editor-hidden .pg-left,
.pg--no-viewport.is-editor-hidden .pg-vsplit,
.pg--no-viewport.is-output-hidden .pg-right,
.pg--no-viewport.is-output-hidden .pg-vsplit { display: none; }
.pg--no-viewport.is-output-hidden .pg-left { flex: 1 1 auto; }

/* Narrow screens: stack the viewer above the editor. */
@media (max-width: 820px) {
	html, body { overflow: auto; }
	.pg { height: auto; min-height: 100%; }
	.pg-toolbar { position: sticky; top: 0; height: 100vh; flex-basis: 44px; }
	.pg-bar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
	.pg-spacer { display: none; }
	.pg-model-chip { max-width: 200px; }
	.pg-main { flex-direction: column-reverse; }
	.pg-left { width: 100% !important; min-width: 0; }
	.pg-editor { height: 55vh; flex: 0 0 auto; }
	.pg-console { height: 30vh !important; }
	.pg-right { height: 52vh; flex: 0 0 auto; }
	.pg--no-viewport .pg-main { flex-direction: column; }
	.pg-right--output { height: 40vh; }
	.pg-right--output .pg-console { height: auto !important; }
	.pg-vsplit, .pg-hsplit, .pg-hint { display: none; }
}
