:root {
  --wood-light: #d6a878;
  --wood-mid: #a5733b;
  --wood-dark: #6b4523;
  --wood-deep: #4a2f17;
  --wood-accent: #8b5a2b;
  --bg: #fbf7f2;
  --bg-gradient: linear-gradient(135deg, #fbf7f2 0%, #f1e4d2 100%);
  --surface: #ffffff;
  --surface-2: #fdf9f4;
  --surface-variant: #f4e7d2;
  --border: #e8dcc8;
  --warn: #c84a4a;
  --info: #3a6fb0;
  --ok: #4a9e5f;
  --text: #2a1b10;
  --text-muted: #6e5a48;
  --shadow-sm: 0 1px 3px rgba(74,47,23,.08), 0 1px 2px rgba(74,47,23,.06);
  --shadow-md: 0 4px 10px rgba(74,47,23,.10), 0 2px 4px rgba(74,47,23,.06);
  --shadow-lg: 0 12px 32px rgba(74,47,23,.14), 0 4px 8px rgba(74,47,23,.08);
  --radius: 14px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  body.auto-dark, body.dark-mode {
    --bg: #1a130d;
    --bg-gradient: linear-gradient(135deg, #1a130d 0%, #2a1f15 100%);
    --surface: #2a1f15;
    --surface-2: #221913;
    --surface-variant: #3a2b1f;
    --border: #4a3624;
    --text: #f4e7d2;
    --text-muted: #ccb89e;
  }
}
body.dark-mode {
  --bg: #1a130d;
  --bg-gradient: linear-gradient(135deg, #1a130d 0%, #2a1f15 100%);
  --surface: #2a1f15;
  --surface-2: #221913;
  --surface-variant: #3a2b1f;
  --border: #4a3624;
  --text: #f4e7d2;
  --text-muted: #ccb89e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, sans-serif;
  background: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}
body { display: flex; flex-direction: column; }

/* ============ HEADER ============ */
.app-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: linear-gradient(135deg, var(--wood-mid) 0%, var(--wood-dark) 100%);
  color: #fff;
  padding: .85rem 1rem;
  padding-top: calc(.85rem + env(safe-area-inset-top));
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.header-subtitle {
  font-size: .72rem;
  opacity: .8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  background: rgba(255,255,255,.18);
  backdrop-filter: blur(6px);
  border: 0;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.icon-btn:active { background: rgba(255,255,255,.35); }
.header-actions { display: flex; gap: .35rem; }

main {
  flex: 1;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

/* ============ HEADER BRAND ============ */
.header-brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex: 1;
  overflow: hidden;
}
.brand-icon {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,.22);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* ============ HERO ============ */
.hero {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--wood-mid);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  top: -50px;
  right: -50px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(165,115,59,.15) 0%, transparent 70%);
  pointer-events: none;
}
.hero-text { position: relative; z-index: 1; }
.hero h2 { margin: 0 0 .35rem; color: var(--wood-dark); font-size: 1.35rem; font-weight: 700; }
.hero p { margin: 0; color: var(--text-muted); font-size: .92rem; }
.hero-stats {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
  position: relative;
  z-index: 1;
}
.hero-stats > div {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: .5rem .85rem;
  border-radius: 10px;
  font-size: .78rem;
}
.hero-stats strong {
  display: block;
  font-size: 1.15rem;
  color: var(--wood-dark);
  font-weight: 700;
}

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 3rem 1.25rem;
  background: var(--surface);
  border-radius: var(--radius);
  margin: 1rem 0;
  border: 2px dashed var(--border);
}
.empty-icon { font-size: 4rem; margin-bottom: .5rem; }
.empty-state h3 { color: var(--wood-dark); margin: .5rem 0; }
.empty-state p { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ============ INFO CARD ============ */
.info-card {
  background: linear-gradient(135deg, rgba(58,111,176,.05), rgba(58,111,176,.1));
  border-left: 4px solid var(--info);
}
.info-card p { margin: 0; }

/* ============ TOOLBAR / SEARCH ============ */
.toolbar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select {
  padding: .6rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .95rem;
  flex: 1;
  min-width: 0;
}
.toolbar input { flex: 2; }

/* ============ CARDS ============ */
.cards { display: flex; flex-direction: column; gap: .85rem; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: .85rem;
  border: 1px solid var(--border);
}
.card h3 {
  margin: 0 0 .8rem;
  color: var(--wood-dark);
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.card label {
  display: block;
  margin: .55rem 0;
  font-size: .85rem;
  color: var(--text-muted);
  font-weight: 500;
}
.card input[type="text"],
.card input[type="number"],
.card input[type="search"],
.card select {
  width: 100%;
  padding: .65rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--surface-2);
  color: var(--text);
  margin-top: .25rem;
  transition: border-color .15s, box-shadow .15s;
}
.card input:focus, .card select:focus {
  outline: none;
  border-color: var(--wood-mid);
  box-shadow: 0 0 0 3px rgba(165,115,59,.15);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.info-strip {
  background: var(--surface-variant);
  padding: .75rem;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  margin: .75rem 0;
  font-size: .9rem;
  flex-wrap: wrap;
  gap: .5rem;
}
.info-strip div { color: var(--text-muted); }
.info-strip strong { color: var(--text); display: block; font-size: .75rem; }

/* ============ SWITCH ============ */
.switch {
  display: flex;
  align-items: center;
  gap: .65rem;
  cursor: pointer;
  margin: 1rem 0 .5rem !important;
  font-size: .95rem;
  color: var(--text);
}
.switch input { display: none; }
.switch-slider {
  width: 44px;
  height: 24px;
  background: #ccc;
  border-radius: 24px;
  position: relative;
  flex-shrink: 0;
  transition: background .2s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform .2s;
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .switch-slider { background: var(--wood-mid); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
}
.row-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: .5rem 0;
  align-items: flex-end;
}
.row-wrap .grow { flex: 1; }
.presets { gap: .4rem; }

/* ============ BUTTONS ============ */
.btn-primary, .btn-secondary {
  border: 0;
  padding: .7rem 1.15rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  transition: transform .1s, box-shadow .15s, background .15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
}
.btn-primary {
  background: linear-gradient(135deg, var(--wood-mid), var(--wood-dark));
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:active { transform: scale(.98); }
.btn-primary:hover { box-shadow: var(--shadow-md); }
.btn-primary.big { width: 100%; padding: .85rem; font-size: 1rem; }
.btn-secondary {
  background: var(--surface-variant);
  color: var(--wood-dark);
}
.btn-secondary:active { transform: scale(.98); }
.btn-secondary:hover { background: var(--border); }

.chip-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--wood-dark);
  border-radius: 22px;
  padding: .45rem .9rem;
  font-size: .85rem;
  cursor: pointer;
  font-weight: 500;
  transition: all .12s;
}
.chip-btn:hover { background: var(--surface-variant); border-color: var(--wood-mid); }
.chip-btn.warn { color: var(--warn); border-color: var(--warn); background: transparent; }
.chip-btn.warn:hover { background: rgba(200,74,74,.08); }

.bottom-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: .85rem 0;
  padding-bottom: calc(.85rem + env(safe-area-inset-bottom));
  margin-top: 1rem;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  z-index: 10;
}
.bottom-actions button { flex: 1; min-width: 70px; }

/* ============ TABS ============ */
.tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: .75rem 1rem;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  font-family: inherit;
  white-space: nowrap;
  margin-bottom: -2px;
  transition: all .15s;
}
.tab.active {
  color: var(--wood-dark);
  border-bottom-color: var(--wood-mid);
  font-weight: 700;
}
.tab:hover { color: var(--wood-dark); }

/* ============ FAB ============ */
.fab-stack {
  position: fixed;
  bottom: 1.5rem;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  align-items: flex-end;
  z-index: 50;
}
.fab {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wood-mid), var(--wood-dark));
  color: #fff;
  font-size: 2rem;
  border: 0;
  box-shadow: 0 6px 18px rgba(74,47,23,.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab-secondary {
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
  background: var(--surface);
  color: var(--wood-dark);
  border: 1.5px solid var(--border);
}

/* ============ PROJECT CARDS ============ */
.project-card {
  cursor: pointer;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--wood-mid);
  transition: transform .12s, box-shadow .15s;
}
.project-card:active { transform: translateY(1px); }
.project-card:hover { box-shadow: var(--shadow-md); }
.project-card h3 { margin: 0 0 .25rem; padding-right: 110px; }
.project-card p { margin: .15rem 0; color: var(--text-muted); font-size: .85rem; }
.project-card .meta {
  display: flex;
  justify-content: space-between;
  margin-top: .65rem;
  font-size: .8rem;
  color: var(--text-muted);
  align-items: center;
}
.project-card .actions {
  position: absolute;
  top: .85rem;
  right: .85rem;
  display: flex;
  gap: .35rem;
}
.project-card .actions button {
  background: var(--surface-variant);
  border: 0;
  color: var(--text-muted);
  font-size: 1rem;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.project-card .actions button:hover { background: var(--border); }
.project-card .actions .delete:hover { background: rgba(200,74,74,.15); color: var(--warn); }

.project-card .stats {
  display: flex;
  gap: .85rem;
  margin-top: .5rem;
  font-size: .8rem;
}
.project-card .stats span { color: var(--text-muted); }
.project-card .stats strong { color: var(--wood-dark); }

/* ============ ROOM CARD ============ */
.room-card {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .85rem;
  margin: .6rem 0;
  border: 1px solid var(--border);
}
.room-card .room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .3rem;
  margin-bottom: .35rem;
}
.room-card .room-header strong { font-size: 1rem; }
.room-card .room-actions {
  display: flex;
  gap: .3rem;
}
.room-card .room-actions button {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--wood-dark);
  border-radius: 6px;
  padding: .35rem .6rem;
  cursor: pointer;
  font-size: .8rem;
  transition: all .12s;
}
.room-card .room-actions button:hover { background: var(--wood-mid); color: white; }

.chip {
  display: inline-block;
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  border-radius: 16px;
  padding: .2rem .75rem;
  font-size: .8rem;
  margin: .15rem .15rem 0 0;
  cursor: pointer;
  font-weight: 500;
  transition: all .12s;
}
.chip.active {
  background: var(--wood-mid);
  color: #fff;
  border-color: var(--wood-mid);
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  font-size: .95rem;
}

/* ============ CATALOG ============ */
.filter-bar {
  position: sticky;
  top: 60px;
  top: calc(60px + env(safe-area-inset-top));
  background: var(--bg);
  z-index: 50;
  padding: .5rem 0;
  margin-bottom: .5rem;
}
.filter-bar input[type="search"] {
  width: 100%;
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
}
.filters-details {
  margin-top: .5rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  border: 1px solid var(--border);
}
.filters-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--wood-dark);
  padding: .35rem 0;
  user-select: none;
}
.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-top: .5rem;
  font-size: .85rem;
}
.filter-row label { color: var(--text-muted); display: block; }
.filter-row label.full { grid-column: span 1; }
.filter-row .inline {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  grid-column: span 1;
}
.filter-row input, .filter-row select {
  width: 100%;
  padding: .45rem .6rem;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  margin-top: .15rem;
  background: var(--surface-2);
  color: var(--text);
  font-size: .85rem;
}
.cat-counter {
  margin-top: .5rem;
  color: var(--wood-dark);
  font-size: .8rem;
  font-weight: 600;
}

.product-card {
  background: var(--surface);
  padding: 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  border-left: 4px solid var(--wood-light);
  transition: transform .12s, box-shadow .15s, border-left-color .15s;
}
.product-card:hover { border-left-color: var(--wood-mid); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.product-card h4 { margin: 0 0 .2rem; font-size: .95rem; color: var(--wood-dark); }
.product-card .dims { font-size: .82rem; color: var(--text-muted); }
.product-card .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .35rem;
  font-size: .78rem;
}
.product-card .meta-row span {
  background: var(--surface-variant);
  padding: .15rem .55rem;
  border-radius: 12px;
  color: var(--text-muted);
}
.product-card .price {
  color: var(--wood-mid);
  font-weight: 700;
  margin-top: .5rem;
  font-size: .95rem;
}
.product-card .water { background: rgba(58,111,176,.15) !important; color: var(--info) !important; font-weight: 600; }

/* ============ CANVAS ============ */
.canvas-wrap {
  width: 100%;
  height: 50vh;
  min-height: 280px;
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface-variant) 100%);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}
.canvas-large { height: 55vh; }
.polygon-wrap { height: 58vh; }
.canvas-hint {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: rgba(0,0,0,.65);
  color: white;
  padding: .35rem .65rem;
  border-radius: 14px;
  font-size: .72rem;
  margin: 0;
  pointer-events: none;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.legend {
  position: absolute;
  bottom: .5rem;
  left: .5rem;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  padding: .4rem .65rem;
  border-radius: 8px;
  font-size: .72rem;
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  box-shadow: var(--shadow-sm);
}
.legend span { display: inline-flex; align-items: center; gap: .25rem; color: var(--text); }
.legend i { width: 12px; height: 12px; display: inline-block; border-radius: 2px; }

#viz-stats div { margin: .25rem 0; font-size: .9rem; }
#viz-stats .warn { color: var(--warn); font-weight: 700; padding: .35rem .5rem; background: rgba(200,74,74,.1); border-radius: 6px; margin-top: .5rem; }

/* ============ PANEL DETAIL ============ */
.panel-detail {
  background: linear-gradient(135deg, var(--wood-mid), var(--wood-dark));
  color: white;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-top: .85rem;
  box-shadow: var(--shadow-lg);
  animation: slide-up .2s ease;
}
.panel-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .65rem;
}
.panel-detail-header h3 {
  margin: 0;
  color: white;
  font-size: 1.05rem;
}
.icon-btn-light {
  background: rgba(255,255,255,.2);
  border: 0;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
}
.panel-detail-body { font-size: .92rem; }
.dir-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin: .5rem 0;
}
.dir-label { font-weight: 600; font-size: .9rem; }
.dir-chips {
  display: flex;
  gap: .3rem;
  align-items: center;
  flex-wrap: wrap;
}
.dir-chip {
  display: inline-block;
  padding: .3rem .6rem;
  border-radius: 14px;
  background: rgba(214,168,120,0.18);
  border: 1px solid rgba(165,115,59,0.3);
  cursor: pointer;
  font-size: .85rem;
  user-select: none;
}
.dir-chip.active {
  background: #C99D6B;
  color: white;
  border-color: #6B4523;
  font-weight: bold;
}
.dir-chips .angle {
  width: 4rem;
  padding: .25rem .35rem;
  border-radius: 8px;
  border: 1px solid rgba(165,115,59,0.4);
}
.dir-preview {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px solid rgba(165,115,59,0.3);
  background: #faf5ec;
}
.pd-canvas {
  width: 100%;
  height: 180px;
  background: rgba(255,255,255,0.10);
  border-radius: 10px;
  margin: .5rem 0;
  display: block;
}
.panel-detail-body .pd-row {
  display: flex;
  justify-content: space-between;
  padding: .4rem 0;
  border-bottom: 1px solid rgba(255,255,255,.18);
}
.panel-detail-body .pd-row:last-child { border: 0; }
.panel-detail-body .pd-row span { opacity: .85; }
.panel-detail-body .pd-row strong { font-weight: 700; text-align: right; }
.panel-detail-body .pd-instruction {
  background: rgba(0,0,0,.25);
  margin-top: .6rem;
  padding: .7rem;
  border-radius: 8px;
  font-size: .88rem;
  line-height: 1.5;
}
.panel-detail-body .pd-instruction strong { color: #FFE680; }

@keyframes slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ POLYGON FOOTER ============ */
.polygon-toolbar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: .65rem .85rem;
  margin-bottom: .65rem;
  box-shadow: var(--shadow-sm);
}
.mode-row {
  background: var(--surface-2);
  padding: .35rem .5rem;
  border-radius: 10px;
  margin-bottom: .5rem;
  border: 1px solid var(--border);
}
.mode-btn { background: transparent; border: 1.5px solid transparent; }
.mode-btn.active {
  background: var(--wood-mid);
  color: white;
  border-color: var(--wood-dark);
}
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .85rem;
  color: var(--text-muted);
  padding: 0 .5rem;
}
.hint-label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 500;
}
.type-btn { font-size: .85rem; }
.type-btn.active {
  background: var(--info);
  color: white;
  border-color: var(--info);
}
.opening-type-row {
  background: rgba(58,111,176,0.08);
  padding: .35rem .55rem;
  border-radius: 10px;
  border: 1px solid rgba(58,111,176,0.25);
  margin-bottom: .5rem;
}
.polygon-footer {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: .85rem;
  box-shadow: var(--shadow-md);
}
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-bottom: 1rem;
  text-align: center;
}
.stats-row > div {
  background: var(--surface-2);
  padding: .65rem .5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.stats-row span {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.stats-row strong {
  display: block;
  font-size: 1.1rem;
  color: var(--wood-dark);
  font-weight: 700;
  margin-top: .2rem;
}

/* ============ SWITCH LABEL ============ */
.switch-label { font-weight: 500; }

/* ============ MINI PREVIEW ============ */
.room-preview {
  width: 100%;
  height: 80px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-top: .5rem;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}

.hint { color: var(--text-muted); font-size: .8rem; margin: .3rem 0; }
.stats { color: var(--wood-dark); font-size: .9rem; margin: .3rem 0; }
.big-stat { font-size: 1.05rem; font-weight: 700; color: var(--wood-dark); }

/* ============ MODAL ============ */
.modal-host[hidden] { display: none !important; }
.modal-host {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: modal-in .2s ease;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-width: 280px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
}
.modal-content h2 {
  margin: 0 0 .85rem;
  color: var(--wood-dark);
  font-size: 1.2rem;
}
.modal-content label {
  display: block;
  margin: .65rem 0;
  font-size: .85rem;
  color: var(--text-muted);
  font-weight: 500;
}
.modal-content input[type=text],
.modal-content input[type=number] {
  width: 100%;
  padding: .65rem .8rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  margin-top: .25rem;
  font-size: 1rem;
  background: var(--surface-2);
  color: var(--text);
}
.modal-content input:focus { outline: none; border-color: var(--wood-mid); }
.modal-content .actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.2rem;
}
.modal-content .radio-group {
  display: flex;
  gap: 1rem;
  margin: .5rem 0;
}
.modal-content .radio-group label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin: 0;
  cursor: pointer;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(.97); }
  to { opacity: 1; transform: scale(1); }
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 5rem;
  bottom: calc(5rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--wood-deep);
  color: #fff;
  padding: .85rem 1.3rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: toast-fade 3s ease forwards;
  pointer-events: none;
}
@keyframes toast-fade {
  0% { opacity: 0; transform: translate(-50%, 20px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* ============ COST SUMMARY ============ */
.cost-summary {
  background: var(--surface-2);
  padding: 1rem;
  border-radius: var(--radius-sm);
  margin-top: 1rem;
}
.cost-summary .row {
  display: flex;
  justify-content: space-between;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.cost-summary .row:last-child { border: 0; }
.cost-summary .total {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--wood-dark);
  border-top: 2px solid var(--wood-mid);
  margin-top: .5rem;
  padding-top: .5rem;
}

/* ============ MEDIA QUERIES ============ */
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .filter-bar { top: 56px; }
  .filter-row { grid-template-columns: 1fr; }
  .project-card h3 { padding-right: 80px; }
  main { padding: .85rem; }
  .card { padding: .95rem; }
  .canvas-wrap { height: 45vh; }
}
@media (min-width: 900px) {
  .cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .product-card { display: flex; flex-direction: column; }
}
