/* KOK.mn Mobile UI Polish v2.2 — KL-010G-R2 staging
 * Load AFTER kok-mobile-v2.1.css (after topform.php).
 * Preserves v2.1 cascade fix; refines header, search-first order, categories.
 * Desktop outside these media queries is unchanged.
 */

@media screen and (max-width: 900px) {

  /* ===== Compact shared header ===== */
  html body #toppanel > header.kok-v2-header,
  html body #toppanel > .kok-v2-header {
    min-height: 0 !important;
    height: auto !important;
    grid-template-columns: minmax(0,1fr) minmax(132px,168px) !important;
    grid-template-rows: auto auto !important;
    grid-template-areas:
      "brand account"
      "nav nav" !important;
    gap: 4px 8px !important;
    padding: 6px 8px 4px !important;
    align-items: center !important;
  }

  html body #toppanel .kok-v2-brand {
    height: auto !important;
    min-height: 36px !important;
    justify-content: center !important;
  }
  html body #toppanel .kok-v2-brand-title {
    font-size: 18px !important;
    line-height: 22px !important;
  }
  html body #toppanel .kok-v2-brand-note {
    font-size: 10px !important;
    line-height: 12px !important;
  }

  /* Login text clipping: topform uses fixed 40px + overflow:hidden */
  html body #toppanel .kok-v2-account.tab,
  html body #toppanel .kok-v2-account.tab > ul.login,
  html body #toppanel .kok-v2-account.tab > ul.login > li#toggle {
    width: 100% !important;
    max-width: 168px !important;
    height: auto !important;
    min-height: 40px !important;
    overflow: visible !important;
  }
  html body #toppanel .kok-v2-account-open,
  html body #toppanel .kok-v2-account-close,
  html body #toppanel > .kok-v2-header > .kok-v2-account.tab > ul.login > li#toggle > a#open.kok-v2-account-open {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    height: auto !important;
    min-height: 40px !important;
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
    line-height: 1.25 !important;
    font-size: 11px !important;
    padding: 6px 8px !important;
    box-sizing: border-box !important;
    text-align: center !important;
  }
  html body #toppanel .kok-v2-account-open > span,
  html body #toppanel .kok-v2-account-close > span,
  html body #toppanel .kok-v2-close-content {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    max-width: 100% !important;
  }
  html body #toppanel .kok-v2-account-copy {
    min-width: 0 !important;
    overflow: visible !important;
  }
  html body #toppanel .kok-v2-account-name {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
  }

  /* Navigation: wrap labels instead of clipping off-screen */
  html body #toppanel .kok-v2-nav {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 4px !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin-left: 0 !important;
    padding: 2px 0 4px !important;
    overflow-x: visible !important;
    overflow-y: visible !important;
    white-space: normal !important;
    scroll-snap-type: none !important;
  }
  html body #toppanel .kok-v2-nav > a.kok-v2-nav-link {
    flex: 0 1 auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 36px !important;
    padding: 6px 10px !important;
    font-size: 11px !important;
    line-height: 1.25 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
  html body #toppanel .kok-v2-nav > a.kok-v2-nav-link > span {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  /* ===== Compact hub: one upload + full-width search ===== */
  .kok-compact-hub,
  body.kok-inner-page .kok-compact-hub,
  body.kok-home-page .kok-compact-hub {
    display: grid !important;
    grid-template-columns: 40px minmax(0,1fr) !important;
    grid-template-areas:
      "home primary"
      "search search" !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  .kok-compact-home { grid-area: home !important; min-height: 40px !important; }
  .kok-compact-action-primary {
    grid-area: primary !important;
    min-height: 40px !important;
    font-size: 12px !important;
  }
  /* Keep one upload CTA; hide secondary hub actions (still in DOM/routes) */
  .kok-compact-action:not(.kok-compact-action-primary),
  .kok-compact-toggle {
    display: none !important;
  }
  .kok-compact-search {
    grid-area: search !important;
    grid-column: 1 / -1 !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
  }
  .kok-compact-search input[type="text"] {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: auto !important;
    min-height: 40px !important;
    height: 40px !important;
    font-size: 16px !important;
    padding: 0 8px !important;
    text-overflow: ellipsis !important;
  }
  .kok-compact-search button {
    flex: 0 0 auto !important;
    min-width: 64px !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 0 10px !important;
    font-size: 13px !important;
  }

  /* ===== Search-first / content-first reading order =====
   * v2.1 set sidebar order:-1 (categories above results).
   * On mobile, show primary content first; categories remain below, compact.
   */
  .kok-content-layout {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) !important;
    gap: 10px !important;
  }
  .kok-content-primary,
  #mainleft.kok-content-primary,
  #mainleft {
    order: 1 !important;
  }
  .kok-content-sidebar {
    order: 2 !important;
  }
  body.kok-inner-page .kok-content-primary,
  body.kok-home-page .kok-content-primary {
    order: 1 !important;
  }
  body.kok-inner-page .kok-content-sidebar,
  body.kok-home-page .kok-content-sidebar {
    order: 2 !important;
  }

  /* ===== Compact category panel ===== */
  .kok-sidebar-categories {
    margin: 4px 0 8px !important;
    border-radius: 10px !important;
  }
  .kok-sidebar-header {
    min-height: 40px !important;
    padding: 6px 8px !important;
    gap: 6px !important;
  }
  .kok-sidebar-header h2 {
    font-size: 12px !important;
    line-height: 16px !important;
  }
  .kok-sidebar-nav {
    padding: 2px 4px 4px !important;
  }
  .kok-sidebar-section {
    margin: 0 !important;
  }
  .kok-sidebar-section summary {
    min-height: 44px !important;
    padding: 4px 6px !important;
    font-size: 13px !important;
    line-height: 16px !important;
    gap: 6px !important;
  }
  .kok-sidebar-summary-main {
    grid-template-columns: 24px minmax(0,1fr) !important;
    gap: 6px !important;
  }
  .kok-sidebar-section-icon {
    width: 24px !important;
    height: 24px !important;
  }
  .kok-sidebar-list {
    padding: 0 0 2px !important;
  }
  .kok-sidebar-link {
    min-height: 44px !important;
    margin: 0 !important;
    padding: 4px 6px !important;
    gap: 6px !important;
    font-size: 12px !important;
    line-height: 15px !important;
    grid-template-columns: 20px minmax(0,1fr) auto !important;
  }
  .kok-sidebar-name {
    max-height: none !important;
    overflow: visible !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    -webkit-line-clamp: unset !important;
    display: block !important;
  }
  .kok-sidebar-count {
    min-width: 28px !important;
    height: 20px !important;
    font-size: 10px !important;
    justify-self: end !important;
  }
  /* Soften non-category sidebar bulk on mobile */
  .kok-sidebar-promo,
  .kok-sidebar-panel {
    margin-bottom: 8px !important;
  }

  /* ===== Banner / info widgets (scoped compact) ===== */
  .kok-home-banner-grid {
    height: auto !important;
    min-height: 0 !important;
    margin-bottom: 6px !important;
    gap: 6px !important;
  }
  .kok-banner-slider,
  .kok-home-product-banner {
    min-height: 120px !important;
  }
  .kok-utility-item {
    min-width: 150px !important;
    height: 48px !important;
  }
  .kok-feature-row .kok-feature-card {
    height: auto !important;
    min-height: 120px !important;
    padding: 10px 12px !important;
  }
  .kok-header-clearance {
    height: 4px !important;
  }

  /* ===== Fixed bottom marquee (home only) — leave flow, avoid overlap ===== */
  body.kok-home-page #main.kok-modern-main > div[style*="position: fixed"],
  body.kok-home-page #main.kok-modern-main > div[style*="bottom: 0"] {
    position: static !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    z-index: auto !important;
    width: 100% !important;
    margin: 0 0 8px !important;
    box-sizing: border-box !important;
    font-size: 12px !important;
    padding: 6px 8px !important;
  }
  body.kok-home-page #main.kok-modern-main > div[style*="bottom: 0"] h4,
  body.kok-home-page #main.kok-modern-main > div[style*="bottom: 0"] strong {
    font-size: 12px !important;
    line-height: 1.35 !important;
  }
}

@media screen and (max-width: 430px) {
  html body #toppanel > header.kok-v2-header,
  html body #toppanel > .kok-v2-header {
    grid-template-columns: minmax(0,1fr) minmax(120px,148px) !important;
  }
  html body #toppanel .kok-v2-brand-title {
    font-size: 16px !important;
  }
  html body #toppanel .kok-v2-account-open,
  html body #toppanel .kok-v2-account-close {
    font-size: 10px !important;
    padding: 5px 6px !important;
  }
  .kok-compact-search button {
    min-width: 56px !important;
    padding: 0 8px !important;
  }
}

@media screen and (min-width: 901px) {
  /* Intentionally empty — desktop remains on existing styles */
}
