/* style.css - Design System ấm áp kiểu app đọc sách, tối ưu cho người lớn tuổi trên Mobile/Tablet */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  /* Bảng màu sáng duy nhất - Ấm áp kiểu app đọc sách (kem/be + nâu cam) */
  --bg-main: #faf3e8;
  --bg-surface: #fffaf3;
  --bg-card: #fffaf3;
  --bg-hover: #f4e6d2;
  --bg-header: #fffaf3;

  --text-main: #3a2a1a;
  --text-sub: #6b5644;
  --text-muted: #9c8874;

  --accent-primary: #8b4513;       /* Nâu cam đậm */
  --accent-primary-hover: #6b3410;
  --accent-cyan: #8b4513;          /* Dùng chung tông nâu cam cho nhất quán */
  --accent-gold: #e8a33d;          /* Vàng cam - badge/active */
  --accent-emerald: #6f8f3f;
  --accent-glow: rgba(139, 69, 19, 0.12);

  --nav-bg: #3d2817;
  --nav-text: #f3e6d4;
  --nav-active: #f0b429;

  --border-color: #e6d6bd;
  --border-subtle: #d8c19a;

  --highlight-bg: #fde047;
  --highlight-text: #3a2a1a;

  --success-bg: #e6f0d8;
  --success-text: #3f5c1f;
  --error-bg: #fbe4e0;
  --error-text: #a13c2b;

  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-reading: 'Lora', Georgia, serif;

  --reader-size: 1.4rem;
  --reader-lh: 1.85;
  --header-height: 68px;
  --bottom-nav-height: 74px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

/* Reset & Base */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 106.25%; /* ~17px gốc, tăng nhẹ cỡ chữ toàn hệ thống */
}

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--accent-gold);
  border-radius: 10px;
}

/* TOP APP HEADER */
header.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 8px rgba(58, 42, 26, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--accent-primary);
  text-decoration: none;
}

.brand-logo .icon {
  font-size: 1.4rem;
}

/* DOC SELECTOR TRIGGER BUTTON (MOBILE & TABLET FRIENDLY) */
.doc-picker-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  color: var(--text-main);
  padding: 0.55rem 1rem;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  max-width: 320px;
  min-height: 48px;
  transition: all 0.2s ease;
}

.doc-picker-btn:hover, .doc-picker-btn:active {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.doc-picker-btn .doc-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-picker-btn .arrow-icon {
  font-size: 0.75rem;
  color: var(--text-sub);
}

/* HEADER ACTION BUTTONS */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  color: var(--text-main);
  min-width: 48px;
  height: 48px;
  padding: 0 0.6rem;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.icon-btn-round {
  border-radius: 50%;
  padding: 0;
  width: 48px;
}

.icon-btn .btn-label {
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Ẩn nhãn chữ trên nút khi màn hình hẹp (mobile), chỉ hiện icon để tiết kiệm chỗ */
@media (max-width: 640px) {
  .icon-btn .btn-label {
    display: none;
  }
  .icon-btn {
    min-width: 46px;
    padding: 0;
  }
}

/* CATEGORY SCROLL PILLS BAR */
.category-bar-wrapper {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 1rem;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.category-pills {
  display: inline-flex;
  gap: 0.5rem;
}

.cat-pill {
  background: var(--bg-main);
  border: 2px solid var(--border-color);
  color: var(--text-sub);
  padding: 0.5rem 1rem;
  border-radius: 24px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: all 0.2s ease;
}

.cat-pill:hover, .cat-pill:active {
  background: var(--bg-hover);
  color: var(--text-main);
}

.cat-pill.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  font-weight: 700;
}

/* HOME VIEW (Trang chủ) */
.home-view {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(var(--bottom-nav-height) + 1.5rem) 1rem;
}

.home-section-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-main);
  margin: 1.25rem 0 0.9rem 0;
}

.home-section-title:first-child {
  margin-top: 0;
}

.featured-row {
  display: flex;
  gap: 0.9rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.featured-card {
  flex: 0 0 auto;
  width: 165px;
  cursor: pointer;
}

.featured-cover {
  position: relative;
  width: 165px;
  height: 200px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  box-shadow: 0 8px 18px rgba(58, 42, 26, 0.18);
  margin-bottom: 0.6rem;
}

.featured-count-badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(58, 42, 26, 0.85);
  color: #ffe8b0;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
}

.featured-type-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: 0.2rem;
}

.featured-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.home-doc-list {
  margin-top: 0;
}

/* Khối icon màu tượng trưng theo loại văn bản (thay ảnh bìa) */
.doc-type-icon {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  color: #ffffff;
}

/* MAIN LAYOUT SPLIT CONTAINER */
.main-wrapper {
  display: flex;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  padding-bottom: var(--bottom-nav-height);
}

/* SIDEBAR TOC (TABLET/DESKTOP & MOBILE DRAWER) */
aside.sidebar-toc {
  width: 340px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - 57px);
  position: sticky;
  top: calc(var(--header-height) + 57px);
  overflow-y: auto;
  z-index: 80;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toc-title-header {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toc-nav-list {
  list-style: none;
  padding: 0.6rem;
}

.toc-nav-item {
  margin-bottom: 0.3rem;
}

.toc-nav-link {
  display: block;
  padding: 0.75rem 0.9rem;
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text-sub);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1.45;
  transition: all 0.2s ease;
}

.toc-nav-link:hover, .toc-nav-link:active {
  background: var(--bg-hover);
  color: var(--text-main);
}

.toc-nav-link.active {
  background: var(--accent-glow);
  color: var(--accent-primary);
  font-weight: 700;
  border-left: 4px solid var(--accent-primary);
}

.toc-lvl-2 {
  font-weight: 700;
  color: var(--text-main);
  margin-top: 0.75rem;
}

.toc-lvl-5 {
  padding-left: 1.1rem;
  font-size: 0.95rem;
}

/* READER PANEL */
main.reader-panel {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* SEARCH BAR CONTAINER */
.search-floating-bar {
  margin-bottom: 1.75rem;
  position: relative;
}

.search-input-card {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.5rem 1.1rem;
  gap: 0.6rem;
  box-shadow: 0 4px 14px rgba(58, 42, 26, 0.08);
  transition: all 0.2s ease;
}

.search-input-card:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input-card input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 1.05rem;
  padding: 0.5rem 0;
}

.search-input-card input::placeholder {
  color: var(--text-muted);
}

.search-scope-badge {
  background: var(--bg-main);
  color: var(--text-sub);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  outline: none;
  font-weight: 600;
}

/* SEARCH OVERLAY POPUP */
.search-popup-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  max-height: 440px;
  overflow-y: auto;
  box-shadow: 0 16px 36px rgba(58, 42, 26, 0.18);
  display: none;
  z-index: 120;
}

.search-popup-results.active {
  display: block;
}

.search-item-card {
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.2s ease;
}

.search-item-card:hover, .search-item-card:active {
  background: var(--bg-hover);
}

.search-doc-tag {
  display: inline-block;
  font-size: 0.78rem;
  background: var(--accent-glow);
  color: var(--accent-primary);
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.search-item-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-main);
  margin-bottom: 0.3rem;
}

.search-item-snippet {
  font-size: 0.92rem;
  color: var(--text-sub);
  line-height: 1.5;
}

/* DOCUMENT READER TYPOGRAPHY */
article.doc-reader-body {
  font-family: var(--font-reading);
  font-size: var(--reader-size);
  line-height: var(--reader-lh);
  color: var(--text-main);
  flex: 1;
}

.doc-cover-header {
  text-align: center;
  padding: 2rem 1.5rem;
  margin-bottom: 2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 6px 20px rgba(58, 42, 26, 0.08);
}

.doc-cover-header h1 {
  font-family: var(--font-ui);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.4;
  color: var(--text-main);
  margin-bottom: 1rem;
}

.doc-stats-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 0.8rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

.stat-pill {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-sub);
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
}

.stat-pill b {
  color: var(--accent-primary);
}

/* HTML CONTENT ELEMENTS */
.mab2 {
  margin-bottom: 1.4rem;
}

.mab2 p {
  text-align: left;
  margin-bottom: 0.85rem;
}

.doc-level-2 {
  margin-top: 2.5rem;
  margin-bottom: 1.4rem;
  text-align: center;
}

.doc-level-2 b {
  font-family: var(--font-ui);
  font-size: 1.25rem;
  text-transform: uppercase;
  color: var(--accent-primary);
  letter-spacing: 0.02em;
}

.doc-level-5 {
  margin-top: 1.75rem;
  margin-bottom: 0.85rem;
  scroll-margin-top: calc(var(--header-height) + 1rem);
}

.doc-level-5 b {
  font-family: var(--font-ui);
  font-size: 1.15rem;
  color: var(--text-main);
}

.doc-level-11 {
  padding-left: 0.9rem;
  margin-bottom: 0.85rem;
}

mark.highlight {
  background-color: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 0.12em 0.35em;
  border-radius: 3px;
  font-weight: 700;
}

/* PREV/NEXT ARTICLE NAVIGATION BAR */
.article-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.article-nav-btn {
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  color: var(--accent-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.75rem 1.1rem;
  border-radius: 24px;
  cursor: pointer;
  min-height: 48px;
  transition: all 0.2s ease;
}

.article-nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.article-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.article-nav-position {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-sub);
  white-space: nowrap;
}

/* MOBILE BOTTOM NAVIGATION BAR (NATIVE APP FEEL) */
nav.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--nav-bg);
  z-index: 110;
  justify-content: space-around;
  align-items: center;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
}

.nav-item-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  background: transparent;
  border: none;
  color: var(--nav-text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  height: 100%;
  transition: color 0.2s ease;
}

.nav-item-btn .nav-icon {
  font-size: 1.4rem;
}

.nav-item-btn.active, .nav-item-btn:active {
  color: var(--nav-active);
  font-weight: 700;
}

/* MODAL SHEET OVERLAY FOR DOCUMENT PICKER (MOBILE & TABLET) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(58, 42, 26, 0.45);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -10px 32px rgba(58, 42, 26, 0.25);
}

.modal-overlay.active .modal-sheet {
  transform: translateY(0);
}

.modal-sheet-header {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-sheet-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-sheet-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.doc-list-grid {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.doc-card-item {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}

.doc-card-item:hover, .doc-card-item:active {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.doc-card-item.selected {
  border-color: var(--accent-primary);
  background: var(--accent-glow);
}

.doc-card-body {
  flex: 1;
  min-width: 0;
}

.doc-card-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  background: var(--accent-glow);
  color: var(--accent-primary);
  margin-bottom: 0.35rem;
}

.doc-card-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--text-main);
  margin-bottom: 0.45rem;
}

.doc-card-meta {
  font-size: 0.85rem;
  color: var(--text-sub);
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

/* RESPONSIVE BREAKPOINTS (MOBILE & TABLET) */
@media (max-width: 900px) {
  nav.mobile-bottom-nav {
    display: flex;
  }

  aside.sidebar-toc {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(58, 42, 26, 0.25);
  }

  aside.sidebar-toc.open {
    transform: translateX(0);
  }

  main.reader-panel {
    padding: 1.25rem 1rem;
  }

  .doc-picker-btn {
    max-width: 170px;
  }
}

@media (min-width: 901px) {
  .modal-overlay {
    align-items: center;
  }
  .modal-sheet {
    border-radius: 20px;
    max-height: 75vh;
  }
}

/* AUTH PAGES (LOGIN / REGISTER) */
.auth-page-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: var(--bg-main);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 2.25rem;
  box-shadow: 0 12px 32px rgba(58, 42, 26, 0.1);
}

.auth-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-sub);
  font-size: 1rem;
  margin-bottom: 1.75rem;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.form-control {
  width: 100%;
  min-height: 52px;
  padding: 0.75rem 1rem;
  font-size: 1.05rem;
  font-family: var(--font-ui);
  color: var(--text-main);
  background: var(--bg-main);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: all 0.2s ease;
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  width: 100%;
  min-height: 54px;
  background: var(--accent-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: background 0.2s ease;
}

.btn-primary:hover, .btn-primary:active {
  background: var(--accent-primary-hover);
}

.alert-message {
  display: none;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  text-align: center;
}

.alert-message.success {
  background: var(--success-bg);
  color: var(--success-text);
}

.alert-message.error {
  background: var(--error-bg);
  color: var(--error-text);
}
