:root {
  --bg: #f7f5f1;
  --bg-elev: #ffffff;
  --bg-sunken: #efece6;
  --ink: #1c1c1a;
  --ink-2: #4a4a47;
  --muted: #8b8a85;
  --line: #e6e2d8;
  --line-2: #d6d1c4;
  --accent: #c8521a;
  --accent-2: #a13f10;
  --accent-soft: #fbe9dd;
  --ok: #2f7d4c;
  --warn: #b88600;
  --danger: #b3261e;
  --earth: #8c6a3f;
  --earth-soft: #f1e7d4;
  --shadow-sm: 0 1px 2px rgba(28, 28, 26, 0.06);
  --shadow: 0 6px 24px rgba(28, 28, 26, 0.08);
  --shadow-lg: 0 18px 48px rgba(28, 28, 26, 0.14);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: var(--font); background: var(--bg); color: var(--ink); }
body { font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; font-size: 14px; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--earth));
  color: white; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; letter-spacing: 0.04em;
  box-shadow: var(--shadow-sm);
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav { display: flex; gap: 2px; flex: 1; }
.nav-btn {
  padding: 8px 14px; border-radius: 8px; color: var(--ink-2); font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: var(--bg-sunken); }
.nav-btn.active { background: var(--ink); color: white; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.lang-select {
  border: 1px solid var(--line);
  background: white;
  border-radius: 6px;
  padding: 6px 8px;
}
.save-status {
  font-size: 12px; color: var(--muted);
  min-width: 0; transition: color 0.2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.save-status::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); transition: background 0.2s, transform 0.2s;
}
.save-status[data-state="saving"] { color: var(--ink-2); }
.save-status[data-state="saving"]::before { background: var(--warn); transform: scale(1.2); animation: pulse 1s ease-in-out infinite; }
.save-status[data-state="saved"]  { color: var(--ok); }
.save-status[data-state="saved"]::before  { background: var(--ok); }
.save-status[data-state="error"]  { color: var(--danger); }
.save-status[data-state="error"]::before  { background: var(--danger); }
.save-status[data-state="idle"]   { color: transparent; }
.save-status[data-state="idle"]::before { background: transparent; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.online-status {
  font-size: 12px; padding: 3px 8px; border-radius: 999px;
  background: var(--earth-soft); color: var(--earth);
}
.online-status[data-state="offline"] { background: #fdecea; color: var(--danger); }
.update-banner {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: white;
  padding: 12px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-lg); z-index: 100;
  font-size: 13px;
}
.update-banner button {
  background: var(--accent); color: white;
  padding: 6px 12px; border-radius: 6px; font-weight: 600;
}

.storage-meter { margin-bottom: 12px; }
.storage-meter-label { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12px; }
.storage-meter-bar {
  height: 8px; border-radius: 4px;
  background: var(--bg-sunken); overflow: hidden;
}
.storage-meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--ok), var(--earth));
  transition: width 0.3s ease, background 0.3s ease;
}
.storage-meter-fill[data-level="high"] { background: var(--warn); }
.storage-meter-fill[data-level="critical"] { background: var(--danger); }

/* Buttons */
.btn-primary {
  background: var(--accent); color: white;
  padding: 8px 16px; border-radius: 8px; font-weight: 600;
  transition: background 0.15s, transform 0.05s;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary.big { padding: 12px 22px; font-size: 15px; }
.btn-primary .plus { font-size: 18px; line-height: 1; margin-right: 4px; }
.btn-ghost {
  background: transparent; border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 6px; color: var(--ink); font-weight: 500;
}
.btn-ghost:hover { background: var(--bg-sunken); border-color: var(--line-2); }
.btn-ghost.small { padding: 4px 8px; font-size: 12px; }
.btn-danger {
  background: transparent; border: 1px solid var(--danger); color: var(--danger);
  padding: 7px 12px; border-radius: 6px; font-weight: 500;
}
.btn-danger:hover { background: var(--danger); color: white; }

/* Views */
.view { display: none; flex: 1; min-height: calc(100vh - 64px); }
.view.active { display: block; }
.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 24px; gap: 16px;
}
.page-head h1 { margin-bottom: 4px; }

/* Dashboard */
.quick-templates { margin: 22px 0 36px; }
.quick-templates h3 { margin-bottom: 12px; }
.template-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px;
}
.template-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.template-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.template-thumb {
  height: 90px; background: var(--earth-soft); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
  border: 1px solid var(--line);
}
.template-thumb svg { width: 100%; height: 100%; }
.template-name { font-weight: 600; }
.template-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

.project-section h3 { margin-bottom: 12px; }
.project-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.project-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}
.project-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.project-card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}
.project-card-name { font-weight: 600; font-size: 15px; }
.project-card-client { color: var(--muted); font-size: 12px; }
.project-card-stats {
  display: flex; gap: 16px; margin: 12px 0;
  padding-top: 12px; border-top: 1px solid var(--line);
}
.project-card-stat .stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.project-card-stat .stat-value { font-weight: 600; font-size: 14px; }
.project-card-actions {
  display: flex; gap: 6px; margin-top: 8px;
}
.project-card-actions button { font-size: 12px; padding: 4px 8px; }

.empty-state {
  text-align: center; padding: 60px 20px;
  background: var(--bg-elev); border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  color: var(--muted);
}
.empty-icon { font-size: 40px; margin-bottom: 8px; }

/* Plan editor */
.plan-layout {
  display: grid; grid-template-columns: 280px 1fr;
  height: calc(100vh - 64px);
}
.plan-sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
}
.project-info {
  padding: 10px 12px;
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}
.project-info .project-name { font-weight: 600; font-size: 14px; margin-top: 2px; }

.tool-section { margin-bottom: 20px; }
.tool-section h4 { margin-bottom: 8px; }

.floor-selector { margin-bottom: 16px; }
.floor-selector > label { font-size: 13px; font-weight: 500; display: block; margin-bottom: 6px; }
.floor-tabs {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px;
}
.floor-tab {
  padding: 5px 10px; border-radius: 6px; font-size: 12px;
  background: var(--bg-sunken); border: 1px solid var(--line);
  cursor: pointer;
}
.floor-tab.active { background: var(--ink); color: white; border-color: var(--ink); }
.floor-tab .floor-delete { margin-left: 6px; opacity: 0.5; }
.floor-tab .floor-delete:hover { opacity: 1; }

.tool-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
}
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 8px;
  background: var(--bg-sunken); border: 1px solid transparent;
  font-size: 11px; color: var(--ink-2);
  transition: all 0.12s;
}
.tool-btn svg { width: 20px; height: 20px; fill: currentColor; }
.tool-btn:hover { background: var(--earth-soft); }
.tool-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-2);
  font-weight: 600;
}

.room-types { display: flex; flex-direction: column; gap: 4px; }
.room-type {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px;
  background: var(--bg-sunken); border: 1px solid transparent;
  cursor: pointer; font-size: 13px;
}
.room-type:hover { background: var(--earth-soft); }
.room-type.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.room-type .color { width: 12px; height: 12px; border-radius: 3px; }

/* Fixture palette (plumbing / electrical) */
/* MEP auto-generation panel */
.mep-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin: 8px 0; }
.mep-actions .btn-ghost.small { width: 100%; text-align: center; padding: 6px 4px; }
.btn-ghost.small.block, .btn-primary.small.block { display: block; width: 100%; margin-top: 6px; text-align: center; }
.btn-primary.small { padding: 6px 10px; font-size: 12px; }
.mep-routes-toggle { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; }
.mep-summary { margin-top: 8px; line-height: 1.5; }
.mep-sum-counts { margin-bottom: 4px; }
.mep-sum-line { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.mep-sum-line .mep-sum-len { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink); }
.mep-sum-dot { width: 9px; height: 3px; border-radius: 2px; flex: 0 0 auto; }
.mep-sum-total { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line); }
/* MEP run inspector */
.mep-swatch { width: 18px; height: 6px; border-radius: 3px; display: inline-block; }
.equip-row-total { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }

.fixture-palette { display: flex; flex-direction: column; gap: 12px; }
.fixture-group {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--bg-sunken);
}
.fixture-group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.fixture-group-plumbing   { border-left: 3px solid #2f5f7a; }
.fixture-group-electrical { border-left: 3px solid #b88600; }
.fixture-group-plumbing   .fixture-group-title { color: #2f5f7a; }
.fixture-group-electrical .fixture-group-title { color: #7a5b00; }
.fixture-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}
.fixture-btn {
  display: flex; align-items: center; gap: 6px;
  min-height: 38px;
  padding: 5px 6px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 11.5px;
  line-height: 1.2;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background 0.12s;
}
.fixture-btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.fixture-btn:hover { border-color: var(--line-2); background: white; }
.fixture-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
  color: var(--accent-2);
}
.fixture-btn span {
  flex: 1; min-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
  hyphens: auto;
}

.properties { background: var(--bg-sunken); border-radius: var(--radius-sm); padding: 10px; }
.properties label { font-size: 11px; color: var(--muted); display: block; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 3px; margin-top: 8px; }
.properties label:first-child { margin-top: 0; }
.properties input, .properties select {
  width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px;
  background: white;
}
.properties .prop-grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.properties .rot-control {
  display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center;
}
.properties .rot-control input { text-align: center; }
.properties .rot-control button { padding: 4px 10px; font-size: 13px; }
.properties .prop-flip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.properties .prop-flip-row button { width: 100%; }
.properties .equip-delete { width: 100%; margin-top: 12px; }

/* Soft-warning block shown above door/window properties when constraints fail. */
.prop-issues {
  background: #fef7ec;
  border: 1px solid #f5c478;
  border-left: 3px solid #d97706;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 10px;
  color: #7a4d00;
}
.prop-issues-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.prop-issues-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: #d97706; color: white;
  font-weight: 700; font-size: 11px; line-height: 1;
}
.prop-issues-list {
  margin: 6px 0 0; padding-left: 18px;
  font-size: 12px; line-height: 1.35;
}
.prop-issues-list li { margin: 2px 0; }
.prop-issue-fix {
  margin-top: 8px;
  border-color: #d97706;
  color: #7a4d00;
}
.prop-issue-fix:hover { background: #fff3dc; }

/* Equipment details card (sidebar) */
.equip-card {
  background: white;
  border: 1px solid var(--line);
  border-left: 3px solid var(--earth);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: -10px -10px 12px;
  box-shadow: var(--shadow-sm);
}
.equip-card.equip-plumbing   { border-left-color: #2f5f7a; }
.equip-card.equip-electrical { border-left-color: #b88600; }
.equip-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.equip-symbol {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--bg-sunken);
  flex-shrink: 0;
}
.equip-symbol svg { width: 30px; height: 30px; }
.equip-card.equip-plumbing   .equip-symbol { background: #eaf3f7; }
.equip-card.equip-electrical .equip-symbol { background: #fff5d6; }
.equip-head-text { min-width: 0; }
.equip-name {
  font-size: 14px; font-weight: 700; color: var(--ink);
  line-height: 1.2;
  word-break: break-word;
}
.equip-family {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); font-weight: 600; margin-top: 2px;
}
.equip-card.equip-plumbing   .equip-family { color: #2f5f7a; }
.equip-card.equip-electrical .equip-family { color: #7a5b00; }
.equip-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 5px 0;
  border-top: 1px dashed var(--line);
  font-size: 12px;
}
.equip-row-label { color: var(--muted); text-transform: none; letter-spacing: 0; }
.equip-row-val { font-weight: 600; color: var(--ink); text-align: right; }
.equip-row-val-sm { font-weight: 500; font-size: 11.5px; }

/* Floating hover tooltip on canvas */
.hover-tip {
  position: absolute;
  pointer-events: none;
  z-index: 6;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 140px;
  max-width: 240px;
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--ink);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.10s ease, transform 0.10s ease;
}
.hover-tip.visible { opacity: 1; transform: translateY(0); }
.hover-tip-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}
.hover-tip-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--earth);
  flex-shrink: 0;
}
.hover-tip-head.hover-tip-plumbing   { color: #2f5f7a; }
.hover-tip-head.hover-tip-electrical { color: #7a5b00; }
.hover-tip-head.hover-tip-plumbing   .hover-tip-dot { background: #2f5f7a; }
.hover-tip-head.hover-tip-electrical .hover-tip-dot { background: #b88600; }
.hover-tip-name { font-weight: 700; font-size: 13px; line-height: 1.25; color: var(--ink); }
.hover-tip-meta { color: var(--ink-2); margin-top: 3px; font-variant-numeric: tabular-nums; }
.hover-tip-price {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed var(--line);
  font-size: 11.5px;
  color: var(--ink-2);
}
.hover-tip-price strong { color: var(--ink); }

.stats-panel { background: var(--bg-sunken); border-radius: var(--radius-sm); padding: 10px; font-size: 12px; }
.stats-panel .stat-row { display: flex; justify-content: space-between; padding: 3px 0; }
.stats-panel .stat-row .stat-label { color: var(--muted); }
.stats-panel .stat-row .stat-val { font-weight: 600; }

/* Canvas */
.plan-canvas-wrap {
  display: flex; flex-direction: column;
  background: var(--bg-sunken);
}
.canvas-toolbar {
  display: flex; gap: 6px; align-items: center;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}
.canvas-toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.canvas-toolbar .toggle {
  display: flex; align-items: center; gap: 4px; font-size: 12px;
  padding: 4px 8px; border-radius: 6px; cursor: pointer;
}
.canvas-toolbar .toggle:hover { background: var(--bg-sunken); }
.canvas-toolbar .toggle.inline-select { cursor: default; gap: 6px; }
.canvas-toolbar .toggle.inline-select:hover { background: transparent; }
.canvas-toolbar .inline-style-select {
  font-size: 12px; padding: 3px 6px; border-radius: 5px;
  border: 1px solid var(--line); background: var(--bg-elev);
  cursor: pointer;
}
.canvas-toolbar .zoom-label { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }

.canvas-host {
  flex: 1; position: relative; overflow: hidden;
}
#planCanvas {
  display: block; width: 100%; height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.canvas-hint {
  position: absolute; bottom: 16px; left: 16px;
  background: rgba(28, 28, 26, 0.86); color: white;
  padding: 6px 12px; border-radius: 6px; font-size: 12px;
  pointer-events: none;
  max-width: 320px;
}

/* Floating multi-select action bar (touch-friendly) */
.sel-actionbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 7;
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  box-shadow: var(--shadow);
}
.sel-actionbar[hidden] { display: none; }
.sel-actionbar .sel-count {
  font-size: 12px; font-weight: 700; color: var(--ink-2);
  padding: 0 6px 0 4px; white-space: nowrap;
}
.sel-actionbar button {
  font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg-elev);
  color: var(--ink); cursor: pointer;
}
.sel-actionbar button:hover { background: var(--bg-sunken); }
.sel-actionbar button.danger { color: var(--danger); border-color: var(--danger); }
.sel-actionbar button.danger:hover { background: #fbeae9; }

/* Context menu (right-click / long-press) */
.context-menu {
  position: fixed; z-index: 60;
  min-width: 168px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  box-shadow: var(--shadow-lg);
}
.context-menu-item {
  display: block; width: 100%; text-align: left;
  font-size: 13px; color: var(--ink);
  padding: 7px 10px; border: 0; border-radius: 5px;
  background: transparent; cursor: pointer;
}
.context-menu-item:hover { background: var(--accent-soft); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item.danger:hover { background: #fbeae9; }
.context-menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }

/* Bulk properties header */
.bulk-head { font-size: 14px; font-weight: 700; color: var(--ink); margin-bottom: 2px; }

/* 3D view */
.view3d-layout {
  display: grid; grid-template-columns: 260px 1fr;
  height: calc(100vh - 64px);
}
.view3d-sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
}
.view3d-sidebar h3 { margin-bottom: 6px; }
.view3d-sidebar .control-group { margin-top: 18px; }
.view3d-sidebar .control-group label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 6px; color: var(--ink-2); }
.view3d-sidebar input[type=range] { width: 100%; }
.rot-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.rot-row input[type=range] { flex: 1; }
.rot-label { width: 16px; text-align: center; color: var(--muted); font-size: 14px; }
.rot-val { width: 42px; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; color: var(--ink-2); }
.rot-actions { display: flex; gap: 6px; margin-top: 6px; }
.rot-actions button { flex: 1; }
.rot-actions button.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Sun study controls */
.sun-study .sun-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.sun-study .sun-row input[type=date] { flex: 1; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.sun-study .sun-slider-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sun-study .sun-slider-row input[type=range] { flex: 1; }
.sun-study .sun-ico { width: 16px; text-align: center; color: var(--muted); font-size: 13px; }
.sun-study .sun-val { width: 48px; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; color: var(--ink-2); }
.section-axis-row { display: flex; gap: 14px; margin-bottom: 10px; }
.section-axis-opt { display: inline-flex !important; align-items: center; gap: 4px; margin-bottom: 0 !important; font-weight: 500 !important; cursor: pointer; }
.section-axis-opt input { margin: 0; }
.section-pos-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.section-pos-row input[type=range] { flex: 1; }
.section-pos-val { min-width: 54px; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; color: var(--ink-2); }
.section-invert-label { display: inline-flex !important; align-items: center; gap: 6px; margin-bottom: 0 !important; font-weight: 500 !important; cursor: pointer; }
.view3d-sidebar input[type=number], .view3d-sidebar select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: white;
}
.view3d-sidebar .control-group > label > span:last-child:not(:first-child) {
  float: right; color: var(--ink-2); font-weight: 600;
}
.view3d-sidebar .roof-toggles label {
  display: flex !important; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 6px;
  cursor: pointer;
}
.view3d-sidebar .roof-toggles input { margin: 0; }
.roof-warnings { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.roof-warn {
  font-size: 11px; padding: 6px 8px; border-radius: 6px; line-height: 1.35;
}
.roof-warn-info    { background: #eef4fb; color: #1e3a5f; border-left: 3px solid #3a72c0; }
.roof-warn-warning { background: #fff5db; color: #6b4a00; border-left: 3px solid #c8881a; }
.roof-warn-error   { background: #fde6e0; color: #6b1f12; border-left: 3px solid #c83c1a; }
.roof-summary {
  background: #f6f1e3; border: 1px solid #e6dec5; border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.roof-summary-title {
  font-size: 11px; font-weight: 700; color: #6e5a1c; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 4px;
}
.roof-summary-row {
  display: flex; justify-content: space-between; font-size: 12px;
  color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.roof-summary-row b { color: var(--ink); }
.view3d-canvas-wrap {
  background: linear-gradient(135deg, #d8d3c3, #efece6);
  position: relative;
  /* Hard guarantee against page-scroll bleed: even if a gesture leaks past
     touch-action (mid-drag pointer-loss, edge cases on iOS), the body
     cannot rubber-band because the wrap absorbs it. */
  overscroll-behavior: contain;
  overflow: hidden;
}
.view3d-layout { overscroll-behavior: contain; }
#canvas3d {
  display: block; width: 100%; height: 100%;
  cursor: grab;
  touch-action: none;
  overscroll-behavior: contain;
}
#canvas3d.is-active { cursor: grabbing; }
#canvas3d.is-hand-tool { cursor: grab; cursor: -webkit-grab; }
#canvas3d.is-hand-tool.is-active { cursor: grabbing; cursor: -webkit-grabbing; }
#canvas3d:focus { outline: none; }
/* Legacy class hooks — kept so any external CSS overrides still match. */
#canvas3d.is-panning { cursor: grabbing; }
#canvas3d.is-orbiting { cursor: grabbing; }

/* ---------- Canvas overlay toolbar (Home / Fit / canonical views) ---------- */
.view3d-overlay-toolbar {
  position: absolute;
  top: 12px; left: 12px;
  display: flex; align-items: center; gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.10);
  z-index: 3;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.view3d-overlay-toolbar .overlay-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink, #2a2a2a);
  font-size: 13px; line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s, border-color 0.12s;
}
.view3d-overlay-toolbar .overlay-btn:hover { background: rgba(0, 0, 0, 0.06); }
.view3d-overlay-toolbar .overlay-btn:active { background: var(--accent, #2563eb); color: white; }
.view3d-overlay-toolbar .overlay-btn:focus-visible {
  outline: none; border-color: var(--accent, #2563eb);
}
.view3d-overlay-toolbar .overlay-sep {
  width: 1px; height: 20px; background: rgba(0, 0, 0, 0.12); margin: 0 2px;
}
.view3d-overlay-toolbar .overlay-btn.active {
  background: var(--accent, #2563eb); color: #fff;
}

/* ---------- Overlay popover menu (measure modes) ---------- */
.overlay-menu { position: relative; display: inline-flex; }
.overlay-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 168px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  padding: 5px;
  z-index: 4;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.overlay-popover[hidden] { display: none; }
.overlay-popover .popover-item {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; border-radius: 6px;
  font-size: 13px; color: var(--ink, #2a2a2a);
  background: transparent; border: none; cursor: pointer;
}
.overlay-popover .popover-item:hover { background: rgba(0, 0, 0, 0.06); }
.overlay-popover .popover-item.active { background: var(--accent, #2563eb); color: #fff; }
.overlay-popover .popover-item:disabled { opacity: 0.4; cursor: default; }
.overlay-popover .popover-item:disabled:hover { background: transparent; }
.overlay-popover .popover-sep { height: 1px; background: rgba(0, 0, 0, 0.10); margin: 5px 2px; }
.overlay-popover .popover-hint {
  font-size: 11px; color: var(--ink-2, #555); line-height: 1.35;
  padding: 4px 10px 2px; max-width: 200px;
}

/* ---------- Measure overlay (HTML/SVG annotations) ---------- */
#canvas3d.is-measuring { cursor: crosshair; }
.m3d-overlay {
  position: absolute; inset: 0;
  pointer-events: none; /* purely visual — all input stays on the canvas */
  z-index: 2;
  overflow: hidden;
}
.m3d-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.m3d-labels { position: absolute; inset: 0; }

/* Segments + area outlines. The measurement always draws on top (no
   depth test): a dimension you can't see is useless, so BIM tools paint
   annotations over geometry. */
.m3d-seg    { stroke: var(--accent, #c8521a); stroke-width: 2; fill: none; }
.m3d-rubber { stroke: var(--accent, #c8521a); stroke-width: 1.5; stroke-dasharray: 5 4; fill: none; opacity: 0.85; }
.m3d-pt     { fill: #fff; stroke: var(--accent, #c8521a); stroke-width: 2; }
.m3d-area-fill { fill: rgba(200, 82, 26, 0.16); stroke: var(--accent, #c8521a); stroke-width: 2; }
.m3d-area-fill.is-live { fill: rgba(200, 82, 26, 0.10); }

/* Snap indicator — square = vertex (corner), circle = edge midpoint. */
.m3d-snap { fill: none; stroke: #1a7f37; stroke-width: 2; }
.m3d-snap-vertex { stroke: #1a7f37; }
.m3d-snap-edge   { stroke: #2563eb; }
.m3d-snap-face, .m3d-snap-ground { stroke: #8b8a85; }

.m3d-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: var(--ink, #1c1c1a);
  color: #fff;
  font-size: 11px; font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.m3d-label.is-live { background: var(--accent, #c8521a); }
.m3d-label-area { background: #1a5a2e; }
.m3d-label-total { background: var(--accent-2, #a13f10); }

/* ---------- Element properties card ---------- */
.view3d-props {
  position: absolute;
  left: 12px; bottom: 12px;
  width: 248px; max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 3;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow: hidden;
}
.view3d-props[hidden] { display: none; }
.view3d-props .props-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--ink, #1c1c1a);
  color: #fff;
}
.view3d-props .props-title { font-size: 13px; font-weight: 700; letter-spacing: 0.01em; }
.view3d-props .props-close {
  width: 22px; height: 22px; border-radius: 5px;
  color: rgba(255, 255, 255, 0.85); font-size: 16px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.view3d-props .props-close:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }
.view3d-props .props-body {
  margin: 0;
  padding: 10px 12px;
  display: grid; grid-template-columns: auto 1fr; gap: 5px 12px;
  font-size: 12.5px;
}
.view3d-props .props-body dt { color: var(--ink-2, #555); }
.view3d-props .props-body dd {
  margin: 0; text-align: right; font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--ink, #1c1c1a);
}
.view3d-props .props-foot {
  padding: 8px 12px 10px; border-top: 1px solid var(--line, #e6e2d8);
}
.view3d-props .props-foot .btn-ghost { width: 100%; text-align: center; }

/* ---------- Navigation hint (first-run discoverability) ---------- */
.view3d-nav-hint {
  position: absolute;
  bottom: 14px; left: 50%; transform: translateX(-50%);
  padding: 6px 12px;
  background: rgba(20, 20, 20, 0.78);
  color: #fff;
  font-size: 12px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 2;
  opacity: 1;
  transition: opacity 0.6s ease;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden; text-overflow: ellipsis;
}
.view3d-nav-hint.is-hidden { opacity: 0; }

/* ---------- Walk mode ---------- */
#canvas3d.is-walking { cursor: none; }
.view3d-walk-banner {
  position: absolute;
  top: 12px; left: 50%; transform: translateX(-50%);
  padding: 7px 14px;
  background: rgba(31, 122, 140, 0.92);
  color: #fff;
  font-size: 12px; font-weight: 600;
  border-radius: 999px;
  pointer-events: none;
  z-index: 4;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.view3d-walk-banner[hidden] { display: none; }

/* ---------- ViewCube ---------- */
.view3d-cube-mount {
  position: absolute;
  top: 12px; right: 12px;
  width: 96px; height: 96px;
  z-index: 3;
  pointer-events: none;
}
.view-cube {
  position: relative;
  width: 100%; height: 100%;
  pointer-events: auto;
  user-select: none;
}
.view-cube .vc-stage {
  width: 64px; height: 64px;
  margin: 4px auto 0;
  perspective: 280px;
  perspective-origin: 50% 50%;
}
.view-cube .vc-cube {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  /* Transform is overwritten on every camera 'change' event by navigation3d.js. */
  transform: rotateX(20deg) rotateY(-30deg);
  transition: transform 0.05s linear;
}
.view-cube .vc-face {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em;
  color: #2a2a2a;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.16);
  cursor: pointer;
  backface-visibility: hidden;
  transition: background 0.12s;
}
.view-cube .vc-face:hover { background: var(--accent, #2563eb); color: white; }
.view-cube .vc-face:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.view-cube .vc-front  { transform: translateZ(32px); }
.view-cube .vc-back   { transform: rotateY(180deg) translateZ(32px); }
.view-cube .vc-right  { transform: rotateY( 90deg) translateZ(32px); }
.view-cube .vc-left   { transform: rotateY(-90deg) translateZ(32px); }
.view-cube .vc-top    { transform: rotateX( 90deg) translateZ(32px); }
.view-cube .vc-bottom { transform: rotateX(-90deg) translateZ(32px); }
.view-cube .vc-home {
  position: absolute;
  top: -2px; right: -2px;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 4px;
  font-size: 14px;
  color: var(--ink, #2a2a2a);
  cursor: pointer;
  padding: 0;
}
.view-cube .vc-home:hover { background: var(--accent, #2563eb); color: white; }
.view-cube .vc-home:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }

/* On-screen pan pad overlaying the 3D canvas. Lets the user move the view
   up/down/left/right on touch devices where right-click drag isn't available. */
.view3d-pan-pad {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: grid;
  grid-template-columns: 36px 36px 36px;
  grid-template-rows: 36px 36px 36px;
  gap: 4px;
  z-index: 2;
  user-select: none;
}
.view3d-pan-pad .pan-btn {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  color: var(--ink, #2a2a2a);
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: background 0.12s, transform 0.05s;
  touch-action: manipulation;
  padding: 0;
}
.view3d-pan-pad .pan-btn:hover { background: rgba(255, 255, 255, 1); }
.view3d-pan-pad .pan-btn:active { background: var(--accent, #2563eb); color: white; transform: translateY(1px); }
.view3d-pan-pad .pan-btn:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.view3d-pan-pad .pan-up    { grid-column: 2; grid-row: 1; }
.view3d-pan-pad .pan-left  { grid-column: 1; grid-row: 2; }
.view3d-pan-pad .pan-right { grid-column: 3; grid-row: 2; }
.view3d-pan-pad .pan-down  { grid-column: 2; grid-row: 3; }

/* Filter bar */
.filter-bar {
  display: flex; gap: 10px; margin-bottom: 16px;
}
.filter-bar input, .filter-bar select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; background: white;
}
.filter-bar input { flex: 1; }

/* Material table */
.material-table-wrap, .estimate-table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.material-table, .estimate-table {
  width: 100%; border-collapse: collapse;
}
.material-table th, .estimate-table th {
  text-align: left; padding: 10px 12px;
  background: var(--bg-sunken);
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2);
  border-bottom: 1px solid var(--line);
}
.material-table td, .estimate-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.material-table tr:last-child td, .estimate-table tr:last-child td { border-bottom: none; }
.material-table input, .estimate-table input {
  padding: 4px 8px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; width: 100%;
}
.material-table input:hover, .estimate-table input:hover { border-color: var(--line); background: white; }
.material-table input:focus, .estimate-table input:focus {
  border-color: var(--accent); background: white; outline: none;
}
.material-table .price-input, .estimate-table .price-input,
.material-table .qty-input, .estimate-table .qty-input { text-align: right; font-variant-numeric: tabular-nums; }

/* Devis per-line badges + actions (exclude engine line / remove custom line) */
.estimate-table .actions-col { width: 40px; text-align: center; padding-left: 0; padding-right: 8px; }
.estimate-table .line-action {
  border: 1px solid transparent; background: transparent; color: var(--ink-2);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.estimate-table .line-action:hover { border-color: var(--line); background: white; color: var(--danger, #c0392b); }
.estimate-table tr.custom-line td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.line-badge {
  display: inline-block; vertical-align: middle; margin-left: 6px;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 1px 6px; border-radius: 999px;
}
.line-badge.added { background: var(--earth-soft, #eee7da); color: var(--ink); }
.line-badge.edited { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

.cat-section-row td {
  background: var(--earth-soft); font-weight: 600;
  padding: 8px 12px; color: var(--ink);
  border-bottom: 1px solid var(--line-2);
}

/* Estimate summary */
.estimate-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.summary-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.summary-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.summary-card .value { font-weight: 700; font-size: 22px; margin-top: 4px; }
.summary-card .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.summary-card.accent { border-color: var(--accent); background: var(--accent-soft); }
.summary-card.accent .value { color: var(--accent-2); }

.estimate-totals {
  margin-top: 20px; padding: 18px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.total-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 15px; }
.total-row.grand { font-size: 19px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 12px; }

/* Settings */
.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.setting-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.setting-card h3 { margin-bottom: 10px; }
.account-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.account-row .account-id { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.account-row button { margin-top: 0; }
.setting-card input, .setting-card select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: white;
}
.setting-card button { margin-top: 8px; margin-right: 6px; }
.about { margin-top: 30px; text-align: center; color: var(--muted); }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center;
}
.modal[aria-hidden="false"] { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(28, 28, 26, 0.55);
  backdrop-filter: blur(2px);
}
.modal-body {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  width: min(560px, 92vw);
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-close {
  font-size: 24px; line-height: 1; padding: 4px 10px; border-radius: 6px;
  color: var(--muted);
}
.modal-close:hover { background: var(--bg-sunken); color: var(--ink); }
.modal-content { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
}

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--ink-2); }
.form-row input, .form-row select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px;
  background: white;
}
.form-row input:focus, .form-row select:focus { border-color: var(--accent); outline: none; }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white;
  padding: 10px 18px; border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* Auth — header chip + OTP modal */
.auth-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--bg-elev); color: var(--ink-2);
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  max-width: 200px;
}
.auth-chip:hover { border-color: var(--accent); color: var(--accent); }
.auth-chip.signed-in { border-color: var(--ok); color: var(--ok); background: #f0f7f2; }
.auth-chip-icon { font-size: 13px; line-height: 1; }
.auth-chip-icon.big { font-size: 26px; }
.auth-chip-label { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.auth-modal-body { width: min(420px, 92vw); }
.modal-head p.small { margin: 3px 0 0; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; background: var(--bg-sunken); padding: 4px; border-radius: 8px; }
.auth-tab {
  flex: 1; padding: 8px 12px; border-radius: 6px; font-size: 13px; font-weight: 600;
  color: var(--muted); background: transparent; cursor: pointer;
}
.auth-tab.active { background: var(--bg-elev); color: var(--ink); box-shadow: var(--shadow-sm); }

.auth-hint { margin: 4px 0 16px; }
.btn-primary.full, .btn-ghost.full { width: 100%; justify-content: center; margin-bottom: 8px; }

/* Mobile feature profile (js/platform.js): hide desktop-only surfaces (full 3D
   walkthrough, IFC export, sheet layout) inside the native app / on phones. */
.mobile-profile [data-desktop-only] { display: none !important; }

/* Supplier panel (js/supplier.js) — sponsored placements beside the estimate,
   visually distinct from the quote so they read as ads, never as line items. */
.supplier-panel { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--border, #e6e2d8); }
.supplier-panel-head h3 { margin: 0 0 2px; font-size: 14px; }
.supplier-card { border: 1px solid var(--border, #e6e2d8); border-radius: 10px; padding: 12px 14px; margin-top: 10px; background: var(--bg-sunken, #faf7f0); }
.supplier-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.supplier-name { font-weight: 600; }
.supplier-sponsored { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted, #8b8a85); border: 1px solid var(--border, #e6e2d8); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.supplier-scope { margin: 4px 0 8px; }
.supplier-lead-btn { margin-top: 4px; }

/* Paywall (js/billing.js) */
.pay-sep { text-align: center; font-size: 11px; color: var(--muted); margin: 14px 0 10px; }
.pay-skus { display: grid; gap: 6px; }
.pay-skus label { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 8px 10px;
  border: 1px solid var(--border, #e6e2d8); border-radius: 8px; cursor: pointer; }
.pay-skus input { accent-color: var(--accent); }
.pay-status { margin-top: 10px; font-size: 12px; }
.pay-status.ok { color: #1a7f37; }
.pay-status.error { color: #c0392b; }
#payNumber { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.pay-plan { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--accent); border-radius: 10px; background: rgba(0,0,0,0.02); }
.pay-plan strong { font-size: 15px; }

/* Conversion-outcome capture on the estimate page (the moat's key signal). */
.estimate-outcome { display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  margin: 4px 0 14px; padding: 10px 12px; border: 1px solid var(--border, #e6e2d8); border-radius: 10px; }
.estimate-outcome .outcome-status { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.estimate-outcome select { padding: 6px 8px; border: 1px solid var(--border, #e6e2d8); border-radius: 8px; }
.estimate-outcome .outcome-accepted { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.estimate-outcome input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* Builder profile fields in Settings. */
.setting-card .field { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; font-size: 13px; }
.setting-card .field input { width: 100%; }

.auth-code {
  letter-spacing: 0.5em; text-align: center; font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.auth-sent { margin: 0 0 14px; }
.auth-verify-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

.auth-account { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.auth-account-identity { font-size: 15px; font-weight: 600; color: var(--ink); word-break: break-all; }

.auth-error {
  margin: 14px 0 0; padding: 9px 12px; border-radius: 6px;
  background: #fdeceb; color: var(--danger);
  font-size: 12px; font-weight: 500;
}

/* Print */
@media print {
  .topbar, .plan-sidebar, .canvas-toolbar, .view3d-sidebar,
  .filter-bar, .page-head button, .nav { display: none !important; }
  .view { display: none; }
  .view.active.print-target { display: block; }
  .container { max-width: 100%; padding: 10mm; }
  body { background: white; }
}

/* Responsive */
@media (max-width: 900px) {
  .plan-layout, .view3d-layout { grid-template-columns: 1fr; }
  .plan-sidebar, .view3d-sidebar {
    border-right: none; border-bottom: 1px solid var(--line);
    max-height: 240px;
  }

  /* Mobile topbar — the desktop single row (brand + 8-item nav + right
     controls) is far wider than a phone viewport, which made the whole page
     pan horizontally. Fix it at the source: brand + compact right controls
     share row 1, and the nav drops to its own full-width, horizontally
     scrollable strip on row 2 (min-width:0 is what lets a flex child shrink
     below its content and actually engage overflow-x). */
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 12px; }
  .brand { min-width: auto; flex: 0 1 auto; }
  .brand-sub { display: none; }
  .topbar-right { margin-left: auto; gap: 8px; }
  /* Autosave already persists work and #saveBtn gives explicit feedback, so
     the status text is redundant weight on a phone — drop it for space. */
  .save-status { display: none; }
  /* Icon-only account chip + compact save button to keep row 1 within width. */
  .auth-chip-label { display: none; }
  .auth-chip { padding: 8px; }
  #saveBtn { padding: 8px 12px; }

  .nav {
    order: 10; flex: 1 1 100%; min-width: 0; gap: 2px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn { flex: 0 0 auto; white-space: nowrap; padding: 6px 12px; font-size: 12px; }
}

/* Native shell must never pan horizontally. `clip` (unlike `hidden`) doesn't
   create a scroll container, so the sticky topbar keeps working; it just
   prevents any stray wide descendant from growing the page beyond the
   viewport. The nav keeps its own overflow-x:auto, so it still scrolls. */
#app { overflow-x: clip; }

/* ------------------------------------------------------------------ */
/* New features: schedules tab, wall layers, image trace, multi-select */
/* ------------------------------------------------------------------ */

.sch-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin: 12px 0 0;
}
.sch-tab {
  background: transparent;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  color: #6b6457;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.sch-tab:hover { color: #1c1c1a; }
.sch-tab.active {
  color: #c8521a;
  border-bottom-color: #c8521a;
}

.sch-table-wrap {
  margin-top: 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.sch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sch-table th, .sch-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.sch-table th {
  background: #efece6;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b6457;
}
.sch-table tr:last-child td { border-bottom: none; }

/* Wall layer breakdown in the properties panel */
.wall-layers {
  list-style: none;
  margin: 4px 0 8px;
  padding: 0;
  font-size: 12px;
}
.wall-layers li {
  display: flex;
  align-items: center;
  padding: 3px 0;
  gap: 6px;
}
.layer-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}
.prop-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin: 4px 0;
}

/* Image-trace sidebar block */
.bg-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: #4f4a40;
}
.bg-row input[type="range"] { flex: 1; }

/* Freshness chip in the materials table (last-updated badge) */
.freshness-chip {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  background: #f1ede2;
  color: #6b6457;
  white-space: nowrap;
}
.freshness-chip.stale { background: #fde7c5; color: #7a4a00; }
.freshness-chip.old   { background: #fcd0c0; color: #8c2a10; }

/* Site photos gallery (js/app.js renderPhotos + js/native.js capture) */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.photo-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}
.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
}
.photo-caption {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
}
.photo-del { align-self: flex-end; }
.photo-meta { margin-top: -2px; }
.note-card {
  background: #fffaf0;
  border-color: #efe2c8;
}
.note-card .photo-caption { min-height: 56px; resize: vertical; }
.note-compose {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 12px;
}
.note-input {
  flex: 1;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  resize: vertical;
}
.photo-sync-chip {
  margin-top: 12px;
  padding: 9px 12px;
  background: #f1e7d4;
  border: 1px solid #efe2c8;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--ink2, #4a4a45);
  cursor: pointer;
}
.photo-sync-chip:hover { filter: brightness(0.98); }

/* ======================================================================
   Welcome / first-run sign-in screen (js/welcome.js)
   Mobile-first full-screen overlay; two-column on wide viewports.
   ====================================================================== */
.welcome {
  position: fixed; inset: 0; z-index: 200;
  display: flex; justify-content: center;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(1200px 600px at 50% -10%, #fff 0%, rgba(255,255,255,0) 60%),
    linear-gradient(160deg, var(--earth-soft) 0%, var(--bg) 42%, var(--accent-soft) 130%);
  opacity: 0; transition: opacity 0.25s ease;
  padding:
    calc(env(safe-area-inset-top) + 20px) 18px
    calc(env(safe-area-inset-bottom) + 24px);
}
.welcome.is-open { opacity: 1; }
.welcome[hidden] { display: none; }

.welcome-panel {
  width: 100%; max-width: 460px; margin: auto;
  display: flex; flex-direction: column; gap: 22px;
}

/* --- Brand + showcase --- */
.welcome-hero { display: flex; flex-direction: column; gap: 18px; }
.welcome-brand { display: flex; align-items: center; gap: 11px; }
.welcome-brand .logo { width: 44px; height: 44px; border-radius: 12px; font-size: 15px; }
.welcome-brand-name { font-weight: 800; font-size: 20px; letter-spacing: -0.01em; }
.welcome-brand-sub { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.welcome-brand .lang-select { margin-left: auto; }

.welcome-showcase { display: flex; flex-direction: column; gap: 14px; }
.welcome-track {
  display: flex; width: 100%;
  transition: transform 0.38s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
}
.welcome-slide {
  min-width: 100%; box-sizing: border-box;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 0 2px;
}
.welcome-art {
  width: 100%; aspect-ratio: 360 / 248;
  background: #f3ece0; border: 1px solid var(--line-2);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow);
}
.welcome-art svg { display: block; width: 100%; height: 100%; }
.welcome-caption { text-align: center; padding: 0 8px; }
.welcome-caption h3 { font-size: 17px; }
.welcome-caption p { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; }

.welcome-dots { display: flex; justify-content: center; gap: 7px; }
.welcome-dots button {
  width: 7px; height: 7px; padding: 0; border-radius: 99px;
  background: var(--line-2); transition: background 0.2s, width 0.2s;
}
.welcome-dots button[aria-selected="true"] { width: 20px; background: var(--accent); }

/* Estimate slide — styled "devis" card instead of an SVG */
.welcome-art-estimate { display: flex; align-items: center; justify-content: center; padding: 16px; }
.welcome-devis {
  width: 100%; max-width: 300px; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 14px 14px 12px;
}
.welcome-devis-head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 13px; margin-bottom: 10px;
}
.welcome-devis-tag {
  font-size: 10px; font-weight: 700; color: var(--accent-2);
  background: var(--accent-soft); border-radius: 99px; padding: 2px 8px;
}
.welcome-devis-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.welcome-devis-rows li {
  display: grid; grid-template-columns: 74px 1fr auto; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--ink-2);
}
.welcome-devis-rows li i {
  height: 6px; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--earth));
  width: var(--w); min-width: 8px;
}
.welcome-devis-rows li b { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.welcome-devis-total {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2);
}
.welcome-devis-total b { font-size: 15px; color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* --- Sign-in card --- */
.welcome-auth-card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 20px 18px 16px;
}
.welcome-auth-card h2 { font-size: 18px; }
.welcome-auth-card > p { margin: 4px 0 14px; }
.welcome-auth-card .auth-tabs { margin-bottom: 12px; }
.welcome-auth-card .form-row { margin-bottom: 12px; }

.welcome-skip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 100%; margin-top: 14px; padding: 10px;
  border-radius: var(--radius); color: var(--ink-2); font-weight: 600;
  transition: background 0.15s;
}
.welcome-skip:hover { background: var(--bg-sunken); }
.welcome-skip small { font-weight: 400; font-size: 11px; }

/* --- Wide viewports: two columns side by side --- */
@media (min-width: 860px) {
  .welcome-panel {
    max-width: 940px; flex-direction: row; align-items: center; gap: 48px;
  }
  /* Sign-in/sign-up card first (leftmost); carousel to its right. */
  .welcome-auth { order: 0; flex: 0.9; min-width: 340px; }
  .welcome-hero { order: 1; flex: 1.1; }
  .welcome-brand-name { font-size: 24px; }
}

/* Devis adjust bar (ceiling / margin / contingency / reset) */
.estimate-adjust { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 6px 0 14px; padding: 10px 14px; background: var(--sunken, #efece6); border-radius: 10px; font-size: 13px; }
.estimate-adjust label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink2, #4a4a47); font-weight: 600; }
.estimate-adjust input[type="number"] { width: 60px; }
.estimate-adjust select { max-width: 200px; }
