:root{
  --forest:#1f3d2c;
  --olive:#5c6b30;
  --orange:#d9491f;
  --cream:#f4f1e8;
  --line:#d8d2c2;
  --ink:#22241f;
}
*{box-sizing:border-box;}
body{
  margin:0;
  font-family:'Inter',-apple-system,Segoe UI,sans-serif;
  background:var(--cream);
  color:var(--ink);
  display:flex;
  height:100vh;
  overflow:hidden;
}

/* ---------- Sidebar ---------- */
#sidebar{
  width:300px; min-width:300px;
  background:var(--forest);
  color:var(--cream);
  display:flex; flex-direction:column;
  overflow-y:auto;
}
#sidebar h1{
  font-family:'Bebas Neue',Inter,sans-serif;
  letter-spacing:1px; font-size:26px;
  margin:18px 16px 4px;
}
#sidebar .sub{ margin:0 16px 16px; font-size:12px; opacity:.7; }

.section{ padding:0 16px 14px; border-bottom:1px solid rgba(244,241,232,.15); }
.section h2{
  font-size:11px; text-transform:uppercase; letter-spacing:1.5px;
  opacity:.65; margin:14px 0 8px;
}

/* Login */
#loginBox input{
  background:rgba(244,241,232,.08);
  border:1px solid rgba(244,241,232,.25);
  color:var(--cream); border-radius:4px;
  padding:6px 8px; font-size:12px;
}
#adminBadge{ display:flex; font-size:12px; }

/* Library cards */
.item-card{
  background:rgba(244,241,232,.08);
  border:1px solid rgba(244,241,232,.18);
  border-radius:6px; padding:8px 10px;
  margin-bottom:6px; cursor:grab; font-size:13px;
  display:flex; justify-content:space-between;
  align-items:center; gap:6px;
}
.item-card:hover{ background:rgba(244,241,232,.16); }
.item-card .meta{ opacity:.6; font-size:11px; white-space:nowrap; }
.item-card .del{ opacity:.4; cursor:pointer; font-size:14px; padding:0 4px; }
.item-card .del:hover{ opacity:1; color:var(--orange); }
.item-card.zone-card{ border-color:rgba(100,180,255,.5); }

/* Add form */
#addForm{ display:flex; flex-direction:column; gap:6px; margin-top:8px; }
#addForm input,#addForm select{
  background:rgba(244,241,232,.08);
  border:1px solid rgba(244,241,232,.25);
  color:var(--cream); border-radius:4px;
  padding:6px 8px; font-size:12px; width:100%;
}
#addForm select option{ color:#22241f; background:white; }
#addForm input::placeholder{ color:rgba(244,241,232,.5); }
#addForm button{
  background:var(--orange); color:white; border:none;
  border-radius:4px; padding:8px; font-size:12px;
  font-weight:600; cursor:pointer; letter-spacing:.3px;
}
#addForm button:hover{ background:#bf3c17; }

/* ---------- Main ---------- */
#main{ flex:1; display:flex; flex-direction:column; min-width:0; }
#toolbar{
  background:white; border-bottom:1px solid var(--line);
  padding:10px 16px; display:flex; align-items:center;
  gap:10px; flex-wrap:wrap;
}
#toolbar input[type=text]{
  border:1px solid var(--line); border-radius:4px;
  padding:6px 10px; font-size:14px; font-weight:600; width:200px;
}
#toolbar select, #toolbar input[type=number]{
  border:1px solid var(--line); border-radius:4px;
  padding:6px 8px; font-size:12px; color:var(--ink);
}
#toolbar button{
  background:var(--forest); color:white; border:none;
  border-radius:4px; padding:7px 12px; font-size:12px;
  font-weight:600; cursor:pointer; white-space:nowrap;
}
#toolbar button.alt{ background:var(--olive); }
#toolbar button.danger{ background:var(--orange); }
#toolbar button:hover{ filter:brightness(1.15); }
.tb-label{ font-size:10px; text-transform:uppercase; letter-spacing:.5px; color:#888; }
.tb-group{ display:flex; align-items:center; gap:5px; }

/* Snap-to-grid toggle */
#snapToggle{ display:flex; align-items:center; gap:5px; font-size:11px; color:#666; cursor:pointer; }
#snapToggle input{ margin:0; }

/* ---------- Canvas ---------- */
#canvasWrap{
  flex:1; overflow:auto;
  background:#eae6da;
  padding:30px;
}
#planTitle{
  text-align:center;
  font-family:'Bebas Neue',Inter,sans-serif;
  font-size:22px; color:var(--forest);
  margin:4px 0 16px;
}
#canvas{
  position:relative;
  background:
    linear-gradient(rgba(0,0,0,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,.05) 1px, transparent 1px);
  background-color:white;
  box-shadow:0 4px 20px rgba(0,0,0,.15);
  margin:0 auto;
}

/* ---------- Placed elements ---------- */
.placed{
  position:absolute;
  border:2px solid var(--forest);
  background:rgba(92,107,48,.2);
  display:flex; flex-direction:column;
  align-items:center; justify-content:center;
  text-align:center;
  font-size:11px; font-weight:700;
  color:var(--ink);
  cursor:move;
  user-select:none;
  line-height:1.3;
  padding:3px;
  overflow:hidden;
  transition:outline .1s;
}
.placed .item-label{
  display:block;
  font-size:11px;
  font-weight:700;
  color:var(--ink);
  text-shadow: 0 0 4px white, 0 0 4px white, 0 0 4px white;
  word-break:break-word;
  hyphens:auto;
  max-width:100%;
  line-height:1.2;
}
.placed .dims{
  display:block;
  font-size:9px; font-weight:400; opacity:.7;
  text-shadow: 0 0 3px white, 0 0 3px white;
}
.placed.circle{ border-radius:50%; }
.placed.huette{
  background:rgba(217,73,31,.1);
  border-color:var(--orange); border-width:2px;
}
.placed.zone{
  background:rgba(100,160,255,.08);
  border:2px dashed rgba(80,130,220,.6);
  cursor:move;
  z-index:1 !important;
}
.placed.zone .item-label{
  position:absolute; top:4px; left:6px;
  font-size:12px; font-weight:700;
  color:rgba(60,100,200,.85);
  text-shadow:0 0 4px white, 0 0 4px white;
  text-align:left;
}
.placed.zone .dims{ display:none; }

.placed.selected{ outline:3px solid var(--orange); outline-offset:2px; z-index:50; }
.placed.locked{ cursor:not-allowed; opacity:.8; }
.placed.locked .item-label::after{ content:' 🔒'; font-size:8px; }

/* ---------- Floating control toolbar (appears above selected element) ---------- */
.el-toolbar{
  position:absolute;
  display:flex;
  gap:3px;
  background:#22241f;
  border-radius:7px;
  padding:5px 6px;
  box-shadow:0 3px 12px rgba(0,0,0,.45);
  z-index:100;
  white-space:nowrap;
  /* positioned by JS */
}
.el-toolbar button{
  display:flex; align-items:center; gap:5px;
  background:rgba(255,255,255,.10);
  color:#f4f1e8;
  border:none; border-radius:5px;
  padding:5px 9px;
  font-size:12px; font-weight:600;
  cursor:pointer;
  line-height:1;
  transition:background .15s;
}
.el-toolbar button:hover{ background:rgba(255,255,255,.22); }
.el-toolbar button.danger{ color:#ff8060; }
.el-toolbar button.danger:hover{ background:rgba(217,73,31,.35); }
.el-toolbar button.active{ background:var(--orange); color:white; }
.el-toolbar .sep{
  width:1px; background:rgba(255,255,255,.18);
  margin:2px 2px;
}
/* SVG icons inside toolbar buttons */
.el-toolbar button svg{
  width:14px; height:14px; flex-shrink:0;
  stroke:currentColor; fill:none; stroke-width:2;
  stroke-linecap:round; stroke-linejoin:round;
}

/* Free-rotate drag handle — visible circle on element edge */
.rotate-drag-handle{
  position:absolute;
  top:50%; right:-22px;
  transform:translateY(-50%);
  width:18px; height:18px;
  background:var(--orange);
  border:2.5px solid white;
  border-radius:50%;
  cursor:grab;
  z-index:65;
  box-shadow:0 2px 6px rgba(0,0,0,.4);
  display:flex; align-items:center; justify-content:center;
}
.rotate-drag-handle svg{
  width:10px; height:10px;
  stroke:white; fill:none; stroke-width:2.5;
  stroke-linecap:round;
}
/* connector line from element edge to rotate handle */
.rotate-drag-handle::before{
  content:'';
  position:absolute;
  right:100%; top:50%;
  width:6px; height:2px;
  background:var(--orange);
  transform:translateY(-50%);
}

/* Packlisten-Button an Hütte — bleibt direkt am Element */
.placed .pack-btn{
  position:absolute; bottom:-11px; left:50%; transform:translateX(-50%);
  display:flex; align-items:center; gap:4px;
  background:var(--forest); color:var(--cream);
  border:2px solid white;
  border-radius:12px; padding:2px 8px;
  font-size:10px; font-weight:700;
  cursor:pointer; z-index:55;
  box-shadow:0 1px 4px rgba(0,0,0,.3);
  white-space:nowrap;
}
.placed .pack-btn:hover{ background:var(--orange); }

/* Zone resize handle */
.resize-handle{
  position:absolute; bottom:-7px; right:-7px;
  width:18px; height:18px;
  background:rgba(80,130,220,.85); border:2.5px solid white;
  border-radius:4px; cursor:se-resize; z-index:62;
  box-shadow:0 1px 5px rgba(0,0,0,.3);
  display:flex; align-items:center; justify-content:center;
}
.resize-handle svg{
  width:10px; height:10px;
  stroke:white; fill:none; stroke-width:2.5;
  stroke-linecap:round;
}

/* Keyboard shortcut hint */
#kbHint{
  position:fixed; bottom:16px; right:16px;
  background:rgba(34,36,31,.75); color:rgba(244,241,232,.85);
  border-radius:8px; padding:10px 14px; font-size:11px;
  line-height:1.7; pointer-events:none; backdrop-filter:blur(4px);
}
#kbHint kbd{
  background:rgba(244,241,232,.2); border-radius:3px;
  padding:1px 5px; font-size:10px; font-family:monospace;
}

/* ---------- Packlisten-Modal ---------- */
.modal-overlay{
  position:fixed; inset:0; background:rgba(34,36,31,.55);
  display:flex; align-items:center; justify-content:center;
  z-index:200;
}
.modal-box{
  background:white; border-radius:8px;
  width:min(720px,92vw); max-height:86vh;
  display:flex; flex-direction:column;
  box-shadow:0 10px 40px rgba(0,0,0,.3);
}
.modal-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 20px; border-bottom:1px solid var(--line);
}
.modal-head h2{
  font-family:'Bebas Neue',Inter,sans-serif;
  font-size:20px; color:var(--forest); margin:0;
}
.modal-head-actions{ display:flex; gap:8px; }
.modal-head-actions button{
  border:none; border-radius:4px; padding:7px 12px; font-size:12px;
  cursor:pointer; background:var(--forest); color:white; font-weight:600;
}
.modal-head-actions button.close{ background:#999; }
.modal-body{ padding:16px 20px; overflow-y:auto; }

.pack-table{ width:100%; border-collapse:collapse; margin-bottom:14px; font-size:13px; }
.pack-table th{
  text-align:left; font-size:10px; text-transform:uppercase;
  letter-spacing:.5px; color:#888;
  border-bottom:1px solid var(--line); padding:4px 6px;
}
.pack-table td{ padding:5px 6px; border-bottom:1px solid #f0eee6; }
.pack-table .checkcell{ width:22px; text-align:center; color:#aaa; }
.pack-table .del{ opacity:.4; cursor:pointer; margin-left:8px; }
.pack-table .del:hover{ opacity:1; color:var(--orange); }
.pack-section-title{
  font-family:'Bebas Neue',Inter,sans-serif; letter-spacing:.5px;
  font-size:16px; color:var(--orange); margin:18px 0 6px;
  border-bottom:2px solid var(--orange); padding-bottom:2px;
}
.pack-add-row{ display:flex; gap:6px; margin:10px 0 4px; flex-wrap:wrap; }
.pack-add-row input{
  border:1px solid var(--line); border-radius:4px; padding:6px 8px; font-size:12px;
}
.pack-add-row input[type=text]:first-child{ flex:1; min-width:140px; }
.pack-add-row input[type=text]:last-of-type{ flex:1; min-width:140px; }
.pack-add-row button{
  background:var(--orange); color:white; border:none; border-radius:4px;
  padding:6px 12px; font-size:12px; font-weight:600; cursor:pointer;
}

/* ---------- Print ---------- */
@media print{
  #sidebar,#toolbar,#kbHint{ display:none !important; }
  #canvasWrap{ overflow:visible; padding:0; background:white; }
  body{ height:auto; }
  #canvas{ box-shadow:none; margin:0; }
  .rotate-drag-handle,.resize-handle,.pack-btn,.el-toolbar{ display:none !important; }
  #packlistModal{ display:none; }

  body.print-packlist-mode #sidebar,
  body.print-packlist-mode #toolbar,
  body.print-packlist-mode #canvasWrap{ display:none !important; }
  body.print-packlist-mode #packlistModal{
    display:flex !important; position:static; background:none;
  }
  body.print-packlist-mode .modal-box{
    box-shadow:none; max-height:none; width:100%;
  }
  body.print-packlist-mode .modal-head-actions{ display:none; }
}
