/* 1. 共通設定（ベース・ユーティリティ） */

body {
  font-family: sans-serif;
  margin: 10px;
  background-color: #f4f4f4;
  color: #333;
}

/* PC・スマホ表示の切り替え */
.pc-only {
  display: block;
}
.sp-only {
  display: none;
}

/* ⚠ 点滅アニメーション（期限切れ警告用） */
@keyframes blinkWarn {
  0%,
  50% {
    opacity: 1;
  }
  51%,
  100% {
    opacity: 0.25;
  }
}

.warn-icon {
  display: inline-block;
  margin-left: 4px;
  animation: blinkWarn 1s step-end infinite;
}

/* ============================================================
   2. レイアウト構造（外枠・ヘッダー）
   ============================================================ */
.container {
  background: white;
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  max-width: 1200px;
  margin: auto;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  height: 40px;
}

h2 {
  font-size: 1.2rem;
  margin: 0;
}

.btn-main {
  padding: 6px 12px;
  cursor: pointer;
  background: #ff9800;
  color: white;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  font-size: 0.9rem;
}

/* ============================================================
   3. 検索・フィルターパネル
   ============================================================ */
.controls-wrapper {
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  background: #f9f9f9;
  overflow: hidden;
}

.controls-summary {
  padding: 8px 15px;
  background: #eee;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
}

.controls-content {
  padding: 15px;
  display: none;
}

.controls-content.active {
  display: block;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  margin-bottom: 10px;
}

/* モーダル内の入力欄共通 */
.search-box {
  padding: 5px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  width: 250px;
}

.filter-card {
  background: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid #ddd;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
}

.input-num {
  width: 35px;
  padding: 2px;
  text-align: center;
}

/* ============================================================
   4. テーブル基本設定
   ============================================================ */
.table-wrapper {
  max-height: 70vh;
  overflow-y: auto;
  border: 1px solid #ccc;
  background: white;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1000px;
}

td {
  border: 1px solid #ccc;
  padding: 8px;
  font-size: 13px;
}

tr:hover {
  background-color: #fff9f0;
  cursor: pointer;
}

/* 2列目（状態）を中央寄せ */
table td:nth-child(2) {
  text-align: center;
}

/* PC用：名前列（3列目）の固定設定 */
thead th:nth-child(3),
td:nth-child(3) {
  position: sticky;
  left: 0;
  z-index: 10;
  background: white;
}

thead th:nth-child(3) {
  z-index: 25;
  background-color: #e8e8e8;
}

tr:hover > td:nth-child(3) {
  background: #fff9f0;
}

/* 横スクロール時に名前列を強調 */
/* PC版：3列目（名前列）が左端に吸着した時のスタイル */
/* PC用：横スクロール時に名前列を強調（borderをbox-shadowに変更） */

/* ヘッダー：どっしりしたグレーで固定感を出す */
table.is-shifted thead th:nth-child(3) {
  background-color: #d4d4d4;
  border: none;
  box-sizing: border-box;
}

/* データ行：上品なグラデーションで可読性を高める */
table.is-shifted tbody td:nth-child(3) {
  background: linear-gradient(102deg, #fff, #f0ead4);
  border: none;
  box-shadow: inset 0 0 0 1px #e6e5e5;
  box-sizing: border-box;
  text-align: center;
}

/* ============================================================
   5. テーブルヘッダー・ソート機能
   ============================================================ */
thead th {
  position: sticky;
  top: 0;
  background-color: #eee;
  z-index: 20;
  border-bottom: 2px solid #ccc;
  border-right: 1px solid #bbb;
  /* padding: 8px; */
  text-align: center;
  font-size: 12px;
  user-select: none;
}

thead th:last-child {
  border-right: none;
}

/* .th-content-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: fit-content;
} */

.sortable-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 15px;
  /* border-radius: 7px; */
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

th.sortable {
  cursor: pointer;
}

.filter-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid #cfcfcf;
  background: #f7f7f7;
  font-size: 13px;
}

/* ホバー・アクティブ効果 */
.sortable-label:hover,
th.sortable:hover,
.filter-trigger:hover {
  /* background: #e9f2ff; */
  background: #aec5e5;
}

.sortable-label:active,
.filter-trigger:active {
  transform: translateY(1px);
}

/* ============================================================
   6. メニュー・ドロップダウン（固定配置系）
   ============================================================ */

/* フィルタードロップダウン */
.filter-dropdown {
  display: none;
  position: fixed;
  z-index: 2000;
  background: white;
  border: 1px solid #ccc;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  min-width: 180px;
  padding: 12px;
  border-radius: 6px;
  font-weight: normal;
}

.filter-dropdown.active {
  display: block;
}

.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.close-btn {
  cursor: pointer;
  font-size: 18px;
  color: #999;
  line-height: 1;
}

.close-btn:hover {
  color: #333;
}

.dropdown-btns {
  display: flex;
  gap: 5px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.btn-sm {
  padding: 3px 8px;
  cursor: pointer;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 3px;
  font-size: 11px;
}

/* ドロップダウン内のグリッド表示 */
.gender-grid,
.ff-grid,
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.gender-grid label,
.ff-grid label,
.status-grid label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: pointer;
}

/* 右クリックメニュー */
.ctx-menu {
  position: fixed;
  z-index: 2000;
  min-width: 180px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  padding: 6px;
}

.ctx-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.ctx-item:hover {
  background: #f3f3f3;
}
.ctx-item.danger {
  color: #d32f2f;
  font-weight: bold;
}
.ctx-item.danger:hover {
  background: #ffebee;
}

/* 既存の .ctx-item.danger を流用、または追加 */
.dropdown-item-danger {
  color: #d32f2f !important;
  font-weight: bold;
  border-top: 1px solid #eee; /* 区切り線 */
  margin-top: 5px;
}

.dropdown-item-danger:hover {
  background: #ffebee !important;
}

/* ============================================================
   7. パーツ要素（バッジ・写真等）
   ============================================================ */

/* 状態バッジ */
.status-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: bold;
  border: 2px solid var(--st-color, #999);
  color: var(--st-color, #333);
  background: var(--st-bg, #eee);
  width: fit-content;
  margin: 0 auto;
}

/* サムネイル写真 */
.thumb-cell {
  width: 50px;
  text-align: center;
  padding: 4px;
}

.cat-thumb {
  width: 50px;
  height: 50px;
  border-radius: 20%;
  object-fit: cover;
  background-color: #eee;
  border: 1px solid #ddd;
  display: block;
  margin: auto;
}

/* 警告テキスト（赤字） */
.alert-text {
  color: #d32f2f;
  font-weight: bold;
}
.filter-group .filter-card input {
  font-size: 1.5em;
  width: 4em;
}

/* ============================================================
   8. レスポンシブ設定（モバイル用 600px以下）
   ============================================================ */
@media (max-width: 600px) {
  /* スマホ用操作バー（チップのコンテナ） */
  .mobile-action-bar {
    display: flex;
    overflow-x: auto; /* 横スワイプ可能に */
    white-space: nowrap;
    gap: 8px;
    padding: 10px 5px;
    background: #f4f4f4;
    position: sticky;
    top: 0;
    z-index: 100; /* テーブルより上に */
    scrollbar-width: none;
  }
  .mobile-action-bar::-webkit-scrollbar {
    display: none;
  }

  /* チップの基本（共通） */
  .action-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px; /* 少し小さくして並びやすく */
    font-weight: bold;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    flex-shrink: 0; /* 幅を維持 */
  }

  /* 並べ替えボタン：少し色を付けて区別 */
  .action-chip.sort {
    background: #e9f2ff;
    border: 1px solid #b3d4ff;
    color: #0056b3;
  }

  /* フィルターボタン：標準的な白 */
  .action-chip.filter {
    background: white;
    border: 1px solid #ddd;
    color: #333;
  }

  /* ============================================================
     dualチップ：左=ソート / 右=▼（モーダル）
     ============================================================ */
  .action-chip.dual {
    padding: 0; /* 左右でpaddingを持つので本体は0 */
    overflow: hidden;
    border-radius: 20px; /* 既存チップと合わせる */
  }

  .action-chip.dual .dual-left,
  .action-chip.dual .dual-right {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-weight: bold;
  }

  /* 左（ソート側）：sortチップに合わせる */
  .action-chip.dual .dual-left {
    padding: 6px 12px;
    background: #e9f2ff;
    border: 1px solid #b3d4ff;
    color: #0056b3;
    border-right: none;
  }

  /* 右（▼）：目立つ＆押しやすい */
  .action-chip.dual .dual-right {
    padding: 6px 14px;
    min-width: 2em;
    /* font-size: 14px;  */
    background: #b4d4ff;
    border: 1px solid #b3d4ff;
    color: #333;
  }

  .action-chip.dual .dual-right:active,
  .action-chip.dual .dual-left:active {
    transform: scale(0.96);
    filter: brightness(0.92);
  }

  .filter-dropdown {
    max-width: calc(100vw - 16px);
  }

  .action-chip:active {
    transform: scale(0.95);
    filter: brightness(0.9);
  }

  /* テーブル構造の解除 */
  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  thead {
    display: none;
  }
  .pc-only {
    display: none !important;
  }
  .sp-only {
    display: block;
  }

  /* 行カードのデザイン */
  tr {
    margin-bottom: 10px;
    border: 1px solid #ddd !important;
    border-radius: 12px;
    background: #fff;
    padding: 8px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 8px;
  }

  /* 名前列（PC用3列目）はスマホカード内では非表示に（まとめ表示側で出すため） */
  td:nth-child(3) {
    display: none;
  }

  /* 写真セル */
  td.thumb-cell {
    width: 70px;
    height: 70px;
    padding: 0;
    border: none;
    order: 1;
  }

  .cat-thumb {
    width: 70px;
    height: 70px;
    border-radius: 8px;
  }

  /* スマホ用：まとめ表示（名前・状態・詳細） */
  .mobile-summary {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 13px;
    line-height: 1.3;
    width: fit-content;
  }

  .mobile-summary .m-name {
    font-size: 13px;
    color: #946969;
  }

  .mobile-summary .m-detail {
    font-size: 11px;
    color: #333;
  }

  /* スマホ用：状態セル（2列目）の固定と装飾 */
  td.status-cell,
  td:nth-child(2) {
    border: none;
    padding: 2px 0;
    order: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: 0 0 110px;
    position: sticky;
    left: 0;
    z-index: 1;
    width: 162px;
    background: #f9f9f9;
    border-radius: 6px;
  }

  .status-badge {
    font-weight: normal;
    border: 1px solid var(--st-color, #999);
  }

  /* 横スクロール時の強調（スマホ） */
  table.is-shifted #catList .status-cell,
  tr.is-shifted td.status-cell {
    background: #fff3d6;
    border: 1px solid #cccccc;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.12);
    border-color: #e0b46a;
  }

  /* 詳細項目（4列目以降）のグリッド表示 */
  td:nth-child(n + 4) {
    width: 10%;
    border: none;
    padding: 5px;
    background: #f9f9f9;
    border-radius: 4px;
    font-size: 11px;
    order: 3;
    display: flex;
    flex-direction: column;
  }

  /* 項目ラベルの追加 */
  td:nth-child(4)::before {
    content: "性別";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  td:nth-child(5)::before {
    content: "年齢";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  td:nth-child(6)::before {
    content: "FF結果";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  td:nth-child(7)::before {
    content: "最終ワクチン";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  td:nth-child(8)::before {
    content: "最新ノミ取り";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  td:nth-child(9)::before {
    content: "出身";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  td:nth-child(10)::before {
    content: "卒業先";
    color: #888;
    font-weight: bold;
    margin-bottom: 2px;
  }
  /* ヘッダー・操作系の調整 */
  .header-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    height: auto;
    gap: 8px;
  }

  .header-row h2 {
    display: none;
  }

  .header-row > div {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
  }

  .btn-main {
    padding: 3px 6px;
  }
  .controls-summary span {
    font-size: 12px;
  }
  #counter {
    white-space: nowrap;
  }

  /* フィルタードロップダウンをモーダルに　*/
  .filter-dropdown.active {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    display: block !important;
    visibility: visible !important;
    z-index: 9100 !important;
    width: 90% !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    padding: 15px;
    box-sizing: border-box;
  }

  /* 背景を暗くする擬似的な「幕」の代わりとして body にクラスを付ける手法 */
  body.modal-open::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1); /* 半透明の黒 */
    z-index: 2500;
    pointer-events: none;
  }

  .modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.23); /* 背景を暗くする */
    z-index: 9000;
  }

  .modal-overlay.active {
    display: block;
  }

  /* PC用の検索バーを消し、チップ(mobile-action-bar)に役割を譲る */
  .controls-wrapper.pc-only {
    display: none !important;
  }

  /* 検索チップだけ目立たせる */
  .action-chip.search {
    background: #fff3e0;
    border: 1px solid #ffb74d;
    color: #e65100;
  }

  /* 検索モーダル専用の調整 */

  .search-modal-style .filter-group {
    margin-bottom: 20px;
    flex-direction: column;
    align-items: flex-start;
  }

  .search-modal-style .search-box {
    height: 45px;
    font-size: 16px; /* Androidでズームされないサイズ */
  }

  .filter-group .filter-card input {
    font-size: 1.2em;
    width: 3.5em;
  }
  .dropdown-header.sp-only {
    display: flex;
  }
}
