:root {
  --bg: #f6f7f9; --card: #fff; --text: #1f2328; --muted: #6b7280; --line: #d8dde3;
  --primary: #1f6feb; --primary-text: #fff; --err: #c62828; --err-bg: #fdecec;
  --warn: #9a6700; --warn-bg: #fff6d6; --ok: #1a7f37; --ok-bg: #e7f6ec; --info-bg: #eaf2ff;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 1.2rem; padding: .6rem 1rem; background: #24292f; color: #fff; flex-wrap: wrap; }
.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 700; }
.topbar nav { display: flex; gap: 1rem; flex: 1; flex-wrap: wrap; }
.topbar nav a:hover { text-decoration: underline; }
.topbar .me { display: flex; gap: .6rem; align-items: center; font-size: .9rem; }
.topbar .me .link { color: #fff; }

main { max-width: 1280px; margin: 0 auto; padding: 1rem; }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 0 0 1rem; }
.card.narrow { max-width: 520px; margin: 2rem auto; }
fieldset.card { min-width: 0; }
legend { font-weight: 700; padding: 0 .4rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.crumb { margin: 0; font-size: .85rem; color: var(--muted); }
.sub { margin: 0; color: var(--muted); font-size: .9rem; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .6rem; }
label.check { display: flex; gap: .4rem; align-items: center; font-weight: 400; }
input, select, textarea { width: 100%; font: inherit; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); }
input[type=checkbox] { width: auto; }
input[readonly] { background: #f0f2f4; color: var(--muted); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }

button, .button { display: inline-block; font: inherit; font-weight: 600; padding: .5rem 1rem; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--text); cursor: pointer; text-decoration: none; }
button:hover, .button:hover { border-color: var(--primary); }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.small, .button.small { padding: .2rem .6rem; font-size: .85rem; }
button.link { background: none; border: none; padding: 0; text-decoration: underline; font-weight: 400; }
form.inline { display: inline; }
button.danger { color: var(--err); border-color: #e7b4b4; }
button.danger:hover { background: var(--err-bg); border-color: var(--err); }
.head-actions { display: flex; gap: .5rem; align-items: center; }
.count-err { display: inline-block; margin-left: .4rem; font-size: .75rem; font-weight: 700; color: #fff; background: var(--err);
  padding: 0 .45rem; border-radius: 999px; vertical-align: middle; }
details.advanced > summary { font-weight: 700; padding: .2rem 0; }
details.advanced[open] > summary { margin-bottom: .6rem; }
.select-search { margin-bottom: .3rem; font-size: .85rem; padding: .3rem .5rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 1rem; }
.grid .wide, .grid label.wide { grid-column: 1 / -1; }
.field { margin-bottom: .7rem; }
.field label { margin-bottom: .2rem; }
.field .hint, .hint { color: var(--muted); font-size: .8rem; margin: .2rem 0 0; font-weight: 400; }
.field .issue { font-size: .82rem; margin: .2rem 0 0; color: var(--warn); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--err); background: var(--err-bg); }
.field.has-error .issue { color: var(--err); }
.field.has-warning input, .field.has-warning select, .field.has-warning textarea { border-color: #d4a72c; }
.counter { float: right; font-weight: 400; color: var(--muted); font-size: .8rem; }
.counter.over { color: var(--err); font-weight: 700; }

.req { display: inline-block; font-size: .7rem; padding: 0 .35rem; border-radius: 4px; vertical-align: middle; font-weight: 700; }
.req-must { background: var(--err); color: #fff; }
.req-cond { background: #f1e3b3; color: #6a4b00; }

.layout-side { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.side-col { position: sticky; top: 1rem; align-self: start; max-height: calc(100vh - 2rem); overflow: auto; }
.form-end { margin: 0 0 1rem; }
.progress { margin: 0 0 .6rem; font-size: .9rem; }
.selected-full { word-break: break-all; }
.mobile-bar { display: none; }
table.conflicts { margin-top: .5rem; background: #fff; }
.flash p { margin: 0; }
.side-col .buttons { display: grid; gap: .5rem; margin-top: 1rem; }
.issues { margin: .2rem 0 .8rem; padding-left: 1.2rem; font-size: .88rem; }
.label-err { color: var(--err); font-weight: 700; margin: .4rem 0 0; }
.label-warn { color: var(--warn); font-weight: 700; margin: .4rem 0 0; }
.ok { color: var(--ok); font-weight: 700; background: var(--ok-bg); padding: .4rem .6rem; border-radius: 6px; }

.flash { padding: .6rem .9rem; border-radius: 6px; margin-bottom: .8rem; background: var(--info-bg); }
.flash-success { background: var(--ok-bg); color: #0f5323; }
.flash-warning { background: var(--warn-bg); color: #6a4b00; }
.flash-error { background: var(--err-bg); color: #8e1b1b; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .9rem; }
th { background: #f0f2f4; white-space: nowrap; }
td.title-cell { min-width: 16rem; }
td.actions a { margin-right: .6rem; white-space: nowrap; }
td.attr { font-family: ui-monospace, Consolas, monospace; font-size: .75rem; color: var(--muted); word-break: break-all; }
td.result-cell { font-size: .85rem; }

.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-draft { background: #e5e7eb; color: #374151; }
.badge-ready { background: #dbeafe; color: #1e40af; }
.badge-exported { background: #dcfce7; color: #166534; }
.badge-uploaded_ok, .badge-up-ok { background: #166534; color: #fff; }
.badge-uploaded_error, .badge-up-error { background: var(--err); color: #fff; }
.badge-up-pending { background: #e5e7eb; color: #374151; }

.filters { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .8rem; }
.filters label { margin: 0; }
.empty { color: var(--muted); }
.muted { color: var(--muted); }
.note { white-space: pre-wrap; font-size: .85rem; margin: .3rem 0; }
dl.kv { display: grid; grid-template-columns: 14rem minmax(0, 1fr); gap: .3rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.history { padding-left: 1.2rem; font-size: .9rem; }
details summary { cursor: pointer; }

@media (max-width: 900px) {
  .layout-side { grid-template-columns: 1fr; }
  .side-col { position: static; max-height: none; }
  .mobile-bar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; gap: .6rem; align-items: center;
    justify-content: space-between; padding: .5rem 1rem; background: #fff; border-top: 1px solid var(--line);
    box-shadow: 0 -2px 8px rgba(0,0,0,.08); }
  .mobile-status { font-size: .9rem; font-weight: 600; }
  body:has(.mobile-bar) footer { padding-bottom: 4.5rem; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dd { margin-bottom: .4rem; }
}

@media (max-width: 600px) {
  .topbar { gap: .4rem .8rem; padding: .5rem .8rem; }
  .topbar nav { order: 3; flex-basis: 100%; gap: .8rem; font-size: .9rem; }
  .topbar .me { margin-left: auto; font-size: .8rem; }
  main { padding: .6rem; }
  .hide-sm { display: none; }
  td.title-cell { min-width: 9rem; }
  .card { padding: .8rem; }
}

/* 自動入力 */
.req-auto { background: #ede9fe; color: #5b21b6; }
.auto-info p { margin: .2rem 0; }
.ai-notes { margin: .2rem 0 .2rem 1.2rem; padding: 0; }
.choice-or { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .85rem; margin: 1.2rem 0 .6rem; }
.choice-or::before, .choice-or::after { content: ""; flex: 1; border-top: 1px solid #e5e7eb; }
.candidates { list-style: none; padding: 0; margin: 0; }
.candidates li { border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: .5rem; }
.candidates label { display: flex; gap: .7rem; align-items: center; padding: .5rem .7rem; cursor: pointer; font-weight: 400; }
.candidates input[type=radio] { flex: none; width: auto; }
.candidates img { width: 64px; height: 64px; object-fit: contain; flex: none; background: #fff; }
.candidates .cand-title { font-weight: 600; }
.candidates li:has(input:checked) { border-color: #2563eb; background: #eff6ff; }
.busy-note { color: var(--muted); font-size: .85rem; }

/* 商品画像 */
.dropzone { border: 2px dashed #9ca3af; border-radius: 10px; padding: 1.2rem; text-align: center; cursor: pointer;
            color: var(--muted); background: #fafafa; }
.dropzone p { margin: 0; }
.dropzone.over, .dropzone:hover, .dropzone:focus { border-color: #2563eb; background: #eff6ff; color: #1e40af; outline: none; }
.image-msg { margin: .5rem 0 0; font-size: .9rem; }
.image-grid { list-style: none; padding: 0; margin: .8rem 0 0; display: grid; gap: .7rem;
              grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.image-grid li { border: 1px solid #e5e7eb; border-radius: 8px; padding: .5rem; display: flex; flex-direction: column; gap: .2rem; }
.image-grid li.is-main { border-color: #2563eb; }
.image-grid img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.image-label { font-weight: 700; font-size: .85rem; }
.slot-buttons { display: flex; gap: .2rem; flex-wrap: wrap; align-items: center; margin-top: .2rem; }
.slot-buttons button { padding: .15rem .4rem; }
.slot-buttons button.slot-on { background: #2563eb; border-color: #2563eb; color: #fff; opacity: 1; }
.image-actions { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .2rem; }
