/* ===== Common Layout (skeleton) ===== */
.aqb-container{
  max-width:980px;
  margin:20px auto;
  padding:0 12px;
  font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial;
  font-size:clamp(14px, 1.6vw, 16px);
}
.aqb-breadcrumbs{color:#666;margin:6px 0 12px}
.aqb-breadcrumbs .sep{margin:0 6px;color:#999}
.aqb-breadcrumbs .current{font-weight:600}

.aqb-card{
  background:#c7c7c7; /* 薄グレー */
  color:#111;
  border:1px solid #b5b5b5;
  border-radius:12px;
  padding:16px;
  margin:12px 0;
  box-shadow:0 1px 2px rgba(0,0,0,.20);
}
/* カード内テーブルは100% */
.aqb-card table{width:100% !important}
.aqb-card a{color:#0b3a5b}
.aqb-sec-title{font-weight:600;margin-bottom:10px;color:#111}

.aqb-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.aqb-row.-right{justify-content:flex-end}
.aqb-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
.aqb-col-span-2{grid-column:span 2 / span 2}
@media (max-width:640px){.aqb-grid{grid-template-columns:1fr}.aqb-col-span-2{grid-column:auto}}

/* 入力・ボタン（可変フォント継承） */
.aqb-input{
  width:100%;
  padding:8px 10px;
  border:1px solid #d9d9d9;
  border-radius:8px;
  background:#fff;
  color:#111;
  box-sizing:border-box;
  font-size:inherit;
  line-height:1.4;
}
.aqb-input--sm{width:auto;padding:6px 8px}
.aqb-label{display:block;margin:6px 0 4px;font-size:.92rem;color:#444}

.aqb-btn{
  border:1px solid #d1d5db;
  border-radius:10px;
  padding:8px 12px;
  background:#f9fafb;
  cursor:pointer;
  opacity:1;
  font-size:inherit;
  line-height:1.2;
  white-space:nowrap;
  display:inline-block;
  color:#111;
}
.aqb-btn.-primary{background:#111827;color:#fff;border-color:#111827}
.aqb-btn.-ghost{background:#ffffff;border-color:#d1d5db;color:#111}
.aqb-btn.-danger{background:#fee2e2;border-color:#fecaca}
.aqb-btn.-sm{padding:4px 8px;font-size:.9rem}
.aqb-btn + .aqb-btn{margin-left:8px}
.aqb-btn[disabled]{cursor:not-allowed;opacity:.6}

.aqb-small{font-size:.85rem}
.aqb-note{font-size:.9rem;color:#444;margin-top:8px}
/* 説明文を見やすいグレーに */
.aqb-muted{color:#6b7280;font-size:.92rem}
.editor-panel .aqb-small{color:#6b7280}

/* === 一般テーブル（下線のみ、実テーブル用） === */
.aqb-table{
  width:100%;
  border-collapse:collapse;
  margin-top:10px;
  font-size:inherit;
}
.aqb-table th,
.aqb-table td{
  border-bottom:1px solid #e5e5e5;
  padding:10px;
  vertical-align:middle;
  background:transparent;
  color:#111;
}

/* ステータス枠 */
.aqb-status{
  min-height:80px;white-space:pre-line;background:#f9fafb;
  border:1px dashed #e5e7eb;border-radius:8px;padding:10px;color:#111
}

/* === タブ === */
.aqb-tab-headers{display:flex;gap:6px;margin-bottom:8px}
.aqb-tab-btn{ border-radius: 10px; }
.aqb-tab-btn.is-active{ background:#111827;color:#fff;border-color:#111827 }
.aqb-tab-panel{display:none}
.aqb-tab-panel.is-active{display:block}

/* ページング・検索 */
.aqb-actions{display:flex;gap:8px;flex-wrap:wrap}
.aqb-list-toolbar{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.aqb-pagination{display:flex;gap:8px;align-items:center;justify-content:flex-end;margin-top:10px}
.aqb-search{min-width:240px}

/* ===== AI ビルド用テーブル（APIキー／パラメータ） ===== */
.aqb-ai-key-table,
.aqb-sb-param-table{
  width:100% !important;
  table-layout:fixed;
  border-collapse:collapse;
  border:none;
  font-size:inherit;
}
.aqb-ai-key-table th,
.aqb-ai-key-table td,
.aqb-sb-param-table th,
.aqb-sb-param-table td{
  padding:8px 0;
  vertical-align:middle;
  background:transparent;
  color:inherit;
  border:none;
  box-sizing:border-box;
}
/* 行の下線（最終行にも付与） */
.aqb-ai-key-table tr > th,
.aqb-ai-key-table tr > td,
.aqb-sb-param-table tr > th,
.aqb-sb-param-table tr > td{
  border-bottom:1px solid #dcdcdc;
}
/* APIキー行の左右比率 */
.aqb-ai-key-table .td-input{width:65%}
.aqb-ai-key-table .td-actions{
  width:35%;
  text-align:center;
  white-space:nowrap;
}
/* パラメータ側の不要な下余白を抑制 */
.aqb-ai-key-table .td-input .aqb-input{margin-bottom:0}
.aqb-sb-param-table td:last-child .aqb-input{margin-bottom:0}
#sb_theme.aqb-input,#sb_extra_notes.aqb-input{margin-bottom:0 !important}
/* パラメータテーブル：列幅%（colgroup と一致） */
.aqb-sb-param-table td:first-child{width:28%}
.aqb-sb-param-table td:last-child{width:72%}

/* ===== 問題ビルダー（表・横スクロール・モーダル） ===== */
.aqb-scroll-x{
  overflow-x:auto;
  background:#fff;
  border-radius:8px;
  margin-top:8px;
  padding:8px;
}
.aqb-builder-table{
  width:100%;
  min-width:1200px;
  border-collapse:collapse;
  font-size:inherit;
}
.aqb-builder-table th,
.aqb-builder-table td{
  border-bottom:1px solid #e5e5e5;
  padding:8px;
  vertical-align:middle;
  background:transparent;
  color:#111;
}

/* ===== モーダル（最前面固定 + 背景スクロール抑止対応） ===== */
.aqb-modal[aria-hidden="true"]{display:none}
.aqb-modal[aria-hidden="false"]{display:block}

/* モーダル全体を最前面 */
.aqb-modal{
  position:fixed;
  inset:0;
  z-index:2147483647; /* テーマのヘッダより上 */
}
/* 背景スクロール抑止用クラス（JSで付与/除去） */
body.aqb-modal-open{ overflow:hidden; }

.aqb-modal__overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  backdrop-filter:blur(2px);
  z-index:1;
}
.aqb-modal__content{
  position:fixed;
  left:50%; top:50%;
  transform:translate(-50%,-50%);
  width:min(900px,90vw);
  max-height:90vh;
  overflow:auto;
  background:#0f1117;            /* ダークテーマ */
  color:#e6edf3;
  border:1px solid #464646;      /* グレー枠 */
  border-radius:12px;
  padding:16px;
  box-shadow:0 12px 40px rgba(0,0,0,.45);
  z-index:2; /* overlay より上 */
}
.aqb-modal__header{
  display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;
  border-bottom:1px solid #2a2f3a;
}
.aqb-modal__close{
  background:#0f1117;
  color:#c8d1db;
  border:1px solid #464646;
  border-radius:10px;
  width:36px;height:36px;line-height:34px;text-align:center;font-size:18px;
  cursor:pointer;
  transition:background .15s ease, color .15s ease, border-color .15s ease, transform .05s ease;
}
.aqb-modal__close:hover{ background:#151922; color:#fff; border-color:#6a6a6a; }
.aqb-modal__close:active{ transform:scale(0.98); }
.aqb-modal__close:focus-visible{ outline:2px solid #3b82f6; outline-offset:2px; }

.aqb-code-block{
  width:100%;
  min-height:420px;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  font-size:13px;
  line-height:1.55;
  border:1px solid #464646;
  border-radius:10px;
  padding:12px 14px;
  box-sizing:border-box;
  background:#0b0e14;
  color:#e6edf3;
  caret-color:#8ab4f8;
  outline:none;
  resize:vertical;
}
/* スクロールバー */
.aqb-code-block::-webkit-scrollbar{height:10px;width:10px}
.aqb-code-block::-webkit-scrollbar-thumb{background:#2f3541;border-radius:8px;border:2px solid #0b0e14}
.aqb-code-block::-webkit-scrollbar-thumb:hover{background:#3a4150}
.aqb-code-block::-webkit-scrollbar-track{background:#0b0e14;border-radius:8px}

/* モーダル内ボタン（コントラスト） */
.aqb-modal .aqb-btn.-ghost{
  background:#0f1117;color:#e6edf3;border:1px solid #464646;
}
.aqb-modal .aqb-btn.-ghost:hover{ background:#151922; border-color:#6a6a6a; }
.aqb-modal .aqb-btn.-primary{
  background:#3b82f6;color:#fff;border:1px solid #2e6bd1;
}
.aqb-modal .aqb-btn.-primary:hover{ background:#2f6fe0; }

/* スクロール位置ジャンプ抑止（ブラウザのアンカー最適化対策） */
.aqb-tabs { overflow-anchor: none; }
.aqb-container { overflow-anchor: none; }

/* ===== 一覧ページ（実テーブル版） ===== */
.aqb-card .aqb-table thead th{
  padding:10px;
  border-bottom:1px solid #e5e5e5;
  text-align:left;
  vertical-align:middle;
  background:transparent;
}
.aqb-card .aqb-table tbody td{
  padding:10px;
  border-bottom:1px solid #e5e5e5;
  vertical-align:middle;
  background:#fff;
  color:#111;
  box-sizing:border-box;
}
/* 幅ユーティリティ（見出しに指定された .aqb-w64 / .aqb-w120 を尊重） */
.aqb-card .aqb-table .aqb-w64{  width:64px }
.aqb-card .aqb-table .aqb-w120{ width:120px }

/* タイトル列は左寄せ固定（thead/tbody 両方） */
.aqb-card .aqb-table thead th:nth-child(2),
.aqb-card .aqb-table tbody td:nth-child(2){
  text-align:left !important;
}

/* 編集/削除列はセル内を中央寄せ＋ボタンは全幅に */
.aqb-card .aqb-table thead th:nth-child(3),
.aqb-card .aqb-table thead th:nth-child(4),
.aqb-card .aqb-table tbody td:nth-child(3),
.aqb-card .aqb-table tbody td:nth-child(4){
  text-align:center;
}
.aqb-card .aqb-table tbody td:nth-child(3) .aqb-btn,
.aqb-card .aqb-table tbody td:nth-child(4) .aqb-btn{
  display:block;
  width:100%;
  margin:0;
  white-space:nowrap;
}

/* 追加の幅ユーティリティ（要望反映） */
.aqb-w64  { width:64px ; text-align:center; }
.aqb-w80  { width:80px; }
.aqb-w100 { width:100px; text-align:center; }
.aqb-w120 { width:180px; }   /* 正解など */
.aqb-w140 { width:160px; }   /* 選択肢/入力/HTML */
.aqb-w160 { width:160px; }
.aqb-w280 { width:450px; }   /* 問題 */
.aqb-builder-table input.aqb-input{margin-bottom:0}

/* 角丸の単一ソース */
:root{ --aqb-radius: 10px; }
.aqb-btn{ border-radius: var(--aqb-radius); }
.aqb-tab-btn{ border-radius: inherit; }
.aqb-tab-headers .aqb-btn,
.aqb-topbar .aqb-btn{ border-radius: var(--aqb-radius); }
a.aqb-tab-btn{ border-radius: 10px; }

/* 詳細ログの改行と等幅フォント */
.aqb-detail-panel{
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  line-height: 1.5;
}

/* =========================
   共通：スクロールバーを太く
   ========================= */
:root{
  --aqb-scrollbar-size: 18px;               /* ← ここを好みで 12~18px などに */
  --aqb-scrollbar-track: #e9eaec;
  --aqb-scrollbar-thumb: #9aa1ad;
  --aqb-scrollbar-thumb-hover: #7f8792;

  /* ダークUI（モーダル/コードブロック） */
  --aqb-scrollbar-track-dark: #0b0e14;
  --aqb-scrollbar-thumb-dark: #2f3541;
  --aqb-scrollbar-thumb-dark-hover: #3a4150;
}

/* WebKit系（Chrome/Edge/Safari/Opera）? 全体に適用 */
*::-webkit-scrollbar{
  width: var(--aqb-scrollbar-size);
  height: var(--aqb-scrollbar-size);
}
*::-webkit-scrollbar-track{
  background: var(--aqb-scrollbar-track);
}
*::-webkit-scrollbar-thumb{
  background: var(--aqb-scrollbar-thumb);
  border-radius: 999px;
  /* “つまみ”を少し細く見せる（余白） */
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover{
  background: var(--aqb-scrollbar-thumb-hover);
}

/* Firefox ? 厚さは厳密指定不可だが「auto」で太め表示＋色指定 */
*{
  scrollbar-width: auto; /* thin / auto */
  scrollbar-color: var(--aqb-scrollbar-thumb) var(--aqb-scrollbar-track);
}

/* 横スクロールのテーブル領域を太く（見やすく） */
.aqb-scroll-x::-webkit-scrollbar{
  height: var(--aqb-scrollbar-size);
}
.aqb-scroll-x{
  scrollbar-width: auto;
}

/* ダーク系（モーダル内コードブロック）専用の色 */
.aqb-code-block::-webkit-scrollbar{
  width: var(--aqb-scrollbar-size);
  height: var(--aqb-scrollbar-size);
}
.aqb-code-block::-webkit-scrollbar-track{
  background: var(--aqb-scrollbar-track-dark);
}
.aqb-code-block::-webkit-scrollbar-thumb{
  background: var(--aqb-scrollbar-thumb-dark);
  border-radius: 999px;
  border: 2px solid var(--aqb-scrollbar-track-dark);
}
.aqb-code-block::-webkit-scrollbar-thumb:hover{
  background: var(--aqb-scrollbar-thumb-dark-hover);
}
/* Firefox のダーク色 */
.aqb-code-block{
  scrollbar-color: var(--aqb-scrollbar-thumb-dark) var(--aqb-scrollbar-track-dark);
}

/* モーダル全体を縦方向flexに */
#aqb-editor-modal .aqb-modal__content{
  display:flex;
  flex-direction:column;
  height:85vh;            /* 既存値があればそのままでOK */
  min-height:0;           /* ← Safari対策 */
}

/* タブのパネル群もflexで伸縮 */
#aqb-editor-modal .editor-tab-panels{
  flex:1;
  min-height:0;           /* ← これが超重要（子の縮みを許可） */
  display:flex;
  flex-direction:column;
}

/* 各タブ（プレビュー/問題フォーム/…）も縦flexで中に余りを作る */
#aqb-editor-modal .editor-panel{
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
}

/* 「問題フォーム」内の白いテーブル領域を残り高さぴったりに */
#aqb-editor-modal .editor-panel[data-editor-panel="qform"] .aqb-scroll-x{
  flex:1;                 /* 残り全部を受け持つ */
  min-height:0;           /* Safari対策 */
  overflow:auto;          /* スクロールはこの箱の中だけに */
  background:#fff;        /* 白背景（既存と同じなら不要） */
  border-radius:8px;      /* 既存と同じなら不要 */
}

/* ついでに横スクロールの厚めスクロールバー（任意） */
#aqb-editor-modal .editor-panel[data-editor-panel="qform"] .aqb-scroll-x::-webkit-scrollbar{
  height: var(--aqb-scrollbar-size, 14px);
}

/* 問題フォーム：正解(6)～HTML(15)を中央寄せ */
.editor-panel[data-editor-panel="qform"] .aqb-builder-table tbody td:nth-child(n+6):nth-child(-n+15),
.editor-panel[data-editor-panel="qform"] .aqb-builder-table thead th:nth-child(n+6):nth-child(-n+15){
  text-align:center;
}

/* カテゴリフォーム：列1=操作、2～10(A～I)=中央、11～21(J～U)=左、22～28(V～AA)=中央 */
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:nth-child(n+2):nth-child(-n+10),
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:nth-child(n+2):nth-child(-n+10),
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:nth-child(n+22):nth-child(-n+28),
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:nth-child(n+22):nth-child(-n+28){
  text-align:center;
}
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:nth-child(n+11):nth-child(-n+21),
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:nth-child(n+11):nth-child(-n+21){
  text-align:left;
}

/* 上部ボタンを左寄せ（カテゴリフォーム用） */
.aqb-cat-toolbar{
  display:flex; gap:.5rem; flex-wrap:wrap; justify-content:flex-start; align-items:center;
}
.aqb-cat-toolbar .aqb-sample{
  background:#f4f4f4; color:#666; padding:.35rem .5rem; border-radius:.35rem;
  border:1px solid #e5e5e5; font-size:.85em;
}

/* ── 共通：モーダル内の表エリア（白い範囲）を“縦ピッタリ”に ─────────────── */
#aqb-editor-modal .editor-panel{
  height:100%;
  display:flex;
  flex-direction:column;
  min-height:0;
}
#aqb-editor-modal .editor-panel .aqb-scroll-x{
  /* 中身のテーブルが縦に伸びる時はパネル内でスクロール */
  flex:1;
  min-height:0;
  overflow:auto;
}

/* ── 問題フォーム：正解(6)～HTML(15)を中央寄せ。操作セル(1)も中央寄せ ── */
.editor-panel[data-editor-panel="qform"] .aqb-builder-table thead th:first-child,
.editor-panel[data-editor-panel="qform"] .aqb-builder-table tbody td:first-child{
  text-align:center;
}
.editor-panel[data-editor-panel="qform"] .aqb-builder-table thead th:nth-child(n+6):nth-child(-n+15),
.editor-panel[data-editor-panel="qform"] .aqb-builder-table tbody td:nth-child(n+6):nth-child(-n+15){
  text-align:center;
}

/* ── カテゴリフォーム：A～I(2?10)=中央／J～U(11?21)=左／V～AA(22?28)=中央。操作(1)も中央 ── */
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:first-child,
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:first-child{
  text-align:center;
}
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:nth-child(n+2):nth-child(-n+10),
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:nth-child(n+2):nth-child(-n+10),
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:nth-child(n+22):nth-child(-n+28),
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:nth-child(n+22):nth-child(-n+28){
  text-align:center;
}
.editor-panel[data-editor-panel="category"] .aqb-builder-table thead th:nth-child(n+11):nth-child(-n+21),
.editor-panel[data-editor-panel="category"] .aqb-builder-table tbody td:nth-child(n+11):nth-child(-n+21){
  text-align:left;
}

/* ── カテゴリフォーム：上部ボタン（左寄せ）＆サンプルのグレーラベル ── */
.aqb-cat-toolbar{
  display:flex; gap:.5rem; flex-wrap:wrap; justify-content:flex-start; align-items:center;
  margin-bottom:.5rem;
}
.aqb-cat-toolbar .aqb-sample{
  background:#f4f4f4; color:#666; padding:.35rem .5rem; border-radius:.35rem;
  border:1px solid #e5e5e5; font-size:.85em;
}

/* （任意）スクロールバーを少し太く */
#aqb-editor-modal .aqb-scroll-x::-webkit-scrollbar{ height:12px; width:12px; }
#aqb-editor-modal .aqb-scroll-x::-webkit-scrollbar-thumb{ background:#888; border-radius:8px; }
#aqb-editor-modal .aqb-scroll-x::-webkit-scrollbar-track{ background:#222; }

/* スクロールバー太め */
.aqb-scroll-x::-webkit-scrollbar,
.aqb-fill-y::-webkit-scrollbar,
.aqb-modal__content::-webkit-scrollbar,
textarea.aqb-code-block::-webkit-scrollbar { height: 12px; width: 12px; }
.aqb-scroll-x::-webkit-scrollbar-thumb,
.aqb-fill-y::-webkit-scrollbar-thumb,
.aqb-modal__content::-webkit-scrollbar-thumb,
textarea.aqb-code-block::-webkit-scrollbar-thumb { background: #bbb; border-radius: 6px; }

/* 文字配置ヘルパ */
.cell-center { text-align:center !important; }
.cell-left   { text-align:left   !important; }

/* “白いテーブル領域”を縦ピッタリ */
.aqb-fill-y { height: 100%; }
