/*
 * TC Factory Mobile Responsive v3.3 — Verified Blank Page Fix
 * Layout ตรงตามภาพตัวอย่างที่ผู้ใช้ยืนยัน
 * ใช้เฉพาะมือถือไม่เกิน 767px — PC/Tablet คงเดิม
 */

.tc-mobile-only { display: none !important; }

@media only screen and (max-width: 767px) {
  :root {
    --tc3-green-dark: #07572a;
    --tc3-green: #087f36;
    --tc3-green-bright: #09ae43;
    --tc3-red: #e51f18;
    --tc3-bg: #f5f7f5;
    --tc3-text: #143d27;
    --tc3-border: #dfe8e1;
  }

  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
  }

  body {
    margin: 0;
    background: var(--tc3-bg);
    padding-bottom: calc(62px + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .tc-desktop-tablet-only { display: none !important; }
  .tc-mobile-only { display: block !important; }

  /*
   * หน้าแรกมือถือใช้ Layout v3 แทนโมดูลหน้าแรกเดิม
   * หน้าอื่นต้องแสดงเนื้อหา OpenCart ตามปกติ
   */
  body.tc-m3-home #content,
  body.tc-m3-home footer {
    display: none !important;
  }

  body.tc-m3-inner .tc-m3-shell {
    min-height: 58px !important;
    height: auto !important;
  }

  body.tc-m3-inner #content,
  body.tc-m3-inner footer {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  body.tc-m3-inner #content {
    min-height: 240px;
    margin-top: 0 !important;
    padding-top: 10px;
    padding-bottom: 20px;
    position: relative;
    z-index: 1;
  }

  body.tc-m3-inner .breadcrumb {
    margin-top: 0;
  }

  .tc-m3-shell {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    min-height: 58px;
    background: #fff;
    color: var(--tc3-text);
    font-family: "Open Sans", Tahoma, Arial, sans-serif;
    box-shadow: 0 0 18px rgba(0,0,0,.06);
  }

  /* Header ตามภาพ: แถบเขียวแถวเดียว */
  .tc-m3-header {
    height: 58px;
    padding: 0 9px;
    position: sticky;
    top: 0;
    z-index: 10020;
    display: grid;
    grid-template-columns: 42px minmax(0,1fr) auto;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #075b2c, #054923);
    color: #fff;
    box-shadow: 0 3px 10px rgba(1,55,24,.22);
  }

  .tc-m3-header-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #fff !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    text-decoration: none !important;
    font-size: 19px;
  }

  .tc-m3-header-btn:active { background: rgba(255,255,255,.12); }

  .tc-m3-brand {
    min-width: 0;
    color: #fff !important;
    text-decoration: none !important;
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .tc-m3-brand-mark {
    min-width: 43px;
    font-size: 27px;
    line-height: 1;
    font-weight: 900;
    font-style: italic;
    color: #fff;
    text-shadow:
      -1px -1px 0 #22ad48,
       1px -1px 0 #22ad48,
      -1px  1px 0 #22ad48,
       1px  1px 0 #22ad48;
  }

  .tc-m3-brand-copy {
    min-width: 0;
    display: block;
    line-height: 1.05;
  }

  .tc-m3-brand-copy strong,
  .tc-m3-brand-copy small {
    display: block;
    color: #fff;
    white-space: nowrap;
  }

  .tc-m3-brand-copy strong {
    font-size: 12px;
    font-weight: 800;
  }

  .tc-m3-brand-copy small {
    margin-top: 2px;
    font-size: 7px;
    font-weight: 700;
    letter-spacing: .3px;
  }

  .tc-m3-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
  }

  .tc-m3-cart-badge {
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    position: absolute;
    right: -2px;
    top: -1px;
    border-radius: 10px;
    background: #4fd04e;
    color: #fff;
    font-size: 10px;
    line-height: 19px;
    font-weight: 800;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,.22);
  }

  .tc-m3-cart-source {
    display: none !important;
  }

  .tc-m3-search-panel {
    display: none;
    position: absolute;
    top: 58px;
    left: 0;
    right: 0;
    padding: 9px;
    background: #fff;
    box-shadow: 0 7px 18px rgba(0,0,0,.15);
  }

  .tc-m3-search-panel.is-open { display: block; }

  .tc-m3-search-panel #search { margin: 0; }
  .tc-m3-search-panel #search .form-control {
    height: 44px;
    border: 1px solid #d6e2d9;
    border-radius: 9px 0 0 9px;
    box-shadow: none;
  }
  .tc-m3-search-panel #search .btn {
    height: 44px;
    border-color: #07572a;
    border-radius: 0 9px 9px 0;
    background: #07572a;
    color: #fff;
  }

  .tc-m3-home-only { display: none; }
  .tc-m3-home-only.is-home { display: block; }

  /* Hero banner */
  .tc-m3-hero {
    min-height: 248px;
    margin: 0;
    position: relative;
    overflow: hidden;
    background:
      linear-gradient(90deg, rgba(244,250,244,.98) 0%, rgba(244,250,244,.94) 37%, rgba(244,250,244,.2) 65%, rgba(244,250,244,0) 100%),
      url("../../../image/catalog/tc-mobile-v3/hero-industrial-mobile.jpg") center right / cover no-repeat;
    border-bottom: 1px solid #dbe7dc;
  }

  .tc-m3-hero-copy {
    width: 61%;
    padding: 23px 0 17px 37px;
    position: relative;
    z-index: 3;
  }

  .tc-m3-hero h1 {
    margin: 0 0 9px;
    color: #0d4f29;
    font-size: clamp(26px, 8vw, 37px);
    line-height: 1.05;
    font-weight: 900;
    letter-spacing: -.7px;
  }

  .tc-m3-hero-copy > p {
    margin: 0;
    color: #183c29;
    font-size: 13px;
    line-height: 1.55;
    font-weight: 700;
  }

  .tc-m3-hero-points {
    display: flex;
    gap: 7px;
    margin-top: 16px;
    font-size: 8px;
    color: #1f6638;
    white-space: nowrap;
  }

  .tc-m3-hero-points i {
    color: #09943d;
    margin-right: 2px;
  }

  .tc-m3-slider-arrow {
    width: 28px;
    height: 43px;
    padding: 0;
    position: absolute;
    z-index: 5;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: rgba(2,109,45,.88);
    color: #fff;
    font-size: 13px;
  }

  .tc-m3-slider-prev {
    left: 0;
    border-radius: 0 18px 18px 0;
  }

  .tc-m3-slider-next {
    right: 0;
    border-radius: 18px 0 0 18px;
  }

  .tc-m3-slider-dots {
    position: absolute;
    z-index: 5;
    left: 50%;
    bottom: 9px;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
  }

  .tc-m3-slider-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #7d9f83;
  }

  .tc-m3-slider-dots .is-active {
    background: #07572a;
  }

  /* โทร / Add LINE */
  .tc-m3-contact-row {
    padding: 13px 10px;
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 8px;
    background: #fff;
  }

  .tc-m3-contact {
    min-height: 70px;
    padding: 10px 8px;
    border-radius: 10px;
    color: #fff !important;
    text-decoration: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    box-shadow: 0 4px 11px rgba(0,0,0,.13);
  }

  .tc-m3-contact-call {
    background: linear-gradient(135deg,#ed241d,#d30d09);
  }

  .tc-m3-contact-line {
    background: linear-gradient(135deg,#12bd43,#02952f);
  }

  .tc-m3-contact-symbol {
    font-size: 29px;
    line-height: 1;
  }

  .tc-m3-line-symbol {
    width: 35px;
    height: 29px;
    border-radius: 50%;
    background: #fff;
    color: #09a638;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: 900;
    position: relative;
  }

  .tc-m3-line-symbol::after {
    content: "";
    position: absolute;
    left: 5px;
    bottom: -5px;
    border-width: 7px 7px 0 0;
    border-style: solid;
    border-color: #fff transparent transparent transparent;
  }

  .tc-m3-contact strong,
  .tc-m3-contact small {
    display: block;
    color: #fff;
  }

  .tc-m3-contact strong {
    font-size: 17px;
    line-height: 1.05;
    font-weight: 900;
  }

  .tc-m3-contact small {
    margin-top: 5px;
    font-size: 8px;
    line-height: 1.2;
    font-weight: 700;
    white-space: nowrap;
  }

  /* หัวข้อหมวดสินค้าแบบมีเส้น */
  .tc-m3-category-section {
    padding: 0 10px 11px;
    background: #fff;
  }

  .tc-m3-title-with-lines {
    min-height: 49px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
  }

  .tc-m3-title-with-lines span {
    height: 1px;
    background: linear-gradient(90deg,transparent,#0a7735);
  }

  .tc-m3-title-with-lines span:last-child {
    background: linear-gradient(90deg,#0a7735,transparent);
  }

  .tc-m3-title-with-lines h2 {
    margin: 0;
    color: #174c2c;
    font-size: 19px;
    line-height: 1;
    font-weight: 900;
  }

  /* การ์ดหมวดสินค้า 2x2 */
  .tc-m3-category-grid {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 7px;
  }

  .tc-m3-category-card {
    overflow: hidden;
    border: 1px solid #dce5dd;
    border-radius: 7px;
    background: #fff;
    color: #fff !important;
    text-decoration: none !important;
    box-shadow: 0 2px 7px rgba(0,0,0,.08);
  }

  .tc-m3-category-card > img {
    width: 100%;
    height: 125px;
    display: block;
    object-fit: cover;
    background: #eef3ef;
  }

  .tc-m3-category-bar {
    min-height: 53px;
    padding: 7px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    background: linear-gradient(135deg,#087832,#075326);
  }

  .tc-m3-category-bar strong,
  .tc-m3-category-bar small {
    display: block;
    color: #fff;
  }

  .tc-m3-category-bar strong {
    font-size: 13px;
    line-height: 1.15;
    font-weight: 900;
  }

  .tc-m3-category-bar small {
    margin-top: 2px;
    font-size: 7px;
    line-height: 1;
    font-weight: 700;
  }

  .tc-m3-category-bar > i {
    font-size: 22px;
    opacity: .95;
  }

  /* จุดเด่น 4 ช่อง */
  .tc-m3-benefit-row {
    padding: 12px 7px;
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    background: #fff;
    border-top: 1px solid #edf1ed;
    border-bottom: 1px solid #e4ebe5;
  }

  .tc-m3-benefit-row > div {
    min-width: 0;
    padding: 0 4px;
    text-align: center;
    border-right: 1px solid #e7ece8;
  }

  .tc-m3-benefit-row > div:last-child {
    border-right: 0;
  }

  .tc-m3-benefit-row i {
    display: block;
    margin-bottom: 5px;
    color: #087a36;
    font-size: 22px;
  }

  .tc-m3-benefit-row strong,
  .tc-m3-benefit-row small {
    display: block;
  }

  .tc-m3-benefit-row strong {
    min-height: 28px;
    color: #18522f;
    font-size: 9px;
    line-height: 1.25;
    font-weight: 900;
  }

  .tc-m3-benefit-row small {
    margin-top: 4px;
    color: #5d7164;
    font-size: 7px;
    line-height: 1.25;
  }

  /* สินค้าแนะนำ 4 ช่อง */
  .tc-m3-featured {
    padding: 9px 8px 14px;
    background: #fff;
  }

  .tc-m3-featured-heading {
    min-height: 41px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .tc-m3-featured-heading h2 {
    margin: 0;
    color: #164b2b;
    font-size: 19px;
    font-weight: 900;
  }

  .tc-m3-featured-heading button {
    border: 0;
    background: transparent;
    color: #196334;
    font-size: 10px;
    font-weight: 800;
  }

  .tc-m3-featured-grid {
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 5px;
  }

  .tc-m3-product-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid #dfe7e0;
    border-radius: 7px;
    background: #fff;
    color: #16291d !important;
    text-decoration: none !important;
    text-align: center;
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
  }

  .tc-m3-product-card img {
    width: 100%;
    height: 83px;
    display: block;
    object-fit: cover;
    background: #f1f4f2;
  }

  .tc-m3-product-card strong {
    min-height: 44px;
    padding: 6px 3px 3px;
    display: block;
    font-size: 8px;
    line-height: 1.35;
    font-weight: 800;
  }

  .tc-m3-product-card span {
    margin: 0 4px 5px;
    min-height: 22px;
    border-radius: 4px;
    background: #098137;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 7px;
    font-weight: 800;
  }

  /* ซ่อนเมนูเดิม แล้วใช้ hamburger เปิดเป็นแผง */
  #menu {
    display: none !important;
  }

  body.tc-m3-menu-open #menu {
    display: block !important;
    position: fixed;
    z-index: 10030;
    top: 58px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 58px);
    margin: 0;
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    background: #07572a;
    box-shadow: 0 10px 22px rgba(0,0,0,.24);
  }

  body.tc-m3-menu-open #menu .navbar-header {
    display: none;
  }

  body.tc-m3-menu-open #menu .navbar-collapse {
    display: block !important;
    height: auto !important;
    padding: 0;
  }

  body.tc-m3-menu-open #menu .nav {
    margin: 0;
  }

  body.tc-m3-menu-open #menu .nav > li > a {
    padding: 13px 16px;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.1);
    font-weight: 700;
  }

  body.tc-m3-menu-open #menu .dropdown-menu {
    position: static;
    float: none;
    width: auto;
    border: 0;
    box-shadow: none;
    background: #fff;
  }

  /* หน้าสินค้า หมวดสินค้า และผลค้นหา ใช้เนื้อหา OpenCart */
  body.tc-m3-inner #content {
    padding-left: 10px;
    padding-right: 10px;
  }

  body.tc-m3-inner #content::after,
  body.tc-m3-inner .row::after {
    content: "";
    display: table;
    clear: both;
  }

  body.tc-m3-inner #product-category,
  body.tc-m3-inner #product-search,
  body.tc-m3-inner #product-product,
  body.tc-m3-inner #common-home {
    width: 100%;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
  }

  body.tc-m3-inner .product-layout {
    width: 50% !important;
    float: left;
    padding-left: 4px;
    padding-right: 4px;
  }

  body.tc-m3-inner .product-thumb {
    overflow: hidden;
    border: 1px solid var(--tc3-border);
    border-radius: 8px;
    background: #fff;
  }

  /* Bottom nav สีเขียวตามภาพ */
  .tc-m3-bottom-nav {
    position: fixed;
    z-index: 10050;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: linear-gradient(135deg,#07572a,#064722);
    box-shadow: 0 -5px 14px rgba(0,0,0,.18);
  }

  .tc-m3-bottom-nav.tc-mobile-only {
    display: grid !important;
    grid-template-columns: repeat(4,minmax(0,1fr));
  }

  .tc-m3-bottom-nav a,
  .tc-m3-bottom-nav button {
    padding: 4px 2px 5px;
    border: 0;
    background: transparent;
    color: #fff !important;
    text-decoration: none !important;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 8px;
    font-weight: 700;
  }

  .tc-m3-bottom-nav a:first-child {
    background: rgba(255,255,255,.07);
  }

  .tc-m3-bottom-nav i {
    font-size: 18px;
  }
  /*
   * v3.3 VERIFIED FAIL-SAFE
   * กฎนี้อยู่ท้ายไฟล์เพื่อชนะกฎเก่าและ Cache CSS รุ่นก่อน
   */
  .tc-m3-shell {
    min-height: 58px !important;
    height: auto !important;
    max-height: none !important;
  }

  /* เนื้อหา OpenCart แสดงไว้ก่อนเสมอ */
  body #content,
  body footer {
    visibility: visible !important;
    opacity: 1 !important;
  }

  body:not(.tc-m3-confirmed-home) #content,
  body.tc-m3-inner #content,
  body:not(.tc-m3-confirmed-home) footer,
  body.tc-m3-inner footer {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    margin-top: 0 !important;
  }

  /* ซ่อนเฉพาะเมื่อ JS ยืนยันหน้าแรกและเติมคลาสนี้ที่ Element โดยตรง */
  #content.tc-m3-original-home-hidden,
  footer.tc-m3-original-home-hidden {
    display: none !important;
  }

  body.tc-m3-inner #content {
    min-height: 240px !important;
    padding-top: 10px;
    padding-bottom: 20px;
    position: relative;
    z-index: 1;
  }

}

@media only screen and (max-width: 390px) {
  .tc-m3-hero { min-height: 238px; }
  .tc-m3-hero-copy { width: 64%; padding-left: 31px; }
  .tc-m3-hero h1 { font-size: 27px; }
  .tc-m3-hero-copy > p { font-size: 12px; }
  .tc-m3-hero-points { gap: 4px; font-size: 7px; }

  .tc-m3-contact strong { font-size: 15px; }
  .tc-m3-contact small { font-size: 7px; }

  .tc-m3-category-card > img { height: 113px; }
  .tc-m3-category-bar { min-height: 50px; }
  .tc-m3-category-bar strong { font-size: 12px; }

  .tc-m3-benefit-row strong { font-size: 8px; }
  .tc-m3-benefit-row small { font-size: 6.5px; }

  .tc-m3-product-card img { height: 74px; }
  .tc-m3-product-card strong { font-size: 7.2px; }
  .tc-m3-product-card span { font-size: 6.5px; }
}
