/**
 * All India Metal Corporation — shared responsive layout
 * Mobile · tablet · desktop · safe-area (notched phones)
 */

/* Header button labels: text on desktop, icons on mobile */
.hdr-icon { display: none; }
.hdr-label { display: inline; }

/* ── Global ─────────────────────────────────────────────── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

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

/* Touch-friendly minimum tap targets */
button,
.btn-auth,
.btn-search,
.btn-ask,
.btn-action,
.btn-ask,
.icon-btn,
.hamburger,
.page-ai-chip,
.chip,
.product-chip,
.carousel-arrow {
  min-height: 44px;
}

input,
select,
textarea {
  font-size: 16px; /* prevents iOS zoom on focus */
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .site-header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .footer {
    padding-bottom: max(32px, env(safe-area-inset-bottom));
  }
  .page-ai-fab {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ── Site header (all pages) ──────────────────────────── */
@media (max-width: 1024px) {
  .container {
    padding-left: 20px;
    padding-right: 20px;
  }
}

@media (max-width: 768px) {
  .site-header {
    padding: 8px 10px !important;
    min-height: 56px !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    overflow: visible !important;
    position: sticky !important;
  }

  .header-left {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: calc(100% - 168px) !important;
    gap: 6px !important;
    overflow: visible !important;
    position: static !important;
  }

  .site-logo {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    display: inline-flex;
  }

  .brand-logo-img,
  .site-logo img {
    height: 32px !important;
    max-width: 100% !important;
    width: auto !important;
  }

  .header-right {
    flex: 0 0 auto !important;
    order: 0 !important;
    margin-left: auto !important;
    width: auto !important;
    max-width: none !important;
    gap: 5px !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    flex-shrink: 0 !important;
  }

  /* Compact icon buttons: Search / Login / Signup */
  .hdr-label {
    display: none !important;
  }

  .hdr-icon {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
  }

  .btn-search,
  .btn-auth {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0 !important;
    box-shadow: none !important;
    flex-shrink: 0 !important;
  }

  .btn-search {
    background: rgba(0, 102, 204, 0.1) !important;
    color: var(--primary-blue, #0066cc) !important;
    border: 1px solid rgba(0, 102, 204, 0.2) !important;
  }

  .btn-login {
    background: #fff !important;
    color: var(--primary-blue, #0066cc) !important;
    border: 1.5px solid var(--primary-blue, #0066cc) !important;
  }

  .btn-signup {
    background: var(--primary-blue, #0066cc) !important;
    color: #fff !important;
    border: none !important;
  }

  .btn-signup .hdr-icon {
    color: #fff;
  }

  /* Search field collapses until expanded — kill desktop min-width */
  .search-wrap {
    flex: 0 0 auto !important;
    max-width: none !important;
    min-width: 0 !important;
    width: auto !important;
    gap: 0 !important;
    position: relative;
  }

  .search-wrap .search-field {
    display: none !important;
    min-width: 0 !important;
  }

  .search-wrap.search-open {
    position: absolute !important;
    left: 10px !important;
    right: 10px !important;
    top: calc(100% + 6px) !important;
    z-index: 260;
    width: auto !important;
    min-width: 0 !important;
    background: #fff;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    display: flex !important;
    gap: 8px !important;
    align-items: center;
  }

  .search-wrap.search-open .search-field {
    display: block !important;
    flex: 1;
    min-width: 0 !important;
  }

  .search-wrap.search-open .btn-search {
    width: 36px !important;
    flex-shrink: 0;
  }

  .header-auth {
    flex: 0 0 auto !important;
    justify-content: flex-end;
    flex-wrap: nowrap !important;
    gap: 4px !important;
  }

  .user-menu-btn {
    max-width: 36px !important;
    width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    overflow: hidden;
    font-size: 0 !important;
    position: relative;
  }

  .user-menu-btn::before {
    content: '👤';
    font-size: 16px;
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .user-menu-btn #header-user-name {
    display: none !important;
  }

  /* Mobile nav drawer */
  .hamburger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0 !important;
    width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
  }

  .site-nav {
    display: none;
    position: absolute !important;
    top: calc(100% + 6px) !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    flex-direction: column;
    align-items: stretch;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
    padding: 8px;
    z-index: 400 !important;
  }

  .site-nav.open {
    display: flex !important;
  }

  .site-nav a,
  .nav-dropdown-toggle {
    padding: 12px 14px;
    font-size: 15px;
  }

  .nav-dropdown-menu {
    position: static !important;
    min-width: 0 !important;
    max-width: none !important;
    box-shadow: none !important;
    border: none !important;
    padding: 4px 0 4px 8px !important;
    transform: none !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  .nav-dropdown:not(.open) .nav-dropdown-menu {
    display: none !important;
  }

  .nav-dropdown-menu.nav-products-mega-menu {
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Modals */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .inquiry-modal,
  .inquiry-form-card {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh;
    overflow-y: auto;
  }

  /* Breadcrumb wrap */
  .breadcrumb {
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
  }

  .breadcrumb-family,
  .breadcrumb-product {
    display: inline;
  }

  .breadcrumb-also {
    width: 100%;
    margin-top: 4px;
  }
}

@media (max-width: 480px) {
  .site-header {
    padding: 8px 10px;
  }

  .brand-logo-img,
  .site-logo img {
    height: 36px;
    max-width: min(200px, 48vw);
  }

  .btn-search,
  .btn-auth,
  .hamburger {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .btn-search {
    padding: 0;
    font-size: 0;
  }

  .container {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ── Home page ────────────────────────────────────────── */
@media (max-width: 768px) {
  .hero {
    padding: 48px 16px 36px;
  }

  .hero .tagline {
    font-size: 16px;
    margin-bottom: 28px;
  }

  .ask-box {
    flex-direction: column;
    padding: 0 4px;
  }

  .btn-ask {
    width: 100%;
  }

  .chips {
    gap: 8px;
    padding: 0 4px;
  }

  .chip {
    font-size: 13px;
    padding: 10px 14px;
  }

  .products-carousel {
    --per-view: 2;
    padding: 0 36px 32px;
  }

  .category-grid,
  .family-box .category-grid,
  .family-box-metals .category-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .category-card {
    min-height: 0;
  }

  /* Mobile home accordion (index.html) */
  .family-box-toggle {
    cursor: pointer;
  }

  .info-section {
    margin-left: 16px;
    margin-right: 16px;
    padding: 28px 18px;
    border-radius: 14px;
  }

  .info-section h2 {
    font-size: 22px;
  }

  .info-section h3 {
    font-size: 18px;
  }

  .footer {
    padding: 28px 16px;
    font-size: 13px;
  }

  .footer p {
    word-break: break-word;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: 36px 12px 28px;
  }

  .products-carousel {
    --per-view: 1;
    padding: 0 32px 28px;
  }

  .carousel-arrow {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }

  .category-grid,
  .family-box .category-grid,
  .family-box-metals .category-grid {
    grid-template-columns: 1fr !important;
  }

  .category-card {
    min-height: 0;
  }

  .product-card {
    padding: 20px 16px;
  }

  .product-card .product-icon img {
    width: 80px;
    height: 80px;
  }
}

@media (max-width: 360px) {
  .chip {
    font-size: 12px;
    padding: 8px 12px;
  }
}

/* ── Product page ─────────────────────────────────────── */
@media (max-width: 992px) {
  .product-hero {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .gallery-main {
    max-width: 100%;
    height: min(360px, 70vw);
    margin: 0 auto;
  }

  .gallery-thumbs {
    max-width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .section {
    padding: 20px 16px;
    margin-bottom: 20px;
    border-radius: 14px;
  }

  .section-title {
    font-size: 18px;
  }

  .product-name {
    font-size: clamp(22px, 5vw, 28px);
  }

  .app-cards {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px;
  }

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

  .action-btns {
    flex-direction: column;
  }

  .btn-action,
  .inquiry-btn {
    width: 100%;
    text-align: center;
  }

  .ai-input-row,
  .page-ai-input-row {
    flex-direction: column;
  }

  .btn-ask,
  .page-ai-ask {
    width: 100%;
  }

  /* Scrollable specs table on small screens */
  .specs-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
    padding: 0 4px;
  }

  .specs-table {
    min-width: 280px;
    font-size: 14px;
  }

  .specs-table td:first-child {
    white-space: nowrap;
    padding-right: 16px;
  }

  .chat-msg {
    max-width: 94% !important;
  }

  .page-ai-widget {
    padding: 18px 14px 20px;
    margin-top: 20px;
  }

  .page-ai-history {
    max-height: 280px;
  }
}

@media (max-width: 480px) {
  .gallery-main {
    height: min(280px, 75vw);
    border-radius: 12px;
  }

  .gallery-thumb {
    width: 64px;
    height: 64px;
  }

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

  .badges {
    gap: 6px;
  }

  .badge {
    font-size: 12px;
    padding: 5px 10px;
  }

  .product-desc {
    font-size: 15px;
  }

  .info-block {
    font-size: 13px;
    padding: 12px 14px;
  }
}

/* ── Category page ────────────────────────────────────── */
@media (max-width: 900px) {
  .subcat-grid,
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .page-hero {
    padding: 20px 0;
  }

  .page-hero h1 {
    font-size: clamp(22px, 5vw, 28px);
  }

  .subcat-grid,
  .product-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .product-card-cat,
  .subcat-card {
    padding: 16px;
  }
}

/* ── Chat page ────────────────────────────────────────── */
@media (max-width: 768px) {
  .top-bar {
    padding: 8px 10px;
    gap: 4px;
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .top-brand {
    order: -1;
  }

  .top-brand .brand-logo-img {
    height: 32px;
    max-width: min(180px, 40vw);
  }

  .top-icons {
    order: 2;
    flex: 1 1 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 4px;
    overflow-x: visible;
    padding-top: 4px;
  }

  .top-bar-right {
    margin-left: 0;
    flex: 1 1 auto;
  }

  .icon-btn {
    padding: 8px 10px;
    min-height: 40px;
  }

  .icon-label {
    display: none;
  }

  .user-badge {
    max-width: 72px;
    font-size: 11px;
    padding: 6px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .guest-hint {
    display: none;
  }

  .chat-close-btn {
    top: 8px;
    right: 10px;
    font-size: 22px;
  }

  .chat-messages {
    padding: 44px 12px 16px;
  }

  .message {
    max-width: 92%;
    font-size: 15px;
  }

  .input-area {
    padding: 12px 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .input-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .btn-send {
    width: 100%;
    text-align: center;
    min-height: 48px;
  }

  .product-chips {
    flex-wrap: wrap;
    gap: 6px;
  }

  .product-chip {
    font-size: 12px;
    padding: 8px 12px;
  }

  .persona-options {
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .top-icons {
    justify-content: space-between;
  }

  .icon-btn {
    padding: 8px;
    font-size: 16px;
    min-width: 40px;
  }

  .chat-input {
    font-size: 16px;
    padding: 14px 16px;
  }
}

/* ── AI mode page ─────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    position: fixed;
    z-index: 500;
    height: 100%;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .message {
    max-width: 92%;
  }
}

/* ── Content guard modal ──────────────────────────────── */
@media (max-width: 480px) {
  #aimc-content-guard-modal {
    padding: 16px;
    align-items: flex-end;
  }

  #aimc-content-guard-modal .aimc-cg-card {
    border-radius: 16px 16px 0 0;
    padding: 24px 20px 20px;
  }

  #aimc-content-guard-modal .aimc-cg-actions {
    flex-direction: column-reverse;
  }

  #aimc-content-guard-modal .aimc-cg-btn {
    width: 100%;
    text-align: center;
    min-height: 48px;
  }
}

/* ── Landscape phones ─────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .hero {
    padding: 24px 16px 20px;
  }

  .page-ai-history {
    max-height: 160px;
  }

  .modal-card {
    max-height: 88vh;
  }
}

/* ── Large tablets / small laptops ────────────────────── */
@media (min-width: 769px) and (max-width: 1100px) {
  .category-grid,
  .family-box .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* Lock body scroll when mobile nav drawer is open */
body.nav-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}
