:root {
  --bg: #f7f7f8; --card: #fff; --text: #222; --muted: #666;
  --line: #ddd; --accent: #ff7a00;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: #0b63ce; text-decoration: none; }

/* ── topbar ── */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; background: #222; color: #fff; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; gap: 8px; }
.topbar a, .topbar-user { color: #fff; margin-right: 14px; }
.topbar-sep { color: #888; margin: 0 6px; }
.brand { font-weight: 700; font-size: 16px; }
.topbar-left { display: flex; align-items: center; }

/* ── layout ── */
.container { max-width: 1280px; margin: 20px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 16px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
/* hidden 属性は UA 側の display:none で効くが、クラス側で display を
   指定すると勝ってしまう。hidden を常に優先させる。 */
[hidden] { display: none !important; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.hidden { display: none !important; }

/* ── buttons & inputs ── */
button, .button { border: 0; border-radius: 10px; padding: 8px 12px; background: var(--accent); color: #fff; cursor: pointer; display: inline-block; font-size: 14px; }
button:hover, .button:hover { filter: brightness(.93); }
.danger { background: #c62828; }
input[type="text"], input[type="password"], input[type="number"], input[type="color"],
input:not([type]), select, textarea { padding: 8px; border-radius: 8px; border: 1px solid #ccc; font-size: 14px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
/* label は既定でキャプションを上に積む。チェックボックスのように
   横並びにしたいものはこれを付ける */
.label-row { flex-direction: row; align-items: center; gap: 6px; }
/* チェックボックスを横一列に並べる小パネル */
.aug-panel { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 0; }

/* ── flash messages ── */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.flash-error { background: #fde8e8; color: #c62828; border: 1px solid #f5c6cb; }
.flash-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }

/* ── login ── */
.login-wrap { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--bg); }
.login-card { width: 340px; }
.brand-lg { font-size: 22px; font-weight: 700; margin: 0 0 20px; color: var(--accent); }
.login-card label { margin-bottom: 12px; }
.login-card input { width: 100%; }

/* ── hints / chips ── */
.hint { color: var(--muted); font-size: 13px; }
.chips { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 2px solid var(--line); border-radius: 999px; padding: 5px 10px; background: #fff; font-size: 13px; }

/* ── badges (split / status) ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #fff; font-weight: 600; }
.badge-none  { background: #9e9e9e; }
.badge-train { background: #1976d2; }
.badge-val   { background: #388e3c; }
.badge-test  { background: #7b1fa2; }

/* ── job status ── */
.job-status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.job-pending { background: #fff3e0; color: #e65100; }
.job-running { background: #e3f2fd; color: #1565c0; }
.job-done    { background: #e8f5e9; color: #2e7d32; }
.job-error   { background: #fde8e8; color: #c62828; }
.job-cancelled { background: #eceff1; color: #546e7a; }

/* ── thumb grid ── */
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.thumb-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; position: relative;
  /* content-visibility:auto はここでは使わない。実測(1557枚で 2.6ms 対 4.2ms)
     で効果がほぼ無い一方、環境によって描画が黒く抜ける報告があったため */ }
.thumb-more { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.thumb-more .hint { font-size: 12px; }
.thumb-card img { width: 100%; height: 100px; object-fit: cover; display: block; background: #eee; }
.thumb-meta { padding: 6px 8px; font-size: 11px; line-height: 1.35; word-break: break-all; }
.thumb-meta b { font-size: 12px; }
.thumb-meta small { font-size: 10px; color: var(--muted); }
.thumb-check { position: absolute; top: 4px; left: 4px; z-index: 2; }
.thumb-split { position: absolute; top: 4px; right: 4px; z-index: 2; font-size: 9px; padding: 1px 5px; }
.row-actions { padding: 4px 6px 8px; display: flex; gap: 4px; }
.row-actions .button, .row-actions button { padding: 4px 8px; font-size: 12px; }

/* ── tables ── */
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }

/* ── nav bar (image carousel) ── */
/* スライダー以外は全部固定幅にする。件数表示やファイル名が内容ぶんだけ
   伸び縮みすると、flex:1 のスライダーがその差を吸収して、画像を変えるたびに
   スライダーの幅と ← → の位置が動いてしまう。 */
.nav-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; margin-bottom: 12px; }
.nav-btn { width: 36px; height: 36px; font-size: 18px; padding: 0; border-radius: 8px; flex: 0 0 36px; }
.nav-btn:disabled { background: #ccc; cursor: default; }
.nav-counter { flex: 0 0 96px; font-size: 14px; font-weight: 600; white-space: nowrap;
  text-align: center; font-variant-numeric: tabular-nums; }
#navSlider { flex: 1 1 auto; min-width: 120px; }
#navInput  { flex: 0 0 68px; width: 68px; font-variant-numeric: tabular-nums; }
/* ファイル名は長さがまちまちなので幅を固定し、溢れた分は … で省略する */
#navInfo   { flex: 0 0 260px; width: 260px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 780px) {
  /* 狭い画面ではファイル名を畳む。他は固定のままなのでスライダーは動かない */
  #navInfo { display: none; }
}
#navInput { width: 64px; text-align: center; }

/* ── annotator ── */
.annotator-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.canvas-wrap { overflow: auto; }
#canvas { max-width: 100%; border: 1px solid #ccc; background: #111; cursor: crosshair; }
.side { position: sticky; top: 60px; max-height: calc(100vh - 80px); overflow-y: auto; }
.button-row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.ann-item { padding: 8px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; font-size: 13px; cursor: pointer; }
.ann-item.selected { outline: 3px solid var(--accent); }
.ann-item b { margin-right: 4px; }

/* ── 単体クラス表示（統計画面の切り抜き一覧）── */
.class-pick { background: none; border: 0; padding: 0; margin: 0; font: inherit;
  color: inherit; cursor: pointer; text-align: left;
  text-decoration: underline; text-decoration-style: dotted; }
.class-pick:hover { color: var(--accent); }
.crop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; }
.crop-card { display: block; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: #fff; color: inherit; text-decoration: none; }
.crop-card:hover { border-color: var(--accent); }
/* contain にして切り抜きをさらに切らない。背景が暗いと輪郭が分かりやすい */
.crop-card img { width: 100%; height: 120px; object-fit: contain; display: block;
  background: #111; }
.crop-meta { padding: 5px 7px; font-size: 11px; line-height: 1.35; word-break: break-all; }
.crop-meta small { color: var(--muted); font-size: 10px; }

/* ── 注釈画面が単体クラス表示のときの帯 ── */
.solo-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px; padding: 8px 14px; border-radius: 10px;
  background: #fff3e0; border-left: 4px solid var(--accent); font-size: 13px; }
.solo-banner b { font-size: 14px; }
.solo-banner .solo-note { flex: 1 1 auto; color: var(--muted); font-size: 12px; }
.solo-banner button, .solo-banner .button { padding: 4px 10px; font-size: 12px; }

/* ── annotate: ファイル名検索 ── */
#searchBox { width: 100%; }
#searchSort { font-size: 12px; padding: 3px 6px; }
.search-result { max-height: 230px; overflow-y: auto; overscroll-behavior: contain;
  margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; }
.search-result > .hint { margin: 0; padding: 4px 8px; font-size: 11px;
  border-bottom: 1px solid var(--line); background: #fafafa;
  position: sticky; top: 0; }
.search-item { padding: 5px 8px; font-size: 12px; line-height: 1.4; cursor: pointer;
  border-bottom: 1px solid var(--line); word-break: break-all; }
.search-item:last-child { border-bottom: 0; }
.search-item:hover { background: #f5f5f5; }
.search-item.selected { background: #fff3e0; }

/* ── annotate: クラス一覧（この画像）── */
/* サイドが狭いので、名前の行と操作ボタンの行を分ける。1行に詰めると
   名前の幅が潰れて1文字ずつ折り返される */
.class-row { display: flex; align-items: center; gap: 6px; font-size: 13px;
  flex-wrap: wrap; padding: 5px 0; border-bottom: 1px solid var(--line); }
.class-row:last-of-type { border-bottom: 0; }
/* この画像に無いクラスは薄く出す。並び順＝クラス番号を保つため隠さない */
.class-row-empty { opacity: .45; }
.class-swatch { width: 12px; height: 12px; border-radius: 3px; border: 2px solid;
  flex-shrink: 0; box-sizing: border-box; }
.class-name { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.class-count { font-weight: 600; min-width: 22px; text-align: right;
  font-variant-numeric: tabular-nums; }
.class-acts { display: flex; gap: 4px; flex: 1 0 100%; margin-left: 18px; }
.class-acts:empty { display: none; }
.class-acts select { max-width: 120px; }
.class-acts button, .class-acts select { padding: 2px 6px; font-size: 11px; }
.class-row { cursor: pointer; }
.class-row:hover { background: #fafafa; }
/* 絞り込み中のクラス */
.class-row-on { background: #fff3e0; }
.class-row-on .class-name { font-weight: 700; }
.class-total { font-size: 11px; color: var(--muted); min-width: 36px; text-align: right;
  font-variant-numeric: tabular-nums; }
.class-filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  padding: 6px 8px; border-radius: 8px; background: #fff3e0;
  border-left: 3px solid var(--accent); font-size: 12px; }
.class-filter-bar span { flex: 1 1 auto; }
.class-filter-bar button { padding: 2px 8px; font-size: 11px; }

/* 右クリックメニューのキーボード絞り込み */
.ctx-filter { width: calc(100% - 16px); margin: 2px 8px 4px; padding: 4px 6px;
  font-size: 13px; box-sizing: border-box; }
.ctx-item.ctx-active { background: #ffe0b2; }

/* ── history panel ── */
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; gap: 8px; }
.history-item button { padding: 4px 8px; font-size: 12px; }

/* ── right-click context menu ── */
#ctxMenu { display:none; position:fixed; z-index:200; background:#fff; border:1px solid #ddd; border-radius:10px; box-shadow:0 4px 20px rgba(0,0,0,.15); padding:4px 0; min-width:150px;
  /* クラス数が多いと画面に収まらない。はみ出させず中でスクロールさせる。
     高さの上限は JS が「カーソルの上下どちらに余裕があるか」を測って
     その場で決めるので、ここでは縛らない（縛ると本来の高さを測れない） */
  overflow-y:auto; overscroll-behavior:contain; }
.ctx-item { display:flex; align-items:center; gap:8px; padding:8px 14px; font-size:14px; cursor:pointer; white-space:nowrap; }
.ctx-item:hover { background:#f5f5f5; }
.ctx-item.ctx-current { background:#fff3e0; font-weight:600; }
.ctx-swatch { width:12px; height:12px; border-radius:3px; flex-shrink:0; }

/* ── model form ── */
.model-form label { margin-bottom: 8px; }
.model-form input, .model-form select { width: 100%; }

/* ── responsive ── */
@media (max-width: 900px) {
  .grid2, .annotator-layout { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
}

/* ── job progress log ── */
.progress-track { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.progress-bar.progress-error { background: #c62828; }
.job-log { max-height: 320px; overflow: auto; background: #1e1e1e; color: #e0e0e0;
  padding: 10px 12px; border-radius: 8px; font-size: 12px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-all; margin: 0; }

/* ── dataset statistics ── */
.stat-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.stat { flex: 1 1 110px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--muted); }
.advice { border-left: 4px solid; padding: 10px 14px; margin: 10px 0; border-radius: 0 8px 8px 0; }
.advice p { margin: 4px 0 0; font-size: 13.5px; }
.advice-danger { background: #fde8e8; border-color: #c62828; }
.advice-warn   { background: #fff8e1; border-color: #f9a825; }
.advice-info   { background: #e3f2fd; border-color: #1976d2; }
.advice-ok     { background: #e8f5e9; border-color: #2e7d32; }
.bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; min-width: 60px; }
.bar span { display: block; height: 100%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; }
.row-muted td { opacity: .5; }
button.gray, .button.gray { background: #6e7781; }
