
:root {
	color-scheme: light;
	--bg: #f6f7f3;
	--panel: #ffffff;
	--text: #20231f;
	--muted: #6f766d;
	--line: #d9dfd4;
	--accent: #0f766e;
	--accent-dark: #0b5d57;
	--draft: #2563eb;
	--draft-bg: #dbeafe;
	--danger: #b42318;
	--danger-bg: #fee2e2;
	--warn: #9a6700;
}
* { box-sizing: border-box; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; }
button {
	border: 1px solid var(--line);
	background: var(--panel);
	color: var(--text);
	min-height: 36px;
	border-radius: 6px;
	padding: 0 12px;
	cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: white; }
button.primary:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: default; }
.login {
	min-height: 100vh;
	display: grid;
	place-items: center;
	padding: 24px;
}
.login-inner {
	width: min(420px, 100%);
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 8px;
	padding: 28px;
}
.login h1 { margin: 0 0 8px; font-size: 28px; }
.login p { margin: 0 0 24px; color: var(--muted); }
.loading {
	min-height: 100vh;
	display: grid;
	place-items: center;
	color: var(--muted);
}
.shell { min-height: 100vh; display: grid; grid-template-rows: 56px 1fr; }
.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 0 18px;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
}
.brand { font-weight: 700; }
.userbar { display: flex; align-items: center; gap: 10px; color: var(--muted); min-width: 0; }
.userbar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }
.sidebar {
	border-right: 1px solid var(--line);
	background: #fbfcf8;
	padding: 12px;
	overflow: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.sidebar h2 { margin: 0; font-size: 15px; }
.tree { display: grid; gap: 1px; }
.tree-row {
	width: 100%;
	display: grid;
	grid-template-columns: 14px 18px minmax(0, 1fr) 8px;
	align-items: center;
	gap: 5px;
	text-align: left;
	border: 0;
	background: transparent;
	padding: 5px 6px;
	min-height: 28px;
	color: var(--text);
	font-size: 13px;
	overflow: hidden;
}
.tree-row.file,
.tree-row.dir { padding-left: calc(6px + var(--depth) * 20px); }
.tree-row.dir { color: var(--muted); font-weight: 650; }
.tree-row.active { background: #dbeee9; color: #0a4b47; }
.tree-row.draft { color: var(--draft); font-weight: 650; }
.tree-row.draft.active { background: var(--draft-bg); color: #1d4ed8; }
.tree-row.conflict { color: var(--danger); font-weight: 700; }
.tree-row.conflict.active { background: var(--danger-bg); color: #991b1b; }
.tree-row .label {
	display: block;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.tree-row .disclosure {
	width: 0;
	height: 0;
	border-top: 4px solid transparent;
	border-bottom: 4px solid transparent;
	border-left: 5px solid var(--muted);
}
.tree-row.expanded .disclosure {
	transform: rotate(90deg);
}
.tree-row.file .disclosure {
	border: 0;
}
.tree-row .kind {
	position: relative;
	width: 16px;
	height: 13px;
}
.tree-row.dir .kind {
	border-radius: 3px;
	background: #5aa7f2;
}
.tree-row.dir .kind::before {
	content: "";
	position: absolute;
	top: -3px;
	left: 1px;
	width: 8px;
	height: 4px;
	border-radius: 3px 3px 0 0;
	background: #5aa7f2;
}
.tree-row.file .kind {
	width: 12px;
	height: 15px;
	border: 1px solid #6b7280;
	border-radius: 2px;
	background: #fff;
}
.tree-row.file .kind::before {
	content: "";
	position: absolute;
	top: -1px;
	right: -1px;
	width: 5px;
	height: 5px;
	background: linear-gradient(135deg, transparent 50%, #d1d5db 50%);
	border-left: 1px solid #6b7280;
	border-bottom: 1px solid #6b7280;
}
.tree-row .state-dot {
	width: 7px;
	height: 7px;
	border-radius: 999px;
}
.tree-row.draft .state-dot { background: var(--draft); }
.tree-row.conflict .state-dot { background: var(--danger); }
.editor-area { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto 1fr auto; }
.filebar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 12px 16px;
	border-bottom: 1px solid var(--line);
	background: var(--panel);
}
.pathbar { display: flex; align-items: center; gap: 8px; min-width: 0; }
.path { font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { display: flex; align-items: center; gap: 8px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; min-height: 34px; }
.segmented button.active { background: #20312f; color: white; }
.workspace { min-height: 0; display: grid; }
textarea.editor {
	width: 100%;
	height: 100%;
	min-height: 0;
	resize: none;
	border: 0;
	outline: 0;
	padding: 18px;
	background: #fff;
	color: var(--text);
	font: 15px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
.editor-host {
	display: none;
	height: 100%;
	min-height: 0;
	overflow: auto;
	background: #fff;
	padding: 28px 20px 48px;
}
.editor-host.ready { display: block; }
.editor.hidden { display: none; }
.codex-editor {
	max-width: 880px;
	margin: 0 auto;
	font-size: 16px;
	line-height: 1.65;
}
.codex-editor__redactor { padding-bottom: 120px !important; }
.ce-block__content,
.ce-toolbar__content {
	max-width: 820px;
}
.ce-header { padding: 0.25em 0; line-height: 1.2; }
.ce-paragraph { line-height: 1.7; }
.cdx-block { padding: 0.35em 0; }
.cdx-list { padding-left: 28px; }
.cdx-quote { border-left: 3px solid var(--accent); padding-left: 14px; }
.cdx-marker { background: #fff3a3; padding: 0 2px; }
.editor-host img {
	max-width: min(100%, 680px);
	height: auto;
	display: block;
	margin: 12px 0;
}
.image-grid-tool {
	display: grid;
	gap: 12px;
}
.image-grid-tool__actions {
	display: flex;
	align-items: center;
	gap: 8px;
}
.image-grid-tool__button {
	border: 1px solid var(--line);
	background: #f8faf6;
	border-radius: 6px;
	min-height: 38px;
	padding: 0 12px;
	font-weight: 650;
}
.image-grid-tool__status {
	color: var(--muted);
	font-size: 13px;
}
.image-grid-tool__status.error { color: var(--danger); }
.image-grid-tool__grid {
	display: grid;
	grid-template-columns: repeat(12, minmax(0, 1fr));
	gap: 10px;
	align-items: start;
}
.image-grid-tool__item {
	position: relative;
	grid-column: span 4;
	border: 1px solid var(--line);
	border-radius: 6px;
	overflow: hidden;
	background: #fbfcf8;
}
.image-grid-tool__item img {
	width: 100%;
	max-width: none;
	aspect-ratio: 4 / 3;
	object-fit: cover;
	margin: 0;
}
.image-grid-tool__caption {
	min-height: 32px;
	padding: 7px 9px;
	outline: 0;
	background: white;
	color: var(--muted);
	font-size: 13px;
}
.image-grid-tool__controls {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 7px 9px;
	border-top: 1px solid var(--line);
	background: #fff;
}
.image-grid-tool__controls select {
	min-height: 30px;
	border: 1px solid var(--line);
	border-radius: 6px;
	background: #fff;
	color: var(--text);
	font-size: 13px;
}
.image-grid-tool__remove {
	position: absolute;
	top: 6px;
	right: 6px;
	min-height: 28px;
	width: 28px;
	padding: 0;
	border-color: rgb(255 255 255 / .7);
	background: rgb(255 255 255 / .88);
}
.editor-host code {
	background: #eef2ea;
	padding: 2px 4px;
	border-radius: 4px;
}
.preview {
	height: 100%;
	overflow: auto;
	padding: 22px;
	background: #fff;
	line-height: 1.65;
}
.preview h1, .preview h2, .preview h3, .preview h4 { line-height: 1.2; }
.preview code { background: #eef2ea; padding: 2px 4px; border-radius: 4px; }
.preview .image-grid-preview {
	display: grid;
	grid-template-columns: repeat(12, minmax(0, 1fr));
	gap: 10px;
	margin: 16px 0;
}
.preview .image-grid-preview figure {
	grid-column: span 4;
	margin: 0;
}
.preview .image-grid-preview img {
	width: 100%;
	aspect-ratio: 4 / 3;
	object-fit: cover;
	border-radius: 6px;
}
@media (max-width: 760px) {
	.image-grid-tool__item,
	.preview .image-grid-preview figure {
		grid-column: 1 / -1 !important;
	}
}
.statusbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 40px;
	padding: 0 16px;
	border-top: 1px solid var(--line);
	background: #fbfcf8;
	color: var(--muted);
}
.statusbar .error { color: var(--danger); }
.statusbar .warn { color: var(--warn); }
.empty {
	display: grid;
	place-items: center;
	color: var(--muted);
	background: #fff;
}
.modal-backdrop {
	position: fixed;
	inset: 0;
	z-index: 1000;
	background: rgb(0 0 0 / .28);
	display: grid;
	place-items: center;
	padding: 16px;
}
.modal {
	position: relative;
	z-index: 1001;
	width: min(520px, 100%);
	background: white;
	border-radius: 8px;
	border: 1px solid var(--line);
	padding: 18px;
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal label {
	display: grid;
	gap: 6px;
	margin-top: 10px;
	color: var(--muted);
	font-size: 13px;
	font-weight: 650;
}
.modal label[hidden] { display: none; }
.modal input,
.modal select {
	width: 100%;
	border: 1px solid var(--line);
	border-radius: 6px;
	min-height: 38px;
	padding: 0 10px;
	background: white;
	color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
@media (max-width: 760px) {
	.main { grid-template-columns: 1fr; grid-template-rows: 220px 1fr; }
	.sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
	.topbar { padding: 0 12px; }
	.userbar span { max-width: 160px; }
}
