/* ======================================================
   Med3D Viewer - Professional Medical Imaging Browser
   ====================================================== */

/* ----- Design Tokens ----- */
:root {
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-surface-hover: #f7f8fa;
  --color-surface-active: #eef2f9;
  --color-border: #e4e7ed;
  --color-border-light: #ebeef3;
  --color-text: #1d2129;
  --color-text-secondary: #6b7280;
  --color-text-tertiary: #9ca3af;
  --color-accent: #1a6ff5;
  --color-accent-hover: #3d8af7;
  --color-accent-light: rgba(26, 111, 245, 0.08);
  --color-accent-glow: rgba(26, 111, 245, 0.18);
  --color-danger: #ef4444;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-lung: #f97316;
  --color-dark-bg: #0a1628;
  --color-dark-surface: #0f1d33;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
  --shadow-xl: 0 12px 48px rgba(0,0,0,0.14);
  --transition-fast: 0.15s ease;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
}

/* ----- Reset ----- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ----- 3D Viewport ----- */
#viewer-container {
  position: fixed; inset: 0; z-index: 1;
}
#viewer-container canvas { display: block; }

/* =============================================
   Top Header Bar
   ============================================= */
#header-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: 44px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.88) 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border-light);
  display: none;
}
#header-bar .header-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--color-text);
}
#header-bar .header-brand .brand-icon {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--color-accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
#header-bar .header-info {
  display: flex; align-items: center; gap: 16px; font-size: 12px;
}
#header-bar .header-info-item {
  display: flex; align-items: center; gap: 4px; color: var(--color-text-secondary);
}
#header-bar .header-info-item strong { color: var(--color-text); font-weight: 600; }

/* =============================================
   Top Toolbar
   ============================================= */
#toolbar {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 20; display: none; gap: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); padding: 4px;
  box-shadow: var(--shadow-lg);
  flex-wrap: wrap; justify-content: center;
}
.tool-group {
  display: flex; gap: 0; padding: 0 4px;
  border-right: 1px solid var(--color-border-light);
}
.tool-group:first-child { padding-left: 2px; }
.tool-group:last-child { border-right: none; padding-right: 2px; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; width: 50px; height: 46px;
  background: transparent; border: none; border-radius: var(--radius);
  color: var(--color-text-secondary); cursor: pointer;
  font-size: 10px; transition: all var(--transition-fast);
  position: relative; font-family: var(--font);
}
.tool-btn:hover { background: var(--color-surface-hover); color: var(--color-text); }
.tool-btn:active { transform: scale(0.95); }
.tool-btn.active {
  background: var(--color-accent); color: #fff;
  box-shadow: 0 2px 8px var(--color-accent-glow);
}
.tool-btn svg { width: 18px; height: 18px; }
.tool-btn .tool-label { font-size: 10px; line-height: 1; font-weight: 500; }

/* =============================================
   Left Panel: Structure Tree (always visible)
   ============================================= */
#left-panel {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 15;
  width: 280px; background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--transition);
  box-shadow: 2px 0 20px rgba(0,0,0,0.04);
}
#left-panel.open { transform: translateX(0); }

#left-panel .panel-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--color-border-light);
  font-size: 14px; font-weight: 600; color: var(--color-text);
  background: linear-gradient(180deg, var(--color-surface-hover) 0%, var(--color-surface) 100%);
  flex-shrink: 0;
}
.panel-header-icon {
  width: 18px; height: 18px; color: var(--color-accent); flex-shrink: 0;
}

#structure-tree {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
#structure-tree::-webkit-scrollbar { width: 5px; }
#structure-tree::-webkit-scrollbar-track { background: transparent; }
#structure-tree::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 10px; }

/* ----- Tree Nodes ----- */
.tree-node { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; border-radius: var(--radius);
  cursor: pointer; transition: background var(--transition-fast);
  margin-bottom: 1px;
}
.tree-row:hover { background: var(--color-accent-light); }

.tree-arrow {
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  font-size: 8px; color: var(--color-text-tertiary); flex-shrink: 0;
  transition: transform var(--transition-fast);
}
.tree-arrow.expanded { transform: rotate(90deg); }
.tree-children { padding-left: 0; }

/* Color dot indicator */
.tree-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 4px rgba(0,0,0,0.2);
  transition: transform var(--transition-fast);
}
.tree-node .item-name {
  font-size: 13px; color: var(--color-text); flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Action buttons (eye + focus) */
.item-actions {
  display: flex; gap: 2px; opacity: 0; transition: opacity var(--transition-fast);
}
.tree-row:hover .item-actions { opacity: 1; }

.item-action-btn {
  width: 28px; height: 28px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--color-text-tertiary);
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: all var(--transition-fast);
  padding: 0;
}
.item-action-btn:hover { background: var(--color-accent-light); color: var(--color-accent); }
.item-action-btn.hidden { opacity: 0.3; }
.item-action-btn svg { width: 16px; height: 16px; }

/* Eye icon specific */
.eye-btn .eye-icon { display: block; }
.eye-btn.hidden .eye-on { display: none; }
.eye-btn.hidden .eye-off { display: block; }

/* Focus button specific */
.focus-btn:hover { color: var(--color-lung); }

.tree-empty {
  padding: 24px; text-align: center; color: var(--color-text-tertiary); font-size: 13px;
}

/* Lobe / Segment styling */
.tree-node.lobe > .tree-row { font-weight: 600; }
.tree-node.lobe > .tree-row .item-name { font-size: 14px; color: var(--color-lung); }
.tree-node.segment > .tree-row .item-name { font-size: 13px; }
.tree-node.subsegment > .tree-row .item-name { font-size: 12px; color: var(--color-text-secondary); }
.tree-node.other > .tree-row .item-name { font-size: 13px; font-weight: 500; }

/* =============================================
   Right Panel: Measurements
   ============================================= */
#right-panel {
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 15;
  width: 290px; background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition);
  box-shadow: -2px 0 24px rgba(0,0,0,0.06);
}
#right-panel.open { transform: translateX(0); }
#right-panel .panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--color-border-light);
  font-size: 14px; font-weight: 600; color: var(--color-text);
  background: linear-gradient(180deg, var(--color-surface-hover) 0%, var(--color-surface) 100%);
  flex-shrink: 0;
}
.panel-close {
  background: none; border: none; color: var(--color-text-tertiary); cursor: pointer;
  font-size: 20px; width: 28px; height: 28px; display: flex; align-items: center;
  justify-content: center; border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.panel-close:hover { color: var(--color-text); background: var(--color-border); }

/* Mobile close button (hidden on desktop) */
.panel-close--mobile {
  display: none;
  margin-left: auto;
}
.panel-close--mobile svg {
  width: 18px; height: 18px;
}

#measurement-list {
  flex: 1; overflow-y: auto; padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
#measurement-list::-webkit-scrollbar { width: 5px; }
#measurement-list::-webkit-scrollbar-track { background: transparent; }
#measurement-list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 10px; }
.measurement-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 6px;
  background: var(--color-surface-hover); border: 1px solid var(--color-border-light);
  font-size: 13px; transition: all var(--transition-fast);
}
.measurement-item:hover { border-color: var(--color-accent); }
.measurement-item .meas-label { color: var(--color-text-tertiary); font-size: 11px; }
.measurement-item .meas-value { color: var(--color-success); font-weight: 600; font-size: 15px; }
.meas-delete {
  background: none; border: none; color: var(--color-text-tertiary); cursor: pointer;
  font-size: 16px; width: 24px; height: 24px; display: flex; align-items: center;
  justify-content: center; border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.meas-delete:hover { color: var(--color-danger); background: rgba(239,68,68,0.08); }

/* =============================================
   Bottom Info Bar
   ============================================= */
#info-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  display: none; align-items: center; justify-content: space-between;
  padding: 6px 16px; background: rgba(255,255,255,0.9);
  border-top: 1px solid var(--color-border-light);
  font-size: 12px; backdrop-filter: blur(8px);
}
#info-bar .info-left { display: flex; align-items: center; gap: 14px; }
#info-bar .info-right { display: flex; align-items: center; gap: 14px; }
#info-bar .info-item { color: var(--color-text-secondary); font-size: 11px; }
#info-bar .info-item strong { color: var(--color-text); font-weight: 600; }
#info-bar .info-sep { color: var(--color-border); }
#fps-badge {
  padding: 2px 10px; border-radius: 10px; font-size: 11px; font-weight: 600;
  background: var(--color-accent-light); color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

/* =============================================
   View Preset Dropdown
   ============================================= */
#view-preset-menu {
  position: fixed; z-index: 30;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: 4px;
  box-shadow: var(--shadow-lg);
  min-width: 110px;
  animation: panelSlideIn 0.15s ease;
}
@keyframes panelSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.view-preset-btn {
  display: block; width: 100%; padding: 8px 16px; border: none;
  background: transparent; color: var(--color-text-secondary);
  font-size: 13px; cursor: pointer; text-align: left;
  border-radius: var(--radius); transition: all var(--transition-fast);
  font-family: var(--font);
}
.view-preset-btn:hover { background: var(--color-accent-light); color: var(--color-accent); }
.view-preset-btn .preset-key {
  display: inline-block; width: 22px; height: 20px; line-height: 20px;
  text-align: center; border-radius: 3px; font-size: 10px; font-weight: 700;
  background: var(--color-surface-hover); color: var(--color-text-secondary);
  margin-right: 8px; border: 1px solid var(--color-border-light);
}

/* =============================================
   Model Selector
   ============================================= */
#model-selector {
  position: fixed; top: 110px; left: 12px; z-index: 25;
  width: 230px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  overflow: hidden; box-shadow: var(--shadow-lg);
  display: none;
  animation: panelSlideIn 0.15s ease;
}
#model-selector.open { display: block; }
.model-selector-item {
  padding: 10px 14px; cursor: pointer; font-size: 13px;
  transition: background var(--transition-fast); color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border-light);
}
.model-selector-item:last-child { border-bottom: none; }
.model-selector-item:hover { background: var(--color-surface-hover); }
.model-selector-item.active { background: var(--color-accent-light); color: var(--color-accent); }
.model-selector-name { display: block; font-size: 13px; color: var(--color-text); }
.model-selector-meta { display: block; font-size: 11px; color: var(--color-text-tertiary); margin-top: 2px; }

/* =============================================
   Loading Overlay
   ============================================= */
#loading-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--color-dark-bg);
}
.loading-logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--color-accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; margin-bottom: 20px;
  box-shadow: 0 4px 20px var(--color-accent-glow);
}
.loading-spinner {
  width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.08);
  border-top-color: var(--color-accent); border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  margin-top: 16px; color: rgba(255,255,255,0.45); font-size: 13px;
  letter-spacing: 0.5px;
}
.loading-progress-bar {
  width: 220px; height: 3px; background: rgba(255,255,255,0.06);
  border-radius: 2px; margin-top: 14px; overflow: hidden;
}
.loading-progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--color-accent), #5b9cf5);
  border-radius: 2px; transition: width 0.3s ease; width: 0%;
}
.loading-percent {
  margin-top: 8px; color: rgba(255,255,255,0.5); font-size: 12px;
  font-weight: 600; font-variant-numeric: tabular-nums;
}

/* =============================================
   Error Overlay
   ============================================= */
#error-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: var(--color-dark-bg);
}
.error-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(239,68,68,0.1); color: var(--color-danger);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin-bottom: 20px;
}
.error-title {
  font-size: 18px; color: rgba(255,255,255,0.85); margin-bottom: 8px;
  font-weight: 600;
}
.error-message {
  font-size: 13px; color: rgba(255,255,255,0.4); margin-bottom: 28px;
  text-align: center; max-width: 380px; line-height: 1.6;
}
.error-retry-btn {
  padding: 10px 36px; border: none; border-radius: var(--radius);
  background: var(--color-accent); color: #fff; font-size: 14px;
  cursor: pointer; font-weight: 500; transition: all var(--transition-fast);
  font-family: var(--font);
}
.error-retry-btn:hover { background: var(--color-accent-hover); transform: translateY(-1px); }

/* =============================================
   Admin Panel
   ============================================= */
#admin-panel {
  position: fixed; inset: 0; z-index: 90;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: var(--color-dark-bg);
}
.admin-panel-card {
  width: 90%; max-width: 500px; max-height: 80vh;
  background: var(--color-dark-surface); border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-xl); overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-xl);
}
.admin-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 15px; font-weight: 600; color: rgba(255,255,255,0.85);
}
.admin-panel-body { flex: 1; overflow-y: auto; padding: 12px; }
.admin-search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.admin-refresh-btn {
  padding: 6px 16px; border: 1px solid rgba(255,255,255,0.08); border-radius: var(--radius);
  background: transparent; color: rgba(255,255,255,0.5); cursor: pointer;
  font-size: 13px; transition: all var(--transition-fast); font-family: var(--font);
}
.admin-refresh-btn:hover { border-color: var(--color-accent); color: var(--color-accent); }
.admin-model-list { display: flex; flex-direction: column; gap: 6px; }
.admin-model-item {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: var(--radius); cursor: pointer;
  transition: background var(--transition-fast); border: 1px solid transparent;
}
.admin-model-item:hover { background: rgba(255,255,255,0.03); border-color: rgba(255,255,255,0.06); }
.admin-model-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.admin-qr-thumb {
  width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: contain;
  cursor: zoom-in; transition: transform 0.2s;
}
.admin-qr-thumb.expanded {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 200px; height: 200px; z-index: 100; border-radius: var(--radius-lg);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.admin-qr-placeholder {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04); display: flex; align-items: center;
  justify-content: center; font-size: 10px; color: rgba(255,255,255,0.3);
}
.admin-model-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.admin-model-name {
  font-size: 14px; color: rgba(255,255,255,0.8); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.admin-model-meta { font-size: 11px; color: rgba(255,255,255,0.4); }
.admin-model-btn {
  padding: 6px 16px; border: none; border-radius: var(--radius);
  background: var(--color-accent); color: #fff; cursor: pointer;
  font-size: 13px; white-space: nowrap; transition: all var(--transition-fast);
  font-family: var(--font);
}
.admin-model-btn:hover { background: var(--color-accent-hover); }
.admin-loading, .admin-empty, .admin-error {
  text-align: center; padding: 40px 20px; color: rgba(255,255,255,0.4); font-size: 14px;
}

/* =============================================
   Panel Backdrop (mobile only)
   ============================================= */
#panel-backdrop {
  position: fixed; inset: 0; z-index: 14;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0; visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
  -webkit-tap-highlight-color: transparent;
}
#panel-backdrop.visible { opacity: 1; visibility: visible; }

/* =============================================
   Measurement Labels (3D overlay)
   ============================================= */
#label-container {
  position: fixed; inset: 0; z-index: 10; pointer-events: none;
}
.measurement-label {
  position: absolute; background: rgba(0,0,0,0.82); color: var(--color-success);
  padding: 3px 10px; border-radius: 10px; font-size: 11px; font-weight: 600;
  white-space: nowrap; pointer-events: none;
  border: 1px solid rgba(34,197,94,0.3);
  backdrop-filter: blur(4px);
}

/* =============================================
   Responsive - Mobile (max-width: 768px)
   ============================================= */
@media (max-width: 768px) {
  /* ----- Header Bar: compact ----- */
  #header-bar {
    height: 36px; padding: 0 10px;
  }
  #header-bar .header-brand { font-size: 11px; gap: 6px; }
  #header-bar .header-brand .brand-icon { width: 22px; height: 22px; font-size: 11px; }
  #header-bar .header-info { gap: 8px; font-size: 10px; }

  /* ----- Toolbar: move to bottom, compact ----- */
  #toolbar {
    top: auto; bottom: 0; left: 0; right: 0; transform: none;
    border-radius: 0; padding: 2px 4px;
    border-left: none; border-right: none; border-bottom: none;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    z-index: 25;
  }
  .tool-group { padding: 0 2px; }
  .tool-group:first-child { padding-left: 0; }
  .tool-group:last-child { padding-right: 0; }
  .tool-btn {
    width: 40px; height: 38px; gap: 1px;
  }
  .tool-btn svg { width: 16px; height: 16px; }
  .tool-btn .tool-label { font-size: 8px; }

  /* ----- Left Panel: overlay drawer (hidden by default) ----- */
  #left-panel {
    width: 85vw; max-width: 280px; z-index: 26;
    transform: translateX(-100%);
    box-shadow: 4px 0 32px rgba(0,0,0,0.15);
    border-right: 1px solid var(--color-border);
  }
  /* On mobile, panel starts closed */
  #left-panel:not(.open) { transform: translateX(-100%); }
  #left-panel.open { transform: translateX(0); }

  /* Mobile panel header: show the close button */
  #left-panel .panel-header {
    padding: 10px 12px;
    font-size: 13px;
  }
  #left-panel .panel-header .panel-header-icon {
    width: 16px; height: 16px;
  }
  #left-panel .panel-close--mobile {
    display: flex;
  }

  /* Structure tree: touch-friendly sizing */
  #structure-tree { padding: 4px; }
  .tree-row {
    padding: 10px 8px; gap: 8px;
    min-height: 42px; /* touch-friendly */
  }
  .tree-dot { width: 10px; height: 10px; }
  .tree-node .item-name { font-size: 14px; }
  .tree-node.segment > .tree-row .item-name { font-size: 13px; }
  .tree-node.subsegment > .tree-row .item-name { font-size: 12px; }

  /* Action buttons always visible on mobile */
  .item-actions { opacity: 1; }
  .item-action-btn {
    width: 32px; height: 32px;
  }
  .item-action-btn svg { width: 18px; height: 18px; }

  /* Right Panel: full width overlay */
  #right-panel {
    width: 100%; z-index: 26;
    box-shadow: -4px 0 32px rgba(0,0,0,0.15);
  }

  /* Bottom Info Bar: compact */
  #info-bar {
    padding: 4px 10px; font-size: 10px;
    bottom: 44px; /* above toolbar */
  }
  #info-bar .info-left { gap: 8px; }
  #info-bar .info-right { gap: 8px; }
  #info-bar .info-item { font-size: 10px; }
  #fps-badge {
    padding: 1px 8px; font-size: 10px;
  }

  /* View Preset Menu: mobile positioning */
  #view-preset-menu {
    bottom: 56px; top: auto;
    left: 50%; transform: translateX(-50%);
    border-radius: var(--radius-lg);
  }

  /* Model Selector: full width on mobile */
  #model-selector {
    width: calc(100vw - 24px); left: 12px; top: auto; bottom: 56px;
    max-height: 50vh; overflow-y: auto;
  }
}

/* =============================================
   Responsive - Small phone (max-width: 400px)
   ============================================= */
@media (max-width: 400px) {
  #toolbar { padding: 1px 2px; }
  .tool-btn { width: 36px; height: 34px; }
  .tool-btn svg { width: 14px; height: 14px; }
  .tool-btn .tool-label { font-size: 7px; }
  #header-bar { height: 32px; padding: 0 8px; }
  #header-bar .header-brand { font-size: 10px; }
  #info-bar { bottom: 40px; padding: 2px 8px; }
  #info-bar .info-item { font-size: 9px; }
}