:root {
  --bg: #0f131a;
  --panel: rgba(21, 26, 35, 0.92);
  --panel-solid: #161b24;
  --border: rgba(255, 255, 255, 0.1);
  --text: #eef2f8;
  --muted: #9aa6ba;
  --accent: #3b82f6;
  --accent-2: #06b6d4;
  --danger: #ef4444;
  --ok: #10b981;
  --canvas-bg: radial-gradient(circle at 50% 30%, #1c2432 0%, #0d1118 75%);
}

body.theme-light {
  --bg: #f1f4f9;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-solid: #ffffff;
  --border: rgba(15, 23, 42, 0.12);
  --text: #111827;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #0891b2;
  --canvas-bg: radial-gradient(circle at 50% 30%, #ffffff 0%, #e4e9f2 85%);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.hidden { display: none !important; }

/* Gallery */
.gallery-wrap {
  height: 100%;
  overflow-y: auto;
  padding: 40px 24px;
  max-width: 1100px;
  margin: 0 auto;
}
.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.gallery-head h1 { margin: 0; font-size: 24px; font-weight: 700; }
.gallery-head p { margin: 4px 0 0; color: var(--muted); }
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.model-card {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.model-card h3 { margin: 0; font-size: 16px; }
.model-meta { color: var(--muted); font-size: 12px; line-height: 1.5; }
.model-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }

/* Buttons & inputs */
.btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: 0.14s ease;
  white-space: nowrap;
}
body.theme-light .btn { background: rgba(15, 23, 42, 0.05); color: var(--text); }
.btn:hover { border-color: var(--accent); background: rgba(59, 130, 246, 0.14); }
.btn.active, body.theme-light .btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary, body.theme-light .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn-sm { padding: 4px 8px; font-size: 11px; }

/* Studio Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.topbar {
  height: 50px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 10px;
  z-index: 20;
  overflow-x: auto;
}
.topbar-group { display: flex; align-items: center; gap: 8px; }
.brand {
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
}
.badge {
  background: rgba(59, 130, 246, 0.18);
  color: var(--accent-2);
  border: 1px solid rgba(6, 182, 212, 0.25);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.mode-switch {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
}
body.theme-light .mode-switch { background: rgba(15, 23, 42, 0.06); }
.mode-switch .btn { border: none; border-radius: 7px; background: transparent; padding: 5px 10px; }
.mode-switch .btn.active { background: var(--accent); color: #fff; }

.workspace {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
}

.viewport {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--canvas-bg);
  overflow: hidden;
}
.viewport canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }

/* Sidebars */
.sidebar {
  width: 300px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 15;
}
.sidebar.right {
  width: 310px;
  border-right: none;
  border-left: 1px solid var(--border);
}
.sidebar-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}
.search-box {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.search-box input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12px;
  outline: none;
}
body.theme-light .search-box input { background: rgba(15, 23, 42, 0.04); }
.search-box input:focus { border-color: var(--accent); }

.tree-scroll, .inspector-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.tree-item:hover { background: rgba(255, 255, 255, 0.06); }
body.theme-light .tree-item:hover { background: rgba(15, 23, 42, 0.05); }
.tree-item.selected { background: rgba(59, 130, 246, 0.22); }
.tree-toggle {
  width: 14px;
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  flex-shrink: 0;
}
.tree-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.tree-tag {
  font-size: 10px;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}
.tree-eye {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 3px;
  font-size: 12px;
}
.tree-eye.off { opacity: 0.35; }
.tree-children { padding-left: 14px; }

/* Inspector */
.prop-section {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.prop-section h4 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.prop-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
  line-height: 1.4;
}
.prop-k { color: var(--muted); flex-shrink: 0; }
.prop-v { text-align: right; word-break: break-word; font-weight: 500; }
.chip-list { display: flex; flex-direction: column; gap: 5px; }
.chip {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 11.5px;
}
body.theme-light .chip { background: rgba(15, 23, 42, 0.03); }

/* Floating bottom control bar in viewport */
.hud-bottom {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 12;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  max-width: calc(100% - 24px);
  flex-wrap: wrap;
}
.slider-wrap { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.slider-wrap input[type="range"] { width: 115px; accent-color: var(--accent); cursor: pointer; }

.hud-views {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  z-index: 12;
}
.hud-toast {
  position: absolute;
  bottom: 74px;
  left: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 10px;
  font-size: 11.5px;
  color: var(--muted);
  z-index: 10;
  pointer-events: none;
}
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 19, 26, 0.65);
  z-index: 30;
  font-size: 15px;
  font-weight: 600;
}

/* Detail Drawing Studio Modal */
.drawing-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.drawing-head {
  min-height: 50px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.draw-select {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 12px;
  max-width: 280px;
}
body.theme-light .draw-select {
  background: rgba(15, 23, 42, 0.05);
}
.drawing-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}
.drawing-sheet-pane {
  position: relative;
  flex: 1.35;
  min-width: 0;
  overflow: hidden;
  padding: 12px;
  background: #dfe5ee;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.drawing-paper {
  position: relative;
  background: #ffffff;
  color: #0f172a;
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.22);
  border: 1px solid #cbd5e1;
  padding: 6px;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.drawing-paper.is-panning {
  cursor: grabbing;
}
.drawing-paper svg {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
}
.draw-zoom-bar {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(15, 23, 42, 0.84);
  color: #f8fafc;
  padding: 5px 8px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.draw-zoom-bar .btn {
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.18);
}
.draw-zoom-pct {
  min-width: 44px;
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
}
.draw-zoom-hint {
  font-size: 10.5px;
  color: #cbd5e1;
  margin-left: 4px;
  padding-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}
.draw-notice {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  max-width: 1120px;
  width: 100%;
}
.drawing-3d-pane {
  flex: 0.95;
  min-width: 340px;
  max-width: 560px;
  border-left: 1px solid var(--border);
  background: var(--panel-solid);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.draw-3d-wrap {
  position: relative;
  height: 52%;
  min-height: 260px;
  border-bottom: 1px solid var(--border);
  background: var(--canvas-bg);
}
.draw-3d-viewport {
  width: 100%;
  height: 100%;
}
.draw-3d-viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}
.draw-3d-toolbar {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: none;
}
.draw-3d-toolbar .btn {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.78);
  color: #f8fafc;
  border-color: rgba(255, 255, 255, 0.16);
}
.draw-3d-toolbar .btn.active {
  background: var(--accent);
  border-color: var(--accent);
}
.draw-3d-hint {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #cbd5e1;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  pointer-events: none;
}
.draw-legend {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}
.draw-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 11.5px;
  cursor: pointer;
  margin-bottom: 5px;
  transition: 0.12s ease;
}
body.theme-light .draw-chip {
  background: rgba(15, 23, 42, 0.03);
}
.draw-chip:hover, .draw-chip.is-active {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.14);
}
.draw-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

@media print {
  body, html {
    background: #fff !important;
    overflow: visible !important;
    height: auto !important;
  }
  #authView, #cabinetView, #adminView, #accountModal, #viewerView, .drawing-head, .drawing-3d-pane, .draw-notice, .draw-zoom-bar, .draw-mob-tabs {
    display: none !important;
  }
  .drawing-modal {
    position: static !important;
    display: block !important;
    background: #fff !important;
  }
  .drawing-body, .drawing-sheet-pane {
    display: block !important;
    padding: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }
  .drawing-paper {
    box-shadow: none !important;
    border: none !important;
    max-width: none !important;
    padding: 0 !important;
  }
}

/* Auth, Cabinet & Admin Portal */
.auth-wrap {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--canvas-bg);
}
.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.auth-brand h1 { margin: 0; font-size: 20px; }
.auth-brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.auth-logo-svg, .mv-head-logo {
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.22);
}
.mv-accent { color: #22d3ee; }
body.theme-light .mv-accent { color: #0284c7; }
.mv-head-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.mv-top-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
  padding-right: 8px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}
.mv-top-brand img { border-radius: 5px; display: block; }
.auth-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(0, 0, 0, 0.16);
  padding: 4px;
  border-radius: 9px;
}
body.theme-light .auth-tabs { background: rgba(15, 23, 42, 0.06); }
.auth-tabs .btn { justify-content: center; border: none; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.field input, .admin-input {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  outline: none;
}
body.theme-light .field input, body.theme-light .admin-input { background: rgba(15, 23, 42, 0.04); }
.field input:focus, .admin-input:focus { border-color: var(--accent); }
.auth-submit { justify-content: center; padding: 10px; font-size: 13px; font-weight: 600; }
.auth-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
}
body.theme-light .auth-error { color: #b91c1c; }
.auth-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11.5px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.cabinet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.cabinet-search {
  flex: 1;
  max-width: 380px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
}
.cabinet-search:focus { border-color: var(--accent); }
.collection-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 16px;
}
.col-pill {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}
.col-pill:hover { border-color: var(--accent); }
.col-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.model-col-tag {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.14);
  color: #60a5fa;
}
body.theme-light .model-col-tag { color: #1d4ed8; }
.model-frag-tag {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.28);
}
body.theme-light .model-frag-tag {
  color: #b45309;
  background: rgba(245, 158, 11, 0.12);
}

.model-thumb {
  width: 100%;
  height: 175px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--canvas-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.model-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.model-thumb-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11.5px;
}
.btn.danger {
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}
.btn.danger:hover {
  background: rgba(239, 68, 68, 0.16);
  border-color: var(--danger);
}

.acc-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.acc-modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.acc-modal-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.acc-modal-body {
  padding: 16px;
  max-height: 75vh;
  overflow-y: auto;
}

/* Admin Tables */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-box {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}
.stat-box .stat-k { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.stat-box .stat-v { font-size: 20px; font-weight: 700; }
.admin-table-wrap {
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  margin-bottom: 22px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.admin-table th, .admin-table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.admin-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.02);
}
.status-pill {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.status-pill.ok { background: rgba(16, 185, 129, 0.18); color: #34d399; }
.status-pill.blk { background: rgba(239, 68, 68, 0.18); color: #f87171; }
body.theme-light .status-pill.ok { color: #047857; }
body.theme-light .status-pill.blk { color: #b91c1c; }

/* Mobile & Touch Responsive Layout */
@media (min-width: 901px) {
  .mob-only { display: none !important; }
}

.model-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draw-mob-tabs {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--border);
}
.draw-mob-tabs .btn {
  flex: 1;
  justify-content: center;
}

.mob-dock {
  position: absolute;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  max-width: calc(100% - 16px);
  overflow-x: auto;
}
.mob-dock .btn {
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
}

.mob-tools-sheet {
  position: absolute;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 54px);
  left: 50%;
  transform: translateX(-50%);
  width: min(94vw, 420px);
  z-index: 22;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
  display: flex;
  flex-direction: column;
  gap: 11px;
  max-height: 62dvh;
  overflow-y: auto;
}
.mob-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
}
.mob-sheet-section { display: flex; flex-direction: column; gap: 6px; }
.mob-sheet-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.mob-pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.mob-pill-row .btn { flex: 0 0 auto; }

@media (max-width: 900px) {
  .desktop-only { display: none !important; }
  input, select, textarea { font-size: 16px !important; }

  .gallery-wrap { padding: 14px; }
  .gallery-head { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
  .gallery-head h1 { font-size: 20px; }
  .cards-grid { grid-template-columns: 1fr; }
  .cabinet-toolbar { flex-wrap: wrap; }
  .cabinet-search { max-width: none; width: 100%; }
  .btn { min-height: 36px; padding: 6px 11px; }
  .btn-sm { min-height: 32px; padding: 5px 10px; }

  .topbar {
    height: 46px;
    padding: 0 10px;
    gap: 8px;
    overflow: hidden;
  }
  .topbar-group { min-width: 0; gap: 6px; }
  .model-title { max-width: 34vw; font-size: 13px; }
  .mode-switch .btn { min-height: 28px; padding: 4px 8px; font-size: 11.5px; }

  /* Hide desktop floating clutter on phone */
  .hud-views, .hud-toast, .hud-bottom { display: none !important; }

  .sidebar {
    position: fixed;
    top: 46px;
    left: 0;
    bottom: 0;
    width: min(86vw, 330px);
    z-index: 45;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    border-right: 1px solid var(--border);
  }
  .sidebar.right {
    left: auto;
    right: 0;
    width: min(88vw, 340px);
    transform: translateX(105%);
    border-left: 1px solid var(--border);
  }
  .sidebar.mob-open {
    transform: translateX(0);
    box-shadow: 0 0 36px rgba(0, 0, 0, 0.45);
  }

  /* Drawing modal clean mobile UX */
  .drawing-head { padding: 6px 8px; gap: 6px; flex-direction: column; align-items: stretch; }
  .draw-nav-group { width: 100%; justify-content: space-between; flex-wrap: nowrap; }
  .draw-select { flex: 1; min-width: 0; max-width: none; }
  .draw-tools-group { display: none; width: 100%; flex-wrap: wrap; gap: 6px; padding-top: 4px; border-top: 1px solid var(--border); }
  .draw-tools-group.mob-open { display: flex; }

  .draw-zoom-hint, .draw-3d-hint { display: none !important; }
  #btnDrawZoomIn, #btnDrawZoomOut { display: none; }
  .draw-zoom-bar { bottom: 12px; right: 12px; padding: 4px 6px; }

  .drawing-body { flex-direction: column; }
  .drawing-sheet-pane { flex: 1; padding: 6px; }
  .drawing-3d-pane {
    flex: 1;
    min-width: 0;
    max-width: none;
    border-left: none;
  }
  .draw-3d-wrap { height: 100%; }
  .draw-3d-toolbar {
    top: auto;
    bottom: 10px;
    left: 8px;
    right: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
  }
  .draw-3d-toolbar > div { flex-wrap: nowrap !important; }

  .drawing-modal[data-mob-tab="2d"] .drawing-3d-pane { display: none; }
  .drawing-modal[data-mob-tab="3d"] .drawing-sheet-pane,
  .drawing-modal[data-mob-tab="3d"] .draw-legend { display: none; }
  .drawing-modal[data-mob-tab="list"] .drawing-sheet-pane,
  .drawing-modal[data-mob-tab="list"] .draw-3d-wrap { display: none; }
  .drawing-modal[data-mob-tab="list"] .draw-legend { flex: 1; height: 100%; }
}
