/* ==========================================================================
   LIBRARY SECTION — Thư Viện Biểu Mẫu & Văn Bản Luật (landing page)
   Branding: Burgundy (#800020) & Gold (#D4AF37) — đồng bộ css/styles.css
   ========================================================================== */

/* Breadcrumb (SEO) — nhỏ, muted, nằm trên tiêu đề */
.library-breadcrumb {
  font-size: 13px;
  color: var(--text-muted-dark);
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.library-breadcrumb a {
  color: var(--primary-burgundy);
  font-weight: 500;
}
.library-breadcrumb .sep {
  color: var(--accent-gold-dark);
}

/* Tabs: Văn bản luật | Biểu mẫu */
.library-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 40px;
}
.library-tab-btn {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted-dark);
  background: var(--bg-light);
  border: 1.5px solid var(--border-light);
  border-radius: 999px;
  padding: 10px 24px;
  cursor: pointer;
  transition: var(--transition-fast);
}
.library-tab-btn:hover {
  border-color: var(--primary-burgundy);
  color: var(--primary-burgundy);
}
.library-tab-btn.active {
  background: var(--primary-burgundy);
  border-color: var(--primary-burgundy);
  color: var(--text-light);
}
.library-tab-count {
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-gold);
  color: var(--bg-dark);
  border-radius: 999px;
  padding: 1px 9px;
  margin-left: 6px;
}

/* Grid cards */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.library-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-light);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-md);
  padding: 22px 22px 20px;
  transition: var(--transition-smooth);
  height: 100%;
}
.library-card:hover {
  transform: translateY(-4px);
  border-color: rgba(128, 0, 32, 0.25);
  box-shadow: 0 14px 34px rgba(128, 0, 32, 0.10);
}

.library-card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.library-card-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: rgba(212, 175, 55, 0.14);
  color: var(--accent-gold-dark);
}
.library-card[data-kind="legal"] .library-card-icon {
  background: rgba(128, 0, 32, 0.08);
  color: var(--primary-burgundy);
}

.library-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 2px;
}
.library-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary-burgundy);
  background: rgba(128, 0, 32, 0.08);
  border: 1px solid rgba(128, 0, 32, 0.14);
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}

.library-card h3 {
  font-size: 16.5px;
  line-height: 1.4;
  color: var(--text-dark);
  font-weight: 700;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.library-card-desc {
  font-size: 14px;
  color: var(--text-muted-dark);
  line-height: 1.6;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.library-card-meta {
  font-size: 12.5px;
  color: var(--text-muted-dark);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
  margin-top: 2px;
}
.library-card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.library-card-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  background: var(--primary-burgundy);
  border-radius: 999px;
  padding: 9px 18px;
  transition: var(--transition-fast);
}
.library-card-btn:hover {
  background: var(--primary-burgundy-light);
}
.library-card-btn[data-kind="legal"] {
  background: var(--bg-dark);
}
.library-card-btn[data-kind="legal"]:hover {
  background: var(--bg-dark-alt);
}

/* Trạng thái rỗng / lỗi */
.library-empty,
.library-error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted-dark);
  font-size: 15px;
  background: var(--bg-light);
  border: 1px dashed var(--border-light);
  border-radius: var(--border-radius-md);
}
.library-error {
  color: var(--primary-burgundy);
}

/* ==========================================================================
   MODAL XEM TOÀN VĂN VĂN BẢN LUẬT (public viewer)
   ========================================================================== */
.legal-detail-overlay {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(15, 5, 7, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.legal-detail-dialog {
  background: #fff; border-radius: 12px;
  width: min(880px, 96vw);
  max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(15, 5, 7, 0.35);
}
.legal-detail-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light, #eee);
  background: var(--bg-light, #fff);
}
.legal-detail-title {
  flex: 1; font-weight: 700; font-size: 16px;
  color: var(--text-dark, #1f1416);
  word-break: break-word;
}
.legal-detail-close {
  flex: 0 0 auto;
  border: none; background: rgba(128, 0, 32, 0.08);
  color: var(--primary-burgundy, #800020);
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 16px; cursor: pointer;
  transition: var(--transition-fast, 0.15s);
}
.legal-detail-close:hover { background: var(--primary-burgundy, #800020); color: #fff; }
.legal-detail-body {
  flex: 1; overflow: auto; padding: 18px 20px;
  font-size: 14.5px; line-height: 1.75;
}
.legal-detail-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light, #eee);
  text-align: right;
}

/* Markdown văn bản luật — chuẩn như bản Word nguồn */
.legal-detail-md {
  font-family: var(--font-sans, 'Be Vietnam Pro', system-ui, sans-serif);
  color: var(--text-dark, #1f1416);
  word-break: break-word;
}
.legal-detail-md > :first-child { margin-top: 0; }
.legal-detail-md > :last-child { margin-bottom: 0; }
.legal-detail-md h1, .legal-detail-md h2, .legal-detail-md h3,
.legal-detail-md h4, .legal-detail-md h5, .legal-detail-md h6 {
  font-weight: 700; color: var(--primary-burgundy, #800020);
  line-height: 1.35; margin: 20px 0 8px;
}
.legal-detail-md h1 { font-size: 21px; border-bottom: 2px solid #f0e8e8; padding-bottom: 6px; }
.legal-detail-md h2 { font-size: 18px; }
.legal-detail-md h3 { font-size: 16px; }
.legal-detail-md h4, .legal-detail-md h5, .legal-detail-md h6 { font-size: 15px; }
.legal-detail-md p { margin: 8px 0; }
.legal-detail-md ul, .legal-detail-md ol { margin: 8px 0; padding-left: 24px; }
.legal-detail-md li { margin: 4px 0; }
.legal-detail-md blockquote {
  margin: 10px 0; padding: 6px 14px;
  border-left: 3px solid var(--accent-gold, #D4AF37);
  background: var(--bg-light-alt, #faf7f4);
  border-radius: 0 6px 6px 0;
}
.legal-detail-md hr { border: none; border-top: 1px solid #eee; margin: 18px 0; }
.legal-detail-md pre {
  background: var(--bg-light-alt, #faf7f4); border: 1px solid #eee;
  border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 13px; line-height: 1.6;
}
.legal-detail-md code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.92em;
}
.legal-detail-md :not(pre) > code {
  background: #f6f1ed; border-radius: 4px; padding: 1px 5px;
  color: var(--primary-burgundy, #800020);
}

/* Bảng markdown — border, header đậm, zebra, cuộn ngang trên mobile */
.md-table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  margin: 12px 0;
}
.md-table-wrap table { margin: 0; }
.legal-detail-md table {
  border-collapse: collapse; width: 100%; margin: 12px 0;
  font-size: 14px; line-height: 1.55;
}
.legal-detail-md th, .legal-detail-md td {
  border: 1px solid #d4c8c8; padding: 8px 12px;
  text-align: left; vertical-align: top;
}
.legal-detail-md thead th {
  background: #f0e8e8; color: #4d0012; font-weight: 700; white-space: nowrap;
}
.legal-detail-md tbody tr:nth-child(even) { background: #faf7f4; }
.legal-detail-md tbody tr:hover { background: #f6f1ed; }

@media (max-width: 640px) {
  .legal-detail-dialog { width: 100vw; max-height: 92vh; }
  .legal-detail-body { padding: 14px 14px; font-size: 14px; }
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
  .library-tabs {
    margin-bottom: 28px;
  }
  .library-tab-btn {
    flex: 1 1 auto;
    min-width: 140px;
    padding: 10px 14px;
  }
  .library-grid {
    grid-template-columns: 1fr; /* 1 cột mobile — không tràn ngang */
    gap: 14px;
  }
  .library-card {
    padding: 18px 16px;
  }
}

@media (max-width: 480px) {
  .library-card h3 {
    font-size: 15.5px;
  }
  .library-card-desc {
    -webkit-line-clamp: 3;
  }
}
