/**
 * THX Library - Frontend Styles
 * Giao diện Tủ sách số, Tra cứu mục lục theo số trang chính xác và Tóm tắt sách.
 */

:root {
	--thx-primary: #1e3a8a;       /* Deep navy blue */
	--thx-primary-hover: #1e40af;
	--thx-primary-light: #eff6ff;
	--thx-secondary: #059669;     /* Emerald green */
	--thx-secondary-light: #ecfdf5;
	--thx-accent: #d97706;        /* Warm amber */
	--thx-accent-light: #fef3c7;
	--thx-bg: #f8fafc;
	--thx-card-bg: #ffffff;
	--thx-text: #1e293b;
	--thx-text-muted: #64748b;
	--thx-border: #e2e8f0;
	--thx-border-hover: #cbd5e1;
	--thx-radius: 12px;
	--thx-radius-sm: 8px;
	--thx-radius-lg: 16px;
	--thx-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
	--thx-shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
	--thx-shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
	--thx-transition: all 0.25s ease-in-out;
}

/* ==========================================================================
   1. TỦ SÁCH CATALOG (SHORTCODE [thx_library])
   ========================================================================== */

.thx-library-catalog-wrap {
	max-width: 1200px;
	margin: 0 auto;
	padding: 1.5rem 1rem;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--thx-text);
}

.thx-lib-hero {
	background: linear-gradient(135deg, #1e3a8a 0%, #065f46 100%);
	color: #ffffff;
	border-radius: var(--thx-radius-lg);
	padding: 2.5rem 2rem;
	margin-bottom: 2rem;
	box-shadow: var(--thx-shadow-md);
}

.thx-lib-hero-content {
	max-width: 800px;
}

.thx-lib-title {
	margin: 0 0 0.75rem 0;
	font-size: 2rem;
	font-weight: 800;
	letter-spacing: -0.025em;
	color: #ffffff;
}

.thx-lib-subtitle {
	margin: 0;
	font-size: 1.05rem;
	line-height: 1.6;
	color: #e2e8f0;
	opacity: 0.95;
}

.thx-lib-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 1.75rem;
}

.thx-book-card {
	background: var(--thx-card-bg);
	border: 1px solid var(--thx-border);
	border-radius: var(--thx-radius);
	overflow: hidden;
	box-shadow: var(--thx-shadow);
	transition: var(--thx-transition);
	display: flex;
	flex-direction: column;
}

.thx-book-card:hover {
	transform: translateY(-4px);
	box-shadow: var(--thx-shadow-md);
	border-color: var(--thx-border-hover);
}

.thx-book-cover-wrap {
	position: relative;
	height: 240px;
	background: #f1f5f9;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
}

.thx-book-cover {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: var(--thx-transition);
}

.thx-book-card:hover .thx-book-cover {
	transform: scale(1.03);
}

.thx-book-cover-placeholder {
	font-size: 3.5rem;
	color: #94a3b8;
}

.thx-badge-toc {
	position: absolute;
	top: 12px;
	right: 12px;
	background: rgba(16, 185, 129, 0.95);
	color: #ffffff;
	padding: 4px 10px;
	font-size: 0.75rem;
	font-weight: 700;
	border-radius: 9999px;
	backdrop-filter: blur(4px);
	box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.thx-book-details {
	padding: 1.25rem;
	display: flex;
	flex-direction: column;
	flex-grow: 1;
}

.thx-book-title {
	margin: 0 0 0.5rem 0;
	font-size: 1.15rem;
	font-weight: 700;
	line-height: 1.4;
}

.thx-book-title a {
	color: var(--thx-primary);
	text-decoration: none;
	transition: var(--thx-transition);
}

.thx-book-title a:hover {
	color: var(--thx-primary-hover);
	text-decoration: underline;
}

.thx-book-meta-author {
	font-size: 0.875rem;
	color: var(--thx-text-muted);
	margin-bottom: 0.35rem;
}

.thx-book-meta-pages {
	font-size: 0.825rem;
	color: var(--thx-secondary);
	font-weight: 600;
	margin-bottom: 1.25rem;
}

.thx-book-card-actions {
	margin-top: auto;
	display: flex;
	gap: 0.5rem;
}

.thx-btn-view-toc {
	flex: 1;
	background: var(--thx-primary);
	color: #ffffff !important;
	text-align: center;
	padding: 0.65rem 1rem;
	font-size: 0.9rem;
	font-weight: 600;
	border-radius: var(--thx-radius-sm);
	text-decoration: none !important;
	transition: var(--thx-transition);
	display: inline-block;
}

.thx-btn-view-toc:hover {
	background: var(--thx-primary-hover);
	transform: translateY(-1px);
}

.thx-btn-view-pdf {
	background: #fee2e2;
	color: #dc2626 !important;
	border: 1px solid #fecaca;
	padding: 0.65rem 0.85rem;
	font-size: 0.85rem;
	font-weight: 700;
	border-radius: var(--thx-radius-sm);
	text-decoration: none !important;
	transition: var(--thx-transition);
}

.thx-btn-view-pdf:hover {
	background: #fecaca;
	color: #991b1b !important;
}

/* ==========================================================================
   2. KHÁM PHÁ MỤC LỤC & SỐ TRANG (EXPLORER & SINGLE BOOK)
   ========================================================================== */

.thx-book-toc-explorer {
	max-width: 1100px;
	margin: 2rem auto;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	color: var(--thx-text);
}

/* Header Bar */
.thx-toc-header-bar {
	background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
	color: #ffffff;
	border-radius: var(--thx-radius-lg);
	padding: 2rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1.5rem;
	margin-bottom: 1.75rem;
	box-shadow: var(--thx-shadow-md);
}

.thx-toc-tag {
	display: inline-block;
	background: rgba(255, 255, 255, 0.18);
	color: #dbeafe;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.05em;
	padding: 4px 10px;
	border-radius: 9999px;
	margin-bottom: 0.65rem;
	text-transform: uppercase;
}

.thx-toc-book-heading {
	margin: 0 0 0.5rem 0;
	font-size: 1.85rem;
	font-weight: 800;
	color: #ffffff;
	line-height: 1.3;
}

.thx-toc-book-meta {
	margin: 0;
	font-size: 0.95rem;
	color: #e2e8f0;
}

.thx-toc-book-meta strong {
	color: #ffffff;
}

.thx-toc-clb-badge {
	background: rgba(255, 255, 255, 0.12);
	border: 1px solid rgba(255, 255, 255, 0.25);
	padding: 1rem 1.25rem;
	border-radius: var(--thx-radius);
	text-align: center;
	min-width: 200px;
	backdrop-filter: blur(4px);
}

.thx-toc-clb-badge span {
	display: block;
	font-size: 0.95rem;
	font-weight: 700;
	color: #a7f3d0;
	margin-bottom: 0.35rem;
}

.thx-link-event {
	color: #ffffff !important;
	font-size: 0.85rem;
	font-weight: 600;
	text-decoration: underline !important;
	transition: var(--thx-transition);
}

.thx-link-event:hover {
	color: #fef08a !important;
}

/* Search & Jump Section */
.thx-toc-search-container {
	background: var(--thx-card-bg);
	border: 1px solid var(--thx-border);
	border-radius: var(--thx-radius);
	padding: 1.5rem;
	margin-bottom: 1.5rem;
	box-shadow: var(--thx-shadow);
}

.thx-search-split {
	display: grid;
	grid-template-columns: 1fr 1.4fr;
	gap: 1.5rem;
}

.thx-page-jump-box label,
.thx-keyword-search-box label {
	display: block;
	font-size: 0.875rem;
	font-weight: 700;
	color: var(--thx-text);
	margin-bottom: 0.5rem;
}

.thx-input-group {
	display: flex;
	gap: 0.5rem;
}

.thx-input-group input {
	flex: 1;
	padding: 0.75rem 1rem;
	border: 1.5px solid var(--thx-border);
	border-radius: var(--thx-radius-sm);
	font-size: 0.95rem;
	outline: none;
	transition: var(--thx-transition);
	background: #ffffff;
}

.thx-input-group input:focus {
	border-color: var(--thx-primary);
	box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

.thx-btn-primary {
	background: var(--thx-primary);
	color: #ffffff;
	border: none;
	padding: 0.75rem 1.25rem;
	font-size: 0.9rem;
	font-weight: 700;
	border-radius: var(--thx-radius-sm);
	cursor: pointer;
	transition: var(--thx-transition);
	white-space: nowrap;
}

.thx-btn-primary:hover {
	background: var(--thx-primary-hover);
}

.thx-btn-secondary {
	background: var(--thx-secondary);
	color: #ffffff;
	border: none;
	padding: 0.75rem 1.25rem;
	font-size: 0.9rem;
	font-weight: 700;
	border-radius: var(--thx-radius-sm);
	cursor: pointer;
	transition: var(--thx-transition);
	white-space: nowrap;
}

.thx-btn-secondary:hover {
	background: #047857;
}

/* Live Result Card */
.thx-toc-highlight-card {
	background: #f0fdf4;
	border: 2px solid #86efac;
	border-radius: var(--thx-radius);
	padding: 1.5rem;
	margin-bottom: 1.75rem;
	box-shadow: var(--thx-shadow-md);
	animation: thxSlideDown 0.3s ease;
}

@keyframes thxSlideDown {
	from {
		opacity: 0;
		transform: translateY(-8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.thx-live-result-header {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 1rem;
	margin-bottom: 0.75rem;
	flex-wrap: wrap;
}

.thx-live-result-title {
	font-size: 1.25rem;
	font-weight: 800;
	color: #14532d;
	margin: 0;
	line-height: 1.35;
}

.thx-live-badges {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex-wrap: wrap;
}

.thx-badge-live-page {
	background: #15803d;
	color: #ffffff;
	font-size: 0.8rem;
	font-weight: 700;
	padding: 4px 10px;
	border-radius: 9999px;
}

.thx-badge-live-habit {
	background: #f59e0b;
	color: #ffffff;
	font-size: 0.8rem;
	font-weight: 700;
	padding: 4px 10px;
	border-radius: 9999px;
}

.thx-live-breadcrumb {
	font-size: 0.825rem;
	color: #166534;
	background: rgba(255, 255, 255, 0.7);
	padding: 6px 12px;
	border-radius: 6px;
	margin-bottom: 1rem;
	border-left: 3px solid #16a34a;
}

.thx-live-summary {
	background: #ffffff;
	border: 1px solid #bbf7d0;
	border-radius: var(--thx-radius-sm);
	padding: 1rem 1.25rem;
	margin-bottom: 1rem;
	color: #1e293b;
	line-height: 1.6;
	font-size: 0.95rem;
}

.thx-live-summary strong {
	color: #166534;
	display: block;
	margin-bottom: 0.35rem;
}

.thx-live-keywords {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	flex-wrap: wrap;
	margin-bottom: 1.25rem;
}

.thx-live-keywords-label {
	font-size: 0.8rem;
	font-weight: 700;
	color: #166534;
}

.thx-live-actions {
	display: flex;
	gap: 0.75rem;
	align-items: center;
}

.thx-btn-locate {
	background: #16a34a;
	color: #ffffff;
	border: none;
	padding: 0.6rem 1.1rem;
	font-size: 0.875rem;
	font-weight: 700;
	border-radius: var(--thx-radius-sm);
	cursor: pointer;
	transition: var(--thx-transition);
}

.thx-btn-locate:hover {
	background: #15803d;
}

.thx-btn-close-result {
	background: transparent;
	border: 1px solid #86efac;
	color: #166534;
	padding: 0.6rem 0.9rem;
	font-size: 0.85rem;
	font-weight: 600;
	border-radius: var(--thx-radius-sm);
	cursor: pointer;
	transition: var(--thx-transition);
}

.thx-btn-close-result:hover {
	background: #dcfce7;
}

/* Multi-result Search List */
.thx-search-results-list {
	margin-top: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	max-height: 480px;
	overflow-y: auto;
	padding-right: 6px;
}

.thx-search-result-item {
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-radius: var(--thx-radius-sm);
	padding: 0.85rem 1rem;
	cursor: pointer;
	transition: var(--thx-transition);
}

.thx-search-result-item:hover {
	border-color: var(--thx-secondary);
	box-shadow: var(--thx-shadow);
	transform: translateX(4px);
}

.thx-search-item-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 0.35rem;
}

.thx-search-item-title {
	font-weight: 700;
	color: var(--thx-primary);
	font-size: 0.95rem;
}

.thx-search-item-pages {
	font-size: 0.75rem;
	font-weight: 700;
	background: #eff6ff;
	color: #1d4ed8;
	padding: 2px 8px;
	border-radius: 9999px;
}

.thx-search-item-snippet {
	font-size: 0.85rem;
	color: var(--thx-text-muted);
	line-height: 1.45;
}

/* Habit Shortcuts */
.thx-habits-shortcuts {
	background: var(--thx-card-bg);
	border: 1px solid var(--thx-border);
	border-radius: var(--thx-radius);
	padding: 1rem 1.25rem;
	margin-bottom: 1.75rem;
	box-shadow: var(--thx-shadow);
	display: flex;
	align-items: center;
	gap: 1rem;
	flex-wrap: wrap;
}

.thx-habits-label {
	font-size: 0.875rem;
	font-weight: 700;
	color: var(--thx-text);
	white-space: nowrap;
}

.thx-habits-buttons {
	display: flex;
	gap: 0.5rem;
	flex-wrap: wrap;
	flex: 1;
}

.thx-habit-pill {
	background: var(--thx-bg);
	border: 1px solid var(--thx-border);
	color: var(--thx-text);
	font-size: 0.8rem;
	font-weight: 600;
	padding: 6px 12px;
	border-radius: 9999px;
	cursor: pointer;
	transition: var(--thx-transition);
	white-space: nowrap;
}

.thx-habit-pill:hover,
.thx-habit-pill.active {
	background: var(--thx-primary);
	color: #ffffff;
	border-color: var(--thx-primary);
	transform: translateY(-1px);
}

/* TOC Tree Section */
.thx-toc-tree-wrap {
	background: var(--thx-card-bg);
	border: 1px solid var(--thx-border);
	border-radius: var(--thx-radius);
	box-shadow: var(--thx-shadow);
	overflow: hidden;
}

.thx-toc-tree-header {
	background: #f8fafc;
	border-bottom: 1px solid var(--thx-border);
	padding: 1.25rem 1.5rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	flex-wrap: wrap;
	gap: 1rem;
}

.thx-toc-tree-header h3 {
	margin: 0;
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--thx-text);
}

.thx-toc-tree-toggle {
	display: flex;
	gap: 0.75rem;
}

.thx-btn-text {
	background: transparent;
	border: none;
	color: var(--thx-primary);
	font-size: 0.85rem;
	font-weight: 700;
	cursor: pointer;
	padding: 4px 8px;
	border-radius: 4px;
	transition: var(--thx-transition);
}

.thx-btn-text:hover {
	background: #eff6ff;
	text-decoration: underline;
}

/* TOC List & Items */
.thx-toc-list {
	padding: 0.5rem 0;
}

.thx-toc-item {
	border-bottom: 1px solid #f1f5f9;
	transition: background-color 0.2s ease;
}

.thx-toc-item:last-child {
	border-bottom: none;
}

.thx-toc-item-header {
	padding: 0.85rem 1.5rem;
	display: flex;
	justify-content: space-between;
	align-items: center;
	cursor: pointer;
	gap: 1rem;
	user-select: none;
	transition: var(--thx-transition);
}

.thx-toc-item-header:hover {
	background-color: #f8fafc;
}

.thx-toc-item-title-wrap {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	flex: 1;
}

.thx-toc-toggle-icon {
	display: inline-block;
	font-size: 0.7rem;
	color: #94a3b8;
	transition: transform 0.25s ease;
	width: 14px;
	text-align: center;
}

.thx-toc-item.is-open > .thx-toc-item-header .thx-toc-toggle-icon {
	transform: rotate(90deg);
	color: var(--thx-primary);
}

.thx-toc-title-text {
	font-size: 0.95rem;
	color: var(--thx-text);
	line-height: 1.4;
}

/* Level styling */
.thx-level-chapter > .thx-toc-item-header {
	background: #f8fafc;
	border-left: 4px solid var(--thx-primary);
	padding-top: 1.1rem;
	padding-bottom: 1.1rem;
}

.thx-level-chapter .thx-toc-title-text {
	font-size: 1.05rem;
	font-weight: 800;
	color: var(--thx-primary);
	text-transform: uppercase;
	letter-spacing: 0.02em;
}

.thx-level-section > .thx-toc-item-header {
	border-left: 3px solid var(--thx-secondary);
	padding-left: 2rem;
}

.thx-level-section .thx-toc-title-text {
	font-weight: 700;
	color: #0f172a;
}

.thx-level-subsection > .thx-toc-item-header {
	padding-left: 2.75rem;
}

.thx-level-subsection .thx-toc-title-text {
	font-weight: 600;
	color: #334155;
}

.thx-level-item > .thx-toc-item-header {
	padding-left: 3.5rem;
}

.thx-level-item .thx-toc-title-text {
	font-weight: 500;
	color: #475569;
}

/* Badges & Pills */
.thx-badge-habit {
	background: #fef3c7;
	color: #b45309;
	font-size: 0.72rem;
	font-weight: 700;
	padding: 2px 8px;
	border-radius: 9999px;
	white-space: nowrap;
}

.thx-toc-page-pill {
	background: #f1f5f9;
	color: #475569;
	font-size: 0.775rem;
	font-weight: 700;
	padding: 4px 10px;
	border-radius: 9999px;
	white-space: nowrap;
	border: 1px solid #e2e8f0;
	transition: var(--thx-transition);
}

.thx-toc-page-pill:hover {
	background: #eff6ff;
	color: var(--thx-primary);
	border-color: #bfdbfe;
	transform: scale(1.04);
}

/* Item Body (Collapsible) */
.thx-toc-item-body {
	padding: 1rem 1.5rem 1.25rem 3.5rem;
	background: #fafafa;
	border-top: 1px solid #f1f5f9;
}

.thx-level-chapter > .thx-toc-item-body {
	padding-left: 2rem;
}
.thx-level-section > .thx-toc-item-body {
	padding-left: 2.75rem;
}
.thx-level-subsection > .thx-toc-item-body {
	padding-left: 3.25rem;
}

.thx-toc-summary-box {
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-left: 3px solid var(--thx-secondary);
	border-radius: var(--thx-radius-sm);
	padding: 0.85rem 1.15rem;
	margin-bottom: 0.85rem;
}

.thx-toc-summary-box strong {
	display: block;
	font-size: 0.85rem;
	color: var(--thx-secondary);
	margin-bottom: 0.35rem;
}

.thx-toc-summary-box p {
	margin: 0;
	font-size: 0.9rem;
	line-height: 1.55;
	color: #334155;
}

.thx-toc-keywords-box {
	margin-bottom: 0.75rem;
}

.thx-toc-keywords-box strong {
	display: inline-block;
	font-size: 0.8rem;
	color: var(--thx-text-muted);
	margin-right: 0.5rem;
}

.thx-kw-tags {
	display: inline-flex;
	gap: 0.4rem;
	flex-wrap: wrap;
}

.thx-kw-tag {
	background: #f1f5f9;
	color: #475569;
	font-size: 0.75rem;
	padding: 2px 8px;
	border-radius: 4px;
	border: 1px solid #e2e8f0;
}

.thx-toc-breadcrumb-trail {
	font-size: 0.75rem;
	color: #94a3b8;
}

/* Glowing Pulse Animation when locating an item */
.thx-toc-highlight-pulse {
	animation: thxGlow 2.5s ease-out;
}

@keyframes thxGlow {
	0% {
		background-color: #fef08a;
		box-shadow: 0 0 15px rgba(234, 179, 8, 0.6);
	}
	50% {
		background-color: #fef9c3;
		box-shadow: 0 0 8px rgba(234, 179, 8, 0.3);
	}
	100% {
		background-color: transparent;
		box-shadow: none;
	}
}

/* ==========================================================================
   3. RESPONSIVE DESIGN (MOBILE & TABLETS)
   ========================================================================== */

@media (max-width: 860px) {
	.thx-toc-header-bar {
		flex-direction: column;
		align-items: flex-start;
		padding: 1.5rem;
	}
	.thx-toc-clb-badge {
		width: 100%;
		text-align: left;
	}
	.thx-search-split {
		grid-template-columns: 1fr;
		gap: 1.25rem;
	}
}

@media (max-width: 640px) {
	.thx-lib-title {
		font-size: 1.6rem;
	}
	.thx-toc-book-heading {
		font-size: 1.4rem;
	}
	.thx-input-group {
		flex-direction: column;
	}
	.thx-btn-primary,
	.thx-btn-secondary {
		width: 100%;
	}
	.thx-level-section > .thx-toc-item-header {
		padding-left: 1.25rem;
	}
	.thx-level-subsection > .thx-toc-item-header {
		padding-left: 1.5rem;
	}
	.thx-level-item > .thx-toc-item-header {
		padding-left: 1.75rem;
	}
	.thx-toc-item-body {
		padding-left: 1.5rem;
	}
}
