* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: #2a2a2a;
  color: #f5f5f5;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  /* iOS notch */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* =========================================================
   HEADER
   ========================================================= */
header {
  background: #1a1a1a;
  border-bottom: 1px solid #444;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  flex-wrap: wrap;
}

.header-row-top {
  border-bottom: 1px solid #2a2a2a;
}

.header-row-bottom {
  padding-top: 6px;
  padding-bottom: 6px;
}

.title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}

.project-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #232323;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #333;
  min-width: 0;
  flex: 1 1 auto;
  max-width: 480px;
}

.project-label {
  font-size: 12px;
  color: #aaa;
  white-space: nowrap;
}

.project-select {
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #444;
  border-radius: 5px;
  padding: 6px 26px 6px 10px;
  font-size: 13px;
  font-family: inherit;
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23bbb' d='M0 0 L5 6 L10 0 Z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.dropdown { position: relative; }

.dropdown-content {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #2f2f2f;
  border: 1px solid #555;
  border-radius: 6px;
  min-width: 180px;
  z-index: 50;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.dropdown-content[hidden] { display: none; }

.dropdown-title {
  padding: 8px 14px 4px;
  font-size: 11px;
  color: #888;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #3a3a3a;
}

.dropdown-content button {
  display: block;
  width: 100%;
  background: none;
  color: #f5f5f5;
  border: none;
  padding: 12px 14px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

.dropdown-content button:hover { background: #3a3a3a; }
.dropdown-content button.danger-item { color: #e07474; }

.save-status {
  font-size: 11px;
  color: #888;
  padding: 4px 8px;
  border-radius: 4px;
  background: #232323;
  white-space: nowrap;
  border: 1px solid #2f2f2f;
  margin-left: auto;
}

.save-status.ok    { color: #6cc26c; border-color: #2e5d3a; }
.save-status.warn  { color: #e6b85a; border-color: #5a4625; }
.save-status.err   { color: #e07474; border-color: #5a2a2a; }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  background: #3a3a3a;
  color: #f5f5f5;
  border: 1px solid #555;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
}

.btn .btn-icon { font-size: 15px; line-height: 1; }

.btn.small {
  padding: 5px 10px;
  font-size: 13px;
  min-height: 30px;
}

.btn.icon {
  padding: 6px 10px;
  min-width: 34px;
  justify-content: center;
}

.btn:hover { background: #4a4a4a; }
.btn:active { background: #555; }
.btn.danger { background: #5a2a2a; border-color: #7a3a3a; }
.btn.danger:hover { background: #6a3a3a; }
.btn.primary { background: #2e5d3a; border-color: #4caf50; }
.btn.primary:hover { background: #3a7044; }

.btn.toggle[aria-pressed="true"] {
  background: #2e5d3a;
  border-color: #4caf50;
}

.zoom-controls {
  display: inline-flex;
  align-items: center;
  background: rgba(35,35,35,0.92);
  padding: 3px;
  border-radius: 7px;
  border: 1px solid #333;
  gap: 2px;
}

.zoom-controls.floating {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 10;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

/* 凡例パネル（HTML側、canvas-wrap 内に絶対配置） */
.legend-panel {
  position: absolute;
  z-index: 8;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #222;
  max-width: 220px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  pointer-events: none;
}
.legend-panel[hidden] { display: none; }
.legend-panel.pos-tl { top: 10px; left: 10px; }
.legend-panel.pos-tr { top: 10px; right: 10px; }
.legend-panel.pos-bl { bottom: 10px; left: 10px; }
.legend-panel.pos-br { bottom: 10px; right: 10px; }
.legend-panel h4 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  color: #555;
  letter-spacing: 0.5px;
}
.legend-panel .legend-section + .legend-section { margin-top: 8px; }
.legend-panel ul { list-style: none; padding: 0; margin: 0; }
.legend-panel li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  line-height: 1.2;
}
.legend-panel li .dot {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border-color: #222;
}
.legend-panel .rank-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

/* 凡例パネル内の形状 dot は .rp-list と同じスタイルを流用 */
.legend-panel .dot.shape-circle-outline {
  background: transparent !important;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
}
.legend-panel .dot.shape-circle-double {
  background: transparent !important;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  position: relative;
}
.legend-panel .dot.shape-circle-double .inner {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  background: transparent;
}
.legend-panel .dot.shape-square-outline {
  background: transparent !important;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
}
.legend-panel .dot.shape-diamond-outline {
  background: transparent !important;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
  transform: rotate(45deg);
  width: 10px;
  height: 10px;
}
.legend-panel .dot.shape-triangle-outline,
.legend-panel .dot.shape-mark {
  background: transparent !important;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  font-weight: bold;
}
.legend-panel .dot.shape-line {
  border: none;
  width: 14px;
  height: 3px;
  border-radius: 1px;
  align-self: center;
}
.legend-panel .dot.shape-circle-solid {
  border-radius: 50%;
  border: none;
}
.legend-panel .dot.shape-square-solid {
  border-radius: 2px;
  border: none;
}

.zoom-controls .btn.small {
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 9px;
  border-radius: 4px;
  min-height: 28px;
  color: #f5f5f5;
}

.zoom-controls .btn.small:hover { background: #3a3a3a; }

.zoom-controls .zoom-btn {
  min-width: 28px;
  font-size: 16px;
  line-height: 1;
}

.zoom-controls .zoom-level {
  min-width: 56px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: #ccc;
}

.desktop-only { display: inline-flex; }
.mobile-only { display: none; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* =========================================================
   TAB BAR
   ========================================================= */
.tab-bar {
  background: #222;
  border-bottom: 1px solid #444;
  flex-shrink: 0;
}

.tabs {
  display: flex;
  align-items: stretch;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.tabs::-webkit-scrollbar { height: 6px; }
.tabs::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #222;
  color: #bbb;
  border-right: 1px solid #333;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  min-height: 40px;
}

.tab:hover { background: #2a2a2a; color: #fff; }

.tab.active {
  background: #2f2f2f;
  color: #fff;
  border-bottom: 2px solid #4caf50;
  padding-bottom: 8px;
}

.tab-name { font-weight: 500; }

.tab-action {
  background: rgba(255,255,255,0.08);
  color: #ddd;
  border: none;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.tab-action:hover { background: rgba(255,255,255,0.16); color: #fff; }

.tab-add {
  background: transparent;
  color: #888;
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  min-height: 40px;
}

.tab-add:hover { background: #2a2a2a; color: #ccc; }

/* =========================================================
   MAIN LAYOUT
   ========================================================= */
main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.toolbar {
  width: 220px;
  background: #1a1a1a;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-right: 1px solid #444;
  flex-shrink: 0;
  overflow-y: auto;
}

.section { display: flex; flex-direction: column; gap: 6px; }
.section[hidden] { display: none; }
.modal-section[hidden] { display: none; }

/* ツールバー：PC/スマホ切替 */
.toolbar-sp-only { display: none; }
.toolbar-pc-only { display: flex; }

.section-label {
  font-size: 11px;
  color: #888;
  letter-spacing: 0.5px;
  padding: 0 2px;
}

.cat-list, .rank-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-btn, .rank-btn {
  background: #2f2f2f;
  color: #f5f5f5;
  border: 2px solid transparent;
  padding: 12px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: inherit;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.cat-btn .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.4);
}

/* ツールバー用 形状バリエーション（中空・塗り・線・記号） */
.cat-btn .dot.shape-circle-outline {
  background: transparent !important;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
}
.cat-btn .dot.shape-circle-double {
  background: transparent !important;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  position: relative;
}
.cat-btn .dot.shape-circle-double .inner {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  background: transparent;
}
.cat-btn .dot.shape-square-outline {
  background: transparent !important;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
}
.cat-btn .dot.shape-diamond-outline {
  background: transparent !important;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
  transform: rotate(45deg);
  width: 11px;
  height: 11px;
}
.cat-btn .dot.shape-triangle-outline {
  background: transparent !important;
  border: none;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  font-weight: bold;
}
.cat-btn .dot.shape-line {
  border: none;
  width: 14px;
  height: 3px;
  border-radius: 1px;
  align-self: center;
}
.cat-btn .dot.shape-circle-solid {
  border-radius: 50%;
  border: none;
}
.cat-btn .dot.shape-square-solid {
  border-radius: 2px;
  border: none;
}
.cat-btn .dot.shape-mark {
  background: transparent !important;
  border: none;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  font-weight: bold;
}

.rank-btn .rank-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  font-weight: bold;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cat-btn .label, .rank-btn .label { flex: 1; }
.cat-btn .label small {
  font-size: 0.78em;
  color: #bbb;
  font-weight: normal;
  margin-left: 3px;
}

.cat-btn.active, .rank-btn.active {
  border-color: #4caf50;
  background: #243024;
}

/* =========================================================
   ツールバー専用：劣化現象アイコンの色を緊急度に連動
   ========================================================= */
.toolbar { --cat-icon-color: #ffffff; }
.toolbar[data-rank="A"] { --cat-icon-color: #B23A2E; }
.toolbar[data-rank="B"] { --cat-icon-color: #3949AB; }
.toolbar[data-rank="C"] { --cat-icon-color: #2E7D32; }

/* 中空系（縁の色を変える） */
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-circle-outline,
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-circle-double,
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-square-outline,
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-diamond-outline {
  border-color: var(--cat-icon-color);
}
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-circle-double .inner {
  border-color: var(--cat-icon-color);
}

/* 記号系（文字色を変える） */
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-triangle-outline,
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-mark {
  color: var(--cat-icon-color);
}

/* 塗り系（背景色を変える） */
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-circle-solid,
.toolbar .cat-btn:not([data-cat="crack"]):not([data-cat="crack_large"]) .dot.shape-square-solid {
  background: var(--cat-icon-color);
}

/* クラック系は緊急度に依存せず固定色 */
.toolbar .cat-btn[data-cat="crack_large"] .dot.shape-line { background: #e53935; }
.toolbar .cat-btn[data-cat="crack"]       .dot.shape-line { background: #1e88e5; }

.tile-select {
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 12px 32px 12px 12px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23bbb' d='M0 0 L6 8 L12 0 Z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-height: 44px;
}

.stepper {
  background: #2a2a2a;
  border-radius: 8px;
  padding: 10px 12px;
}

.stepper-label {
  font-size: 12px;
  color: #bbb;
  margin-bottom: 6px;
}

.stepper-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-btn {
  background: #3a3a3a;
  color: #fff;
  border: 1px solid #555;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  font-size: 22px;
  font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-btn:hover { background: #4a4a4a; }
.step-btn:active { background: #555; }

.step-input {
  flex: 1;
  height: 44px;
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  font-family: inherit;
  min-width: 0;
}

.step-input::-webkit-inner-spin-button,
.step-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.step-unit { color: #bbb; font-size: 14px; }

.step-unit-select {
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 0 24px 0 10px;
  height: 44px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path fill='%23bbb' d='M0 0 L5 6 L10 0 Z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
  flex-shrink: 0;
  min-width: 56px;
}

/* PCのサイドバー（縦カラム・220px）では数量と単位を2段にして潰れを防ぐ */
@media (min-width: 901px) {
  .toolbar .stepper-row { flex-wrap: wrap; }
  .toolbar .stepper-row .step-unit-select {
    flex-basis: 100%;
    margin-top: 2px;
    width: 100%;
  }
}

.hint {
  font-size: 12px;
  color: #888;
  line-height: 1.6;
  text-align: center;
  margin-top: auto;
}

.canvas-wrap {
  flex: 1;
  overflow: auto;
  background: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
}

.canvas-wrap.zoomed {
  align-items: flex-start;
  justify-content: flex-start;
}

canvas {
  background: white;
  touch-action: none;
  cursor: crosshair;
  display: none;
}

canvas.loaded { display: block; }

.placeholder {
  color: #ccc;
  text-align: center;
  font-size: 16px;
  line-height: 1.8;
  padding: 20px;
}

.placeholder.hidden { display: none; }

/* =========================================================
   RIGHT PANEL (集計)
   ========================================================= */
.right-panel {
  width: 280px;
  background: #1a1a1a;
  border-left: 1px solid #444;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, max-width 0.2s ease, transform 0.2s ease;
}

.right-panel.collapsed {
  width: 0;
  border-left: none;
}

.right-panel-header {
  padding: 12px 14px;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.right-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.right-panel-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.right-panel-backdrop {
  display: none;
}

.rp-total {
  background: #243024;
  border: 1px solid #2e5d3a;
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.rp-total-label { font-size: 12px; color: #b0d0b0; letter-spacing: 0.5px; }

.rp-total-value {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
}

.rp-total-value .unit { font-size: 13px; color: #b0d0b0; margin-left: 4px; }

.rp-subtotal {
  font-size: 11px;
  color: #888;
  padding: 0 4px;
  margin-top: -6px;
}

.rp-target-block {
  background: #1f1f1f;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
}

.rp-target-block .rp-target-name {
  font-size: 12px;
  font-weight: 600;
  color: #ddd;
  margin-bottom: 4px;
  padding: 0 2px;
}

.rp-target-block .rp-list li {
  background: #2a2a2a;
}

/* 見積プラン別セクション */
.rp-plan-section {
  background: linear-gradient(180deg, #243024 0%, #1f2a1f 100%);
  border: 1px solid #2e5d3a;
  border-radius: 8px;
  padding: 10px 12px;
}
.rp-plan-section h4 { color: #b0d0b0; }

.rp-plan-list li {
  background: #1a1a1a;
  border: 1px solid #2a3a2a;
  padding: 8px 10px;
}
.rp-plan-list li.plan-ab {
  border-color: #4caf50;
  background: #1f2a1f;
}
.rp-plan-list li.plan-ab .label::after {
  content: ' ★';
  color: #4caf50;
}
.rp-plan-list li .num { font-weight: bold; color: #fff; }

.plan-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #2e5d3a;
  color: #fff;
  font-size: 10px;
  font-weight: bold;
  border: 1px solid rgba(255,255,255,0.3);
}

.rp-export-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.rp-export-actions .btn { flex: 1 1 auto; justify-content: center; }

.rp-export-hint {
  font-size: 10px;
  color: #8aaa8a;
  text-align: center;
  margin-top: 4px;
}

.rp-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rp-section h4 {
  font-size: 11px;
  color: #888;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 0 2px;
  margin-bottom: 2px;
}

.rp-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rp-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: #232323;
  border-radius: 5px;
  font-size: 13px;
}

.rp-list li.dim { opacity: 0.4; }

.rp-list .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.3);
}

/* 劣化現象の形状（リスト用） */
.rp-list .dot.shape-circle-outline {
  background: transparent !important;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
}
.rp-list .dot.shape-circle-double {
  background: transparent !important;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  position: relative;
}
.rp-list .dot.shape-circle-double .inner {
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  background: transparent;
}
.rp-list .dot.shape-square-outline {
  background: transparent !important;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
}
.rp-list .dot.shape-diamond-outline {
  background: transparent !important;
  border-width: 2px;
  border-style: solid;
  border-radius: 2px;
  transform: rotate(45deg);
  width: 9px;
  height: 9px;
}
.rp-list .dot.shape-triangle-outline {
  background: transparent !important;
  border: none;
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  font-weight: bold;
}
.rp-list .dot.shape-line {
  border: none;
  width: 12px;
  height: 3px;
  border-radius: 1px;
  align-self: center;
}
.rp-list .dot.shape-circle-solid {
  border-radius: 50%;
  border: none;
}
.rp-list .dot.shape-square-solid {
  border-radius: 2px;
  border: none;
}
.rp-list .dot.shape-mark {
  background: transparent !important;
  border: none;
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  font-weight: bold;
}

.rp-list .rank-badge {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  color: #fff;
  font-weight: bold;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.3);
}

.rp-list .tile-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.3);
}

.rp-list .label { flex: 1; color: #ddd; }

.rp-list .num {
  font-weight: bold;
  color: #fff;
  min-width: 40px;
  text-align: right;
}

.rp-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: #232323;
  border-radius: 5px;
  overflow: hidden;
}

.rp-matrix th, .rp-matrix td {
  padding: 6px 4px;
  border-bottom: 1px solid #333;
  text-align: center;
}

.rp-matrix tr:last-child th, .rp-matrix tr:last-child td { border-bottom: none; }

.rp-matrix thead th {
  color: #888;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.3px;
  background: #1f1f1f;
}

.rp-matrix tbody th {
  text-align: left;
  color: #ddd;
  font-weight: 500;
  font-size: 12px;
  padding-left: 8px;
  white-space: nowrap;
}

.rp-matrix tbody td { color: #ddd; }
.rp-matrix tbody td.dim { color: #555; }
.rp-matrix tbody td.total, .rp-matrix tbody th.total-row { font-weight: bold; color: #fff; background: #1f1f1f; }
.rp-matrix thead th.total-col { color: #ccc; }

.rp-notes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rp-note-item {
  background: #232323;
  border-left: 3px solid #4caf50;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  color: #ddd;
  line-height: 1.5;
}

.rp-note-item .rp-note-header {
  font-size: 11px;
  color: #aaa;
  margin-bottom: 3px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.rp-note-item .rp-note-header .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.rp-note-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* =========================================================
   LOCK SCREEN (PIN)
   ========================================================= */
.lock-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lock-screen[hidden] { display: none; }

.lock-box {
  background: #2f2f2f;
  border: 1px solid #555;
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.lock-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  text-align: center;
}

.lock-sub {
  font-size: 13px;
  color: #aaa;
  text-align: center;
  margin-bottom: 8px;
}

.lock-input {
  background: #1a1a1a;
  color: #fff;
  border: 2px solid #555;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  min-height: 44px;
}
.lock-input::placeholder { color: #777; }
.lock-input:focus {
  outline: none;
  border-color: #4caf50;
}

.lock-error {
  color: #e07474;
  font-size: 13px;
  text-align: center;
  padding: 8px 12px;
  background: rgba(224,116,116,0.1);
  border-radius: 6px;
  line-height: 1.5;
}
.lock-error[hidden] { display: none; }

.lock-info {
  color: #7cb342;
  font-size: 13px;
  text-align: center;
  padding: 10px 12px;
  background: rgba(124,179,66,0.1);
  border: 1px solid rgba(124,179,66,0.3);
  border-radius: 6px;
  line-height: 1.5;
}
.lock-info[hidden] { display: none; }

.lock-submit {
  min-height: 48px;
  font-size: 15px;
  justify-content: center;
}
.lock-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.lock-help {
  font-size: 11px;
  color: #888;
  text-align: center;
  line-height: 1.7;
  margin: 4px 0 0;
}

/* =========================================================
   CLOUD LIST
   ========================================================= */
.cloud-list-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.cloud-list-status {
  font-size: 12px;
  color: #888;
  margin-left: auto;
}
.cloud-list-status.ok   { color: #6cc26c; }
.cloud-list-status.warn { color: #e6b85a; }
.cloud-list-status.err  { color: #e07474; }

.cloud-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 8px;
  background: #1f1f1f;
}

.cloud-empty {
  text-align: center;
  color: #888;
  padding: 24px 12px;
  font-size: 13px;
}

.cloud-item {
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cloud-item.current {
  border-color: #4caf50;
  background: #243024;
}

.cloud-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cloud-item-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cloud-item-meta {
  font-size: 11px;
  color: #888;
}

.cloud-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.cloud-item-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
  min-height: 32px;
}

/* =========================================================
   MODAL
   ========================================================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal[hidden] { display: none; }

/* 確認ダイアログは他のモーダルより最前面に */
#dialogModal { z-index: 200; }

/* 招待コード発行フォームは管理画面より少し上に */
#adminCodeForm { z-index: 150; }

.modal-box {
  background: #2f2f2f;
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid #555;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-box-narrow { max-width: 360px; }

.modal-box h3 {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

.modal-section { display: flex; flex-direction: column; gap: 6px; }

/* 編集モーダル内の現象アイコンは白基調（クラックのみ赤/青固定） */
.modal .cat-btn .dot.shape-circle-outline,
.modal .cat-btn .dot.shape-circle-double,
.modal .cat-btn .dot.shape-square-outline,
.modal .cat-btn .dot.shape-diamond-outline {
  border-color: #fff !important;
  background: transparent !important;
}
.modal .cat-btn .dot.shape-circle-double .inner {
  border-color: #fff !important;
}
.modal .cat-btn .dot.shape-triangle-outline,
.modal .cat-btn .dot.shape-mark {
  color: #fff !important;
}
.modal .cat-btn .dot.shape-circle-solid,
.modal .cat-btn .dot.shape-square-solid {
  background: #fff !important;
}
.modal .cat-btn[data-cat="crack_large"] .dot.shape-line { background: #e53935 !important; }
.modal .cat-btn[data-cat="crack"]       .dot.shape-line { background: #1e88e5 !important; }

.modal-label {
  font-size: 12px;
  color: #aaa;
  letter-spacing: 0.5px;
}

.cat-list.compact, .rank-list.compact {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
}

.cat-list.compact .cat-btn,
.rank-list.compact .rank-btn {
  padding: 10px 10px;
  font-size: 13px;
  flex: 1 1 calc(50% - 3px);
  min-width: 0;
  min-height: 44px;
}

.modal-stepper { background: #1f1f1f; }

.note-input {
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  width: 100%;
  min-height: 70px;
  line-height: 1.5;
}

.dialog-message {
  font-size: 14px;
  color: #ddd;
  line-height: 1.55;
  white-space: pre-wrap;
}

.dialog-input {
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  width: 100%;
  min-height: 44px;
}

.dialog-input[hidden] { display: none; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 4px;
}

.modal-actions .btn { min-width: 80px; justify-content: center; }
.modal-actions .danger { margin-right: auto; }

/* =========================================================
   ADMIN PANEL (招待コード管理)
   ========================================================= */
.modal-box-wide {
  max-width: 1000px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.admin-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

.admin-actions {
  display: flex;
  gap: 8px;
}

.admin-table-wrap {
  overflow: auto;
  max-height: 60vh;
  border: 1px solid #444;
  border-radius: 6px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: #ddd;
}

.admin-table th,
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #444;
  text-align: left;
  white-space: nowrap;
}

.admin-table th {
  background: #1f1f1f;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.admin-table tr:hover td {
  background: #383838;
}

.admin-table .code-cell {
  font-family: 'Consolas', 'Courier New', monospace;
  font-weight: 600;
  color: #fff;
}

.admin-table tr.used-up td {
  opacity: 0.45;
}

.admin-table .op-cell {
  text-align: right;
}

.admin-table .op-cell button {
  border: 1px solid #666;
  background: #3a3a3a;
  color: #ddd;
  border-radius: 4px;
  padding: 4px 8px;
  margin-left: 4px;
  cursor: pointer;
  font-size: 12px;
}

.admin-table .op-cell button:hover {
  background: #4a4a4a;
}

.admin-table .op-cell .danger {
  border-color: #c62828;
  color: #ef5350;
}

.admin-table .empty-row {
  text-align: center;
  padding: 24px;
  color: #888;
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #ddd;
}

.admin-form-label {
  font-weight: 600;
}

.admin-form input,
.admin-form select {
  padding: 8px 10px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #1f1f1f;
  color: #fff;
  font-size: 14px;
}

.admin-form input:focus,
.admin-form select:focus {
  outline: none;
  border-color: #4caf50;
}

.code-input-row {
  display: flex;
  gap: 6px;
}

.code-input-row input {
  flex: 1;
  font-family: 'Consolas', 'Courier New', monospace;
}

/* 簡易トースト */
.app-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f1f1f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  z-index: 99999;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  border: 1px solid #555;
}

.app-toast[hidden] { display: none; }

/* =========================================================
   TABLET / SMALL DESKTOP
   ========================================================= */
@media (max-width: 1100px) {
  .right-panel { width: 240px; }
}

/* =========================================================
   MOBILE / iPad PORTRAIT (横幅 900px 以下)
   ========================================================= */
@media (max-width: 900px) {
  header { gap: 0; }
  .header-row { padding: 5px 8px; gap: 6px; }
  .header-row-top { padding-bottom: 4px; }
  .header-row-bottom { padding-top: 4px; padding-bottom: 5px; }
  .title { font-size: 13px; }

  /* スマホ：デスクトップ専用要素は隠す、モバイル専用要素を表示 */
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex; }

  /* 下段ボタンは小さめラベルを表示。data-short があれば短縮版に置換 */
  .header-row-bottom .btn { padding: 6px 8px; min-width: 0; justify-content: center; gap: 3px; font-size: 12px; }
  .header-row-bottom .btn .btn-icon { font-size: 14px; }
  .header-row-bottom .btn-label { font-size: 12px; }
  .header-row-bottom .btn-label[data-short] { font-size: 0; }
  .header-row-bottom .btn-label[data-short]::before {
    content: attr(data-short);
    font-size: 12px;
  }
  /* アイコンonlyボタン(⋯)はラベルなし */
  .header-row-bottom .btn.icon { padding: 6px 9px; min-width: 32px; }

  .project-select { font-size: 13px; }
  .project-bar { max-width: none; padding: 3px 6px; }

  .tab { padding: 8px 12px; font-size: 13px; min-height: 36px; }
  .tab.active { padding-bottom: 6px; }
  .tab-add { padding: 8px 12px; min-height: 36px; font-size: 13px; }

  /* フローティングズームを小さく */
  .zoom-controls.floating {
    bottom: 8px;
    right: 8px;
  }
  .zoom-controls .zoom-level { min-width: 44px; font-size: 11px; }
  .zoom-controls .btn.small { padding: 4px 7px; min-height: 26px; }

  main { flex-direction: column; }
  .toolbar {
    width: 100%;
    flex-direction: row;
    padding: 6px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid #444;
    align-items: stretch;
    flex-shrink: 0;
  }
  /* PC/SP切替：スマホでは PC専用を隠す */
  .toolbar-pc-only { display: none; }
  .toolbar-sp-only { display: flex; }

  /* セクションは内容幅にフィット */
  .section { flex-shrink: 0; min-width: 0; width: auto; padding: 0; }
  .section-label { font-size: 10px; }

  /* 緊急度は横並びにして詰める */
  .rank-list { flex-direction: row; gap: 4px; }
  .rank-btn {
    padding: 6px 8px;
    font-size: 12px;
    min-height: 40px;
    gap: 4px;
  }
  .rank-btn .rank-badge { width: 20px; height: 20px; font-size: 10px; }
  .rank-btn .label { display: none; } /* A/B/C のバッジだけで十分 */

  /* select 系は内容幅にフィット */
  .tile-select {
    padding: 8px 26px 8px 10px;
    font-size: 13px;
    min-height: 40px;
    width: auto;
    min-width: 90px;
  }

  /* stepper は数値入力分の幅を確保 */
  .stepper { padding: 6px 8px; flex-shrink: 0; min-width: 180px; }
  .stepper-label { font-size: 11px; margin-bottom: 2px; }
  .step-btn { width: 40px; height: 40px; font-size: 20px; }
  .step-input { height: 40px; font-size: 16px; min-width: 50px; }
  .step-unit-select { height: 40px; font-size: 13px; min-width: 56px; }
  .hint { display: none; }

  /* 集計パネルはオーバーレイ */
  .right-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 88%;
    max-width: 360px;
    z-index: 80;
    box-shadow: -4px 0 16px rgba(0,0,0,0.5);
  }
  .right-panel.collapsed {
    width: 88%;
    max-width: 360px;
    transform: translateX(100%);
    box-shadow: none;
  }

  .right-panel-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 70;
  }
  .right-panel-backdrop[hidden] { display: none; }

  /* 編集モーダルはボトムシート風 */
  .modal { padding: 0; align-items: flex-end; }
  .modal-box {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .modal-box-narrow { max-width: 100%; }
}

/* =========================================================
   VERY NARROW (スマホ縦・iPhone)
   ========================================================= */
@media (max-width: 560px) {
  .header-row { padding: 6px 8px; }
  .header-row-top { gap: 6px; }
  .title {
    /* 縦長スマホではタイトルを隠してスペース節約 */
    font-size: 0;
    padding: 0;
  }
  .title::before {
    content: "🔨";
    font-size: 18px;
  }

  .project-bar { padding: 3px 6px; gap: 4px; }
  .project-label { display: none; }
  .save-status { font-size: 10px; padding: 3px 6px; }

  .header-row-bottom {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .header-row-bottom::-webkit-scrollbar { display: none; }
  .header-row-bottom .btn { flex-shrink: 0; }

  /* スマホ時、その他アクションメニューは横スクロール領域に
     クリッピングされないよう画面右上に固定表示する */
  .mobile-action-menu {
    position: fixed;
    top: auto;
    right: 8px;
    margin-top: 0;
    z-index: 200;
    min-width: 200px;
  }

  .toolbar { padding: 4px; gap: 5px; }
  .section { min-width: 0; }
  .stepper { min-width: 170px; padding: 5px 7px; }
  .tile-select { min-width: 80px; }
  .step-input { min-width: 44px; }
  .step-unit-select { min-width: 52px; }
}

/* =========================================================
   LANDSCAPE （スマホ横）
   ========================================================= */
@media (max-height: 500px) and (orientation: landscape) {
  .header-row { padding: 4px 10px; }
  .toolbar { padding: 6px; }
  .hint { display: none; }
}
