:root {
  --bg: #121820;
  --panel: #161d27;
  --card: #1d2531;
  --card-2: #232c39;
  --line: #2b3442;
  --line-2: #344050;
  --text: #e8ecf1;
  --muted: #9aa4b2;
  --faint: #6c7686;
  --blue: #4f80f0;
  --blue-2: #6b95f5;
  --green: #3ad07a;
  --red: #f0554f;
  --orange: #f0a23c;
  /* artifact rarity */
  --q0: #c9ced6; --q1: #3ad07a; --q2: #3fa9f5; --q3: #b46cff; --q4: #ff5a7a; --q5: #ffc23d; --q6: #ff8a3d;
  /* item rank */
  --rDEFAULT: #e8ecf1; --rRANK_NEWBIE: #3ad07a; --rRANK_STALKER: #3fa9f5; --rRANK_VETERAN: #b46cff;
  --rRANK_MASTER: #ff5a5a; --rRANK_LEGEND: #ffc23d;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue-2); }
code, pre { font-family: Consolas, "SF Mono", monospace; font-size: 13px; }
:focus-visible { outline: 2px solid var(--blue-2); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 8px; padding: 8px 16px; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--card-2); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-2); }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 6px; }
.btn.danger { color: var(--red); border-color: rgba(240, 85, 79, .5); }
.btn.close { float: right; }
.inp {
  width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 7px;
  padding: 7px 10px; color: var(--text);
}
.inp:focus { border-color: var(--blue); outline: none; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); }
.check input { width: 16px; height: 16px; accent-color: var(--blue); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card-2); color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-2); background: none; border-radius: 6px; padding: 4px 10px; cursor: pointer; color: var(--muted); font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--card-2); color: var(--text); border-color: var(--faint); }
.chip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 4px; }
.tag { background: var(--card-2); border-radius: 5px; padding: 2px 8px; font-size: 12px; cursor: pointer; }
.tag:hover { text-decoration: line-through; }
.row-btns { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; }
.form-err { color: var(--red); min-height: 1em; margin: 6px 0 0; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 22px; height: 58px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 30; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.tabs { display: flex; height: 100%; gap: 2px; }
.tabs button { background: none; border: 0; padding: 0 12px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--blue); }
.badge { background: var(--green); color: #0b1a10; border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.status-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.dot.ok { background: var(--green); }
.profile-menu { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line-2); border-radius: 8px; padding: 4px; min-width: 180px; z-index: 40; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--card-2); }

main { padding: 16px 24px 60px; max-width: 1800px; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.sort { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.sort .inp { width: auto; }
.filters { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px 8px; margin-bottom: 14px; }
.filters h3 { font-size: 13px; font-weight: 600; margin: 14px 0 8px; }
.filters h3:first-child { margin-top: 0; }
.feed-meta { color: var(--muted); font-size: 13px; margin: 0 2px 8px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }

/* ---------- lot cards ---------- */
.cards.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cards.row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(300px, 380px); gap: 16px; overflow-x: auto; padding-bottom: 12px; }
.cards.row::-webkit-scrollbar { height: 8px; }
.cards.row::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; min-height: 330px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 14px; margin: 0 0 0; border-bottom: 1px solid var(--line-2); margin: 0 16px; padding-left: 0; padding-right: 0; }
.card-head img { width: 44px; height: 44px; object-fit: contain; flex: none; }
.card-name { margin-left: auto; text-align: right; font-weight: 700; font-size: 18px; line-height: 1.25; background: none; border: 0; cursor: pointer; padding: 0; }
.card-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.card-name .sep { opacity: .8; margin: 0 4px; }
.card-body { padding: 12px 16px; flex: 1; }
.kv-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.kv-row span:first-child { color: var(--muted); }
.kv-row span:last-child { text-align: right; }
.more { background: none; border: 0; padding: 4px 0 0; color: var(--orange); font-weight: 600; cursor: pointer; }
.more::after { content: " ›"; display: inline-block; transition: transform .15s; }
.more[aria-expanded="true"]::after { transform: rotate(90deg); }
.more-body { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line-2); font-size: 13px; }
.card-foot { border-top: 1px solid var(--line-2); padding: 12px 16px 14px; }
.card-foot .kv-row { padding: 4px 0; font-size: 15px; }
.cost { color: var(--red); font-weight: 600; }
.target { font-weight: 700; }
.profit-pos { color: var(--green); font-weight: 600; }
.profit-neg { color: var(--red); font-weight: 600; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions .btn { flex: 1; justify-content: center; }
.btn.bought { color: var(--green); border-color: rgba(58, 208, 122, .5); cursor: default; }
.card.deal { border-color: rgba(58, 208, 122, .65); box-shadow: 0 0 0 1px rgba(58, 208, 122, .25); }
.card.flash { animation: flash 1.8s ease-out 1; }
@keyframes flash { 0%, 25% { box-shadow: 0 0 0 3px rgba(58, 208, 122, .6); } 100% { box-shadow: 0 0 0 1px rgba(58, 208, 122, .25); } }
.card.fresh .listed-val { color: var(--green); }
@media (prefers-reduced-motion: reduce) { .card.flash { animation: none; } .more::after { transition: none; } }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; max-width: 560px; margin: 0 auto; }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 8px; }

/* colors by rarity / rank */
.q0 { color: var(--q0); } .q1 { color: var(--q1); } .q2 { color: var(--q2); } .q3 { color: var(--q3); }
.q4 { color: var(--q4); } .q5 { color: var(--q5); } .q6 { color: var(--q6); }
.rDEFAULT { color: var(--rDEFAULT); } .rRANK_NEWBIE { color: var(--rRANK_NEWBIE); } .rRANK_STALKER { color: var(--rRANK_STALKER); }
.rRANK_VETERAN { color: var(--rRANK_VETERAN); } .rRANK_MASTER { color: var(--rRANK_MASTER); } .rRANK_LEGEND { color: var(--rRANK_LEGEND); }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: right; color: var(--faint); font-weight: 500; font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl .l { text-align: left; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover, .tbl th.sorted { color: var(--text); }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: var(--card); }
.item-cell { display: flex; align-items: center; gap: 10px; }
.item-cell img { width: 32px; height: 32px; object-fit: contain; }
.item-cell b { font-weight: 600; }
.sub { font-size: 12px; color: var(--muted); }

/* ---------- price history ---------- */
.hist-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; }
.hist-side { display: flex; flex-direction: column; gap: 8px; position: sticky; top: 72px; align-self: start; }
#hCount { font-size: 12px; padding: 0 2px; }
.hist-list { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; max-height: calc(100vh - 210px); overflow-y: auto; overscroll-behavior: contain; }
.hist-list button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 7px 10px; cursor: pointer; }
.hist-list button:hover, .hist-list button[aria-current="true"] { background: var(--card); }
.hist-list img { width: 28px; height: 28px; object-fit: contain; }
.h-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.h-head img { width: 56px; height: 56px; object-fit: contain; }
.h-head h2 { margin: 0; font-size: 22px; }
.h-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.h-controls .inp { width: auto; min-width: 150px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile > b { display: block; font-size: 19px; font-weight: 700; }
.tile > span { font-size: 12px; color: var(--muted); }
.chart-box { position: relative; height: 300px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 4px 8px; border-radius: 5px; white-space: nowrap; transform: translate(-50%, -125%); }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.legend i.ln { width: 14px; height: 3px; border-radius: 1px; vertical-align: 3px; }
.h-section { font-size: 15px; margin: 20px 0 6px; }
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 70px; margin-top: 6px; }
.hours div { background: var(--blue); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .8; }
.hours div.best { background: var(--green); opacity: 1; }
.hours-axis { display: grid; grid-template-columns: repeat(24, 1fr); font-size: 10px; color: var(--faint); text-align: center; }

/* ---------- purchases ---------- */
.add-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; padding: 14px 18px 4px; }
.add-form .grow { flex: 1; min-width: 220px; }
.w80 { width: 90px; } .w140 { width: 150px; }
.purchase { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; }
.p-row { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(4, minmax(110px, 1fr)) auto; gap: 12px; align-items: center; padding: 12px 16px; }
.p-row .lbl { font-size: 12px; color: var(--muted); }
.p-row .val { font-weight: 600; }
.p-actions { display: flex; gap: 6px; }
.advice { border-top: 1px solid var(--line); padding: 14px 16px 16px; }
.verdict { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.verdict.sell { color: var(--green); } .verdict.hold { color: var(--orange); } .verdict.wait { color: var(--red); } .verdict.unknown { color: var(--muted); }
.advice-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; margin-top: 12px; }

/* ---------- api / modals / misc ---------- */
.doc h2 { font-size: 17px; margin: 18px 0 6px; }
.doc h2:first-child { margin-top: 0; }
.keybox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.keybox code { background: var(--bg); border: 1px solid var(--line-2); border-radius: 7px; padding: 8px 12px; font-size: 14px; }
pre { background: var(--bg); border: 1px solid var(--line-2); border-radius: 8px; padding: 12px; overflow-x: auto; white-space: pre; }
.doc-tbl td { white-space: normal; }
.modal-bg { position: fixed; inset: 0; background: rgba(5, 8, 12, .72); z-index: 60; display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; padding: 22px 24px; width: min(640px, 100%); margin-bottom: 40px; }
.modal.wide { width: min(1100px, 100%); }
.modal.small { width: min(360px, 100%); }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal h3 { font-size: 14px; margin: 18px 0 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }
.log { max-height: 200px; overflow-y: auto; font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); border-radius: 8px; padding: 10px 16px; display: none; gap: 14px; align-items: center; z-index: 90; font-weight: 500; }
.toast.show { display: flex; }
.toast button { background: none; border: 0; color: var(--blue); font-weight: 700; cursor: pointer; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.login-box { width: min(460px, 100%); }
.login-title { font-size: 28px; margin: 0 0 4px; }
.profile-list { display: flex; flex-direction: column; gap: 8px; margin: 20px 0; }
.profile-list button { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; cursor: pointer; font-weight: 600; font-size: 15px; text-align: left; }
.profile-list button:hover { border-color: var(--blue); }
.new-profile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.new-profile h2 { font-size: 16px; margin: 0 0 12px; }

@media (max-width: 1100px) { .filters { grid-template-columns: 1fr 1fr; } .p-row { grid-template-columns: 1fr 1fr; } .advice-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .top { gap: 10px; padding: 0 12px; overflow-x: auto; }
  main { padding: 12px; }
  .filters, .hist-layout, .grid3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .cards.grid { grid-template-columns: 1fr; }
  .hist-side { position: static; }
  .hist-list { max-height: 50vh; }
}

/* ---------- live listings / insights / speed ---------- */
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; color: var(--text); }
.live-tbl tr.this td { background: rgba(79, 128, 240, .16); }
.live-tbl tr.cheaper td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.note { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--orange); border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; }
.note.good { border-left-color: var(--green); }
.ins-section { margin-bottom: 22px; }
.ins-section > h2 { font-size: 17px; margin: 0 0 4px; }
.ins-section > p { margin: 0 0 10px; }
.bars { display: grid; gap: 3px; align-items: end; height: 80px; }
.bars div { background: var(--blue); border-radius: 2px 2px 0 0; min-height: 2px; position: relative; }
.bars div.lo { background: var(--green); }
.bars div.hi { background: var(--red); }
.bars-axis { display: grid; font-size: 10px; color: var(--faint); text-align: center; margin-top: 3px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.advice-text { margin: 4px 0 0; color: var(--muted); font-size: 13px; white-space: normal; max-width: 520px; }
.budget { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 8px 0 6px; }
.meter { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; margin: 8px 0 6px; }
.meter div { height: 100%; background: var(--green); }
.meter div.over { background: var(--orange); }
.watch.on { color: var(--orange); border-color: rgba(240, 162, 60, .55); }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }

/* ---------- alerts / investments ---------- */
.badge.orange { background: var(--orange); color: #1a1205; }
.panel-title { font-size: 16px; margin: 0 0 6px; }
.section-title { font-size: 17px; margin: 22px 0 8px; }
.card.alerted { border-color: var(--orange); box-shadow: 0 0 0 1px rgba(240, 162, 60, .35); }
.alert-tag { display: inline-block; background: var(--orange); color: #1a1205; font-size: 11px; font-weight: 700; border-radius: 4px; padding: 1px 6px; margin-right: 6px; vertical-align: 2px; }
.spark { display: block; }
.tagpill { display: inline-block; font-size: 11px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 7px; margin: 2px 4px 0 0; color: var(--muted); }
.tagpill.good { color: var(--green); border-color: rgba(58, 208, 122, .5); }
.tagpill.bad { color: var(--red); border-color: rgba(240, 85, 79, .5); }
.toggle { width: 36px; height: 20px; accent-color: var(--blue); }
.warn { color: var(--orange); }

/* ---------- roles ---------- */
body.not-admin .admin-only { display: none !important; }
body:not(.not-admin) .non-admin-only { display: none !important; }
body.not-admin #spGroups .seg, body.not-admin #spList, body.not-admin #page-speed .grid3 { pointer-events: none; opacity: .7; }
code.invite { font-size: 14px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; padding: 3px 8px; }
#page-speed .grid3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
body.not-admin #spCheap { pointer-events: none; opacity: .7; }
.ex-filters { flex-wrap: wrap; gap: 8px; }
.ex-wrap { max-height: 520px; overflow: auto; border: 1px solid var(--line-2); border-radius: 8px; margin-top: 8px; }
.ex-wrap thead th { position: sticky; top: 0; background: var(--card); z-index: 1; }
.btn.danger-armed { background: #b83a3a; color: #fff; border-color: #b83a3a; }
#exQuick .btn[aria-pressed="true"] { border-color: var(--accent, #5b8cff); color: var(--text); }
.ctx { position: fixed; z-index: 1000; min-width: 230px; max-width: 320px; background: var(--card-2); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.ctx-title { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 7px 10px; border-radius: 6px; cursor: pointer; font: inherit; }
.ctx button:hover { background: var(--card); }
.ctx .ctx-danger { color: var(--red); }
.ctx .ctx-danger.danger-armed { background: #b83a3a; color: #fff; }
.advice-note { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--orange); border-radius: 8px; padding: 12px 16px; margin: 0 0 14px; }
.advice-note .an-full p { margin: 6px 0; color: var(--muted); line-height: 1.5; max-width: 980px; }
.advice-note .an-full .btn { margin-top: 4px; }
.advice-note .an-short { display: none; color: var(--muted); font-size: 13px; }
.advice-note.seen { padding: 8px 14px; }
.advice-note.seen .an-full { display: none; }
.advice-note.seen .an-short { display: block; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--orange); cursor: pointer; font: inherit; text-decoration: underline; }
