/* ===== CSS RESET & TOKENS ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:      #0f1117;
  --bg-surface:   #161b27;
  --bg-elevated:  #1e2535;
  --bg-card:      #242d3f;
  --border:       rgba(255,255,255,0.08);
  --border-light: rgba(255,255,255,0.12);

  --accent:       #6c63ff;
  --accent-glow:  rgba(108,99,255,0.35);
  --accent-hover: #7d75ff;
  --accent2:      #00d4aa;
  --accent2-glow: rgba(0,212,170,0.25);
  --danger:       #ff5a5a;

  --text-primary:   #eef0f8;
  --text-secondary: #8e98b0;
  --text-muted:     #5a6380;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 6px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.5);

  --sidebar-w: 300px;
  --header-h: 56px;
  --transition: 0.18s ease;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 99px; }

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(15,17,23,0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  width: 28px; height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}
.brand-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #a29bff 0%, #6c63ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-tagline {
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 10px;
  border-left: 1px solid var(--border-light);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Unit Toggle */
.unit-toggle {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}
.unit-btn {
  padding: 5px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.unit-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
}
.unit-btn:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-light);
}
.btn-primary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}
.btn-primary:hover { background: var(--bg-card); }
.btn-accent {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-accent:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px);
}
.btn.full-width { width: 100%; justify-content: center; }

.chevron { width: 11px; height: 11px; margin-left: 2px; }

/* Export dropdown */
.export-dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
  animation: fadeIn 0.15s ease;
}
.dropdown-menu.open { display: flex; }
.dropdown-item {
  padding: 10px 14px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}
.dropdown-item:hover { background: var(--bg-elevated); }

/* ===== MAIN LAYOUT ===== */
.app-main {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.panel {
  border-bottom: 1px solid var(--border);
}
.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  cursor: pointer;
  user-select: none;
}
.step-badge {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9b8fff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.panel-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}
.panel-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.panel-badge.active {
  background: rgba(0,212,170,0.15);
  color: var(--accent2);
}

.panel-body {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== FORM ELEMENTS ===== */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.input-with-unit {
  display: flex;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-light);
  background: var(--bg-base);
  transition: border-color var(--transition);
}
.input-with-unit:focus-within { border-color: var(--accent); }
.form-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-base);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}
.input-with-unit .form-input {
  border: none;
  border-radius: 0;
  background: transparent;
  flex: 1;
  min-width: 0;
}
.form-input:focus { border-color: var(--accent); }
.unit-label {
  padding: 0 10px;
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

/* ===== TOOL BUTTONS ===== */
.tool-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tool-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  min-width: 60px;
}
.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-light);
}
.tool-btn.active {
  background: rgba(108,99,255,0.15);
  color: var(--accent);
  border-color: var(--accent);
}
.tool-btn.danger:hover {
  background: rgba(255,90,90,0.1);
  color: var(--danger);
  border-color: var(--danger);
}

.hint-box {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: rgba(108,99,255,0.08);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.hint-box svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; color: var(--accent); }
.hint-box strong { color: var(--text-primary); }

/* ===== COLOR SWATCHES ===== */
.color-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.color-swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.color-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 1px rgba(255,255,255,0.3); }

/* ===== FURNITURE LIST ===== */
.furniture-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.empty-list-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.furniture-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: var(--transition);
  user-select: none;
}
.furniture-item:hover {
  border-color: var(--border-light);
  background: var(--bg-elevated);
  transform: translateX(2px);
}
.furniture-item:active { cursor: grabbing; }
.furniture-item.selected {
  border-color: var(--accent);
  background: rgba(108,99,255,0.1);
}
.room-list-item {
  cursor: pointer;
}
.room-list-item.selected {
  border-color: #a29bff;
  background: rgba(162,155,255,0.1);
}
.furniture-item-swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.furniture-item-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.furniture-item-size {
  font-size: 10px;
  color: var(--text-muted);
}
.furniture-item-actions {
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity var(--transition);
}
.furniture-item:hover .furniture-item-actions { opacity: 1; }
.icon-btn-sm {
  width: 20px; height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition);
}
.icon-btn-sm:hover { background: var(--bg-elevated); color: var(--text-primary); }
.icon-btn-sm svg { width: 12px; height: 12px; }
.drag-hint {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0 0;
}

/* ===== CANVAS AREA ===== */
.canvas-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  min-width: 0;
  position: relative;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.icon-btn {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.icon-btn.active { background: rgba(108,99,255,0.15); color: var(--accent); }
.icon-btn.danger:hover { background: rgba(255,90,90,0.1); color: var(--danger); }

.zoom-label {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
}
.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.canvas-scroll-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  cursor: default;
}

#mainCanvas {
  display: block;
  cursor: crosshair;
}

.canvas-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 14px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  display: none;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 340px;
  animation: slideUp 0.2s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.modal-close:hover { background: var(--bg-elevated); color: var(--text-primary); }
.modal-body { padding: 16px 20px; }
.modal-footer {
  padding: 12px 20px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* ===== NAV LINKS (About / GitHub) ===== */
.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.nav-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.nav-link.active {
  background: rgba(108,99,255,0.15);
  color: var(--accent);
}

/* ===== ABOUT POPUP ===== */
.about-popup {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  width: min(500px, calc(100vw - 40px));
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(108,99,255,0.12);
  z-index: 400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.about-popup.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.about-popup-inner {
  padding: 24px 28px 20px;
  position: relative;
}
.about-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.about-close:hover { background: var(--bg-elevated); color: var(--text-primary); }
.about-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #a29bff 0%, #6c63ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
}
.about-body {
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.about-body p {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-secondary);
}
.about-body p strong {
  color: var(--text-primary);
  font-weight: 600;
}
.about-footer {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-about-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  background: rgba(108,99,255,0.18);
  color: #a29bff;
  border: 1px solid rgba(108,99,255,0.3);
}
.btn-about-link:hover {
  background: rgba(108,99,255,0.28);
  box-shadow: 0 4px 14px var(--accent-glow);
  transform: translateY(-1px);
  color: #c5c0ff;
}
.btn-about-github {
  background: rgba(255,255,255,0.07);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
}
.btn-about-github:hover {
  background: rgba(255,255,255,0.12);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  color: var(--text-primary);
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Glow on room canvas when room exists */
.has-room .canvas-scroll-wrapper {
  background: radial-gradient(ellipse at center, #141826 0%, var(--bg-base) 100%);
}

/* Display-unit toggle pill (ft+in / in only) */
.display-unit-toggle {
  display: flex;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.du-btn {
  padding: 3px 10px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.du-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 6px var(--accent-glow);
}
.du-btn:hover:not(.active) { color: var(--text-primary); background: var(--bg-elevated); }

/* Labeled icon button (grid/snap) */
.icon-btn.labeled {
  width: auto;
  padding: 4px 8px;
  gap: 4px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-secondary);
  flex-direction: row;
}
.icon-btn.labeled span { line-height: 1; }

/* ===== SIDEBAR TOGGLE BUTTON ===== */
.sidebar-toggle {
  display: none; /* shown only on mobile/tablet */
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 300;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow), 0 2px 8px rgba(0,0,0,0.4);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
}
.sidebar-toggle:hover {
  background: var(--accent-hover);
  box-shadow: 0 6px 24px var(--accent-glow);
  transform: scale(1.06);
}
.sidebar-toggle svg { width: 20px; height: 20px; }

/* ===== SIDEBAR BACKDROP (mobile) ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ===== WALL MEASURE OVERLAY ===== */
.wall-measure-overlay {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(108, 99, 255, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(162, 155, 255, 0.4);
  border-radius: 12px;
  padding: 10px 22px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 24px rgba(108,99,255,0.5), 0 2px 8px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
  min-width: 120px;
  text-align: center;
}
.wall-measure-overlay.active {
  opacity: 1;
}
.wall-measure-overlay .wm-label {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: block;
  margin-bottom: 2px;
  font-family: 'Inter', sans-serif;
}

/* ===== ABOUT POPUP — SCROLLABLE ON SMALL SCREENS ===== */
.about-popup {
  max-height: calc(100vh - var(--header-h) - 24px);
  overflow-y: auto;
}

/* ===== Print styles ===== */
@media print {
  .app-header, .sidebar, .canvas-toolbar, .canvas-status,
  .sidebar-toggle, .sidebar-backdrop { display: none !important; }
  .canvas-container { padding-top: 0 !important; }
  #mainCanvas { max-width: 100vw; max-height: 100vh; }
}

/* ===== TABLET (≤ 900px) ===== */
@media (max-width: 900px) {
  /* Header: compress controls */
  .header-nav { display: none; } /* move to sidebar toggle on tablet */
  .brand-tagline { display: none; }
  .header-controls { gap: 8px; }
  .unit-toggle { display: none; } /* moved to accessible sidebar area */
  .btn span, .btn-ghost span { display: none; }
  .btn { padding: 7px 10px; }
  .header-actions { gap: 6px; }

  /* Sidebar: slides in/out as a drawer */
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 32px rgba(0,0,0,0.5);
    width: min(320px, 85vw);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Canvas takes full width */
  .app-main { padding-left: 0; }

  /* Show sidebar toggle */
  .sidebar-toggle { display: flex; }

  /* Canvas toolbar: allow wrap and smaller buttons */
  .canvas-toolbar {
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 3px;
  }
  .icon-btn.labeled span { display: none; }
  .icon-btn.labeled { padding: 4px 6px; }
}

/* ===== MOBILE (≤ 600px) ===== */
@media (max-width: 600px) {
  :root { --header-h: 52px; }

  .app-header { padding: 0 12px; gap: 8px; }

  /* Hide brand tagline and unit toggle completely */
  .brand-tagline { display: none; }
  .brand-name { font-size: 16px; }

  /* Compact header controls */
  .header-controls { gap: 6px; }
  .header-actions { gap: 4px; }

  /* Show only icon in header buttons on very small screens */
  .btn-ghost .btn-text, .btn-primary .btn-text { display: none; }
  .btn svg { display: block; }

  /* Sidebar as full-height overlay */
  .sidebar {
    width: min(300px, 88vw);
  }

  /* Wall measure overlay: larger on mobile */
  .wall-measure-overlay {
    font-size: 26px;
    padding: 12px 28px;
    bottom: 80px; /* above the toggle button */
  }

  /* Sidebar toggle: slightly larger tap target */
  .sidebar-toggle {
    width: 52px; height: 52px;
    bottom: 16px;
    left: 16px;
  }

  /* About popup: full-width on mobile */
  .about-popup {
    width: calc(100vw - 24px);
    left: 12px;
    right: 12px;
    transform: translateX(0) translateY(-8px);
  }
  .about-popup.open {
    transform: translateX(0) translateY(0);
  }

  /* Canvas toolbar: scrollable horizontally */
  .canvas-toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 4px 8px;
    gap: 2px;
  }
  .canvas-toolbar::-webkit-scrollbar { height: 0; }
  .zoom-label { min-width: 36px; font-size: 11px; }
  .toolbar-sep { margin: 0 2px; }

  /* Compress canvas status bar */
  .canvas-status { font-size: 10px; padding: 4px 10px; }
}

/* ===== VERY SMALL (≤ 380px) ===== */
@media (max-width: 380px) {
  .brand-icon { display: none; }
  .brand-name { font-size: 14px; }
  .header-actions .btn:not(#btnSave) { display: none; }
}

/* ===== MOBILE WALL INPUT PANEL (bottom sheet) ===== */
.mobile-wall-panel {
  display: none; /* only revealed inside the media query below */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 310;
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(108,99,255,0.12);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.mobile-wall-panel.open {
  transform: translateY(0);
}

.mwp-drag-handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--border-light);
  margin: 10px auto 0;
}

.mwp-inner {
  padding: 10px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 58vh;
  overflow-y: auto;
}

.mwp-header { display: flex; flex-direction: column; gap: 8px; }

.mwp-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mwp-icon {
  width: 18px; height: 18px;
  color: var(--accent);
  flex-shrink: 0;
}
.mwp-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.mwp-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  padding: 7px 12px;
  background: rgba(108,99,255,0.1);
  border: 1px solid rgba(108,99,255,0.22);
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.mwp-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mwp-section { display: flex; flex-direction: column; gap: 6px; }

.mwp-dir-group {
  display: flex;
  gap: 6px;
}
.mwp-dir-btn {
  flex: 1;
  padding: 9px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-base);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}
.mwp-dir-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.mwp-dir-btn.active {
  background: rgba(108,99,255,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* Angle row: hidden by default, shown via .visible class */
.mwp-angle-row {
  display: none;
  flex-direction: column;
  gap: 5px;
}
.mwp-angle-row.visible { display: flex; }

.mwp-footer {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 2px;
  border-top: 1px solid var(--border);
}
.mwp-footer .btn {
  flex: 1;
  min-width: 0;
  justify-content: center;
  font-size: 12px;
  padding: 8px 6px;
  white-space: nowrap;
}
.mwp-cancel-btn {
  color: var(--danger) !important;
  border-color: rgba(255,90,90,0.3) !important;
}
.mwp-cancel-btn:hover {
  background: rgba(255,90,90,0.1) !important;
}

@media (max-width: 900px) {
  .mobile-wall-panel { display: block; }
}
