/* ════════════════════════════════════════════════════════════════════════════ */
/* ── layout.css — App shell, rail, section panel, editor, mobile chrome ────── */
/* ════════════════════════════════════════════════════════════════════════════ */

#app-screen {
	flex-direction: column;
	height: 100vh;
	height: 100dvh;
	overflow: hidden;
}

/* ── Mobile Topbar ─────────────────────────────────────────────────────────── */
.mobile-topbar {
	height: var(--nav-height);
	background: var(--surface);
	border-bottom: 1px solid var(--border);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 12px;
	z-index: 100;
	flex-shrink: 0;
}

.mobile-topbar-left { display: flex; align-items: center; gap: 6px; }

.mobile-topbar-title {
	font-size: 1.12rem;
	font-weight: 800;
	color: var(--text-primary);
	letter-spacing: -0.3px;
}

.mobile-topbar-actions { display: flex; align-items: center; gap: 4px; }

.nav-btn {
	background: transparent;
	border: none;
	cursor: pointer;
	padding: 9px;
	border-radius: var(--radius-sm);
	color: var(--text-secondary);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: var(--transition);
	min-width: 44px;
	min-height: 44px;
}
.nav-btn:hover { background: var(--accent-soft); color: var(--text-primary); }

/* ── Mobile tier badge ─────────────────────────────────────────────────────── */
.mobile-tier-badge {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: var(--accent);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	cursor: pointer;
	position: relative;
	transition: var(--transition);
}
.mobile-tier-badge:hover { filter: brightness(0.94); }
.mobile-tier-badge svg {
	width: 19px; height: 19px; display: block;
	color: #000; fill: #000; position: relative; z-index: 2;
}

/* ── App Shell ─────────────────────────────────────────────────────────────── */
.app-shell {
	display: flex;
	flex: 1;
	overflow: hidden;
	position: relative;
	height: 100%;
}

/* ── Sidebar Overlay (mobile dim) ──────────────────────────────────────────── */
.sidebar-overlay {
	position: fixed;
	inset: 0;
	top: var(--nav-height);
	background: rgba(0, 0, 0, 0.4);
	opacity: 0;
	pointer-events: none;
	z-index: calc(var(--z-panel) - 1);
	transition: opacity 0.3s ease;
	backdrop-filter: blur(2px);
}

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── APP RAIL ────────────────────────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════════════════════════ */
#app-rail {
	width: var(--rail-width);
	background: var(--sidebar-bg);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	align-items: center;
	flex-shrink: 0;
	height: 100%;
	overflow: visible;
	z-index: var(--z-rail);
	transition: width 0.2s ease;
	padding: 10px 0;
}

#app-rail.rail-expanded { width: var(--rail-expanded-width); }

.rail-brand {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 10px;
	padding: 4px 0 12px;
	width: 100%;
	border-bottom: 1px solid var(--border);
	margin-bottom: 6px;
	overflow: visible;
}

/* ── Tier Badge ────────────────────────────────────────────────────────────── */
.rail-tier-badge {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--accent);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	cursor: pointer;
	position: relative;
	transition: var(--transition);
	box-shadow: var(--shadow-xs);
}
.rail-tier-badge:hover { filter: brightness(0.94); transform: scale(1.04); }
.rail-tier-badge svg {
	width: 21px; height: 21px; display: block;
	color: #000; fill: #000; position: relative; z-index: 2;
}

/* ── Panel collapse toggle ─────────────────────────────────────────────────── */
.rail-panel-toggle-btn {
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--surface);
	color: var(--text-secondary);
	border: 1px solid var(--border);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: var(--transition);
	flex-shrink: 0;
	line-height: 1;
}
.rail-panel-toggle-btn:hover { background: var(--accent-soft); color: var(--text-primary); border-color: var(--accent); }
.rail-panel-toggle-btn svg { display: block; transition: transform 0.2s ease; }
.app-shell.panel-collapsed .rail-panel-toggle-btn svg { transform: rotate(180deg); }

/* ── Rail Nav ──────────────────────────────────────────────────────────────── */
.rail-nav {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	flex: 1;
	width: 100%;
	padding: 6px 0;
}

.rail-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 4px;
	width: 58px;
	min-height: 56px;
	padding: 7px 4px;
	border: none;
	border-radius: var(--radius-md);
	background: transparent;
	color: var(--text-secondary);
	font-family: var(--font);
	cursor: pointer;
	transition: var(--transition);
	position: relative;
}
.rail-item:hover { background: var(--accent-soft); color: var(--text-primary); }
.rail-item.active { background: var(--accent-soft); color: var(--accent-hover); }
.rail-item.active::before {
	content: '';
	position: absolute;
	left: -10px;
	top: 50%;
	transform: translateY(-50%);
	width: 3px;
	height: 24px;
	border-radius: var(--radius-pill);
	background: var(--accent);
}
.rail-item svg { flex-shrink: 0; }

.rail-item-label {
	font-size: 0.62rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	text-align: center;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 100%;
	line-height: 1.2;
	display: block;
}

.rail-nav-divider {
	width: 40px;
	height: 1px;
	background: var(--border);
	margin: 8px 0;
	flex-shrink: 0;
}

.rail-action-group {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	width: 100%;
}

.rail-action-dropdown {
	position: absolute;
	top: 0;
	left: calc(100% + 8px);
	min-width: 210px;
	width: max-content;
	max-width: calc(100vw - var(--rail-width) - 24px);
	background: var(--surface-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-md);
	z-index: var(--z-floating);
	overflow: hidden;
	padding: 6px;
}

.rail-bottom {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding: 10px 0 2px;
	border-top: 1px solid var(--border);
	width: 100%;
}

#user-avatar { display: none; }

/* ── Tooltip on tier badge ─────────────────────────────────────────────────── */
.rail-tier-badge[data-tooltip]::before {
	content: attr(data-tooltip);
	position: absolute;
	top: calc(100% + 8px);
	left: 0;
	right: auto;
	transform: none;
	background: var(--text-primary);
	color: var(--surface);
	font-size: 0.72rem;
	font-weight: 600;
	white-space: normal;
	width: max-content;
	max-width: min(220px, calc(100vw - var(--rail-width) - 24px));
	padding: 6px 11px;
	border-radius: var(--radius-sm);
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.15s ease;
	z-index: var(--z-floating);
	line-height: 1.45;
	box-shadow: var(--shadow-sm);
}
.rail-tier-badge[data-tooltip]:hover::before,
.rail-tier-badge[data-tooltip]:focus::before { opacity: 1; }

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── SECTION PANEL ───────────────────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════════════════════════ */
#section-panel {
	width: var(--panel-width);
	background: var(--sidebar-bg);
	border-right: 1px solid var(--border);
	display: flex;
	flex-direction: column;
	flex-shrink: 0;
	height: 100%;
	overflow: hidden;
	z-index: var(--z-panel);
}

.app-shell.panel-collapsed #section-panel { display: none; }

.section-panel-body {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow-y: auto;
	overflow-x: hidden;
}

.panel-sub { display: flex; flex-direction: column; flex: 0 0 auto; }
.panel-sub.hidden { display: none !important; }

.panel-header {
	padding: 16px 18px 12px;
	flex-shrink: 0;
}

.panel-header h2 {
	font-size: 1.05rem;
	font-weight: 800;
	color: var(--text-primary);
	margin-bottom: 12px;
	letter-spacing: -0.3px;
}

.panel-new-note-btn {
	width: 100%;
	padding: 10px 14px;
	background: var(--accent);
	color: var(--accent-contrast);
	border: none;
	border-radius: var(--radius-sm);
	font-size: 0.9rem;
	font-weight: 700;
	font-family: var(--font);
	cursor: pointer;
	transition: var(--transition);
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	box-shadow: var(--shadow-xs);
}
.panel-new-note-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.panel-search { padding: 4px 14px 12px; flex-shrink: 0; }

.panel-search input {
	width: 100%;
	padding: 10px 14px;
	border: 1.5px solid var(--border);
	border-radius: var(--radius-pill);
	font-size: 0.88rem;
	font-family: var(--font);
	background: var(--surface);
	color: var(--text-primary);
	outline: none;
	transition: var(--transition);
}
.panel-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.panel-notes-list { flex: 0 0 auto; padding: 6px 10px 8px; }

.sidebar-empty-msg {
	text-align: center;
	color: var(--text-muted);
	font-size: 0.85rem;
	padding: 32px 18px;
	line-height: 1.6;
}

/* ── Shared footer ─────────────────────────────────────────────────────────── */
.section-app-footer {
	flex: 0 0 auto;
	margin-top: auto;
	padding: 14px 18px;
	border-top: 1px solid var(--border);
	text-align: center;
	background: var(--sidebar-bg);
}
.footer-copy { font-size: 0.72rem; color: var(--text-muted); line-height: 1.5; }
.footer-version { font-size: 0.68rem; color: var(--text-muted); margin-top: 3px; line-height: 1.5; opacity: 0.85; }
.footer-links { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.footer-link {
	font-size: 0.69rem; color: var(--text-secondary); text-decoration: none;
	cursor: pointer; transition: color 0.15s ease; white-space: nowrap;
}
.footer-link:hover { color: var(--text-primary); text-decoration: underline; }
.footer-link-sep { font-size: 0.69rem; color: var(--text-muted); opacity: 0.5; user-select: none; }
.footer-link-pro { color: var(--pro-gold); font-weight: 700; }
.footer-link-pro:hover { color: var(--accent-hover); }
html.night-mode .footer-link-pro { color: var(--accent); }

/* ── Sidebar dropdown group (shared) ───────────────────────────────────────── */
.sidebar-dropdown-group { position: relative; flex: 1; }

.btn-sidebar-action {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	width: 100%;
	padding: 11px 12px;
	border: 1.5px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text-secondary);
	font-size: 0.88rem;
	font-family: var(--font);
	font-weight: 600;
	cursor: pointer;
	transition: var(--transition);
	white-space: nowrap;
}
.btn-sidebar-action:hover { border-color: var(--accent); color: var(--text-primary); background: var(--accent-soft); }

.sidebar-dropdown {
	position: absolute;
	bottom: calc(100% + 8px);
	left: 0;
	min-width: 210px;
	width: max-content;
	max-width: calc(100vw - 24px);
	background: var(--surface-elevated);
	border: 1px solid var(--border);
	border-radius: var(--radius-md);
	box-shadow: var(--shadow-md);
	z-index: var(--z-floating);
	overflow: hidden;
	padding: 6px;
}
#mobile-receive-group .sidebar-dropdown { left: auto; right: 0; }

.mobile-share-receive-bar { display: none; }

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── EDITOR WORKSPACE ────────────────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════════════════════════ */
.editor-workspace {
	flex: 1;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	height: 100%;
	background: var(--bg);
	transition: background 0.3s ease;
}

.empty-state {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 40px;
	text-align: center;
}
.empty-icon { font-size: 3.4rem; opacity: 0.85; }
.empty-state h2 { font-size: 1.35rem; color: var(--text-primary); font-weight: 700; letter-spacing: -0.3px; }
.empty-state p { color: var(--text-secondary); font-size: 0.92rem; max-width: 300px; line-height: 1.6; }
.empty-state .btn-primary { width: auto; margin-top: 10px; padding: 12px 26px; }

.note-editor {
	flex: 1;
	display: flex;
	flex-direction: column;
	height: 100%;
	overflow: hidden;
}

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── RESPONSIVE — desktop ─────────────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════════════════════════ */
@media (min-width: 769px) {
	.mobile-topbar { display: none; }
	#section-panel { transform: none !important; position: static !important; }
	#app-screen { flex-direction: row; }
	.app-shell { height: 100%; width: 100%; }
	.mobile-share-receive-bar { display: none !important; }

	.sidebar-overlay,
	.sidebar-overlay.active {
		display: none !important;
		opacity: 0 !important;
		pointer-events: none !important;
	}

	.section-app-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
}

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── RESPONSIVE — mobile (≤768px) ────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
	#app-screen { flex-direction: column; }
	.app-shell { flex: 1; overflow: hidden; height: calc(100% - var(--nav-height)); }
	#app-rail { display: none; }
	.app-shell.panel-collapsed #section-panel { display: flex; }

	#section-panel {
		position: fixed;
		top: var(--nav-height);
		left: 0;
		width: 86%;
		max-width: 320px;
		height: calc(100vh - var(--nav-height));
		height: calc(100dvh - var(--nav-height));
		transform: translateX(-100%);
		transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
		z-index: var(--z-panel);
		overflow-y: hidden;
		overflow-x: hidden;
		display: flex;
		flex-direction: column;
		box-shadow: var(--shadow-lg);
	}
	#section-panel.panel-open { transform: translateX(0); }

	.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

	.mobile-section-switcher { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }

	.section-panel-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }

	.section-app-footer {
		margin-bottom: calc(
			var(--mobile-action-bar-height) +
			max(var(--mobile-bottom-clearance), env(safe-area-inset-bottom, 0px))
		);
	}

	.mobile-share-receive-bar {
		display: flex;
		gap: 8px;
		align-items: center;
		flex-shrink: 0;
		padding: 12px 12px;
		padding-bottom: max(var(--mobile-bottom-clearance), env(safe-area-inset-bottom, 0px));
		background: var(--surface);
		border-top: 1px solid var(--border);
		box-shadow: 0 -6px 20px rgba(0,0,0,0.08);
		z-index: 3;
	}
	html.night-mode .mobile-share-receive-bar { box-shadow: 0 -6px 20px rgba(0,0,0,0.4); }

	.editor-workspace { width: 100%; }
}

/* ── Mobile section switcher ───────────────────────────────────────────────── */
.mobile-section-switcher { display: none; }

@media (max-width: 768px) {
	.mobile-section-switcher { display: flex; padding: 6px 8px; gap: 4px; }

	.mobile-section-tab {
		flex: 1;
		padding: 10px 4px;
		border: none;
		border-radius: var(--radius-sm);
		background: transparent;
		color: var(--text-secondary);
		font-size: 0.82rem;
		font-weight: 600;
		font-family: var(--font);
		cursor: pointer;
		text-align: center;
		transition: var(--transition);
	}
	.mobile-section-tab.active { color: var(--accent-contrast); background: var(--accent); }
	html.night-mode .mobile-section-tab.active { color: var(--accent-contrast); }
}