* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  background: #2d3a4b;
  color: #e8ecef;
  min-height: 100vh;
}

.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px;
}

header {
  background: linear-gradient(180deg, #1d2938 0%, #283648 100%);
  border: 1px solid #445268;
  border-radius: 4px;
  padding: 12px 18px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: #ffd866;
  letter-spacing: 0.3px;
}
header h1 span { color: #e8ecef; font-weight: 400; font-size: 14px; }

.header-meta {
  font-size: 11px;
  color: #8ba0b8;
  line-height: 1.6;
}
.header-meta a { color: #ffd866; text-decoration: none; }
.header-meta a:hover { text-decoration: underline; }

/* Control panels */
.controls {
  background: #34435a;
  border: 1px solid #445268;
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-group label {
  font-size: 11px;
  color: #b8c4d4;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  white-space: nowrap;
}

.ctrl-group input[type="number"],
.ctrl-group select {
  background: #1d2938;
  color: #e8ecef;
  border: 1px solid #556679;
  border-radius: 3px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: inherit;
  width: 72px;
}
.ctrl-group select { width: auto; min-width: 120px; }
.ctrl-group input[type="number"]:focus,
.ctrl-group select:focus { outline: none; border-color: #ffd866; }

/* Era/Type button bars */
.btn-bar {
  display: flex;
  background: #1d2938;
  border: 1px solid #556679;
  border-radius: 3px;
  overflow: hidden;
}

.btn-bar button {
  background: transparent;
  border: none;
  color: #b8c4d4;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-right: 1px solid #556679;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.btn-bar button:last-child { border-right: none; }
.btn-bar button:hover { background: #40516b; color: #e8ecef; }
.btn-bar button.active {
  background: #ffd866;
  color: #1d2938;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #1d2938;
  border: 1px solid #556679;
  border-radius: 12px;
  cursor: pointer;
  font-size: 11px;
  color: #b8c4d4;
  user-select: none;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.toggle-pill input { cursor: pointer; accent-color: #ffd866; }
.toggle-pill:has(input:checked) { border-color: #ffd866; color: #ffd866; }

/* Weight sliders — compact */
.weights {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: #2a3749;
  border: 1px solid #445268;
  border-radius: 4px;
  margin-bottom: 10px;
}
.weight-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #b8c4d4;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.weight-ctrl input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: #1d2938;
  border: 1px solid #556679;
  border-radius: 3px;
  outline: none;
}
.weight-ctrl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ffd866;
  border: 1px solid #1d2938;
  cursor: pointer;
}
.weight-ctrl input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: #ffd866; border: 1px solid #1d2938; cursor: pointer;
}
.weight-ctrl .val {
  display: inline-block;
  width: 38px;
  text-align: right;
  color: #ffd866;
  font-variant-numeric: tabular-nums;
}

/* Table */
.table-wrap {
  background: #1d2938;
  border: 1px solid #445268;
  border-radius: 4px;
  overflow: auto;
  max-height: calc(100vh - 260px);
  position: relative;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #283648;
}

thead tr {
  background: linear-gradient(180deg, #34435a 0%, #283648 100%);
}

th {
  padding: 8px 10px;
  text-align: right;
  font-weight: 600;
  color: #ffd866;
  border-bottom: 2px solid #ffd866;
  border-right: 1px solid #445268;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
th:first-child { text-align: center; padding-left: 8px; }
th[data-sort="name"] { text-align: left; }
th:hover { background: #405169; }
th .sort-ind {
  display: inline-block;
  margin-left: 3px;
  color: #ffa500;
  font-size: 10px;
}

tbody tr {
  border-bottom: 1px solid #34435a;
  transition: background 0.1s;
}
tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
tbody tr:hover { background: rgba(255, 216, 102, 0.08); }

td {
  padding: 6px 10px;
  text-align: right;
  border-right: 1px solid #34435a;
  color: #e8ecef;
}
td:first-child { text-align: center; color: #8ba0b8; font-weight: 600; }
td.name {
  text-align: left;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  min-width: 130px;
}

.badge {
  display: inline-block;
  font-size: 9px;
  padding: 1px 4px;
  margin-left: 4px;
  border-radius: 2px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
.badge-bonus { background: #ff6b6b; color: #fff; }
.badge-slot { background: #3d5066; color: #ffd866; border: 1px solid #ffd866; }

/* Cell color coding — green for good, red for bad */
td.metric {
  position: relative;
  font-weight: 600;
}

.rank-1 td.metric-target { background: rgba(76, 175, 80, 0.35); color: #fff; }
.rank-2 td.metric-target { background: rgba(76, 175, 80, 0.25); }
.rank-3 td.metric-target { background: rgba(76, 175, 80, 0.15); }
.rank-last td.metric-target { background: rgba(244, 67, 54, 0.25); }
.rank-last-2 td.metric-target { background: rgba(244, 67, 54, 0.15); }

tr.rank-1 { border-left: 3px solid #4caf50; }
tr.rank-last { opacity: 0.75; }
tr.bonus td.name { color: #ffb366; }

.bar-cell {
  position: relative;
  overflow: hidden;
}
.bar-cell .fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(255, 216, 102, 0.1), rgba(255, 216, 102, 0.3));
  z-index: 0;
  transition: width 0.4s ease;
}
.bar-cell .value {
  position: relative;
  z-index: 1;
}

/* Key metric column highlight */
th.key, td.key {
  background: rgba(255, 216, 102, 0.08);
  border-left: 2px solid #ffd866;
  font-weight: 700;
  color: #ffd866;
}
tbody tr:hover td.key { background: rgba(255, 216, 102, 0.2); }

.cat-sprinter { color: #66b3ff; }
.cat-longhaul { color: #ff9966; }
.cat-shorthaul { color: #66d9a3; }
.cat-hauler { color: #b88fff; }
.cat-marathon { color: #ffcc66; }
.cat-allround { color: #cccccc; }

/* Tooltip */
[title] { cursor: help; }

/* Footer info */
.info-strip {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  font-size: 11px;
  color: #b8c4d4;
}
.info-cell {
  background: #283648;
  border: 1px solid #445268;
  border-left: 3px solid #ffd866;
  border-radius: 3px;
  padding: 8px 12px;
  line-height: 1.5;
}
.info-cell b { color: #ffd866; }

footer {
  text-align: center;
  padding: 16px 0 8px;
  color: #6b7a8f;
  font-size: 11px;
}
footer a { color: #8ba0b8; }

/* Pill buttons для уровней апгрейда в таблице */
.lvl-cell {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-wrap: nowrap;
}
.lvl-pill {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  color: #556679;
  background: transparent;
  border: 1px solid #445268;
  cursor: pointer;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: all 0.1s;
  user-select: none;
}
.lvl-pill:hover {
  color: #ffd866;
  border-color: #ffd866;
}
.lvl-pill.active {
  color: #1d2938;
  background: #ffd866;
  border-color: #ffd866;
  font-weight: 700;
}

/* Bonus sections */
.bonus-panel {
  background: linear-gradient(180deg, #34435a 0%, #2a3749 100%);
  border: 1px solid #445268;
  border-left: 3px solid #66b3ff;
  border-radius: 4px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.bonus-panel.worker { border-left-color: #ff9966; }
.bonus-panel.coupon { border-left-color: #4ec9a6; }
.bonus-panel.power { border-left-color: #ba7dff; }

.bonus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 10px;
}
.bonus-header h3 {
  font-size: 12px;
  font-weight: 700;
  color: #ffd866;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.bonus-header h3 .icon {
  font-size: 14px;
  opacity: 0.8;
}
.bonus-panel.worker h3 { color: #ff9966; }
.bonus-panel.coupon h3 { color: #4ec9a6; }
.bonus-panel.power h3 { color: #ba7dff; }

.bonus-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip-btn {
  background: #1d2938;
  border: 1px solid #445268;
  color: #b8c4d4;
  padding: 5px 10px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  user-select: none;
  white-space: nowrap;
}
.chip-btn:hover { background: #2d3d54; border-color: #66a0cc; }
.chip-btn.active {
  background: #ff9966;
  border-color: #ff9966;
  color: #1d2938;
}
.bonus-panel.power .chip-btn.active {
  background: #ba7dff;
  border-color: #ba7dff;
  color: #1d2938;
}
.bonus-panel.coupon .chip-btn.active {
  background: #4ec9a6;
  border-color: #4ec9a6;
  color: #1d2938;
}
.chip-btn small {
  font-weight: 400;
  font-size: 10px;
  opacity: 0.8;
}

.active-bonus-strip {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255,255,255,0.1);
  font-size: 11px;
  color: #8ba0b8;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.active-bonus-strip .tag {
  background: rgba(255, 216, 102, 0.15);
  padding: 2px 8px;
  border-radius: 3px;
  color: #ffd866;
  font-weight: 600;
}
.active-bonus-strip .tag.none {
  background: transparent;
  color: #556679;
  font-style: italic;
  font-weight: 400;
}

.number-input-small {
  background: #1d2938;
  color: #e8ecef;
  border: 1px solid #556679;
  border-radius: 3px;
  padding: 3px 6px;
  font-size: 11px;
  font-family: inherit;
  width: 54px;
}

.bonus-flag-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid #445268;
  font-size: 10px;
  color: #8ba0b8;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
}

.era-type-indicator {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 2px;
  margin-left: 6px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.era-type-steam { background: #6b4423; color: #ffd866; }
.era-type-diesel { background: #2d4d6b; color: #8bd3ff; }
.era-type-electric { background: #4a2d6b; color: #d4a3ff; }

/* Responsive */
@media (max-width: 900px) {
  .controls, .weights { font-size: 11px; }
  .weight-ctrl input[type="range"] { width: 80px; }
  th, td { padding: 5px 6px; font-size: 11px; }
}