// style.css
/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Base Colors (Shared) */
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: rgba(59, 130, 246, 0.2);
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #10b981;
  --warning: #f59e0b;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -1px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -2px rgba(0,0,0,0.2);
}

/* Light Theme Palette */
html[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.03);
}

/* Dark Theme Palette (Default) */
html[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #334155;
  --border: #475569;
  --border-dark: #64748b;
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-light: #94a3b8;
}

body {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

/* ===== Layout ===== */
#app {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 24px clamp(12px, 2vw, 32px);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}
header h1 .material-symbols-rounded { color: var(--primary); font-size: 28px; }

/* ===== Stepper ===== */
.stepper {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  padding: 12px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
}
.step-item.active { color: var(--primary); }
.step-item.completed { color: var(--text-main); }
.step-item.step-navigable { cursor: pointer; border-radius: var(--radius-sm); padding: 4px 6px; margin: -4px -6px; }
.step-item.step-navigable:hover { background: var(--surface-alt); color: var(--primary); }
.step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-alt);
  font-size: 0.8rem;
}
.step-item.active .step-num { background: var(--primary); color: #ffffff; }
.step-item.completed .step-num { background: var(--text-main); color: var(--surface); }
.step-divider { flex: 1; height: 2px; background: var(--border); min-width: 40px; }
.step-item.completed + .step-divider { background: var(--text-main); }

/* ===== Step Container ===== */
.step-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: opacity 0.3s ease;
}
.step-inner { padding: 32px; overflow-y: auto; height: 100%; display: flex; flex-direction: column; }

.step-title {
  font-size: 1.25rem; font-weight: 700; margin-bottom: 20px;
  color: var(--text-main);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}

/* ===== Buttons & Inputs ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #ffffff; box-shadow: 0 2px 4px rgba(59,130,246,0.2); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--surface-alt); color: var(--text-main); border: 1px solid var(--border-dark); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

/* Soft Danger Button */
.btn-soft-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-soft-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.btn-danger-outline { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,0.5); }
.btn-danger-outline:hover:not(:disabled) { background: rgba(239,68,68,0.2); border-color: var(--danger); }
/* 罫線モードONが分かりやすいようにする */
#btnDrawLine.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(59,130,246,0.25);
}

.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-icon { padding: 8px; min-width: 36px; border-radius: var(--radius); }
.material-symbols-rounded { font-variation-settings: 'FILL' 1, 'wght' 500, 'GRAD' 0, 'opsz' 24; font-size: 20px; }

/* Button Groups (Segmented Control) */
.btn-group {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}
.btn-group .btn {
  background: transparent; color: var(--text-muted); border: none; box-shadow: none;
  border-radius: var(--radius-sm); padding: 8px 16px;
}
.btn-group .btn:hover:not(:disabled) { color: var(--text-main); background: rgba(255,255,255,0.05); transform: none; }
.btn-group .btn.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); font-weight: 700; border: 1px solid var(--border); }

.btn-group.toggle-group { height: 36px; align-items: stretch; }
.btn-group.toggle-group .btn { padding: 0 12px; font-size: 0.8rem; height: 100%; }

/* Apple-style switches */
.switch-control-wrap { display: flex; align-items: center; min-height: 36px; }
.switch-control {
  display: inline-flex !important; align-items: center; gap: 8px;
  padding: 0 !important; margin: 0 !important;
  color: var(--text-main) !important; font-size: 0.8rem !important;
  font-weight: 600 !important; line-height: 1 !important;
  cursor: pointer; user-select: none;
}
.switch-control input {
  position: absolute; width: 1px; height: 1px; opacity: 0;
  pointer-events: none;
}
.switch-track {
  position: relative; display: inline-block; flex: 0 0 auto;
  width: 44px; height: 26px; border-radius: 999px;
  background: var(--border-dark); transition: background-color 0.2s ease;
  box-shadow: inset 0 0 0 1px rgba(15,23,42,0.18);
}
.switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(15,23,42,0.35);
  transition: transform 0.2s ease;
}
.switch-control input:checked + .switch-track { background: var(--primary); }
.switch-control input:checked + .switch-track::after { transform: translateX(18px); }
.switch-control input:disabled + .switch-track { opacity: 0.45; }
.switch-control:focus-within .switch-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.click-layout-slot { display: none; align-items: stretch; flex: 0 0 auto; }
.click-layout-slot #btnClickLayout { white-space: nowrap; }

/* ===== Upload Area ===== */
.upload-area {
  border: 2px dashed var(--border-dark); border-radius: var(--radius-lg);
  padding: 64px 24px; text-align: center;
  transition: all 0.2s; background: var(--surface-alt);
  flex-shrink: 0;
}
.upload-area.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-icon .material-symbols-rounded { font-size: 64px; color: var(--text-light); margin-bottom: 16px; }
.upload-area.dragover .upload-icon .material-symbols-rounded { color: var(--primary); }
.upload-area p { color: var(--text-muted); margin-bottom: 24px; font-size: 1.1rem; }

/* ===== Step 2: Thumbnails ===== */
.page-filter-controls { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-shrink: 0; }
.hint { font-size: 0.85rem; color: var(--text-muted); display: flex; align-items: center; gap: 4px; margin-bottom: 16px; flex-shrink: 0;}

.page-thumbnails {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  grid-auto-rows: max-content;
  gap: 16px;
  padding: 4px; flex: 1; overflow-y: auto;
  align-content: flex-start;
  min-height: 0;
}
.page-thumb {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: zoom-in; transition: all 0.2s; position: relative;
  display: flex; flex-direction: column;
  aspect-ratio: 1;
}
.page-thumb:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--border-dark); }
.page-thumb.selected { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.page-thumb.selected::after {
  content: none !important;
  display: none !important;
}
.page-thumb-select {
  position: absolute !important; top: 8px; right: 8px; width: 34px; height: 34px;
  padding: 0; margin: 0; border-radius: 999px; border: 2px solid rgba(255,255,255,0.95);
  background: rgba(15,23,42,0.65); color: #ffffff; display: flex !important;
  align-items: center; justify-content: center; z-index: 20; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: all 0.2s; line-height: 1;
  appearance: none; -webkit-appearance: none; flex: none;
}
.page-thumb-select:hover { transform: scale(1.08); background: var(--primary); }
.page-thumb-select .material-symbols-rounded { font-size: 22px; line-height: 1; }
.page-thumb.selected .page-thumb-select { background: var(--primary); border-color: #ffffff; }

.page-thumb-image-container {
  width: 100%;
  flex: 1;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  overflow: hidden;
  min-height: 0;
}
.page-thumb canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto !important;
  height: auto !important;
  display: block;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

.page-thumb-info {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.page-thumb-label { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); white-space: nowrap; }
.page-thumb-name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
  text-align: left;
  flex: 1;
}

/* ===== Step 2 integrated layout ===== */
.step2-action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.step2-layout {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}
.step2-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
}
.step2-floor-panel {
  width: 320px;
  margin: 0;
  flex-shrink: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}
.floor-add-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 12px;
  flex-shrink: 0;
  min-width: 0;
}
.floor-add-row .floor-name-input {
  min-width: 0;
}
.floor-add-btn {
  flex-shrink: 0;
  white-space: nowrap;
  padding-left: 10px;
  padding-right: 10px;
}

/* ===== Step 3: Work Area ===== */
.work-area {
  display: flex; flex-direction: column; height: 100%; gap: 16px;
}
.work-layout {
  display: flex; flex: 1; gap: 16px; min-height: 0;
}

/* Toolbar Redesign */
.toolbar-container {
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 20px;
}

.setting-item { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.setting-item label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); padding-left: 2px; line-height: 1; transition: opacity 0.2s; }

/* list-name-displayをlist-name-inputに変更 */
.list-name-input {
  font-size: 1.1rem; font-weight: 700; color: var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1;
  background: transparent; border: none; border-bottom: 1px dashed var(--border-dark);
  outline: none; transition: border-color 0.2s; padding-bottom: 2px;
}
.list-name-input:focus { border-bottom-color: var(--primary); }

.badge-info {
  background: var(--surface); border: 1px solid var(--border); padding: 6px 12px;
  border-radius: 20px; font-size: 0.85rem; font-weight: 600; color: var(--text-main);
  display: flex; align-items: center; gap: 6px; box-shadow: var(--shadow-sm);
}

/* Canvas Container */
.main-canvas-wrapper {
  flex: 1; position: relative; border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg); overflow: auto;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
  z-index: 1;
}
#pdfCanvas { display: block; margin: 0 auto; background-color: #ffffff; }
.selection-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; cursor: crosshair; }
.edit-item-layer {
  box-sizing: border-box !important;
  background-origin: border-box !important;
  background-clip: border-box !important;
  z-index: 5 !important;
}

/* Side Panel */
.side-panel {
  width: 300px; display: flex; flex-direction: column; gap: 16px;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.side-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px; border-bottom: 1px solid var(--border-dark); flex-shrink: 0;
}
.side-panel-header h3 { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: 6px; color: var(--text-main); }
.side-panel-header h3 span { color: var(--primary); }

.extracted-list {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  gap: 12px; align-content: flex-start;
  padding-right: 4px; min-height: 0;
}

/* グループヘッダーとコンテンツ用のスタイル */
.group-header {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); padding: 8px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; font-size: 0.85rem; font-weight: 700; color: var(--text-main);
  box-shadow: var(--shadow-sm); transition: background-color 0.2s, border-color 0.2s;
}
.group-header:hover { background: var(--surface-alt); border-color: var(--border-dark); }
.group-content { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.group-content.collapsed { display: none; }
.group-toggle-icon { font-size: 20px; color: var(--text-muted); transition: transform 0.3s; }
.group-toggle-icon.collapsed { transform: rotate(-90deg); }

.extracted-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; box-shadow: var(--shadow-sm); transition: transform 0.2s, box-shadow 0.2s;
  position: relative; display: flex; flex-direction: column;
}
.extracted-item:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-dark); }
.extracted-item img {
  width: 100%; height: 100px; flex-shrink: 0;
  object-fit: contain; background: #ffffff; display: block; cursor: pointer;
}

/* ファイル名入力用スタイル */
.extracted-item-name-input {
  flex: 1; border: none; background: transparent; color: var(--text-main);
  font-size: 0.7rem; font-weight: 600; text-align: left; padding: 6px 4px 6px 8px;
  outline: none; min-width: 0; transition: background-color 0.2s;
}
.extracted-item-name-input:focus {
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--primary);
}
.extracted-item-ext {
  font-size: 0.65rem; color: var(--text-muted); padding-right: 8px; font-weight: 600; flex-shrink: 0;
}

.del-btn {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(30, 41, 59, 0.9); border: 1px solid var(--border); color: #ef4444;
  display: flex; align-items: center; justify-content: center; cursor: pointer; opacity: 0; transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}
.extracted-item:hover .del-btn { opacity: 1; }
.del-btn:hover { background: #ef4444; color: #ffffff; border-color: #ef4444; }
.del-btn .material-symbols-rounded { font-size: 14px; }

/* Selection Rects */
.selection-rect { position: absolute; border: 2px dashed; pointer-events: none; border-radius: 2px; z-index: 12; box-sizing: border-box; }
.selection-rect.header-sel { border-color: var(--warning); background: rgba(245,158,11,0.2); }
.selection-rect.fixed-header-sel { border-color: #8b5cf6; background: rgba(139,92,246,0.2); }
.selection-rect.header-row-sel { border-color: #06b6d4; background: rgba(6,182,212,0.2); }
.selection-rect.target-sel { border-color: var(--success); background: rgba(16,185,129,0.2); }

.selection-rect.edit-sel { border-color: #eab308; background: rgba(234, 179, 8, 0.2); }
.selection-rect.copy-sel { border-color: var(--primary); background: rgba(59, 130, 246, 0.2); }
.selection-rect.confirmed { border-style: solid; z-index: 10; }

.history-rect {
  opacity: 0.8 !important; border-color: var(--border-dark) !important;
  background: rgba(148, 163, 184, 0.15) !important; border-style: dashed !important; z-index: 1 !important;
}

/* Loading & Toast */
.loading-info {
  padding: 16px; background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius); color: var(--primary-hover); font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 20px;
}
.loading-info .material-symbols-rounded { animation: spin 2s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 12px 24px; background: var(--surface-alt); color: var(--text-main); font-weight: 500;
  border-radius: 30px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  opacity: 0; pointer-events: none; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.preview-modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15, 23, 42, 0.8); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 2000; cursor: default; animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.preview-close-btn { position: absolute; top: 24px; right: 24px; background: var(--surface); color: var(--text-main); border: 1px solid var(--border); border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 10; box-shadow: var(--shadow); transition: all 0.2s; }
.preview-close-btn:hover { background: var(--danger); color: #fff; border-color: var(--danger); transform: scale(1.05); }
.preview-modal img { border-radius: var(--radius); box-shadow: var(--shadow-lg); background: #ffffff; cursor: default; }
.preview-modal-name { background: var(--surface); color: var(--text-main); padding: 8px 24px; border-radius: 30px; font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border); display: flex; align-items: center; gap: 4px; cursor: text; margin: 0; }
.preview-name-input { background: transparent; border: none; color: inherit; font-family: inherit; font-size: inherit; font-weight: inherit; outline: none; text-align: left; min-width: 150px; border-bottom: 1px dashed var(--border-dark); transition: border-color 0.2s; }
.preview-name-input:focus { border-bottom-color: var(--primary); }
.preview-nav-btn { background: var(--surface); color: var(--text-main); border: 1px solid var(--border); box-shadow: var(--shadow); transition: all 0.2s; flex-shrink: 0; }
.preview-nav-btn:hover:not(:disabled) { background: var(--primary); color: #fff; border-color: var(--primary); transform: scale(1.05); }
.preview-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ===== Floor Setup ===== */
.floor-name-input {
  flex: 1; padding: 8px 12px; border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text-main); font-size: 0.9rem; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.floor-name-input:focus { border-color: var(--primary); }
.floor-list {
  display: flex; flex-direction: column; gap: 8px;
  flex: 1; overflow-y: auto; min-height: 0;
}
.floor-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; color: var(--text-main);
  transition: all 0.2s;
}
.floor-item:hover { border-color: var(--border-dark); box-shadow: var(--shadow-sm); }
.floor-item .floor-item-name { display: flex; align-items: center; gap: 8px; }
.floor-item .floor-item-name .material-symbols-rounded { color: var(--warning); font-size: 18px; }
.floor-item .floor-item-actions { display: flex; gap: 4px; }
.floor-item .floor-item-actions button {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px; border-radius: 4px; transition: all 0.2s; display: flex; align-items: center;
}
.floor-item .floor-item-actions button:hover { color: var(--danger); background: rgba(239,68,68,0.1); }
.floor-selector {
  flex: 1; padding: 6px 10px; border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text-main); font-size: 0.85rem; font-weight: 600;
  font-family: inherit; outline: none; cursor: pointer;
}
.floor-selector:focus { border-color: var(--primary); }
.floor-subgroup-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; margin-top: 4px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.9rem; font-weight: 700; color: var(--text-main);
  background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.35);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, border-color 0.2s;
  grid-column: 1 / -1;
}
.floor-subgroup-header:hover { background: rgba(245,158,11,0.2); border-color: rgba(245,158,11,0.55); }
.floor-subgroup-header .group-toggle-icon { color: var(--warning); }
.group-content > .group-content { grid-column: 1 / -1; }
.extracted-item.dragging { opacity: 0.4; }
.floor-subgroup-header.drag-over,
.group-header.drag-over { background: var(--primary-light); border-color: var(--primary); }

/* Horizontal merge controls */
.merge-toolbar, .merge-footer { display:flex; flex-wrap:wrap; gap:8px; flex-shrink:0; }
.merge-select { display:flex; align-items:center; gap:6px; padding:8px; font-size:12px; min-height:36px; cursor:pointer; }
.merge-select input { width:16px; height:16px; accent-color:var(--primary); }
.merge-dialog { margin:auto; width:min(800px, calc(100vw - 32px)); max-height:90vh; overflow:auto; padding:24px; border:1px solid var(--border); border-radius:12px; background:var(--surface); color:var(--text-main); font:14px/1.5 'Noto Sans JP',sans-serif; }
.merge-dialog::backdrop { background:rgba(0,0,0,.65); }
.merge-dialog h2 { font-size:20px; margin-bottom:8px; }
.merge-dialog p { margin:12px 0; }
.merge-order { display:flex; flex-direction:column; gap:8px; margin:16px 0; max-height:240px; overflow:auto; }
.merge-order-row { display:flex; align-items:center; gap:8px; }
.merge-order-row span { flex:1; min-width:0; overflow-wrap:anywhere; }
.merge-dialog .btn { min-height:44px; }
.merge-preview-wrap { overflow:auto; max-height:35vh; background:#fff; border:1px solid var(--border); }
.merge-preview { display:block; max-width:100%; height:auto; }
.merge-preview[hidden] { display:none; }
.merge-dialog input { max-width:100%; padding:8px; border:1px solid var(--border); border-radius:6px; background:var(--surface-alt); color:var(--text-main); font:inherit; }
.merge-footer { justify-content:flex-end; margin-top:16px; }
.merge-dialog :focus-visible, .merge-toolbar :focus-visible, .merge-select input:focus-visible { outline:2px solid var(--primary); outline-offset:3px; }
@media (max-width:480px) { .merge-dialog {padding:16px;} .merge-order-row {flex-wrap:wrap;} .merge-order-row span {flex-basis:100%;} }
@media (prefers-reduced-motion:reduce) { .merge-dialog *, .merge-toolbar * { transition:none!important; animation:none!important; } }


/* ===== Table layout editor ===== */
.layout-dialog {
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px 12px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-main);
  box-shadow: var(--shadow);
}
.layout-dialog-form { display: grid; gap: 12px; width: 100%; }
.layout-dialog-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.layout-dialog-kicker {
  color: var(--primary); font-size: 0.72rem; font-weight: 700;
  letter-spacing: 0.08em; margin-bottom: 3px;
}
.layout-dialog-header h2 { font-size: 1.08rem; line-height: 1.3; margin: 0; }
.layout-dialog-header p { margin-top: 5px; color: var(--text-muted); font-size: 0.78rem; line-height: 1.5; }
.layout-dialog-badge {
  display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto;
  padding: 6px 9px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-muted); font-size: 0.72rem; white-space: nowrap;
  background: var(--surface-alt);
}
.layout-dialog-badge .material-symbols-rounded { font-size: 16px; color: var(--primary); }
.layout-visual { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr); gap: 12px; align-items: stretch; }
.layout-basic-section, .layout-optional-section {
  min-width: 0; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.layout-optional-section { border-style: dashed; }
.layout-section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.layout-section-heading > span { font-size: 0.78rem; font-weight: 800; color: var(--text-main); }
.layout-section-heading > small { color: var(--text-muted); font-size: 0.68rem; }
.layout-basic-steps { display: flex; align-items: center; gap: 7px; min-width: 0; }
.layout-flow-arrow { flex: 0 0 auto; color: var(--text-light); font-weight: 800; }
.layout-step-button, .layout-option-button {
  appearance: none; border: 1px solid var(--border-dark); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-main); font: inherit; cursor: pointer;
  transition: border-color 0.16s, background-color 0.16s, box-shadow 0.16s, transform 0.16s;
}
.layout-step-button {
  display: grid; grid-template-columns: 25px minmax(0, 1fr) auto; align-items: center;
  gap: 7px; flex: 1 1 0; min-width: 0; padding: 8px 9px; text-align: left;
}
.layout-step-button:hover:not(:disabled), .layout-option-button:hover:not(:disabled) {
  border-color: var(--primary); background: var(--primary-light); transform: translateY(-1px);
}
.layout-step-button.is-active, .layout-option-button.is-active {
  border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); background: var(--surface);
}
.layout-step-number {
  display: inline-flex; align-items: center; justify-content: center;
  width: 25px; height: 25px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 0.78rem; font-weight: 800;
}
.layout-step-copy, .layout-option-button > span:last-child { display: grid; min-width: 0; gap: 1px; }
.layout-step-copy strong, .layout-option-button strong { font-size: 0.76rem; line-height: 1.2; white-space: nowrap; }
.layout-step-copy small, .layout-option-button small { color: var(--text-muted); font-size: 0.66rem; line-height: 1.2; white-space: nowrap; }
.layout-step-check { color: var(--text-light); font-size: 0.64rem; white-space: nowrap; }
.layout-optional-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.layout-option-button { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 8px 9px; text-align: left; }
.layout-option-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 25px; height: 25px; border-radius: 7px;
  color: #bd45cd; background: rgba(189,69,205,0.12); font-size: 1rem; font-weight: 800;
}
.layout-option-button[data-edge="unit"] .layout-option-icon { color: var(--success); background: rgba(16,185,129,0.13); }
.layout-dialog-hint {
  min-height: 34px; display: flex; align-items: center;
  padding: 8px 10px; border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-main); background: var(--primary-light);
  font-size: 0.76rem; line-height: 1.45;
}
.layout-dialog-info { display: none; }
.layout-dialog-error { min-height: 0; margin: 0; color: var(--danger); font-size: 0.76rem; }
.layout-dialog-actions { display: flex; align-items: center; gap: 7px; padding-top: 2px; }
.layout-dialog-actions-spacer { flex: 1 1 auto; }
.layout-dialog-actions .btn { padding: 7px 12px; font-size: 0.78rem; white-space: nowrap; }
.layout-dialog-actions #layoutReset { margin-right: auto; }
.layout-hover-candidate.layout-unit-break-preview, .layout-applied-preview.layout-unit-break-preview { border-left-style: dashed !important; }
.layout-hover-candidate.layout-band-break-preview, .layout-applied-preview.layout-band-break-preview { border-top-style: dashed !important; }
@media (max-width: 900px) {
  .layout-visual { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .layout-dialog-header { display: grid; }
  .layout-basic-steps { align-items: stretch; flex-direction: column; }
  .layout-flow-arrow { display: none; }
  .layout-optional-buttons { grid-template-columns: 1fr; }
}

/* 表構成エディタ：右サイドバー内の一時パネル */
.layout-dialog-sidebar {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  border-radius: var(--radius);
}
.layout-dialog-sidebar .layout-dialog-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  height: auto;
}
.layout-dialog-sidebar .layout-dialog-form > * { flex: 0 0 auto; }
.layout-dialog-sidebar .layout-dialog-header {
  display: grid;
  gap: 8px;
  padding-bottom: 10px;
  flex: 0 0 auto;
}
.layout-dialog-sidebar .layout-dialog-header h2 { font-size: 0.98rem; }
.layout-dialog-sidebar .layout-dialog-header p { font-size: 0.72rem; line-height: 1.45; margin: 0; }
.layout-dialog-sidebar .layout-dialog-badge { justify-self: start; font-size: 0.68rem; }
.layout-dialog-sidebar .layout-visual { grid-template-columns: 1fr; gap: 8px; flex: 0 0 auto; }
.layout-dialog-sidebar .layout-basic-steps {
  align-items: stretch;
  flex-direction: column;
  gap: 5px;
}
.layout-dialog-sidebar .layout-flow-arrow {
  align-self: center;
  transform: rotate(90deg);
  line-height: 1;
}
.layout-dialog-sidebar .layout-step-button { flex: 0 0 auto; width: 100%; }
.layout-dialog-sidebar .layout-optional-buttons { grid-template-columns: 1fr; gap: 5px; }
.layout-dialog-sidebar .layout-option-button { width: 100%; padding: 7px 8px; }
.layout-dialog-sidebar .layout-dialog-hint { font-size: 0.7rem; min-height: 48px; }
.layout-dialog-sidebar .layout-dialog-actions { flex-wrap: wrap; }
.layout-dialog-sidebar .layout-dialog-actions-spacer { display: none; }
.layout-dialog-sidebar .layout-dialog-actions #layoutReset { flex: 1 1 100%; margin-right: 0; }
.layout-dialog-sidebar .layout-dialog-actions .btn { flex: 1 1 auto; padding: 7px 8px; }
.layout-dialog-sidebar .layout-dialog-info {
  display: block;
  margin: 0;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  background: rgba(59,130,246,0.10);
  color: var(--text-muted);
  font-size: 0.68rem;
  line-height: 1.4;
}
.layout-dialog-sidebar .layout-basic-section,
.layout-dialog-sidebar .layout-optional-section { padding: 9px; }
.layout-dialog-sidebar .layout-section-heading { margin-bottom: 6px; }
.layout-dialog-sidebar .layout-control-state {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--text-light);
  font-size: 0.62rem;
  white-space: nowrap;
}
.layout-dialog-sidebar .layout-option-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
  flex: 1 1 auto;
}
.layout-dialog-sidebar .layout-option-copy strong,
.layout-dialog-sidebar .layout-option-copy small { overflow: hidden; text-overflow: ellipsis; }

/* 表構成ツールバー：既存のツールバー高を増やさない */
.click-layout-slot.layout-slot-active {
  display: flex !important;
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  height: 44px;
  max-height: 44px;
  align-items: stretch;
}
.layout-toolbar-editor {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  height: 44px;
  max-height: 44px;
  box-sizing: border-box;
  padding: 4px 8px;
  overflow: hidden;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface-alt);
}
.layout-toolbar-title {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-width: 118px;
  white-space: nowrap;
}
.layout-toolbar-kicker {
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
}
.layout-toolbar-title strong {
  color: var(--text-main);
  font-size: 0.76rem;
}
.layout-toolbar-steps {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 0;
}
.layout-toolbar-arrow { color: var(--text-light); font-size: 0.8rem; }
.layout-toolbar-step {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  min-width: 132px;
  padding: 4px 8px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-main);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.16s, background-color 0.16s, box-shadow 0.16s;
}
.layout-toolbar-step:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }
.layout-toolbar-step.is-active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.layout-toolbar-step:disabled { opacity: 0.45; cursor: not-allowed; }
.layout-toolbar-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
}
.layout-toolbar-step-label { font-size: 0.72rem; font-weight: 700; }
.layout-toolbar-step .layout-control-state {
  margin-left: auto;
  color: var(--text-light);
  font-size: 0.62rem;
}
.layout-toolbar-hint {
  flex: 1 1 auto;
  min-width: 120px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.72rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layout-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}
.layout-toolbar-actions .btn { height: 34px; padding: 5px 9px; font-size: 0.72rem; white-space: nowrap; }
@media (max-width: 1100px) {
  .layout-toolbar-title { min-width: 92px; }
  .layout-toolbar-title strong { display: none; }
  .layout-toolbar-step { min-width: 112px; }
  .layout-toolbar-hint { min-width: 70px; }
}
@media (max-width: 760px) {
  .layout-toolbar-hint { display: none; }
  .layout-toolbar-step { min-width: 104px; }
  .layout-toolbar-actions #layoutReset { display: none; }
}

/* ===== 画面内フィットと表構成ツールバーの簡素化 ===== */
html, body {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
#app {
  min-width: 0;
  max-width: 100vw;
  overflow: hidden;
}
.step-content,
#step3,
.work-area,
.work-layout,
.work-layout > * {
  min-width: 0;
  min-height: 0;
}
.work-area,
.work-layout {
  max-width: 100%;
  overflow: hidden;
}
.work-layout > .step3-left-col,
.work-layout > .step3-right-col,
.toolbar-container,
.side-panel {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
#drawToolGroup {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
  align-content: flex-start;
}
#drawToolGroup .btn { flex: 0 0 auto; }
.side-panel-header,
.side-panel-header h3 {
  min-width: 0;
  max-width: 100%;
}
.side-panel-header h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-panel-header > .btn {
  min-width: 0;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 表構成は「手順・ヒント・操作」だけを残す */
.layout-toolbar-title { min-width: 62px; }
.layout-toolbar-title strong { display: none; }
.layout-toolbar-step { min-width: 118px; }
.layout-toolbar-step .layout-control-state { display: none; }
.layout-toolbar-hint { min-width: 96px; font-size: 0.68rem; }
.layout-dialog-sidebar .layout-dialog-header p { display: none; }
.layout-dialog-sidebar .layout-dialog-header { padding-bottom: 6px; }
.layout-dialog-sidebar .layout-dialog-kicker { margin-bottom: 0; }

@media (max-width: 1500px) {
  .layout-toolbar-step { min-width: 100px; }
  .layout-toolbar-hint { display: none; }
  .layout-toolbar-actions .btn { padding-left: 7px; padding-right: 7px; }
}
@media (max-width: 900px) {
  #drawToolGroup .btn { padding-left: 10px; padding-right: 10px; }
  .layout-toolbar-title { min-width: 54px; }
  .layout-toolbar-step { min-width: 100px; }
  .layout-toolbar-hint { display: none; }
}
@media (max-width: 1300px) {
  .layout-toolbar-editor { gap: 5px; padding-left: 5px; padding-right: 5px; }
  .layout-toolbar-title { min-width: 48px; }
  .layout-toolbar-step { min-width: 88px; padding-left: 6px; padding-right: 6px; }
  .layout-toolbar-actions #layoutReset { display: none; }
}

/* ===== ルート幅・ヘッダー・左右カラムの最終フィット ===== */
header {
  width: 100%;
  min-width: 0;
  flex-shrink: 0;
  overflow: hidden;
}
header > div {
  min-width: 0;
}
header > div.header-brand {
  flex: 0 1 40%;
  max-width: 40%;
}
header > div.header-workflow {
  flex: 1 1 60%;
  min-width: 0;
  justify-content: flex-end;
}
header h1 {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
header > div.header-brand > .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.stepper {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
  overflow: hidden;
}
.step-item {
  min-width: 0;
  white-space: nowrap;
}
.step-item > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step-divider { min-width: 16px; }
.work-layout { width: 100%; }
.work-layout > .step3-left-col {
  width: 0;
  flex: 1 1 0;
}
.work-layout > .step3-right-col {
  width: 300px;
  flex: 0 0 300px;
}
.side-panel-header { flex-wrap: wrap; gap: 8px; }
.side-panel-header h3 { flex: 1 1 120px; }
.side-panel-header > .btn { flex: 0 1 auto; max-width: 48%; }

@media (max-width: 1100px) {
  header > div.header-brand { max-width: 46%; }
  header > div.header-workflow { flex-basis: 54%; }
  .stepper { padding-left: 10px; padding-right: 10px; gap: 8px; }
  .step-item { font-size: 0.76rem; gap: 5px; }
  .step-num { width: 24px; height: 24px; }
}
@media (max-width: 760px) {
  header > div.header-brand { max-width: 48%; }
  header > div.header-workflow { flex-basis: 52%; gap: 6px !important; }
  header > div.header-workflow > a { display: none !important; }
  .stepper { gap: 5px; padding: 6px 8px; }
  .step-divider { min-width: 8px; }
  .step-item { font-size: 0.7rem; }
  .step-item > span { max-width: 6em; }
}

/* ===== Global viewport layout v2: structural fit ===== */
html {
  width: 100%;
  min-width: 0;
  height: 100%;
}
body {
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}
#app {
  box-sizing: border-box;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  height: 100vh;
  max-height: 100vh;
  min-height: 0;
  padding: clamp(12px, 1.6vw, 32px);
  overflow: hidden;
}
@supports (height: 100dvh) {
  #app {
    height: 100dvh;
    max-height: 100dvh;
  }
}
#app > header,
#app > .step-content {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
header {
  display: grid !important;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  margin: 0 0 clamp(12px, 1.5vw, 24px);
  overflow: visible;
}
header > div {
  min-width: 0;
  max-width: 100%;
}
header > div.header-brand,
header > div.header-workflow {
  min-width: 0;
  max-width: 100%;
  flex: none !important;
}
header > div.header-brand {
  display: flex;
  overflow: hidden;
}
header > div.header-workflow {
  display: flex;
  justify-content: flex-end;
  overflow: hidden;
}
header h1 {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stepper {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  gap: clamp(6px, 0.8vw, 16px);
  padding-left: clamp(10px, 1.2vw, 24px);
  padding-right: clamp(10px, 1.2vw, 24px);
  overflow: hidden;
}
.step-item {
  min-width: 0;
  flex: 0 1 auto;
  white-space: nowrap;
}
.step-item > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step-divider {
  min-width: clamp(12px, 2vw, 40px);
  flex: 1 1 0;
}
.step-content {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  overflow: hidden;
}
.step-inner {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}
.upload-area {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Step 3: grid owns the split; children may not impose min-content width. */
#step3 {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
}
#step3 > .work-area {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
#step3 .work-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 300px);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
#step3 .work-layout > .step3-left-col,
#step3 .work-layout > .step3-right-col {
  width: auto !important;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  flex: none !important;
}
#step3 .toolbar-container,
#step3 .main-canvas-wrapper,
#step3 .side-panel {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
#step3 .main-canvas-wrapper {
  min-height: 0;
}
#step3 .toolbar-container > div,
#step3 .side-panel-header,
#step3 .side-panel-header h3 {
  min-width: 0;
  max-width: 100%;
}
#step3 .floor-selector {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
#step3 .side-panel-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}
#step3 .side-panel-header > .btn {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  white-space: nowrap;
}

@media (max-width: 1700px) {
  header {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 12px;
  }
  header > div.header-workflow {
    justify-content: stretch;
    overflow: visible;
  }
}
@media (max-width: 1100px) {
  #step3 .work-layout {
    grid-template-columns: minmax(0, 1fr);
    overflow: auto;
  }
  #step3 .work-layout > .step3-right-col {
    min-height: 280px;
  }
}
@media (max-width: 620px) {
  header > div.header-brand {
    flex-wrap: wrap;
    gap: 8px !important;
  }
  header h1 {
    font-size: 1.1rem;
  }
  header > div.header-workflow {
    flex-wrap: wrap;
  }
  header > div.header-workflow > a {
    display: none !important;
  }
}

/* ===== Stepper compact sizing ===== */
header > div.header-workflow {
  justify-content: flex-end;
}
.stepper {
  width: fit-content;
  max-width: 100%;
  flex: 0 1 auto;
}
.step-divider {
  flex: 0 0 clamp(32px, 4vw, 72px);
  min-width: 32px;
}
@media (max-width: 760px) {
  .stepper {
    width: 100%;
  }
  .step-divider {
    flex-basis: 24px;
    min-width: 24px;
  }
}

/* ===== 表構成：サイドバーを使わない簡潔なツールバー ===== */
.click-layout-slot.layout-slot-active {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: 100%;
  height: 44px;
  max-height: 44px;
}
.layout-toolbar-editor {
  gap: 5px;
  padding: 4px 6px;
  border-color: var(--border);
  background: var(--surface);
}
.layout-toolbar-title {
  min-width: 48px;
}
.layout-toolbar-title strong {
  display: none;
}
.layout-toolbar-steps {
  gap: 4px;
  flex: 0 1 auto;
}
.layout-toolbar-step {
  min-width: 108px;
  height: 32px;
  gap: 4px;
  padding: 4px 6px;
}
.layout-toolbar-step-number {
  width: 20px;
  height: 20px;
  font-size: 0.64rem;
}
.layout-toolbar-step-label {
  font-size: 0.68rem;
}
.layout-toolbar-step .layout-control-state {
  display: none;
}
.layout-toolbar-options {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 1 auto;
  min-width: 0;
  padding-left: 5px;
  border-left: 1px solid var(--border);
}
.layout-toolbar-option {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  min-width: 78px;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.16s, background-color 0.16s, box-shadow 0.16s;
}
.layout-toolbar-option:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}
.layout-toolbar-option.is-active {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--primary-light);
  color: var(--text-main);
}
.layout-toolbar-option:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.layout-toolbar-option-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.layout-toolbar-option .layout-control-state {
  color: var(--text-light);
  font-size: 0.58rem;
  font-weight: 600;
}
.layout-toolbar-hint {
  display: none;
}
.layout-toolbar-actions {
  margin-left: auto;
  gap: 4px;
}
.layout-toolbar-actions .btn {
  height: 32px;
  padding: 4px 8px;
  font-size: 0.68rem;
}
@media (max-width: 1500px) {
  .layout-toolbar-title { min-width: 42px; }
  .layout-toolbar-step { min-width: 96px; }
  .layout-toolbar-option { min-width: 70px; padding-left: 6px; padding-right: 6px; }
  .layout-toolbar-actions .btn { padding-left: 7px; padding-right: 7px; }
}
@media (max-width: 1200px) {
  .layout-toolbar-step { min-width: 88px; }
  .layout-toolbar-option { min-width: 64px; }
  .layout-toolbar-actions #layoutReset { display: none; }
}
@media (max-width: 900px) {
  .layout-toolbar-title { min-width: 38px; }
  .layout-toolbar-step { min-width: 82px; }
  .layout-toolbar-option { min-width: 58px; }
  .layout-toolbar-option .layout-control-state { display: none; }
}
@media (max-width: 680px) {
  .layout-toolbar-editor { gap: 3px; padding-left: 4px; padding-right: 4px; }
  .layout-toolbar-title { display: none; }
  .layout-toolbar-step { min-width: 72px; padding-left: 5px; padding-right: 5px; }
  .layout-toolbar-step-number { display: none; }
  .layout-toolbar-option { min-width: 54px; padding-left: 5px; padding-right: 5px; }
  .layout-toolbar-actions .btn { padding-left: 5px; padding-right: 5px; }
}

/* ===== 表構成設定：上段ツールバーの選択方法直後に配置 ===== */
.click-layout-toolbar-slot {
  display: inline-flex;
  align-items: stretch;
  gap: 6px;
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
}
.click-layout-toolbar-slot.layout-slot-active {
  display: flex !important;
  align-items: stretch;
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  height: 44px;
  max-height: 44px;
}
.table-layout-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-width: max-content;
  white-space: nowrap;
}
.table-layout-button svg {
  display: block;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}
.table-layout-button.is-active {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.click-layout-toolbar-slot .layout-toolbar-editor {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  height: 44px;
  max-height: 44px;
  box-sizing: border-box;
  overflow: hidden;
}
.click-layout-toolbar-slot .layout-toolbar-editor #layoutReset {
  display: inline-flex !important;
}
/* 旧スロットが残る場合も下段ツールバーには表示しない */
#clickLayoutSlot { display: none !important; }

@media (max-width: 1200px) {
  .click-layout-toolbar-slot { gap: 4px; }
  .click-layout-toolbar-slot .layout-toolbar-editor { gap: 4px; padding-left: 5px; padding-right: 5px; }
  .click-layout-toolbar-slot .layout-toolbar-step { min-width: 88px; }
  .click-layout-toolbar-slot .layout-toolbar-option { min-width: 64px; }
  .click-layout-toolbar-slot .layout-toolbar-actions .btn { padding-left: 6px; padding-right: 6px; }
}
@media (max-width: 900px) {
  .click-layout-toolbar-slot { flex: 1 1 100%; width: 100%; }
  .click-layout-toolbar-slot.layout-slot-active { width: 100%; flex-basis: 100%; }
  .click-layout-toolbar-slot .layout-toolbar-editor { gap: 3px; padding-left: 4px; padding-right: 4px; }
  .click-layout-toolbar-slot .layout-toolbar-step { min-width: 76px; }
  .click-layout-toolbar-slot .layout-toolbar-option { min-width: 58px; }
}

/* ===== 表構成エディタ：キャンバス上部へ移動／操作ボタンは上段へ ===== */
/* 開いている間は設定ボタンを隠し、同じ位置に操作ボタンだけを置く */
.click-layout-toolbar-slot.layout-slot-active {
  display: inline-flex !important;
  flex: 0 0 auto !important;
  width: auto;
  height: 36px;
  max-height: 36px;
  min-width: 0;
}
.click-layout-toolbar-slot.layout-slot-active .table-layout-button {
  display: none !important;
}
.click-layout-toolbar-slot.layout-slot-active .layout-toolbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  margin-left: 0;
  height: 36px;
}
.click-layout-toolbar-slot.layout-slot-active .layout-toolbar-actions .btn {
  height: 32px;
  padding: 4px 8px;
  font-size: 0.68rem;
  white-space: nowrap;
}
/* エディタ本体は下段のキャンバス上部ツール選択グループに置く */
.layout-toolbar-editor {
  width: auto;
  max-width: 100%;
  min-width: 280px;
  flex: 1 1 420px;
}
.layout-toolbar-editor .layout-toolbar-actions {
  display: none;
}
@media (max-width: 900px) {
  .layout-toolbar-editor {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
}

/* ===== selectionActionGroupを表構成エディタのホストとして再利用 ===== */
#selectionActionGroup.layout-editor-host {
  display: flex !important;
  align-items: stretch;
  flex: 1 1 520px;
  min-width: 280px;
  max-width: 100%;
  gap: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}
#selectionActionGroup.layout-editor-host > .layout-toolbar-editor {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  gap: 10px;
}
#selectionActionGroup.layout-editor-host .layout-toolbar-steps {
  gap: 9px;
}
#selectionActionGroup.layout-editor-host .layout-toolbar-options {
  gap: 8px;
  padding-left: 8px;
}
#selectionActionGroup.layout-editor-host .layout-toolbar-actions {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
#selectionActionGroup.layout-editor-host .layout-toolbar-step {
  min-width: 128px;
  padding-left: 10px;
  padding-right: 10px;
}
#selectionActionGroup.layout-editor-host .layout-toolbar-option {
  min-width: 86px;
  padding-left: 9px;
  padding-right: 9px;
}
@media (max-width: 1200px) {
  #selectionActionGroup.layout-editor-host {
    flex-basis: 440px;
  }
  #selectionActionGroup.layout-editor-host > .layout-toolbar-editor {
    gap: 8px;
  }
  #selectionActionGroup.layout-editor-host .layout-toolbar-steps {
    gap: 7px;
  }
  #selectionActionGroup.layout-editor-host .layout-toolbar-step {
    min-width: 108px;
  }
  #selectionActionGroup.layout-editor-host .layout-toolbar-option {
    min-width: 72px;
  }
}
@media (max-width: 900px) {
  #selectionActionGroup.layout-editor-host {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
  #selectionActionGroup.layout-editor-host > .layout-toolbar-editor {
    gap: 6px;
  }
  #selectionActionGroup.layout-editor-host .layout-toolbar-steps,
  #selectionActionGroup.layout-editor-host .layout-toolbar-options,
  #selectionActionGroup.layout-editor-host .layout-toolbar-actions {
    gap: 5px;
  }
}

/* ===== 表構成アクションとオプションのUIUX ===== */
/* オプションは選択状態を文字で重ねず、ボタンの見た目で示す */
.layout-toolbar-option .layout-control-state,
.layout-option-button .layout-control-state {
  display: none !important;
}
#selectionActionGroup.layout-editor-host .layout-toolbar-option {
  justify-content: center;
  gap: 8px;
}
/* 操作エリアを右端にまとめ、適用を主操作として強調 */
#selectionActionGroup.layout-editor-host .layout-toolbar-actions {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}
#selectionActionGroup.layout-editor-host .layout-apply-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 88px;
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.24);
}
#selectionActionGroup.layout-editor-host .layout-apply-button svg {
  flex: 0 0 auto;
}
#selectionActionGroup.layout-editor-host .layout-apply-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(37, 99, 235, 0.3);
}
#selectionActionGroup.layout-editor-host .layout-reset-button {
  min-height: 36px;
  padding: 8px 12px;
  white-space: nowrap;
}
#selectionActionGroup.layout-editor-host .layout-close-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
}
#selectionActionGroup.layout-editor-host .layout-close-button svg {
  flex: 0 0 auto;
}
#selectionActionGroup.layout-editor-host .layout-apply-button:focus-visible,
#selectionActionGroup.layout-editor-host .layout-close-button:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.35);
  outline-offset: 2px;
}
@media (max-width: 900px) {
  #selectionActionGroup.layout-editor-host .layout-toolbar-actions {
    gap: 5px;
    padding-left: 8px;
    border-left: 0;
  }
  #selectionActionGroup.layout-editor-host .layout-apply-button {
    min-width: 78px;
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* ===== 控えめな操作カラー ===== */
#selectionActionGroup.layout-editor-host .layout-apply-button {
  background: #609879;
  border-color: #609879;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(67, 126, 93, 0.18);
}
#selectionActionGroup.layout-editor-host .layout-apply-button:hover {
  background: #568b6d;
  border-color: #568b6d;
  transform: none;
  box-shadow: 0 3px 8px rgba(67, 126, 93, 0.22);
}
#selectionActionGroup.layout-editor-host .layout-reset-button {
  background: #8d7caf;
  border-color: #8d7caf;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(111, 87, 157, 0.16);
}
#selectionActionGroup.layout-editor-host .layout-reset-button:hover {
  background: #806fa1;
  border-color: #806fa1;
  box-shadow: 0 3px 8px rgba(111, 87, 157, 0.2);
}
#selectionActionGroup.layout-editor-host .layout-close-button {
  background: transparent;
  border-color: transparent;
  color: #c76e6e;
  box-shadow: none;
}
#selectionActionGroup.layout-editor-host .layout-close-button:hover {
  background: rgba(199, 110, 110, 0.08);
  border-color: rgba(199, 110, 110, 0.18);
  color: #b85d5d;
  box-shadow: none;
}

/* ===== 見出し位置の利用可否とレイアウトボタンの表示 ===== */
#positionSettingItem.is-disabled {
  opacity: 0.58;
  filter: saturate(0.55);
}
#positionSettingItem.is-disabled .btn {
  cursor: not-allowed;
}
#selectionActionGroup.layout-editor-host > .layout-toolbar-editor {
  border: 0 !important;
  box-shadow: none !important;
}
.layout-toolbar-step[hidden],
.layout-toolbar-option[hidden],
.layout-step-button[hidden],
.layout-option-button[hidden] {
  display: none !important;
}

/* 連結モードの確定操作 */
#btnNextMergeImage.automatic-merge-confirm {
  background: #609879;
  border-color: #609879;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(67, 126, 93, 0.18);
}
#btnNextMergeImage.automatic-merge-confirm:hover:not(:disabled) {
  background: #568b6d;
  border-color: #568b6d;
  box-shadow: 0 3px 8px rgba(67, 126, 93, 0.22);
}
#btnNextMergeImage.automatic-merge-confirm:disabled {
  opacity: 0.5;
}

/* ===== Step 2 compact control row ===== */
.step2-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  margin-bottom: 16px;
  flex-shrink: 0;
  min-width: 0;
}
.step2-topbar .page-filter-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
}
.step2-topbar .page-filter-controls .step-title {
  white-space: nowrap;
  margin: 0;
}
.step2-topbar > .hint {
  flex: 1 1 auto;
  min-width: 120px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step2-topbar .step2-action-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 auto;
  gap: 12px;
  margin: 0;
  padding: 0;
  border: 0;
}
.step2-topbar .step2-action-bar .btn { white-space: nowrap; }

/* ===== Sidebar download button beside the heading ===== */
#step3 .side-panel-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}
#step3 .side-panel-header > .btn {
  width: auto;
  max-width: 100%;
  justify-self: end;
  white-space: nowrap;
}

/* ===== Confirmation popup ===== */
.confirm-dialog {
  width: min(440px, calc(100vw - 32px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
}
.confirm-dialog::backdrop { background: rgba(15, 23, 42, 0.68); }
.confirm-dialog-form {
  display: grid;
  gap: 16px;
  padding: 24px;
}
.confirm-dialog-form h2 {
  font-size: 1.05rem;
  line-height: 1.35;
}
.confirm-dialog-form p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}
.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}
.confirm-dialog-actions .btn { min-width: 96px; }

@media (max-width: 1000px) {
  .step2-topbar { flex-wrap: wrap; }
  .step2-topbar > .hint {
    order: 3;
    flex: 1 1 100%;
  }
}

/* ===== Notion-style compact UI (2026-09-16) ===== */
:root {
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.12);
  --radius-sm: 5px;
  --radius: 7px;
  --radius-lg: 10px;
}

html[data-theme="light"] {
  --bg: #f7f7f5 !important;
  --surface: #ffffff !important;
  --surface-alt: #f7f7f5 !important;
  --border: #e9e9e7 !important;
  --border-dark: #d5d5d2 !important;
  --text-main: #37352f !important;
  --text-muted: #787774 !important;
  --text-light: #9b9a97 !important;
  --primary: #2383e2 !important;
  --primary-hover: #1f6fbd !important;
  --primary-light: rgba(35, 131, 226, 0.10) !important;
}

html[data-theme="dark"] {
  --bg: #191919 !important;
  --surface: #202020 !important;
  --surface-alt: #292929 !important;
  --border: #373737 !important;
  --border-dark: #4a4a4a !important;
  --text-main: #f7f7f5 !important;
  --text-muted: #aaa8a3 !important;
  --text-light: #777570 !important;
  --primary: #529cca !important;
  --primary-hover: #6aaed7 !important;
  --primary-light: rgba(82, 156, 202, 0.15) !important;
}

html, body { font-size: 13px; line-height: 1.45; }
body { background: var(--bg); }

#app {
  padding: 12px 16px 14px !important;
  gap: 0 !important;
}

header {
  grid-template-columns: minmax(190px, auto) minmax(0, 1fr) !important;
  gap: 12px !important;
  margin-bottom: 10px !important;
  min-height: 34px;
}
header > div.header-brand {
  gap: 10px !important;
  max-width: none !important;
  overflow: hidden;
}
header > div.header-workflow {
  gap: 8px !important;
  min-width: 0;
  overflow: visible !important;
}
header h1 {
  font-size: 1.05rem !important;
  gap: 6px !important;
  letter-spacing: -0.01em;
}
header h1 .material-symbols-rounded { font-size: 22px !important; }
header > div.header-brand > .btn {
  padding: 5px 8px !important;
  font-size: 0.72rem !important;
}
header > div.header-brand > .btn .material-symbols-rounded { font-size: 15px !important; }
header > div.header-workflow > a,
header > div.header-workflow > button { flex: 0 0 auto; }

.stepper {
  gap: 8px !important;
  padding: 4px 8px !important;
  border-radius: 7px !important;
  box-shadow: none !important;
  background: transparent !important;
  border-color: var(--border) !important;
}
.step-item { gap: 5px !important; font-size: 0.76rem !important; }
.step-num { width: 22px !important; height: 22px !important; font-size: 0.68rem !important; }
.step-divider { flex-basis: 24px !important; min-width: 14px !important; height: 1px !important; }

.btn {
  padding: 6px 10px !important;
  border-radius: 6px !important;
  font-size: 0.78rem !important;
  font-weight: 600;
  box-shadow: none !important;
  transform: none !important;
}
.btn:hover:not(:disabled) { transform: none !important; box-shadow: none !important; }
.btn-sm { padding: 5px 8px !important; font-size: 0.74rem !important; }
.btn-icon { min-width: 30px !important; padding: 5px !important; }
.material-symbols-rounded { font-size: 18px; }
.btn-group { padding: 2px !important; border-radius: 7px !important; box-shadow: none !important; }
.btn-group .btn { padding: 5px 8px !important; border-radius: 5px !important; }
.btn-group.toggle-group { height: 30px !important; }
.btn-group.toggle-group .btn { padding: 0 8px !important; font-size: 0.74rem !important; }

.step-content {
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
.step-inner { padding: 0 !important; }
.step-title {
  font-size: 0.98rem !important;
  margin-bottom: 10px !important;
  gap: 6px !important;
}

/* Step 1 */
#step1 .step-inner { justify-content: center; }
#step1 .step-title { width: min(720px, 100%); margin: 0 auto 8px !important; }
.upload-area {
  width: min(720px, 100%) !important;
  margin: 0 auto !important;
  padding: 34px 24px !important;
  border-width: 1px !important;
  border-radius: 8px !important;
  background: var(--surface) !important;
}
.upload-icon .material-symbols-rounded { font-size: 44px !important; margin-bottom: 8px !important; }
.upload-area p { margin-bottom: 14px !important; font-size: 0.86rem !important; }
.upload-area .btn-lg { padding: 8px 14px !important; font-size: 0.82rem !important; }

/* Step 2 */
#step2 .step2-topbar {
  gap: 10px !important;
  margin-bottom: 8px !important;
  min-height: 32px;
}
#step2 .step2-topbar .page-filter-controls { gap: 8px !important; }
#step2 .step2-topbar .step-title { margin: 0 !important; }
#step2 .step2-topbar > .hint {
  margin: 0 !important;
  font-size: 0.72rem !important;
}
#step2 .step2-action-bar { gap: 8px !important; }
#step2 .badge-info { padding: 5px 8px !important; border-radius: 6px !important; font-size: 0.72rem !important; box-shadow: none !important; }
#step2 .step2-layout { gap: 10px !important; }
#step2 .page-thumbnails {
  gap: 8px !important;
  padding: 0 !important;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
#step2 .page-thumb {
  border-width: 1px !important;
  border-radius: 7px !important;
  box-shadow: none !important;
  aspect-ratio: 1.12;
}
#step2 .page-thumb-select { top: 6px; right: 6px; width: 27px; height: 27px; border-width: 1px; }
#step2 .page-thumb-select .material-symbols-rounded { font-size: 18px; }
#step2 .page-thumb-info { padding: 6px 8px !important; gap: 4px !important; }
#step2 .page-thumb-label { font-size: 0.68rem !important; }
#step2 .page-thumb-name { font-size: 0.72rem !important; }
#step2 .step2-floor-panel { width: 248px !important; }
#step2 .side-panel { padding: 10px !important; gap: 8px !important; border-radius: 8px !important; box-shadow: none !important; }
#step2 .side-panel-header { padding-bottom: 8px !important; }
#step2 .side-panel-header h3 { font-size: 0.86rem !important; }
#step2 .hint { margin-bottom: 8px !important; font-size: 0.72rem !important; }
#step2 .floor-add-row { gap: 6px !important; margin-bottom: 8px !important; }
#step2 .floor-name-input { padding: 6px 8px !important; font-size: 0.76rem !important; }
#step2 .floor-list { gap: 5px !important; }
#step2 .floor-item { padding: 7px 9px !important; font-size: 0.76rem !important; }

/* Step 3 */
#step3 { padding: 8px !important; }
#step3 .work-area { gap: 8px !important; }
#step3 .work-layout { gap: 10px !important; }
#step3 .work-layout > .step3-left-col { gap: 8px !important; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar {
  gap: 8px !important;
  padding-bottom: 8px !important;
  align-items: center !important;
  flex-wrap: wrap;
  row-gap: 6px;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-mode-method,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
  gap: 10px !important;
  align-items: center !important;
  min-width: 0;
  flex-wrap: wrap;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings { margin-left: auto; }
#step3 .setting-item { gap: 3px !important; }
#step3 .setting-item label { font-size: 0.66rem !important; padding-left: 1px !important; }
#step3 .switch-control-wrap { min-height: 28px !important; }
#step3 .switch-control { gap: 5px !important; font-size: 0.72rem !important; }
#step3 .switch-track { width: 34px !important; height: 20px !important; }
#step3 .switch-track::after { top: 2px !important; left: 2px !important; width: 16px !important; height: 16px !important; }
#step3 .switch-control input:checked + .switch-track::after { transform: translateX(14px); }
#step3 .main-canvas-wrapper { border-radius: 7px !important; box-shadow: none !important; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-canvas-toolbar { margin-bottom: 6px !important; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-canvas-toolbar > div.step3-tool-group { gap: 6px !important; }
#step3 #drawToolGroup { padding: 2px !important; }
#step3 #drawToolGroup .btn { padding: 5px 7px !important; font-size: 0.72rem !important; }
#step3 #drawToolGroup .material-symbols-rounded { font-size: 16px !important; }
#step3 .selection-overlay { cursor: crosshair; }
#step3 .work-layout > .step3-right-col { gap: 8px !important; }
#step3 .toolbar-container {
  padding: 8px 10px !important;
  gap: 8px !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}
#step3 .toolbar-container > div { min-width: 0; }
#step3 .side-panel {
  padding: 10px !important;
  gap: 8px !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}
#step3 .side-panel-header { padding-bottom: 8px !important; }
#step3 .side-panel-header h3 { font-size: 0.86rem !important; }
#step3 .floor-selector { padding: 5px 7px !important; font-size: 0.74rem !important; height: 30px; }
#step3 #btnEditFloorName,
#step3 #btnEditListName { width: 28px !important; height: 30px !important; }
#step3 #btnPrevWork,
#step3 #btnDuplicateWorkPage,
#step3 #btnNextWork { width: 30px !important; height: 30px !important; }
#step3 #currentPageBadge { padding: 4px 9px !important; border-radius: 6px !important; box-shadow: none !important; }
#step3 .extracted-list { gap: 7px !important; padding-right: 2px !important; }
#step3 .group-header { padding: 6px 8px !important; border-radius: 5px !important; box-shadow: none !important; font-size: 0.76rem !important; }
#step3 .group-content { gap: 6px !important; margin-top: 6px !important; }
#step3 .floor-subgroup-header { padding: 6px 8px !important; margin-top: 2px !important; font-size: 0.78rem !important; }
#step3 .extracted-item { border-radius: 5px !important; box-shadow: none !important; }
#step3 .extracted-item img { height: 76px !important; }
#step3 .extracted-item-name-input { padding: 4px 3px 4px 6px !important; font-size: 0.66rem !important; }
#step3 .extracted-item-ext { padding-right: 5px !important; font-size: 0.6rem !important; }
#step3 #btnClearImages { margin-top: 6px !important; }
#step3 .toast { bottom: 16px; padding: 8px 14px; font-size: 0.78rem; }

/* Keep the layout dense without changing the canvas coordinate system. */
.selection-rect { border-radius: 1px; }

@media (min-width: 1101px) {
  #step3 .work-layout { grid-template-columns: minmax(0, 1fr) 280px !important; }
}

@media (max-width: 1100px) {
  #app { padding: 10px !important; }
  header { grid-template-columns: minmax(0, 1fr) !important; row-gap: 8px !important; }
  header > div.header-workflow { justify-content: stretch !important; }
  .stepper { width: 100% !important; }
  #step3 .work-layout { grid-template-columns: minmax(0, 1fr) !important; gap: 8px !important; overflow: auto !important; }
  #step3 .work-layout > .step3-right-col { min-height: 240px; }
}

@media (max-width: 680px) {
  #app { padding: 8px !important; }
  header > div.header-brand { flex-wrap: wrap; }
  header h1 { font-size: 0.98rem !important; }
  header > div.header-workflow { flex-wrap: wrap; }
  .stepper { order: 3; }
  #step2 .step2-topbar { flex-wrap: wrap; }
  #step2 .step2-topbar > .hint { order: 3; flex: 1 1 100%; }
  #step2 .step2-floor-panel { width: 100% !important; max-height: 220px; }

  #step3 .work-layout,
  #step3 .work-layout > .step3-left-col,
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar {
    width: 100% !important;
    min-width: 0 !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px !important;
    align-items: stretch !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-mode-method,
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
    width: 100% !important;
    min-width: 0 !important;
    margin-left: 0 !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    justify-content: flex-start !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-mode-method > .setting-item {
    width: 100% !important;
    min-width: 0 !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-mode-method > .setting-item > div {
    width: 100% !important;
    min-width: 0 !important;
  }
  #step3 #selectMethodGroup {
    width: 100% !important;
    min-width: 0 !important;
    display: flex !important;
  }
  #step3 #selectMethodGroup .btn {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding-left: 5px !important;
    padding-right: 5px !important;
    white-space: nowrap;
  }
  #step3 #clickLayoutToolbarSlot:not(.layout-slot-active) {
    display: none !important;
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    flex: 0 0 0 !important;
  }
  #step3 #clickLayoutToolbarSlot.layout-slot-active {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > .setting-item {
    min-width: 0 !important;
    width: 100% !important;
  }
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings label {
    white-space: nowrap;
  }
  #step3 .toolbar-container {
    width: 100% !important;
    min-width: 0 !important;
  }
  #step3 .toolbar-container > div {
    width: 100% !important;
    min-width: 0 !important;
    flex-wrap: nowrap !important;
  }
  #step3 .toolbar-container .floor-selector,
  #step3 .toolbar-container .list-selector {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }
}

/* ===== Extraction setting controls: order and alignment (2026-09-17) ===== */
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
  column-gap: 32px !important;
  row-gap: 8px !important;
  align-items: flex-start !important;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem {
  order: 1;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem {
  order: 2;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions {
  order: 3;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions {
  display: grid !important;
  grid-template-rows: 16px 30px;
  row-gap: 4px !important;
  align-items: start !important;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem > label,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem > label,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions > label {
  display: flex !important;
  align-items: center !important;
  height: 16px !important;
  min-height: 16px !important;
  line-height: 16px !important;
  white-space: nowrap;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem > .btn-group,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem > .switch-control-wrap,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions > .switch-control-wrap {
  height: 30px !important;
  min-height: 30px !important;
  align-self: start !important;
  display: flex !important;
  align-items: center !important;
}
#step3 #autoMergeLabel,
#step3 #borderCheckboxText {
  display: none !important;
}
#step3 #autoMergeSwitch,
#step3 #borderCheckboxLabel {
  gap: 0 !important;
}
@media (max-width: 1100px) {
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
    column-gap: 24px !important;
  }
}
@media (max-width: 680px) {
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
    column-gap: 12px !important;
  }
}

/* ===== Extraction settings final alignment v21 (2026-09-18) ===== */
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
  margin-right: 28px !important;
  column-gap: 48px !important;
  row-gap: 14px !important;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem { order: 1; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractReadSettingItem { order: 3; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractTextPositionSettingItem { order: 2; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem { order: 4; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions { order: 5; }
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractReadSettingItem,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractTextPositionSettingItem,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions {
  display: grid !important;
  grid-template-rows: 16px 30px;
  row-gap: 8px !important;
  align-items: start !important;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem > label,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractReadSettingItem > label,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractTextPositionSettingItem > label,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem > label,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions > label {
  display: flex !important;
  align-items: center !important;
  height: 16px !important;
  min-height: 16px !important;
  line-height: 16px !important;
  white-space: nowrap;
}
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #positionSettingItem > .btn-group,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractReadSettingItem > .switch-control-wrap,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #singleExtractTextPositionSettingItem > .btn-group,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #borderSettingItem > .switch-control-wrap,
#step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings > #autoMergeOptions > .switch-control-wrap {
  height: 30px !important;
  min-height: 30px !important;
  align-self: start !important;
  display: flex !important;
  align-items: center !important;
}
#step3 #autoMergeLabel,
#step3 #borderCheckboxText,
#step3 #singleExtractReadText {
  display: none !important;
}
#step3 #autoMergeSwitch,
#step3 #borderCheckboxLabel,
#step3 #singleExtractReadLabel {
  gap: 0 !important;
}
#step3 #singleExtractReadSettingItem .switch-control {
  height: 20px !important;
  min-height: 20px !important;
  align-items: center !important;
}
#step3 #autoMergeOptions > .switch-control-wrap,
#step3 #borderSettingItem > .switch-control-wrap,
#step3 #singleExtractReadSettingItem > .switch-control-wrap {
  height: 30px !important;
  min-height: 30px !important;
  max-height: 30px !important;
  align-items: center !important;
}
#step3 #autoMergeOptions .switch-control,
#step3 #borderSettingItem .switch-control {
  height: 20px !important;
  min-height: 20px !important;
  align-items: center !important;
}
@media (max-width: 1100px) {
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
    margin-right: 16px !important;
    column-gap: 40px !important;
    row-gap: 12px !important;
  }
}
@media (max-width: 680px) {
  #step3 .work-layout > .step3-left-col > .step3-top-area > .step3-top-bars > .step3-control-bar > div.step3-extraction-settings {
    margin-right: 0 !important;
    column-gap: 20px !important;
    row-gap: 12px !important;
  }
}

/* ===== Extraction settings spacing and label alignment v23 (2026-09-18) ===== */
/* 実際のSTEP 3上段ツールバー構造に合わせて、各設定を同じ高さ・同じ上端へ揃える。 */
#step3 .step3-top-area .step3-control-bar > .step3-extraction-settings {
  gap: 24px !important;
  column-gap: 24px !important;
  row-gap: 24px !important;
  align-items: flex-start !important;
}
#step3 .step3-top-area .step3-control-bar > .step3-extraction-settings > .setting-item {
  height: 54px !important;
  min-height: 54px !important;
  gap: 8px !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
}
#step3 .step3-top-area .step3-control-bar > .step3-extraction-settings > .setting-item > label {
  display: flex !important;
  align-items: center !important;
  height: 16px !important;
  min-height: 16px !important;
  max-height: 16px !important;
  line-height: 16px !important;
  white-space: nowrap;
}
#step3 .step3-top-area .step3-control-bar > .step3-extraction-settings > .setting-item > .btn-group,
#step3 .step3-top-area .step3-control-bar > .step3-extraction-settings > .setting-item > .switch-control-wrap {
  height: 30px !important;
  min-height: 30px !important;
  max-height: 30px !important;
  align-self: flex-start !important;
  display: flex !important;
  align-items: center !important;
}
@media (max-width: 1100px) {
  #step3 .step3-top-area .step3-control-bar > .step3-extraction-settings {
    column-gap: 24px !important;
    row-gap: 24px !important;
  }
}
@media (max-width: 680px) {
  #step3 .step3-top-area .step3-control-bar > .step3-extraction-settings {
    column-gap: 24px !important;
    row-gap: 24px !important;
  }
}

/* ===== STEP 3 rail gap consistency v24 (2026-09-18) ===== */
/* 上段のドキュメント操作と下段キャンバスを、右レールから同じ距離に揃える。 */
:root { --step3-rail-gap: 12px; }
#step3 .work-layout {
  column-gap: var(--step3-rail-gap) !important;
}
@media (min-width: 1101px) {
  #step3 .step3-top-area,
  #step3 .step3-left-col {
    width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  #step3 .work-layout {
    column-gap: var(--step3-rail-gap) !important;
  }
}
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    padding-right: calc(var(--step3-side-width) + 20px) !important;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    right: calc(var(--step3-side-width) + 20px) !important;
  }
  #step3 .step3-right-col {
    right: 8px !important;
  }
}

/* ===== STEP 3 top area: merged bars + doc controls (2026-09-17) ===== */
.step3-top-area { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; flex-shrink: 0; min-width: 0; }
.step3-top-bars { display: flex; flex-direction: column; gap: 12px; flex: 1 1 auto; min-width: 0; }
.step3-top-area > .step3-doc-controls { flex: 0 0 300px; width: 300px; min-width: 0; }
@media (max-width: 1100px) {
  .step3-top-area { flex-wrap: wrap; }
  .step3-top-area > .step3-doc-controls { flex: 1 1 100%; width: auto; }
}

/* ===== STEP 3 right rail: header left + doc controls above panel (2026-09-17) ===== */
header > div.header-workflow { justify-content: flex-start !important; }
#step3 .work-layout { grid-template-columns: minmax(0, 1fr) 300px !important; grid-template-rows: auto minmax(0, 1fr) !important; }
#step3 .step3-top-area { grid-column: 1 / -1; grid-row: 1; align-items: stretch; }
#step3 .step3-left-col { grid-column: 1; grid-row: 2; }
#step3 .step3-right-col { grid-column: 2; grid-row: 2; }
#step3 .step3-top-area > .step3-doc-controls { flex: 0 0 300px; width: 300px; align-self: stretch; justify-content: space-between; }
@media (max-width: 1100px) {
  #step3 .work-layout { grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: auto auto auto !important; }
  #step3 .step3-top-area { grid-column: 1; grid-row: auto; }
  #step3 .step3-left-col, #step3 .step3-right-col { grid-column: 1; grid-row: auto; }
  #step3 .step3-top-area > .step3-doc-controls { flex: 1 1 100%; width: auto; }
}

/* ===== STEP 3 reference layout: top controls + full-height right rail (2026-09-17) ===== */
#step3 .work-layout {
  position: relative;
  grid-template-columns: minmax(0, 1fr) 320px !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  align-items: stretch;
}
#step3 .step3-top-area {
  grid-column: 1;
  grid-row: 1;
  padding-right: 0 !important;
}
#step3 .step3-top-bars {
  flex: 1 1 auto;
  min-width: 0;
}
#step3 .step3-top-area > .step3-doc-controls {
  flex: 0 0 300px;
  width: 300px;
  min-width: 0;
  min-height: 200px;
  height: 200px;
  margin-top: -68px;
  align-self: flex-start;
  justify-content: space-between;
  box-sizing: border-box;
}
#step3 .step3-left-col {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
}
#step3 .step3-right-col {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: start;
  margin-top: -68px !important;
  height: calc(100% + 68px) !important;
  width: auto !important;
  min-width: 0;
  min-height: 0;
}
#step3 .step3-right-col > .side-panel {
  width: 100% !important;
  max-width: 100% !important;
  height: 100%;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
}
@media (max-width: 1100px) {
  #step3 .work-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto !important;
  }
  #step3 .step3-top-area,
  #step3 .step3-left-col,
  #step3 .step3-right-col {
    grid-column: 1;
    grid-row: auto;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    flex: 1 1 100%;
    width: auto;
    min-height: 0;
    height: auto;
    margin-top: 0;
  }
  #step3 .step3-right-col {
    align-self: auto;
    margin-top: 0 !important;
    height: auto !important;
  }
}

/* ===== STEP 3 header overlap fix: keep every top control visible (2026-09-17) ===== */
#step3 .step3-top-area > .step3-doc-controls {
  min-height: 0 !important;
  height: auto !important;
  margin-top: 0 !important;
  align-self: stretch;
}
#step3 .step3-right-col {
  align-self: stretch;
  margin-top: 0 !important;
  height: auto !important;
}
#step3 .step3-right-col > .side-panel {
  height: auto !important;
  flex: 1 1 auto;
}

/* ===== Compact header: reclaim the top viewport strip (2026-09-17) ===== */
#app {
  padding-top: 4px !important;
}
header {
  min-height: 28px;
  margin-bottom: 6px !important;
  gap: 8px !important;
}
header > div.header-brand {
  gap: 8px !important;
}
header h1 {
  font-size: 0.92rem !important;
  line-height: 1.1 !important;
  gap: 5px !important;
}
header h1 .material-symbols-rounded {
  font-size: 20px !important;
}
header > div.header-brand > .btn {
  padding: 3px 7px !important;
  font-size: 0.68rem !important;
  line-height: 1.2 !important;
}
header > div.header-brand > .btn .material-symbols-rounded {
  font-size: 14px !important;
}
header > div.header-workflow {
  gap: 6px !important;
}
header > div.header-workflow > a {
  padding: 3px 7px !important;
  font-size: 0.68rem !important;
  line-height: 1.2 !important;
}
header > div.header-workflow > button {
  width: 28px !important;
  min-width: 28px !important;
  height: 28px !important;
  padding: 4px !important;
}
.stepper {
  padding: 2px 6px !important;
  gap: 6px !important;
  border-radius: 6px !important;
}
.step-item {
  gap: 4px !important;
  font-size: 0.70rem !important;
}
.step-num {
  width: 20px !important;
  height: 20px !important;
  font-size: 0.62rem !important;
}
.step-divider {
  flex-basis: 16px !important;
  min-width: 10px !important;
}

/* ===== STEP 3 reference composition: header left, doc rail, side rail (2026-09-17) ===== */
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    padding-right: 656px !important;
  }

  #step3 .work-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
  }

  #step3 .step3-top-area {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    min-width: 0;
  }

  #step3 .step3-top-area > .step3-doc-controls {
    position: fixed !important;
    top: 8px;
    right: 336px;
    width: 320px !important;
    min-width: 320px !important;
    height: 200px !important;
    min-height: 200px !important;
    margin: 0 !important;
    align-self: initial;
    z-index: 40;
  }

  #step3 .step3-right-col {
    position: fixed !important;
    top: 8px;
    right: 8px;
    bottom: 8px;
    width: 320px !important;
    min-width: 320px !important;
    height: auto !important;
    margin: 0 !important;
    align-self: initial;
    z-index: 39;
  }

  #step3 .step3-right-col > .side-panel {
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    min-height: 0;
    box-sizing: border-box;
  }
}

@media (max-width: 1500px) and (min-width: 1101px) {
  #app {
    padding-right: 16px !important;
  }
  #step3 .step3-top-area > .step3-doc-controls,
  #step3 .step3-right-col {
    position: static !important;
    right: auto;
    top: auto;
    bottom: auto;
    width: auto;
    min-width: 0;
    height: auto !important;
  }
  #step3 .step3-right-col {
    width: 280px !important;
    min-width: 280px;
  }
}

/* ===== STEP 3 canvas spans under the doc rail to the side panel (2026-09-17) ===== */
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    /* reserve only the far-right side panel; the PDF uses the doc-rail column too */
    padding-right: 336px !important;
  }

  #step3 .step3-top-area > .step3-top-bars {
    flex: 0 0 calc(100% - 328px) !important;
    width: calc(100% - 328px) !important;
    max-width: calc(100% - 328px) !important;
  }

  #step3 .step3-left-col,
  #step3 .step3-left-col > .step3-canvas-section,
  #step3 .main-canvas-wrapper {
    width: 100% !important;
    max-width: none !important;
  }
}

/* ===== STEP 3 keep the PDF below the doc toolbar (2026-09-17) ===== */
@media (min-width: 1501px) {
  #step3 .step3-left-col {
    margin-top: 32px !important;
  }
}

/* ===== UI stability & visual refinement v6 (2026-09-17) ===== */
:root {
  --step3-side-width: 320px;
  --step3-doc-width: 312px;
  --step3-rail-gap: 12px;
  --ui-control-height: 34px;
}

/* Common interaction and surface polish */
button,
select,
input {
  font: inherit;
}
.btn,
.floor-selector,
.floor-name-input,
.extracted-item-name-input {
  transition: border-color .14s ease, background-color .14s ease, color .14s ease, opacity .14s ease !important;
}
.btn:focus-visible,
.floor-selector:focus-visible,
.floor-name-input:focus-visible,
.extracted-item-name-input:focus-visible,
input[type="range"]:focus-visible {
  outline: 2px solid var(--primary) !important;
  outline-offset: 2px;
}
.toolbar-container,
.side-panel,
.main-canvas-wrapper {
  border-color: var(--border) !important;
}

/* Step 3 rhythm */
#step3 {
  padding: 10px 12px 12px !important;
}
#step3 .work-area,
#step3 .work-layout {
  gap: 10px !important;
}
#step3 .step3-top-area {
  gap: 12px !important;
  align-items: stretch !important;
}
#step3 .step3-top-bars {
  gap: 8px !important;
}
#step3 .step3-control-bar {
  min-width: 0;
  gap: 16px;
  padding: 9px 10px 10px !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px;
  background: var(--surface);
  box-sizing: border-box;
}
#step3 .step3-mode-method {
  min-width: 0;
  gap: 16px !important;
  align-items: flex-end;
}
#step3 .step3-extraction-settings {
  min-width: 0;
  gap: 12px !important;
  row-gap: 8px !important;
}
#step3 .setting-item {
  min-width: 0;
  gap: 5px;
}
#step3 .setting-item > label {
  padding-left: 1px;
  font-size: .70rem;
  letter-spacing: .02em;
}
#step3 .btn-group.toggle-group {
  height: 32px !important;
}
#step3 .btn-group.toggle-group .btn {
  min-height: 28px;
}
#step3 .step3-canvas-toolbar {
  min-height: 36px;
  margin: 0 0 6px !important;
  padding: 2px 2px 0;
  box-sizing: border-box;
}
#step3 .step3-tool-group,
#step3 .step3-canvas-actions {
  min-width: 0;
}
#step3 .main-canvas-wrapper {
  border-radius: 10px !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04) !important;
}
#step3 .step3-canvas-hint {
  margin-top: 6px !important;
  font-size: .68rem !important;
  opacity: .78;
}

/* Document controls: consistent compact card */
#step3 .toolbar-container.step3-doc-controls {
  gap: 8px !important;
  padding: 10px !important;
  border-radius: 10px !important;
  background: var(--surface-alt) !important;
  box-shadow: 0 1px 2px rgba(0,0,0,.05) !important;
  overflow: hidden;
  box-sizing: border-box;
}
#step3 .step3-doc-row {
  min-width: 0;
  min-height: var(--ui-control-height);
  gap: 7px !important;
}
#step3 .step3-doc-row > .material-symbols-rounded {
  width: 20px;
  text-align: center;
}
#step3 .step3-doc-controls .floor-selector {
  width: 0;
  min-width: 0 !important;
  height: var(--ui-control-height);
  flex: 1 1 0;
  padding: 5px 28px 5px 9px !important;
  border-radius: 7px !important;
  background-color: var(--surface) !important;
  font-size: .76rem !important;
  font-weight: 600;
}
#step3 .step3-doc-row > .btn-icon {
  width: var(--ui-control-height) !important;
  min-width: var(--ui-control-height) !important;
  height: var(--ui-control-height) !important;
  flex: 0 0 var(--ui-control-height) !important;
  border-radius: 7px !important;
}
#step3 .step3-page-nav {
  min-width: 0;
  gap: 8px !important;
  padding-top: 8px;
  margin-top: 1px;
  border-top: 1px solid var(--border);
}
#step3 .step3-page-nav > .btn-icon {
  width: 34px !important;
  min-width: 34px !important;
  height: 34px !important;
  border-radius: 7px !important;
}
#step3 #currentPageBadge {
  min-width: 68px;
  min-height: 34px;
  justify-content: center;
  padding: 4px 10px !important;
  border-radius: 7px !important;
  box-sizing: border-box;
}

/* The extraction rail owns a fixed inline size. Dynamic content cannot resize it. */
#step3 .step3-right-col {
  width: var(--step3-side-width) !important;
  min-width: var(--step3-side-width) !important;
  max-width: var(--step3-side-width) !important;
  flex: 0 0 var(--step3-side-width) !important;
  contain: inline-size;
  box-sizing: border-box;
  overflow: hidden;
}
#step3 .step3-right-col > .side-panel {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: 100% !important;
  min-height: 0;
  padding: 12px !important;
  gap: 8px !important;
  overflow: hidden;
  border-radius: 10px !important;
  box-sizing: border-box;
}
#step3 .side-panel-header {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 108px !important;
  align-items: center;
  gap: 8px !important;
  min-width: 0;
  padding-bottom: 10px !important;
}
#step3 .side-panel-header h3 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: .82rem !important;
}
#step3 .side-panel-header h3 > .material-symbols-rounded {
  flex: 0 0 auto;
}
#step3 .side-panel-header > #btnDownloadAll {
  width: 108px !important;
  min-width: 108px !important;
  max-width: 108px !important;
  min-height: 34px;
  justify-content: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
#step3 .extracted-list {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 0 3px 0 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  scrollbar-gutter: stable;
  box-sizing: border-box;
  align-content: start;
}
#step3 .extracted-list:empty::before {
  content: "画像を抽出すると\Aここに表示されます";
  display: grid;
  place-items: center;
  min-height: 132px;
  padding: 24px 12px;
  border: 1px dashed var(--border-dark);
  border-radius: 8px;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  font-size: .72rem;
  line-height: 1.65;
  text-align: center;
  white-space: pre-line;
  box-sizing: border-box;
}
#step3 .extracted-list > div,
#step3 .extracted-list .group-content,
#step3 .extracted-list .extracted-item,
#step3 .extracted-list .extracted-item > div {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
#step3 .floor-subgroup-header,
#step3 .group-header {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
#step3 .floor-subgroup-header > span:first-child,
#step3 .group-header > span:first-child {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#step3 .extracted-list .group-content {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 8px !important;
}
#step3 .extracted-item {
  overflow: hidden;
  border-radius: 7px !important;
}
#step3 .extracted-item:hover {
  transform: none !important;
  border-color: var(--border-dark) !important;
  background: var(--surface);
}
#step3 .extracted-item img {
  width: 100% !important;
  height: 86px !important;
  object-fit: contain;
}
#step3 .extracted-item > div {
  overflow: hidden;
}
#step3 .extracted-item-name-input {
  width: 0;
  min-width: 0 !important;
  flex: 1 1 0;
  padding: 5px 2px 5px 6px !important;
  text-overflow: ellipsis;
}
#step3 .extracted-item-ext {
  flex: 0 0 auto;
  padding-right: 5px !important;
}
#step3 #btnClearImages {
  min-height: 34px;
  margin-top: 2px !important;
}

/* Stable wide-screen composition: canvas + document card + extraction rail */
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    padding-right: calc(var(--step3-side-width) + 20px) !important;
  }
  #step3 .work-layout {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
  }
  #step3 .step3-top-area {
    grid-column: 1;
    grid-row: 1;
  }
  #step3 .step3-top-area > .step3-top-bars {
    width: calc(100% - var(--step3-doc-width) - var(--step3-rail-gap)) !important;
    max-width: calc(100% - var(--step3-doc-width) - var(--step3-rail-gap)) !important;
    flex: 0 0 calc(100% - var(--step3-doc-width) - var(--step3-rail-gap)) !important;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    position: fixed !important;
    top: 8px;
    right: calc(var(--step3-side-width) + 16px);
    width: var(--step3-doc-width) !important;
    min-width: var(--step3-doc-width) !important;
    max-width: var(--step3-doc-width) !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    z-index: 40;
  }
  #step3 .step3-left-col {
    grid-column: 1;
    grid-row: 2;
    width: 100% !important;
    margin-top: 24px !important;
  }
  #step3 .step3-right-col {
    position: fixed !important;
    inset: 8px 8px 8px auto;
    height: auto !important;
    margin: 0 !important;
    z-index: 39;
  }
}

/* Mid-size desktop: keep a fixed rail and turn document controls into one row. */
@media (max-width: 1500px) and (min-width: 1101px) {
  :root {
    --step3-side-width: 300px;
  }
  #app {
    padding-right: 16px !important;
  }
  #step3 .work-layout {
    grid-template-columns: minmax(0, 1fr) var(--step3-side-width) !important;
    grid-template-rows: auto minmax(0, 1fr) !important;
    align-items: stretch;
  }
  #step3 .step3-top-area {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px !important;
  }
  #step3 .step3-top-area > .step3-top-bars {
    width: 100% !important;
    max-width: 100% !important;
    flex: none !important;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    position: static !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
  }
  #step3 .step3-doc-controls .step3-page-nav {
    width: auto !important;
    padding: 0 0 0 8px;
    margin: 0;
    border-top: 0;
    border-left: 1px solid var(--border);
  }
  #step3 .step3-left-col {
    grid-column: 1;
    grid-row: 2;
    width: 100% !important;
    margin: 0 !important;
  }
  #step3 .step3-right-col {
    position: static !important;
    grid-column: 2;
    grid-row: 1 / 3;
    height: 100% !important;
    margin: 0 !important;
  }
}

/* Tablet and mobile: stack without horizontal page overflow. */
@media (max-width: 1100px) {
  :root {
    --step3-side-width: 100%;
  }
  #step3 {
    overflow-y: auto !important;
  }
  #step3 .work-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto auto !important;
    overflow: visible !important;
  }
  #step3 .step3-top-area,
  #step3 .step3-left-col,
  #step3 .step3-right-col {
    position: static !important;
    grid-column: 1 !important;
    grid-row: auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto !important;
    margin: 0 !important;
  }
  #step3 .step3-top-area {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr);
  }
  #step3 .step3-top-area > .step3-top-bars,
  #step3 .step3-top-area > .step3-doc-controls {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  #step3 .step3-doc-controls {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  }
  #step3 .step3-doc-controls .step3-page-nav {
    width: auto !important;
    padding: 0 0 0 8px;
    margin: 0;
    border-top: 0;
    border-left: 1px solid var(--border);
  }
  #step3 .step3-right-col {
    min-height: 280px !important;
    contain: none;
  }
  #step3 .step3-right-col > .side-panel {
    min-height: 280px;
    max-height: 420px;
  }
}

@media (max-width: 720px) {
  #app {
    padding: 8px !important;
  }
  header {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #step3 {
    padding: 6px !important;
  }
  #step3 .step3-control-bar {
    flex-direction: column;
    align-items: stretch !important;
  }
  #step3 .step3-mode-method,
  #step3 .step3-extraction-settings {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    justify-content: flex-start !important;
    scrollbar-width: none;
  }
  #step3 .step3-mode-method::-webkit-scrollbar,
  #step3 .step3-extraction-settings::-webkit-scrollbar {
    display: none;
  }
  #step3 .toolbar-container.step3-doc-controls {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  #step3 .step3-doc-controls .step3-page-nav {
    width: 100% !important;
    padding: 8px 0 0;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
  #step3 .step3-canvas-toolbar {
    align-items: flex-start !important;
    gap: 6px;
  }
  #step3 .step3-canvas-actions {
    margin-left: auto;
  }
  #step3 .extracted-list .group-content {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .floor-selector,
  .floor-name-input,
  .extracted-item-name-input {
    transition: none !important;
  }
}


/* Mobile flow correction: let stacked Step 3 content define its own height. */
@media (max-width: 720px) {
  header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    align-items: center;
  }
  header > .header-brand {
    width: 100%;
    min-width: 0;
    flex-wrap: nowrap !important;
  }
  header > .header-workflow {
    display: grid !important;
    grid-template-columns: 28px 28px minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    gap: 6px !important;
    flex-wrap: nowrap !important;
  }
  header > .header-workflow > a,
  header > .header-workflow > button {
    width: 28px !important;
    min-width: 28px !important;
    height: 28px !important;
    padding: 0 !important;
    justify-content: center;
  }
  header > .header-workflow > a {
    overflow: hidden;
    font-size: 0 !important;
  }
  header > .header-workflow > a .material-symbols-rounded {
    margin: 0;
    font-size: 16px !important;
  }
  header .stepper {
    order: initial !important;
    width: 100% !important;
    min-width: 0;
  }
  header .step-item {
    min-width: 0;
  }
  header .step-item > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #step3 .work-area {
    height: auto !important;
    min-height: 0 !important;
    flex: 0 0 auto !important;
    overflow: visible !important;
  }
  #step3 .work-layout {
    height: auto !important;
    min-height: 0 !important;
    flex: 0 0 auto !important;
    grid-template-rows: auto auto auto !important;
    align-content: start;
  }
  #step3 .step3-top-area,
  #step3 .step3-top-bars,
  #step3 .step3-doc-controls {
    height: auto !important;
    min-height: 0 !important;
    align-self: start !important;
  }
  #step3 .step3-doc-controls {
    overflow: hidden !important;
  }
  #step3 .step3-control-bar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
  }
  #step3 .step3-mode-method {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    width: 100%;
    overflow: visible !important;
    gap: 8px !important;
  }
  #step3 .step3-mode-method > .setting-item,
  #step3 .step3-mode-method > .setting-item > div {
    width: 100%;
    min-width: 0;
  }
  #step3 #selectionModeGroup {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }
  #step3 #selectionModeGroup .btn,
  #step3 #selectMethodGroup .btn {
    min-width: 0 !important;
    padding-left: 5px !important;
    padding-right: 5px !important;
    white-space: nowrap;
    font-size: .68rem !important;
  }
  #step3 #selectionModeGroup .material-symbols-rounded {
    display: none !important;
  }
  #step3 .step3-extraction-settings {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    overflow: visible !important;
    gap: 8px !important;
    align-items: end !important;
  }
  #step3 .step3-extraction-settings > .setting-item {
    width: 100%;
    min-width: 0;
  }
  #step3 .step3-canvas-toolbar {
    min-height: 42px;
    height: auto !important;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap !important;
    scrollbar-width: thin;
  }
  #step3 .step3-tool-group {
    width: max-content;
    min-width: max-content;
    flex-wrap: nowrap !important;
  }
  #step3 .step3-tool-group .btn,
  #step3 .step3-canvas-actions .btn {
    white-space: nowrap;
  }
  #step3 .step3-canvas-actions {
    flex: 0 0 auto;
  }
  #step3 .step3-left-col {
    min-height: 340px !important;
    height: min(56vh, 520px) !important;
  }
  #step3 .step3-canvas-section,
  #step3 .main-canvas-wrapper {
    min-height: 0;
  }
}

@media (max-width: 720px) {
  header > .header-workflow {
    grid-template-columns: 28px minmax(0, 1fr);
  }
  header > .header-workflow > a {
    display: none !important;
  }
  header > .header-workflow > .stepper {
    grid-column: 2;
    width: 100% !important;
    max-width: 100% !important;
  }
}


/* ===== Ideal wide-screen spacing & toolbar proportions v7 (2026-09-17) =====
   Matches the requested reference: 16px outer inset, a 172px document card,
   and additional breathing room before the drawing canvas. */
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    padding-top: 16px !important;
  }

  #step3 .step3-right-col {
    top: 16px !important;
    right: 16px !important;
    height: calc(100vh - 24px) !important;
    height: calc(100dvh - 24px) !important;
  }

  #step3 .step3-top-area > .step3-doc-controls {
    top: 16px !important;
    right: 348px !important;
    width: 312px !important;
    min-width: 312px !important;
    max-width: 312px !important;
    height: 172px !important;
    min-height: 172px !important;
    max-height: 172px !important;
    padding: 12px !important;
    gap: 10px !important;
    grid-template-rows: 36px 36px 44px !important;
    align-content: start !important;
  }

  #step3 .step3-doc-controls .step3-doc-row {
    height: 36px !important;
    min-height: 36px !important;
  }

  #step3 .step3-doc-controls .floor-selector,
  #step3 .step3-doc-controls input.floor-selector,
  #step3 .step3-doc-controls .step3-doc-row > .btn {
    height: 36px !important;
    min-height: 36px !important;
  }

  #step3 .step3-doc-controls .step3-page-nav {
    height: 44px !important;
    min-height: 44px !important;
    padding-top: 4px !important;
  }

  #step3 .step3-left-col {
    padding-top: 16px !important;
    box-sizing: border-box;
  }
}


/* Match the reference document toolbar exactly: 200px card with three evenly spaced rows. */
@media (min-width: 1501px) {
  #step3 .step3-top-area > .step3-doc-controls {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    height: 200px !important;
    min-height: 200px !important;
    max-height: 200px !important;
    gap: 16px !important;
  }
}

/* ===== Canvas directly below its toolbar v8 (2026-09-17) ===== */
@media (min-width: 1501px) {
  #step3 .work-layout {
    row-gap: 0 !important;
  }

  #step3 .step3-top-area {
    margin-bottom: 0 !important;
  }

  #step3 .step3-canvas-toolbar {
    margin-bottom: 0 !important;
  }

  #step3 .step3-left-col {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }

  #step3 .step3-top-area > .step3-doc-controls {
    display: grid !important;
    grid-template-rows: 36px 36px 44px !important;
    align-content: start !important;
    justify-content: stretch !important;
    height: 172px !important;
    min-height: 172px !important;
    max-height: 172px !important;
    gap: 10px !important;
  }
}

@media (min-width: 1501px) {
  #step3 .step3-top-area > .step3-doc-controls {
    height: 169px !important;
    min-height: 169px !important;
    max-height: 169px !important;
  }
}

/* ===== Stable Step 3 height across every desktop mode v9 (2026-09-17) ===== */
:root {
  --step3-control-row-height: 72px;
  --step3-tool-row-height: 44px;
  --step3-top-row-gap: 8px;
  --step3-top-stack-height: 124px;
}
@media (min-width: 1101px) {
  #step3 .step3-top-bars {
    display: grid !important;
    grid-template-rows: var(--step3-control-row-height) var(--step3-tool-row-height) !important;
    gap: var(--step3-top-row-gap) !important;
    height: var(--step3-top-stack-height) !important;
    min-height: var(--step3-top-stack-height) !important;
    max-height: var(--step3-top-stack-height) !important;
    align-content: start !important;
  }
  #step3 .step3-control-bar {
    height: var(--step3-control-row-height) !important;
    min-height: var(--step3-control-row-height) !important;
    max-height: var(--step3-control-row-height) !important;
    flex-wrap: nowrap !important;
    align-items: flex-end !important;
    overflow: visible;
  }
  #step3 .step3-mode-method,
  #step3 .step3-extraction-settings {
    flex-wrap: nowrap !important;
    align-items: flex-end !important;
  }
  #step3 .step3-canvas-toolbar {
    height: var(--step3-tool-row-height) !important;
    min-height: var(--step3-tool-row-height) !important;
    max-height: var(--step3-tool-row-height) !important;
    margin: 0 !important;
    padding: 3px 2px !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  #step3 .step3-canvas-toolbar::-webkit-scrollbar { display: none; }
  #step3 .step3-tool-group,
  #step3 .step3-canvas-actions {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
  }
  #step3 #selectionActionGroup,
  #step3 #selectionActionGroup.layout-editor-host {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    align-items: center !important;
  }
  #step3 #selectionActionGroup.layout-editor-host > .layout-toolbar-editor {
    height: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    padding: 0 4px !important;
    align-items: center !important;
    overflow: hidden;
    box-sizing: border-box;
  }
  #step3 #selectionActionGroup.layout-editor-host .layout-apply-button,
  #step3 #selectionActionGroup.layout-editor-host .layout-reset-button,
  #step3 #selectionActionGroup.layout-editor-host .layout-close-button {
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
  }
  #step3 #lineStyleGroup {
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    box-sizing: border-box;
  }
}
@media (min-width: 1501px) {
  #step3 .work-layout { row-gap: 0 !important; }
  #step3 .step3-top-area {
    height: var(--step3-top-stack-height) !important;
    min-height: var(--step3-top-stack-height) !important;
    max-height: var(--step3-top-stack-height) !important;
    margin-bottom: 0 !important;
  }
  #step3 .step3-left-col { padding-top: 0 !important; margin-top: 0 !important; }
  #step3 .step3-top-area > .step3-doc-controls {
    display: grid !important;
    grid-template-rows: 36px 36px 44px !important;
    align-content: start !important;
    justify-content: stretch !important;
    height: 176px !important;
    min-height: 176px !important;
    max-height: 176px !important;
    gap: 10px !important;
  }
}


/* Consistent breathing room above the canvas v10 */
:root { --step3-canvas-gap: 8px; }
@media (min-width: 1501px) {
  #step3 .work-layout { row-gap: var(--step3-canvas-gap) !important; }
}

/* ===== Balanced application header v11 (2026-09-17) ===== */
header.app-header {
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr) !important;
  align-items: center !important;
  column-gap: 24px !important;
  width: 100%;
  height: 44px !important;
  min-height: 44px !important;
  max-height: 44px !important;
  margin: 0 0 12px !important;
  overflow: visible !important;
}
header.app-header > .header-brand,
header.app-header > .header-workflow {
  display: flex !important;
  align-items: center !important;
  min-width: 0;
  max-width: none !important;
  overflow: visible !important;
  flex-wrap: nowrap !important;
}
header.app-header > .header-brand {
  gap: 8px !important;
  justify-content: flex-start;
}
header.app-header > .header-workflow {
  gap: 12px !important;
  justify-content: flex-end !important;
  justify-self: stretch;
}
header.app-header h1 {
  flex: 0 0 auto;
  max-width: none !important;
  margin: 0 4px 0 0;
  font-size: 19px !important;
  line-height: 1.15 !important;
  letter-spacing: -0.02em;
  gap: 7px !important;
  overflow: visible;
}
header.app-header h1 .material-symbols-rounded {
  flex: 0 0 auto;
  font-size: 26px !important;
}
header.app-header .header-help,
header.app-header .header-theme,
header.app-header .btn-reset-all {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px !important;
  min-height: 36px !important;
  max-height: 36px !important;
  border-radius: 7px !important;
  line-height: 1 !important;
  white-space: nowrap;
  flex: 0 0 auto !important;
}
header.app-header .header-help {
  width: auto !important;
  min-width: 78px !important;
  padding: 0 11px !important;
  font-size: 13px !important;
  text-decoration: none;
}
header.app-header .header-theme {
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  padding: 0 !important;
}
header.app-header .header-help .material-symbols-rounded,
header.app-header .header-theme .material-symbols-rounded,
header.app-header .btn-reset-all .material-symbols-rounded {
  font-size: 18px !important;
  flex: 0 0 auto;
}
header.app-header .btn-reset-all {
  width: auto !important;
  min-width: 148px !important;
  padding: 0 12px !important;
  font-size: 13px !important;
}
header.app-header .stepper {
  display: flex !important;
  align-items: center;
  width: clamp(360px, 28vw, 520px) !important;
  min-width: 360px !important;
  max-width: 520px !important;
  height: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  padding: 4px 10px !important;
  gap: 8px !important;
  border-radius: 8px !important;
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  box-shadow: none !important;
  overflow: hidden;
  flex: 0 0 auto !important;
}
header.app-header .step-item {
  gap: 6px !important;
  font-size: 13px !important;
  line-height: 1 !important;
  flex: 0 0 auto;
}
header.app-header .step-num {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px;
  font-size: 12px !important;
}
header.app-header .step-divider {
  flex: 1 1 22px !important;
  min-width: 16px !important;
  height: 1px !important;
}
@media (min-width: 1501px) {
  #app:has(> #step2:not(.hidden)),
  #app:has(> #step3:not(.hidden)) {
    padding-top: 16px !important;
  }
  #app:has(> #step2:not(.hidden)) > header.app-header,
  #app:has(> #step3:not(.hidden)) > header.app-header {
    width: calc(100% - 660px) !important;
    max-width: calc(100% - 660px) !important;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    height: 188px !important;
    min-height: 188px !important;
    max-height: 188px !important;
  }
}
@media (min-width: 1501px) and (max-width: 1800px) {
  header.app-header { column-gap: 12px !important; }
  header.app-header h1 { font-size: 17px !important; margin-right: 0; }
  header.app-header h1 .material-symbols-rounded { font-size: 23px !important; }
  header.app-header .header-help {
    width: 36px !important;
    min-width: 36px !important;
    padding: 0 !important;
    font-size: 0 !important;
  }
  header.app-header .header-help .material-symbols-rounded { font-size: 18px !important; }
  header.app-header .stepper {
    width: 360px !important;
    min-width: 360px !important;
  }
  header.app-header .btn-reset-all { min-width: 138px !important; padding: 0 9px !important; font-size: 12px !important; }
}
@media (max-width: 1100px) {
  header.app-header {
    grid-template-columns: minmax(0, 1fr) !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    row-gap: 8px !important;
    margin-bottom: 10px !important;
  }
  header.app-header > .header-brand,
  header.app-header > .header-workflow { width: 100%; }
  header.app-header > .header-workflow {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px !important;
  }
  header.app-header .stepper {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }
}
@media (max-width: 520px) {
  header.app-header h1 { font-size: 16px !important; gap: 5px !important; }
  header.app-header h1 .material-symbols-rounded { font-size: 22px !important; }
  header.app-header .header-help,
  header.app-header .header-theme,
  header.app-header .btn-reset-all {
    width: 34px !important;
    min-width: 34px !important;
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 !important;
    font-size: 0 !important;
  }
  header.app-header .header-button-label { display: none; }
  header.app-header .stepper { height: 36px !important; min-height: 36px !important; padding: 4px 7px !important; gap: 5px !important; }
  header.app-header .step-item { font-size: 11px !important; gap: 4px !important; }
  header.app-header .step-num { width: 22px !important; height: 22px !important; min-width: 22px; font-size: 11px !important; }
  header.app-header .step-divider { min-width: 6px !important; }
}
@media (max-width: 400px) {
  header.app-header .step-item > span { display: none; }
}

/* v11 final alignment and sizing pass */
header.app-header,
header.app-header .header-help,
header.app-header .header-theme,
header.app-header .btn-reset-all,
header.app-header .stepper {
  box-sizing: border-box !important;
}
@media (min-width: 1501px) {
  #app:has(> #step2:not(.hidden)) > header.app-header,
  #app:has(> #step3:not(.hidden)) > header.app-header {
    width: calc(100vw - 692px) !important;
    max-width: calc(100vw - 692px) !important;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    height: 190px !important;
    min-height: 190px !important;
    max-height: 190px !important;
  }
}


/* ===== Compact header-to-controls spacing v12 (2026-09-17) ===== */
@media (min-width: 1501px) {
  header.app-header { margin-bottom: 4px !important; }
  #step3 { padding-top: 4px !important; }
  #step3 .step3-top-area > .step3-doc-controls {
    height: 176px !important;
    min-height: 176px !important;
    max-height: 176px !important;
  }
}

/* ===== Step 2 breathing room + thumbnail sizing v13 (2026-09-17) ===== */
:root { --step2-thumb-size: 160px; }
#step2 .step-inner {
  padding: 4px 6px 8px !important;
  overflow: hidden !important;
}
#step2 .step2-topbar {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto !important;
  align-items: center !important;
  column-gap: 24px !important;
  row-gap: 10px !important;
  min-height: 0 !important;
  margin: 0 0 14px !important;
  padding: 12px 14px !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  background: var(--surface) !important;
  box-shadow: none !important;
}
#step2 .step2-topbar-primary {
  display: grid;
  align-content: center;
  gap: 6px;
  min-width: 0;
}
#step2 .page-filter-controls {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  flex-wrap: wrap;
  gap: 12px !important;
  min-width: 0;
  margin: 0 !important;
}
#step2 .page-filter-controls .step-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 !important;
  font-size: 15px !important;
  line-height: 1.25;
  white-space: nowrap;
}
#step2 .page-filter-controls .step-title .material-symbols-rounded { font-size: 19px !important; }
#step2 .page-selection-actions { display: inline-flex; align-items: center; gap: 8px; }
#step2 .page-selection-actions .btn { min-height: 34px; padding-inline: 11px !important; }
#step2 .step2-guidance {
  margin: 0 !important;
  font-size: 12px !important;
  line-height: 1.4;
  white-space: normal !important;
  overflow: visible !important;
}
#step2 .step2-guidance .material-symbols-rounded { font-size: 16px !important; }
#step2 .step2-topbar-secondary {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  min-width: 0;
}
#step2 .thumbnail-size-control {
  display: grid;
  grid-template-columns: auto 16px minmax(110px, 150px) 18px 48px;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  box-sizing: border-box;
}
#step2 .thumbnail-size-control label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-main);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
#step2 .thumbnail-size-control label .material-symbols-rounded { font-size: 17px !important; color: var(--primary); }
#step2 .thumb-size-mark { font-size: 14px !important; color: var(--text-muted); }
#step2 .thumb-size-mark-large { font-size: 17px !important; }
#step2 #thumbnailSizeRange {
  width: 100%;
  height: 28px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  accent-color: var(--primary);
}
#step2 #thumbnailSizeRange::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--border-dark); }
#step2 #thumbnailSizeRange::-webkit-slider-thumb {
  width: 18px; height: 18px; margin-top: -7px;
  border: 2px solid var(--surface-alt); border-radius: 50%;
  background: var(--primary); box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 55%, transparent);
  -webkit-appearance: none;
}
#step2 #thumbnailSizeRange::-moz-range-track { height: 4px; border: 0; border-radius: 999px; background: var(--border-dark); }
#step2 #thumbnailSizeRange::-moz-range-thumb { width: 18px; height: 18px; border: 2px solid var(--surface-alt); border-radius: 50%; background: var(--primary); }
#step2 #thumbnailSizeRange:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
#step2 #thumbnailSizeValue {
  min-width: 48px;
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
#step2 .step2-action-bar {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  flex: 0 0 auto;
}
#step2 .step2-action-bar .btn,
#step2 .step2-selection-count { min-height: 36px; box-sizing: border-box; }
#step2 .step2-selection-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px !important;
  border: 1px solid var(--border);
  border-radius: 8px !important;
  background: var(--surface-alt) !important;
  box-shadow: none !important;
  white-space: nowrap;
}
#step2 .step2-selection-count .material-symbols-rounded { color: var(--primary); font-size: 18px !important; }
#step2 .step2-layout { gap: 14px !important; min-height: 0; }
#step2 .step2-main {
  min-width: 0;
  min-height: 0;
  padding: 0 2px 0 0;
  overflow: hidden;
}
#step2 .page-thumbnails {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--step2-thumb-size)), 1fr)) !important;
  grid-auto-rows: max-content;
  gap: 12px !important;
  padding: 2px 6px 12px 2px !important;
  align-content: start;
  scrollbar-gutter: stable;
}
#step2 .page-thumb {
  border-width: 1px !important;
  border-radius: 9px !important;
  aspect-ratio: 1.1 !important;
  box-shadow: none !important;
  transform: none !important;
}
#step2 .page-thumb:hover {
  transform: translateY(-1px) !important;
  border-color: var(--primary) !important;
  box-shadow: 0 3px 10px rgba(0,0,0,.12) !important;
}
#step2 .page-thumb.selected { box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 24%, transparent) !important; }
#step2 .page-thumb-select { top: 7px !important; right: 7px !important; width: 30px !important; height: 30px !important; }
#step2 .page-thumb-info { min-height: 36px; padding: 7px 9px !important; gap: 5px !important; }
#step2 .page-thumb-label { font-size: 11px !important; }
#step2 .page-thumb-name { font-size: 12px !important; }
#step2 .step2-floor-panel {
  /* Step 3の抽出サイドパネルと同じ --step3-side-width を使用 */
  width: var(--step3-side-width) !important;
  padding: 14px !important;
  gap: 10px !important;
  border-radius: 10px !important;
}
#step2 .step2-floor-panel .floor-add-row { gap: 8px !important; }
#step2 .step2-floor-panel .floor-name-input { min-height: 36px; }
#step2 .step2-floor-panel .floor-add-btn { min-height: 36px; }
@media (max-width: 1320px) {
  #step2 .step2-topbar { grid-template-columns: minmax(0, 1fr) !important; }
  #step2 .step2-topbar-secondary { justify-content: space-between; }
}
@media (max-width: 760px) {
  #step2 .step-inner { padding: 2px !important; }
  #step2 .step2-topbar { padding: 10px !important; margin-bottom: 10px !important; }
  #step2 .step2-topbar-secondary { display: grid; grid-template-columns: minmax(0, 1fr); }
  #step2 .thumbnail-size-control { grid-template-columns: auto 14px minmax(70px, 1fr) 17px 44px; width: 100%; }
  #step2 .step2-action-bar { justify-content: space-between !important; width: 100%; }
  #step2 .step2-layout { gap: 10px !important; }
  #step2 .step2-floor-panel { width: 100% !important; }
}

/* ===== Step 2 reference layout v17 (2026-09-18) ===== */
/* ステッパーの位置は従来のまま、STEP 2の追加操作だけを右レールへ置く。 */
.step2-header-actions {
  display: none;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
  box-sizing: border-box;
}
#app:has(> #step2:not(.hidden)) .step2-header-actions {
  display: flex !important;
}
.step2-header-actions .step2-selection-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  box-shadow: none;
  white-space: nowrap;
  font-size: 0.78rem;
  flex: 0 0 auto;
}
.step2-header-actions .step2-selection-count .material-symbols-rounded {
  color: var(--primary);
  font-size: 18px;
}
.step2-header-actions #goToStep3 {
  min-height: 36px;
  white-space: nowrap;
  flex: 1 1 auto;
}
#step2 .step2-topbar {
  display: flex !important;
  align-items: center !important;
  gap: 24px !important;
}
#step2 .step2-topbar-primary {
  flex: 0 0 360px;
  min-width: 0;
}
#step2 .step2-topbar-secondary {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: space-between !important;
}
#step2 .page-selection-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
#step2 .step2-layout {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) var(--step3-side-width);
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  gap: 14px !important;
}
#step2 .step2-main-column {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
#step2 .step2-main-column > .step2-topbar,
#step2 .step2-main-column > #loadingInfo {
  flex: 0 0 auto;
}
#step2 .step2-main-column > .step2-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
#step2 .step2-floor-panel {
  grid-column: 2;
  grid-row: 1;
  width: var(--step3-side-width) !important;
  height: 100%;
  align-self: stretch;
}
@media (min-width: 1101px) {
  #app:has(> #step2:not(.hidden)) {
    position: relative;
  }
  #app:has(> #step2:not(.hidden)) > header.app-header .step2-header-actions {
    position: absolute;
    top: 4px;
    right: 8px;
    width: var(--step3-side-width);
    justify-content: space-between;
  }
}
@media (min-width: 1501px) {
  /* 既存のSTEP 2ヘッダー幅を維持し、ステッパーを動かさない。 */
  #app:has(> #step2:not(.hidden)) > header.app-header {
    width: calc(100vw - 692px) !important;
    max-width: calc(100vw - 692px) !important;
  }
}
@media (max-width: 1320px) {
  #step2 .step2-topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
  }
  #step2 .step2-topbar-primary { flex-basis: auto; }
  #step2 .step2-topbar-secondary { justify-content: space-between !important; }
}
@media (max-width: 1100px) {
  #app:has(> #step2:not(.hidden)) > header.app-header .step2-header-actions {
    position: static;
    width: auto;
    justify-content: flex-end;
  }
  #step2 .step2-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px !important;
  }
  #step2 .step2-main-column {
    grid-column: 1;
    grid-row: 1;
  }
  #step2 .step2-floor-panel {
    grid-column: 1;
    grid-row: 2;
    width: 100% !important;
    height: auto;
    max-height: 220px !important;
    flex: 0 0 220px !important;
  }
}

/* ===== Step 2 header actions + warning action color v20 (2026-09-18) ===== */
/* ヘッダー操作を階層パネルの幅・右端・上下位置に合わせる。 */
#app:has(> #step2:not(.hidden)) .step2-header-actions {
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  width: var(--step3-side-width) !important;
  height: 40px !important;
  min-width: 0 !important;
  min-height: 40px !important;
  max-width: var(--step3-side-width) !important;
  max-height: 40px !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}
#app:has(> #step2:not(.hidden)) .step2-header-actions .step2-selection-count,
#app:has(> #step2:not(.hidden)) .step2-header-actions #goToStep3 {
  height: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  min-width: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}
#app:has(> #step2:not(.hidden)) .step2-header-actions .step2-selection-count {
  justify-content: center;
  padding: 0 12px !important;
  border-radius: 8px !important;
  line-height: 1;
  background: var(--surface) !important;
  border-color: var(--border) !important;
  box-shadow: none !important;
  white-space: nowrap;
}
#app:has(> #step2:not(.hidden)) .step2-header-actions #goToStep3 {
  width: auto !important;
  justify-content: center;
  padding: 0 16px !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}
@media (min-width: 1101px) {
  /* ヘッダー内のステッパーと同じ上下マージンで揃える。 */
  #app:has(> #step2:not(.hidden)) > header.app-header .step2-header-actions {
    top: 14px !important;
    right: 22px !important;
    width: var(--step3-side-width) !important;
    max-width: var(--step3-side-width) !important;
    margin: 0 !important;
  }
}
@media (min-width: 1501px) {
  /* ワイド画面はSTEP 2ヘッダーの上端16px＋中央合わせ分2px。 */
  #app:has(> #step2:not(.hidden)) > header.app-header .step2-header-actions {
    top: 18px !important;
  }
}
#step2 #btnAddFloor {
  background: var(--warning) !important;
  border-color: var(--warning) !important;
  color: #ffffff !important;
}
#step2 #btnAddFloor:hover:not(:disabled) {
  background: color-mix(in srgb, var(--warning) 86%, #000000) !important;
  border-color: color-mix(in srgb, var(--warning) 86%, #000000) !important;
  color: #ffffff !important;
}
@media (max-width: 1100px) {
  #app:has(> #step2:not(.hidden)) .step2-header-actions {
    display: flex !important;
    position: static !important;
    top: auto !important;
    right: auto !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    gap: 8px;
    align-items: center;
  }
  #app:has(> #step2:not(.hidden)) .step2-header-actions .step2-selection-count,
  #app:has(> #step2:not(.hidden)) .step2-header-actions #goToStep3 {
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
  }
}

/* ===== Canvas viewport cleanup v13 (2026-09-17) ===== */
#step3 .step3-left-col,
#step3 .step3-canvas-section {
  min-width: 0;
  min-height: 0;
  overflow: hidden !important;
}
#step3 .main-canvas-wrapper {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto !important;
  overscroll-behavior: contain;
  scrollbar-width: none !important;
  scrollbar-gutter: auto !important;
  -ms-overflow-style: none;
  isolation: isolate;
  background-clip: padding-box;
}
#step3 .main-canvas-wrapper::-webkit-scrollbar,
#step3 .step3-canvas-toolbar::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}
#step3 .main-canvas-wrapper::-webkit-scrollbar-track,
#step3 .main-canvas-wrapper::-webkit-scrollbar-thumb { background: transparent !important; }
#step3 .step3-canvas-toolbar { scrollbar-width: none !important; -ms-overflow-style: none; }
#step3 #pdfCanvas {
  display: block;
  margin: 0 !important;
  max-width: none !important;
  max-height: none !important;
  transform-origin: 0 0 !important;
}
#step3 #lineCanvas { max-width: none !important; max-height: none !important; transform-origin: 0 0 !important; }
#step3 .selection-overlay { transform-origin: 0 0; }
#step3 .step3-canvas-hint { margin-top: 6px !important; line-height: 1.3; }
@media (min-width: 1101px) {
  #step3 .work-layout { overflow: hidden !important; }
}
/* v13 sizing guard: keep Step 2 surfaces inside their layout columns. */
#step2 .step2-topbar,
#step2 .step2-floor-panel { box-sizing: border-box !important; }
#step2 .step2-topbar { width: 100% !important; }
/* Remove the orphan divider when the selection group has no visible actions. */
#step3 #selectionActionGroup:not(.layout-editor-host) {
  min-width: 0 !important;
  padding-left: 0 !important;
  border-left: 0 !important;
}
#step3 #selectionActionGroup:not(.layout-editor-host):not(:has(> .btn:not([hidden]):not([style*="display: none"]):not([style*="display:none"]))) {
  display: none !important;
}
@media (max-width: 760px) {
  #step2 .step2-layout {
    flex-direction: column !important;
    align-items: stretch !important;
    overflow: hidden !important;
  }
  #step2 .step2-main {
    width: 100% !important;
    flex: 1 1 300px !important;
    min-height: 260px !important;
    overflow: hidden !important;
  }
  #step2 .page-thumbnails { width: 100% !important; min-width: 0 !important; }
  #step2 .step2-floor-panel {
    order: 2;
    width: 100% !important;
    max-height: 220px !important;
    flex: 0 0 220px !important;
  }
}

/* ===== STEP 3 final rail alignment v25 (2026-09-18) ===== */
/* 実際に最後に適用されるルールとして、上段・下段の右端と右レール間隔を揃える。 */
@media (min-width: 1101px) {
  #step3 .work-layout {
    column-gap: var(--step3-rail-gap) !important;
  }
  #step3 .step3-top-area,
  #step3 .step3-left-col,
  #step3 .step3-left-col > .step3-canvas-section,
  #step3 .main-canvas-wrapper {
    box-sizing: border-box !important;
    min-width: 0 !important;
  }
}
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    /* step3の右パディング12pxを含め、下段の右端を上段と同じ位置へ */
    padding-right: calc(var(--step3-side-width) + 16px) !important;
  }
  #step3 .step3-right-col {
    right: 16px !important;
    width: var(--step3-side-width) !important;
    min-width: var(--step3-side-width) !important;
    max-width: var(--step3-side-width) !important;
  }
  #step3 .step3-top-area > .step3-doc-controls {
    right: calc(var(--step3-side-width) + 16px + var(--step3-rail-gap)) !important;
  }
  #step3 .step3-left-col,
  #step3 .step3-left-col > .step3-canvas-section,
  #step3 .main-canvas-wrapper {
    width: 100% !important;
    max-width: none !important;
  }
}

/* ===== STEP 3 tool icons and full-height canvas v27 (2026-09-18) ===== */
#step3 .step3-mode-method .btn-group.toggle-group .btn {
  gap: 4px !important;
  white-space: nowrap;
}
#step3 .step3-mode-method .btn-group.toggle-group .material-symbols-rounded {
  flex: 0 0 auto;
  font-size: 15px !important;
  line-height: 1;
}
#step3 .step3-canvas-section {
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
}
#step3 .step3-canvas-section > .main-canvas-wrapper {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  margin-bottom: 0 !important;
}

/* ===== STEP 3 outer edge spacing and rail alignment v34 (2026-09-18) ===== */
@media (min-width: 1501px) {
  #app:has(> #step3:not(.hidden)) {
    /* 右レールの右端16pxに、アプリ外周の左端・下端を揃える。 */
    padding-left: 16px !important;
    padding-bottom: 16px !important;
  }
  /* #appと#step3の余白を二重計上せず、外周基準を#appへ一本化する。 */
  #step3 {
    padding-left: 0 !important;
    padding-bottom: 0 !important;
  }
  /* 上16px＋下16pxで、右レールの上下端を外周基準に合わせる。 */
  #step3 .step3-right-col {
    height: calc(100dvh - 32px) !important;
  }
  #step3 .step3-left-col {
    padding-bottom: 0 !important;
  }
  #step3 .step3-canvas-section > .main-canvas-wrapper {
    margin-bottom: 0 !important;
  }
  #step3 .step3-right-col > .side-panel {
    height: 100% !important;
  }
}


/* v20: canonical raster-grid preview; SVG is visual only and never enters exports. */
#step3 .click-grid-preview { contain: layout style paint; mix-blend-mode: multiply; }


/* ===== v21 final UI polish (2026-09-24) ===== */
/* Header help is intentionally icon-only at every desktop width. */
header.app-header a.header-help {
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  height: 36px !important;
  min-height: 36px !important;
  padding: 0 !important;
  gap: 0 !important;
  border-radius: 7px !important;
  font-size: 0 !important;
}
header.app-header a.header-help .material-symbols-rounded {
  margin: 0 !important;
  font-size: 18px !important;
}

/* The table-layout command uses its accessible title/label and shows only the icon. */
#step3 .click-layout-toolbar-slot #btnClickLayout.table-layout-button {
  width: 32px !important;
  min-width: 32px !important;
  max-width: 32px !important;
  height: 32px !important;
  min-height: 32px !important;
  max-height: 32px !important;
  padding: 0 !important;
  gap: 0 !important;
  border-radius: 7px !important;
  justify-content: center !important;
}
#step3 #btnClickLayout.table-layout-button svg {
  width: 18px !important;
  height: 18px !important;
  margin: 0 !important;
}

/* Match the target-range control to the upper segmented controls. */
#step3 .step3-canvas-toolbar {
  padding: 3px 10px !important;
  box-sizing: border-box !important;
}
#step3 #selectionActionGroup:not(.layout-editor-host) {
  height: 32px !important;
  min-height: 32px !important;
  max-height: 32px !important;
  gap: 0 !important;
  align-items: stretch !important;
  border-radius: 7px !important;
}
#step3 #selectionActionGroup:not(.layout-editor-host) > .btn {
  gap: 4px !important;
  border-radius: 5px !important;
  font-size: .74rem !important;
}
#step3 #selectionActionGroup:not(.layout-editor-host) > .btn svg {
  width: 16px !important;
  height: 16px !important;
  margin: 0 !important;
  flex: 0 0 auto;
}
#step3 .step3-canvas-toolbar:has(#selectionActionGroup.layout-editor-host) {
  padding-block: 3px !important;
}

/* Centre the three document rows as one stack and centre the page row internally. */
#step3 .step3-page-nav {
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
  margin-block: 0 !important;
}
@media (min-width: 1501px) {
  #step3 .step3-top-area > .step3-doc-controls {
    align-content: center !important;
  }
  #step3 .step3-doc-controls .step3-page-nav {
    height: 44px !important;
    min-height: 44px !important;
    max-height: 44px !important;
    padding: 4px 0 !important;
  }
}


/* ===== v22 control consistency pass (2026-09-24) ===== */
/* Help and theme are bare icon actions: no persistent box, fill, or border. */
header.app-header .header-help,
header.app-header .header-theme {
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  outline-offset: 2px;
}
header.app-header .header-help:hover,
header.app-header .header-theme:hover {
  background: color-mix(in srgb, var(--text-main) 8%, transparent) !important;
  border-color: transparent !important;
  box-shadow: none !important;
}
header.app-header .header-help:focus-visible,
header.app-header .header-theme:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 62%, transparent) !important;
  border: 0 !important;
}

/* Table-layout settings and drag-detection settings share one square control. */
#step3 .click-layout-toolbar-slot #btnClickLayout.table-layout-button,
#step3 #btnSettingsToggle {
  width: 38px !important;
  min-width: 38px !important;
  max-width: 38px !important;
  height: 38px !important;
  min-height: 38px !important;
  max-height: 38px !important;
  padding: 0 !important;
  gap: 0 !important;
  border-radius: 7px !important;
  align-items: center !important;
  justify-content: center !important;
  box-sizing: border-box !important;
}
#step3 #btnClickLayout.table-layout-button .material-symbols-rounded,
#step3 #btnSettingsToggle .material-symbols-rounded {
  margin: 0 !important;
  font-size: 18px !important;
  line-height: 1 !important;
}

/* Remove the residual blank band below page navigation on wide screens. */
@media (min-width: 1501px) {
  #step3 .step3-top-area > .step3-doc-controls {
    height: 160px !important;
    min-height: 160px !important;
    max-height: 160px !important;
    align-content: center !important;
  }
  #step3 .step3-doc-controls .step3-page-nav {
    padding: 4px 0 !important;
    align-items: center !important;
    justify-content: center !important;
  }
}


/* ===== v23 dark-mode icon contrast (2026-09-24) ===== */
html[data-theme="dark"] header.app-header .header-help,
html[data-theme="dark"] header.app-header .header-theme,
html[data-theme="dark"] header.app-header .header-help .material-symbols-rounded,
html[data-theme="dark"] header.app-header .header-theme .material-symbols-rounded {
  color: #ffffff !important;
}
