* {
  margin: 0;
  padding: 0;
  nonbox-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #999999;
  color: #262626;
  min-height: 100vh;
}

/* Header (grid page only) */
.header {
  position: sticky;
  top: 0;
  background: #999999;
  border-bottom: none;
  padding: 10px 12px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.site-logo {
  cursor: pointer;
  display: block;
  height: 36px;
  width: auto;
  max-width: 72%;
  margin: 0 auto;
  object-fit: contain;
  border-radius: 8px;
}

#search {
  position: fixed;
  left: 50%;
  right: auto;
  bottom: calc(18% - 20px);
  width: 33%;
  min-width: 140px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid #dbdbdb;
  border-radius: 8px;
  font-size: 16px;
  background: rgba(239,239,239,0.95);
  outline: none;
  z-index: 150;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  transition: top 0.15s ease, bottom 0.15s ease;
}

#search.search-active {
  top: calc(58px + 1.5in);
  bottom: auto;
  left: 50%;
  width: 33%;
  transform: translateX(-50%);
}

#search:focus {
  background: #fff;
  border-color: #a8a8a8;
}

/* Instagram-style Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding-bottom: 40px;
}

.card {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #efefef;
  cursor: pointer;
}

.card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Detail View */
.detail {
  position: fixed;
  inset: 0;
  background: #999999;
  z-index: 200;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.detail.hidden {
  display: none;
}

body.detail-open #search {
  display: none;
}

.detail-header {
  position: sticky;
  top: 0;
  background: #999999;
  border-bottom: none;
  padding: 10px 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}

.detail-header .site-logo {
  cursor: pointer;
  height: 36px;
  max-width: 62%;
}

.back-arrow {
  position: absolute;
  left: 12px;
  width: 48px;
  height: 28px;
  border: none;
  background: #808080;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
}


.detail-content {
  padding: 12px 8px 40px;
}

.detail-title {
  width: 96%;
  max-width: 420px;
  margin: 0 auto 10px;
  padding: 8px 12px;
  background: #808080; /* 50% gray */
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  border-radius: 10px;
  line-height: 1.3;
  overflow: hidden;
}

/* Framed media with a little breathing room */
.detail-media {
  position: relative;
  width: 96%;
  max-width: 420px;
  margin: 0 auto 8px;
  background: #999999;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #ddd;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.detail-media video,
.detail-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.detail-media video {
  position: absolute;
  inset: 0;
  background: transparent;
}
.detail-media video::-webkit-media-controls,
.detail-media video::-webkit-media-controls-start-playback-button,
.detail-media video::-webkit-media-controls-overlay-play-button {
  display: none !important;
}

.detail-media img.hidden,
.detail-media video.hidden {
  opacity: 0;
  pointer-events: none;
}

.detail-info {
  width: 96%;
  max-width: 420px;
  margin: 0 auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 88%;
  max-width: 360px;
  margin: 0 auto 6px;
}
.stats > * {
  min-width: 0;
}

.stat {
  background: #d9d9d9;
  border-radius: 10px;
  padding: 10px 4px 8px;
  text-align: center;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat .label {
  display: block;
  font-size: 11px;
  color: #8e8e8e;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat .value {
  font-size: 16px;
  font-weight: 600;
}

#detailStock {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  outline: none;
  color: #0095f6;
}

.order-cell {
  background: #0095f6;
  padding: 8px 4px;
  align-items: center;
}

.order-btn,
.order-btn:link,
.order-btn:visited,
.order-btn:hover,
.order-btn:active {
  display: block;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #fff;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}
.order-btn:hover {
  color: #ff3b30;
}

.order-cell input {
  width: 100%;
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  outline: none;
  color: #fff;
  padding: 0;
}

.order-cell input::placeholder {
  color: rgba(255,255,255,0.7);
}



.history-section {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 6px;
  align-items: start;
  width: calc(66% + 8px);
  max-width: 268px;
  margin-left: calc(6% - 25px);
}

.history-box {
  background: transparent;
  border-radius: 0;
  aspect-ratio: auto;
  padding: 0;
  display: block;
}

.history-box h3 {
  font-size: 12px;
  line-height: 1.15;
  font-weight: 600;
  color: #262626;
  margin: 0;
  padding-top: 0;
  text-align: right;
}


.history-list {
  font-size: 11px;
  color: #444;
  font-weight: 400;
  padding-left: 11px;
}

.history-item {
  padding: 0;
  margin: 0;
  border-bottom: none;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  line-height: 1.2;
  font-weight: 400;
}

.history-date {
  color: #666;
  font-size: 11px;
  font-weight: 400;
}

.history-qty {
  font-weight: 400;
  font-size: 11px;
  white-space: nowrap;
  padding-right: 15px;
}

.empty {
  color: #8e8e8e;
  font-size: 11px;
}

/* Responsive - larger phones / small tablets */
@media (min-width: 500px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}


/* Desktop / laptop type */
@media (hover: hover) and (pointer: fine) {
  .history-box h3 {
    font-size: 18px;
  }
  .history-section {
    width: 80%;
    max-width: none;
    margin-left: 6%;
  }
  .history-list,
  .history-date,
  .history-qty,
  .empty {
    font-size: 14px;
    color: #000;
    font-weight: 600;
    white-space: nowrap;
  }
  .stat .label {
    font-size: 13px;
  }
  .stat .value,
  #detailStock {
    font-size: 22px;
  }
  .order-btn {
    font-size: 16px;
  }
  .detail-title {
    font-size: 32px;
  }
}


/* Phone-like column on desktop */
@media (hover: hover) and (pointer: fine) {
  body {
    max-width: 430px;
    margin: 0 auto;
    min-height: 100vh;
    box-shadow: 0 0 40px rgba(0,0,0,0.25);
  }
  .header, .detail-header, .grid, .detail {
    max-width: 430px;
  }
  .detail {
    left: 50%;
    right: auto;
    width: 430px;
    transform: translateX(-50%);
  }
  #search {
    left: 50%;
    right: auto;
    width: 398px;
    transform: translateX(-50%);
  }
}

@media (hover: hover) and (pointer: fine) {
  .order-cell input[type=number] {
    width: 2.4em;
    max-width: 42px;
    padding: 0;
    margin: 0 auto;
  }
}

.nav-arrow {
  display: none;
}
@media (hover: hover) and (pointer: fine) {
  .nav-arrow {
    display: flex;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    width: 36px;
    height: 52px;
    border: none;
    border-radius: 8px;
    background: rgba(0,0,0,0.35);
    color: #fff;
    font-size: 32px;
    line-height: 1;
    align-items: center;
    justify-content: center;
    cursor: pointer;
  }
  .nav-prev { left: 8px; }
  .nav-next { right: 8px; }
  .nav-arrow:hover { background: rgba(0,0,0,0.55); }
}

.card { position: relative; }
.badge {
  position: absolute;
  bottom: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  color: #fff;
}
.badge-del {
  left: 6px;
  background: rgba(0,0,0,0.55);
}
.badge-ord {
  right: 6px;
  background: #808080;
  animation: orderPulse 6.5s ease-in-out infinite;
}
@keyframes orderPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
