/* ==========================================================================
   DEVRATH COMPLETE MOBILE RESPONSIVE & ANDROID ENGINE
   WCAG AA / AAA Accessibility, Fluid Typography, Zero Horizontal Overflow
   Target Viewports: 320x568, 360x800, 375x812, 390x844, 412x915, 768x1024, 1366x768
   ========================================================================== */

/* --- 1. Global Reset & Viewport Constraints --- */
:root {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden !important;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(227, 162, 26, 0.15);
}

*, *::before, *::after {
  box-sizing: border-box;
  min-width: 0; /* Prevents flex/grid children from exceeding parent container */
}

/* Ensure images, SVGs, and media never breach parent bounds */
img, svg, video, iframe, object, canvas {
  max-width: 100% !important;
  height: auto;
}

/* Touch targets for interactive elements (>= 44px for Android Accessibility) */
button, input[type="button"], input[type="submit"], input[type="reset"],
.btn, .eq-btn, .menu-btn, .hub-tab-btn, .res-tab-btn, .preset-btn, .quick-tag {
  min-height: 44px;
  touch-action: manipulation;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* --- 2. Container & Section Constraints --- */
.wrap {
  width: min(1120px, 100% - 2.25rem);
  margin-inline: auto;
  box-sizing: border-box;
}

@media (max-width: 480px) {
  .wrap {
    width: min(1120px, 100% - 1.25rem);
    padding-inline: 0.25rem;
  }
}

section {
  padding-block: 3.5rem;
}

@media (max-width: 640px) {
  section {
    padding-block: 2.25rem;
  }
}

/* --- 3. Responsive Header & Mobile Navigation Drawer --- */
.top {
  position: sticky;
  top: var(--safe-area-top);
  z-index: 999;
  background: #19244F;
  color: #EEE4CC;
  width: 100%;
}

.top .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  min-height: 44px;
}

.brand b {
  font-family: "Tiro Devanagari Hindi", serif;
  font-size: 1.3rem;
  letter-spacing: 0.05em;
  color: #FAF8F2;
}

/* Navigation Drawer Breakpoint at 980px */
@media (max-width: 980px) {
  .menu-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0.35rem 0.85rem;
    background: transparent;
    border: 2px solid #E3A21A;
    color: #FAF8F2;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
  }

  .top nav {
    display: none;
    position: fixed !important;
    left: 0;
    right: 0;
    top: calc(60px + var(--safe-area-top));
    background: #19244F !important;
    flex-direction: column !important;
    gap: 0 !important;
    padding: 0.75rem 1.25rem 1.5rem !important;
    border-bottom: 4px solid #E3A21A !important;
    box-shadow: 0 16px 36px rgba(10, 16, 38, 0.65) !important;
    max-height: calc(100vh - 60px - var(--safe-area-top));
    overflow-y: auto;
    z-index: 9999 !important;
  }

  .top nav.open {
    display: flex !important;
  }

  .top nav a {
    display: flex !important;
    align-items: center;
    min-height: 48px !important;
    padding: 0.75rem 0 !important;
    font-size: 1.08rem !important;
    font-weight: 600 !important;
    color: #FAF8F2 !important;
    border-bottom: 1px solid rgba(238, 228, 204, 0.15) !important;
    text-decoration: none;
  }

  .top nav a[aria-current="page"] {
    color: #E3A21A !important;
    font-weight: 700 !important;
  }

  .top nav a:last-child {
    border-bottom: none !important;
  }
}

@media (min-width: 981px) {
  .menu-btn {
    display: none !important;
  }

  .top nav {
    display: flex !important;
    gap: clamp(0.4rem, 1.2vw, 1.1rem);
    align-items: center;
  }
}

/* --- 4. Responsive Hero Sections --- */
.hero, .g-hero {
  width: 100%;
  overflow: hidden;
}

@media (max-width: 860px) {
  .hero .wrap {
    grid-template-columns: 1fr !important;
    padding-block: 1.5rem 2rem !important;
    gap: 1.5rem !important;
  }

  .hero h1, .g-hero h1 {
    font-size: clamp(2.1rem, 9vw, 3.6rem) !important;
    line-height: 1.05 !important;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .hero .hi, .g-hero .hi {
    font-size: clamp(1.2rem, 5vw, 1.75rem) !important;
  }

  .hero p.lede, .g-hero p.lede {
    font-size: 1.05rem !important;
    max-width: 100% !important;
    line-height: 1.5 !important;
  }

  .actions {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }

  .actions .btn {
    width: 100% !important;
    min-height: 46px !important;
    justify-content: center !important;
    text-align: center !important;
  }

  .wheel-box {
    order: -1;
    margin-bottom: 0.5rem;
  }

  .wheel {
    width: min(200px, 55vw) !important;
  }
}

/* --- 5. Responsive Cards System & Grids --- */
.card-grid, .posts, .tlist, .ways, .calc-grid, .cols, .checks, .classification-grid, .summary-stats-grid, .agreements-grid {
  width: 100%;
  box-sizing: border-box;
}

/* Small Android phones (320px - 600px): Single Column for Cards */
@media (max-width: 600px) {
  .card-grid, .posts, .tlist, .ways, .calc-grid, .cols, .checks, .classification-grid, .agreements-grid {
    grid-template-columns: 1fr !important;
    gap: 1.25rem !important;
  }

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

  .card, .post, .way, .classification-result-card, .results-card, .agreement-card {
    padding: 1.25rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
    min-width: 0 !important;
  }

  .card h3, .card h4, .post h3, .way strong {
    font-size: 1.28rem !important;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .card p, .card li, .post p {
    font-size: 0.98rem !important;
    line-height: 1.5 !important;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .card-footer, .card .card-footer {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.65rem !important;
    margin-top: 1rem !important;
  }

  .card .btn, .card-footer .btn {
    width: 100% !important;
    min-height: 44px !important;
    justify-content: center !important;
    text-align: center !important;
  }
}

/* Tablets (601px - 980px): 2 Columns */
@media (min-width: 601px) and (max-width: 980px) {
  .card-grid, .posts, .tlist, .ways, .classification-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.35rem !important;
  }
}

/* --- 6. Bahi-Khata Ledger Rows (Home & Services) --- */
@media (max-width: 640px) {
  .ledger::before, .ledger::after {
    display: none !important;
  }

  .row {
    grid-template-columns: 1fr !important;
  }

  .row .mark {
    display: none !important;
  }

  .row .body {
    padding: 1.25rem 1rem !important;
  }

  .row h3 {
    font-size: 1.35rem !important;
  }

  .row h3 span {
    display: block !important;
    margin-left: 0 !important;
    margin-top: 0.2rem !important;
    font-size: 0.98rem !important;
  }
}

/* --- 7. Process Steps & Export Guide Steps --- */
@media (max-width: 640px) {
  .steps {
    grid-template-columns: 1fr !important;
    gap: 1.25rem !important;
  }

  .steps li {
    padding-top: 1rem !important;
    border-top: 1px solid rgba(25, 36, 79, 0.15);
  }

  .xsteps > li {
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    padding: 1.25rem 0 !important;
  }

  .xsteps > li::before {
    font-size: 2.2rem !important;
  }
}

/* --- 8. Forms, Inputs & Calculators --- */
@media (max-width: 640px) {
  .calc-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }

  .form {
    max-width: 100% !important;
    width: 100% !important;
  }

  .form .two {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  .form input, .form select, .form textarea,
  .eq-group input, .eq-group select, .eq-group textarea,
  .hsn-input-group input, .form-field input, .form-field select {
    font-size: 16px !important; /* Prevents mobile browser auto-zoom on focus */
    min-height: 44px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .search-controls {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  .hsn-input-group {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  .hsn-input-group button, .search-action-btn {
    width: 100% !important;
    min-height: 46px !important;
  }

  .eq-row {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  #enquiry-dialog, .hsn-modal-window {
    width: 95vw !important;
    max-height: 92vh !important;
    margin: auto !important;
  }

  .eq-body, .hsn-modal-body {
    padding: 1rem !important;
  }
}

/* --- 9. Data Tables & Horizontal Scrolling Wrappers --- */
.tbl, .hsn-table-wrapper, .table-container, .results-table-wrapper {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  max-width: 100% !important;
  margin-block: 1rem !important;
  border-radius: 6px !important;
}

table, .trade-table, .results-table, .hsn-catalog-table {
  width: 100% !important;
  box-sizing: border-box !important;
}

@media (max-width: 640px) {
  table, .trade-table, .results-table, .hsn-catalog-table {
    font-size: 0.88rem !important;
  }

  th, td {
    padding: 0.5rem 0.6rem !important;
  }

  .next li {
    grid-template-columns: 1fr !important;
    gap: 0.2rem !important;
  }
}

/* --- 10. Hub Tabs & Navigation Links --- */
@media (max-width: 640px) {
  .hub-nav, .res-tabs, .toc .wrap {
    flex-direction: row !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 0.5rem !important;
    gap: 0.5rem !important;
  }

  .hub-tab-btn, .res-tab-btn, .toc a {
    white-space: nowrap !important;
    font-size: 0.9rem !important;
    padding: 0.5rem 0.85rem !important;
    min-height: 40px !important;
    flex-shrink: 0 !important;
  }

  .links-list {
    columns: 1 !important;
  }
}

/* --- 11. Footer Adjustments --- */
@media (max-width: 640px) {
  footer .wrap {
    flex-direction: column !important;
    gap: 1.25rem !important;
  }

  footer .flinks {
    flex-direction: column !important;
    gap: 0.65rem !important;
  }

  footer p {
    font-size: 0.85rem !important;
  }
}
