/* ==========================================================================
   TNPSC Portal - Responsive CSS
   Viewport Adaptations for 360px, 390px, 430px, 768px, 1024px, 1366px, 1920px
   Touch targets, Mobile Bottom Navigation, Drawer, and Grid reflows
   ========================================================================== */

/* --------------------------------------------------------------------------
   Desktop & Large Screens (1024px and above)
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
  .site-header {
    height: var(--header-height);
  }
}

@media (min-width: 1440px) {
  :root {
    --max-width: 1320px;
  }
}

/* --------------------------------------------------------------------------
   Tablets and Medium Displays (Below 992px)
   -------------------------------------------------------------------------- */
@media (max-width: 991px) {
  .main-nav {
    display: none; /* Collapses into mobile drawer */
  }

  .mobile-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
  }

  .test-interface-layout {
    grid-template-columns: 1fr;
  }

  .palette-card {
    order: -1;
    margin-bottom: 1.5rem;
  }
}

/* --------------------------------------------------------------------------
   Mobile App Redesign (Below 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  body {
    padding-bottom: 70px; /* Safe offset for mobile bottom navigation */
  }

  .topbar {
    display: none; /* Clean uncluttered mobile header */
  }

  .site-header {
    box-shadow: 0 1px 4px rgba(18, 59, 104, 0.08);
  }

  .header-inner {
    height: 60px;
  }

  .brand-emblem {
    width: 36px;
    height: 36px;
  }

  .brand-emblem svg {
    width: 20px;
    height: 20px;
  }

  .site-brand {
    gap: 0.5rem;
  }

  .brand-title {
    font-size: 1.05rem;
    line-height: 1.15;
  }

  .brand-tagline {
    display: block;
    font-size: 0.6875rem;
    color: var(--secondary);
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
  }

  .btn-header-cta {
    display: none; /* Replaced by bottom nav / drawer */
  }

  /* Show Bottom App Bar */
  .mobile-bottom-nav {
    display: block;
  }

  /* Typography Adjustments */
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.1rem; }

  .page-banner {
    padding: 1.75rem 0 1.5rem;
  }

  .page-banner h1 {
    font-size: 1.5rem;
  }

  /* Hero Section Adaptations */
  .hero-section {
    padding: 2.25rem 0 2rem !important;
  }

  .hero-headline {
    font-size: 1.55rem !important;
    line-height: 1.3 !important;
  }

  .hero-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.75rem !important;
  }

  .hero-cta-group {
    flex-direction: column;
    width: 100%;
  }

  .hero-cta-group .btn {
    width: 100%;
    min-height: 48px; /* Touch target requirement */
  }

  /* Quick access cards - 2 columns on mobile */
  .quick-access-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .quick-card {
    padding: 1rem 0.75rem;
  }

  .quick-card-icon {
    width: 42px;
    height: 42px;
  }

  /* Filter form stacking */
  .filter-grid {
    grid-template-columns: 1fr;
  }

  /* Footer single column */
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 1.75rem;
  }

  .footer-bottom .container {
    flex-direction: column;
    text-align: center;
  }

  .footer-legal-links {
    justify-content: center;
  }

  /* Mock test on mobile */
  .palette-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .test-actions-bar {
    flex-direction: column-reverse;
  }

  .test-actions-bar .btn {
    width: 100%;
    min-height: 46px;
  }

  .toast-container {
    bottom: 80px;
    left: 15px;
    right: 15px;
  }

  .toast {
    max-width: 100%;
  }
}

/* --------------------------------------------------------------------------
   Small Handsets (Below 430px: 360px, 390px, 430px)
   -------------------------------------------------------------------------- */
@media (max-width: 429px) {
  .container {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .brand-title {
    font-size: 0.95rem;
  }

  .brand-tagline {
    font-size: 0.625rem;
    max-width: 175px;
  }

  .hero-headline {
    font-size: 1.35rem !important;
  }

  .card-body, .card-header, .card-footer {
    padding: 1rem;
  }

  .btn {
    font-size: 0.875rem;
  }

  .badge {
    font-size: 0.7rem;
  }
}

/* --------------------------------------------------------------------------
   Mobile Layouts & Global Overflow Prevention
   -------------------------------------------------------------------------- */
html, body {
  overflow-x: hidden !important;
  max-width: 100% !important;
  width: 100% !important;
  position: relative;
}

*, *::before, *::after {
  box-sizing: border-box;
}

img, svg, video {
  max-width: 100%;
  height: auto;
}

/* Hero Badge */
.hero-badge-h1 {
  display: inline-block;
  max-width: 100%;
  word-break: break-word;
  background: rgba(233, 162, 59, 0.15);
  border: 1px solid rgba(233, 162, 59, 0.4);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 700;
  color: #FDE68A !important;
  margin-bottom: 1.25rem;
  letter-spacing: 0.3px;
  line-height: 1.4;
  margin-top: 0;
  text-align: center;
}

/* ==========================================================================
/* ==========================================================================
   Samacheer School Books: Mobile & Tablet Card Layout (<= 850px)
   Transforms horizontal cards into vertical mobile cards
   ========================================================================== */
@media (max-width: 850px) {
  .standards-cards-container {
    gap: 0.95rem;
  }

  .standard-overview-card {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.85rem !important;
    padding: 1.15rem !important;
    border-left: 4px solid var(--primary, #1B4B78) !important;
    border-radius: var(--radius-md, 10px) !important;
    background: #FFFFFF !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04) !important;
  }

  .standard-overview-card:hover {
    transform: none !important;
    box-shadow: 0 4px 12px rgba(27, 75, 120, 0.08) !important;
  }

  .std-card-meta {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    padding-bottom: 0.65rem !important;
    border-bottom: 1px solid #F1F5F9 !important;
  }

  .std-card-title {
    font-size: 1.1rem !important;
  }

  .std-card-badge {
    font-size: 0.75rem !important;
    padding: 3px 10px !important;
  }

  .std-card-subjects {
    width: 100% !important;
    padding: 0.15rem 0 !important;
  }

  .subject-pills-list {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.45rem !important;
    width: 100% !important;
  }

  .subject-pill {
    padding: 0.35rem 0.75rem !important;
    font-size: 0.8125rem !important;
  }

  .std-card-action {
    display: block !important;
    width: 100% !important;
    padding-top: 0.25rem !important;
  }

  .std-action-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    min-height: 44px !important;
    padding: 0.65rem 1.25rem !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    background: #F8FAFC !important;
    border: 1px solid #CBD5E1 !important;
    color: var(--primary-dark, #0F2942) !important;
    border-radius: var(--radius-sm, 6px) !important;
    text-align: center !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03) !important;
    white-space: normal !important;
  }

  .std-action-btn:hover,
  .std-action-btn:active {
    background: var(--primary, #1B4B78) !important;
    color: #FFFFFF !important;
    border-color: var(--primary, #1B4B78) !important;
    box-shadow: 0 3px 10px rgba(27, 75, 120, 0.25) !important;
  }
}

/* Grid Layouts with clean mobile breakpoints */
.current-affairs-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 2rem;
  align-items: start;
  min-width: 0;
  width: 100%;
}

.mock-test-banner-layout {
  display: grid;
  grid-template-columns: 1.4fr 1.1fr;
  gap: 2rem;
  align-items: center;
  min-width: 0;
  width: 100%;
}

.prep-tips-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  min-width: 0;
  width: 100%;
}

@media (max-width: 991px) {
  .current-affairs-layout {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }
  
  .mock-test-banner-layout {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }

  .prep-tips-layout {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }
}

@media (max-width: 767px) {
  .hero-badge-h1 {
    font-size: 0.8rem !important;
    padding: 0.4rem 0.75rem !important;
    border-radius: var(--radius-md) !important;
  }

  .btn-alert-action {
    width: 100% !important;
    text-align: center;
    margin-top: 0.75rem;
  }

  .school-books-overview-section .school-books-header-cta {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 44px !important;
    text-align: center !important;
  }

  .quick-access-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
  }
}

@media (max-width: 380px) {
  .quick-access-grid {
    grid-template-columns: 1fr !important;
  }
  
  .hero-stats {
    grid-template-columns: 1fr !important;
  }
}

/* --------------------------------------------------------------------------
   Print Friendly Styles
   -------------------------------------------------------------------------- */
@media print {
  .topbar,
  .site-header,
  .mobile-bottom-nav,
  .site-footer,
  .toast-container,
  .search-modal-backdrop,
  .btn,
  .filter-card,
  .pagination-nav,
  .breadcrumb-wrapper {
    display: none !important;
  }

  body {
    background: #FFFFFF !important;
    color: #000000 !important;
    padding: 0 !important;
  }

  .card, .test-question-box, .accordion-item {
    border: 1px solid #CCCCCC !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  a {
    color: #000000 !important;
    text-decoration: underline !important;
  }
}
