:root {
  --bg-color: #111;
  --text-color: #eee;
  --border-color: #222;
}

/* Base styles */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  width: 100vw;
  overflow-x: hidden;
}
a, button, .filter-bar button, .sort-bar button { cursor: pointer; }
a { color: var(--text-color); text-decoration: underline; }
header, footer { max-width: 1140px; width: 100%; padding: 1rem; }
header {
  display: flex; align-items: center; border-bottom: 1px solid var(--border-color);
  gap: 1rem; flex-wrap: wrap; justify-content: space-between; position: relative;
}

.logo { width: 100px; height: 100px; border-radius: 50%; background: url('https://halat.nyc3.digitaloceanspaces.com/logo/logo.gif') no-repeat center/cover; }
.bio { flex: 1; min-width: 250px; }
.bio h1 { margin: 0; font-size: 1.8rem; }
.bio p { margin: 0.2rem 0 0 0; font-style: italic; font-size: 0.95rem; }

.search-bar { display: flex; justify-content: center; margin: 0.5rem 0; width: 100%; }
.search-bar input {
  padding: 0.5rem; width: 240px; border-radius: 4px; border: 1px solid var(--border-color);
  background: #222; color: #fff; margin: 0 auto; display: block;
}

.filter-bar, .sort-bar { text-align: center; margin-top: 1rem; }
.filter-bar button, .sort-bar button {
  margin: 0.2rem; padding: 0.4rem 0.8rem; border-radius: 4px;
  border: 1px solid var(--border-color); background: #222; color: #fff;
}
.filter-bar button.active, .sort-bar button.active { background: #444; }

/* Blue style for "Sort by For Sale" */
.sort-bar button[data-sort="forsale"] {
  background: #008CFF;
  border-color: #008CFF;
}

.social-icons, .delivery-icons { text-align: center; margin: 1rem 0; }
.social-icons a, .delivery-icons a { margin: 0 9px; color: var(--text-color); font-size: 1.4rem; }
.delivery-icons img {
  vertical-align: middle; border-radius: 5px; width: 50px; height: 50px;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* ===== Grid (ALWAYS 3 columns, perfect squares) ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr) !important;
  gap: 1px;
  width: 100%;
  max-width: 1140px;
  margin: 0 auto;
}
.grid-item {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  background: #000;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Media wrapper + badge — bulletproof square */
.img-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;     /* modern browsers */
  flex: 0 0 auto;
}
/* fallback square for older mobile browsers */
.img-wrapper::before {
  content: "";
  display: block;
  padding-top: 100%;        /* 1:1 square */
}
/* absolutely fill the square */
.img-wrapper img,
.img-wrapper video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #111;
}

/* Red notification badge (qty) */
.item-count-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: #e74c3c;
  color: #fff;
  border-radius: 50%;
  font-size: 0.8rem;
  padding: 4px 7px;
  font-weight: bold;
  display: none;
  box-shadow: 0 2px 6px #0008;
}
.item-count-badge.active { display: inline-block; }
/* larger on bigger screens */
@media (min-width: 768px) {
  .item-count-badge { font-size: 0.95rem; padding: 6px 9px; }
}
@media (min-width: 1200px) {
  .item-count-badge { font-size: 1.05rem; padding: 7px 11px; }
}

/* Controls BELOW image, ABOVE title */
.controls {
  order: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #111;
  padding: 6px 0;
  gap: 10px;
}
.controls.price-only { padding: 8px 0; }

/* Square +/- buttons */
.qty-btn {
  background: #008cff;
  color: #fff;
  border: none;
  border-radius: 6px;       /* square */
  width: 34px;
  height: 34px;
  font-size: 1.2rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 6px #0005;
}
.qty-btn:active { transform: scale(0.96); }

/* Mobile: smaller +/- and show price (no KD) between them */
@media (max-width: 767px) {
  .qty-btn { width: 28px; height: 28px; font-size: 1rem; }
  .controls:not(.price-only) .item-price {
    display: inline;
    font-size: 0.95rem;
  }
}

/* Desktop/tablet: price text a bit larger when visible */
@media (min-width: 768px) {
  .controls .item-price { font-size: 1.05rem; }
}

.grid-item-price, .item-price { color: #fff; font-weight: bold; }

/* Title — v1.0 size */
.grid-item .title {
  order: 2;
  flex: 0 0 auto;
  width: 100%;
  background: rgba(0,0,0,0.62);
  color: #fff;
  font-size: clamp(0.95rem, 2.4vw, 2rem);
  padding: 3px 4px 2px 4px;
  text-align: center;
  z-index: 2;
  line-height: 1.3;
}

/* Video/music overlay icon */
.video-icon {
  left:50%; top:50%; transform:translate(-50%,-50%);
  position:absolute;
  background: rgba(0,0,0,0.54);
  padding: 9px;
  border-radius: 50%;
  color: white;
  font-size: 1.5rem;
  z-index: 2;
  box-shadow: 0 0 3px #000b;
  display: flex; align-items: center; justify-content: center;
}

/* ===== Banners ===== */
.banner {
  width: 100%;
  max-width: 1140px;
  aspect-ratio: 3 / 1;
  overflow: hidden;
  margin: 1rem 0;
  position: relative;
  border-radius: 12px;
}
.banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
  position: absolute;
  top: 0; left: 0;
  transition: opacity 0.5s ease;
  border-radius: 12px;
}
.banner img.active { display: block; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.95);
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column;
  z-index: 1000;
  padding: 1rem;
  transition: opacity 0.3s ease;
}
.modal.active { display: flex; }
.modal-title {
  text-align: center;
  padding: 8px 0 0 0;
  font-size: clamp(1.2rem, 5vw, 3.2rem);
  font-weight: 600;
  color: #fff;
  word-break: break-word;
  line-height: 1.3;
}
/* Size modal media by viewport, not by text width; preserve aspect ratio */
.modal .img-wrapper {
  position: relative;
  width: 90vw;          /* tie to viewport */
  max-width: 90vw;
  height: auto;
  aspect-ratio: auto;   /* cancel square in modal */
}
.modal .img-wrapper::before { content: none; display: none; }
.modal .img-wrapper img,
.modal .img-wrapper video {
  position: static;     /* remove absolute fill */
  width: 100%;
  height: auto;
  max-height: 70vh;     /* keep within screen vertically */
  object-fit: contain;  /* no cropping */
  display: block;
}
/* Badge inside modal */
.modal .item-count-badge { position: absolute; top: 8px; right: 8px; }

.modal-content img, .modal-content video, .modal-content audio {
  max-width: 90vw; max-height: 80vh;
}
.modal-desc {
  text-align: center;
  max-width: 90vw;
  margin: 8px auto 0 auto;
  font-size: 1.1rem;
  line-height: 1.5;
}
.desc-ar {
  font-weight: bold;
  font-size: 1.15rem;
  direction: rtl;
  margin-bottom: 6px;
}
.desc-en {
  font-size: 1rem;
  font-style: italic;
  opacity: 0.9;
}
.modal-price {
  font-size: 1.25rem;
  font-weight: bold;
  margin-top: 10px;
  color: #28a745;
}
.modal-buy-btn {
  margin-top: 8px;
  background: #008CFF;
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 32px;
  font-weight: bold;
  font-size: 1.05rem;
  cursor: pointer;
}

@media (min-width: 900px) { .modal-title { font-size: 2.5rem; } }
@media (min-width: 1400px) { .modal-title { font-size: 3.2rem; } }

.close {
  position: absolute;
  top: 1rem; right: 1rem;
  font-size: 2rem;
  background: none; color: #fff; border: none;
  cursor: pointer; z-index: 3;
}
[data-folder], [data-sort], .close, a, button, .delivery-icons img { cursor: pointer; }

/* ===== Cart (floating) ===== */
.cart-icon-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  background: #000c;
  padding: 6px 12px;
  border-radius: 32px;
  box-shadow: 0 2px 10px #0006;
}
.cart-icon { font-size: 2.1rem; color: #00aaff; cursor: pointer; }
.cart-badge {
  position: absolute; top: -9px; right: -12px;
  background: #e74c3c; color: #fff;
  font-size: 0.95rem; border-radius: 50%;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; box-shadow: 0 2px 7px #0007; z-index: 10;
}

/* ===== Cart Modal ===== */
.cart-modal {
  display: none; position: fixed; z-index: 2000; left: 0; top: 0;
  width: 100vw; height: 100vh; overflow: auto; background: rgba(0,0,0,0.85);
  align-items: center; justify-content: center;
}
.cart-modal.active { display: flex; }
.cart-modal-content {
  background: #fff; color: #222; padding: 2rem 1.2rem; border-radius: 18px;
  min-width: 90vw; max-width: 480px; margin: auto; position: relative; box-shadow: 0 2px 16px #0005;
}
.close-cart { position: absolute; top: 0.2rem; right: 0.6rem; font-size: 2rem; color: #e74c3c; cursor: pointer; z-index: 30; }

.cart-item-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid #eee;
}
.cart-item-title { flex: 1; margin-right: 8px; }
.cart-item-qty { display: flex; align-items: center; gap: 5px; }

/* Square +/- in cart modal */
.cart-qty-btn {
  background: #2196f3; color: #fff; font-size: 1.3rem;
  width: 34px; height: 34px; border: none; border-radius: 6px;
  cursor: pointer; text-align: center; line-height: 34px;
}
.cart-qty-btn:active { background: #0b7dda; }

.cart-remove-btn { background: none; border: none; color: #d32f2f; font-size: 1.6rem; margin-left: 9px; cursor: pointer; }
.cart-price { font-weight: bold; color: #129d39; font-size: 1.08rem; }

.cart-footer {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Mobile: center the Total, button on new line, then Clear link */
@media (max-width: 600px) {
  .cart-footer {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }
  .cart-total {
    width: 100%;
    text-align: center;
    margin-bottom: 6px;
  }
  .cart-checkout-btn {
    width: 90%;
    max-width: 360px;
    margin: 0 auto;
  }
  .cart-clear-link {
    display: inline-block;
    width: 100%;
    text-align: center;
  }
}

.cart-checkout-btn {
  background: #008CFF; color: #fff; padding: 12px 28px; border-radius: 32px;
  border: none; font-size: 1.09rem; font-weight: bold; cursor: pointer; margin-right: 8px; box-shadow: 0 2px 7px #0002;
}
.cart-clear-link { color: #e74c3c; font-size: 1rem; cursor: pointer; margin-left: 8px; text-decoration: underline; }
.cart-total { font-weight: bold; font-size: 1.18rem; color: #222; }
