:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --line: #dfe3dd;
  --ink: #1f2420;
  --muted: #6d7570;
  --accent: #4a7c3f;
  --accent-ink: #ffffff;
  --danger: #b23b3b;
  --warn: #a8741a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* 下端の固定パネル（実行バー＋ログ）の実測高さを JS が --bottom-h に入れる */
  padding: 0 0 var(--bottom-h, 120px);
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.topbar h1 { margin: 0; font-size: 17px; letter-spacing: .02em; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.pick-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.dir-hint {
  font-size: 11px;
  color: var(--warn);
  max-width: 440px;
  text-align: right;
  line-height: 1.5;
}
.dir-hint b { font-weight: 700; }
/* 出力先が決まったら注意書きは引っ込める */
.dir-ready .dir-hint { display: none; }
.dir-label {
  font-size: 12px;
  color: var(--muted);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dir-label.ok { color: var(--accent); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: #eef1ec; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: #3d6835; }
.btn-ghost { border-style: dashed; color: var(--muted); }
.btn-mini { padding: 3px 9px; font-size: 12px; border-radius: 6px; }
.btn-danger { color: var(--danger); border-color: #e8cccc; }
.btn-run {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  padding: 11px 28px;
  font-size: 15px;
  font-weight: 600;
}
.btn-run:hover:not(:disabled) { background: #3d6835; }

/* ---------- banner ---------- */
.banner { margin: 12px 20px; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.banner-error { background: #fdecec; border: 1px solid #f2c9c9; color: #7d2626; }

/* ---------- settings ---------- */
.settings {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.field select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.field-check { cursor: pointer; }
.field-check input { width: 15px; height: 15px; accent-color: var(--accent); }

/* ---------- products ---------- */
.products { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sku-field { display: flex; align-items: center; gap: 8px; }
.sku-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sku-input {
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 7px 10px;
  min-width: 240px;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.sku-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.sku-input.invalid { border-color: var(--danger); background: #fff7f7; }
.sku-preview { font-size: 12px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.sku-preview.warn { color: var(--warn); }
.card-tools { margin-left: auto; display: flex; gap: 6px; }

.dropzone {
  margin-top: 12px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  transition: border-color .12s, background .12s;
}
.dropzone.over { border-color: var(--accent); background: #eef5ec; }
.dz-text { margin: 0; }

/* ---------- thumbnails ---------- */
.thumbs {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}
.thumbs:empty { display: none; }

.thumb {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fafbfa;
  cursor: grab;
  user-select: none;
  touch-action: none;          /* ドラッグ中に画面がスクロールしないように */
  -webkit-user-drag: none;
}
.thumb img { -webkit-user-drag: none; pointer-events: none; }
.thumb.dragging { opacity: .3; }

/* ドラッグ中に指先へ追随する複製 */
.thumb.ghost {
  position: fixed;
  z-index: 999;
  margin: 0;
  pointer-events: none;
  opacity: .95;
  cursor: grabbing;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
  transform-origin: center;
}
body.dragging-active { cursor: grabbing; }
body.dragging-active .thumb { cursor: grabbing; }
.thumb.drop-before { box-shadow: -3px 0 0 0 var(--accent); }
.thumb.drop-after  { box-shadow:  3px 0 0 0 var(--accent); }
.thumb img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #eee; }
.thumb .idx {
  position: absolute; top: 4px; left: 4px;
  background: rgba(31,36,32,.85); color: #fff;
  font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; line-height: 20px;
  text-align: center; border-radius: 5px; padding: 0 5px;
}
.thumb .del {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; line-height: 18px; text-align: center;
  border: none; border-radius: 5px; cursor: pointer;
  background: rgba(31,36,32,.6); color: #fff; font-size: 13px; padding: 0;
}
.thumb .del:hover { background: var(--danger); }
.thumb .name {
  font-size: 10px; color: var(--muted);
  padding: 4px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-top: 1px solid var(--line);
}
.thumb .badge {
  position: absolute; bottom: 26px; left: 4px;
  background: var(--warn); color: #fff;
  font-size: 9px; padding: 1px 5px; border-radius: 4px;
}

/* ---------- add row ---------- */
.add-row { padding: 0 20px; display: flex; align-items: center; gap: 12px; }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- run bar ---------- */
.runbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(0,0,0,.05);
  z-index: 20;
}
.runbar-info { flex: 1; }
#summary { font-size: 13px; color: var(--muted); }
.progress { height: 6px; background: #e8ebe6; border-radius: 3px; overflow: hidden; margin-top: 6px; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---------- log ---------- */
.log-wrap {
  position: fixed;
  bottom: var(--runbar-h, 62px); left: 0; right: 0;
  max-height: 34vh;
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  z-index: 19;
}
.log-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 4px 20px;
  border-bottom: 1px solid var(--line);
}
.log-toggle {
  display: flex; align-items: center; gap: 7px;
  font: inherit; font-size: 13px; font-weight: 600;
  background: none; border: none; padding: 4px 2px;
  color: var(--ink); cursor: pointer; border-radius: 6px;
}
.log-toggle:hover { color: var(--accent); }
.log-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.log-toggle .chev { font-size: 11px; transition: transform .15s; }
.log-wrap.collapsed .log-toggle .chev { transform: rotate(-90deg); }
.log-wrap.collapsed .log { display: none; }
.log-wrap.collapsed { border-top-color: var(--line); }
.log-count { font-size: 11px; font-weight: 500; color: var(--muted); }
.log-count.has-err { color: var(--danger); font-weight: 700; }

.log { list-style: none; margin: 0; padding: 8px 20px; overflow-y: auto; font-size: 12px; font-family: ui-monospace, Menlo, monospace; }
.log li { padding: 2px 0; border-bottom: 1px solid #f2f4f1; }
.log li.err { color: var(--danger); }
.log li.warn { color: var(--warn); }
.log li.ok { color: var(--accent); }

.license { padding: 0 20px 20px; font-size: 11px; color: var(--muted); }
.license a { color: var(--muted); }
