:root{
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1e1e1f;
  --ink-soft: #5b5b5e;
  --border: #e3e2de;
  --accent: #4b4ac0;
  --accent-soft: #eeeeff;
  --ok: #1f7a4c;
  --warn: #b3541e;

  --r-uncommon: #1f7a4c;
  --r-rare: #1c6fd0;
  --r-veryrare: #8e2fc9;
  --r-legendary: #b3760a;
  --r-artifact: #c0392b;
}
*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; background:var(--bg); color:var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; }

header{ padding: 20px 20px 18px 20px; border-bottom: 1px solid var(--border); background: var(--panel); }
.backlink{ display:inline-block; font-size:12.5px; color: var(--ink-soft); text-decoration:none; margin-bottom:8px; margin-right:14px; }
.backlink:hover{ color: var(--accent); }
header h1{ margin:0 0 4px 0; font-size: 22px; letter-spacing: -0.01em; }
header p{ margin:0; color: var(--ink-soft); font-size: 13.5px; }

.toolbar{
  display:flex; flex-wrap:wrap; gap:10px; align-items:center;
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top:0; z-index: 5;
}
select, input[type=text]{
  padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
  font-size: 13.5px; color: var(--ink); max-width: 100%;
}
button.btn, .toolbar button{
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent-soft); color: var(--accent); font-size: 13.5px; font-weight:600;
  cursor:pointer; white-space:nowrap;
}
button.btn:hover, .toolbar button:hover{ background: var(--accent); color: white; }
button.btn:disabled, .toolbar button:disabled{ opacity:.4; cursor:not-allowed; }
button.btn.subtle{ background: var(--bg); color: var(--ink-soft); border-color: var(--border); }
button.btn.subtle:hover{ background: var(--border); color: var(--ink); }

.searchWrap{ position:relative; padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.searchWrap input[type=text]{ width:100%; padding: 10px 14px; }
.searchWrap input[type=text]:focus{ outline: 2px solid var(--accent); outline-offset:1px; }
.searchResults{
  position:absolute; left:20px; right:20px; top: 58px; background: var(--panel);
  border:1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  max-height: 320px; overflow-y:auto; z-index: 10; display:none;
}
.searchResults.show{ display:block; }
.searchHint{ font-size:11.5px; color: var(--ink-soft); margin-top:6px; }
.searchRow{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding: 9px 14px; border-bottom: 1px solid var(--border); cursor:pointer;
}
.searchRow:hover{ background: var(--bg); }
.searchRow:last-child{ border-bottom:none; }
.searchRow .info{ min-width:0; }
.searchRow .info .n{ font-weight:600; font-size:13.6px; }
.searchRow .info .meta{ font-size:11.5px; color: var(--ink-soft); }
.searchRow button{
  flex-shrink:0; padding: 6px 12px; border-radius:7px; border:1px solid var(--accent);
  background: var(--accent-soft); color: var(--accent); font-size:12.5px; font-weight:600; cursor:pointer;
}
.searchRow button:hover{ background: var(--accent); color:white; }
.searchEmpty{ padding: 14px; font-size: 13px; color: var(--ink-soft); text-align:center; }

main{ max-width: 900px; margin: 0 auto; padding: 20px 20px 70px 20px; }

.itemName{ font-weight:600; font-size:13.8px; word-break: break-word; cursor:pointer; }
.itemName:hover{ text-decoration: underline; }
.itemName.rarity-uncommon{ color: var(--r-uncommon); }
.itemName.rarity-rare{ color: var(--r-rare); }
.itemName.rarity-veryrare{ color: var(--r-veryrare); }
.itemName.rarity-legendary{ color: var(--r-legendary); }
.itemName.rarity-artifact{ color: var(--r-artifact); }
.catTag{
  font-size: 10.5px; padding: 2px 8px; border-radius: 999px; border:1px solid var(--border);
  background: var(--bg); color: var(--ink-soft); white-space:nowrap; margin-left:6px;
}
.itemNote{ font-size:11.5px; color: var(--ink-soft); margin-top:2px; }

.empty{ text-align:center; color: var(--ink-soft); padding: 60px 16px; font-size: 14px; }
.empty b{ display:block; font-size: 16px; color: var(--ink); margin-bottom:6px; }

.footnote{ margin-top: 18px; font-size:11.5px; color: var(--ink-soft); line-height:1.5; }

/* ---- Generic modal (settings / saved shops / item detail) ---- */
.modalBackdrop{
  position:fixed; inset:0; background: rgba(20,18,28,0.45); display:none;
  align-items:center; justify-content:center; padding: 20px; z-index: 100;
}
.modalBackdrop.show{ display:flex; }
.modal{
  background: var(--panel); border-radius: 14px; max-width: 520px; width:100%;
  max-height: 85vh; overflow-y:auto; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal h3{ margin: 0 0 4px 0; font-size: 18px; display:flex; justify-content:space-between; align-items:center; gap:10px; }
.modal .modalClose{ border:none; background:none; font-size:18px; cursor:pointer; color: var(--ink-soft); line-height:1; }
.modal .modalClose:hover{ color: var(--ink); }
.modal .modalSub{ font-size:12.5px; color: var(--ink-soft); margin: 0 0 16px 0; }
.modal .sliderRow{ margin-bottom: 14px; }
.modal .sliderRow label{ display:flex; justify-content:space-between; font-size:13px; margin-bottom:4px; }
.modal .sliderRow input[type=range]{ width:100%; accent-color: var(--accent); }
.modal .modalActions{ display:flex; gap:8px; justify-content:flex-end; margin-top: 16px; flex-wrap:wrap; }

.savedRow{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.savedRow:last-child{ border-bottom:none; }
.savedRow .info .n{ font-weight:600; font-size:13.8px; }
.savedRow .info .meta{ font-size:11.5px; color: var(--ink-soft); }
.savedRow .actions{ display:flex; gap:6px; flex-shrink:0; }

/* Item detail modal specifically: allow it to grow with long descriptions
   (up to the full window, per request) instead of staying pinned to the
   compact size shared by the Settings/Saved Shops modals. */
#itemModalBackdrop .modal{ max-width: min(760px, 94vw); max-height: 92vh; }
.itemDesc{ font-size:13.8px; line-height:1.6; margin-top:4px; }
.itemDesc p{ margin: 0 0 12px 0; }
.itemDesc p:last-child{ margin-bottom:0; }

.modalSource{
  margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border);
  font-size: 12.5px; font-style: italic; color: var(--ink-soft);
}
.modalSource a{ color: var(--accent); }

.statTable{ width:100%; border-collapse:collapse; margin-top:10px; font-size:13px; }
.statTable a{ color: var(--accent); word-break: break-all; }
.statTable td{ padding: 5px 0; border-bottom: 1px solid var(--border); }
.statTable td:first-child{ color: var(--ink-soft); width: 40%; }
.statTable tr:last-child td{ border-bottom:none; }

/* ---- Edit Item form (shop-common.js ensureEditModal) ---- */
.editRow{ margin-bottom:12px; }
.editRow label{ display:block; font-size:12.5px; font-weight:600; color:var(--ink-soft); margin-bottom:4px; }
.editRow input[type=text], .editRow input[type=number], .editRow select, .editRow textarea, #editPwInput{
  width:100%; padding:8px 10px; border-radius:8px; border:1px solid var(--border); background:var(--bg);
  font-size:13.5px; color:var(--ink); font-family:inherit;
}
.editRow textarea{ resize:vertical; }
.editRow2col{ display:grid; grid-template-columns:1fr 1fr; gap:0 12px; }
.editError{ color:var(--warn); font-size:12.5px; margin:8px 0 0 0; min-height:1em; }

/* Rich-text description box (contenteditable) in the item editor -- styled
   to match the plain form fields, but rendered with the same typography as
   .itemDesc (the shop/item-detail read view) so bold/italic/paragraphs look
   identical in both places instead of showing raw marker characters. */
.editDescBox{
  width:100%; min-height:110px; max-height:320px; overflow-y:auto; padding:8px 10px;
  border-radius:8px; border:1px solid var(--border); background:var(--bg);
  font-size:13.5px; line-height:1.6; color:var(--ink); font-family:inherit;
}
.editDescBox:focus{ outline:2px solid var(--accent); outline-offset:-1px; }
.editDescBox p{ margin:0 0 12px 0; }
.editDescBox p:last-child{ margin-bottom:0; }
.editDescBox:empty::before{ content: attr(data-placeholder); color: var(--ink-soft); }
.editDescHint{ font-size:11.5px; color:var(--ink-soft); margin-top:4px; }
@media (max-width:480px){ .editRow2col{ grid-template-columns:1fr; } }

/* Shared with loot-common.css's identical rules (this file loads on pages
   that don't include that one -- shop/index.html, shop/items.html -- but
   the Edit Item form's new "Manually set which shops carry this item"
   section, shared code in shop-common.js, needs them everywhere). */
.checkboxRow{ display:flex; align-items:center; gap:8px; font-size:13px; margin-bottom:6px; }
.checkboxRow input[type=checkbox]{ width:15px; height:15px; accent-color: var(--accent); flex-shrink:0; }
.checkGroup{ display:flex; flex-wrap:wrap; gap:8px 16px; margin: 4px 0 12px 0; }

.iconBtn{
  border:1px solid var(--border); background: var(--bg); border-radius:7px; cursor:pointer;
  font-size:13px; padding: 5px 8px; line-height:1;
}
.iconBtn:hover{ background: var(--accent-soft); border-color: var(--accent); }
.iconBtn.on{ background: var(--accent); border-color: var(--accent); color:white; }

.toast{
  position:fixed; left:50%; bottom:28px; transform: translate(-50%, 12px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight:600; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity:0; pointer-events:none; transition: opacity .18s ease, transform .18s ease; z-index: 200;
}
.toast.show{ opacity:1; transform: translate(-50%, 0); }

.sortBar{
  display:flex; align-items:center; gap:8px; padding: 10px 16px; flex-wrap:wrap;
  background: var(--bg); border-bottom: 1px solid var(--border); font-size:12.5px; color: var(--ink-soft);
}
.sortBar .sortBtn{
  padding: 5px 11px; border-radius: 999px; border:1px solid var(--border); background: var(--panel);
  color: var(--ink-soft); font-size:12px; font-weight:600; cursor:pointer;
}
.sortBar .sortBtn:hover{ border-color: var(--accent); color: var(--accent); }
.sortBar .sortBtn.active{ background: var(--accent); border-color: var(--accent); color: #fff; }
.sortBar .sortBarReroll{ margin-left: auto; font-size:12.5px; }

.addBtn{
  flex-shrink:0; padding: 6px 12px; border-radius:7px; border:1px solid var(--accent);
  background: var(--accent-soft); color: var(--accent); font-size:12.5px; font-weight:600; cursor:pointer;
}
.addBtn:hover{ background: var(--accent); color:white; }
.addBtn:disabled{ opacity:.4; cursor:not-allowed; background:var(--bg); color:var(--ink-soft); border-color:var(--border); }

@media (max-width: 640px){
  header{ padding: 16px 14px; }
  .toolbar, .searchWrap, .legend{ padding-left:14px; padding-right:14px; }
  main{ padding: 16px 14px 60px 14px; }
  .toolbar select, .toolbar button.wide{ width:100%; }
  .searchResults{ left:14px; right:14px; }
  .modal{ padding: 18px; }
}
