:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --border: #d6dee8;
  --text: #17212b;
  --muted: #4f6275;
  --accent: #0f6cbd;
  --accent-soft: #e7f1fb;
  --danger: #b42318;
  --ok: #0f5630;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, sans-serif;
}

.viewer-app {
  min-height: 100vh;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.2rem 0.8rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.saved-view-toolbar {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.2rem 0.35rem;
  border: 1px solid #d6e1ec;
  border-radius: 0.45rem;
  background: #f8fbff;
}

.saved-view-toolbar label {
  font-size: 0.76rem;
  font-weight: 600;
  color: #2b4965;
  white-space: nowrap;
}

.saved-view-toolbar select {
  min-width: 12rem;
  height: 1.9rem;
  border: 1px solid #b7c9dd;
  border-radius: 0.35rem;
  padding: 0 0.4rem;
  color: #1f3f5c;
  background: #fff;
  font-size: 0.78rem;
}

.saved-view-toolbar .action-button {
  height: 1.9rem;
  padding: 0.22rem 0.6rem;
}

.header-main h1 {
  margin: 0 0 0.25rem;
  font-size: 1.2rem;
}

.header-main p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status {
  min-height: 1.2rem;
  max-width: 44ch;
  color: var(--ok);
  font-size: 0.9rem;
  text-align: right;
  margin-left: auto;
}

.status.error {
  color: var(--danger);
}

.nav-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 0.45rem;
  background: #fff;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
  padding: 0.4rem 0.7rem;
}

.nav-link-button:hover {
  background: #eef5fd;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(500px, 1.55fr) minmax(320px, 0.95fr) minmax(280px, 0.72fr);
  padding: 1rem;
}

.manage-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(280px, 1fr));
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  overflow: hidden;
  min-height: 420px;
}

.panel h2 {
  margin: 0;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  background: #f9fbfd;
  border-bottom: 1px solid #e7edf3;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.panel-title-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.mesh-opacity-control {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid #d2dfed;
  border-radius: 0.4rem;
  background: #ffffff;
  padding: 0.16rem 0.45rem;
}

.mesh-opacity-control label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #2a4866;
  white-space: nowrap;
}

.mesh-opacity-control input[type="range"] {
  width: 7rem;
  accent-color: #0f6cbd;
}

.mesh-opacity-control output {
  min-width: 2.4rem;
  text-align: right;
  font-size: 0.72rem;
  color: #264361;
  font-variant-numeric: tabular-nums;
}

.panel-title-button {
  border: 1px solid #a9bfd6;
  border-radius: 0.35rem;
  background: #ffffff;
  color: #24415f;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
}

.panel-title-button:hover {
  background: #eef5fd;
}

.panel-title-button.is-active {
  border-color: #0f6cbd;
  background: #deefff;
  color: #0d3f6e;
}

.panel-title-button:disabled {
  border-color: #ccd8e5;
  background: #f1f5f9;
  color: #7d8ea0;
  cursor: wait;
}

.viewport-panel {
  display: flex;
  flex-direction: column;
}

.panel-inner {
  padding: 0.75rem;
  max-height: calc(72vh + 140px);
  overflow: auto;
}

.tree-panel .panel-inner {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  height: calc(72vh + 140px);
  max-height: none;
  overflow: hidden;
}

.tree-panel .tool-block {
  margin-top: 0;
}

.tree-panel .tool-block + .tool-block {
  margin-top: 0;
}

.tree-panel .tool-block:last-child {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tool-block + .tool-block {
  margin-top: 0.9rem;
}

.tool-block h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: #28425e;
}

.tree-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.tree-tab {
  border: 1px solid #b7c9dd;
  border-radius: 0.35rem;
  background: #f7fbff;
  color: #28425e;
  font-size: 0.82rem;
  padding: 0.26rem 0.55rem;
  cursor: pointer;
}

.tree-tab:hover {
  background: #eef5fd;
}

.tree-tab.is-active {
  border-color: #0f6cbd;
  background: #dfefff;
  color: #0d3f6e;
  font-weight: 600;
}

.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  height: auto;
}

.cross-section-panel {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-height: 120px;
  border-top: 1px solid #d8e3ee;
  background: #fdfefe;
}

.cross-section-panel[hidden] {
  display: none !important;
}

.cross-section-resize-handle {
  height: 9px;
  cursor: row-resize;
  background:
    linear-gradient(
      to bottom,
      rgba(172, 191, 210, 0.36) 0,
      rgba(172, 191, 210, 0.36) 1px,
      transparent 1px,
      transparent 8px
    );
  position: relative;
  touch-action: none;
}

.cross-section-resize-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 3px;
  width: 62px;
  height: 3px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #adc1d5;
}

.cross-section-resize-handle.is-dragging::after {
  background: #0f6cbd;
}

.cross-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.7rem;
  padding: 0.48rem 0.65rem;
  border-bottom: 1px solid #e0e9f2;
  background: #f4f9ff;
}

.cross-section-header > div:first-child {
  flex: 1 1 220px;
  min-width: 0;
}

.cross-section-title {
  margin: 0;
  font-size: 0.84rem;
  color: #1d3e5d;
}

.cross-section-subtitle {
  margin: 0.16rem 0 0;
  color: #4a647d;
  font-size: 0.73rem;
}

.cross-section-station-row {
  margin-top: 0.28rem;
  display: grid;
  grid-template-columns: auto minmax(132px, 190px) minmax(140px, 1fr);
  align-items: center;
  gap: 0.32rem;
}

.cross-section-station-row label {
  color: #35526b;
  font-size: 0.72rem;
  white-space: nowrap;
}

.cross-section-station-input-group {
  display: grid;
  grid-template-columns: auto minmax(72px, 1fr) auto;
  gap: 0.24rem;
  align-items: center;
  min-width: 0;
}

.cross-section-station-input-group input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 1.58rem;
  border: 1px solid #b9cadb;
  border-radius: 0.32rem;
  padding: 0 0.36rem;
  background: #ffffff;
  color: #1e3f5a;
  font-size: 0.76rem;
}

.cross-section-station-step-button {
  width: 1.58rem;
  min-width: 1.58rem;
  height: 1.58rem;
  border: 1px solid #b2c5d8;
  border-radius: 0.32rem;
  background: #ffffff;
  color: #264966;
  font-size: 0.86rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.cross-section-station-step-button:hover:not(:disabled) {
  background: #edf4fc;
}

.cross-section-station-row input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: #0f6cbd;
}

.cross-section-station-row input:disabled,
.cross-section-station-step-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.cross-section-measure-row {
  margin-top: 0.3rem;
  display: grid;
  grid-template-columns: auto minmax(136px, 1fr) auto;
  align-items: center;
  gap: 0.32rem;
}

.cross-section-measure-row label {
  color: #35526b;
  font-size: 0.72rem;
  white-space: nowrap;
}

.cross-section-measure-row select,
.cross-section-measure-row button {
  height: 1.58rem;
  border: 1px solid #b9cadb;
  border-radius: 0.32rem;
  background: #ffffff;
  color: #1e3f5a;
  font-size: 0.74rem;
}

.cross-section-measure-row select {
  width: 100%;
  min-width: 0;
  padding: 0 0.34rem;
}

.cross-section-measure-row button {
  min-width: 3.15rem;
  padding: 0 0.5rem;
  cursor: pointer;
}

.cross-section-measure-row button:hover:not(:disabled) {
  background: #edf4fc;
}

.cross-section-measure-row select:disabled,
.cross-section-measure-row button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.cross-section-measure-result {
  margin: 0.24rem 0 0;
  color: #38556f;
  font-size: 0.72rem;
}

.cross-section-measure-result.is-error {
  color: #c2362b;
}

.cross-section-controls {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.32rem;
  max-width: 100%;
}

.cross-section-controls button {
  min-width: 1.95rem;
  height: 1.95rem;
  border: 1px solid #b2c5d8;
  border-radius: 0.34rem;
  background: #ffffff;
  color: #264966;
  font-size: 0.8rem;
  cursor: pointer;
  flex: 0 0 auto;
}

.cross-section-controls button:hover {
  background: #edf4fc;
}

.cross-section-close {
  font-size: 0.96rem !important;
  font-weight: 700;
}

.cross-section-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #ffffff;
}

.cross-section-grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.cross-section-meter-labels {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4.25rem;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.35), transparent);
}

.cross-section-meter-label {
  position: absolute;
  left: 0.3rem;
  transform: translateY(-50%);
  color: #6a7b8d;
  font-size: 0.67rem;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 0 2px rgba(255, 255, 255, 0.88);
}

.cross-section-empty {
  margin: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #5c7186;
  font-size: 0.82rem;
  pointer-events: none;
  z-index: 2;
}

.volume-panel {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  border-top: 1px solid #d8e3ee;
  background: #fdfefe;
}

.volume-panel[hidden] {
  display: none !important;
}

.volume-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.48rem 0.65rem;
  border-bottom: 1px solid #e0e9f2;
  background: #f4f9ff;
}

.volume-title {
  margin: 0;
  font-size: 0.84rem;
  color: #1d3e5d;
}

.volume-subtitle {
  margin: 0.16rem 0 0;
  color: #4a647d;
  font-size: 0.73rem;
}

.volume-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
}

.volume-controls button {
  min-width: 1.95rem;
  height: 1.95rem;
  border: 1px solid #b2c5d8;
  border-radius: 0.34rem;
  background: #ffffff;
  color: #264966;
  font-size: 0.9rem;
  cursor: pointer;
}

.volume-controls button:hover {
  background: #edf4fc;
}

.volume-close {
  font-weight: 700;
}

.volume-content {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
  padding: 0.5rem 0.62rem 0.62rem;
  background: #fbfdff;
}

.volume-grid-row,
.volume-select-row,
.volume-boundary-row,
.volume-station-range-row {
  display: grid;
  align-items: center;
  gap: 0.34rem;
}

.volume-grid-row {
  grid-template-columns: auto minmax(80px, 120px) auto;
}

.volume-select-row {
  grid-template-columns: auto minmax(140px, 1fr) auto auto;
}

.volume-boundary-row {
  grid-template-columns: auto minmax(150px, 1fr);
}

.volume-station-range-row {
  grid-template-columns: auto minmax(74px, 1fr) auto minmax(74px, 1fr);
}

.volume-content label {
  color: #35526b;
  font-size: 0.72rem;
  white-space: nowrap;
}

.volume-content input[type="number"],
.volume-content select,
.volume-content button {
  height: 1.58rem;
  border: 1px solid #b9cadb;
  border-radius: 0.32rem;
  background: #ffffff;
  color: #1e3f5a;
  font-size: 0.74rem;
}

.volume-content input[type="number"],
.volume-content select {
  width: 100%;
  min-width: 0;
  padding: 0 0.34rem;
}

.volume-content button {
  min-width: 3.15rem;
  padding: 0 0.5rem;
  cursor: pointer;
}

.volume-content button:hover:not(:disabled) {
  background: #edf4fc;
}

.volume-content button.is-active {
  border-color: #0f6cbd;
  background: #deefff;
  color: #0d3f6e;
  font-weight: 600;
}

.volume-content button:disabled,
.volume-content input:disabled,
.volume-content select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.volume-selected-label {
  display: inline-block;
  min-height: 1.58rem;
  line-height: 1.58rem;
  border: 1px solid #d3dfec;
  border-radius: 0.32rem;
  background: #ffffff;
  color: #274763;
  font-size: 0.72rem;
  padding: 0 0.4rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.volume-boundary-block {
  border: 1px solid #d9e5f1;
  border-radius: 0.38rem;
  background: #ffffff;
  padding: 0.42rem;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}

.volume-boundary-block[hidden] {
  display: none !important;
}

.volume-polygon-hint {
  margin: 0;
  color: #3f5d79;
  font-size: 0.72rem;
}

.volume-polygon-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.32rem;
}

.volume-results {
  border: 1px solid #d9e5f1;
  border-radius: 0.38rem;
  background: #ffffff;
  padding: 0.44rem 0.46rem;
}

.volume-result-summary {
  margin: 0;
  color: #38556f;
  font-size: 0.72rem;
}

.volume-result-summary.is-error {
  color: #c2362b;
}

.volume-result-grid {
  margin-top: 0.34rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  gap: 0.26rem 0.5rem;
  color: #294865;
  font-size: 0.72rem;
}

.volume-result-grid strong {
  font-variant-numeric: tabular-nums;
}

body.is-cross-section-resizing,
body.is-cross-section-resizing * {
  cursor: row-resize !important;
  user-select: none !important;
}

.map-attribution {
  position: absolute;
  right: 0.55rem;
  bottom: 0.45rem;
  z-index: 2;
  padding: 0.18rem 0.4rem;
  border-radius: 0.3rem;
  background: rgba(255, 255, 255, 0.86);
  color: #37546d;
  font-size: 0.72rem;
  line-height: 1.2;
  pointer-events: none;
  display: none;
}

.transform-debug-panel {
  position: absolute;
  left: 0.55rem;
  top: 0.55rem;
  z-index: 3;
  min-width: 360px;
  max-width: min(92%, 520px);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #b8c8d8;
  border-radius: 0.45rem;
  padding: 0.45rem 0.5rem 0.4rem;
  box-shadow: 0 4px 10px rgba(20, 38, 56, 0.12);
}

.transform-debug-panel h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: #1c3d5a;
}

.transform-debug-controls {
  display: grid;
  grid-template-columns: auto minmax(170px, 1fr) auto auto;
  gap: 0.3rem;
  align-items: center;
}

.transform-debug-controls select,
.transform-debug-controls button {
  height: 1.9rem;
  border: 1px solid #b8c8d8;
  border-radius: 0.32rem;
  background: #fff;
  color: #17314a;
  font-size: 0.78rem;
}

.transform-debug-controls select {
  padding: 0 0.35rem;
}

.transform-debug-controls button {
  padding: 0 0.45rem;
  cursor: pointer;
}

.transform-debug-controls button:hover:not(:disabled) {
  background: #eff5fb;
}

.transform-debug-controls button:disabled,
.transform-debug-controls select:disabled {
  opacity: 0.7;
  cursor: wait;
}

.transform-debug-state {
  margin: 0.32rem 0 0;
  font-size: 0.74rem;
  color: #2d4d69;
  line-height: 1.25;
}

.pick-list-popup {
  position: absolute;
  left: 0.7rem;
  top: 0.7rem;
  z-index: 4;
  width: min(460px, calc(100% - 1.4rem));
  max-height: min(300px, calc(100% - 1.4rem));
  display: flex;
  flex-direction: column;
  border: 1px solid #b7c9dd;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 8px 22px rgba(16, 34, 51, 0.18);
  overflow: hidden;
}

.pick-list-popup[hidden] {
  display: none !important;
}

.pick-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid #dbe6f1;
  background: #f7fbff;
}

.pick-list-header h3 {
  margin: 0;
  font-size: 0.86rem;
  color: #1d3e5c;
}

.pick-list-close {
  width: 1.7rem;
  height: 1.7rem;
  border: 1px solid #b9c9da;
  border-radius: 0.36rem;
  background: #fff;
  color: #2b4a67;
  font-size: 0.82rem;
  cursor: pointer;
}

.pick-list-close:hover {
  background: #eff5fb;
}

.pick-list-tabs {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.42rem 0.5rem 0;
}

.pick-list-tab {
  border: 1px solid #b8cadb;
  border-radius: 0.34rem;
  background: #fff;
  color: #2c4b66;
  font-size: 0.78rem;
  padding: 0.24rem 0.5rem;
  cursor: pointer;
}

.pick-list-tab:hover {
  background: #eef5fc;
}

.pick-list-tab.is-active {
  border-color: #0f6cbd;
  background: #deefff;
  color: #11436f;
  font-weight: 600;
}

.pick-list-summary {
  margin: 0;
  padding: 0.34rem 0.58rem 0.42rem;
  color: #4a637a;
  font-size: 0.75rem;
  border-bottom: 1px solid #edf3f8;
}

.pick-list-content {
  padding: 0.45rem 0.5rem 0.55rem;
  overflow: auto;
  min-height: 120px;
}

.pick-tree-root {
  max-height: none;
}

.pick-object-item {
  width: 100%;
  border: 1px solid #d6e1eb;
  border-radius: 0.32rem;
  background: #fff;
  color: #26445f;
  font-size: 0.78rem;
  text-align: left;
  padding: 0.2rem 0.38rem;
  cursor: pointer;
}

.pick-object-item:hover {
  border-color: #abc5de;
  background: #eef5fd;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stack-form input[type="text"],
.stack-form input[type="number"],
.stack-form select,
.stack-form input[type="file"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  padding: 0.45rem 0.55rem;
  background: #fff;
  color: var(--text);
}

.stack-form button {
  border: 1px solid var(--accent);
  border-radius: 0.45rem;
  background: var(--accent);
  color: #fff;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
}

.stack-form button:hover {
  filter: brightness(1.08);
}

.panel-divider {
  border: 0;
  border-top: 1px solid #e2eaf2;
  margin: 0.85rem 0 0.75rem;
}

.panel-subtitle {
  margin: 0 0 0.55rem;
  font-size: 0.9rem;
  color: #2c4660;
}

.file-label,
.check-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
  color: #314257;
}

.model-list-items {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.model-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 0.55rem;
}

.operation-log {
  margin-top: 0.6rem;
  border-top: 1px solid #e3eaf2;
  padding-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-height: 1.2rem;
}

.operation-log-item {
  margin: 0;
  font-size: 0.78rem;
  color: #36506a;
}

.operation-log-item.error {
  color: #b42318;
}

.model-row {
  border: 1px solid #d9e2ec;
  background: #fff;
  border-radius: 0.45rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.45rem 0.55rem;
  cursor: pointer;
  text-align: left;
}

.model-row-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.model-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.model-row.active {
  border-color: #0f6cbd;
  background: #eef5fd;
}

.project-row {
  cursor: default;
}

.project-actions {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.project-manage-layout {
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.15fr);
}

.launcher-layout {
  max-width: 980px;
  margin: 0 auto;
  padding: 1rem;
}

.danger-button {
  border: 1px solid #b42318;
  border-radius: 0.35rem;
  background: #fff5f4;
  color: #b42318;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.danger-button:hover {
  background: #ffe6e3;
}

.action-button {
  border: 1px solid #0f6cbd;
  border-radius: 0.35rem;
  background: #eef5fd;
  color: #0f6cbd;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.action-button:hover {
  background: #dfebf8;
}

.action-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.tree-root {
  max-height: 32vh;
  overflow: auto;
}

.tree-panel .tree-root {
  flex: 1;
  min-height: 0;
  max-height: none;
}

.tree-root ul {
  list-style: none;
  margin: 0;
  padding-left: 1rem;
  border-left: 1px dashed #cad3de;
}

.tree-root li {
  margin: 0.22rem 0;
}

.tree-root details > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.tree-root details > summary::-webkit-details-marker {
  display: none;
}

.tree-root details > summary::marker {
  content: "";
}

.tree-root details > summary::before {
  content: "\25B8";
  color: #6a7f95;
  font-size: 0.72rem;
  width: 0.7rem;
  flex: 0 0 0.7rem;
  text-align: center;
  line-height: 1;
}

.tree-root details[open] > summary::before {
  content: "\25BE";
}

.tree-root details.leaf-node > summary::before {
  content: "\00B7";
  font-size: 0.9rem;
  color: #a2b1c1;
}

.node-row {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex: 1;
}

.visibility-toggle {
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #a7b8cc;
  background: #f4f8fc;
  color: #1f4c75;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.visibility-toggle[data-state="on"] {
  border-color: #75ab75;
  background: #ebf9eb;
  color: #235623;
}

.visibility-toggle[data-state="off"] {
  border-color: #c6d0dd;
  background: #f4f7fb;
  color: #7d8da3;
}

.visibility-toggle[data-state="mixed"] {
  border-color: #dab875;
  background: #fff4dd;
  color: #825f1a;
}

.visibility-toggle:focus-visible {
  outline: 2px solid #0f6cbd;
  outline-offset: 1px;
}

.fit-object-toggle {
  height: 1.35rem;
  min-width: 2.2rem;
  padding: 0 0.42rem;
  border-radius: 0.38rem;
  border: 1px solid #9eb5cd;
  background: #eef5fc;
  color: #1b4a74;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 600;
  cursor: pointer;
}

.fit-object-toggle:hover {
  background: #dce9f6;
  border-color: #86a8c8;
}

.fit-object-toggle:focus-visible {
  outline: 2px solid #0f6cbd;
  outline-offset: 1px;
}

.node-label {
  display: inline-block;
  min-width: 0;
  flex: 1;
  border-radius: 0.3rem;
  padding: 0.12rem 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-label.object {
  background: var(--accent-soft);
  color: #0b3d67;
}

.node-label.object.is-hidden {
  opacity: 0.6;
}

.node-label.object.is-mixed {
  box-shadow: inset 0 0 0 1px #d9b776;
}

.node-label.object.selected {
  background: #0b3d67;
  color: #fff;
}

.details-root {
  padding: 0.75rem;
  max-height: calc(72vh + 140px);
  overflow: auto;
}

.detail-section + .detail-section {
  margin-top: 0.75rem;
}

.detail-section h3 {
  margin: 0 0 0.35rem;
  font-size: 0.94rem;
  color: #28425e;
}

.detail-section h4 {
  margin: 0.45rem 0 0.25rem;
  font-size: 0.86rem;
  color: #365471;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.muted.error {
  color: #b91c1c;
  font-weight: 600;
}

.empty-note {
  margin: 0;
  color: var(--muted);
}

.kv-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #e4eaf1;
  background: #fff;
  font-size: 0.9rem;
}

.kv-table th,
.kv-table td {
  border-bottom: 1px solid #e4eaf1;
  padding: 0.35rem 0.45rem;
  text-align: left;
  vertical-align: top;
}

.kv-table thead th {
  background: #eef3f8;
  color: #24415f;
  font-size: 0.82rem;
}

.kv-table tbody th {
  width: 36%;
  background: #fafcff;
  color: #1d3d59;
}

.kv-table tbody tr:last-child th,
.kv-table tbody tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
}

.empty {
  max-width: 720px;
  margin: 10vh auto;
  padding: 0 20px;
  text-align: center;
}

@media (min-width: 981px) {
  .viewer-page-app {
    height: 100dvh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .viewer-page-app .layout {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
  }

  .viewer-page-app .layout > .panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .viewer-page-app .layout > .panel > h2 {
    flex: 0 0 auto;
  }

  .viewer-page-app .viewport {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .viewer-page-app .tree-panel .panel-inner {
    flex: 1;
    min-height: 0;
    height: auto;
    max-height: none;
  }

  .viewer-page-app .tree-root,
  .viewer-page-app .details-root {
    max-height: none;
  }

  .viewer-page-app .details-root {
    flex: 1;
    min-height: 0;
  }
}

@media (max-width: 1380px) {
  .layout {
    grid-template-columns: minmax(420px, 1.25fr) minmax(280px, 0.9fr);
  }

  .details-panel {
    grid-column: 1 / -1;
  }

  .manage-layout {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
  }
}

@media (max-width: 980px) {
  .viewer-page-app .panel {
    min-height: 0;
  }

  .viewport-panel .panel-title-row {
    flex-wrap: wrap;
    row-gap: 0.45rem;
  }

  .viewport-panel .panel-title-actions {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .mesh-opacity-control {
    padding: 0.14rem 0.4rem;
  }

  .mesh-opacity-control input[type="range"] {
    width: 5.4rem;
  }

  .app-header {
    flex-direction: column;
    align-items: stretch;
  }

  .status {
    text-align: left;
    margin-left: 0;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .saved-view-toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .saved-view-toolbar select {
    min-width: 0;
    flex: 1 1 180px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .manage-layout {
    grid-template-columns: 1fr;
  }

  .project-manage-layout {
    grid-template-columns: 1fr;
  }

  .viewer-page-app .viewport {
    flex: 0 0 auto;
    height: min(44dvh, 360px);
    min-height: 210px;
  }

  .cross-section-panel {
    min-height: 120px;
  }

  .cross-section-viewport {
    min-height: 120px;
  }

  .cross-section-controls button {
    min-width: 1.75rem;
    height: 1.75rem;
    font-size: 0.74rem;
    padding: 0 0.4rem;
  }

  .cross-section-station-row {
    grid-template-columns: auto minmax(114px, 154px) minmax(110px, 1fr);
  }

  .cross-section-measure-row {
    grid-template-columns: auto minmax(110px, 1fr) auto;
  }

  .volume-grid-row {
    grid-template-columns: auto minmax(74px, 96px) auto;
  }

  .volume-select-row {
    grid-template-columns: auto minmax(110px, 1fr) auto auto;
  }

  .volume-boundary-row {
    grid-template-columns: auto minmax(130px, 1fr);
  }

  .volume-station-range-row {
    grid-template-columns: auto minmax(70px, 1fr) auto minmax(70px, 1fr);
  }

  .volume-result-grid {
    grid-template-columns: 1fr;
  }

  .transform-debug-panel {
    min-width: 0;
    max-width: calc(100% - 1.1rem);
  }

  .transform-debug-controls {
    grid-template-columns: auto 1fr auto;
  }

  .transform-debug-controls button:last-child {
    grid-column: 1 / -1;
  }

  .panel-inner,
  .details-root,
  .tree-root {
    max-height: none;
  }

  .tree-panel .panel-inner {
    height: auto;
    overflow: visible;
  }

  .tree-panel .tool-block:last-child {
    flex: none;
  }
}

@media (max-width: 980px) and (orientation: portrait) {
  .viewer-page-app .viewport {
    height: clamp(182px, 58.5vw, 286px);
    min-height: 0;
  }
}
