/* ══════════════════════════════════════════════════════════════
   エネコン®カード「貼付指示書」作成ツール（2026-09-14追加）
   ──────────────────────────────────────────────────────────────
   営業マンが撮影した分電盤・キュービクル等の写真をもとに、実際の写真の上に
   「どこにカードを貼るか」を赤枠で示した指示書PDFを作成するツール。
   AIはあくまで「叩き台」の位置を提案するのみで、最終的な位置は営業マンが
   自由にドラッグ・リサイズ・追加・削除して確定させる（完全手動確定が前提）。
   ══════════════════════════════════════════════════════════════ */

.cg-wrap { max-width: 980px; margin: 0 auto; }
.cg-intro {
  font-size: 13px; color: #555; line-height: 1.7; margin-bottom: 18px;
  background: #f7f9fc; border: 1px solid #e4e9f2; border-radius: 10px; padding: 12px 14px;
}
.cg-intro b { color: #222; }

/* ── 宛先情報（PDF表紙用） ── */
.cg-header-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px;
}
@media (max-width: 560px) { .cg-header-fields { grid-template-columns: 1fr; } }
.cg-header-fields label { font-size: 12px; font-weight: 700; color: #444; display: block; margin-bottom: 4px; }
.cg-header-fields input {
  width: 100%; padding: 9px 10px; border: 1px solid #d7dce3; border-radius: 8px; font-size: 14px; font-family: inherit;
}

/* ── グループ（=1枚の写真+その中のブレーカー項目群）カード ── */
.cg-groups { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.cg-group {
  border: 1px solid #e2e6ee; border-radius: 12px; padding: 14px; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.cg-group-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cg-group-title-input {
  flex: 1; font-size: 14px; font-weight: 700; padding: 7px 9px; border: 1px solid #d7dce3;
  border-radius: 7px; font-family: inherit; min-width: 0;
}
.cg-group-del {
  flex-shrink: 0; background: #fff1f1; color: #c8102e; border: 1px solid #f3c6c6; border-radius: 7px;
  padding: 6px 10px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.cg-group-del:hover { background: #ffe3e3; }

/* 【2026-09-16追加】対象外判定（分電盤の内部写真ではない／主幹を確認できなかった）グループの見た目 */
.cg-group-excluded { background: #f7f7f8; opacity: 0.85; }
.cg-excluded-badge {
  background: #fff4e5; border: 1px solid #f0c489; color: #8a5a00; border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; font-weight: 700; margin-bottom: 10px; line-height: 1.5;
}

.cg-photo-area { display: flex; gap: 14px; flex-wrap: wrap; }
.cg-photo-drop {
  width: 220px; min-height: 150px; border: 2px dashed #c7cede; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px;
  cursor: pointer; background: #fafbfd; flex-shrink: 0; padding: 10px; text-align: center;
  /* 【2026-09-16修正】labelの内部にfile inputがあり、選択操作の前後でこのlabelや
     内部inputにフォーカスが移ることがある。ブラウザ・OSによってはフォーカス時に
     既定の赤系アウトライン（Windows版Chromeの一部設定等）が表示されるため、
     独自の枠デザインと衝突しないよう明示的に無効化する（赤枠の意図しない表示を防止）。*/
  outline: none;
}
.cg-photo-drop:hover { background: #f0f3fa; border-color: #9fb0d0; }
.cg-photo-drop:focus-within { outline: none; border-color: #9fb0d0; box-shadow: 0 0 0 3px rgba(90,130,220,0.18); }
.cg-photo-input { outline: none; }
.cg-photo-input:focus { outline: none; }
.cg-photo-drop img { max-width: 100%; max-height: 220px; border-radius: 6px; display: block; }
.cg-photo-drop-label { font-size: 12px; color: #667; font-weight: 700; }
.cg-photo-drop-hint { font-size: 11px; color: #99a; }

.cg-items { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 8px; }
.cg-item-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: #f7f9fc; border: 1px solid #e6eaf1; border-radius: 8px; padding: 7px 8px;
}
.cg-item-row input.cg-item-name {
  flex: 1 1 120px; min-width: 90px; padding: 6px 8px; border: 1px solid #d7dce3; border-radius: 6px; font-size: 13px; font-family: inherit;
}
.cg-item-row input.cg-item-amp {
  width: 76px; padding: 6px 8px; border: 1px solid #d7dce3; border-radius: 6px; font-size: 13px; font-family: inherit;
}
.cg-item-row .cg-item-cards {
  font-size: 12px; color: #556; white-space: nowrap; min-width: 52px; text-align: center; font-weight: 700;
}
.cg-item-row .cg-item-del {
  background: none; border: none; color: #b33; font-size: 16px; cursor: pointer; padding: 2px 6px; line-height: 1;
}
.cg-item-add-btn {
  align-self: flex-start; background: #eef4ff; color: #2563eb; border: 1px solid #bcd3f7; border-radius: 7px;
  padding: 6px 12px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; margin-top: 2px;
}
.cg-item-add-btn:hover { background: #dde9ff; }

.cg-group-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.cg-suggest-btn {
  background: #0969da; color: #fff; border: none; border-radius: 8px; padding: 9px 16px;
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.cg-suggest-btn:hover { background: #085ec4; }
.cg-suggest-btn:disabled { background: #9db8d9; cursor: not-allowed; }
.cg-edit-btn {
  background: #fff; color: #0969da; border: 1px solid #0969da; border-radius: 8px; padding: 9px 16px;
  font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
}
.cg-edit-btn:hover { background: #eff6ff; }
.cg-group-status { font-size: 12px; color: #667; margin-top: 6px; min-height: 16px; }
.cg-group-status.cg-status-error { color: #c8102e; }
.cg-group-status.cg-status-ok { color: #1a7f37; }

.cg-add-group-btn {
  display: block; width: 100%; background: #fff; border: 2px dashed #c7cede; border-radius: 10px;
  padding: 14px; font-size: 14px; font-weight: 700; color: #556; cursor: pointer; font-family: inherit;
  text-align: center; box-sizing: border-box;
}
.cg-add-group-btn:hover { background: #f4f6fb; border-color: #9fb0d0; }

.cg-generate-bar {
  position: sticky; bottom: 0; background: #fff; border-top: 1px solid #e4e9f2; padding: 14px 4px;
  display: flex; justify-content: center; margin-top: 18px;
}
.cg-generate-btn {
  background: #c8102e; color: #fff; border: none; border-radius: 10px; padding: 13px 32px;
  font-size: 15px; font-weight: 800; cursor: pointer; font-family: inherit; box-shadow: 0 3px 10px rgba(200,16,46,0.28);
}
.cg-generate-btn:hover { background: #a80d26; }
.cg-generate-btn:disabled { background: #d9a3ac; cursor: not-allowed; box-shadow: none; }
.cg-generate-status { text-align: center; font-size: 12.5px; color: #667; margin-top: 8px; }
.cg-generate-status.cg-status-error { color: #c8102e; }

/* ── 位置編集モーダル（フルスクリーンに近い大きめモーダル。編集自由度を最大化） ── */
.cg-edit-overlay {
  display: none; position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,0.72);
  align-items: center; justify-content: center; padding: 10px;
}
.cg-edit-overlay.active { display: flex; }
.cg-edit-box {
  background: #fff; border-radius: 14px; width: 100%; max-width: 920px; max-height: 96vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.cg-edit-head {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 16px;
  border-bottom: 1px solid #eee; flex-shrink: 0;
}
.cg-edit-title { font-size: 14px; font-weight: 800; }
.cg-edit-close { background: none; border: none; font-size: 20px; cursor: pointer; color: #888; padding: 4px 8px; }
.cg-edit-body { flex: 1; overflow: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.cg-edit-canvas-wrap {
  position: relative; width: 100%; touch-action: none; border-radius: 8px; overflow: hidden;
  border: 1px solid #ddd; background: #222;
}
.cg-edit-canvas-wrap img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.cg-edit-hint { font-size: 11.5px; color: #778; line-height: 1.6; }

/* 個別の貼付マーカー（ドラッグ・リサイズ可能。実カード画像＋赤枠の二重表示） */
.cg-marker {
  position: absolute; border: 2.5px solid #ff2d2d; background: rgba(255,45,45,0.14);
  box-sizing: border-box; cursor: move; touch-action: none; min-width: 16px; min-height: 12px;
}
.cg-marker.selected { border-color: #ffd400; background: rgba(255,212,0,0.22); z-index: 5; }
.cg-marker-card-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill;
  pointer-events: none; border-radius: 2px; opacity: 0.92;
}
.cg-marker-label {
  position: absolute; top: -20px; left: -2px; background: #ff2d2d; color: #fff; font-size: 10px;
  font-weight: 800; padding: 1px 5px; border-radius: 4px; white-space: nowrap; pointer-events: none;
}
.cg-marker.selected .cg-marker-label { background: #cc9d00; }
.cg-marker-corner {
  position: absolute; width: 18px; height: 18px; margin: -9px;
  background: #ff2d2d; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3); touch-action: none;
}
.cg-marker.selected .cg-marker-corner { background: #cc9d00; }
.cg-marker-corner.cgm-nw { top: 0;   left: 0;   cursor: nwse-resize; }
.cg-marker-corner.cgm-ne { top: 0;   left: 100%; cursor: nesw-resize; }
.cg-marker-corner.cgm-sw { top: 100%; left: 0;   cursor: nesw-resize; }
.cg-marker-corner.cgm-se { top: 100%; left: 100%; cursor: nwse-resize; }
.cg-marker-del {
  position: absolute; top: -20px; right: -2px; width: 18px; height: 18px; line-height: 16px;
  background: #333; color: #fff; border-radius: 50%; font-size: 12px; text-align: center; cursor: pointer;
}

/* ── 側面（奥行き面）用マーカー（2026-09-15追加）──
   正面用（赤枠・軸並行矩形）とは別に、青系の自由四角形（台形・平行四辺形）として区別する。
   4隅の点を個別にドラッグでき、CSSのclip-pathで実カード画像をその形に切り抜いて重ねる。 */
.cg-side-marker {
  position: absolute; cursor: move; touch-action: none; box-sizing: border-box;
  min-width: 16px; min-height: 12px;
}
.cg-side-marker-clip { position: absolute; inset: 0; overflow: hidden; }
.cg-side-marker-clip .cg-marker-card-img { opacity: 0.92; }
.cg-side-marker-fill { position: absolute; inset: 0; background: rgba(37,99,235,0.16); }
.cg-side-marker.selected .cg-side-marker-fill { background: rgba(255,212,0,0.22); }
.cg-side-marker-outline {
  position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none;
}
.cg-side-marker-outline polygon {
  fill: none; stroke: #2563eb; stroke-width: 2.5; vector-effect: non-scaling-stroke;
}
.cg-side-marker.selected .cg-side-marker-outline polygon { stroke: #cc9d00; }
.cg-side-marker-vertex {
  position: absolute; width: 18px; height: 18px; margin: -9px;
  background: #2563eb; border: 2px solid #fff; border-radius: 50%; cursor: grab;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3); touch-action: none;
}
.cg-side-marker.selected .cg-side-marker-vertex { background: #cc9d00; }
.cg-side-marker .cg-marker-label { background: #2563eb; }
.cg-side-marker.selected .cg-marker-label { background: #cc9d00; }

.cg-edit-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cg-edit-toolbar button {
  font-size: 12.5px; font-weight: 700; padding: 8px 13px; border-radius: 7px; cursor: pointer; font-family: inherit;
}
.cg-btn-add-marker { background: #eef4ff; color: #2563eb; border: 1px solid #bcd3f7; }
.cg-btn-add-marker:hover { background: #dde9ff; }
.cg-btn-add-side-marker { background: #e8f0ff; color: #1d4ed8; border: 1px solid #93b4f5; }
.cg-btn-add-side-marker:hover { background: #d6e4ff; }
.cg-btn-clear-markers { background: #fff1f1; color: #c8102e; border: 1px solid #f3c6c6; }
.cg-btn-clear-markers:hover { background: #ffe3e3; }
.cg-edit-marker-count { font-size: 12px; color: #667; margin-left: auto; }

.cg-edit-foot {
  display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid #eee; flex-shrink: 0;
}
.cg-edit-foot button {
  font-size: 13px; font-weight: 700; padding: 9px 18px; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.cg-edit-cancel { background: #f4f4f4; color: #555; border: 1px solid #ddd; }
.cg-edit-save { background: #0969da; color: #fff; border: none; }
.cg-edit-save:hover { background: #085ec4; }
