:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee5;
  --text: #1c2530;
  --muted: #66717e;
  --accent: #06c755;
  --accent-dark: #05a346;
  --danger: #d92d20;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
  font-size: 15px;
}
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 17px; margin: 0 0 10px; border-left: 4px solid var(--accent); padding-left: 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); }
a { color: #0b6bcb; }
code { background: #eef1f4; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.admin-wrap, .o-wrap { max-width: 960px; margin: 24px auto; padding: 0 16px; }
.admin-wrap.narrow, .o-wrap.narrow { max-width: 560px; }
.o-wrap { max-width: 720px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.panel.center { text-align: center; padding: 40px 24px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head p { margin: 0; }

.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: block; font-weight: 600; font-size: 13px; }
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
textarea { resize: vertical; }

.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #fdecea; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.large { font-size: 17px; padding: 12px 32px; }

.flash { border-radius: 8px; padding: 10px 14px; margin: 8px 0; font-size: 14px; }
.flash-ok { background: #e7f8ee; color: #0a6b34; border: 1px solid #b5e6c9; }
.flash-error { background: #fdecea; color: #8f1f14; border: 1px solid #f3c2bc; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
  background: #e5e8ec;
  color: #333;
}
.badge-waiting_input { background: #fff3cd; color: #7a5c00; }
.badge-ready { background: #dcefff; color: #0b4f8a; }
.badge-selecting { background: #e7dcff; color: #4b2596; }
.badge-selected { background: #ffe4ec; color: #96174c; }
.badge-completed { background: #d9f3e3; color: #0a6b34; }
.badge-cancelled { background: #eee; color: #777; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.brand-label { margin: 0 0 6px; color: var(--accent-dark); font-size: 13px; font-weight: 700; letter-spacing: .04em; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.photo-cell { margin: 0; }
.photo-cell figcaption { font-size: 13px; margin-bottom: 4px; }
.photo-cell img, .empty-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eceff2;
  display: block;
}
.line-asset-preview { object-fit: contain !important; background: #f2f3f5; }
.line-asset-tab { aspect-ratio: 96 / 74 !important; }

.style-ref { max-width: 280px; border-radius: 8px; border: 1px solid var(--line); display: block; margin: 8px 0; }

.phrase-list { columns: 2; margin: 0; padding-left: 40px; font-size: 14px; }
.phrase-list li { padding: 1px 0; }

.attach-list { margin: 0; padding-left: 22px; font-size: 14px; }
.prompt-box {
  width: 100%;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
}
.copy-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.copy-row input { flex: 1; }

.candidate-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.candidate-cell { margin: 0; text-align: center; }
.candidate-cell img, .candidate-cell .empty-thumb {
  width: 100%;
  aspect-ratio: 37 / 32;
  object-fit: contain;
  background: repeating-conic-gradient(#f2f4f6 0% 25%, #e7eaee 0% 50%) 50% / 16px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.candidate-cell .phrase { font-size: 11px; margin: 2px 0 0; color: var(--muted); min-height: 1.2em; }

.tag { display: inline-block; font-size: 11px; border-radius: 4px; padding: 0 6px; font-weight: 700; }
.tag.ok { background: #d9f3e3; color: #0a6b34; }
.tag.missing { background: #fdecea; color: #8f1f14; }

.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.danger-zone { border-color: #f3c2bc; }

.import-status { font-size: 14px; }
.import-status .row-ok { color: #0a6b34; }
.import-status .row-ng { color: #8f1f14; }

.selection-list { columns: 2; margin: 0; padding-left: 30px; font-size: 14px; }
.consent { margin: 8px 0; padding: 10px 14px; background: #f4f6f8; border-radius: 8px; font-size: 13.5px; }
.consent-check { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.slot { border: 1px dashed var(--line); border-radius: 8px; padding: 10px; }
.slot-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.slot-status { font-size: 12px; color: var(--muted); }
.slot-status.saved { color: #0a6b34; font-weight: 700; }
.slot-preview img { width: 100%; max-height: 180px; object-fit: contain; border-radius: 6px; }
.slot-error { color: var(--danger); margin: 4px 0 0; }

/* pet入力フォーム (stepper / 写真カード) */
.pet-step-nav {
  list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0;
  font-size: 12.5px; color: var(--muted);
}
.pet-step-nav-item {
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; background: #fff;
  display: flex; align-items: center; gap: 5px;
}
.pet-step-nav-item.active { border-color: var(--accent); color: var(--accent-dark); font-weight: 700; background: #f0fbf4; }
.pet-step-nav-item.done { color: #0a6b34; }
.pet-step-nav-item .no { font-weight: 700; }
.pet-count-options { display: flex; gap: 18px; margin: 8px 0 12px; font-weight: 600; }
.pet-count-options label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
#pet-input-root .pet-count-note { margin: -4px 0 12px; padding: 10px 12px; border-left: 3px solid var(--line); background: #f4f6f8; border-radius: 4px; }
.pet-fields { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; padding: 12px; display: grid; gap: 8px; }
.pet-fields legend { font-weight: 700; padding: 0 6px; }
.pet-fields input, .pet-fields textarea { width: 100%; box-sizing: border-box; }
.pet-photo-card {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px;
}
.pet-photo-card.unassigned { border-color: #e0a800; background: #fffaf0; }
.pet-photo-card.unassignable { border-color: var(--danger); background: #fff7f6; }
.pet-photo-card img { width: 100%; max-height: 160px; object-fit: contain; border-radius: 6px; }
.pet-photo-card .card-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.pet-photo-card .card-warn { color: #8f1f14; font-size: 12px; }
.pet-photo-card select { width: 100%; }
.pet-step-actions { margin-top: 4px; }
/* .btn(display:inline-block)や.pet-fields(display:grid)などauthor指定がUAの[hidden]より
   強いため、petフォーム内のhidden要素は明示的に非表示にする */
#pet-input-root [hidden] { display: none !important; }

/* Step 6 確認サマリー (既存の変数・角丸のみ使用) */
.pet-confirm-summary {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px 14px;
  margin: 0 0 12px;
  font-size: 14px;
}
.pet-confirm-summary .confirm-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.pet-confirm-summary .confirm-row:last-child { border-bottom: none; padding-bottom: 8px; }
.pet-confirm-summary .confirm-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.pet-confirm-summary .confirm-value { margin-top: 2px; }
.pet-confirm-summary .confirm-value p { margin: 0 0 6px; }
.pet-confirm-summary .confirm-value p:last-child { margin-bottom: 0; }
.pet-confirm-summary .confirm-phrases { margin: 6px 0 2px; padding-left: 22px; font-size: 13.5px; }
.pet-confirm-summary .confirm-phrases li { padding: 1px 0; }
.pet-confirm-summary .confirm-phrase-empty { color: var(--muted); }
.pet-confirm-summary summary { cursor: pointer; font-weight: 600; }
#pet-input-root .confirm-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; margin-top: 8px; }
#pet-input-root .confirm-photo-item { display: flex; flex-direction: column; gap: 4px; min-width: 0; font-size: 12px; text-align: center; }
#pet-input-root .confirm-photo-item img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: #fff; }
#pet-input-root .confirm-photo-item span { overflow-wrap: anywhere; }
#pet-input-root .confirm-style-preview-container { margin-top: 6px; }
#pet-input-root .confirm-style-preview-image { display: block; width: 112px; max-width: 100%; border-radius: 6px; margin: 6px 0; }
#pet-input-root .confirm-style-preview-btn { width: auto; }

#pet-input-root .pet-style-card { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
#pet-input-root .pet-style-card .style-item { flex: 1; }
#pet-input-root .style-preview-btn { min-height: 40px; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; background: #fff; color: var(--text); cursor: pointer; }
#pet-input-root .style-preview-btn:hover { border-color: var(--accent); color: var(--accent-dark); }
#pet-input-root .pet-style-dialog { box-sizing: border-box; width: min(760px, calc(100vw - 24px)); max-width: 760px; max-height: calc(100dvh - 24px); padding: 16px; border: 0; border-radius: 12px; color: var(--text); background: #fff; box-shadow: 0 16px 48px rgba(0, 0, 0, .25); }
#pet-input-root .pet-style-dialog::backdrop { background: rgba(15, 23, 42, .68); }
#pet-input-root .pet-style-dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#pet-input-root .pet-style-dialog-header h2 { margin: 0 0 12px; font-size: 18px; }
#pet-input-root .style-dialog-close { flex: 0 0 auto; min-height: 40px; border: 1px solid var(--line); border-radius: 7px; padding: 6px 12px; background: #fff; cursor: pointer; }
#pet-input-root .pet-style-dialog-image-area { display: flex; justify-content: center; align-items: center; min-height: 160px; max-height: calc(100dvh - 190px); overflow: hidden; touch-action: pan-y; }
#pet-input-root .pet-style-dialog-image { display: block; width: auto; max-width: 100%; max-height: min(68dvh, 640px); object-fit: contain; border-radius: 6px; }
#pet-input-root .pet-style-dialog-footer { margin-top: 12px; }
#pet-input-root .pet-style-dialog-position { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; text-align: center; }
#pet-input-root .pet-style-dialog-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#pet-input-root .pet-style-dialog-nav button { min-height: 44px; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; background: #fff; cursor: pointer; }
#pet-input-root .pet-style-dialog-nav button:disabled { opacity: .45; cursor: default; }
#pet-input-root .pet-style-dialog-nav .primary { background: var(--accent); border-color: var(--accent); color: #fff; }

#pet-input-root .request-note-field { display: block; margin-top: 12px; }

/* petフォームのタップ領域・focus (child_16 / 管理画面へ影響させないため #pet-input-root にscope) */
#pet-input-root input[type="text"],
#pet-input-root select { min-height: 44px; }
#pet-input-root .style-chip { min-height: 44px; }
#pet-input-root .pet-count-options label,
#pet-input-root .consent-check { min-height: 44px; }
#pet-input-root .pet-photo-card .btn { min-height: 40px; }
#pet-input-root button:focus-visible,
#pet-input-root input:focus-visible,
#pet-input-root select:focus-visible,
#pet-input-root textarea:focus-visible,
#pet-input-root .style-item:has(input:focus-visible) {
  outline: 3px solid rgba(6, 199, 85, 0.35);
  outline-offset: 2px;
}

.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.style-item { display: flex; flex-direction: column; align-items: center; gap: 6px; border: 2px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; font-size: 13px; text-align: center; }
.style-item:has(input:checked) { border-color: var(--accent); background: #f0fbf4; }
.style-item img { width: 100%; height: auto; border-radius: 6px; }
.style-item--hidden { display: none; }

.style-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.style-chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; }
.style-chip.active { border-color: var(--accent); background: var(--accent); color: #fff; }

.phrase-inputs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.phrase-inputs li { display: flex; align-items: center; gap: 8px; }
.phrase-inputs .no { font-size: 12px; color: var(--muted); width: 24px; }
.phrase-inputs input { margin-top: 0; }

.select-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.select-bar #pick-count { font-weight: 700; font-size: 16px; }

/* シート分割補正 (救済ツール・最小限) */
.sheet-repair-dialog {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 23, 42, 0.6);
  overflow: auto; padding: 20px;
}
.sheet-repair-panel { max-width: 960px; margin: 0 auto; }
.sheet-repair-sheetrow { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.sheet-repair-loadrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.sheet-repair-canvas-wrap { position: relative; display: inline-block; max-width: 100%; }
.sheet-repair-stage { display: block; border: 1px solid var(--line); border-radius: 8px; max-width: 100%; }
.crop-overlay { position: absolute; left: 0; top: 0; }
.crop-box {
  position: absolute; border: 2px solid #0b6bcb; background: rgba(11, 107, 203, 0.08);
  cursor: move; box-sizing: border-box;
}
.crop-box.selected { border-color: var(--accent); background: rgba(6, 199, 85, 0.10); }
.crop-box.dirty { box-shadow: 0 0 0 2px rgba(217, 45, 32, 0.35); }
.crop-label {
  position: absolute; left: 0; top: 0; font-size: 11px; font-weight: 700;
  background: rgba(255, 255, 255, 0.9); padding: 0 4px; border-radius: 0 0 4px 0;
}
.crop-handle {
  position: absolute; width: 12px; height: 12px; background: #fff;
  border: 2px solid #0b6bcb; border-radius: 3px;
}
.crop-handle.nw { left: -7px; top: -7px; cursor: nwse-resize; }
.crop-handle.ne { right: -7px; top: -7px; cursor: nesw-resize; }
.crop-handle.sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.crop-handle.se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.sheet-repair-cells { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.sheet-repair-detail-canvaswrap { display: inline-block; border: 1px solid var(--line); border-radius: 8px; }
.sheet-repair-detail-canvas { display: block; touch-action: none; cursor: crosshair; }
.transparency-overlay { position: absolute; }
.repair-preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; margin: 8px 0; }
.repair-compare-row { display: flex; gap: 8px; }
.repair-compare-row figure { margin: 0; flex: 1; }
.repair-compare-row img { width: 100%; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; }
.checkerboard { background: repeating-conic-gradient(#f2f4f6 0% 25%, #e7eaee 0% 50%) 50% / 16px 16px; }
.sheet-repair-row { margin-top: 10px; }

.pick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pick-cell { margin: 0; border: 3px solid transparent; border-radius: 10px; cursor: pointer; padding: 6px; background: #fff; border-style: solid; border-color: var(--line); }
.pick-cell img { width: 100%; display: block; border-radius: 6px; }
.pick-cell figcaption { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }
.pick-cell.picked { border-color: var(--accent); background: #f0fbf4; }
.pick-cell.picked::after { content: "✓ 選択"; display: block; text-align: center; color: var(--accent-dark); font-weight: 700; font-size: 12px; }

@media (max-width: 640px) {
  .photo-grid { grid-template-columns: 1fr 1fr; }
  .candidate-grid { grid-template-columns: repeat(3, 1fr); }
  .pick-grid { grid-template-columns: 1fr 1fr; }
  .phrase-list, .selection-list { columns: 1; }
  .phrase-inputs { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }

  /* petフォーム: 操作バーをモバイルのみ下部固定(長いステップ中も戻る/次へが常時押せる) */
  #pet-input-root {
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }
  #pet-input-root .pet-step-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    margin: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: rgba(246, 247, 249, 0.96);
    border-top: 1px solid var(--line);
  }
  #pet-input-root .pet-step-actions .btn {
    flex: 1;
    min-height: 48px;
    padding: 8px 10px;
    text-align: center;
  }
  #pet-input-root .pet-step-actions #submit-btn { flex: 2; }
  #pet-input-root .pet-style-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); padding: 12px; }
  #pet-input-root .pet-style-dialog-image-area { max-height: calc(100dvh - 184px); }
  #pet-input-root .pet-style-dialog-image { max-height: min(62dvh, 560px); }
  #pet-input-root .pet-style-dialog-nav { gap: 6px; }
  #pet-input-root .pet-style-dialog-nav button { padding: 7px 8px; }
}
