/* Mobile overrides for OneCreed (loaded only on small screens) */
/* Scope to public site components to avoid affecting admin panel */

/* Base mobile-safe tweaks */
@media (max-width: 920px) {
  *, *::before, *::after { box-sizing: border-box; }
  html,
  body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Header & navigation */
  .nav-container {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    position: relative;
    max-width: 100%;
    width: 100%;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  /* Guard against any stray horizontal overflow */
  .header, .container, .footer, .hero { overflow-x: hidden; }
  .hamburger {
    display: flex;
    /* Pin the hamburger to the far-right on mobile */
    position: absolute;
    right: max(20px, env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    grid-column: auto; /* layout-independent when absolutely positioned */
    z-index: 1001;
  }
  .nav-logo {
    grid-column: 1;
    justify-self: start;
    display: inline-flex;
    align-items: center;
  }
  .auth-buttons {
    display: none !important;
  }

  /* Slide-in menu (works with main-functional.js) */
  .nav-menu {
    display: flex;
    position: fixed;
    top: 0;
    right: -100%;
    height: 100dvh;
    width: min(88vw, 320px); /* slightly wider but responsive */
    background: rgba(16, 39, 31, 0.96);
    backdrop-filter: blur(18px);
    flex-direction: column;
    padding: 96px 20px 28px; /* tighter polish */
    gap: 14px;
    overflow-y: auto;
    overscroll-behavior: contain; /* prevent background scroll chaining */
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    transition: right 0.5s cubic-bezier(0.7, 0.2, 0.2, 1);
    z-index: 1000; /* keep above backdrop */
    box-shadow: -10px 0 30px -10px rgba(0, 0, 0, 0.5);
  }
  .nav-menu.open {
    right: 0;
  }
  /* Backdrop for slide-in menu (created by JS as .nav-backdrop) */
  .nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 999; /* under the menu */
  }
  .nav-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }
  .nav-menu .nav-link {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    padding: 8px 10px;
  }
  .nav-menu .mobile-auth {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .nav-menu .mobile-auth .btn {
    width: 100%;
    justify-content: center;
  }

  /* Compact mobile user icon with dropdown */
  .mobile-user {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
  }
  .mobile-user-trigger {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #fff;
    border-radius: 12px;
    padding: 8px 10px;
  }
  .mobile-user-trigger .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
  }
  .mobile-user-trigger .name {
    font-size: 14px;
    font-weight: 600;
    text-align: left;
  }
  .mobile-user-trigger .chevron {
    opacity: 0.85;
  }
  .mobile-user-trigger.open .chevron {
    transform: rotate(180deg);
    transition: transform 0.2s ease;
  }
  .mobile-user-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 8px;
  }
  .mobile-user-menu .menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 14px;
  }
  .mobile-user-menu .menu-item i {
    width: 18px;
    text-align: center;
  }
  .mobile-user-menu .menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
  }
  .mobile-user-menu .menu-item.danger {
    border-color: rgba(255, 99, 71, 0.45);
  }
  .mobile-user-menu .menu-item.danger:hover {
    background: rgba(255, 99, 71, 0.12);
  }
  .mobile-user-menu .menu-divider {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    margin: 4px 0;
  }
  body.nav-open {
    overflow: hidden;
  }

  /* Hero */
  .hero {
    min-height: auto;
    padding: 84px 0 48px; /* slightly tighter */
  }
  /* Improve mobile search appearance in hero */
  .hero .search-input-wrapper {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(17, 24, 39, 0.08);
    border-radius: 999px; /* more round */
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px) saturate(1.1);
    /* Keep inline layout like desktop */
    flex-direction: row;
  }
  .hero .search-input-wrapper:focus-within {
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
  }
  .hero .search-icon {
    left: 12px;
    color: var(--text-secondary);
    font-size: 16px;
  }
  .hero-content {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  .hero-text {
    text-align: left;
  }
  .hero-title {
    font-size: clamp(1.8rem, 6vw, 2.4rem);
  }
  .hero-subtitle {
    font-size: 15px;
    max-width: 100%;
  }
  .hero .search-box {
  max-width: none;
  width: 100%;
  }
  .hero .search-input {
    padding: 10px 10px 10px 38px;
    font-size: 14px;
    background: transparent;
    color: var(--text-primary);
  }
  .hero .search-button {
    /* Match desktop gradient style but smaller */
    background: linear-gradient(90deg, var(--accent-orange), #ffb14a);
    color: #1d2b23;
    padding: 12px 12px;
    min-height: 36px;
    font-size: 13px;
    border-radius: 0 999px 999px 0; /* more round */
  }
  .hero .search-button:hover {
    filter: brightness(1.03);
  }
  .hero .search-suggestions {
    border: 1px solid rgba(17, 24, 39, 0.08);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
  }
  /* Keep hero search fully visible and centered */
  .search-container, .search-box, .search-input-wrapper {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  /* Center category chips on mobile */
  .category-topics { width: 100%; margin-left: auto; margin-right: auto; }
  .category-tags { justify-content: center; }
}

@media (max-width: 768px) {
  /* Cards and grids */
  .articles-grid,
  .videos-grid,
  .audio-grid {
    grid-template-columns: 1fr !important;
  }

  /* Section headers */
  .section-header {
    gap: 12px;
    flex-wrap: wrap;
  }
  .section-title {
    font-size: 22px;
  }
  .category-filter {
    width: 100%;
  }
  .category-select {
    width: 100%;
  }

  /* Make category tabs horizontally scrollable on small screens */
  .categories-nav {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    scrollbar-width: thin;
    padding-bottom: 6px;
  }
  .categories-nav .category-tab {
    flex: 0 0 auto;
  }

  /* Newsletter */
  .newsletter-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
  }
  .newsletter-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .newsletter-input {
    width: 100%;
  }

  /* Keep hero search inline like desktop, just smaller */
  .hero .search-input-wrapper {
    flex-direction: row;
  }
  .hero .search-input {
    border-radius: 999px 0 0 999px; /* more round */
  }
  .hero .search-button {
    border-radius: 0 999px 999px 0; /* more round */
    justify-content: center;
  }

  /* Hero stats */
  .hero-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  /* Article page */
  .article-page-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .article-sidebar {
    order: 2;
  }
  .article-main {
    order: 1;
  }
  .article-hero {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .article-image-container img {
    width: 100%;
    height: auto;
    max-height: 320px;
    object-fit: cover;
  }

  /* Footer */
  .footer-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    text-align: left;
  }
  .footer-links {
    flex-wrap: wrap;
    gap: 12px;
  }
}

@media (max-width: 600px) {
  .hero {
    padding: 84px 0 40px;
  }
  .hero-badge {
    font-size: 13px;
    padding: 6px 12px;
  }
  .category-tags {
    gap: 10px;
  }

  /* Modals */
  .modal .modal-content {
    width: calc(100% - 32px);
    margin: 0 auto;
  }
}

@media (max-width: 480px) {
  /* Tighten spacing on very small screens */
  .header .navbar {
    padding: 10px 0;
  }
  .hero {
    padding: 72px 0 32px;
  }
  .hero-title {
    font-size: clamp(1.6rem, 7vw, 2rem);
  }
  .article-title {
    font-size: 1.5rem;
  }
  .hero-stats {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .container {
    padding: 0 14px; /* align content better on small screens */
  }
}
