* { box-sizing: border-box; }

:root {
  --primary: #e85d3c;
  --primary-dark: #c94a2c;
  --border: #1d1d1f;
  --border-light: #888;
  --bg: #fafafa;
  --cell-bg: #fff;
  --text: #1d1d1f;
  --text-sub: #666;
  --highlight: #fff8e1;
  --danger: #d32f2f;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

#survey-form {
  width: 100%;
  max-width: 1366px;
  margin: 0 auto;
  padding: 8px;
}

/* ========== 共通セル ========== */
.cell {
  background: var(--cell-bg);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  position: relative;
}

.cell-title {
  font-weight: 700;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 3px;
  margin-bottom: 5px;
  color: var(--text);
}

/* ========== ヘッダー ========== */
.sheet-header {
  display: grid;
  grid-template-columns: 170px 1fr 360px;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
  background: white;
  border: 2px solid var(--border);
  padding: 6px 10px;
  border-radius: 4px;
}

.logo-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logo {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -1px;
}

.slogan {
  font-size: 9px;
  color: var(--text-sub);
  margin-top: 2px;
}

.sheet-title {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 3px;
  color: var(--text);
}

.customer-area { font-size: 11px; }

.customer-table {
  border-collapse: collapse;
  width: 100%;
}

.customer-table th,
.customer-table td {
  border: 1px solid var(--border);
  padding: 3px 5px;
  text-align: left;
}

.customer-table th {
  background: #f5f5f5;
  width: 70px;
  font-weight: 600;
  font-size: 10px;
}

.customer-table input {
  border: none;
  width: 100%;
  padding: 3px 2px;
  font-size: 12px;
  background: transparent;
  font-family: inherit;
}

.customer-table input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

/* ========== タブナビ ========== */
.tab-nav {
  display: flex;
  align-items: center;
  gap: 5px;
  background: white;
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 5px;
  margin-bottom: 6px;
}

.tab-btn {
  padding: 9px 14px;
  background: #f0f0f0;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-sub);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(232,93,60,0.3);
}

.tab-btn:active {
  transform: scale(0.97);
}

.tab-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.btn-primary-sm, .btn-secondary-sm {
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 700;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary-sm {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(232,93,60,0.3);
}

.btn-primary-sm:active {
  background: var(--primary-dark);
  transform: scale(0.97);
}

.btn-secondary-sm {
  background: white;
  color: var(--text);
  border: 1px solid var(--border-light);
}

/* ========== ページ切替 ========== */
.page { display: none; }
.page.active { display: block; }

/* ========== ステータス ========== */
.status {
  padding: 0;
  font-size: 12px;
  border-radius: 4px;
  text-align: center;
  font-weight: 600;
  min-height: 0;
  transition: all 0.2s;
}
.status.success {
  background: #e8f5e9;
  color: #2e7d32;
  padding: 8px;
  margin-bottom: 6px;
}
.status.error {
  background: #ffebee;
  color: var(--danger);
  padding: 8px;
  margin-bottom: 6px;
}

/* ========== 共通入力 ========== */
input[type="text"],
input[type="date"],
select,
textarea {
  font-size: 13px;
  font-family: inherit;
  padding: 5px 7px;
  border: 1px solid var(--border-light);
  border-radius: 3px;
  background: white;
  width: 100%;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  border-color: var(--primary);
}

input.mini {
  width: 68px;
  display: inline-block;
  padding: 4px 6px;
  font-size: 13px;
  text-align: right;
}

select.inline,
input.inline {
  display: inline-block;
  width: auto;
  margin-right: 3px;
}

label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 5px;
}

label input,
label select,
label textarea {
  margin-top: 2px;
}

label.inline-label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-right: 12px;
  margin-bottom: 4px;
}

textarea {
  resize: vertical;
  min-height: 36px;
  font-size: 12px;
}

/* ======================== PAGE 1 ======================== */
.p1-row-a {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 8px;
  margin-bottom: 6px;
}

.p1-row-b {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 8px;
}

.color-table {
  border-collapse: collapse;
  width: 100%;
}

.color-table th,
.color-table td {
  border: 1px solid var(--border-light);
  padding: 5px;
}

.color-table th {
  background: #f5f5f5;
  width: 50px;
  font-size: 11px;
  font-weight: 600;
}

.color-table select,
.color-table input {
  font-size: 12px;
  padding: 4px 6px;
  border: none;
  background: transparent;
}

.dim-area { min-height: 180px; }

.dim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
}

.dim-grid label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  margin-bottom: 0;
  color: var(--text);
}

.dim-grid input.mini {
  flex: 1;
  max-width: 80px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  padding: 6px;
}

.plan-select label {
  font-size: 11px;
  margin-bottom: 6px;
}

.plan-select select {
  font-size: 12px;
  padding: 6px;
}

.perim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.gutter-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-sub);
  border-bottom: 1px dotted var(--border-light);
  padding-bottom: 2px;
  margin-bottom: 3px;
}

.gutter-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 160px;
  overflow-y: auto;
}

.gutter-list input {
  padding: 5px 7px;
  font-size: 13px;
  width: 100%;
}

.memo-area textarea {
  min-height: 120px;
  font-size: 12px;
}

.memo-free label {
  font-size: 10px;
}

.memo-free textarea {
  min-height: 45px;
  font-size: 12px;
}

/* ======================== PAGE 2 ======================== */
.p2-top-row {
  display: grid;
  grid-template-columns: 1.4fr 1.3fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}

.window-table {
  border-collapse: collapse;
  width: 100%;
}

.window-table th,
.window-table td {
  border: 1px solid var(--border-light);
  padding: 2px;
  text-align: center;
}

.window-table thead th {
  background: #fff8e1;
  font-size: 10px;
  font-weight: 600;
}

.window-table tbody th {
  background: #f5f5f5;
  font-size: 10px;
  font-weight: 600;
  width: 80px;
}

.window-table small {
  font-weight: 400;
  color: var(--text-sub);
  font-size: 8px;
}

.window-table input {
  width: 100%;
  border: none;
  padding: 6px 2px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  background: transparent;
}

.seal-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 11px;
}

.seal-table th,
.seal-table td {
  border: 1px solid var(--border-light);
  padding: 2px;
}

.seal-table th {
  background: #f5f5f5;
  font-size: 10px;
}

.seal-table input,
.seal-table select {
  border: none;
  padding: 4px 6px;
  font-size: 13px;
  background: transparent;
  width: 100%;
}

.btn-mini {
  display: inline-block;
  padding: 4px 10px;
  background: #f0f0f0;
  border: 1px dashed var(--border-light);
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-sub);
  margin-top: 3px;
  -webkit-tap-highlight-color: transparent;
}

.btn-mini:active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.memo-attach label {
  font-size: 9px;
  margin-bottom: 5px;
}

.memo-attach input, .memo-attach select {
  font-size: 11px;
  padding: 4px 6px;
}

.p2-bot-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr 1.2fr;
  gap: 6px;
}

.wall-detail label,
.duct-area label,
.gutter-area label {
  font-size: 9px;
  margin-bottom: 5px;
}

.wall-detail input,
.duct-area input,
.duct-area select,
.gutter-area input {
  font-size: 11px;
  padding: 4px 6px;
}

.gutter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
  margin-bottom: 6px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text);
  margin-bottom: 0;
  padding: 3px;
  border-radius: 3px;
}

.check-grid input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
}

.scaffold-area label {
  font-size: 10px;
}

/* ======================== PAGE 3/4 : 全画面キャンバス ======================== */
.canvas-page {
  margin: 0;
}
.canvas-page.active {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 185px);
  min-height: 480px;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 2px solid var(--border);
  border-radius: 6px 6px 0 0;
  padding: 8px 12px;
  border-bottom: none;
}

.toolbar-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  padding-right: 8px;
  border-right: 1px solid var(--border-light);
  margin-right: 4px;
}

.canvas-toolbar .tool-btn {
  background: #f0f0f0;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  top: auto;
  right: auto;
}

.canvas-toolbar .tool-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.canvas-toolbar .tool-btn.danger {
  background: #fff5f5;
  border-color: #f5c6c6;
  color: #c62828;
}

.canvas-toolbar .tool-btn.danger:active {
  background: #ffebee;
}

.tool-file-label {
  cursor: pointer;
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-hint {
  font-size: 11px;
  color: var(--text-sub);
  padding-right: 4px;
}

.canvas-wrap.fullscreen {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 0 0 6px 6px;
  background: #fdfdfd;
  position: relative;
  overflow: hidden;
}

.canvas-wrap.fullscreen .draw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  cursor: crosshair;
}

/* 既存の canvas-tools 用スタイル（キャンバス内絶対配置）は page 3/4 では使われない */
.canvas-wrap:not(.fullscreen) {
  position: relative;
  border: 1.5px solid var(--border-light);
  background: #fdfdfd;
}

.canvas-wrap:not(.fullscreen) .canvas-tools {
  position: absolute;
  top: 3px;
  right: 3px;
  display: flex;
  gap: 3px;
}

.canvas-wrap:not(.fullscreen) .draw-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  cursor: crosshair;
}

/* ============== ホワイトボード入力オーバーレイ ============== */
.wb-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  justify-content: flex-end;
  align-items: center;
  padding: 20px;
}

.wb-overlay.active {
  display: flex;
  animation: wbFade 0.18s ease;
}

@keyframes wbFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.wb-panel {
  width: min(620px, 60vw);
  max-height: 90vh;
  background: white;
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
}

.wb-header {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.wb-label {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  flex: 1;
}

.wb-btn-cancel {
  background: #f0f0f0;
  border: 1px solid var(--border-light);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.wb-hint {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.5;
  background: #fff8e1;
  padding: 10px 14px;
  border-radius: 8px;
  border-left: 4px solid #f4a261;
}

.wb-hint strong { color: var(--primary); }

.wb-hint-sub {
  font-size: 11px;
  color: var(--text-sub);
}

.wb-input-wrap {
  position: relative;
  width: 100%;
  min-height: 260px;
  border: 3px dashed var(--primary);
  border-radius: 12px;
  background: #fff8f5;
  overflow: hidden;
}

.wb-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  font-weight: 700;
  color: #ffc4b0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.2s;
  user-select: none;
}

.wb-input-wrap:has(.wb-input:not(:placeholder-shown)) .wb-watermark,
.wb-input-wrap.has-value .wb-watermark {
  opacity: 0;
}

.wb-input {
  position: relative;
  width: 100%;
  min-height: 260px;
  font-size: 88px;
  font-weight: 700;
  text-align: center;
  padding: 20px;
  border: none;
  background: transparent;
  color: var(--primary-dark);
  outline: none;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  line-height: 1;
  -webkit-appearance: none;
  z-index: 1;
}

.wb-input:focus {
  outline: none;
}

.wb-buttons {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.wb-btn-clear {
  flex: 1;
  padding: 14px;
  background: #f0f0f0;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.wb-btn-confirm {
  flex: 2;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(232,93,60,0.3);
  -webkit-tap-highlight-color: transparent;
}

.wb-btn-confirm:active {
  background: var(--primary-dark);
  transform: scale(0.98);
}

/* ホワイトボード対応の入力欄に小さなペンアイコン（値が空の時だけ） */
input[inputmode="decimal"],
input[inputmode="numeric"] {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23bbb'><path d='M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34a1 1 0 00-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 4px center;
  background-size: 12px;
  padding-right: 20px;
}

/* 値が入力されていたらアイコン非表示・パディング標準化 */
input[inputmode="decimal"]:not(:placeholder-shown),
input[inputmode="numeric"]:not(:placeholder-shown) {
  background-image: none;
  padding-right: 7px;
}

/* ============== 動的行 ============== */
.dyn-row {
  display: flex;
  align-items: center;
  gap: 3px;
}

.dyn-row input { flex: 1; }

.dyn-row .idx {
  font-size: 10px;
  color: var(--text-sub);
  min-width: 14px;
}

.dyn-row .btn-del {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 16px;
  padding: 0 4px;
  cursor: pointer;
}
