:root {
  --bg: #0a0e15;
  --card: #111827;
  --card-2: #151f31;
  --muted: #8ea0bb;
  --text: #eef4ff;
  --line: rgba(255,255,255,.09);
  --accent: #dc2626;
  --accent-2: #f97316;
  --danger: #ef4444;
  --ok: #22c55e;
  --shadow: 0 20px 60px rgba(0,0,0,.35);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, rgba(220,38,38,.18), transparent 38%), var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, select { font: inherit; }
button, .file-label {
  border: 0;
  border-radius: 12px;
  color: var(--text);
  background: #263247;
  padding: 10px 13px;
  cursor: pointer;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
  user-select: none;
}
button:hover, .file-label:hover { transform: translateY(-1px); background: #303d55; }
button:active { transform: translateY(0); }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-weight: 850; }
button.danger { background: rgba(239,68,68,.15); color: #fecaca; border: 1px solid rgba(239,68,68,.35); }
button.ghost, .file-label { background: rgba(255,255,255,.06); border: 1px solid var(--line); }
button.small, .file-label.small { padding: 7px 10px; border-radius: 10px; font-size: 13px; }
button.active, .tab.active, .view-btn.active { background: rgba(220,38,38,.22); border-color: rgba(220,38,38,.55); color: #fff; }
button:disabled { opacity: .55; cursor: not-allowed; }

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  padding: 16px;
  gap: 14px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: rgba(17,24,39,.78);
  backdrop-filter: blur(16px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.topbar-start {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 22px;
}
.brand-block h1, .project-card h2 { margin: 0; }
.brand-block p { margin: 4px 0 0; color: var(--muted); }
.suite-nav {
  display: inline-grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, max-content);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(3,7,18,.5);
}
.suite-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  transition: color .12s ease, background .12s ease;
}
.suite-link:hover { color: #fff; background: rgba(255,255,255,.07); }
.suite-link.active { color: #fff; background: linear-gradient(135deg, rgba(220,38,38,.88), rgba(249,115,22,.82)); }
.suite-link:focus-visible { outline: 3px solid rgba(249,115,22,.3); outline-offset: 2px; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .14em;
  font-size: 11px;
  font-weight: 900;
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.workspace { display: grid; grid-template-columns: 390px 1fr; gap: 14px; min-height: 0; }
.panel, .viewer-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17,24,39,.84);
  box-shadow: var(--shadow);
  min-height: 0;
}
.panel { overflow: auto; padding: 14px; }
.viewer-card { overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.project-card {
  background: linear-gradient(145deg, rgba(255,255,255,.08), rgba(255,255,255,.03));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}
.project-title { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.metric-grid div { background: rgba(0,0,0,.22); border: 1px solid var(--line); border-radius: 13px; padding: 10px; }
.metric-grid span { display: block; font-weight: 900; font-size: 20px; }
.metric-grid small { color: var(--muted); }
.tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.tab { border: 1px solid var(--line); background: rgba(255,255,255,.05); font-weight: 800; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
.pane-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 10px; }
.pane-head h3, .form-card h4 { margin: 0; }
.list { display: grid; gap: 8px; margin-bottom: 14px; }
.list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.045);
  border-radius: 14px;
  padding: 10px;
}
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: rgba(255,255,255,.075); }
.list-item.active { outline: 2px solid rgba(220,38,38,.45); background: rgba(220,38,38,.10); }
.list-item strong { display: block; margin-bottom: 2px; }
.list-item small { color: var(--muted); line-height: 1.35; }
.list-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.swatch { width: 15px; height: 15px; border-radius: 5px; border: 1px solid rgba(255,255,255,.45); display: inline-block; margin-right: 6px; vertical-align: -2px; }
.shape-pill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; font-size: 11px; color: var(--muted); }
.form-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.20);
  border-radius: 16px;
  padding: 13px;
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select {
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(3,7,18,.72);
  color: var(--text);
  border-radius: 11px;
  padding: 10px 11px;
  outline: none;
}
input:focus, select:focus { border-color: rgba(220,38,38,.72); box-shadow: 0 0 0 3px rgba(220,38,38,.13); }
input[type="color"] { padding: 3px; height: 42px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mount-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -2px;
}
.mount-presets button {
  font-size: 12px;
  padding: 7px 9px;
}

.wall-editor {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  border-radius: 14px;
  padding: 11px;
}
.wall-editor-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
}
.wall-editor-head span { color: var(--muted); font-size: 12px; font-weight: 700; }
.wall-toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.wall-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(3,7,18,.45);
  border-radius: 12px;
  padding: 9px 10px;
  cursor: pointer;
}
.wall-toggle input { width: auto; }
.wall-toggle span { color: var(--text); font-size: 13px; }
.wall-toggle small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.wall-toggle:has(input:checked) { border-color: rgba(34,211,238,.46); background: rgba(34,211,238,.10); }

.hint { color: var(--muted); font-size: 12px; margin: 0; line-height: 1.4; }
.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,.16);
}
.view-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.view-btn { border: 1px solid var(--line); background: rgba(255,255,255,.055); font-weight: 850; }
.viewer { position: relative; min-height: 0; height: 100%; background: #070a10; }
#planCanvas, .three-view, .empty-state { position: absolute; inset: 0; width: 100%; height: 100%; }
#planCanvas { display: block; touch-action: none; }
.three-view { outline: none; }
.hidden { display: none !important; }
.empty-state { display: grid; place-items: center; text-align: center; padding: 30px; color: var(--muted); }
.empty-state h3 { color: var(--text); margin-bottom: 4px; }
.mobile-hint { display: none; }

.canvas-tooltip {
  position: absolute;
  z-index: 20;
  max-width: 260px;
  pointer-events: none;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(3,7,18,.92);
  box-shadow: var(--shadow);
  border-radius: 12px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.35;
}
.canvas-tooltip strong { display: block; font-size: 13px; margin-bottom: 3px; }

.three-hud {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 18;
  width: min(330px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  overflow: auto;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(7,10,16,.82);
  backdrop-filter: blur(14px);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.hud-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.hud-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.room-visibility { display: grid; gap: 6px; }
.room-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.055);
  border-radius: 12px;
  padding: 8px 9px;
  color: var(--text);
  font-size: 13px;
}
.room-toggle input { width: auto; accent-color: var(--accent); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.58);
  backdrop-filter: blur(5px);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(17,24,39,.96);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; }
.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}
.modal-form { background: rgba(0,0,0,.18); }
.preset-card { width: min(920px, 100%); }
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.preset-item {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.055);
  padding: 12px;
  border-radius: 16px;
  min-height: 98px;
}
.preset-item .emoji { font-size: 28px; display: block; margin-bottom: 8px; }
.preset-item strong { display: block; }
.preset-item small { color: var(--muted); }

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  background: rgba(255,255,255,.055);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}
.save-status[data-state="ok"] { color: #bbf7d0; border-color: rgba(34,197,94,.35); background: rgba(34,197,94,.11); }
.save-status[data-state="saving"] { color: #fed7aa; border-color: rgba(249,115,22,.35); background: rgba(249,115,22,.10); }
.save-status[data-state="error"], .save-status[data-state="local"] { color: #fecaca; border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.10); }
.setup-warning {
  border: 1px solid rgba(249,115,22,.45);
  background: rgba(249,115,22,.12);
  color: #ffedd5;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
  line-height: 1.45;
}
.setup-warning a { color: white; font-weight: 900; }

@media (max-width: 1450px) {
  .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
  .topbar-start { width: 100%; justify-content: space-between; }
  .top-actions { width: 100%; justify-content: stretch; }
  .top-actions button, .top-actions .file-label { flex: 1 1 auto; text-align: center; }
}

@media (max-width: 1050px) {
  body { overflow: auto; }
  .app-shell { min-height: 100%; height: auto; padding: 10px; }
  .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
  .topbar-start { width: 100%; justify-content: space-between; }
  .top-actions { width: 100%; justify-content: stretch; }
  .top-actions button, .top-actions .file-label { flex: 1 1 auto; text-align: center; }
  .workspace { grid-template-columns: 1fr; }
  .panel { max-height: none; order: 2; }
  .viewer-card { height: 72vh; min-height: 520px; order: 1; }
  .viewer-toolbar { align-items: stretch; flex-direction: column; }
  .view-buttons { display: grid; grid-template-columns: repeat(3, 1fr); }
  .view-btn, .ghost.small { padding-left: 8px; padding-right: 8px; }
  .mobile-hint { display: block; position: sticky; bottom: 0; padding: 9px 12px; background: rgba(220,38,38,.92); color: white; font-weight: 800; text-align: center; z-index: 20; }
  .save-status { width: 100%; justify-content: center; }
}

@media (max-width: 540px) {
  .form-row, .metric-grid, .tabs { grid-template-columns: 1fr; }
  .topbar-start { align-items: stretch; flex-direction: column; gap: 12px; }
  .suite-nav { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .viewer-card { height: 65vh; min-height: 450px; }
  .view-buttons { grid-template-columns: 1fr; }
  .brand-block h1 { font-size: 24px; }
  .modal { padding: 8px; }
  .modal-card { max-height: 94vh; border-radius: 18px; }
  .three-hud { top: 8px; left: 8px; width: calc(100% - 16px); }
}

.preset-category {
  grid-column: 1 / -1;
  margin: 14px 0 2px;
  font-size: .82rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.preset-controls {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}
.preset-room-filter {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.preset-room-chip {
  white-space: nowrap;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.055);
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}
.preset-room-chip.active {
  background: rgba(220,38,38,.22);
  border-color: rgba(220,38,38,.55);
}
.preset-category {
  display: flex;
  align-items: center;
  gap: 8px;
}
.preset-category span { color: #fff; }
.preset-category small {
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 800;
}
.preset-empty { grid-column: 1 / -1; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.045); }
