:root{
  --navy:#1c3faa; --navy-d:#15307f; --blue:#2f6bff;
  --fill:#eaf1ff; --fill-done:#cfe0ff; --line:#1c3faa;
  --ink:#0d1b3e; --muted:#5b6b95; --bg:#f4f6fb; --card:#fff;
  --shadow:0 6px 24px rgba(20,40,100,.16);
  --safe-b:env(safe-area-inset-bottom,0px);
}
*{box-sizing:border-box}
html,body{margin:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg); color:var(--ink); -webkit-text-size-adjust:100%;
  overscroll-behavior-y:none;
}
#app{max-width:760px;margin:0 auto;display:flex;flex-direction:column;min-height:100dvh}

/* Header */
header{position:sticky;top:0;z-index:5;background:var(--navy);color:#fff;
  padding:calc(env(safe-area-inset-top,0px) + 12px) 16px 0}
.title{display:flex;align-items:center;justify-content:space-between;gap:10px}
header h1{font-size:19px;margin:0;font-weight:800;letter-spacing:.2px}
.sync{font-size:11.5px;font-weight:700;white-space:nowrap;color:#bcd0ff}
.sync.saved{color:#7ee6b8}.sync.saving{color:#ffe08a}.sync.error{color:#ff9e98}.sync.local{color:#9fb4e6}
.subbar{display:flex;align-items:flex-end;gap:10px;margin-top:12px}
.tabs{display:flex;gap:8px;flex:1}
.tab{flex:1;border:0;background:rgba(255,255,255,.14);color:#dce6ff;
  padding:11px 8px;border-radius:10px 10px 0 0;font-size:14px;font-weight:700;cursor:pointer}
.tab.on{background:var(--bg);color:var(--navy)}
.progress{font-size:12.5px;color:#bcd0ff;font-weight:600;white-space:nowrap;padding-bottom:10px}

/* Main */
main{flex:1;padding:14px 12px}
.plan-wrap{background:var(--card);border-radius:14px;box-shadow:var(--shadow);padding:8px;overflow:hidden}
.hint{color:var(--muted);font-size:12.5px;text-align:center;margin:12px 6px 0;line-height:1.45}

/* Plan stage: image + tappable overlay */
.plan-stage{position:relative;display:block;line-height:0}
.plan-img{width:100%;height:auto;display:block;border-radius:8px}
.plan-ovl{position:absolute;inset:0;width:100%;height:100%}
g.room rect,g.room polygon{fill:transparent;stroke:transparent;stroke-width:1.4;
  pointer-events:all;cursor:pointer;vector-effect:non-scaling-stroke;transition:fill .15s,stroke .15s}
g.room.filled rect,g.room.filled polygon{fill:rgba(22,163,74,.16);stroke:rgba(22,163,74,.7)}
g.room:hover rect,g.room:hover polygon{fill:rgba(47,107,255,.12)}
g.room.active rect,g.room.active polygon{fill:rgba(47,107,255,.28);stroke:var(--blue);stroke-width:2.4}
g.room.nodata{pointer-events:none}

/* Badge layer (HTML, undistorted) */
.badge-layer{position:absolute;inset:0;pointer-events:none}
.badge{position:absolute;transform:translate(5px,5px)}
.chip{display:inline-block;font-size:10.5px;font-weight:800;line-height:1;
  padding:4px 6px;border-radius:7px;box-shadow:0 1px 4px rgba(0,0,0,.18);white-space:nowrap}
.chip.done{background:#16a34a;color:#fff}
.chip.add{background:rgba(255,255,255,.92);color:var(--navy);border:1px solid #c3cfe8}

/* Missing-image fallback */
.img-missing{display:none;text-align:center;padding:38px 20px;background:#eef2fb;
  border:2px dashed #c3cfe8;border-radius:10px;color:var(--muted);line-height:1.6}
.img-missing strong{display:block;color:var(--navy);font-size:15px;margin-bottom:4px}
.img-missing code{background:#dbe4f7;padding:2px 6px;border-radius:5px;font-size:12.5px}
.plan-stage.noimg .img-missing{display:block}
.plan-stage.noimg .plan-ovl,.plan-stage.noimg .badge-layer{display:none}

/* Footer */
footer{position:sticky;bottom:0;display:flex;gap:8px;padding:10px 12px calc(10px + var(--safe-b));
  background:linear-gradient(transparent,var(--bg) 28%)}
.ghost{flex:1;border:1.5px solid #c3cfe8;background:#fff;color:var(--navy);
  padding:13px;border-radius:11px;font-size:14px;font-weight:700;cursor:pointer}
.ghost.danger{color:#c0322b;border-color:#f0c6c3;flex:.7}

/* Sheet */
#sheet:empty{display:none}
.backdrop{position:fixed;inset:0;background:rgba(13,27,62,.45);z-index:20}
.card{position:fixed;left:0;right:0;bottom:0;z-index:21;max-width:760px;margin:0 auto;
  background:var(--card);border-radius:18px 18px 0 0;box-shadow:var(--shadow);
  max-height:92dvh;display:flex;flex-direction:column;animation:up .22s ease}
@keyframes up{from{transform:translateY(100%)}to{transform:translateY(0)}}
.grab{width:42px;height:5px;border-radius:3px;background:#d2dbf0;margin:9px auto 2px}
.card-head{display:flex;justify-content:space-between;align-items:flex-start;
  padding:6px 18px 10px;border-bottom:1px solid #eef1f8}
.card-head h2{margin:0;font-size:20px;font-weight:800}
.planref,.calc-label{font-size:12.5px;color:var(--muted);margin-top:3px}
.close{border:0;background:#eef1f8;color:var(--muted);width:34px;height:34px;border-radius:50%;
  font-size:16px;cursor:pointer;flex:none}
.card-body{padding:14px 18px calc(20px + var(--safe-b));overflow-y:auto;-webkit-overflow-scrolling:touch}

.row{display:flex;gap:12px}
label{display:flex;flex-direction:column;font-size:12.5px;font-weight:700;color:var(--muted);
  flex:1;margin-bottom:14px;gap:5px}
label.full{flex:1}
input,textarea{font-size:16px;font-family:inherit;color:var(--ink);
  border:1.5px solid #d6deef;border-radius:10px;padding:11px 12px;font-weight:600;background:#fbfcfe}
input:focus,textarea:focus{outline:0;border-color:var(--blue);background:#fff}
textarea{resize:vertical;font-weight:500}
.calc{flex:1;display:flex;flex-direction:column;justify-content:flex-start;gap:5px}
.calc-val{font-size:18px;font-weight:800;color:var(--blue);padding-top:4px}

/* Furniture */
.furn{margin-top:6px;border-top:1px solid #eef1f8;padding-top:14px}
.furn-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.furn-head h3{margin:0;font-size:15px;font-weight:800}
.addf{border:0;background:var(--navy);color:#fff;padding:8px 13px;border-radius:9px;
  font-weight:700;font-size:13px;cursor:pointer}
.empty{color:var(--muted);font-size:13px;margin:4px 0 0;line-height:1.5}
.fitem{background:#f6f8fd;border:1px solid #e6ecf8;border-radius:12px;padding:10px;margin-bottom:10px}
.fname{width:100%;margin-bottom:8px}
.fdims{display:flex;gap:7px}
.fdims input{width:100%;text-align:center;padding:9px 4px}
.delf{border:0;background:#fdeceb;color:#c0322b;border-radius:9px;width:42px;flex:none;
  font-size:15px;cursor:pointer}
.fit{display:inline-block;margin-top:8px;font-size:12px;font-weight:700;color:var(--muted)}

/* Toast */
.toast{position:fixed;bottom:calc(80px + var(--safe-b));left:50%;transform:translateX(-50%);
  background:var(--ink);color:#fff;padding:11px 18px;border-radius:11px;font-size:13.5px;
  font-weight:600;z-index:40;box-shadow:var(--shadow)}
