/* ==========================================================================
   StudentTools - Responsive Layout & Device Optimization (responsive.css)
   Ultra-Deep Mobile Device Optimization (320px - 1400px+)
   Guarantees 100% zero overflow, zero cropped text, touch-friendly, 100% screen-fit tables.
   ========================================================================== */

/* Universal Mobile Safety Defaults */
html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

*, *::before, *::after {
  box-sizing: border-box;
  overflow-wrap: break-word;
  word-break: break-word;
}

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

/* Touch-friendly Targets */
.btn, .nav-link, .mobile-nav-link, .form-control:not(.calc-table .form-control) {
  min-height: 44px;
}

/* Table Wrappers & Universal Table Scrolling */
.calc-table-wrapper, .table-wrapper, .article-container table, .tool-info-content table, section table {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.25rem;
  border-radius: var(--radius-md);
}

.content-table {
  width: 100%;
  min-width: 500px;
}

/* --------------------------------------------------------------------------
   1. Large Desktops & Laptops (1200px and down)
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .tools-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .megamenu {
    width: 780px;
  }
}

/* --------------------------------------------------------------------------
   2. Tablets & Medium Screens (992px and down)
   -------------------------------------------------------------------------- */
@media (max-width: 992px) {
  .hero-grid {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 2.25rem;
  }

  .hero-description {
    margin-left: auto;
    margin-right: auto;
  }

  .hero-actions {
    justify-content: center;
  }

  .hero-visual {
    display: none;
  }

  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }

  .calc-grid, .contact-grid {
    grid-template-columns: 1fr !important;
    gap: 1.5rem !important;
  }

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

  /* Navigation Drawer Controls */
  .desktop-nav {
    display: none !important;
  }

  .mobile-nav-toggle {
    display: flex !important;
  }

  .mobile-nav-drawer {
    position: fixed;
    top: 76px;
    left: 0;
    width: 100%;
    height: calc(100vh - 76px);
    background-color: var(--bg-surface);
    z-index: 1200;
    padding: 1.5rem;
    overflow-y: auto;
    display: none !important;
    flex-direction: column;
    gap: 0.75rem;
    border-top: 1px solid var(--border-color);
    box-shadow: var(--shadow-3d);
  }

  .mobile-nav-drawer.active {
    display: flex !important;
  }

  .mobile-nav-link {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .mobile-category-group {
    padding-left: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.45rem;
  }

  .mobile-category-title {
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--primary);
    margin-top: 0.65rem;
    letter-spacing: 0.05em;
  }

  .blog-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}

/* --------------------------------------------------------------------------
   3. Small Tablets & Large Mobile Phones (768px and down)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .hero-title {
    font-size: 2.25rem;
  }

  .tools-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .tool-widget-card {
    padding: 1.1rem 0.65rem;
  }

  .tool-info-content, .article-container {
    padding: 1.25rem 0.85rem;
  }

  .blog-grid {
    grid-template-columns: 1fr;
  }

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

  .footer-bottom {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  /* 100% Fit Table Layout for Mobile Screens */
  .calc-table-wrapper {
    overflow-x: hidden !important;
    width: 100% !important;
    margin-bottom: 1rem !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--border-color) !important;
  }

  .calc-table {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
  }

  .calc-table th:nth-child(1),
  .calc-table td:nth-child(1) {
    width: 38% !important;
  }

  .calc-table th:nth-child(2),
  .calc-table td:nth-child(2) {
    width: 24% !important;
  }

  .calc-table th:nth-child(3),
  .calc-table td:nth-child(3) {
    width: 24% !important;
  }

  .calc-table th:nth-child(4),
  .calc-table td:nth-child(4) {
    width: 14% !important;
    text-align: center !important;
  }

  .calc-table th {
    font-size: 0.68rem !important;
    font-weight: 800 !important;
    padding: 0.5rem 0.15rem !important;
    white-space: normal !important;
    text-align: center !important;
    line-height: 1.2 !important;
    letter-spacing: 0 !important;
  }

  .calc-table th:first-child {
    text-align: left !important;
    padding-left: 0.35rem !important;
  }

  .calc-table td {
    padding: 0.35rem 0.15rem !important;
    vertical-align: middle !important;
  }

  .calc-table td .form-control {
    width: 100% !important;
    min-width: 0 !important;
    padding: 0.35rem 0.25rem !important;
    font-size: 0.82rem !important;
    height: 36px !important;
    min-height: 36px !important;
    box-sizing: border-box !important;
  }

  .calc-table td:nth-child(2) .form-control,
  .calc-table td:nth-child(3) .form-control {
    text-align: center !important;
  }

  .btn-remove-row {
    width: 28px !important;
    height: 28px !important;
    min-height: 28px !important;
    padding: 0 !important;
    font-size: 0.75rem !important;
    margin: 0 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 4px !important;
  }

  /* Blog Content Data Tables Mobile Touch Scroll & Word Integrity */
  .table-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin: 1.25rem 0 !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--border-color) !important;
  }

  .content-table {
    width: 100% !important;
    min-width: 520px !important;
    border-collapse: collapse !important;
  }

  .content-table th, .content-table td {
    word-break: normal !important;
    overflow-wrap: normal !important;
    word-wrap: normal !important;
    hyphens: manual !important;
  }

  .content-table th {
    font-size: 0.75rem !important;
    padding: 0.65rem 0.75rem !important;
    white-space: nowrap !important;
    letter-spacing: 0.03em !important;
  }

  .content-table td {
    font-size: 0.82rem !important;
    padding: 0.65rem 0.75rem !important;
    white-space: normal !important;
  }

  summary.blog-collapsible-header {
    padding: 0.85rem 0.75rem !important;
    font-size: 0.88rem !important;
    gap: 0.5rem !important;
  }

  .collapsible-badge {
    font-size: 0.7rem !important;
    padding: 0.2rem 0.55rem !important;
  }

  .blog-collapsible-content {
    padding: 0.65rem 0.35rem !important;
  }
}

/* --------------------------------------------------------------------------
   4. Mobile Standard Phones (576px and down)
   -------------------------------------------------------------------------- */
@media (max-width: 576px) {
  .site-header {
    height: 62px;
  }

  .header-inner {
    height: 62px;
  }

  .mobile-nav-drawer {
    top: 62px;
    height: calc(100vh - 62px);
    padding: 1.1rem;
  }

  .brand-logo {
    font-size: 1.2rem;
  }

  .brand-logo svg {
    width: 26px;
    height: 26px;
  }

  .theme-toggle-btn, .mobile-nav-toggle {
    width: 36px;
    height: 36px;
  }

  /* Sleek Horizontal Breadcrumbs */
  .breadcrumb-nav {
    padding: 0.5rem 0;
  }

  .breadcrumb-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    font-size: 0.78rem;
    padding-bottom: 0.2rem;
  }

  .tools-grid {
    grid-template-columns: 1fr;
  }

  .tool-widget-card {
    padding: 0.85rem 0.5rem;
    border-radius: var(--radius-md);
  }

  .tool-widget-header {
    margin-bottom: 0.95rem;
    padding-bottom: 0.75rem;
  }

  .tool-title {
    font-size: 1.35rem;
  }

  .tool-description {
    font-size: 0.88rem;
    line-height: 1.45;
  }

  .form-group {
    margin-bottom: 0.85rem;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .calc-actions {
    flex-direction: column;
    gap: 0.65rem;
    margin-top: 1rem;
  }

  .btn {
    width: 100%;
    padding: 0.7rem 0.85rem;
    font-size: 0.88rem;
  }

  /* Result Box Mobile Scaling */
  .result-box {
    padding: 0.95rem 0.6rem;
  }

  .result-header {
    font-size: 0.92rem;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .result-main {
    padding: 0.85rem 0.5rem;
  }

  .result-value {
    font-size: clamp(1.65rem, 6vw, 2.2rem);
    word-break: break-all;
  }

  .breakdown-item {
    font-size: 0.82rem;
  }

  .formula-box {
    font-size: 0.74rem;
    padding: 0.55rem 0.65rem;
    word-break: break-all;
  }

  .hero-title {
    font-size: 1.75rem;
  }

  .search-input {
    font-size: 0.9rem;
    padding-left: 2.6rem;
  }

  .search-icon {
    left: 0.75rem;
  }

  /* Mobile 2-Column Footer Layout & Premium Surface Background */
  .site-footer {
    padding: 2.25rem 0 1.25rem !important;
    background-color: var(--bg-surface-hover) !important;
    border-top: 2px solid var(--border-color) !important;
  }

  .footer-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1.5rem 1rem !important;
    margin-bottom: 2rem !important;
  }

  .footer-grid > div:first-child {
    grid-column: 1 / -1 !important;
    margin-bottom: 0.25rem !important;
  }

  .footer-col-title {
    font-size: 0.8rem !important;
    font-weight: 800 !important;
    color: var(--primary) !important;
    margin-bottom: 0.65rem !important;
    letter-spacing: 0.05em !important;
    border-bottom: 2px solid var(--primary-light) !important;
    padding-bottom: 0.3rem !important;
  }

  .footer-links {
    gap: 0.45rem !important;
  }

  .footer-links a {
    font-size: 0.85rem !important;
    padding: 0.2rem 0 !important;
    color: var(--text-secondary) !important;
    display: block !important;
    font-weight: 500 !important;
  }

  .footer-links a:hover {
    color: var(--primary) !important;
  }

  .footer-bottom {
    flex-direction: column !important;
    gap: 0.5rem !important;
    text-align: center !important;
    font-size: 0.78rem !important;
    padding-top: 1.25rem !important;
    border-top: 1px solid var(--border-color) !important;
  }
}

/* --------------------------------------------------------------------------
   5. Extra Small Devices (320px - 375px)
   -------------------------------------------------------------------------- */
@media (max-width: 375px) {
  .container {
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }

  .tool-widget-card {
    padding: 0.75rem 0.35rem;
  }

  .hero-title {
    font-size: 1.55rem;
  }

  .tool-title {
    font-size: 1.25rem;
  }

  .brand-logo {
    font-size: 1.1rem;
  }

  .brand-badge {
    display: none;
  }

  .result-value {
    font-size: clamp(1.5rem, 5.5vw, 1.85rem);
  }
}
