/* ========================================
   RESET
======================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --pink: #d94b70;
  --pink-light: #fff1f5;
  --text: #292529;
  --muted: #929096;
  --border: #eee8eb;
  --bg: #fafafa;
  --white: #fff;
  --shadow: 0 8px 30px rgba(67, 35, 46, 0.08);
}


/* ========================================
   BODY
======================================== */
body {
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(
      circle at 50% -10%,
      #fff1f5 0,
      transparent 34%
    ),
    var(--bg);
  color: var(--text);

  -webkit-tap-highlight-color: transparent;
}

body.modal-open {
  overflow: hidden;
}


/* ========================================
   HEADER
======================================== */
.header {
  position: sticky;
  top: 0;
  z-index: 1000;

  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);

  border-bottom: 1px solid var(--border);

  padding: 20px 0 16px;
  text-align: center;
}

.logo {
  font-size: clamp(21px, 3vw, 28px);
  letter-spacing: 3px;
  font-weight: 800;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}


/* ========================================
   CONTAINER
======================================== */
.container {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
}

.flex{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ========================================
   DESKTOP / MOBILE ONLY
======================================== */
.laptop-only {
  display: block;
}

.mobile-only {
  display: none;
}


/* ========================================
   TOOLBAR
======================================== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;

  margin: 18px 0;

  position: sticky;
  top: 77px;
  z-index: 900;

  padding: 8px 0;

  background: rgba(250, 250, 250, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}


/* ========================================
   SEARCH BOX
======================================== */
.search-box {
  flex: 1;

  height: 48px;

  display: flex;
  align-items: center;
  gap: 8px;

  padding: 0 12px;

  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;

  box-shadow: 0 5px 18px rgba(67, 35, 46, 0.05);
}

.search-icon {
  font-size: 22px;
  color: #aaa;
}

.search-box input {
  min-width: 0;
  flex: 1;

  height: 100%;

  border: 0;
  outline: 0;

  background: transparent;

  font-size: 15px;
}

.clear-search {
  display: none;

  width: 25px;
  height: 25px;

  border: 0;
  border-radius: 50%;

  background: #f1eef0;
  color: #777;

  cursor: pointer;
}

.clear-search.visible {
  display: block;
}


/* ========================================
   FALLBACK SEARCH INPUT
======================================== */
#searchInput {
  flex: 1;

  height: 48px;

  border: 1px solid var(--border);
  border-radius: 14px;

  padding: 0 14px;

  background: var(--white);

  font-size: 15px;

  outline: none;

  box-shadow: 0 5px 18px rgba(67, 35, 46, 0.05);
}

#searchInput:focus {
  border-color: var(--pink);
}


/* ========================================
   SORT BUTTON
======================================== */
.sort-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-self: center;
}

.sort-buttons button {

  height: 48px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-wrap: nowrap;
  background: #fff;
  color: var(--text);

  font-size: 13px;
  font-weight: 600;

  cursor: pointer;

  transition:
    background .2s ease,
    color .2s ease,
    border-color .2s ease;
}

.sort-buttons button:hover {
  border-color: var(--pink);
  color: var(--pink);
}

.sort-buttons button.active {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
}

@media (max-width: 600px) {
  .sort-buttons {
    gap: 7px;
   
  }

  .sort-buttons button {
    height: 40px;
    font-size: 12px;
    border-radius: 10px;
  }
}
/* ========================================
   REFRESH BUTTON
======================================== */
#refreshBtn {
  height: 48px;
  min-width: 48px;
  display: flex;
  justify-items: center;
  justify-content: space-around;
  align-items: center;
  gap: 8px;
  padding: 0 18px;

  border: none;
  border-radius: 14px;

  background: #222;
  color: #fff;

  cursor: pointer;

  font-size: 14px;

  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.1);

  transition:
    transform 0.15s ease,
    opacity 0.15s ease;
}

#refreshBtn:hover {
  opacity: 0.85;
}

#refreshBtn:active {
  transform: scale(0.96);
}


/* ========================================
   STATUS
======================================== */
.status {
  text-align: center;

  padding: 16px;

  color: var(--muted);
  font-size: 14px;
}


/* ========================================
   PRODUCT GRID
======================================== */
.product-grid {
  display: grid;

  grid-template-columns: repeat(4, minmax(0, 1fr));

  gap: 18px;

  padding-bottom: 40px;
}


/* ========================================
   PRODUCT CARD
======================================== */
.product-card {
  background: var(--white);

  border: 1px solid var(--border);
  border-radius: 17px;

  overflow: hidden;

  box-shadow: var(--shadow);

  cursor: pointer;
  user-select: none;

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.product-card:hover {
  transform: translateY(-3px);

  box-shadow:
    0 12px 32px rgba(67, 35, 46, 0.12);
}

.product-card:active {
  transform: scale(0.985);
}


/* ========================================
   PRODUCT IMAGE
======================================== */
.product-image {
  width: 100%;

  aspect-ratio: 1 / 1;

  object-fit: cover;

  display: block;

  background: #f5f5f5;

  transition: transform 0.35s ease;
}

.product-card:hover .product-image {
  transform: scale(1.025);
}


/* ========================================
   PRODUCT INFO
======================================== */
.product-info {
  padding: 14px;
}

.product-name {
  font-size: 15px;
  line-height: 1.4;

  min-height: 42px;

  margin-bottom: 8px;
}

.product-price {
  font-size: 18px;

  font-weight: 700;

  color: var(--pink);
}


/* ========================================
   EMPTY
======================================== */
.empty {
  grid-column: 1 / -1;

  text-align: center;

  padding: 60px 20px;

  color: var(--muted);
}


/* ========================================
   MODAL
======================================== */
.modal {
  position: fixed;

  inset: 0;

  z-index: 9999;

  display: none;

  align-items: center;
  justify-content: center;

  padding: 20px;
}

.modal.open {
  display: flex;
}


/* ========================================
   MODAL BACKDROP
======================================== */
.modal-backdrop {
  position: absolute;

  inset: 0;

  background: rgba(20, 14, 17, 0.72);

  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}


/* ========================================
   MODAL CONTENT
======================================== */
.modal-content {
  position: relative;

  z-index: 1;

  width: min(680px, 100%);

  max-height: calc(100dvh - 40px);

  overflow: auto;

  background: #fff;

  border-radius: 22px;

  box-shadow:
    0 25px 80px rgba(0, 0, 0, 0.28);

  animation: modalIn 0.2s ease-out;
}


/* ========================================
   MODAL ANIMATION
======================================== */
@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}


/* ========================================
   MODAL CLOSE
======================================== */
.modal-close {
  position: absolute;

  top: 12px;
  right: 12px;

  z-index: 2;

  width: 42px;
  height: 42px;

  border: 0;
  border-radius: 50%;

  background: rgba(255, 255, 255, 0.94);

  font-size: 29px;
  line-height: 1;

  box-shadow:
    0 3px 14px rgba(0, 0, 0, 0.12);

  cursor: pointer;
}


/* ========================================
   MODAL IMAGE
======================================== */
.modal-image-wrap {
  background: #f7f5f6;

  display: flex;

  justify-content: center;
  align-items: center;
}

.modal-image {
  width: 100%;

  max-height: 72dvh;

  object-fit: contain;

  display: block;
}


/* ========================================
   MODAL INFO
======================================== */
.modal-info {
  padding: 17px 20px 21px;
}

.modal-info h2 {
  font-size: 19px;

  line-height: 1.35;

  margin-bottom: 8px;
}

.modal-price {
  font-size: 22px;

  font-weight: 800;

  color: var(--pink);
}


/* ========================================
   TABLET
======================================== */
@media (max-width: 900px) {

  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .laptop-only {
    display: none;
  }

  .mobile-only {
    display: none;
  }
}


/* ========================================
   MOBILE
======================================== */
@media (max-width: 600px) {

  /* Container */
  .container {
    width: calc(100% - 16px);
  }


  /* Mobile / Laptop visibility */
  .laptop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }


  /* Header */
  .header {
    padding: 15px 0 12px;

    /*
      Header cao khoảng 67px.
      Toolbar sẽ nằm bên dưới.
    */
  }

  .logo {
    font-size: 20px;
  }

  .subtitle {
    font-size: 12px;
  }


  /* Toolbar */
  .toolbar {
    top: 67px;

    margin-top: 6px;

    gap: 7px;

    padding: 7px 0;
  }


  /* Search */
  .search-box {
    height: 44px;

    border-radius: 12px;
  }

  .search-box input {
    font-size: 14px;
  }


  #searchInput {
    height: 44px;

    border-radius: 12px;

    font-size: 14px;
  }


  /* Refresh */
  #refreshBtn {
    width: 44px;
    min-width: 44px;

    height: 44px;

    padding: 0;

    border-radius: 12px;
    display: none;
  }

  .refresh-label {
    display: none;
  }


  /* Product */
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));

    gap: 10px;
  }

  .product-card {
    border-radius: 13px;
  }

  .product-info {
    padding: 9px 10px 11px;
  }

  .product-name {
    font-size: 13px;

    min-height: 37px;

    margin-bottom: 5px;
  }

  .product-price {
    font-size: 16px;
  }


  /* Status */
  .status {
    padding: 10px;

    font-size: 12px;
  }


  /* ====================================
     MOBILE MODAL
     ==================================== */

  .modal {

    /*
      QUAN TRỌNG:
      Không dùng flex-end vì nó làm modal
      dính xuống đáy màn hình.
    */
    align-items: center;

    justify-content: center;

    padding: 16px;
  }


  .modal-content {

    width: 100%;

    max-width: 420px;

    max-height: 88dvh;

    margin: 0;

    border-radius: 20px;

    /*
      Đẩy modal lên nhẹ 25px
      để nhìn cân hơn trên điện thoại.
    */
    transform: translateY(-25px);
  }


  .modal-image {

    max-height: 62dvh;

    object-fit: contain;
  }


  .modal-close {
    top: 10px;
    right: 10px;

    width: 40px;
    height: 40px;
  }


  .modal-info {
    padding: 14px 16px 18px;
  }

  .modal-info h2 {
    font-size: 17px;
  }

  .modal-price {
    font-size: 20px;
  }
}


/* ========================================
   VERY SMALL PHONE
======================================== */
@media (max-width: 380px) {

  .container {
    width: calc(100% - 12px);
  }

  .product-grid {
    gap: 8px;
  }

  .product-info {
    padding: 8px;
  }

  .product-name {
    font-size: 12px;
  }

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

  .modal {
    padding: 10px;
  }

  .modal-content {
    max-height: 90dvh;

    transform: translateY(-15px);
  }
}