:root {
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #38bdf8;
  --accent-dim: #93c5fd;
  --gold: #e8b830;
  --panel: rgba(10, 10, 12, 0.78);
  --border: rgba(232, 184, 48, 0.18);
  --input-bg: rgba(0, 0, 0, 0.35);
  --ok: #6ee7a0;
  --warn: #fbbf24;
  --bad: #f87171;
  --mono: "Share Tech Mono", "Consolas", monospace;
}

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

body {
  min-height: 100vh;
  font-family: "Exo 2", "Segoe UI", sans-serif;
  color: var(--text);
}

.wrap {
  max-width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.top {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  margin-bottom: 24px;
}

.top h1 {
  font-family: "Orbitron", "Exo 2", sans-serif;
  font-size: clamp(0.95rem, 3vw, 1.3rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.35;
}

.lang { display: flex; gap: 8px; margin-top: 0; }

.lang button {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 6px 12px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.lang button.is-active {
  color: var(--accent-dim);
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.1);
}

.page-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 14px;
}

.page-tabs button {
  font-family: "Orbitron", "Exo 2", sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 10px 18px;
  border: none;
  border-bottom: 2px solid rgba(232, 184, 48, 0.18);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 0;
}

.page-tabs button.is-active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 16px 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.field { margin-bottom: 10px; }

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.field input[type="number"] {
  width: 100%;
  font-family: inherit;
  font-size: 0.88rem;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--input-bg);
  color: var(--text);
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 0;
}

.radio-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  line-height: 1.2;
  cursor: pointer;
}

.results-toolbar {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(232, 184, 48, 0.12);
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
}

.price-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  width: fit-content;
  max-width: 100%;
}

.price-toolbar.hidden {
  display: none;
}

.price-updated {
  margin: 0 0 0 auto;
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
  align-self: center;
}

.price-updated:empty {
  display: none;
}

.price-toolbar .toolbar-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.price-toolbar .toolbar-group + .toolbar-group {
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.toolbar-group {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.yield-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.yield-fields .field {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-bottom: 0;
}

.yield-fields .field label {
  display: block;
  order: 2;
  margin-bottom: 0;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-align: left;
  line-height: 1.2;
  white-space: nowrap;
}

.yield-fields .field input[type="number"] {
  width: 5rem;
  min-width: 0;
  height: 28px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--input-bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.2;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
  box-sizing: border-box;
}

.yield-fields .field input.reprocess-pct-input {
  width: 3.4rem;
  padding: 2px 4px;
}

.yield-fields .field input[type="number"]::-webkit-outer-spin-button,
.yield-fields .field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.yield-fields .field input[type="number"]:focus {
  outline: 2px solid rgba(56, 189, 248, 0.45);
  border-color: rgba(56, 189, 248, 0.35);
}

@media (max-width: 640px) {
  .price-toolbar {
    width: 100%;
    gap: 12px;
  }

  .price-toolbar .toolbar-group + .toolbar-group {
    padding-left: 0;
    border-left: none;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    width: 100%;
  }
}

.toolbar-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  line-height: 1.2;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

table {
  width: 100%;
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  font-family: "Orbitron", "Exo 2", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  background:
    linear-gradient(rgba(232, 184, 48, 0.08), rgba(232, 184, 48, 0.08)),
    #0a0a0c;
  padding: 10px 10px;
  text-align: right;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  vertical-align: bottom;
}

thead th[data-key^="chg"] {
  text-transform: none;
}

thead th.col-name,
thead th.col-region {
  text-align: left;
}

thead th.col-name,
tbody td.col-name {
  position: sticky;
  left: 0;
  z-index: 2;
  border-right: 1px solid rgba(232, 184, 48, 0.12);
}

thead th.col-name {
  z-index: 3;
}

tbody td.col-name {
  background: #0a0a0c;
}

tbody tr:nth-child(even) td.col-name {
  background:
    linear-gradient(rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.02)),
    #0a0a0c;
}

thead th.sorted-asc::after { content: " \25B2"; font-size: 0.6rem; }
thead th.sorted-desc::after { content: " \25BC"; font-size: 0.6rem; }

tbody td {
  padding: 8px 10px;
  text-align: right;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: middle;
}

tbody td.col-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tbody td.col-name,
tbody td.col-region {
  text-align: left;
}

tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }

.col-name { width: 16%; }
.col-region { width: 11%; }
.col-units { width: 11%; }
.col-isk { width: 18%; white-space: nowrap; }
.col-refine { width: 18%; white-space: nowrap; }

.isk-pair {
  display: inline-flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.4em;
  width: 100%;
  box-sizing: border-box;
}

.isk-pair .trend {
  display: inline-block;
  box-sizing: border-box;
  flex: 0 0 3.25rem;
  width: 3.25rem;
  min-width: 3.25rem;
  max-width: 3.25rem;
  text-align: right;
  font-size: 0.7em;
  white-space: nowrap;
}

.isk-pair .isk-amt {
  flex: 0 0 auto;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.isk-pair--solo {
  justify-content: flex-end;
}
.col-chg { width: 6.5%; }

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.trend {
  display: inline-block;
  min-width: 5.2ch;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  white-space: nowrap;
  text-align: right;
}

.trend-up { color: var(--ok); }
.trend-down { color: var(--bad); }
.trend-flat { color: var(--muted); }

thead th.trend-col {
  font-size: 0.65rem;
}

.error-banner {
  padding: 14px 16px;
  border-radius: 6px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.08);
  color: var(--bad);
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.empty-msg {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.region-toolbar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.region-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.region-chips button {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 5px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  cursor: pointer;
}

/* Inactive chips stay muted gray; color appears only when selected. */
.region-chips button.is-active[data-region="HS"] {
  border-color: rgba(82, 210, 115, 0.7);
  background: rgba(82, 210, 115, 0.22);
  color: #74e394;
}

.region-chips button.is-active[data-region="LS"] {
  border-color: rgba(245, 158, 11, 0.75);
  background: rgba(245, 158, 11, 0.22);
  color: #fbbf24;
}

.region-chips button.is-active[data-region="NS"] {
  border-color: rgba(239, 68, 68, 0.75);
  background: rgba(239, 68, 68, 0.22);
  color: #fb7185;
}

.region-chips button.is-active[data-region="WH"] {
  border-color: rgba(167, 139, 250, 0.75);
  background: rgba(167, 139, 250, 0.22);
  color: #c4b5fd;
}

.region-chips button.is-active[data-region="TS"] {
  border-color: rgba(249, 115, 22, 0.75);
  background: rgba(249, 115, 22, 0.22);
  color: #fb923c;
}

.region-chips button.is-active[data-region="A0"] {
  border-color: rgba(56, 189, 248, 0.75);
  background: rgba(56, 189, 248, 0.22);
  color: #7dd3fc;
}

.region-chips button.is-active[data-region="R4"] {
  border-color: rgba(148, 163, 184, 0.75);
  background: rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
}

.region-chips button.is-active[data-region="R8"] {
  border-color: rgba(96, 165, 250, 0.75);
  background: rgba(96, 165, 250, 0.22);
  color: #93c5fd;
}

.region-chips button.is-active[data-region="R16"] {
  border-color: rgba(52, 211, 153, 0.75);
  background: rgba(52, 211, 153, 0.22);
  color: #6ee7b7;
}

.region-chips button.is-active[data-region="R32"] {
  border-color: rgba(251, 191, 36, 0.8);
  background: rgba(251, 191, 36, 0.22);
  color: #fcd34d;
}

.region-chips button.is-active[data-region="R64"] {
  border-color: rgba(244, 114, 182, 0.8);
  background: rgba(244, 114, 182, 0.22);
  color: #f9a8d4;
}

.region-cell {
  white-space: nowrap;
}

.region-cell .region-badge {
  margin-right: 4px;
}

.region-cell .region-badge:last-child {
  margin-right: 0;
}

.price-toolbar + .price-toolbar {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.region-badge {
  display: inline-block;
  min-width: 2.2em;
  text-align: center;
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(232, 184, 48, 0.15);
  color: var(--gold);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.region-badge--hs { background: rgba(82, 210, 115, 0.12); color: #74e394; }
.region-badge--ls { background: rgba(245, 158, 11, 0.12); color: #fbbf24; }
.region-badge--ns { background: rgba(239, 68, 68, 0.12); color: #fb7185; }
.region-badge--wh { background: rgba(167, 139, 250, 0.12); color: #c4b5fd; }
.region-badge--ts { background: rgba(249, 115, 22, 0.12); color: #fb923c; }
.region-badge--a0 { background: rgba(56, 189, 248, 0.12); color: #7dd3fc; }
.region-badge--r4 { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; }
.region-badge--r8 { background: rgba(96, 165, 250, 0.14); color: #93c5fd; }
.region-badge--r16 { background: rgba(52, 211, 153, 0.14); color: #6ee7b7; }
.region-badge--r32 { background: rgba(251, 191, 36, 0.16); color: #fcd34d; }
.region-badge--r64 { background: rgba(244, 114, 182, 0.16); color: #f9a8d4; }

.price-mode-btn,
.reprocess-btn {
  --price-accent: var(--bad);
  --price-accent-bg: rgba(248, 113, 113, 0.12);
  --price-accent-border: rgba(248, 113, 113, 0.45);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 2rem;
  padding: 0 10px 0 8px;
  border: 1px solid var(--price-accent-border);
  border-radius: 4px;
  background: var(--price-accent-bg);
  color: var(--price-accent);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.price-mode-btn[data-mode="sell"],
.reprocess-btn[aria-pressed="true"] {
  --price-accent: var(--ok);
  --price-accent-bg: rgba(110, 231, 160, 0.12);
  --price-accent-border: rgba(110, 231, 160, 0.4);
}

.price-mode-svg {
  width: 1.05rem;
  height: 1.05rem;
  flex-shrink: 0;
  display: none;
}

.price-mode-btn[data-mode="buy"] .price-mode-svg--buy,
.price-mode-btn[data-mode="sell"] .price-mode-svg--sell {
  display: block;
}

.price-mode-btn:hover,
.reprocess-btn:hover {
  filter: brightness(1.12);
}

.price-mode-btn:focus-visible,
.reprocess-btn:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.55);
  outline-offset: 2px;
}

.reprocess-btn {
  padding: 0 12px;
}

.hidden { display: none !important; }
