/* ==========================================================================
   AtmoLab Layout & Minimalist UI Components (Desktop-First 3-Column Lab)
   Left: Component Palette | Center: 2D Cross-Section Canvas | Right: Inspector
   ========================================================================== */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--p-font-sans);
  font-size: var(--p-text-base);
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ---------- App Shell ---------- */
.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  width: 100vw;
  height: 100vh;
}

/* ---------- Top Toolbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--p-space-4);
  padding: 0 var(--p-space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 210px;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--p-radius-sm);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  display: grid;
  place-items: center;
  font-family: var(--p-font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.04em;
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--p-font-mono);
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: var(--p-space-4);
  flex: 1;
  justify-content: center;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--p-radius-sm);
  padding: 2px;
  gap: 2px;
}

.segmented-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--p-font-sans);
  font-size: var(--p-text-sm);
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.segmented-btn:hover {
  color: var(--text-primary);
}

.segmented-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--p-shadow-xs);
}

.segmented-btn.active[data-env="water"] {
  color: var(--accent-water);
}

.segmented-btn.active[data-env="air"] {
  color: var(--accent-air);
}

.quick-pressure {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--p-radius-sm);
}

.quick-pressure-label {
  font-size: var(--p-text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

.quick-pressure-value {
  font-family: var(--p-font-mono);
  font-size: var(--p-text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 70px;
  text-align: right;
  color: var(--text-primary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--p-space-2);
}

/* ---------- Buttons & Inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--p-font-sans);
  font-size: var(--p-text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform 80ms ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--p-neutral-400);
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--bg-inverse);
  border-color: var(--bg-inverse);
  color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
  background: var(--p-neutral-700);
  border-color: var(--p-neutral-700);
}

.btn-danger {
  color: var(--accent-heat);
  border-color: #fecdd3;
  background: var(--p-heat-50);
}

.btn-danger:hover:not(:disabled) {
  background: #ffe4e6;
  border-color: #fda4af;
}

.btn-active-accent {
  background: var(--p-air-50);
  border-color: #93c5fd;
  color: var(--accent-air);
}

.btn-active-heat {
  background: var(--p-heat-50);
  border-color: #fda4af;
  color: var(--accent-heat);
}

.btn-active-cool {
  background: var(--p-water-50);
  border-color: #7dd3fc;
  color: var(--accent-water);
}

.btn-sm {
  height: 28px;
  padding: 0 9px;
  font-size: var(--p-text-xs);
}

.btn-block {
  width: 100%;
}

/* Minimalist Range Slider */
input[type="range"].minimal-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--p-neutral-200);
  border-radius: var(--p-radius-full);
  outline: none;
  cursor: pointer;
}

input[type="range"].minimal-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-inverse);
  border: 2px solid var(--bg-surface);
  box-shadow: 0 0 0 1px var(--border-strong), var(--p-shadow-xs);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

input[type="range"].minimal-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"].minimal-slider.compact {
  width: 132px;
}

/* ---------- 3-Column Main Workspace Grid ---------- */
.workspace-grid {
  display: grid;
  grid-template-columns: var(--palette-width) 1fr var(--inspector-width);
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ---------- Side Panels Shared ---------- */
.side-panel {
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.side-panel-left {
  position: relative;
  border-right: 1px solid var(--border-subtle);
}

.side-panel-left.drag-delete-active::after {
  content: '放開以移除元件';
  position: absolute;
  inset: 10px;
  border: 2px dashed #f43f5e;
  border-radius: var(--p-radius-lg);
  background: rgba(255, 241, 242, 0.9);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  color: #be123c;
  pointer-events: none;
  z-index: 25;
}

.side-panel-right {
  border-left: 1px solid var(--border-subtle);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--p-space-4) 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-title {
  font-size: var(--p-text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--p-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--p-space-3);
}

.panel-scroll::-webkit-scrollbar {
  width: 6px;
}

.panel-scroll::-webkit-scrollbar-thumb {
  background: var(--p-neutral-200);
  border-radius: var(--p-radius-full);
}

/* ---------- Left Palette Cards ---------- */
.palette-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--p-radius-md);
  background: var(--bg-surface);
  cursor: grab;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.palette-card:hover {
  border-color: var(--p-neutral-400);
  box-shadow: var(--p-shadow-sm);
  transform: translateY(-1px);
}

.palette-card:active {
  cursor: grabbing;
}

.palette-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.palette-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--p-radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.palette-meta {
  flex: 1;
  min-width: 0;
}

.palette-name {
  font-size: var(--p-text-base);
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.palette-tag {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: var(--p-radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.palette-desc {
  font-size: var(--p-text-xs);
  color: var(--text-secondary);
  line-height: 1.45;
  margin-top: 2px;
}

.palette-add-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 6px;
  border-top: 1px dashed var(--border-subtle);
}

.palette-footer {
  margin-top: auto;
  padding: var(--p-space-3) var(--p-space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-app);
}

.tip-box {
  font-size: var(--p-text-xs);
  color: var(--text-secondary);
  line-height: 1.55;
}

.tip-box strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ---------- Center Workspace Canvas ---------- */
.canvas-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
}

.canvas-stage.drag-over::after {
  content: '放開以放置元件至 2D 剖面實驗區';
  position: absolute;
  inset: 14px;
  border: 2px dashed var(--p-neutral-400);
  border-radius: var(--p-radius-lg);
  background: rgba(255, 255, 255, 0.55);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 15;
}

#sim-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

/* Floating Minimalist HUD Chips inside Canvas */
.stage-hud-top {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

.hud-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: auto;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: var(--p-radius-full);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--p-shadow-xs);
  font-size: var(--p-text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

.hud-pill strong {
  font-family: var(--p-font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-primary);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Floating Live Physics Explanation Bar */
.stage-explainer {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--p-radius-md);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--p-shadow-sm);
  z-index: 10;
}

.explainer-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--p-radius-full);
  background: var(--bg-inverse);
  color: var(--text-inverse);
  white-space: nowrap;
}

.explainer-text {
  flex: 1;
  font-size: var(--p-text-sm);
  color: var(--text-primary);
  line-height: 1.45;
}

.empty-stage-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 20px 26px;
  border-radius: var(--p-radius-lg);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--p-shadow-sm);
  pointer-events: none;
  z-index: 5;
  max-width: 340px;
}

.empty-stage-hint h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
}

.empty-stage-hint p {
  font-size: var(--p-text-xs);
  color: var(--text-secondary);
  line-height: 1.55;
}

/* ---------- Right Inspector Panel ---------- */
.inspector-tabs {
  display: flex;
  gap: 4px;
}

.inspector-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.inspector-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.inspector-entity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inspector-entity-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.inspector-entity-sub {
  font-size: var(--p-text-xs);
  color: var(--text-secondary);
}

/* Metric Grid */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.metric-card {
  padding: 9px 10px;
  border-radius: var(--p-radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
}

.metric-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.metric-value {
  font-family: var(--p-font-mono);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.metric-unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 3px;
}

/* Pressure Balance Bar */
.pressure-compare {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: var(--p-radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
}

.pressure-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.pressure-bar-label {
  width: 48px;
  color: var(--text-secondary);
}

.pressure-bar-track {
  flex: 1;
  height: 7px;
  border-radius: var(--p-radius-full);
  background: var(--p-neutral-200);
  overflow: hidden;
}

.pressure-bar-fill {
  height: 100%;
  border-radius: var(--p-radius-full);
  transition: width 90ms linear;
}

.pressure-bar-fill.internal {
  background: var(--accent-internal);
}

.pressure-bar-fill.external {
  background: var(--accent-air);
}

.pressure-bar-fill.water {
  background: var(--accent-water);
}

.pressure-bar-num {
  width: 62px;
  text-align: right;
  font-family: var(--p-font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-primary);
}

/* Control Rows */
.control-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--p-text-xs);
}

.control-name {
  color: var(--text-primary);
  font-weight: 500;
}

.control-val {
  font-family: var(--p-font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.btn-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.btn-row.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
}

.toggle-label {
  font-size: var(--p-text-sm);
  color: var(--text-primary);
}

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

.toggle-switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: var(--p-radius-full);
  background: var(--p-neutral-300);
  transition: background var(--transition-fast);
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-surface);
  box-shadow: var(--p-shadow-xs);
  transition: transform var(--transition-fast);
}

.toggle-switch.on {
  background: var(--bg-inverse);
}

.toggle-switch.on::after {
  transform: translateX(14px);
}

/* Step Guide (e.g. Aluminum Can Experiment) */
.step-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.step-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: var(--p-text-xs);
  line-height: 1.45;
  color: var(--text-secondary);
}

.step-item.active {
  border-color: var(--border-strong);
  background: var(--bg-app);
  color: var(--text-primary);
}

.step-item.done {
  border-color: #bbf7d0;
  background: var(--p-ok-50);
  color: #166534;
}

.step-num {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-default);
  display: grid;
  place-items: center;
  font-family: var(--p-font-mono);
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 1px;
}

.step-item.active .step-num {
  background: var(--bg-inverse);
  border-color: var(--bg-inverse);
  color: var(--text-inverse);
}

.step-item.done .step-num {
  background: var(--accent-ok);
  border-color: var(--accent-ok);
  color: var(--text-inverse);
}

/* Educational Explanation Callout */
.callout-box {
  padding: 11px 12px;
  border-radius: var(--p-radius-sm);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--bg-inverse);
  font-size: var(--p-text-xs);
  line-height: 1.6;
  color: var(--text-secondary);
}

.callout-box strong {
  color: var(--text-primary);
  display: block;
  margin-bottom: 3px;
  font-size: var(--p-text-sm);
}

.callout-box.warning {
  border-left-color: var(--accent-heat);
  background: var(--p-heat-50);
  color: #881337;
}

.callout-box.warning strong {
  color: #9f1239;
}

.callout-box.water {
  border-left-color: var(--accent-water);
  background: var(--p-water-50);
  color: #0c4a6e;
}

.callout-box.water strong {
  color: #075985;
}
