/*!
 * Khôi Anh Home — redesign layer (GĐ1: tokens + header + điều hướng)
 * File: flatsome-child/assets/css/kah-redesign.css
 * Nạp sau style.css của child theme. Không sửa Flatsome gốc.
 * Mobile-first: style gốc cho <850px, desktop trong @media (min-width:850px) — khớp breakpoint medium của Flatsome.
 * Rollback: bỏ dòng wp_enqueue_style('kah-redesign') trong functions.php.
 */

/* ---------- 1. Design tokens ---------- */
:root {
  --kah-blue: #1877F2;          /* màu thương hiệu — cố định */
  --kah-blue-dark: #0a3d78;     /* đang dùng trên site */
  --kah-blue-soft: #eaf3ff;
  --kah-text: #14233d;
  --kah-muted: #5b6472;
  --kah-line: #e4e8ee;
  --kah-surface-alt: #f5f8fc;
  --kah-price: #ed2024;         /* chỉ dùng cho giá / cảnh báo */
  --kah-radius-sm: 8px;
  --kah-radius: 12px;
  --kah-tap: 48px;              /* ≥44px theo WCAG 2.5.8 */
  --kah-focus: 0 0 0 3px rgba(24, 119, 242, .45);
  --kah-shadow: 0 4px 20px rgba(16, 45, 91, .08);
  --kah-font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Focus nhìn thấy được cho mọi phần tử điều hướng */
.header-wrapper a:focus-visible,
.header-wrapper button:focus-visible,
.mobile-sidebar a:focus-visible,
.mobile-sidebar button:focus-visible,
#mega-menu-wrap a:focus-visible,
#mega-menu-title:focus-visible,
.header-wrapper .search-field:focus-visible,
.mobile-sidebar .search-field:focus-visible {
  outline: none;
  box-shadow: var(--kah-focus);
  border-radius: var(--kah-radius-sm);
}

/* ---------- 2. Header mobile (<850px) ---------- */
@media (max-width: 849px) {
  .header-main .searchform-wrapper .search-field {
    height: 40px;
    font-size: 15px;            /* ≥15px: iOS không tự zoom ô nhập (cần 16px để chắc chắn) */
    border-radius: 999px 0 0 999px;
  }
  .header-main .searchform-wrapper .ux-search-submit {
    height: 40px;
    min-width: 44px;
    border-radius: 0 999px 999px 0;
  }
  /* Logo không bị cột tìm kiếm (flex:1 1 0) ép còn ~37px ở 360px; ô tìm kiếm tự co */
  /* Mobile: logo trái cạnh nút menu (không căn giữa) để ô tìm kiếm đủ rộng ≥160px ở 360px */
  .header-main .flex-col.flex-left { flex: 0 0 auto; }
  .header-main #logo {
    flex: 0 0 auto;
    width: clamp(76px, 22vw, 112px);
    margin: 0 10px 0 4px;
  }
  .header-main #logo img {
    width: 100%;
    height: auto;
    max-height: none;
  }
  .header-main .flex-col.flex-right { min-width: 0; }
  .header-main .mobile-nav > li.header-search-form { flex: 1 1 auto; min-width: 0; }
}

/* ---------- 3. Drawer mobile (Flatsome off-canvas #main-menu) ---------- */
.mobile-sidebar {
  font-family: var(--kah-font);
}
/* Chừa chỗ cho cụm Gọi/Zalo/TikTok (.kah-contact-bar) để mục cuối drawer không bị che */
.mobile-sidebar .sidebar-menu {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
.mobile-sidebar .nav-sidebar.nav-uppercase > li > a,
.mobile-sidebar .nav-sidebar .nav-sidebar-ul > li > a {
  text-transform: none;          /* chữ hoa có dấu khó đọc */
  letter-spacing: 0;
}
.mobile-sidebar .nav-sidebar > li > a {
  min-height: var(--kah-tap);
  display: flex;
  align-items: center;
  padding: 0 52px 0 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--kah-text);
  line-height: 1.3;
}
.mobile-sidebar .nav-sidebar > li {
  border-top: 1px solid var(--kah-line);
}
.mobile-sidebar .nav-sidebar > li.header-search-form {
  border-top: 0;
  padding: 12px 16px;
}
.mobile-sidebar .nav-sidebar .nav-sidebar-ul {
  background: var(--kah-surface-alt);
  padding: 4px 0 8px;
}
.mobile-sidebar .nav-sidebar .nav-sidebar-ul > li > a {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 52px 0 32px;
  font-size: 15px;
  font-weight: 500;
  color: var(--kah-text);
  line-height: 1.3;
}
.mobile-sidebar .nav-sidebar .nav-sidebar-ul .nav-sidebar-ul > li > a {
  padding-left: 44px;
  font-size: 14.5px;
  color: var(--kah-muted);
}
/* Nút mở accordion (Flatsome .toggle) đủ lớn để chạm */
.mobile-sidebar .nav-sidebar li .toggle {
  width: var(--kah-tap);
  height: var(--kah-tap);
  margin: 0;
  top: 0;
  right: 0;
  opacity: 1;
  color: var(--kah-blue);
}
.mobile-sidebar .nav-sidebar .nav-sidebar-ul li .toggle {
  height: 44px;
}
.mobile-sidebar .nav-sidebar li.active > a,
.mobile-sidebar .nav-sidebar li.current-menu-item > a {
  color: var(--kah-blue);
}
/* Mục "xem tất cả" cuối mỗi nhóm (class kah-nav-all gán trong WP Menus) */
.mobile-sidebar .nav-sidebar li.kah-nav-all > a {
  color: var(--kah-blue);
  font-weight: 600;
}

/* ---------- 4. Desktop (≥850px, header desktop của Flatsome hiện từ 850px) ---------- */
@media (min-width: 850px) {
  /* Ô tìm kiếm lớn ở header chính (sau khi chuyển vị trí trong Header Builder) */
  .header-main .flex-col.flex-grow .searchform-wrapper {
    width: 100%;
    max-width: 560px;
  }
  .header-main .searchform-wrapper .search-field {
    background-color: #fff !important;  /* Flatsome .dark .form-flat input dùng !important; t-custom reset về trong suốt */
    color: var(--kah-text) !important;
    height: 44px;
    font-size: 15px;
    padding-left: 18px;
    border-radius: 999px 0 0 999px;
  }
  .header-main .searchform-wrapper .ux-search-submit {
    height: 44px;
    min-width: 52px;
    border-radius: 0 999px 999px 0;
  }

  /* Thanh menu dưới */
  /* Thắng rule Customizer ".flex-col.flex-center ul.header-nav li.menu-item a" (in hoa) */
  .header-bottom .flex-col ul.header-nav.header-bottom-nav > li.menu-item > a {
    text-transform: none;
    letter-spacing: 0;
    font-size: 15px;
    font-weight: 600;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Ô search do Header Builder đặt vào header chính */
  .header-main ul.header-nav-main > li.header-search-form {
    flex: 1 1 420px;
    min-width: 340px;
    max-width: 560px;
    margin-right: 24px;
  }
  .header-main ul.header-nav-main > li.header-search-form .searchform-wrapper { width: 100%; }
  .header-main .searchform-wrapper .search-field::placeholder { color: var(--kah-muted); opacity: 1; }

  /* Mọi dropdown ở thanh menu dưới: chữ tối trên nền trắng (rule Customizer đang ép trắng !important) */
  .header-bottom .flex-col ul.header-nav li.menu-item .nav-dropdown li.menu-item > a {
    color: var(--kah-text) !important;
    text-transform: none;
    font-size: 15px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .header-bottom .flex-col ul.header-nav li.menu-item .nav-dropdown li.menu-item > a:hover,
  .header-bottom .flex-col ul.header-nav li.menu-item .nav-dropdown li.menu-item > a:focus-visible {
    color: var(--kah-blue) !important;
    background: var(--kah-blue-soft);
  }
  .header-bottom .flex-col ul.header-nav li.menu-item .nav-dropdown li.kah-nav-all > a {
    color: var(--kah-blue) !important;
    font-weight: 600;
  }

  /* Dropdown "Giải pháp công trình": 2 cột, có mô tả 1 dòng */
  .header-bottom .menu-item.kah-solutions > .nav-dropdown {
    min-width: 560px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 8px;
    padding: 12px;
    border: 1px solid var(--kah-line);
    border-radius: var(--kah-radius);
    box-shadow: var(--kah-shadow);
  }
  /* !important bắt buộc vì rule Customizer đang ép màu trắng bằng !important */
  .header-bottom .flex-col ul.header-nav li.menu-item.kah-solutions > .nav-dropdown > li.menu-item > a {
    color: var(--kah-text) !important;
    display: block;
    padding: 10px 12px;
    border-radius: var(--kah-radius-sm);
    font-size: 15px;
    font-weight: 600;
    color: var(--kah-text);
    text-transform: none;
    line-height: 1.35;
  }
  .header-bottom .flex-col ul.header-nav li.menu-item.kah-solutions > .nav-dropdown > li.menu-item > a:hover,
  .header-bottom .flex-col ul.header-nav li.menu-item.kah-solutions > .nav-dropdown > li.menu-item > a:focus-visible {
    background: var(--kah-blue-soft);
    color: var(--kah-blue) !important;
  }
  /* WP Menus → trường "Mô tả" của mục menu hiển thị bằng span này */
  .header-bottom .menu-item.kah-solutions .kah-nav-desc {
    text-transform: none;
    display: block;
    margin-top: 2px;
    font-size: 13px;
    font-weight: 400;
    color: var(--kah-muted);
  }

  /* Menu dọc "Danh mục sản phẩm" (OT Flatsome Vertical Menu) */
  #mega-menu-wrap #mega-menu-title {
    text-transform: none;
    font-size: 15px;
    font-weight: 700;
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  #mega_menu.sf-menu {
    width: 290px;
    border: 1px solid var(--kah-line);
    border-radius: 0 0 var(--kah-radius) var(--kah-radius);
    box-shadow: var(--kah-shadow);
    background: #fff;
  }
  #mega_menu.sf-menu > li > a {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0 36px 0 16px;
    font-size: 15px;
    font-weight: 600;
    color: var(--kah-text);
    text-transform: none;
    border-bottom: 1px solid var(--kah-line);
  }
  #mega_menu.sf-menu > li:last-child > a { border-bottom: 0; }
  /* child style.css đang tô đỏ #ed1c24 !important khi hover — đỏ chỉ dành cho giá */
  #mega_menu.sf-menu li:hover > a,
  #mega_menu.sf-menu li.sfHover > a,
  #mega_menu.sf-menu li > a:hover,
  #mega_menu.sf-menu li > a:focus-visible {
    background: var(--kah-blue-soft) !important;
    color: var(--kah-blue) !important;
  }
  #mega_menu.sf-menu li:hover,
  #mega_menu.sf-menu li.sfHover {
    background: #fff;
  }
  #mega_menu.sf-menu .sub-menu {
    min-width: 260px;
    padding: 8px;
    border: 1px solid var(--kah-line);
    border-radius: var(--kah-radius);
    box-shadow: var(--kah-shadow);
    background: #fff;
  }
  #mega_menu.sf-menu .sub-menu li a {
    min-height: 40px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: var(--kah-radius-sm);
    font-size: 14.5px;
    font-weight: 500;
    color: var(--kah-text);
    text-transform: none;
  }
  #mega_menu.sf-menu .sub-menu li a:hover {
    background: var(--kah-blue-soft);
    color: var(--kah-blue);
  }
}

/* Nút kính lúp nằm trên nền xanh: dùng outline trắng thay vì bóng xanh */
.header-wrapper .ux-search-submit:focus-visible {
  outline: 2px solid #fff !important;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .mobile-sidebar *,
  .header-wrapper *,
  #mega-menu-wrap * {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- 5. Cụm thông tin header (Hotline / Showroom) ---------- */
/* HTML header đổi <h3> → <span class="kah-svc-title"> để không lặp heading trên mọi trang */
.service-item .service-content .kah-svc-title {
  display: block;
  margin: 0 0 2px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: .02em;
}
.service-item .service-content p {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}
@media (min-width: 850px) {
  .header-main .service-grid {
    grid-template-columns: repeat(2, auto);
    gap: 8px 20px;
  }
}
/* 850–1279px: không đủ chỗ cho search + 2 khối → giữ Hotline, ẩn Showroom (vẫn có trong menu Liên hệ) */
@media (min-width: 850px) and (max-width: 1279px) {
  .header-main .service-grid { grid-template-columns: auto; }
  .header-main .service-grid > .service-item:nth-child(2) { display: none; }
  .header-main ul.header-nav-main > li.header-search-form { min-width: 300px; margin-right: 16px; }
}
/* 850–1099px: plugin OT ép cột "Danh mục sản phẩm" min-width 245px → menu ngang xuống dòng */
@media (min-width: 850px) and (max-width: 1099px) {
  #wide-nav > .flex-row > .flex-left { width: 200px; min-width: 200px; }
  .header-bottom .flex-col ul.header-nav.header-bottom-nav > li.menu-item > a { padding-left: 8px; padding-right: 8px; }
  .header-main .flex-grow > ul.header-nav-main { flex-wrap: nowrap; }
  .header-main ul.header-nav-main > li.html { flex: 0 0 auto; }
  .header-main .service-item .kah-svc-title { white-space: nowrap; }
  .header-main ul.header-nav-main > li.header-search-form { flex: 1 1 auto; min-width: 200px; }
}
@media (min-width: 850px) and (max-width: 959px) {
  .header-bottom .flex-col ul.header-nav.header-bottom-nav > li.menu-item { margin-left: 0; margin-right: 0; }
  .header-bottom .flex-col ul.header-nav.header-bottom-nav > li.menu-item > a { padding-left: 6px; padding-right: 6px; }
}
/* Mobile: ô tìm kiếm header nền trắng (Flatsome .dark .form-flat input bị t-custom reset trong suốt) */
@media (max-width: 849px) {
  .header-main .searchform-wrapper .search-field { background-color: #fff !important; color: var(--kah-text) !important; }
  .header-main .searchform-wrapper .search-field::placeholder { color: var(--kah-muted); opacity: 1; }
}
