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

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

/* ── State-driven application startup view ───────────────────────────────── */
.startup-state {
	position: fixed;
	inset: 0;
	z-index: var(--z-modal);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 32px;
	text-align: center;
	background: var(--bg);
	color: var(--text-primary);
}
.startup-state.hidden { display: none !important; }
.startup-spinner {
	width: 38px;
	height: 38px;
	border: 4px solid var(--border);
	border-top-color: var(--accent-hover);
	border-radius: 50%;
	animation: qr-spin 0.8s linear infinite;
}
.startup-title { font-size: 1.15rem; font-weight: 800; }
.startup-body { max-width: 420px; color: var(--text-secondary); line-height: 1.65; }
.startup-failure .startup-title { color: var(--danger-dark); }

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

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

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

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

.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 back-to-notes label button ─────────────────────────────────────── */
.mobile-back-btn { gap: 4px; min-width: auto; padding: 9px 12px; }
.mobile-back-btn span { font-size: 0.86rem; font-weight: 600; }

/* ── Mobile tier badge (hidden while editing to make room for Back) ────────── */
.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);
	overflow: hidden;
}
.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;
}

/* ── Free-tier official logo image inside badges (Phase 1) ─────────────────── */
/* The badge container supplies the accessible name; the image is decorative.   */
/* SVG rendering remains vector-sharp at every size. The scale compensates for  */
/* the SVG canvas while retaining a deliberate clear gap around the badge edge. */
.rail-tier-badge img.tier-logo-img,
.mobile-tier-badge img.tier-logo-img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
	position: relative;
	z-index: 2;
	transform: scale(1.22);
	pointer-events: none;
	user-select: none;
}

/* ── 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;
	/* v1.2.4: pinned so the five-item navigation region scrolls instead.        */
	flex-shrink: 0;
}

/* ── 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);
	overflow: hidden;
}
.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;
}

/* ── Free-tier badge: square (v1.4.0) ─────────────────────────────────────── */
/* The Free badge is the only tier badge rendered as a square, using the       */
/* existing extra-small radius token. Pro and Max badges keep their round      */
/* coin styling and are unchanged.                                             */
.rail-tier-badge.tier-free,
.mobile-tier-badge.tier-free { border-radius: var(--radius-xs); }

/* ── 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 ──────────────────────────────────────────────────────────────── */
/* v1.2.4: with five destinations the rail can exceed a short viewport, so the */
/* navigation region is bounded and scrolls while the brand block and the      */
/* bottom utilities stay pinned and always reachable. The tier-badge tooltip   */
/* lives in .rail-brand, OUTSIDE this scrolling region, so it is not clipped   */
/* and #app-rail keeps overflow: visible.                                      */
.rail-nav {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	flex: 1;
	min-height: 0;
	width: 100%;
	padding: 6px 0;
	overflow-y: auto;
	overflow-x: hidden;
	scrollbar-width: thin;
}

.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-bottom {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	padding: 10px 0 2px;
	border-top: 1px solid var(--border);
	width: 100%;
	/* v1.2.4: pinned so it can never be pushed off-screen by the fifth item.    */
	flex-shrink: 0;
}

/* ── Desktop quick-install control (v1.2.3) ────────────────────────────────── */
/* Reuses the .rail-item pattern; hidden unless a direct install is available.  */
/* On very short displays it must not overflow the rail, so it can shrink.      */
.rail-install-btn { flex-shrink: 0; }
@media (max-height: 640px) {
	.rail-install-btn .rail-item-label { display: none; }
	.rail-install-btn { min-height: 44px; }
}

/* ── Short-viewport compact modes for the five-item rail (v1.2.4) ─────────── */
/* Scrolling above is the guaranteed fallback; these breakpoints simply keep   */
/* everything visible without scrolling for as long as possible. Touch and     */
/* pointer targets never drop below the 44px standard.                        */
@media (max-height: 700px) {
	.rail-item { min-height: 48px; padding: 5px 4px; }
	.rail-nav { gap: 2px; }
	.rail-brand { gap: 8px; padding: 2px 0 10px; margin-bottom: 4px; }
}

@media (max-height: 600px) {
	/* Labels stay visible: discoverability outweighs the saved pixels, and the */
	/* rail's own scrolling is the guaranteed fallback on very short screens.   */
	.rail-item { min-height: 44px; }
	.rail-bottom { padding: 8px 0 2px; }
}

#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; }

/* ── The panel body no longer scrolls as one block. Each panel-sub owns its ── */
/* own bounded scrolling so headings/search stay pinned while lists scroll.    */
.section-panel-body {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.panel-sub {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
	overflow: hidden;
}
.panel-sub.hidden { display: none !important; }

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

.panel-header-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 12px;
}

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

.panel-new-note-btn {
	padding: 9px 14px;
	background: var(--accent);
	color: var(--accent-contrast);
	border: none;
	border-radius: var(--radius-sm);
	font-size: 0.86rem;
	font-weight: 700;
	font-family: var(--font);
	cursor: pointer;
	transition: var(--transition);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	box-shadow: var(--shadow-xs);
	white-space: nowrap;
	flex-shrink: 0;
}
.panel-new-note-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }

/* ── Panel header action group (v1.3.7) ────────────────────────────────────── */
/* A single segmented bar styled like the Notes panel's primary New Note        */
/* button: New Folder leads as the main action, New note follows behind a       */
/* visible divider.                                                             */
.panel-header-actions {
	display: flex;
	align-items: stretch;
	flex-shrink: 0;
	background: var(--accent);
	border-radius: var(--radius-sm);
	box-shadow: var(--shadow-xs);
}

.panel-header-action {
	background: transparent;
	border: none;
	cursor: pointer;
	font-family: var(--font);
	color: var(--accent-contrast);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* Matches the + New Note button's rendered box: 9px 14px padding around a    */
	/* 20px content area, giving a 38px height and a ~97px total bar width.       */
	padding: 9px 14px;
	width: 48px;
	height: 38px;
	transition: var(--transition);
}
.panel-header-action:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.panel-header-action:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.panel-header-action:hover { background: var(--accent-hover); }
/* The divider stays the light-theme accent-hover shade in BOTH themes: in      */
/* night mode the accent bar itself is light, so the dark-mode token would      */
/* render as a pale, washed-out line.                                           */
.panel-header-action-divided { border-left: 1.5px solid #C89A1E; }

.panel-search { padding: 0 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); }

/* ── Independently scrolling note list ─────────────────────────────────────── */
.panel-notes-list {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 6px 10px 12px;
}

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

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── 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;
}

/* ════════════════════════════════════════════════════════════════════════════ */
/* ── MOBILE BOTTOM NAVIGATION ──────────────────────────────────────────────── */
/* ════════════════════════════════════════════════════════════════════════════ */
.mobile-bottom-nav {
	display: none;
	flex-shrink: 0;
	background: var(--surface);
	border-top: 1px solid var(--border);
	box-shadow: 0 -4px 18px rgba(0,0,0,0.06);
	z-index: var(--z-bottomnav);
	padding-bottom: var(--app-safe-bottom);
}
html.night-mode .mobile-bottom-nav { box-shadow: 0 -4px 18px rgba(0,0,0,0.4); }

.mobile-bottom-nav-inner {
	display: flex;
	align-items: stretch;
	height: var(--mobile-bottomnav-height);
}

.bottomnav-item {
	flex: 1;
	min-width: 0;
	padding: 0 2px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 3px;
	border: none;
	background: transparent;
	color: var(--text-secondary);
	font-family: var(--font);
	cursor: pointer;
	transition: var(--transition-fast);
	min-height: 44px;
	position: relative;
}
.bottomnav-item svg { width: 21px; height: 21px; flex-shrink: 0; }
.bottomnav-item-label {
	font-size: 0.62rem;
	font-weight: 600;
	letter-spacing: 0.01em;
	/* v1.2.4: five equal-width items must remain legible at 320px without       */
	/* wrapping or overlapping. Each item is still 64px wide by 62px tall at     */
	/* that width, so every target stays above the 44px standard.                */
	max-width: 100%;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

@media (max-width: 340px) {
	.bottomnav-item-label { font-size: 0.58rem; }
}
.bottomnav-item.active { color: var(--accent-hover); }
html.night-mode .bottomnav-item.active { color: var(--accent); }
.bottomnav-item.active::before {
	content: '';
	position: absolute;
	top: 0; left: 50%;
	transform: translateX(-50%);
	width: 26px; height: 3px;
	border-radius: var(--radius-pill);
	background: var(--accent);
}

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

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

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

	.panel-header-action { min-height: 44px; }

	/* On mobile, the section panel becomes a full-width destination view that   */
	/* occupies the area between the topbar and the bottom nav.                  */
	#section-panel {
		position: static;
		width: 100%;
		max-width: none;
		height: 100%;
		transform: none;
		z-index: var(--z-panel);
		overflow: hidden;
		display: flex;
		flex-direction: column;
		box-shadow: none;
		border-right: none;
	}

	/* Editor takes the full mobile content area when active. */
	.editor-workspace { width: 100%; }

	/* When the editor is the active mobile destination, hide the section panel. */
	.app-shell.mobile-editing #section-panel { display: none; }
	.app-shell:not(.mobile-editing) .editor-workspace { display: none; }

	.sidebar-overlay { display: none !important; }

	.section-panel-body { flex: 1; min-height: 0; }
}