/* Global styles */
* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	display: flex;
	height: 100vh;
	overflow: hidden;
	background: transparent; /* Use the mesh on body from theme.css */
}

#sidebar {
	width: 260px;
	min-width: 260px;
	background: var(--sidebar-bg);
	backdrop-filter: var(--backdrop-blur-md);
	-webkit-backdrop-filter: var(--backdrop-blur-md);
	color: var(--sidebar-color);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border-right: 1px solid var(--sidebar-border);
	transition:
		width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
		min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.is-resizing {
	transition: none !important;
}

body.sidebar-collapsed #sidebar {
	width: 0 !important;
	min-width: 0 !important;
}

/* Backdrop behind the mobile overlay drawer; hidden on desktop, shown by the
   mobile media query when the drawer is open. */
#sidebar-backdrop {
	display: none;
}

#sidebar-header {
	padding: 16px;
	background: var(--sidebar-header-bg);
	border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-header-top {
	display: flex;
	align-items: center;
	margin-bottom: 14px;
}

#sidebar-header h1 {
	font-size: 15px;
	font-weight: 700;
	color: var(--text);
	letter-spacing: -0.02em;
	min-width: 0;
}

.app-title {
	line-height: 1;
	display: inline-flex;
	align-items: baseline;
	gap: 6px;
	font-family:
		'SFMono-Regular', 'JetBrains Mono', 'Fira Code', 'Menlo', monospace;
	font-size: 22px;
	font-weight: 700;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	justify-content: center;
	flex-wrap: wrap;
}

.app-title-main {
	color: var(--text);
	text-shadow: 0 0 18px rgba(148, 163, 184, 0.12);
}

.app-title-accent {
	color: var(--sidebar-accent);
	text-shadow: 0 0 22px var(--accent-selected-ring);
	position: relative;
}

.app-title-accent::before {
	content: '</>';
	position: absolute;
	top: -8px;
	right: -28px;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: 0.08em;
	color: color-mix(in srgb, var(--sidebar-accent) 42%, white);
	opacity: 0.9;
}

.app-logo {
	width: 28px;
	height: 28px;
	border-radius: 10px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(
		145deg,
		color-mix(in srgb, var(--sidebar-accent) 26%, transparent),
		color-mix(in srgb, var(--sidebar-accent) 10%, transparent)
	);
	border: 1px solid color-mix(in srgb, var(--sidebar-accent) 28%, white);
	box-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.16),
		0 8px 18px rgba(15, 23, 42, 0.28);
	position: relative;
	overflow: hidden;
}

.app-logo::after {
	content: '';
	position: absolute;
	inset: 1px;
	border-radius: 9px;
	background: radial-gradient(
		circle at top left,
		rgba(255, 255, 255, 0.18),
		transparent 45%
	);
	pointer-events: none;
}

.app-logo-core {
	position: relative;
	z-index: 1;
	width: 18px;
	height: 18px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.app-logo-bracket {
	position: absolute;
	top: 50%;
	transform: translateY(-54%);
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	color: color-mix(in srgb, var(--sidebar-accent) 30%, white);
}

.app-logo-bracket-left {
	left: 0;
}

.app-logo-bracket-right {
	right: 0;
}

.app-logo-node {
	width: 6px;
	height: 6px;
	border-radius: 999px;
	background: linear-gradient(
		180deg,
		color-mix(in srgb, var(--sidebar-accent) 46%, white),
		var(--sidebar-accent)
	);
	box-shadow:
		0 0 0 3px color-mix(in srgb, var(--sidebar-accent) 16%, transparent),
		0 0 16px color-mix(in srgb, var(--sidebar-accent) 42%, transparent);
}

#sidebar-actions {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

#btn-add {
	width: 100%;
	padding: 11px 14px;
	background: linear-gradient(
		135deg,
		color-mix(in srgb, var(--sidebar-accent) 22%, transparent),
		color-mix(in srgb, var(--sidebar-accent) 8%, transparent)
	);
	color: var(--text);
	border: 1px solid color-mix(in srgb, var(--sidebar-accent) 35%, transparent);
	border-radius: 12px;
	cursor: pointer;
	font-size: 13px;
	font-weight: 600;
	transition:
		background 0.15s,
		transform 0.15s,
		border-color 0.15s,
		box-shadow 0.15s;
	text-align: left;
	display: flex;
	flex-direction: column;
	gap: 4px;
	box-shadow: 0 10px 24px color-mix(in srgb, var(--sidebar-accent) 14%, transparent);
}

#btn-add:hover {
	background: linear-gradient(
		135deg,
		color-mix(in srgb, var(--sidebar-accent) 30%, transparent),
		color-mix(in srgb, var(--sidebar-accent) 12%, transparent)
	);
	border-color: color-mix(in srgb, var(--sidebar-accent) 55%, white);
	transform: translateY(-1px);
}

.sidebar-action-title {
	font-size: 16px;
	line-height: 1.1;
	color: var(--sidebar-accent);
}

.sidebar-action-subtitle {
	font-size: 11px;
	line-height: 1.4;
	color: var(--text-secondary);
}

#sidebar-utility-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 7px;
}

.sidebar-utility-btn {
	min-height: 58px;
	padding: 10px 8px;
	background: var(--sidebar-btn-bg);
	color: var(--text);
	border: 1px solid var(--sidebar-btn-border);
	border-radius: 12px;
	cursor: pointer;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	transition:
		background 0.15s,
		border-color 0.15s,
		transform 0.15s;
	text-decoration: none;
	font: inherit;
}

.sidebar-utility-btn:hover {
	background: var(--sidebar-btn-hover);
	border-color: var(--sidebar-btn-border-strong);
	transform: translateY(-1px);
}

.sidebar-utility-btn span {
	font-size: 11px;
	font-weight: 500;
	line-height: 1.2;
}

.sidebar-utility-btn svg {
	width: 16px;
	height: 16px;
	stroke: currentColor;
}

.sidebar-utility-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

#btn-export.active {
	background: rgba(34, 197, 94, 0.12);
	border-color: rgba(74, 222, 128, 0.4);
	color: #4ade80;
}

#selection-toolbar {
	padding: 10px 16px 12px;
	border-bottom: 1px solid var(--sidebar-border);
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: rgba(59, 130, 246, 0.08);
}

#selection-toolbar[hidden] {
	display: none !important;
}

#selection-toolbar-actions {
	display: flex;
	gap: 8px;
}

#selection-toolbar-copy {
	font-size: 12px;
	font-weight: 600;
	color: var(--text);
}

.selection-toolbar-btn {
	flex: 1;
	padding: 8px 10px;
	border-radius: 10px;
	border: 1px solid rgba(74, 222, 128, 0.28);
	background: rgba(34, 197, 94, 0.14);
	color: var(--text);
	cursor: pointer;
	font: inherit;
	font-size: 12px;
	font-weight: 600;
}

.selection-toolbar-btn.secondary {
	border-color: var(--sidebar-btn-border);
	background: var(--sidebar-btn-bg);
}

.selection-toolbar-btn:disabled {
	opacity: 0.55;
	cursor: not-allowed;
}

#sidebar-footer {
	padding: 14px 16px 18px;
	border-top: 1px solid var(--sidebar-border);
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px 6px;
}

#btn-coffee {
	flex: 0 0 100%;
}

.sidebar-footer-btn {
	flex: 1;
	padding: 10px 8px;
	background: var(--sidebar-btn-bg);
	color: var(--text-secondary);
	border: 1px solid var(--sidebar-btn-border);
	border-radius: 999px;
	display: flex;
	align-items: center;
	gap: 6px;
	justify-content: center;
	text-decoration: none;
	transition:
		background 0.15s,
		border-color 0.15s,
		color 0.15s;
	overflow: hidden;
}

.sidebar-footer-btn:hover {
	background: var(--sidebar-btn-hover);
	border-color: var(--sidebar-btn-border-strong);
	color: var(--text);
}

.sidebar-footer-btn span {
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

#spec-list {
	flex: 1;
	overflow-y: auto;
	padding: 8px;
}

.spec-item {
	display: flex;
	align-items: center;
	padding: 6px 10px;
	border-radius: 8px;
	cursor: pointer;
	margin-bottom: 4px;
	min-height: 36px;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	gap: 6px;
	border: 1px solid transparent;
	position: relative;
	overflow: hidden;
}
.spec-item::before {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent);
	opacity: 0;
	transition: opacity 0.2s;
	pointer-events: none;
}
.spec-item:hover,
.spec-item:focus-visible {
	background: var(--sidebar-item-hover);
	border-color: rgba(255, 255, 255, 0.05);
	outline: none;
}
.spec-item:hover::before {
	opacity: 1;
}
.spec-item.selection-mode:hover::before {
	opacity: 0;
}
.spec-item:focus-visible {
	outline: 2px solid var(--sidebar-accent);
	outline-offset: -2px;
}
.spec-item.active {
	background: var(--sidebar-item-active);
	border-color: rgba(255, 255, 255, 0.1);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.spec-item.selected {
	background: rgba(34, 197, 94, 0.09);
	outline: 1px solid rgba(74, 222, 128, 0.3);
}

.spec-item.selection-mode {
	display: flex;
	align-items: center;
	gap: 6px;
	cursor: default;
	min-height: 36px; 
	margin-bottom: 6px;
}

/* Disable hover background & shimmer in selection mode */
.spec-item.selection-mode:hover,
.spec-item.selection-mode:focus-visible {
	background: transparent;
	border-color: transparent;
}
.spec-item.selection-mode.selected:hover {
	background: rgba(34, 197, 94, 0.09);
}

/* Hide action buttons entirely in selection mode */
.spec-item.selection-mode .spec-item-actions {
	display: none !important;
}

.spec-item-name {
	flex: 1;
	font-size: 13px;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: var(--text);
	letter-spacing: 0.01em;
}

.spec-item-actions {
	display: flex;
	gap: 6px;
	opacity: 0;
	transform: translateX(4px);
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	flex-shrink: 0;
}
.spec-item:not(.selection-mode):hover .spec-item-actions,
.spec-item:not(.selection-mode).active .spec-item-actions {
	opacity: 1;
	transform: translateX(0);
}

.icon-btn {
	background: none;
	border: none;
	color: var(--icon-btn);
	cursor: pointer;
	padding: 4px;
	border-radius: 6px;
	font-size: 13px;
	line-height: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.icon-btn svg {
	width: 14px;
	height: 14px;
}
.icon-btn:hover {
	color: var(--text);
	transform: translateY(-1px);
}
.icon-btn.delete:hover {
	color: #ef4444;
}

.spec-item-badges {
	display: flex;
	gap: 4px;
}

.badge {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 14px;
	height: 14px;
	border-radius: 4px;
	font-size: 9px;
	font-weight: 800;
	color: #fff;
	user-select: none;
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.badge.left {
	background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.badge.right {
	background: linear-gradient(135deg, #ef4444, #dc2626);
}

.spec-item-selector {
	display: inline-flex;
	align-items: center;
	flex-shrink: 0;
	cursor: pointer;
}

.spec-item-selector input[type='checkbox'] {
	width: 14px;
	height: 14px;
	margin: 0;
	accent-color: #4ade80;
	cursor: pointer;
}

#empty-state {
	padding: 32px 16px;
	text-align: center;
	color: var(--text-muted);
	font-size: 13px;
	line-height: 1.6;
}

/* ─── Directory Tree ──────────────────────────────────────────────────────── */

/* Toolbar above the spec list: "SPECS" label + New Folder button */
#tree-toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 12px 8px;
	user-select: none;
	position: sticky;
	top: 0;
	z-index: 10;
	background: var(--sidebar-bg);
	backdrop-filter: var(--backdrop-blur-md);
	-webkit-backdrop-filter: var(--backdrop-blur-md);
}

.tree-toolbar-label {
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.08em;
	color: var(--text-muted);
	text-transform: uppercase;
}

.tree-toolbar-btns {
	display: flex;
	gap: 4px;
}

/* New Folder button */
.tree-toolbar-btn {
	padding: 4px;
	color: var(--text-muted);
	border-radius: 6px;
	opacity: 0.7;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree-toolbar-btn:hover {
	opacity: 1;
	color: var(--text);
	background: var(--sidebar-btn-hover);
	transform: translateY(-1px);
}

/* ── Spec item additions ─────────────────────────────────────────────────── */

/* File icon (YAML) */
.tree-file-icon {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	color: var(--sidebar-accent);
	margin-right: 2px;
	opacity: 0.8;
	transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree-file-icon svg,
.tree-folder-icon svg {
	width: 15px;
	height: 15px;
	stroke-width: 2;
}

/* Breadcrumb prefix shown when in search mode */
.tree-folder-breadcrumb {
	color: var(--text-muted);
	font-size: 11px;
	margin-right: 2px;
	font-weight: 400;
}

/* ── Folder row ──────────────────────────────────────────────────────────── */

.tree-folder {
	margin-bottom: 2px;
}

.tree-folder-row {
	display: flex;
	align-items: center;
	padding: 6px 10px;
	border-radius: 8px;
	cursor: pointer;
	gap: 6px;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	border: 1px solid transparent;
	position: relative;
	overflow: hidden;
}

.tree-folder-row::before {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent);
	opacity: 0;
	transition: opacity 0.2s;
	pointer-events: none;
}

.tree-folder-row:hover {
	background: var(--sidebar-item-hover);
	border-color: rgba(255, 255, 255, 0.05);
}

.tree-folder-row:hover::before {
	opacity: 1;
}

/* Chevron arrow – rotates 90° when folder is expanded */
.tree-chevron {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 18px;
	height: 18px;
	border-radius: 4px;
	color: var(--text-muted);
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree-chevron svg {
	width: 12px;
	height: 12px;
	stroke-width: 2.5;
}

.tree-folder-row:hover .tree-chevron {
	color: var(--text);
	background: rgba(255, 255, 255, 0.1);
}

body[data-theme='light'] .tree-folder-row:hover .tree-chevron {
	background: rgba(0, 0, 0, 0.05);
}

.tree-chevron.expanded {
	transform: rotate(90deg); /* Pointing down = expanded */
}

/* Folder icon */
.tree-folder-icon {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	color: #eab308;
	filter: drop-shadow(0 2px 4px rgba(234, 179, 8, 0.2));
	transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.tree-folder.expanded > .tree-folder-row .tree-folder-icon {
	transform: scale(1.05);
}

.tree-folder-row .tree-item-name {
	flex: 1;
	font-size: 13px;
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: var(--text);
	letter-spacing: 0.01em;
}

/* Folder action buttons – revealed on hover */
.tree-folder-actions {
	display: flex;
	gap: 6px;
	opacity: 0;
	transform: translateX(4px);
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	flex-shrink: 0;
}

.tree-folder-row:hover .tree-folder-actions {
	opacity: 1;
	transform: translateX(0);
}

/* ── Folder children ─────────────────────────────────────────────────────── */

.tree-folder-children {
	/* Indent children and draw a subtle guide line from the folder */
	padding-left: 10px;
	margin-left: 14px;
	margin-top: 2px;
	border-left: 1px solid;
	border-image: linear-gradient(to bottom, var(--sidebar-border), transparent)
		1;
	animation: slideDown 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
	transform-origin: top;
}

@keyframes slideDown {
	from {
		opacity: 0;
		transform: translateY(-4px) scaleY(0.98);
	}
	to {
		opacity: 1;
		transform: translateY(0) scaleY(1);
	}
}

body[data-theme='light'] .tree-folder-children {
	border-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), transparent) 1;
}

.tree-folder-children.collapsed {
	display: none;
}

/* "Empty folder" hint inside an open but empty folder */
.tree-folder-empty {
	padding: 8px 12px;
	font-size: 12px;
	color: var(--text-muted);
	font-style: italic;
	display: flex;
	align-items: center;
	gap: 6px;
	opacity: 0.7;
}

.tree-folder-empty::before {
	content: '';
	display: inline-block;
	width: 4px;
	height: 4px;
	border-radius: 50%;
	background: currentColor;
}

/* Slightly less left-padding for nested specs */
.tree-spec-item.is-nested {
	padding-left: 8px;
	margin-top: 2px;
}

.tree-spec-item.is-nested::before {
	display: none; /* No nested gradient overlays */
}

/* ── Drag and Drop ───────────────────────────────────────────────────────── */

/* Dim the spec being dragged */
.tree-spec-item.dragging {
	opacity: 0.4;
	transform: scale(0.98);
}

/* Highlight a folder when a spec is dragged over it */
.tree-folder.drop-over > .tree-folder-row {
	background: rgba(59, 130, 246, 0.1);
	box-shadow:
		inset 0 0 0 1px var(--sidebar-accent),
		0 4px 12px rgba(59, 130, 246, 0.2);
	border-radius: 8px;
	transform: scale(1.02);
	z-index: 1;
}

/* Highlight the root drop zone */
#spec-list.root-drop-over {
	box-shadow: inset 0 0 0 1px var(--sidebar-accent);
	background: rgba(59, 130, 246, 0.03);
	border-radius: 8px;
}

/* ── Inline rename / create input ────────────────────────────────────────── */

.tree-inline-input {
	flex: 1;
	min-width: 0;
	background: var(--glass-bg-highest);
	border: 1px solid var(--sidebar-accent);
	border-radius: 4px;
	color: var(--text);
	font-size: 13px;
	font-family: inherit;
	font-weight: 500;
	padding: 2px 6px;
	height: 24px;
	outline: none;
	box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
	transition:
		border-color 0.2s,
		box-shadow 0.2s;
}

.tree-inline-input:focus {
	border-color: #60a5fa;
	box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
}

body[data-theme='light'] .tree-inline-input {
	background: #fff;
	box-shadow:
		0 2px 6px rgba(0, 0, 0, 0.05),
		0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Pending new-folder row (inserted by app.promptCreateFolder) */
.tree-new-folder-row .tree-folder-row {
	background: rgba(59, 130, 246, 0.08);
	border: 1px dashed rgba(59, 130, 246, 0.4);
	animation: pulse-border 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse-border {
	0%,
	100% {
		border-color: rgba(59, 130, 246, 0.4);
	}
	50% {
		border-color: rgba(59, 130, 246, 0.8);
		background: rgba(59, 130, 246, 0.12);
	}
}
