/* レイアウト（幅広 / 中央寄せ） */
.kwd-wrap { width: min(1600px, 94vw); margin: 0 auto; padding: 8px 1vw; }
.kwd-wrap .tool-heading { margin: 8px 0; font-size: 20px; }
.kwd-wrap .desc { color:#555; margin-bottom: 12px; }
/* はみ出し抑止の基本 */
.kwd-wrap, .kwd-wrap * { box-sizing: border-box; max-width: 100%; }

/* 40/60 レイアウト（PC） */
.kwd-panels {
  display:grid;
  grid-template-columns: 2fr 3fr;
  gap: 16px;
}
.input-panel { grid-column: 1 / -1; } /* 入力パネルは横幅いっぱい（PCでもOK） */
.panel {
  background:#fff; border:1px solid #ddd; border-radius:10px; padding:16px;
  box-shadow:0 1px 2px rgba(0,0,0,.04);
  /* 🔧 Gridのはみ出し防止：子要素は最小幅0で親に合わせて縮む */
  min-width: 0;
  width: 100%;
}
#kwd-input { width:100%; max-width:100%; height:180px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.controls {
  margin-top:8px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  flex-wrap:wrap;
}

.controls-left {
  font-size:12px;
  color:#555;
  order: 2;
}

.controls-right {
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
  order: 1;
}

.kwd-counter {
  font-size:12px;
  color:#555;
}

/* ツールバー */
.token-toolbar { display:flex; align-items:center; gap:10px; margin-bottom:8px; flex-wrap:wrap; }
.kwlist-toolbar { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:8px; flex-wrap:wrap; }
.kwlist-left { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.kwlist-right { display:flex; align-items:center; gap:8px; }

/* KW一覧：コピー / 一括削除 / 一括復元 行 */
.kwlist-copy-row {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin:0 0 8px 0;
  flex-wrap:wrap;
}

.kwlist-copy-left {
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

/* ページネーション行 */
.kwlist-pager {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin:0 0 8px 0;
  flex-wrap:wrap;
}

.kwlist-pager-left {
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.kwlist-pager-right {
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

.kwlist-pager select {
  max-width:100%;
}

/* 除外チェックを次行で通常サイズに */
.exclude-one {
  flex-basis:100%;
  margin-top:4px;
  font-size:inherit;
  color:#333;
  line-height:1.4;
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:8px;
}

.exclude-one-inner {
  display:inline-block;
}

/* タブのアクティブ */
.kwlist-toolbar .button.active { background:#1176d4; color:#fff; border-color:#1a5a8a; }

/* テーブル＆ヘッダ固定 */
.table-wrap { max-height: 60vh; overflow:auto; border:1px solid #e5e5e5; border-radius:8px; }
.wp-list-table { width:100%; border-collapse: collapse; }
.wp-list-table.sticky-head thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f6f7f7; box-shadow: inset 0 -1px 0 #ddd;
  text-align:left; color:#333;
}
td.num, th.num { text-align:right; }

/* 行状態 */
.row-deleted { background:#fee !important; }

/* 単語テーブル：クリック中の行を緑ハイライト */
#tokens-table tbody tr.active { background:#e6f4ea !important; }

/* 左の単語リンク */
.token-link { color:#1176d4; cursor:pointer; text-decoration:underline; }

/* ソートヘッダ */
th.sortable { cursor:pointer; }
th.sortable::after { content:" ⇵"; color:#666; }

/* ---- Chip（少し小さく） ---- */
.chip-bar { display:none; flex-wrap:wrap; gap:4px; margin: 0 0 6px 0; }
.chip-bar.visible { display:flex; }
.chip {
  display:inline-flex; align-items:center; gap:4px;
  padding:4px 8px; border:1px solid #ddd; border-radius:999px;
  background:#f8f9fa; color:#333; cursor:pointer; user-select:none;
  font-size: 11px; line-height: 1.2;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.chip .count { font-size:10px; color:#555; }
.chip.active { background:#e6f4ea; border-color:#34a853; color:#1e4620; box-shadow:0 0 0 2px rgba(52,168,83,.15) inset; }
.chip:hover { border-color:#999; }

/* KW一覧：削除行の見た目 */
#kw-table tbody tr.row-deleted td { background:#fdecea !important; color:#8a1f17; }

/* KW一覧リンク */
#kw-table tbody td a { color:#1176d4; text-decoration: underline; }
#kw-table tbody td a:hover { text-decoration: underline; }

/* ---- インライン編集 ---- */
.cell-flex {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.kw-edit-btn {
  border: none;
  background: transparent;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  margin-left: auto;
}

.kw-edit-btn i { font-size: 14px; }

.kw-edit-btn:focus {
  outline: 2px solid rgba(17,118,212,.2);
  outline-offset: 2px;
}

.kw-edit-input, .vol-edit-input {
  width: 100%; max-width: 100%;
  padding: 4px 6px;
  border: 1px solid #cfd8e3; border-radius: 6px;
  font: inherit;
}
.vol-edit-input { max-width: 120px; }

/* =========================================================
   レスポンシブ対応
   1) 1022px以下：1カラム（縦並び）
   2) 630px以下：さらに余白縮小＆内側スクロール最適化
   ========================================================= */

/* 1) 1022px以下：縦並び化＆はみ出し防止 */
@media (max-width: 1022px) {
  .kwd-wrap { width: 100%; padding: 8px 12px; }

  /* パネルを縦並びに */
  .kwd-panels { grid-template-columns: 1fr; }
  .input-panel { grid-column: 1 / 2; }

  /* ツールバーは縦積み寄せ */
  .kwlist-toolbar { flex-direction: column; align-items: stretch; gap: 6px; }
  .kwlist-left { flex-wrap: wrap; }
  .kwlist-right { align-self: flex-end; }

  /* 各パネルの横はみ出しを根こそぎ防止 */
  .kwd-panels > .panel { min-width: 0; max-width: 100%; overflow: visible; }

  /* テーブルは内側だけ横スクロール（画面はみ出しなし） */
  .table-wrap { max-height: none; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .wp-list-table { table-layout: fixed; min-width: 560px; }
  .wp-list-table th, .wp-list-table td { white-space: normal; word-break: break-word; }
}

/* 2) 630px以下：さらに詰める（630px問題の解消） */
@media (max-width: 630px) {
  .panel { padding: 12px; border-radius: 8px; }
  .controls { gap: 6px; }
  #kwd-input { height: 160px; }

  .kwlist-toolbar { gap: 4px; }
  .kwlist-left, .kwlist-right { width: 100%; }
  .kwlist-right { display:flex; justify-content: flex-end; }

  /* テーブルの最小幅を下げ、内側スクロールを維持 */
  .wp-list-table { min-width: 520px; }
  .chip { padding: 2px 6px; font-size: 10.5px; }
  .chip .count { font-size: 10px; }
  .kw-edit-btn i { font-size: 13px; }
}
