* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f8f8f8;
  color: #333;
  padding-bottom: env(safe-area-inset-bottom);
}

.header {
  background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
  color: white;
  padding: 26px 16px 12px;
  padding-top: calc(26px + env(safe-area-inset-top));
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.15);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
}

.recent-modal-header {
  font-size: 16px;
  font-weight: 700;
  color: #333;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #eee;
}

.bottom-bar-divider {
  width: 1px;
  height: 24px;
  align-self: center;
  background: rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

.bottom-bar-link {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
  transition: opacity 0.2s;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.bottom-bar-link:active {
  opacity: 0.6;
}

/* 問い合わせフォームへのフローティングボタン（右下・下部バーの上に浮かせる）。
   z-index は下部バー(100)より下・モーダル(200)より下にして、モーダル表示中は隠れるようにする。 */
.inquiry-fab {
  position: fixed;
  right: 16px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  background: #eb1626;
  color: #fff;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: opacity 0.2s, transform 0.2s;
}

.inquiry-fab:active {
  opacity: 0.8;
  transform: scale(0.97);
}

/* 右下フローティングボタン群（営業用一覧）。QR・問い合わせを横並びにする。
   グループ内では各ボタンの固定配置を解除し、このコンテナで位置を決める。
   customer.html は .fab-group を使わないので、単体の .inquiry-fab はそのまま。 */
.fab-group {
  position: fixed;
  right: 16px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: flex-end;   /* 折り返し時は右寄せで積む */
  flex-wrap: wrap;             /* 3つに増えても狭い画面で崩れないよう折り返す */
  gap: 10px;
  max-width: calc(100vw - 32px);
}

.fab-group .inquiry-fab,
.fab-group .print-fab,
.fab-group .qr-fab {
  position: static;
  right: auto;
  bottom: auto;
  z-index: auto;
}

/* 印刷用一覧ボタン（QR＝青・問い合わせ＝赤と色分けするスレート系） */
.print-fab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  background: #4a5568;
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.print-fab:active {
  opacity: 0.8;
  transform: scale(0.97);
}

/* 印刷用一覧ボタンはスマホ（1列表示の幅）では非表示。印刷はPC/タブレット想定のため。 */
@media (max-width: 499px) {
  .print-fab { display: none; }
}

/* 顧客ページQRボタン（問い合わせと同じピル形状・営業らしい青系で色分け） */
.qr-fab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  background: #357abd;
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: opacity 0.2s, transform 0.2s;
}

.inquiry-fab {
  white-space: nowrap;
}

.qr-fab:active {
  opacity: 0.8;
  transform: scale(0.97);
}

.header h1 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.update-date {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 12px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.customer-mode .update-date {
  color: #999;
}

.search-box {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.search-box input {
  background: none;
  border: none;
  color: white;
  font-size: 16px;
  flex: 1;
  outline: none;
}

.search-box input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.search-icon {
  margin-right: 8px;
  opacity: 0.7;
}

.search-clear {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  cursor: pointer;
  padding: 8px;
  margin: -8px -4px -8px 0;
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.customer-mode .search-clear {
  color: #999;
}

.filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 0 4px 0;
}

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
  scroll-behavior: smooth;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  padding: 7px 13px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  background: transparent;
  color: white;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.filter-btn.active {
  background: white;
  color: #4a90e2;
  border-color: white;
}

.filter-btn:active {
  transform: scale(0.95);
}

.filter-group-btn {
  padding: 7px 13px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.filter-group-btn.active {
  background: rgba(255, 255, 255, 0.35);
  border-color: white;
}

.filter-group-btn:active {
  transform: scale(0.95);
}

.filter-children-row {
  display: none;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0 2px 8px;
  scroll-behavior: smooth;
}

.filter-children-row::-webkit-scrollbar {
  display: none;
}

.filter-children-row.open {
  display: flex;
}

.container {
  padding: 12px;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  max-width: 600px;
  margin: 0 auto;
}

.product-card {
  background: white;
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.2s;
  cursor: pointer;
  display: flex;
  height: 110px;
}

.product-card:active {
  transform: scale(0.98);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.product-image {
  width: 110px;
  height: 110px;
  background: #fff;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #999;
  overflow: hidden;
  position: relative;
  padding-top: 8px;
}

.product-image img {
  /* width: 100%; */
  height: 100%;
  /* object-fit: cover; */
}

.image-count {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.product-details {
  flex: 1;
  min-width: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-name {
  font-size: 15px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-code {
  font-size: 12px;
  color: #999;
  margin-bottom: 4px;
}

.product-specs {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.product-size {
  font-size: 12px;
  color: #666;
}

.product-price {
  font-size: 16px;
  font-weight: 700;
  color: #e74c3c;
}

.customer-mode .product-price,
.customer-mode .detail-price {
  display: none !important;
}

/* customer-mode カラーテーマ（白ベース赤ライン） */
.customer-mode .bottom-bar {
  background: linear-gradient(135deg, #eb1626 0%, #c00e1c 100%);
}

.customer-mode .header {
  background: #fff;
  border-left: 4px solid #eb1626;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.customer-mode .header h1 {
  color: #eb1626;
}

.customer-mode .search-box {
  background: #f5f5f5;
}

.customer-mode .search-box input {
  color: #333;
}

.customer-mode .search-box input::placeholder {
  color: #999;
}

.customer-mode .filter-btn {
  border-color: #eb1626;
  color: #eb1626;
}

.customer-mode .filter-btn.active {
  background: #eb1626;
  color: #fff;
  border-color: #eb1626;
}

.customer-mode .filter-group-btn {
  background: rgba(235, 22, 38, 0.08);
  border-color: #eb1626;
  color: #eb1626;
}

.customer-mode .filter-group-btn.active {
  background: rgba(235, 22, 38, 0.18);
  border-color: #eb1626;
}

.customer-mode .spinner {
  border-top-color: #eb1626;
}

.customer-mode .badge {
  background: #fff0f1;
  color: #eb1626;
}

.customer-mode .category-badge {
  background: #fff0f1;
  color: #eb1626;
}

.pamphlet-badge {
  display: inline-block;
  background: #fff4e6;
  color: #f39c12;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 8px;
  white-space: nowrap;
}

.category-badge {
  display: none;
  background: #f0f7ff;
  color: #4a90e2;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  margin-right: 4px;
  margin-bottom: 4px;
}

.empty {
  text-align: center;
  padding: 40px 20px;
  color: #999;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.loading {
  text-align: center;
  padding: 40px 20px;
  color: #999;
}

.spinner {
  border: 3px solid #f0f0f0;
  border-top: 3px solid #4a90e2;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.info-bar {
  background: #fff3cd;
  color: #856404;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 12px;
  text-align: center;
}

.info-bar.offline {
  background: #d1ecf1;
  color: #0c5460;
}

/* モーダル */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal.active {
  display: flex;
  align-items: flex-start;
  padding-top: 80px;
}

.modal-content {
  width: 100%;
  background: white;
  border-radius: 16px 16px 0 0;
  padding: 0;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
  min-height: calc(100vh - 80px);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

.modal-close {
  position: sticky;
  top: 12px;
  width: 44px;
  height: 44px;
  background: white;
  border: none;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-left: auto;
  margin-right: 16px;
}

/* 顧客ページQRモーダルの中身（常に縦積み・中央寄せ） */
.qr-modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 24px 40px;
  text-align: center;
}

.qr-modal-title {
  font-size: 18px;
  font-weight: 700;
  color: #333;
  margin: 0 0 8px;
}

.qr-modal-desc {
  font-size: 13px;
  color: #666;
  line-height: 1.6;
  max-width: 320px;
  margin: 0 auto 20px;
}

.qr-modal-img {
  width: 260px;
  max-width: 80%;
  height: auto;
  border: 1px solid #eee;
  border-radius: 12px;
}

.qr-modal-link {
  display: inline-block;
  margin-top: 20px;
  padding: 12px 24px;
  background: #357abd;
  color: #fff;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}

.qr-modal-link:active {
  opacity: 0.8;
}

.qr-modal-url {
  margin-top: 12px;
  font-size: 12px;
  color: #999;
  word-break: break-all;
}

/* 画像スライダー */
.image-slider {
  position: relative;
  background: #f0f0f0;
  aspect-ratio: 1;
  overflow: hidden;
}

.slider-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.slides {
  display: flex;
  height: 100%;
  transition: transform 0.3s ease-out;
}

.slide {
  min-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.slider-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 24px;
  cursor: pointer;
  z-index: 5;
  transition: background 0.2s;
}

.slider-btn:active {
  background: rgba(0, 0, 0, 0.7);
}

.slider-btn.prev {
  left: 8px;
}

.slider-btn.next {
  right: 8px;
}

.slide-counter {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 6px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

/* 詳細情報 */
.detail-info {
  padding: 20px;
}

.detail-info h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.4;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  background: #f0f7ff;
  color: #4a90e2;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
}

.code {
  font-size: 13px;
  color: #999;
}

.detail-price {
  font-size: 28px;
  font-weight: 700;
  color: #e74c3c;
  margin-bottom: 12px;
}

.detail-specs {
  margin-bottom: 16px;
  padding: 12px;
  background: #f9f9f9;
  border-radius: 6px;
}

.spec-item {
  font-size: 14px;
  color: #555;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}

.spec-item:last-child {
  border-bottom: none;
}

.spec-item:empty {
  display: none;
}

.spec-label {
  font-weight: 600;
  color: #333;
  margin-right: 8px;
}

.detail-desc {
  font-size: 14px;
  color: #555;
  line-height: 1.6;
}

/* Media Queries */
@media (max-width: 480px) {
  .product-card {
    height: 110px;
  }

  .product-image {
    width: 110px;
    height: 110px;
    padding-bottom: 8px;
  }

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

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

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


  .detail-info {
    padding: 16px;
  }

  .detail-info h2 {
    font-size: 18px;
  }

  .detail-price {
    font-size: 24px;
  }

  /* モバイル画像を正方形で中央配置 */
  .image-slider {
    max-width: 80%;
    aspect-ratio: 1;
    margin: 0 auto 16px;
  }
}

/* タブレット向け（3列グリッド） */
@media (min-width: 500px) {
  .container {
    max-width: none;
    padding: 16px;
    padding-bottom: calc(125px + env(safe-area-inset-bottom));
  }

  #productsContainer {
    display: grid;
    /* 画面幅いっぱいに自動で列数を増やす（カードは小さいまま・PCでは多列に）。 */
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
  }

  .product-card {
    display: flex;
    flex-direction: column;
    height: auto;
    margin-bottom: 0;
  }

  .product-image {
    width: 100%;
    height: 150px;
    flex-shrink: 0;
  }

  .product-details {
    flex-direction: column;
    justify-content: flex-start;
    padding: 8px;
  }

  .product-name {
    font-size: 13px;
    margin-bottom: 4px;
  }

  .product-code {
    font-size: 10px;
    margin-bottom: 4px;
  }

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

  /* モーダル画像サイズ制限 */
  .image-slider {
    max-width: 60%;
    aspect-ratio: 1;
    margin: 0 auto;
  }
}

/* 大画面：列数は auto-fill が幅に応じて自動で増やすため固定列指定は不要。
   （旧: 4列固定。全幅表示のため撤去し、カードは小さいまま多列に） */

/* ===== 説明会モード（?present）=====
   大画面モニターに映しても、タブレット縦くらいの比率の「枠」に収めて表示する。
   通常の顧客・営業表示には一切影響しない（body.present-mode のときだけ有効）。
   sticky なヘッダー・fixed な下部バー・モーダルも同じフレーム幅に揃える。 */
body.present-mode {
  --frame-w: 800px;
  background: #f8f8f8;
  /* 枠外はごく薄いグレーのレターボックス */
}

/* ヘッダー・本文・モーダル中身をフレーム幅に収めて中央寄せ */
body.present-mode .header,
body.present-mode .container {
  max-width: var(--frame-w);
  margin-left: auto;
  margin-right: auto;
}

/* 本文（商品一覧）はフレーム内を白背景にして端末画面のように見せる */
body.present-mode .container {
  background: #fff;
}

/* ヘッダー：端末上部のように影を付けてフレームを際立たせる */
body.present-mode .header {
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.2);
}

/* 下部バー：画面中央のフレーム幅に合わせる（全幅に伸ばさない） */
body.present-mode .bottom-bar {
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--frame-w);
}

/* フローティングボタン：画面右端ではなくフレームの右端に合わせる（枠外に飛び出さない）。
   営業一覧は .fab-group、顧客ページは単体の .inquiry-fab を使う。 */
body.present-mode .fab-group,
body.present-mode .inquiry-fab {
  right: max(16px, calc(50% - var(--frame-w) / 2 + 16px));
}

/* 商品グリッド：モニター幅に関係なく3列で固定（大画面での4列化を防ぐ） */
body.present-mode #productsContainer {
  grid-template-columns: repeat(3, 1fr);
}

/* モーダル：背景オーバーレイは全画面のまま、中身だけフレーム幅に収めて中央寄せ。
   これでクリック時に商品画像が画面いっぱいに広がらない。 */
body.present-mode .modal.active {
  justify-content: center;
}

body.present-mode .modal-content {
  width: 100%;
  max-width: var(--frame-w);
  border-radius: 16px;
}

/* ===== 大画面(PC)の自動表示：一覧は画面全幅・モーダルだけ枠内 =====
   present-mode（?present の説明会モード）と違い、一覧（ヘッダー/本文/グリッド）は
   全幅のまま多列表示にする。モーダルだけは中身が画面いっぱいに広がらないよう枠幅に収める。 */
body.contain-modal {
  --frame-w: 560px;   /* PCのモーダル横幅。大きすぎると画像の粗が目立つので抑える */
}
/* PCでは画像も小さめに収める（大写しにして粗が目立たないように） */
body.contain-modal .image-slider {
  max-width: 300px;
}
body.contain-modal .modal.active {
  justify-content: center;
  align-items: center;   /* 上下も中央に（既定の上寄せ flex-start を上書き） */
  padding-top: 0;        /* 上寄せ用の余白を解除して真ん中に置く */
}
body.contain-modal .modal-content {
  width: 100%;
  max-width: var(--frame-w);
  border-radius: 16px;              /* 上だけでなく全角を丸める（下にくっつかない見た目） */
  min-height: 0;                    /* 高さを内容なりにして画面下に貼り付かせない */
  max-height: calc(100vh - 80px);  /* 高いときは中でスクロール（上下に余白を残す） */
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);  /* 下から浮くのではなく中央ダイアログの影 */
  animation: none;                 /* PCでは下から出るスライドを付けない（中央表示と矛盾するため） */
}
