/* Mobile-Friendly Layout - Comprehensive Mobile Optimizations */

/* Mobile First Approach - Base Mobile Styles */
@media (max-width: 768px) {

  /* === MOBILE VIEWPORT & CONTAINERS === */
  /* Hide all modals by default on mobile */
  .modal:not(.active) {
    display: none !important;
  }

  .modal.active {
    display: flex !important;
  }

  /* Aggressive navigation containment */
  .header .nav-links:not(.active) {
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  html {
    font-size: 14px;
    /* Smaller base font for mobile */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
  }

  body {
    min-height: 100vh;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
  }

  .container {
    width: 100%;
    max-width: 100%;
    padding: 0 1rem;
    margin: 0 auto;
  }

  /* === HEADER & NAVIGATION === */
  .header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1000 !important;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: 60px;
    display: block;
    /* Ensure header is visible */
    width: 100vw !important;
    box-sizing: border-box !important;
  }

  .navbar {
    height: 60px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .nav-brand .logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
  }

  .logo-icon {
    font-size: 1.5rem;
  }

  .logo-text {
    font-size: 1.1rem;
    font-weight: 600;
  }

  /* Mobile Navigation Menu */
  .nav-links {
    position: fixed !important;
    top: 60px !important;
    left: 0 !important;
    right: 0 !important;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    display: none !important;
    flex-direction: column !important;
    gap: 0.5rem;
    z-index: 999 !important;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
    flex-wrap: nowrap !important;
    width: 100vw !important;
    box-sizing: border-box !important;
  }

  .nav-links.active {
    display: flex;
  }

  /* Ensure nav-links is completely hidden when not active */
  .nav-links:not(.active) {
    display: none !important;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary);
    transition: background-color 0.2s ease;
    flex: none !important;
    min-width: auto !important;
    justify-content: flex-start !important;
  }

  .nav-link:hover {
    background-color: var(--bg-tertiary);
  }

  .nav-link i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
  }

  .nav-link span {
    font-size: 0.85rem;
    font-weight: 500;
    display: inline;
    /* Show text labels in small mobile navigation */
  }

  /* Mobile Menu Button */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease;
  }

  .mobile-menu-btn:hover {
    background-color: var(--bg-tertiary);
  }

  .mobile-menu-btn i {
    font-size: 1.2rem;
  }

  /* Navigation Actions */
  .nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease;
  }

  .theme-toggle:hover {
    background-color: var(--bg-tertiary);
  }

  /* Search on Mobile */
  .nav-search {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    z-index: 998;
    display: none;
  }

  .nav-search.active {
    display: block;
  }

  .search-box {
    position: relative;
    width: 100%;
  }

  .search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--bg-primary);
  }

  .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
  }

  /* Auth Links on Mobile */
  .auth-nav-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    width: 100% !important;
    justify-content: flex-start !important;
  }

  .auth-nav-links .btn {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  /* User Navigation Links on Mobile */
  .user-nav-links {
    width: 100% !important;
    justify-content: flex-start !important;
  }

  /* Dropdowns on Mobile */
  .nav-dropdown {
    width: 100%;
  }

  .nav-dropdown-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .nav-dropdown-btn span {
    display: inline;
    /* Ensure dropdown button text is visible */
  }

  .nav-dropdown-menu {
    position: static;
    opacity: 1;
    visibility: visible;
    display: none;
    margin-top: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
  }

  .nav-dropdown-menu.active {
    display: block;
  }

  .nav-dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
  }

  .nav-dropdown-menu a span {
    display: inline;
    /* Ensure dropdown menu text is visible */
  }

  .nav-dropdown-menu a:hover {
    background-color: var(--bg-tertiary);
  }

  /* === MAIN CONTENT === */
  .main-content {
    margin-top: 60px !important;
    min-height: calc(100vh - 60px);
    padding: 1rem 0;
    position: relative;
    z-index: 1;
    width: 100%;
    box-sizing: border-box;
  }

  .page {
    display: none;
    /* Hide all pages by default */
    padding: 0 1rem;
  }

  .page.active {
    display: block;
    /* Show only active page */
  }

  /* NOTE: Do NOT add #page-home { display: block } here.
     Navigation is controlled by JS via .active class only. */

  /* === HERO SECTION === */
  .hero {
    padding: 2rem 0;
    text-align: center;
  }

  .hero h1 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
    line-height: 1.3;
  }

  .hero p {
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
  }

  .hero-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
  }

  .hero-actions .btn {
    width: 100%;
    max-width: 280px;
    padding: 0.875rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 500;
  }

  /* === CARDS & GRIDS === */
  .card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
  }

  .card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
  }

  .card p {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .grid {
    display: grid;
    gap: 1rem;
  }

  .grid-cols-2 {
    grid-template-columns: 1fr;
  }

  .grid-cols-3 {
    grid-template-columns: 1fr;
  }

  .grid-cols-4 {
    grid-template-columns: 1fr;
  }

  /* === BUTTONS === */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    /* Touch-friendly */
  }

  .btn-primary {
    background: var(--primary);
    color: white;
  }

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

  .btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
  }

  .btn-outline:hover {
    background: var(--primary);
    color: white;
  }

  /* === FORMS === */
  .form-group {
    margin-bottom: 1rem;
  }

  .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
  }

  .form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 44px;
    /* Touch-friendly */
  }

  .form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.1);
  }

  /* === MODALS === */
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    /* Hide by default */
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
  }

  .modal.active {
    display: flex;
    /* Show when active */
  }

  .modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    width: 100%;
    padding: 1.5rem;
  }

  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
  }

  .modal-title {
    font-size: 1.1rem;
    font-weight: 600;
  }

  .modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .modal-close:hover {
    background: var(--bg-tertiary);
  }

  /* Ensure certificate modal is hidden by default */
  #certificate-modal {
    display: none;
  }

  #certificate-modal.active {
    display: flex;
  }

  /* === FOOTER === */
  .footer {
    background: var(--bg-tertiary);
    padding: 2rem 1rem 1rem;
    margin-top: 3rem;
  }

  .footer-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
  }

  .footer-section h4 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
  }

  .footer-section ul {
    list-style: none;
  }

  .footer-section li {
    margin-bottom: 0.5rem;
  }

  .footer-section a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
  }

  .footer-section a:hover {
    color: var(--primary);
  }

  .footer-bottom {
    text-align: center;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-tertiary);
  }
}

/* === SMALL MOBILE (≤480px) === */
@media (max-width: 480px) {

  html {
    font-size: 13px;
  }

  .container {
    padding: 0 0.75rem;
  }

  .navbar {
    padding: 0 0.75rem;
  }

  .page {
    padding: 0 0.75rem;
  }

  .hero h1 {
    font-size: 1.5rem;
  }

  .hero p {
    font-size: 0.9rem;
  }

  .card {
    padding: 1rem;
  }

  .modal-content {
    padding: 1rem;
  }

  /* Ensure certificate modal is hidden by default on small mobile */
  #certificate-modal {
    display: none;
  }

  #certificate-modal.active {
    display: flex;
  }

  .btn {
    padding: 0.625rem 1rem;
    font-size: 0.85rem;
  }

  .form-control {
    padding: 0.625rem 0.875rem;
    font-size: 0.85rem;
  }

  /* Touch-friendly adjustments */
  .btn,
  .form-control,
  .nav-link {
    min-height: 48px;
  }

  .mobile-menu-btn,
  .theme-toggle {
    width: 44px;
    height: 44px;
  }

  /* Ensure dropdown text is visible on small mobile */
  .nav-dropdown-btn span {
    display: inline;
  }

  .nav-dropdown-menu a span {
    display: inline;
  }
}

/* === LANDSCAPE MOBILE === */
@media (max-width: 768px) and (orientation: landscape) {
  .nav-links {
    max-height: 50vh;
  }

  .hero {
    padding: 1rem 0;
  }

  .hero h1 {
    font-size: 1.4rem;
  }
}

/* === ACCESSIBILITY === */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === HIGH CONTRAST === */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  .form-control {
    border-width: 2px;
  }

  .card {
    border-width: 2px;
  }
}

/* === TOUCH OPTIMIZATIONS === */
@media (hover: none) and (pointer: coarse) {

  .btn:hover,
  .nav-link:hover,
  .card:hover {
    transform: none;
  }

  .btn:active,
  .nav-link:active {
    transform: scale(0.98);
  }
}