/* cutlist viewer — mobile-first, lightweight, no textures. */

:root {
  --bar-bg: rgba(17, 20, 24, 0.92);
  --bar-fg: #fff;
  --panel-bg: rgba(255, 255, 255, 0.97);
  --panel-fg: #111;
  --accent: #0b5fff;
  --border: #c9c9c9;
}

* {
  box-sizing: border-box;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Crosshair on canvas while measuring. */
body.measuring #view {
  cursor: crosshair;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", sans-serif;
  color: var(--panel-fg);
  background: #202428;
}

/* Full-screen canvas. */
#view {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  display: block;
  touch-action: none;
}

/* Top bar. */
#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding:
    calc(8px + env(safe-area-inset-top)) 12px 8px
    calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  background: var(--bar-bg);
  color: var(--bar-fg);
  z-index: 10;
}

#title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

#global-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#global-actions button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  font-size: 14px;
  line-height: 1.2;
  color: var(--bar-fg);
  background: #2c333b;
  border: 1px solid #555;
  border-radius: 8px;
  cursor: pointer;
}

#global-actions button:active {
  background: #3d4650;
}

#global-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (hover: hover) {
  #global-actions button:not(:disabled):hover {
    background: #3d4650;
  }
  #global-actions button.active:not(:disabled):hover {
    background: #0a52d6;
  }
  #info-close:hover {
    background: #0a52d6;
  }
  .info-btn:hover {
    background: #eef3ff;
  }
  #parts li:hover {
    background: #eef3ff;
  }
}

/* Parts panel: bottom sheet on narrow screens. */
#panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-bg);
  color: var(--panel-fg);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
  z-index: 10;
}

#panel-heading {
  margin: 4px 0 8px;
  font-size: 14px;
  font-weight: 700;
}

#parts {
  list-style: none;
  margin: 0;
  padding: 0;
}

#parts li {
  margin: 0;
  padding: 0;
}

#parts label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 4px 0;
  font-size: 16px;
  cursor: pointer;
}

#parts input[type="checkbox"] {
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Wide screens: right dock. */
@media (min-width: 768px) {
  #topbar {
    right: 320px; /* ドックと重ならないようバーはドック左で終わる */
  }
  #panel {
    left: auto;
    top: 0;
    bottom: 0;
    width: 320px;
    max-height: none;
    border-top: none;
    border-left: 1px solid var(--border);
    padding-top: calc(76px + env(safe-area-inset-top));
  }
  #parts li:hover {
    background: #eef3ff;
  }
  .info-btn {
    font-size: 20px;
  }
}

/* Loading / error overlay. */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(17, 20, 24, 0.72);
  color: #fff;
  font-size: 16px;
  text-align: center;
  z-index: 20;
}

#overlay[hidden] {
  display: none;
}

#overlay.error {
  background: rgba(120, 20, 20, 0.92);
}

#overlay-text {
  margin: 0;
  max-width: 32em;
  line-height: 1.7;
  white-space: pre-line;
}

/* Measure mode. */
#global-actions button.active,
#btn-measure[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#measure-result {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(40vh + 12px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 24px);
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  color: #111;
  background: rgba(255, 193, 7, 0.97);
  border: 1px solid #a97f00;
  border-radius: 8px;
  z-index: 15;
}

#measure-result[hidden] {
  display: none;
}

@media (min-width: 768px) {
  #measure-result {
    bottom: 24px;
    left: calc((100vw - 320px) / 2);
  }
}

/* Empty-state banner: non-blocking, bottom-center. */
#empty-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(40vh + 64px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 24px);
  padding: 10px 12px 10px 16px;
  font-size: 14px;
  color: #fff;
  background: rgba(17, 20, 24, 0.92);
  border: 1px solid #555;
  border-radius: 8px;
  z-index: 16;
}

#empty-banner[hidden] {
  display: none;
}

#empty-banner button {
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  font-size: 14px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
}

@media (hover: hover) {
  #empty-banner button:hover {
    background: #0a52d6;
  }
}

@media (min-width: 768px) {
  #empty-banner {
    left: calc((100vw - 320px) / 2);
    bottom: 76px;
  }
}

/* Per-row info buttons. */
#parts li {
  display: flex;
  align-items: center;
  gap: 8px;
}

#parts li label {
  flex: 1;
}

.info-btn {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  line-height: 1;
  color: var(--panel-fg);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

/* Info popup / drawer. */
#info {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--panel-bg);
  color: var(--panel-fg);
  border-top: 1px solid var(--border);
  z-index: 18;
}

#info[hidden] {
  display: none;
}

#info-title {
  margin: 4px 0 8px;
  font-size: 16px;
  font-weight: 700;
}

#info-text {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

#info-close {
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  font-size: 14px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
}

@media (min-width: 768px) {
  #info {
    left: auto;
    right: 332px; /* ドックの左に表示 */
    top: 76px;
    bottom: auto;
    width: 320px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-right: 0;
  }
}
