/* NexDesign — floor plan editor */

:root {
  --bg: #0d1116;
  --chrome: #151b22;
  --chrome-2: #1b222b;
  --line: #262f3a;
  --line-soft: #1f2731;
  --ink: #d9e1ea;
  --ink-dim: #8794a4;
  --ink-faint: #61707f;
  --accent: #2b8ef0;
  --accent-ink: #ffffff;
  --accent-soft: rgba(43, 142, 240, .14);
  --warn: #e8843c;
  --ok: #3fb977;
  --radius: 7px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.45 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--chrome-2);
  font: 11px/1.5 var(--mono);
  text-align: center;
  color: var(--ink);
}

#app {
  display: grid;
  grid-template-columns: 54px 1fr 302px;
  grid-template-rows: 50px 1fr 28px;
  height: 100vh;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }

.mark {
  width: 20px; height: 20px;
  border-radius: 5px;
  background:
    linear-gradient(135deg, var(--accent), #7db8ff);
  position: relative;
  flex: none;
}
.mark::after {
  content: "";
  position: absolute; inset: 5px 5px auto auto;
  width: 8px; height: 8px;
  border: 2px solid rgba(255,255,255,.85);
  border-left: 0; border-bottom: 0;
}

.plan-name {
  width: 168px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-weight: 600;
  letter-spacing: .1px;
}
.plan-name:hover { border-color: var(--line); }
.plan-name:focus { outline: none; border-color: var(--accent); background: var(--bg); }

.tb-group { display: flex; align-items: center; gap: 4px; }
.level-group { gap: 6px; }
.spacer { flex: 1; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

.lbl { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; }

.tb {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  color: var(--ink-dim);
  transition: background .12s, color .12s, border-color .12s;
}
.tb:hover { background: var(--chrome-2); color: var(--ink); }
.tb:active { transform: translateY(.5px); }
.tb[disabled] { opacity: .35; pointer-events: none; }
.tb svg { width: 17px; height: 17px; }

svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.select {
  height: 28px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--chrome-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%238794a4' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 6px center / 12px;
  appearance: none;
  cursor: pointer;
  max-width: 150px;
}
.select:focus { outline: none; border-color: var(--accent); }

/* ----------------------------------------------------------------- toolbar */

.toolbar {
  grid-row: 2; grid-column: 1;
  display: flex; flex-direction: column; align-items: center;
  gap: 3px;
  padding: 8px 0;
  background: var(--chrome);
  border-right: 1px solid var(--line);
}

.tool {
  position: relative;
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.tool:hover { background: var(--chrome-2); color: var(--ink); }
.tool.active { background: var(--accent-soft); color: #7dbaff; border-color: rgba(43,142,240,.32); }
.tool svg { width: 20px; height: 20px; }
.tool .key {
  position: absolute; right: 3px; bottom: 1px;
  font: 9px var(--mono); color: var(--ink-faint);
}
.tool.active .key { color: #7dbaff; }
.tool-sep { width: 22px; height: 1px; background: var(--line); margin: 5px 0; }

/* ------------------------------------------------------------------- stage */

.stage { grid-row: 2; grid-column: 2; position: relative; overflow: hidden; background: #fbfcfd; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

[hidden] { display: none !important; }

/* dynamic dimension input */
.dyn {
  position: absolute;
  z-index: 6;
  display: flex; gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 27, 34, .96);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  transform: translate(-50%, -160%);
  pointer-events: auto;
}
.dyn .field { display: flex; align-items: center; gap: 4px; }
.dyn label { font-size: 10px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; }
.dyn input {
  width: 74px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  font: 12px var(--mono);
  text-align: right;
}
.dyn input:focus { outline: none; border-color: var(--accent); background: #0a0e12; }
.dyn input.locked { border-color: var(--warn); color: #ffcb9a; }
.dyn .unit { font: 10px var(--mono); color: var(--ink-faint); width: 22px; }

/* welcome */
.welcome {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center;
  gap: 4px;
  text-align: center;
  padding: 24px;
  color: #33414f;
  background: radial-gradient(ellipse at 50% 40%, rgba(255,255,255,.9), rgba(251,252,253,.72));
  z-index: 4;
  pointer-events: none;
}
.welcome button, .welcome kbd { pointer-events: auto; }
.welcome h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -.4px; color: #1e2732; }
.welcome p { margin: 6px 0 18px; max-width: 460px; color: #5b6875; }
.welcome-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.welcome-tips { list-style: none; margin: 26px 0 0; padding: 0; max-width: 520px; text-align: left; }
.welcome-tips li {
  padding: 9px 12px; margin-bottom: 6px;
  border: 1px solid #e3e9ef; border-radius: 8px;
  background: rgba(255,255,255,.75);
  color: #55636f; font-size: 12.5px;
}
.welcome-tips b { color: #1e2732; }
.welcome-tips kbd { border-color: #d7dee6; background: #fff; color: #33414f; }

.btn {
  height: 34px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--chrome-2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 500;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #222b36; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1f7fdd; }
.btn.ghost { background: transparent; }
.welcome .btn { border-color: #d4dce4; background: #fff; color: #2a3644; }
.welcome .btn:hover { background: #f1f5f8; }
.welcome .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.welcome .btn.ghost { background: transparent; border-color: transparent; color: #5b6875; }

/* toast */
.toast {
  position: absolute; left: 50%; bottom: 22px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 8px;
  background: rgba(21,27,34,.95);
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(0,0,0,.3);
  z-index: 7;
  font-size: 12.5px;
}

/* ------------------------------------------------------------------- panel */

.panel {
  grid-row: 2; grid-column: 3;
  background: var(--chrome);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: #29323d; border-radius: 6px; border: 3px solid var(--chrome); }

.sect { border-bottom: 1px solid var(--line-soft); }
.sect > h3 {
  display: flex; align-items: center; gap: 6px;
  margin: 0; padding: 11px 13px 9px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint);
  cursor: pointer;
  user-select: none;
}
.sect > h3::before {
  content: ""; width: 5px; height: 5px;
  border-right: 1.4px solid currentColor; border-bottom: 1.4px solid currentColor;
  transform: rotate(45deg); margin-bottom: 2px;
  transition: transform .15s;
}
.sect.collapsed > h3::before { transform: rotate(-45deg); }
.sect.collapsed > .body { display: none; }
.sect > .body { padding: 2px 13px 13px; }

.row { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.row > label { flex: none; width: 82px; color: var(--ink-dim); font-size: 12px; }
.row > .grow { flex: 1; min-width: 0; }
.row.tight { margin-bottom: 4px; }

.inp {
  width: 100%; height: 27px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font: 12px var(--mono);
}
.inp:focus { outline: none; border-color: var(--accent); }
.inp.text { font-family: var(--font); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  flex: 1; height: 26px;
  border: 0; border-right: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 11.5px;
  padding: 0 6px;
  white-space: nowrap;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--chrome-2); color: var(--ink); }
.seg button.on { background: var(--accent-soft); color: #7dbaff; }

.check { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; cursor: pointer; color: var(--ink-dim); }
.check input { accent-color: var(--accent); width: 14px; height: 14px; }
.check:hover { color: var(--ink); }

.color-row { display: flex; align-items: center; gap: 6px; }
.swatch {
  flex: 1; min-width: 0; height: 27px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}
.swatch::-webkit-color-swatch-wrapper { padding: 0; }
.swatch::-webkit-color-swatch { border: 0; border-radius: 4px; }
.swatch:focus { outline: none; border-color: var(--accent); }
.color-row .btn { flex: none; }
.color-row .btn:disabled { opacity: .45; cursor: default; }

.hintline { color: var(--ink-faint); font-size: 11.5px; line-height: 1.5; margin: 2px 0 8px; }
.empty { color: var(--ink-faint); font-size: 12px; padding: 4px 0 8px; }

.stat { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; color: var(--ink-dim); }
.stat b { color: var(--ink); font-weight: 500; font-family: var(--mono); font-size: 11.5px; }

.pill-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.pill {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--ink-dim);
  font-size: 11.5px;
  cursor: pointer;
}
.pill:hover { border-color: #3a4553; color: var(--ink); }
.pill.on { background: var(--accent-soft); border-color: rgba(43,142,240,.35); color: #7dbaff; }

.lib-cat { margin: 10px 0 5px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); }
.lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.lib-item {
  display: grid; grid-template-rows: 1fr auto; gap: 2px;
  padding: 6px 4px 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.lib-item:hover { border-color: #3a4553; background: var(--chrome-2); }
.lib-item.on { border-color: var(--accent); background: var(--accent-soft); }
.lib-item canvas { width: 100%; height: 40px; display: block; }
.lib-item span { font-size: 9.5px; color: var(--ink-faint); text-align: center; line-height: 1.25; }
.lib-item.on span { color: #7dbaff; }

.level-list { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.level-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
}
.level-item.on { border-color: var(--accent); background: var(--accent-soft); }
.level-item .nm { flex: 1; font-size: 12px; }
.level-item .mini { color: var(--ink-faint); font: 10px var(--mono); }
.level-item button {
  border: 0; background: transparent; color: var(--ink-faint);
  cursor: pointer; padding: 2px; display: grid; place-items: center;
}
.level-item button:hover { color: var(--warn); }
.level-item button svg { width: 13px; height: 13px; }

.room-list { display: flex; flex-direction: column; gap: 2px; }
.room-row { display: flex; align-items: center; gap: 6px; }
.room-row .inp { height: 25px; }
.room-row .a { font: 11px var(--mono); color: var(--ink-faint); width: 62px; text-align: right; flex: none; }

.danger { color: #e8756a; }
.btn.wide { width: 100%; justify-content: center; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-row { display: flex; gap: 6px; margin-top: 8px; }
.btn-row .btn { flex: 1; }

/* --------------------------------------------------------------- statusbar */

.statusbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 14px;
  padding: 0 12px;
  background: var(--chrome);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-dim);
}
.mono { font-family: var(--mono); font-size: 11px; }
.dim { color: var(--ink-faint); }
.hint { color: var(--ink-faint); }

/* ------------------------------------------------------------------ dialog */

.dlg {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--chrome);
  color: var(--ink);
  padding: 22px 24px;
  max-width: 720px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.dlg::backdrop { background: rgba(6,9,12,.6); }
.dlg h2 { margin: 0 0 16px; font-size: 17px; font-weight: 600; }
.dlg h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); }
.dlg p { margin: 0 0 5px; color: var(--ink-dim); font-size: 12.5px; }
.help-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 22px; margin-bottom: 20px; }

.export-dlg { max-width: 340px; }
.export-dlg .check { margin-bottom: 4px; }
.export-dlg .hintline { margin: 0 0 4px; }

/* ---------------------------------------------------------------- AI layout */

.ai-launch {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px;
  border-color: rgba(43,142,240,.4);
  background: var(--accent-soft);
  color: #8cc2ff;
}
.ai-launch:hover { background: rgba(43,142,240,.22); }
.ai-launch svg { width: 15px; height: 15px; }

.ai-dlg { width: min(1080px, 94vw); max-height: 88vh; padding: 0; display: flex; flex-direction: column; }
.ai-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.ai-head h2 { margin: 0; }
.ai-body { padding: 18px 20px 20px; overflow-y: auto; }
.ai-body::-webkit-scrollbar { width: 10px; }
.ai-body::-webkit-scrollbar-thumb { background: #29323d; border-radius: 6px; border: 3px solid var(--chrome); }

.ai-note {
  padding: 9px 12px; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink-dim); font-size: 12.5px;
}
.ai-warn {
  padding: 9px 12px; margin-bottom: 14px;
  border: 1px solid rgba(232,132,60,.4); border-radius: 8px;
  background: rgba(232,132,60,.09); color: #edb98c; font-size: 12.5px;
}
.ai-warn b { color: #f3cba6; }
.ai-sub {
  margin: 16px 0 7px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint);
}
.ai-fine { margin: 8px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--ink-faint); }

.cnt-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cnt {
  display: flex; flex-direction: column; gap: 7px;
  padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg);
}
.cnt-label { font-size: 12px; color: var(--ink-dim); }
.cnt-ctl { display: flex; align-items: center; gap: 10px; }
.cnt-btn {
  width: 26px; height: 26px; flex: none;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--chrome-2); color: var(--ink);
  cursor: pointer; font-size: 15px; line-height: 1;
}
.cnt-btn:hover { background: #222b36; border-color: #3a4553; }
.cnt-val { font: 600 16px var(--mono); min-width: 20px; text-align: center; }

.ai-notes { min-height: 62px; padding: 8px; resize: vertical; line-height: 1.5; }

.ai-key { margin: 14px 0 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.ai-key summary {
  padding: 9px 12px; cursor: pointer; font-size: 12.5px; color: var(--ink-dim);
  list-style: none;
}
.ai-key summary::-webkit-details-marker { display: none; }
.ai-key summary::before { content: "▸ "; color: var(--ink-faint); }
.ai-key[open] summary::before { content: "▾ "; }
.ai-key > .row, .ai-key > .ai-fine { padding: 0 12px; }
.ai-key > .ai-fine { padding-bottom: 12px; }

.ai-actions { display: flex; gap: 8px; margin-top: 16px; }
.ai-actions .btn { flex: 1; }

.ai-busy { display: flex; align-items: center; gap: 16px; padding: 40px 10px; }
.ai-busy-txt { display: flex; flex-direction: column; gap: 4px; }
.ai-busy-txt b { font-size: 14px; }
.ai-busy-txt span { color: var(--ink-faint); font-size: 12.5px; }
.ai-spin {
  width: 30px; height: 30px; flex: none;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 900ms linear infinite;
}
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.ai-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg);
}
.ai-thumb {
  display: grid; place-items: center;
  border-radius: 7px; overflow: hidden;
  background: #fff; border: 1px solid var(--line);
}
.ai-thumb canvas { display: block; max-width: 100%; height: auto; }
.ai-card-name { margin: 2px 0 0; font-size: 14px; font-weight: 600; }
.ai-card-sum { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-dim); }
.ai-rooms { display: flex; flex-wrap: wrap; gap: 4px; }
.ai-room {
  display: inline-flex; gap: 5px; align-items: baseline;
  padding: 3px 8px;
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--chrome-2);
  font-size: 11px;
}
.ai-room b { font-weight: 500; color: var(--ink); }
.ai-room i { font-style: normal; font-family: var(--mono); color: var(--ink-faint); font-size: 10px; }
.ai-card .btn { margin-top: auto; }

@media (max-width: 1120px) {
  #app { grid-template-columns: 54px 1fr 270px; }
}
@media (max-width: 900px) {
  .help-grid { grid-template-columns: repeat(2, 1fr); }
  .plan-name { width: 120px; }
}
