/*!
 * shell.css — bố cục App Shell: sidebar · rail · drawer · topbar · vùng nội dung.
 *
 * Component (button, input, card, nav item, toast, modal) nằm ở components.css.
 * File này chỉ lo BỐ CỤC và trạng thái responsive của khung.
 *
 * Ba breakpoint, một khối DOM duy nhất cho điều hướng:
 *   ≥1024px  sidebar 256px (thu gọn được về rail 72px)
 *   768–1023 rail 72px, không thu/mở
 *   <768px   drawer trượt từ trái + scrim
 *
 * Không nhân đôi markup điều hướng cho mobile: hai bản sao sẽ khiến screen reader
 * đọc menu hai lần và làm bài crawl link A65 đếm trùng toàn bộ route.
 */

/* ================================================================== *
 * Khung
 * ================================================================== */

.xh-app .xh-shell,
.xh-auth .xh-shell {
	min-height: 100vh;
	min-height: 100dvh;
	background: var(--xh-app-bg);
}

.xh-app .xh-shell__main {
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh;
	margin-left: 256px;
	transition: margin-left .16s ease;
}

.xh-app .xh-content {
	flex: 1;
	padding: var(--xh-space-8);
}

/* ================================================================== *
 * Sidebar
 * ================================================================== */

.xh-app .xh-sidebar {
	position: fixed;
	inset: 0 auto 0 0;
	z-index: 60;
	display: flex;
	flex-direction: column;
	width: 256px;
	background: var(--xh-sidebar);
	transition: width .16s ease, transform .16s ease;
}

.xh-app .xh-sidebar__head {
	display: flex;
	align-items: center;
	flex: none;
	height: 60px;
	padding: 0 var(--xh-space-3) 0 var(--xh-space-4);
}

.xh-app .xh-sidebar__brand {
	display: flex;
	align-items: center;
	gap: var(--xh-space-3);
	min-width: 0;
	color: var(--xh-on-dark);
	text-decoration: none;
	overflow: hidden;
}

.xh-app .xh-sidebar__brand:hover { text-decoration: none; }

.xh-app .xh-sidebar__logo {
	flex: none;
	width: 32px;
	height: 32px;
	border-radius: var(--xh-r-sm);
	object-fit: contain;
	background: var(--xh-on-dark);
}

.xh-app .xh-sidebar__title {
	display: block;
	font-size: 14px;
	line-height: 18px;
	white-space: nowrap;
}

.xh-app .xh-sidebar__sub {
	display: block;
	font-size: 11.5px;
	line-height: 16px;
	color: var(--xh-sidebar-ink);
	white-space: nowrap;
}

.xh-app .xh-sidebar__nav {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: var(--xh-space-2) var(--xh-space-3) var(--xh-space-6);
}

.xh-app .xh-sidebar__section { margin-top: var(--xh-space-5); }

.xh-app .xh-sidebar__section-label {
	display: block;
	padding: 0 var(--xh-space-3) var(--xh-space-2);
	color: var(--xh-sidebar-ink-2);
}

.xh-app .xh-sidebar__list { display: flex; flex-direction: column; gap: 2px; }

/* --- Chân sidebar: khối danh tính --- */

.xh-app .xh-sidebar__foot {
	flex: none;
	padding: var(--xh-space-3);
	border-top: 1px solid var(--xh-sidebar-line);
}

/* Nội dung của khối này là .xh-account — xem mục "Dropdown tài khoản" bên dưới. */

/* Nút đóng drawer — chỉ tồn tại ở chế độ drawer. */
.xh-app .xh-sidebar__close {
	display: none;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 40px;
	height: 40px;
	margin-left: auto;
	border: 0;
	border-radius: var(--xh-r-sm);
	background: none;
	color: var(--xh-sidebar-ink);
	cursor: pointer;
}

.xh-app .xh-sidebar__close:hover { background: var(--xh-sidebar-hover); color: var(--xh-on-dark); }

/* Lớp mờ sau drawer. */
.xh-app .xh-scrim {
	position: fixed;
	inset: 0;
	z-index: 55;
	background: var(--xh-overlay);
	opacity: 0;
	visibility: hidden;
	transition: opacity .16s ease, visibility .16s ease;
}

/* ================================================================== *
 * Rail — sidebar thu gọn. Nhãn KHÔNG bị display:none: nó chuyển sang
 * dạng chỉ-screen-reader để mỗi mục vẫn giữ accessible name (A42).
 * ================================================================== */

.xh-app.is-rail .xh-sidebar { width: 72px; }
.xh-app.is-rail .xh-shell__main { margin-left: 72px; }

.xh-app.is-rail .xh-sidebar__head { justify-content: center; padding: 0; }

.xh-app.is-rail .xh-sidebar__text,
.xh-app.is-rail .xh-nav-item__label,
.xh-app.is-rail .xh-account__id,
.xh-app.is-rail .xh-account__chevron,
.xh-app.is-rail .xh-sidebar__section-label {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.xh-app.is-rail .xh-sidebar__nav { padding-left: var(--xh-space-2); padding-right: var(--xh-space-2); }
.xh-app.is-rail .xh-nav-item { justify-content: center; padding: 9px 0; }
.xh-app.is-rail .xh-sidebar__section { margin-top: var(--xh-space-4); }
.xh-app.is-rail .xh-sidebar__foot { padding: var(--xh-space-2); }
.xh-app.is-rail .xh-account__trigger { justify-content: center; padding: var(--xh-space-2) 0; }

/* Rail rộng 72px — panel 220px không nhét vừa, phải bung sang phải như tooltip. */
.xh-app.is-rail .xh-account__panel { left: calc(100% + var(--xh-space-2)); right: auto; bottom: 0; }

/* Tooltip của rail — hiện khi hover VÀ khi focus bàn phím. */
.xh-app.is-rail .xh-nav-item { position: relative; }

.xh-app.is-rail .xh-nav-item::after {
	content: attr(data-tooltip);
	position: absolute;
	left: calc(100% + var(--xh-space-2));
	top: 50%;
	transform: translateY(-50%);
	z-index: 70;
	padding: 6px 10px;
	border-radius: var(--xh-r-sm);
	background: var(--xh-sidebar);
	color: var(--xh-tooltip-ink);
	font-size: 12px;
	line-height: 18px;
	white-space: nowrap;
	box-shadow: var(--xh-sh-md);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity .12s ease, visibility .12s ease;
}

.xh-app.is-rail .xh-nav-item:hover::after,
.xh-app.is-rail .xh-nav-item:focus-visible::after { opacity: 1; visibility: visible; }

/* ================================================================== *
 * Topbar
 * ================================================================== */

.xh-app .xh-topbar {
	position: sticky;
	top: 0;
	z-index: 50;
	display: flex;
	align-items: center;
	gap: var(--xh-space-4);
	flex: none;
	height: 60px;
	padding: 0 var(--xh-space-6);
	background: var(--xh-surface);
	border-bottom: 1px solid var(--xh-line);
}

.xh-app .xh-topbar__toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 38px;
	height: 38px;
	border: 1px solid var(--xh-line);
	border-radius: var(--xh-r-sm);
	background: var(--xh-surface);
	color: var(--xh-ink-2);
	cursor: pointer;
}

.xh-app .xh-topbar__toggle:hover { background: var(--xh-hover-soft); color: var(--xh-primary); }

/* Một nút, hai vai trò: thu gọn rail ở desktop, mở drawer ở mobile. */
.xh-app .xh-topbar__icon-drawer { display: none; }

.xh-app .xh-topbar__greeting { min-width: 0; }

.xh-app .xh-topbar__hello {
	display: block;
	font-size: 14px;
	line-height: 20px;
	color: var(--xh-ink);
}

.xh-app .xh-topbar__date {
	display: block;
	font-size: 11.5px;
	line-height: 16px;
	color: var(--xh-ink-muted);
}

.xh-app .xh-topbar__search { margin-left: auto; width: 280px; max-width: 34vw; }

/* ================================================================== *
 * Dropdown tài khoản
 *
 * Ngữ nghĩa là <button> + <nav><ul><a> (Q4/X8). CSS không áp đặt role nào.
 * Panel đóng bằng thuộc tính `hidden`, không bằng class — `hidden` loại
 * hẳn link khỏi tab order, class chỉ ẩn về mặt thị giác.
 * ================================================================== */

.xh-app .xh-account { position: relative; flex: none; }

/* Nút nằm trên nền tối của sidebar ⇒ màu chữ và màu hover đều theo bảng sidebar,
   không dùng bảng màu của vùng nội dung sáng. */
.xh-app .xh-account__trigger {
	display: flex;
	align-items: center;
	gap: var(--xh-space-3);
	width: 100%;
	min-height: 44px;
	padding: var(--xh-space-2);
	border: 1px solid transparent;
	border-radius: var(--xh-r-sm);
	background: none;
	color: var(--xh-on-dark);
	text-align: left;
	cursor: pointer;
}

.xh-app .xh-account__trigger:hover { background: var(--xh-sidebar-hover); }
.xh-app .xh-account__trigger[aria-expanded="true"] { background: var(--xh-sidebar-hover); border-color: transparent; }

.xh-app .xh-account__id { flex: 1; min-width: 0; }

.xh-app .xh-account__name {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 13.5px;
	line-height: 20px;
	color: var(--xh-on-dark);
}

.xh-app .xh-account__role {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-size: 11.5px;
	line-height: 17px;
	color: var(--xh-sidebar-ink-2);
}

/* Một icon duy nhất, xoay khi mở — không đổi href để tránh lệch giữa hai trạng thái. */
.xh-app .xh-account__chevron {
	flex: none;
	width: 16px;
	height: 16px;
	color: var(--xh-sidebar-ink-2);
	transition: transform .12s ease;
}

.xh-app .xh-account__trigger[aria-expanded="true"] .xh-account__chevron { transform: rotate(180deg); }

/* Panel mở LÊN TRÊN: khối này nằm sát đáy màn hình, mở xuống là tràn ra ngoài. */
.xh-app .xh-account__panel {
	position: absolute;
	left: 0;
	right: 0;
	bottom: calc(100% + var(--xh-space-2));
	z-index: 70;
	min-width: 220px;
	padding: 6px;
	border: 1px solid var(--xh-line);
	border-radius: var(--xh-r-md);
	background: var(--xh-surface);
	box-shadow: var(--xh-sh-lg);
}

.xh-app .xh-account__panel[hidden] { display: none; }

.xh-app .xh-account__item {
	display: flex;
	align-items: center;
	gap: var(--xh-space-2);
	padding: 9px 10px;
	border-radius: var(--xh-r-sm);
	color: var(--xh-ink-2);
	font-size: 13.5px;
	line-height: 20px;
	text-decoration: none;
}

.xh-app .xh-account__item:hover { background: var(--xh-app-bg); text-decoration: none; }

.xh-app .xh-account__item .xh-icon { width: 18px; height: 18px; }

/* Vạch ngăn thuần trình bày — không <hr>, không <li> rỗng (D6). */
.xh-app .xh-account__item--danger {
	margin-top: 5px;
	padding-top: 14px;
	border-top: 1px solid var(--xh-line);
	border-radius: 0 0 var(--xh-r-sm) var(--xh-r-sm);
	color: var(--xh-danger);
}

.xh-app .xh-account__item--danger:hover { background: var(--xh-danger-bg); }

/* ================================================================== *
 * 768–1023px — rail cố định, không cho thu/mở
 * ================================================================== */

@media (min-width: 768px) and (max-width: 1023px) {

	.xh-app .xh-sidebar { width: 72px; }
	.xh-app .xh-shell__main { margin-left: 72px; }
	.xh-app .xh-sidebar__head { justify-content: center; padding: 0; }

	.xh-app .xh-sidebar__text,
	.xh-app .xh-nav-item__label,
	.xh-app .xh-account__id,
	.xh-app .xh-account__chevron,
	.xh-app .xh-sidebar__section-label {
		position: absolute !important;
		width: 1px;
		height: 1px;
		padding: 0;
		margin: -1px;
		overflow: hidden;
		clip: rect(0, 0, 0, 0);
		white-space: nowrap;
		border: 0;
	}

	.xh-app .xh-sidebar__foot { padding: var(--xh-space-2); }
	.xh-app .xh-account__trigger { justify-content: center; padding: var(--xh-space-2) 0; }
	.xh-app .xh-account__panel { left: calc(100% + var(--xh-space-2)); right: auto; bottom: 0; }

	.xh-app .xh-sidebar__nav { padding-left: var(--xh-space-2); padding-right: var(--xh-space-2); }
	.xh-app .xh-nav-item { position: relative; justify-content: center; padding: 9px 0; }

	.xh-app .xh-nav-item::after {
		content: attr(data-tooltip);
		position: absolute;
		left: calc(100% + var(--xh-space-2));
		top: 50%;
		transform: translateY(-50%);
		z-index: 70;
		padding: 6px 10px;
		border-radius: var(--xh-r-sm);
		background: var(--xh-sidebar);
		color: var(--xh-tooltip-ink);
		font-size: 12px;
		line-height: 18px;
		white-space: nowrap;
		box-shadow: var(--xh-sh-md);
		opacity: 0;
		visibility: hidden;
		pointer-events: none;
	}

	.xh-app .xh-nav-item:hover::after,
	.xh-app .xh-nav-item:focus-visible::after { opacity: 1; visibility: visible; }

	.xh-app .xh-topbar__search { width: 200px; }

	/* Rail bị ép ở dải này — không có gì để thu/mở nên nút biến mất hẳn. */
	.xh-app .xh-topbar__toggle { display: none; }
}

/* ================================================================== *
 * <768px — drawer
 * ================================================================== */

@media (max-width: 767px) {

	.xh-app .xh-sidebar {
		width: 280px;
		max-width: 86vw;
		transform: translateX(-100%);
	}

	/* Bóng CHỈ khi drawer mở.
	 *
	 * Để bóng ở trạng thái đóng thì nó vẫn đổ ra ngoài: drawer nằm ở
	 * translateX(-100%) nên mép phải của nó trùng x = 0, mà --xh-sh-lg có độ
	 * nhoè 30px — thành ra một vệt tối chạy dọc mép trái màn hình, lúc nào cũng
	 * thấy dù menu đang đóng. transform không cắt bóng, và overflow của phần tử
	 * cha cũng không cắt vì sidebar là position:fixed. */
	.xh-app.is-drawer-open .xh-sidebar {
		transform: translateX(0);
		box-shadow: var(--xh-sh-lg);
	}
	.xh-app.is-drawer-open .xh-scrim { opacity: 1; visibility: visible; }

	.xh-app .xh-shell__main { margin-left: 0; }

	.xh-app .xh-sidebar__close { display: flex; }

	.xh-app .xh-topbar {
		height: 56px;
		gap: var(--xh-space-2);
		padding: 0 var(--xh-space-4);
	}

	.xh-app .xh-topbar__toggle { width: 44px; height: 44px; }
	.xh-app .xh-topbar__icon-rail { display: none; }
	.xh-app .xh-topbar__icon-drawer { display: block; }

	/* Lời chào nhường chỗ cho ô tìm kiếm và avatar. */
	.xh-app .xh-topbar__greeting { display: none; }

	.xh-app .xh-topbar__search { width: auto; max-width: none; flex: 1; margin-left: 0; }

	/* Drawer mở ra là đủ rộng — khối tài khoản hiện đầy đủ như ở desktop. */
	.xh-app .xh-account__panel { min-width: 200px; }

	.xh-app .xh-content { padding: var(--xh-space-4); }

	/* Rail không tồn tại ở kích thước này — trạng thái thu gọn bị vô hiệu. */
	.xh-app.is-rail .xh-sidebar { width: 280px; max-width: 86vw; }
	.xh-app.is-rail .xh-shell__main { margin-left: 0; }

	.xh-app.is-rail .xh-sidebar__text,
	.xh-app.is-rail .xh-nav-item__label,
	.xh-app.is-rail .xh-account__id,
	.xh-app.is-rail .xh-account__chevron,
	.xh-app.is-rail .xh-sidebar__section-label {
		position: static !important;
		width: auto;
		height: auto;
		margin: 0;
		overflow: visible;
		clip: auto;
	}

	/* Rail bị vô hiệu ở kích thước này ⇒ trả khối tài khoản về dạng đầy đủ. */
	.xh-app.is-rail .xh-sidebar__foot { padding: var(--xh-space-3); }
	.xh-app.is-rail .xh-account__trigger { justify-content: flex-start; padding: var(--xh-space-2); }
	.xh-app.is-rail .xh-account__panel { left: 0; right: 0; bottom: calc(100% + var(--xh-space-2)); }
	.xh-app.is-rail .xh-account__chevron { width: 16px; height: 16px; }

	.xh-app.is-rail .xh-nav-item { justify-content: flex-start; padding: 9px var(--xh-space-3); }
	.xh-app.is-rail .xh-nav-item::after { content: none; }
	.xh-app.is-rail .xh-sidebar__head { justify-content: flex-start; padding: 0 var(--xh-space-3) 0 var(--xh-space-4); }

	/* Mục tiêu chạm 44px (A50). */
	.xh-app .xh-nav-item { min-height: 44px; }
	.xh-app .xh-account__item { min-height: 44px; }
}

/* ================================================================== *
 * Không có JavaScript — sidebar phải mở, không được kẹt ở trạng thái ẩn
 * ================================================================== */

@media (max-width: 767px) {
	.xh-app.no-js .xh-sidebar { position: static; transform: none; width: auto; max-width: none; box-shadow: none; }
	.xh-app.no-js .xh-sidebar__close { display: none; }
	.xh-app.no-js .xh-topbar__toggle { display: none; }
}

/*
 * Ngoại lệ DUY NHẤT được phép đè luật `[hidden] { display:none !important }` ở base.css.
 * Lý do: không có JS thì không ai bỏ được `hidden`, mà panel tài khoản chứa link Đăng
 * xuất — mất nó là người dùng kẹt lại trong hệ thống. Phải !important vì luật ở base.css
 * cũng !important; specificity (0,4,0) của dòng này mới là thứ quyết định thắng thua.
 */
.xh-app.no-js .xh-account__panel[hidden] { display: block !important; }
.xh-app.no-js .xh-account__trigger { display: none; }

/* ================================================================== *
 * Reduced motion
 * ================================================================== */

@media (prefers-reduced-motion: reduce) {
	.xh-app .xh-sidebar,
	.xh-app .xh-shell__main,
	.xh-app .xh-scrim { transition: none !important; }
}
