:root {
  --bg: #0f1419;
  --bg-card: #1a2028;
  --bg-elev: #232a35;
  --border: #2c3540;
  --text: #e6e6e6;
  --text-dim: #8a96a8;
  --accent: #c9a662;
  --accent-2: #9bb5c2;
  --good: #4caf50;
  --warn: #ff9800;
  --bad: #ef5350;
  --quest: #ab47bc;
  --hideout: #29b6f6;
  --barter: #ff7043;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Roboto", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  padding: 20px;
  min-height: 100vh;
}
.container { max-width: 1700px; margin: 0 auto; }
header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.title-block h1 {
  font-size: 24px; font-weight: 600; color: var(--accent);
  letter-spacing: -0.3px; display: flex; align-items: baseline; gap: 10px;
}
.title-block .badge {
  background: var(--accent); color: var(--bg);
  font-size: 11px; padding: 3px 8px; border-radius: 4px;
  font-weight: 700; letter-spacing: 0.5px;
}
.subtitle { color: var(--text-dim); margin-top: 6px; font-size: 13px; }
.subtitle a { color: var(--accent-2); text-decoration: none; }
.subtitle a:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; align-items: center; }
.btn {
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 6px; cursor: pointer; font-family: inherit;
  font-size: 13px; transition: all 0.15s;
}
.btn:hover { border-color: var(--accent-2); color: var(--accent); }
.btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.lang-toggle button {
  background: var(--bg-elev); color: var(--text-dim); border: none;
  padding: 8px 14px; font-family: inherit; font-size: 13px; cursor: pointer;
}
.lang-toggle button.active { background: var(--accent); color: var(--bg); font-weight: 600; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin: 18px 0;
}
.stat {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px;
}
.stat-label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 4px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.controls {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 0.7fr;
  gap: 10px; align-items: end;
  margin-bottom: 12px;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
input, select {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 6px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-dim);
  padding: 5px 10px; border-radius: 14px; font-size: 12px; cursor: pointer; user-select: none;
}
.tag:hover { color: var(--text); border-color: var(--accent-2); }
.tag.active { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.tag.quest.active { background: var(--quest); border-color: var(--quest); color: white; }
.tag.hideout.active { background: var(--hideout); border-color: var(--hideout); color: white; }
.tag.barter.active { background: var(--barter); border-color: var(--barter); color: white; }

.split { display: grid; grid-template-columns: 1fr 320px; gap: 14px; }
.controls--3 { grid-template-columns: 2fr 1fr 1fr; }
.controls--4 { grid-template-columns: 2fr 1fr 1fr 1fr; }
.controls--5 { grid-template-columns: 1fr 1fr 1fr 1fr 1fr; }

@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }

.table-wrap { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg-elev); position: sticky; top: 0; z-index: 5; }
th {
  text-align: left; padding: 10px 12px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-dim); cursor: pointer; user-select: none;
  white-space: nowrap; border-bottom: 1px solid var(--border);
}
th:hover { color: var(--accent); }
th.sorted { color: var(--accent); }
th.sorted::after { content: ' ↓'; }
th.sorted.asc::after { content: ' ↑'; }
td {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
tbody tr { transition: background 0.1s; cursor: pointer; }
tbody tr:hover { background: var(--bg-elev); }
tbody tr:hover td.name-cell a { color: var(--accent); }
.wiki-link {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 4px; font-size: 12px;
  color: var(--accent-2); text-decoration: none;
}
.wiki-link:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.margin-pct-high { color: var(--good); font-weight: 700; }
.margin-pct-mid { color: var(--warn); font-weight: 600; }
.margin-pct-low { color: var(--text-dim); }
.fir-badge {
  display: inline-block; background: #d32f2f; color: white;
  padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.3px; vertical-align: middle;
}
.fir-badge.small { font-size: 9px; padding: 0 4px; margin-left: 4px; }
.fir-warn {
  background: rgba(211, 47, 47, 0.12);
  border-left: 3px solid #d32f2f;
}
.station-bar.fir { border-color: #d32f2f; background: rgba(211, 47, 47, 0.1); }
.station-bar.fir .lvl { background: #d32f2f; }
.trader-info { color: var(--text-dim); font-size: 11px; }
.task-lock {
  display: inline-block; background: rgba(171, 71, 188, 0.15); border: 1px solid var(--quest);
  color: var(--quest); padding: 1px 6px; border-radius: 3px; font-size: 10px; font-weight: 600;
}
.cross-badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.3px;
  border: 1px solid; margin-left: 4px;
}
.cross-badge.hideout {
  background: rgba(41, 182, 246, 0.15); border-color: var(--hideout); color: var(--hideout);
}
.cross-badge.quest {
  background: rgba(171, 71, 188, 0.15); border-color: var(--quest); color: var(--quest);
}
.row-double {
  background: linear-gradient(90deg, rgba(171, 71, 188, 0.05), rgba(41, 182, 246, 0.05));
}
.kappa-check {
  width: 22px; height: 22px; border-radius: 4px;
  border: 2px solid var(--border); background: var(--bg-card);
  cursor: pointer; display: inline-block; vertical-align: middle;
  position: relative; transition: all 0.15s;
}
.kappa-check:hover { border-color: var(--accent); }
.kappa-check.checked { background: var(--good); border-color: var(--good); }
.kappa-check.checked::after {
  content: '✓'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 16px;
}
.row-done {
  opacity: 0.45;
  text-decoration: line-through;
  text-decoration-color: var(--good);
}
.row-done td:last-child { text-decoration: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.rank { color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; width: 38px; }
td.name-cell { font-weight: 500; }
td.name-cell .icon {
  width: 32px; height: 32px; border-radius: 4px;
  vertical-align: middle; margin-right: 10px; background: var(--bg-elev);
  display: inline-block;
}
td.name-cell a { color: var(--text); text-decoration: none; }
td.name-cell a:hover { color: var(--accent); }
.short { color: var(--text-dim); font-size: 11px; margin-left: 6px; }
.size-badge {
  display: inline-block; background: var(--bg-elev); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 4px; font-size: 11px; font-variant-numeric: tabular-nums;
}
.flags { display: inline-flex; gap: 4px; }
.flag {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 4px;
  font-size: 11px; font-weight: 700; color: white;
}
.flag.q { background: var(--quest); }
.flag.h { background: var(--hideout); }
.flag.b { background: var(--barter); }
.flag.f { background: var(--good); }
.method-flea { color: var(--good); font-weight: 500; }
.method-trader { color: var(--accent-2); }
.liq-high { color: var(--good); }
.liq-mid { color: var(--text); }
.liq-low { color: var(--warn); }
.row-quest { border-left: 3px solid var(--quest); }
.row-hideout { border-left: 3px solid var(--hideout); }
.row-quest.row-hideout { border-left: 3px solid; border-image: linear-gradient(to bottom, var(--quest), var(--hideout)) 1; }

.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: var(--bg-elev); border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
  flex-wrap: wrap; gap: 12px;
}
.pagi-controls { display: flex; gap: 4px; align-items: center; }
.pagi-btn {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 5px 10px; border-radius: 4px; cursor: pointer; font-family: inherit;
  font-size: 12px; min-width: 30px; text-align: center;
}
.pagi-btn:hover:not(:disabled) { border-color: var(--accent-2); color: var(--accent); }
.pagi-btn.current { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 600; }
.pagi-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.pagi-ellipsis { padding: 5px 6px; color: var(--text-dim); }
.pagi-size {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 4px 8px; border-radius: 4px; font-size: 12px; font-family: inherit;
}

.sidebar { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.card h3 { font-size: 13px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 0.5px; margin-bottom: 10px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 6px; }
.legend-row .flag { width: 18px; height: 18px; }
.legend-row .desc { color: var(--text-dim); }

.flip-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.flip-row { display: flex; justify-content: space-between; padding: 8px; background: var(--bg-elev); border-radius: 4px; font-size: 12px; }
.flip-row .name { color: var(--text); }
.flip-row .pct { color: var(--good); font-weight: 600; }
.flip-row .from { color: var(--text-dim); font-size: 11px; }

.chart-box { height: 260px; position: relative; }
.footer { margin-top: 24px; color: var(--text-dim); font-size: 12px; text-align: center; }
.footer a { color: var(--accent-2); }
.empty { padding: 60px 20px; text-align: center; color: var(--text-dim); }
.loader { padding: 80px 20px; text-align: center; color: var(--text-dim); font-size: 14px; }
.loader::before {
  content: ''; display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--text-dim); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin-right: 10px; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.refresh-info {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-dim);
}
.refresh-info .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--good);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.3; } }

.tabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent; color: var(--text-dim); border: none;
  padding: 10px 16px; cursor: pointer; font-family: inherit; font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab .badge-count {
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 10px; font-size: 11px; margin-left: 6px;
  color: var(--text-dim); font-weight: 400;
}
.tab.active .badge-count { background: var(--accent); color: var(--bg); border-color: var(--accent); }

.hideout-grid {
  display: grid; grid-template-columns: 1fr 320px; gap: 14px;
}
@media (max-width: 1100px) { .hideout-grid { grid-template-columns: 1fr; } }

.hideout-table .progress-cell {
  min-width: 100px; display: flex; align-items: center; gap: 8px;
}
.station-bar {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 12px; font-size: 12px;
  display: inline-flex; gap: 6px; align-items: center; margin: 2px;
}
.station-bar .lvl {
  background: var(--accent); color: var(--bg); padding: 1px 6px;
  border-radius: 3px; font-size: 10px; font-weight: 700;
}
.stations-list { display: flex; flex-direction: column; gap: 8px; max-height: 600px; overflow-y: auto; }
.station-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px; font-size: 12px;
  cursor: pointer; transition: all 0.15s;
}
.station-card:hover { border-color: var(--accent-2); }
.station-card.active { border-color: var(--accent); }
.station-card-head { display: flex; justify-content: space-between; font-weight: 600; }
.station-card-meta { color: var(--text-dim); font-size: 11px; margin-top: 4px; }

/* ===== Баннеры честности данных ===== */
.banner {
  border-radius: 8px; padding: 10px 14px; margin: 0 0 12px;
  font-size: 13px; font-weight: 500;
}
.banner-warn { background: rgba(255, 152, 0, 0.12); border: 1px solid var(--warn); color: var(--warn); }
.banner-bad { background: rgba(239, 83, 80, 0.12); border: 1px solid var(--bad); color: var(--bad); }

/* ===== Дельта цены за 24ч + спарклайн 7д ===== */
.delta { font-variant-numeric: tabular-nums; font-size: 12px; }
.delta-up { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }
.delta-flat, .delta-na { color: var(--text-dim); }
.spark { vertical-align: middle; margin-left: 4px; }

/* ===== Мобильный режим ===== */
@media (max-width: 768px) {
  body { padding: 10px; }
  header { flex-direction: column; gap: 10px; }
  .container { max-width: 100%; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .tabs .tab { white-space: nowrap; flex: 0 0 auto; }
  .controls, .controls--3, .controls--4, .controls--5 { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  /* Все таблицы прокручиваются по горизонтали... */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 640px; }
  /* ...кроме главной — она становится карточками */
  #items-table { min-width: 0 !important; display: block; width: 100%; }
  #items-table tbody { display: block; width: 100%; }
  #items-table thead { display: none; }
  #items-table tbody tr { display: block; padding: 10px 4px; border-bottom: 2px solid var(--border); }
  #items-table td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-bottom: none; padding: 3px 4px; }
  #items-table td.rank { display: none; }
  #items-table td.name-cell { justify-content: flex-start; font-size: 14px; }
  #items-table td:not(.name-cell)::before {
    content: attr(data-label);
    color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px;
  }
}

/* ===== Глобальный поиск ===== */
.gsearch { position: relative; flex: 1; max-width: 440px; margin: 0 16px; }
.gsearch input {
  width: 100%; background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: 8px; font-size: 13px;
}
.gsearch input:focus { outline: none; border-color: var(--accent); }
#g-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  max-height: 60vh; overflow-y: auto; box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.gs-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px;
}
.gs-row:last-child { border-bottom: none; }
.gs-row:hover { background: var(--bg-elev); }
.gs-dim { color: var(--text-dim); cursor: default; }
.gs-icon { width: 28px; height: 28px; border-radius: 4px; background: var(--bg-elev); flex: 0 0 28px; }
.gs-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gs-short { color: var(--text-dim); font-size: 11px; margin-left: 6px; }
.gs-meta { display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--accent); white-space: nowrap; }
.gs-badge {
  font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 3px;
  border: 1px solid; letter-spacing: 0.3px;
}
.gs-top { color: var(--accent); border-color: var(--accent); }
.gs-quest { color: var(--quest); border-color: var(--quest); }
.gs-hideout { color: var(--hideout); border-color: var(--hideout); }
.gs-kappa { color: var(--good); border-color: var(--good); }

/* ===== Карточка предмета ===== */
#g-modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
#g-modal {
  position: relative; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; max-width: 480px; width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.g-modal-close {
  position: absolute; top: 10px; right: 10px; background: none; border: none;
  color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 6px;
}
.g-modal-close:hover { color: var(--text); }
.g-modal-head { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.g-modal-icon { width: 56px; height: 56px; border-radius: 8px; background: var(--bg-elev); }
.g-modal-name { font-size: 17px; font-weight: 600; color: var(--accent); }
.g-modal-sub { color: var(--text-dim); font-size: 12px; margin-top: 3px; }
.g-modal-row { margin: 8px 0; font-size: 13px; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.g-modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ===== Патроны по калибрам ===== */
.ammo-group { margin-bottom: 18px; }
.ammo-group-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 8px 2px; }
.ammo-group-head h3 { color: var(--accent); font-size: 16px; }
.ammo-group-sub { color: var(--text-dim); font-size: 12px; }
.pen-badge {
  display: inline-flex; align-items: baseline; gap: 4px;
  border: 1px solid; border-radius: 4px; padding: 2px 7px;
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.pen-badge small { font-weight: 500; font-size: 9px; opacity: 0.85; }

@media (max-width: 768px) {
  .gsearch { max-width: none; margin: 0; order: 3; flex-basis: 100%; }
  header { flex-wrap: wrap; }
}

/* === Fix: alignment колонок между ammo-группами (table-layout: fixed + text-align) === */
#tab-ammo-panel table { table-layout: fixed; width: 100%; }
#tab-ammo-panel table th:nth-child(1),
#tab-ammo-panel table td:nth-child(1) { width: 36%; word-break: break-word; text-align: left; }
#tab-ammo-panel table th:nth-child(2),
#tab-ammo-panel table td:nth-child(2) { width: 13%; text-align: center; }
#tab-ammo-panel table th:nth-child(3),
#tab-ammo-panel table td:nth-child(3) { width: 9%;  text-align: right; }
#tab-ammo-panel table th:nth-child(4),
#tab-ammo-panel table td:nth-child(4) { width: 11%; text-align: right; }
#tab-ammo-panel table th:nth-child(5),
#tab-ammo-panel table td:nth-child(5) { width: 9%;  text-align: right; }
#tab-ammo-panel table th:nth-child(6),
#tab-ammo-panel table td:nth-child(6) { width: 11%; text-align: right; }
#tab-ammo-panel table th:nth-child(7),
#tab-ammo-panel table td:nth-child(7) { width: 11%; text-align: right; white-space: nowrap; }
/* небольшие отступы справа чтобы значение не липло к границе */
#tab-ammo-panel table th:nth-child(n+3),
#tab-ammo-panel table td:nth-child(n+3) { padding-right: 18px; }
