/* 
 * Responsive Styles for YeuTruyen
 * Mobile Menu – Right Drawer
 */

/* ============================================
   TABLET (768px - 991px)
   ============================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
  .header-search {
    max-width: 280px;
    margin: 0 12px;
  }

  .header-btn-login,
  .header-btn-register {
    padding: 7px 12px;
    font-size: 12px;
  }
}

/* ============================================
   MOBILE (max-width: 767px)
   ============================================ */
@media (max-width: 767.98px) {

  /* ----- Header Top ----- */
  .header-top {
    padding: 10px 0;
  }

  .header-logo-text {
    font-size: 20px;
  }

  /* Ẩn nút desktop */
  .header-btn-login,
  .header-btn-register {
    display: none;
  }

  /* ----- Hamburger Button ----- */
  .header-mobile-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(6px);
    position: relative;
    z-index: 1060;
  }

  .header-mobile-toggle.is-open {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(255, 255, 255, 0.5);
  }

  /* ----- Overlay Backdrop ----- */
  .mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1055;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .mobile-nav-overlay.show {
    display: block;
    opacity: 1;
  }

  /* ----- Nav Drawer (Right Slide) ----- */
  .header-nav {
    position: fixed;
    top: 0;
    /* JS sẽ override bằng chiều cao thực của site-header */
    right: -100%;
    width: 300px;
    height: 100dvh;
    /* JS sẽ override */
    overflow-y: auto;
    z-index: 1058;
    background: linear-gradient(160deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-dark) 100%);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.35);
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: block !important;
    padding-bottom: 32px;
  }

  .header-nav.open {
    right: 0;
  }

  .header-nav>.container {
    max-width: 100%;
    padding: 0;
  }

  /* ----- Search inside drawer ----- */
  .header-mobile-search-wrap {
    padding: 14px 16px 10px;
  }

  .header-mobile-search-wrap form {
    position: relative;
  }

  .header-mobile-search-wrap input[type="text"] {
    width: 100%;
    padding: 11px 18px 11px 40px;
    border-radius: 12px;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 13px;
    font-family: inherit;
    transition: border-color 0.2s ease, background 0.2s ease;
  }

  .header-mobile-search-wrap input[type="text"]:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.4);
  }

  .header-mobile-search-wrap input::placeholder {
    color: rgba(255, 255, 255, 0.5);
  }

  .header-mobile-search-wrap .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
    pointer-events: none;
  }

  /* ----- Nav List ----- */
  .header-nav-list {
    flex-direction: column;
    padding: 10px 12px;
    gap: 8px;
  }

  .header-nav-item {
    width: 100%;
  }

  /* Card style links */
  .header-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.88);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
    white-space: normal;
  }

  .header-nav-link:hover,
  .header-nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.2);
  }

  /* Active left bar */
  .header-nav-link.active {
    background: rgba(255, 209, 102, 0.15);
    border-color: rgba(255, 209, 102, 0.3);
    color: #ffd166;
  }

  /* Icon bubble */
  .header-nav-link>i:first-child {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.13);
    border-radius: 9px;
    font-size: 13px;
    flex-shrink: 0;
    transition: background 0.2s ease;
  }

  .header-nav-link.active>i:first-child {
    background: rgba(255, 209, 102, 0.25);
    color: #ffd166;
  }

  /* Chevron */
  .header-nav-link .fa-chevron-down {
    margin-left: auto;
    font-size: 11px !important;
    transition: transform 0.3s ease;
    color: rgba(255, 255, 255, 0.45);
    width: auto !important;
    height: auto !important;
    background: none !important;
    border-radius: 0 !important;
  }

  .header-nav-item.dropdown-open>.header-nav-link .fa-chevron-down {
    transform: rotate(180deg);
    color: #ffd166;
  }

  /* ----- Dropdown "Thể loại" ----- */
  .header-dropdown {
    position: static;
    min-width: 100%;
    opacity: 1;
    visibility: hidden;
    transform: none;
    box-shadow: none;
    padding: 0 4px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1),
      padding 0.2s ease,
      visibility 0s 0.38s;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 0 0 12px 12px;
    margin-top: -6px;
    display: block;
  }

  .header-dropdown.open {
    visibility: visible;
    max-height: 600px;
    padding: 10px 4px 12px;
    transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1),
      padding 0.2s ease,
      visibility 0s 0s;
  }

  /* Disable hover on mobile */
  .header-nav-item:hover .header-dropdown {
    visibility: hidden;
    max-height: 0;
    padding: 0 4px;
  }

  .header-nav-item .header-dropdown.open {
    visibility: visible;
    max-height: 600px;
    padding: 10px 4px 12px;
  }

  .header-dropdown-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
  }

  .header-dropdown-link {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 10px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.07);
    color: rgba(255, 255, 255, 0.82);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.18s ease;
  }

  .header-dropdown-link:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
  }

  .header-dropdown-link i {
    color: #ffd166;
    width: 14px;
    text-align: center;
    font-size: 11px;
  }

  /* ----- User action row inside drawer ----- */
  .mobile-nav-user-row {
    display: flex !important;
    gap: 8px;
    padding: 12px 12px 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    margin-top: 4px;
  }

  .mobile-nav-user-row .header-btn-login,
  .mobile-nav-user-row .header-btn-register {
    display: flex !important;
    flex: 1;
    justify-content: center;
    border-radius: 12px;
    padding: 11px 12px;
    font-size: 13px;
    font-weight: 600;
    gap: 7px;
  }

  .mobile-nav-user-row .header-btn-login {
    background: rgba(255, 255, 255, 0.12);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    color: #fff;
  }

  .mobile-nav-user-row .header-btn-register {
    background: #fff;
    color: var(--primary);
    border: none;
  }
}

/* ============================================
   SMALL MOBILE (max-width: 480px)
   ============================================ */
@media (max-width: 479.98px) {
  .header-nav {
    width: 285px;
  }

  .header-logo-text {
    font-size: 18px;
  }

  .header-logo-icon {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .header-dropdown-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ============================================
   RANKING SECTION – MOBILE FIXES
   ============================================ */
@media (max-width: 767.98px) {

  /* Prevent ranking list from overflowing viewport */
  .ranking-main-section {
    overflow: hidden;
  }

  .ranking-main-body {
    overflow: hidden;
  }

  .ranking-list {
    overflow: hidden;
  }

  /* Each ranking item must clip its content */
  .ranking-item {
    overflow: hidden;
    min-width: 0;
  }

  /* Info box must truncate, not push layout */
  .ranking-info {
    overflow: hidden;
    min-width: 0;
    flex: 1;
  }

  /* Title ellipsis  */
  .ranking-title {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* Section tabs: allow scroll if needed */
  .section-tab-container {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .section-tab-container::-webkit-scrollbar {
    display: none;
  }

  .section-tab-btn {
    white-space: nowrap;
  }
}

/* ============================================
   STORY DETAIL PAGE – MOBILE FIXES
   ============================================ */
@media (max-width: 767.98px) {

  /* Section padding nhỏ lại */
  .story-detail-section {
    padding: 16px !important;
    border-radius: 12px;
    margin-top: 12px;
  }

  /* Layout: ảnh trên, info dưới */
  .story-info-wrapper {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
  }

  /* Ảnh bìa to hơn */
  .story-cover-container {
    width: 200px;
  }

  /* Rating overlay gọn lại */
  .story-cover-rating {
    padding: 5px 6px;
    gap: 2px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .story-cover-rating i {
    font-size: 10px;
  }

  .story-cover-rating span {
    font-size: 11px;
    font-weight: 700;
  }

  /* Ẩn text "(x đánh giá)" cho gọn — chỉ giữ số điểm */
  .story-cover-rating .rating-count {
    display: none;
  }

  /* Title không bị tràn */
  .story-detail-title {
    font-size: 18px !important;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: break-word;
    margin-bottom: 10px;
  }

  /* Tags căn giữa */
  .story-detail-tags {
    justify-content: center;
  }

  /* Ẩn meta mặc định trên mobile vì đã có stats bar mới */
  .story-detail-meta {
    display: none !important;
  }

  /* Nếu meta chỉ có 3 item thì item cuối chiếm full width */
  .story-detail-meta>.story-meta-item:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* Meta item: fix white-space */
  .story-meta-item {
    white-space: normal !important;
    font-size: 12px;
    padding: 9px 8px;
    flex: unset;
    text-align: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
  }

  .story-meta-item .meta-value {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  /* Description căn trái */
  .story-detail-section .story-description {
    text-align: left;
  }

  /* Action buttons */
  .story-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
  }

  .story-btn-read,
  .story-btn-chapter-list {
    flex: 1;
    min-width: 130px;
    border-radius: 50px;
    padding: 12px 10px;
    font-size: 13px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff !important;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
  }

  .story-btn-read i,
  .story-btn-chapter-list i {
    color: #fff !important;
    font-size: 12px;
  }

  .story-btn-bookmark {
    display: none !important;
  }

  /* Secondary actions */
  .story-secondary-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Chapter section */
  .chapter-list-section {
    margin-top: 16px;
    border-radius: 12px;
    padding: 16px !important;
  }

  .chapter-list-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .chapter-list-controls {
    width: 100%;
    gap: 6px;
  }

  .chapter-search {
    width: 100%;
  }

  .chapter-search-input {
    width: 100%;
  }

  .chapter-grid {
    grid-template-columns: 1fr !important;
    gap: 6px;
  }

  /* Related section */
  .related-section {
    padding: 16px !important;
    border-radius: 12px;
  }

  .completed-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px;
  }

  /* Related section mobile: 3 cột */
  .related-grid-5 {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* ===== MOBILE STATS BAR ===== */
  .mobile-stats-bar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    background: none;
    border: none;
    padding: 0;
    margin: 12px 0;
  }

  .mobile-stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: none;
    color: #4b5563;
    /* Darker gray for better visibility */
    font-size: 13px;
  }

  .mobile-stat-icon {
    font-size: 14px;
    color: #4b5563;
  }

  .mobile-stat-value {
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
  }
}

@media (max-width: 479.98px) {
  .story-cover-container {
    width: 180px;
  }

  .story-detail-title {
    font-size: 16px !important;
  }

  .completed-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Related section small: 2 cột */
  .related-grid-5 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}