:root {
  --bg: #101215;
  --surface: #171a1f;
  --surface-2: #1d2127;
  --line: #262b33;
  --ink: #e8eaed;
  --ink-2: #a4abb6;
  --ink-3: #6f7783;
  --accent: #3aa757;
  --danger: #ef4444;
  --focus: #4b8ef5;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* у .filters, #login-screen и прочих display задан явно - без этого он бьёт атрибут hidden */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: #39414d; background: #232830; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #06210f; font-weight: 600; }
button.primary:hover { background: #43bd63; border-color: #43bd63; }
button.ghost { background: transparent; }
button.danger { color: #ffb4b4; }
button.danger:hover { border-color: #5a2b2b; background: #2a1a1a; }
button.sm { padding: 4px 9px; font-size: 12.5px; }

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  width: 100%;
}
input::placeholder { color: var(--ink-3); }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pos { color: #6fd48c; }
.neg { color: #ff8a8a; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }

/* ---------- вход ---------- */
#login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px;
}
.login-card h1 { margin: 0 0 4px; font-size: 19px; }
.login-card p { margin: 0 0 20px; color: var(--ink-2); font-size: 13px; }
.login-card label { display: block; margin-bottom: 12px; }
.login-card label span { display: block; margin-bottom: 5px; color: var(--ink-2); font-size: 12.5px; }
.error { color: #ff8a8a; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- каркас ---------- */
header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 20px;
  background: rgba(16, 18, 21, 0.94);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -0.01em; margin-right: 4px; }
.brand span { color: var(--ink-3); font-weight: 400; font-size: 12.5px; }
.logo { object-fit: contain; }
.logo-lg { display: block; margin: 0 auto 12px; object-fit: contain; }
.top .spacer { flex: 1; }

.tabs { display: flex; gap: 2px; padding: 12px 20px 0; flex-wrap: wrap; }
.tabs button {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 14px;
  color: var(--ink-2);
}
.tabs button:hover { background: transparent; color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* контент во всю ширину окна: таблица позиций широкая, ограничение только мешало */
main { padding: 16px 20px 60px; }
section[hidden] { display: none; }

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.filters .field { display: flex; align-items: center; gap: 6px; }
.filters .field > span { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.filters select, .filters input { width: auto; min-width: 110px; }
.chips { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.chips button { border: none; background: transparent; padding: 4px 10px; font-size: 12.5px; color: var(--ink-2); border-radius: 6px; }
.chips button[aria-pressed="true"] { background: #2b313a; color: var(--ink); }

/* ---------- счётчики ---------- */
/* сетка на фоне-линии: зазор в 1px сам рисует разделители при любом переносе строк */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}
.stat { background: var(--surface); padding: 11px 14px 12px; }
.stat .label { color: var(--ink-3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat .value {
  font-size: 19px;
  font-weight: 600;
  margin-top: 3px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.stat .sub { color: var(--ink-3); font-size: 11.5px; margin-top: 2px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card .label { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.card .value { font-size: 22px; font-weight: 600; margin-top: 6px; font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.card .sub { color: var(--ink-2); font-size: 12.5px; margin-top: 4px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 2px; font-size: 15px; font-weight: 600; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-head .hint { margin-bottom: 14px; }
.panel > .hint { margin: 0 0 14px; color: var(--ink-3); font-size: 12.5px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }

/* ---------- горизонтальные бары (вкладка "Статистика") ---------- */
.bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 190px) 1fr auto; align-items: center; gap: 10px; }
.bar-row .name { display: flex; align-items: center; gap: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .name img { width: 20px; height: 20px; object-fit: contain; flex: none; }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.bar-fill.neg { background: var(--danger); }
.bar-row .val { font-family: var(--mono); font-size: 12.5px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
/* липкие заголовки работают только относительно скроллящегося предка,
   поэтому длинная таблица прокручивается внутри себя, а не всей страницей */
.table-wrap.scroll { overflow: auto; max-height: calc(100vh - 300px); min-height: 260px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
td.r, th.r { text-align: right; }
tbody tr:hover { background: #1b1f25; }
tbody tr.mine td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }

.item-cell { display: flex; align-items: center; gap: 8px; }
.item-cell img { width: 26px; height: 26px; object-fit: contain; flex: none; image-rendering: -webkit-optimize-contrast; }
.quality-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.q-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.sharp { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; }
tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
/* в таблице "в наличии" действия нужны сразу, без наведения */
.row-actions.always { opacity: 1; }

.hide-user .col-user { display: none; }

/* поле ввода цены прямо в строке таблицы */
.inline-price { width: 100%; text-align: right; }

/* Колонки таблицы позиций фиксированной ширины: иначе появление поля ввода
   пересчитывает раскладку и вся таблица дёргается. Ширины берутся из шапки,
   поэтому скрытие th (колонка "Игрок") по-прежнему убирает колонку целиком. */
#positions-table { table-layout: fixed; min-width: 1240px; }
#positions-table th:nth-child(1) { width: 190px; }
#positions-table th:nth-child(2) { width: 134px; }
#positions-table th:nth-child(3) { width: 68px; }
/* первые три колонки держим плотно: между ними нет длинных значений */
#positions-table th:nth-child(-n+3), #positions-table td:nth-child(-n+3) { padding-left: 8px; padding-right: 6px; }
#positions-table th:nth-child(4) { width: 124px; }
#positions-table th:nth-child(5) { width: 130px; }
#positions-table th:nth-child(6) { width: 124px; }
#positions-table th:nth-child(7) { width: 140px; }
#positions-table th:nth-child(8) { width: 90px; }
#positions-table th:nth-child(9) { width: 130px; }
#positions-table th.col-user { width: 130px; }
#positions-table th:last-child { width: 90px; }
#positions-table td { overflow: hidden; text-overflow: ellipsis; }

/* окно выбора артефакта */
#item-dialog { width: min(920px, calc(100vw - 24px)); }
#item-dialog .body { max-height: min(70vh, 620px); }
#item-search { margin-bottom: 14px; position: sticky; top: 0; z-index: 2; }
#item-grid { display: grid; gap: 14px; }
.item-group > h3 {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
}
.item-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; }
.item-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  text-align: center;
  line-height: 1.25;
  font-size: 12.5px;
}
.item-tile:hover { background: var(--surface-2); border-color: var(--line); }
.item-tile[aria-current="true"] { border-color: var(--accent); background: #1b2a20; }
.item-tile img { width: 44px; height: 44px; object-fit: contain; }
.item-tile span { display: block; overflow-wrap: anywhere; }

/* меню выбора заточки: 0-5 / 6-10 / 11-15 по столбцам */
.sharp-pop {
  position: fixed;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(3, 52px);
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.sharp-cell {
  padding: 5px 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface-2);
  border-radius: 6px;
}
.sharp-cell.wide { width: auto; }
.sharp-cell.step { color: var(--ink); font-weight: 700; }
.sharp-cell[aria-current="true"] { border-color: var(--accent); color: var(--ink); background: #1b2a20; }
.draft-sharp { width: 100%; text-align: right; padding: 2px 4px; }

/* меню выбора заточки: столбцы 0-5 / 6-10 / 11-15, строки выровнены */
.sharp-pop {
  position: fixed;
  z-index: 60;
  display: grid;
  grid-template-columns: repeat(3, 54px);
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.sharp-cell {
  padding: 5px 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 6px;
}
.sharp-cell:hover { background: #2b313a; color: var(--ink); }
.sharp-cell.step { color: var(--ink); font-weight: 700; }
.sharp-cell[aria-current="true"] { border-color: var(--accent); color: var(--ink); background: #1b2a20; }
.draft-sharp { width: 100%; text-align: right; padding: 2px 4px; }

/* черновая строка новой позиции */
tr.draft td { background: #1c2128; border-bottom: 1px solid var(--accent); }
tr.draft input[type="date"] { font-size: 13px; }
.draft-item { width: 100%; display: flex; align-items: center; gap: 8px; justify-content: flex-start; padding: 2px 4px; }
.draft-item img { width: 22px; height: 22px; object-fit: contain; }

/* ячейки, которые правятся на месте */
.editable { cursor: text; }
.editable .cell-view {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px dashed transparent;
}
tr:hover .editable .cell-view { border-bottom-color: #3c434e; }
.editable .cell-view img { width: 26px; height: 26px; object-fit: contain; flex: none; }
/* Поля внутри таблицы без рамки и внутренних отступов: текст встаёт ровно туда
   же, где стоял в режиме просмотра, и совпадает с заголовком столбца. */
#positions-table input,
#positions-table select {
  width: 100%;
  min-width: 0;
  padding: 2px 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
#positions-table input:focus, #positions-table select:focus { border-bottom-color: var(--accent); }
#positions-table td.r input { text-align: right; }
#positions-table select { padding-left: 0; margin-left: -2px; }
/* редкость с заливкой: небольшой отступ, чтобы цвет не лип к тексту вплотную */
#positions-table select[style*="background"] { padding: 2px 6px; border-radius: 5px; margin-left: -6px; }

/* ---------- модалка ---------- */
dialog {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  width: min(560px, calc(100vw - 24px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0; padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 16px; }
dialog .body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
dialog .foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label.field-l { display: block; }
label.field-l > span { display: block; margin-bottom: 5px; color: var(--ink-2); font-size: 12.5px; }

.picker { position: relative; }
.picker-list {
  position: absolute;
  z-index: 5;
  left: 0; right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 4px;
}
.picker-list button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  border-radius: 0;
  background: transparent;
  text-align: left;
  padding: 6px 10px;
}
.picker-list button:hover, .picker-list button.active { background: #2b313a; }
.picker-list img { width: 24px; height: 24px; object-fit: contain; }
.picker-list .cat { margin-left: auto; color: var(--ink-3); font-size: 12px; }

.q-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.q-picker button { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 5px 10px; }
.q-picker button[aria-pressed="true"] { border-color: var(--ink-3); background: #2b313a; }

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 16px;
  z-index: 60;
}
.toast.err { border-color: #5a2b2b; color: #ffb4b4; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 12px 12px 60px; }
  header.top, .filters { padding-left: 12px; padding-right: 12px; }
  .tabs { padding-left: 12px; }
}
