/* ═══════════════════ RESET & BASE ═══════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:        #0d0d16;
  --surface:   #131320;
  --panel:     #1a1a2e;
  --card:      #22223a;
  --border:    #2d2d4e;
  --accent:    #f0a500;
  --accent2:   #e07800;
  --text:      #e0e0f0;
  --text-dim:  #888899;
  --green:     #4caf50;
  --red:       #ef5350;
  --blue:      #42a5f5;
  --gold:      #ffd54f;
  --radius:    8px;
  --radius-sm: 4px;
  --shadow:    0 2px 12px rgba(0,0,0,.5);
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; }
body { background: var(--bg); color: var(--text); overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
input, select, button { font-family: inherit; font-size: 14px; }

/* ═══════════════════ SCROLLBAR ═══════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ═══════════════════ LOADING / ERROR ═══════════════════ */
#loading-overlay, #error-overlay {
  position: fixed; inset: 0; background: var(--bg);
  align-items: center; justify-content: center;
  z-index: 9999;
}
#loading-overlay { display: flex; }
.loading-box, .error-box {
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.error-box h2 { color: var(--red); font-size: 22px; }
.error-box p  { color: var(--text-dim); max-width: 420px; line-height: 1.6; }
.error-box button {
  padding: 10px 28px; background: var(--accent); color: #000;
  border: none; border-radius: var(--radius); cursor: pointer; font-weight: 600;
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--text-dim); font-size: 15px; }

/* ═══════════════════ HEADER ═══════════════════ */
header {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 54px;
  box-shadow: var(--shadow);
}

.logo { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.logo-icon { font-size: 22px; color: var(--accent); }
.logo-text { font-size: 17px; font-weight: 700; color: var(--text); letter-spacing: .5px; }
.logo-accent { color: var(--accent); }

.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  padding: 6px 18px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim); cursor: pointer;
  transition: all .15s; font-weight: 500; white-space: nowrap;
}
.tab:hover  { background: var(--card); color: var(--text); }
.tab.active { background: var(--accent); color: #000; font-weight: 700; }

.catalog-info { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.user-menu { display: flex; align-items: center; gap: 10px; }
.user-name-badge {
  font-size: 12px; color: var(--accent); font-weight: 700;
  background: rgba(240,165,0,.12); padding: 3px 10px; border-radius: 12px;
}
.user-link {
  font-size: 12px; color: var(--text-dim); white-space: nowrap;
  transition: color .15s;
}
.user-link:hover { color: var(--text); }
.logout-link:hover { color: var(--red); }
.admin-link { color: var(--red) !important; }

/* ═══════════════════ LAYOUT ═══════════════════ */
.tab-content { display: none; padding: 16px 20px; }
.tab-content.active { display: block; }

/* ═══════════════════ PANEL ═══════════════════ */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.panel-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--accent); margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}

/* ═══════════════════ BUILD TAB ═══════════════════ */
.build-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  max-width: 1280px;
}
@media (max-width: 900px) { .build-layout { grid-template-columns: 1fr; } }

/* Searchable select widget */
.ssel-wrap { position: relative; width: 100%; }
.ssel-display {
  width: 100%; padding: 8px 32px 8px 10px; box-sizing: border-box;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; user-select: none; font-size: 13px;
  transition: border-color .15s; position: relative;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ssel-display::after {
  content: '▾'; position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%); color: var(--text-dim); pointer-events: none;
}
.ssel-display:hover, .ssel-display:focus { border-color: var(--accent); outline: none; }
.ssel-dropdown {
  position: absolute; top: calc(100% + 3px); left: 0; right: 0; z-index: 300;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.ssel-search {
  width: 100%; box-sizing: border-box; padding: 7px 10px; font-size: 12px;
  background: var(--surface); color: var(--text);
  border: none; border-bottom: 1px solid var(--border); outline: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.ssel-search:focus { border-bottom-color: var(--accent); }
.ssel-list { max-height: 260px; overflow-y: auto; }
.ssel-item {
  padding: 8px 10px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); transition: background .1s;
}
.ssel-item:last-child { border-bottom: none; }
.ssel-item:hover { background: var(--panel); }
.ssel-item.active { color: var(--accent); }
.ssel-item-icon { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; margin-right: 8px; }
.ssel-item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ssel-item-sub { font-size: 11px; color: var(--text-dim); flex-shrink: 0; margin-left: 8px; }
.ssel-empty { padding: 12px 10px; color: var(--text-dim); font-size: 13px; text-align: center; }

.mini-stats { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.mini-stat-chip {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 3px; padding: 2px 6px; font-size: 11px;
  color: var(--text-dim);
}

.container-info {
  margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-dim);
}
.container-info span strong { color: var(--accent); }

/* Slots */
.artifact-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.slot {
  aspect-ratio: 1;
  background: var(--card);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  cursor: pointer; padding: 8px;
  transition: border-color .15s, background .15s;
  position: relative; text-align: center;
  min-height: 90px;
}
.slot:hover { border-color: var(--accent); background: #1e1e38; }
.slot.filled { border-style: solid; border-color: var(--border); }
.slot.filled:hover { border-color: var(--accent); }
.slot-empty-icon { font-size: 24px; color: var(--border); margin-bottom: 4px; }
.slot-empty-text { font-size: 11px; color: var(--text-dim); }
.slot-art-name { font-size: 11px; font-weight: 600; color: var(--text); line-height: 1.3; }
.slot-art-stats { font-size: 10px; color: var(--text-dim); margin-top: 3px; line-height: 1.4; }
.slot-remove {
  position: absolute; top: 4px; right: 4px;
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 14px; line-height: 1; padding: 2px 4px;
  border-radius: 3px;
}
.slot-remove:hover { color: var(--red); background: rgba(239,83,80,.15); }
.slot-icon { width: 38px; height: 38px; object-fit: contain; margin-bottom: 4px; }

.mode-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
.mode-label { font-size: 12px; color: var(--text-dim); }
.radio-label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.radio-label input { accent-color: var(--accent); }
.hp-input {
  width: 64px; padding: 3px 6px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
}
.hp-input:focus { border-color: var(--accent); }

/* Stats panel */
.build-right { display: flex; flex-direction: column; }
.stats-panel { flex: 1; }

.eff-hp-block {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  text-align: center;
}
.eff-hp-label { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--accent); }
.eff-hp-value { font-size: 36px; font-weight: 900; color: var(--gold); line-height: 1.1; margin: 4px 0; }
.eff-hp-formula { font-size: 10px; color: var(--text-dim); font-style: italic; }

.stats-list { display: flex; flex-direction: column; gap: 4px; }
.stats-placeholder { color: var(--text-dim); font-size: 13px; text-align: center; padding: 32px 0; }

.stat-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--card);
  gap: 8px;
}
.stat-row:hover { background: #252545; }
.stat-name { color: var(--text-dim); font-size: 12px; flex: 1; }
.stat-value { font-weight: 700; font-size: 13px; white-space: nowrap; }
.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-value.neutral  { color: var(--text-dim); }

.stat-section-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--accent); padding: 8px 8px 4px; font-weight: 700;
}

/* ═══════════════════ INVENTORY TAB ═══════════════════ */
.inv-layout { max-width: 1100px; }

/* ── Add bar (search + filters) ── */
.inv-add-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  margin-bottom: 20px;
}
.inv-add-wrapper { position: relative; flex: 1; min-width: 260px; }
.inv-add-wrapper input[type=search] {
  width: 100%; box-sizing: border-box;
  padding: 9px 14px; font-size: 13px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
}
.inv-add-wrapper input:focus { border-color: var(--accent); }

/* ── Dropdown ── */
.inv-add-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 200;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 300px; overflow-y: auto;
}
.inv-dd-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); transition: background .1s;
}
.inv-dd-item:last-child { border-bottom: none; }
.inv-dd-item:hover { background: var(--panel); }
.inv-dd-icon { width: 30px; height: 30px; object-fit: contain; flex-shrink: 0; margin-right: 10px; }
.inv-dd-name { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; min-width: 0; }
.inv-dd-cat  { font-size: 11px; color: var(--text-dim); flex-shrink: 0; margin-left: 10px; }
.inv-dd-empty { padding: 14px; color: var(--text-dim); font-size: 13px; text-align: center; }

/* ── Filters ── */
.inv-filters { display: flex; gap: 6px; }
.filter-btn {
  padding: 6px 14px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-dim); border-radius: var(--radius-sm);
  cursor: pointer; transition: all .15s;
}
.filter-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.filter-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }
.save-status { font-size: 12px; color: var(--green); }

/* ── Inventory list ── */
.inv-list { }

.inv-empty {
  color: var(--text-dim); text-align: center;
  padding: 48px 20px; font-size: 14px; line-height: 1.7;
}
.inv-section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--accent);
  margin: 20px 0 8px;
}
.inv-section-title:first-child { margin-top: 0; }
.inv-section-count {
  font-size: 11px; color: var(--text-dim); font-weight: 400;
}
.inv-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

/* ── Card ── */
.inv-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  display: flex; align-items: flex-start; gap: 8px;
  transition: border-color .15s;
}
.inv-card:hover { border-color: var(--border); }
.inv-card-remove {
  flex-shrink: 0; width: 20px; height: 20px; margin-top: 1px;
  background: none; border: 1px solid var(--border); border-radius: 50%;
  color: var(--text-dim); cursor: pointer; font-size: 9px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; line-height: 1; padding: 0;
}
.inv-card-remove:hover { border-color: var(--red); color: var(--red); background: rgba(239,83,80,.12); }
.inv-card-icon { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; }
.inv-card-body { flex: 1; min-width: 0; }
.inv-card-name { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.3; margin-bottom: 3px; }
.inv-card-cat  { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.inv-card-stats { font-size: 11px; color: var(--text-dim); line-height: 1.5; }

/* Rarity colors */
.color-DEFAULT        { border-left: 3px solid #888; }
.color-RANK_NEWBIE    { border-left: 3px solid #6ebf6e; }
.color-RANK_STALKER   { border-left: 3px solid #42a5f5; }
.color-RANK_VETERAN   { border-left: 3px solid #ab47bc; }
.color-RANK_MASTER    { border-left: 3px solid var(--accent); }
.color-RANK_LEGEND    { border-left: 3px solid #ef5350; }

/* ═══════════════════ OPTIMIZER TAB ═══════════════════ */
.opt-layout { max-width: 1000px; }

.preset-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-btn {
  padding: 8px 20px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); border-radius: var(--radius);
  cursor: pointer; transition: all .15s; font-weight: 500;
}
.preset-btn:hover  { border-color: var(--accent); }
.preset-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.preset-desc { font-size: 11px; color: var(--text-dim); margin-top: 8px; }

.hint { font-size: 11px; color: var(--text-dim); font-weight: 400; text-transform: none; letter-spacing: 0; }

.sliders-container { display: flex; flex-direction: column; gap: 8px; }
.slider-row {
  display: grid;
  grid-template-columns: 180px 1fr 60px;
  align-items: center;
  gap: 10px;
}
.slider-name { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slider-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 2px; outline: none; cursor: pointer;
  background: linear-gradient(to right, var(--red) 0%, var(--border) 50%, var(--green) 100%);
}
.slider-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
  border: 2px solid #000;
}
.slider-value { font-size: 12px; font-weight: 700; text-align: right; min-width: 40px; }
.slider-value.pos { color: var(--green); }
.slider-value.neg { color: var(--red); }
.slider-value.zero { color: var(--text-dim); }

.opt-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.opt-hp-row { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; font-size: 13px; color: var(--text-dim); }
.btn-optimize {
  padding: 10px 28px; background: var(--accent); color: #000;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-weight: 700; font-size: 14px; transition: background .15s;
  white-space: nowrap;
}
.btn-optimize:hover { background: var(--accent2); }
.btn-optimize:disabled { background: var(--border); color: var(--text-dim); cursor: not-allowed; }

.opt-results { display: flex; flex-direction: column; gap: 12px; }
.opt-result-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  transition: border-color .15s;
}
.opt-result-card:hover { border-color: var(--accent); }
.opt-result-card.rank-1 { border-color: var(--gold); }

.opt-result-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.opt-rank { font-size: 13px; font-weight: 700; color: var(--text-dim); }
.opt-rank-1 { color: var(--gold); }
.opt-eff-hp { font-size: 22px; font-weight: 900; color: var(--gold); }
.opt-eff-hp small { font-size: 12px; color: var(--text-dim); font-weight: 400; }
.btn-apply {
  padding: 6px 18px; background: var(--green); color: #000;
  border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 700;
}
.btn-apply:hover { background: #66bb6a; }

.opt-items { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.opt-tag {
  padding: 3px 10px; border-radius: 12px; font-size: 11px;
  background: var(--card); border: 1px solid var(--border); color: var(--text-dim);
}
.opt-tag.armor-tag    { border-color: var(--blue); color: var(--blue); }
.opt-tag.cont-tag     { border-color: var(--accent); color: var(--accent); }
.opt-tag.art-tag      { border-color: var(--green); color: var(--green); }

.opt-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.opt-stat-chip {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 3px 8px; font-size: 11px;
}
.opt-stat-chip .v { font-weight: 700; }
.opt-stat-chip .v.pos { color: var(--green); }
.opt-stat-chip .v.neg { color: var(--red); }

.no-inv-warning {
  background: rgba(240,165,0,.1); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 16px; color: var(--text-dim);
  text-align: center;
}

/* ═══════════════════ MODAL ═══════════════════ */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-content {
  position: relative; z-index: 1;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(680px, 96vw); max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: 0 8px 40px rgba(0,0,0,.8);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; color: var(--accent); }
.modal-close {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 18px;
}
.modal-close:hover { color: var(--red); }
.modal-search { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.modal-search input {
  width: 100%; padding: 8px 12px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
}
.modal-search input:focus { border-color: var(--accent); }
.picker-cats { display: flex; flex-wrap: wrap; gap: 6px; }
.picker-cat-btn {
  padding: 3px 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-dim);
  border-radius: 12px; font-size: 11px; cursor: pointer;
}
.picker-cat-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.picker-list {
  flex: 1; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 8px;
}
.picker-item {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  cursor: pointer; transition: border-color .12s;
  display: flex; align-items: flex-start; gap: 8px;
}
.picker-item:hover { border-color: var(--accent); }
.picker-item-icon { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; }
.picker-item-body { flex: 1; min-width: 0; }
.picker-item-name { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.picker-item-stats { font-size: 10px; color: var(--text-dim); line-height: 1.5; }
.picker-item-stats .p { color: var(--green); }
.picker-item-stats .n { color: var(--red); }
