#shelfmgr-root{
  --page:#f5fbff;
  --white:#fff;
  --accent:#00aae7;
  --accent-dark:#0096cb;
  --border:#e0edf5;
  --border-input:#d5e5ee;
  --border-soft:#eef6fb;
  --text:#222;
  --text-muted:#888;
  --danger:#e03131;
  --shadow:0 6px 24px rgba(0,170,231,.08);
  background:var(--page);
  color:var(--text);
  font-family:'Be Vietnam Pro',sans-serif;
  padding:24px 16px 60px;
  border-radius:16px;
}
#shelfmgr-root *{box-sizing:border-box;}
#shelfmgr-root .wrap{max-width:1100px;margin:0 auto;padding-bottom:8px;}
#shelfmgr-root.shelfmgr-editmode .wrap{padding-bottom:64px;} /* chừa chỗ cho thanh chọn nổi ở dưới */

#shelfmgr-root header{text-align:center;margin-bottom:20px;}
#shelfmgr-root h1{margin:0 0 6px;font-size:22px;font-weight:700;color:var(--accent);}
#shelfmgr-root .dims{font-size:13px;color:var(--text-muted);}
#shelfmgr-root .dims b{color:var(--accent-dark);}

/* SEARCH */
#shelfmgr-root .search-card{
  max-width:650px;margin:0 auto 22px;background:var(--white);
  border:1px solid var(--border);border-radius:14px;box-shadow:var(--shadow);padding:18px 20px;
}
#shelfmgr-root .search-card label{
  display:block;font-size:13px;color:var(--text-muted);font-weight:600;margin-bottom:8px;text-align:center;
}
#shelfmgr-root #searchInput{
  width:100%;padding:12px 14px;border:1px solid var(--border-input);border-radius:999px;
  font-size:15px;font-family:inherit;text-align:center;outline:none;transition:.2s;
}
#shelfmgr-root #searchInput:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(0,170,231,.08);}
#shelfmgr-root .search-results{margin-top:14px;display:flex;flex-direction:column;gap:10px;}
#shelfmgr-root .sr-item{border-top:1px solid var(--border-soft);padding-top:10px;}
#shelfmgr-root .sr-item:first-child{border-top:none;padding-top:0;}
#shelfmgr-root .sr-name{display:flex;align-items:center;gap:8px;font-weight:700;font-size:14px;margin-bottom:6px;}
#shelfmgr-root .sr-name .swatch{width:10px;height:10px;border-radius:3px;flex-shrink:0;}
#shelfmgr-root .sr-locs{display:flex;flex-wrap:wrap;gap:6px;}
#shelfmgr-root .sr-loc{
  background:var(--page);border:1px solid var(--border);color:var(--accent-dark);font-size:12.5px;
  font-weight:600;padding:5px 11px;border-radius:999px;cursor:pointer;transition:.15s;
}
#shelfmgr-root .sr-loc:hover{background:var(--accent);color:#fff;border-color:var(--accent);}
#shelfmgr-root .sr-empty,#shelfmgr-root .sr-none{font-size:13px;color:var(--text-muted);text-align:center;}

/* SHELF MAP */
#shelfmgr-root .shelfmap{max-width:650px;margin:0 auto 26px;}
#shelfmgr-root .map-row{display:flex;align-items:center;gap:10px;margin-bottom:6px;}
#shelfmgr-root .map-row-label{width:64px;flex-shrink:0;font-size:12.5px;color:var(--text-muted);font-weight:600;text-align:right;}
#shelfmgr-root .map-shelves{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;flex:1;}
#shelfmgr-root .map-shelves-mid{grid-template-columns:1fr;max-width:180px;margin:0 auto;}
#shelfmgr-root .map-shelf{
  background:var(--white);border:1.5px solid var(--border-input);border-radius:10px;
  padding:9px 4px;text-align:center;cursor:pointer;transition:.15s;
}
#shelfmgr-root .map-shelf:hover{border-color:var(--accent);}
#shelfmgr-root .map-shelf.active{
  border-color:var(--accent);background:rgba(0,170,231,.06);box-shadow:0 0 0 3px rgba(0,170,231,.1);
}
#shelfmgr-root .map-shelf .ms-name{font-size:13px;font-weight:700;color:var(--text);}
#shelfmgr-root .map-shelf .ms-count{font-size:11px;color:var(--text-muted);margin-top:2px;}
#shelfmgr-root .aisle{
  text-align:center;color:var(--text-muted);font-size:11.5px;letter-spacing:.5px;margin:10px 0;position:relative;
}
#shelfmgr-root .aisle::before,#shelfmgr-root .aisle::after{
  content:'';display:inline-block;width:70px;height:1px;background:var(--border-input);vertical-align:middle;margin:0 10px;
}

#shelfmgr-root .layout{display:grid;grid-template-columns:1.5fr 1fr;gap:20px;align-items:start;}
@media (max-width:820px){
  #shelfmgr-root .layout{grid-template-columns:1fr;}
  #shelfmgr-root .map-row-label{width:52px;font-size:11px;}
}

/* SHELF EDITOR */
#shelfmgr-root .shelf-panel{
  background:var(--white);border:1px solid var(--border);border-radius:14px;box-shadow:var(--shadow);padding:18px;
}
#shelfmgr-root .shelf-panel-head{
  display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;margin-bottom:14px;
}
#shelfmgr-root .shelf-panel-head h2{margin:0;font-size:16px;font-weight:700;color:var(--text);}
#shelfmgr-root .levels-ctrl{
  display:flex;align-items:center;gap:8px;background:var(--page);border:1px solid var(--border);
  border-radius:999px;padding:6px 12px;font-size:12.5px;color:var(--text-muted);white-space:nowrap;
}
#shelfmgr-root .levels-ctrl button{
  width:22px;height:22px;border-radius:50%;border:1px solid var(--border-input);
  background:var(--white);font-size:14px;line-height:1;cursor:pointer;color:var(--accent-dark);
}
#shelfmgr-root .levels-ctrl button:hover{border-color:var(--accent);}
#shelfmgr-root .levels-ctrl span.n{font-weight:700;min-width:14px;text-align:center;color:var(--text);}

#shelfmgr-root .tang-row{
  display:grid;grid-template-columns:repeat(4,1fr);gap:8px;align-items:center;padding:7px 0;
}
#shelfmgr-root .tang-row + .tang-row{border-top:1px dashed var(--border-soft);}
#shelfmgr-root .slot{
  position:relative;aspect-ratio:1/0.85;border-radius:8px;border:1.5px dashed var(--border-input);
  background:var(--page);display:flex;align-items:center;justify-content:center;cursor:pointer;padding:3px;transition:.15s;
}
@media (max-width:480px){
  #shelfmgr-root .tang-row{gap:6px;}
  #shelfmgr-root .slot{aspect-ratio:1/1.25;} /* ô cao hơn trên mobile để chứa tên dài */
}
#shelfmgr-root .slot:hover{border-color:var(--accent);}
#shelfmgr-root .slot.drop-hover{border-color:var(--accent);background:rgba(0,170,231,.1);}
#shelfmgr-root .slot.flash{animation:shelfmgrflash 1s ease;}
@keyframes shelfmgrflash{
  0%,100%{box-shadow:0 0 0 0 rgba(0,170,231,0);}
  30%{box-shadow:0 0 0 5px rgba(0,170,231,.35);}
}
#shelfmgr-root .slot .plus{color:var(--border-input);font-size:16px;pointer-events:none;}
#shelfmgr-root .slot.filled{border-style:solid;border-color:var(--border);align-items:stretch;}
#shelfmgr-root .crate{
  width:100%;height:100%;border-radius:6px;background:var(--white);border:1px solid var(--border);
  border-top:6px solid var(--accent);display:flex;align-items:center;justify-content:center;
  text-align:center;padding:9px 4px 6px;position:relative;box-shadow:inset 0 0 0 1px rgba(0,0,0,.06);
  overflow:hidden; /* chặn tên sản phẩm dài tràn ra khỏi ô */
}
#shelfmgr-root .crate .dot{
  position:absolute;top:-4px;left:50%;transform:translate(-50%,-100%);
  width:16px;height:16px;border-radius:50%;box-shadow:0 0 0 2px var(--white), inset 0 0 0 1px rgba(0,0,0,.2);
}
#shelfmgr-root .crate .name{
  font-size:11px;font-weight:700;color:var(--text);line-height:1.55;word-break:break-word;
  width:100%;
  display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;
  overflow:hidden;text-overflow:ellipsis;
  cursor:default;
}
@media (max-width:480px){
  #shelfmgr-root .crate .name{font-size:10.5px;-webkit-line-clamp:4;}
}
#shelfmgr-root .crate .clear-x{
  position:absolute;top:1px;right:1px;width:15px;height:15px;border-radius:50%;
  background:var(--border-soft);color:var(--text-muted);font-size:11px;
  display:flex;align-items:center;justify-content:center;line-height:1;cursor:pointer;
}
#shelfmgr-root .crate .clear-x:hover{background:var(--danger);color:#fff;}

#shelfmgr-root .shelf-note{color:var(--text-muted);font-size:12px;margin-top:12px;line-height:1.6;text-align:center;}

/* SIDEBAR */
#shelfmgr-root .side-panel{
  background:var(--white);border:1px solid var(--border);border-radius:14px;box-shadow:var(--shadow);padding:18px;
}
#shelfmgr-root .side-panel h2{
  margin:0 0 12px;font-size:16px;font-weight:700;color:var(--text);
  display:flex;align-items:baseline;gap:6px;
}
#shelfmgr-root .list-count{font-size:12.5px;font-weight:600;color:var(--text-muted);}
#shelfmgr-root .add-form{display:flex;gap:8px;margin-bottom:10px;}
#shelfmgr-root .add-form input{
  flex:1;border:1px solid var(--border-input);border-radius:8px;padding:10px 12px;
  font-size:14px;font-family:inherit;background:var(--white);color:var(--text);
}
#shelfmgr-root .add-form input:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px rgba(0,170,231,.08);}
#shelfmgr-root .add-form button{
  background:var(--accent);color:#fff;border:none;border-radius:999px;padding:0 18px;
  font-weight:700;font-size:14px;cursor:pointer;transition:.15s;
}
#shelfmgr-root .add-form button:hover{background:var(--accent-dark);}
#shelfmgr-root .filter-input{
  width:100%;box-sizing:border-box;border:1px solid var(--border-input);border-radius:8px;
  padding:8px 12px;font-size:13px;font-family:inherit;background:var(--page);color:var(--text);
  margin-bottom:12px;
}
#shelfmgr-root .filter-input:focus{outline:none;border-color:var(--accent);background:var(--white);box-shadow:0 0 0 3px rgba(0,170,231,.08);}
#shelfmgr-root .hint{font-size:12px;color:var(--text-muted);margin-bottom:14px;line-height:1.6;}
#shelfmgr-root .product-list{
  display:flex;flex-direction:column;gap:7px;
  max-height:min(60vh,560px);overflow-y:auto;overflow-x:hidden;
  padding-right:4px;scrollbar-width:thin;
}
#shelfmgr-root .product-list::-webkit-scrollbar{width:6px;}
#shelfmgr-root .product-list::-webkit-scrollbar-thumb{background:var(--border);border-radius:99px;}
#shelfmgr-root .product-list::-webkit-scrollbar-track{background:transparent;}
#shelfmgr-root .product-card{
  display:flex;align-items:center;gap:10px;background:var(--page);border:1px solid var(--border);
  border-radius:10px;padding:9px 11px;cursor:grab;user-select:none;touch-action:none;transition:.15s;
}
#shelfmgr-root .product-card .swatch{width:18px;height:18px;border-radius:5px;flex-shrink:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.18);}
#shelfmgr-root .product-card .pname{flex:1;font-size:13.5px;font-weight:600;color:var(--text);}
#shelfmgr-root.shelfmgr-editmode .product-card .pname{cursor:text;}
#shelfmgr-root.shelfmgr-editmode .product-card .pname:hover{text-decoration:underline dotted;}
#shelfmgr-root .product-card .pname-edit{
  flex:1;font-size:13.5px;font-weight:600;color:var(--text);font-family:inherit;
  border:1px solid var(--accent);border-radius:6px;padding:3px 6px;outline:none;background:var(--white);
}
#shelfmgr-root .product-card .count{
  font-size:11px;color:var(--accent-dark);background:var(--white);border:1px solid var(--border);
  border-radius:999px;padding:2px 8px;
}
#shelfmgr-root .product-card .edit{color:var(--text-muted);font-size:13px;padding:2px 5px;cursor:pointer;}
#shelfmgr-root .product-card .edit:hover{color:var(--accent-dark);}
#shelfmgr-root .product-card .del{color:var(--text-muted);font-size:14px;padding:2px 4px;cursor:pointer;}
#shelfmgr-root .product-card .del:hover{color:var(--danger);}
#shelfmgr-root .product-card.selected{border-color:var(--accent);box-shadow:0 0 0 2px rgba(0,170,231,.15);}
#shelfmgr-root .product-card.dragging-source{opacity:.35;}
#shelfmgr-root .empty-state{
  font-size:13px;color:var(--text-muted);text-align:center;padding:24px 10px;
  border:1.5px dashed var(--border-input);border-radius:10px;line-height:1.6;
}
#shelfmgr-root .ghost{
  position:fixed;z-index:999;pointer-events:none;background:var(--text);color:#fff;
  font-size:12.5px;font-weight:600;padding:7px 12px;border-radius:999px;
  box-shadow:0 6px 16px rgba(0,0,0,.25);transform:translate(-50%,-140%);
  display:flex;align-items:center;gap:6px;
}
#shelfmgr-root .ghost .sw{width:9px;height:9px;border-radius:3px;}

#shelfmgr-root .select-bar{
  position:fixed;left:12px;right:12px;bottom:calc(12px + env(safe-area-inset-bottom));
  z-index:1000;background:var(--text);color:#fff;border-radius:14px;
  padding:11px 14px;display:flex;align-items:center;gap:8px;flex-wrap:wrap;
  box-shadow:0 8px 24px rgba(0,0,0,.28);font-size:13px;
}
#shelfmgr-root .select-bar[hidden]{display:none;}
#shelfmgr-root .select-bar .sb-dot{width:10px;height:10px;border-radius:50%;flex:0 0 auto;}
#shelfmgr-root .select-bar .sb-text{font-weight:500;}
#shelfmgr-root .select-bar .sb-text b{font-weight:700;}
#shelfmgr-root .select-bar .sb-hint{color:rgba(255,255,255,.7);font-size:12px;}
#shelfmgr-root .select-bar button{
  margin-left:auto;background:rgba(255,255,255,.14);color:#fff;border:none;border-radius:999px;
  padding:6px 14px;font-size:12.5px;font-weight:600;cursor:pointer;
}
#shelfmgr-root .select-bar button:hover{background:rgba(255,255,255,.24);}
@media (max-width:480px){
  #shelfmgr-root .select-bar{left:8px;right:8px;bottom:calc(8px + env(safe-area-inset-bottom));font-size:12.5px;}
  #shelfmgr-root .select-bar .sb-hint{width:100%;order:5;}
  #shelfmgr-root .product-list{max-height:46vh;}
}

#shelfmgr-root .save-btn{
  background:var(--accent);color:#fff;border:none;border-radius:999px;padding:6px 16px;
  font-weight:700;font-size:12.5px;cursor:pointer;transition:.15s;font-family:inherit;
}
#shelfmgr-root .save-btn:hover{background:var(--accent-dark);}
#shelfmgr-root .save-status{font-size:12px;color:var(--text-muted);white-space:nowrap;}
#shelfmgr-root .save-status.pending{color:var(--accent-dark);}
#shelfmgr-root .save-status.ok{color:#2f9e44;}
#shelfmgr-root .save-status.error{color:var(--danger);font-weight:600;}

/* ---------------- VIEW-ONLY MODE (khách, chưa đăng nhập admin) ---------------- */
#shelfmgr-root.shelfmgr-viewonly .add-form,
#shelfmgr-root.shelfmgr-viewonly .side-panel,
#shelfmgr-root.shelfmgr-viewonly .side-panel .hint,
#shelfmgr-root.shelfmgr-viewonly .levels-ctrl button,
#shelfmgr-root.shelfmgr-viewonly .product-card .del,
#shelfmgr-root.shelfmgr-viewonly .crate .clear-x,
#shelfmgr-root.shelfmgr-viewonly .note-admin{
  display:none !important;
}
#shelfmgr-root.shelfmgr-viewonly .layout{
  grid-template-columns:1fr;
}
#shelfmgr-root.shelfmgr-viewonly .note-view{
  display:block !important;
}
#shelfmgr-root.shelfmgr-viewonly .product-card{cursor:default;}
#shelfmgr-root.shelfmgr-viewonly .slot{cursor:default;}
#shelfmgr-root .note-view{display:none;}
