/* NSN TRADE-UP CALCULATOR — main styles (dark + light) */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&family=Oswald:wght@500;600;700&display=swap');

/* ========== TOKENS ========== */
:root {
  --blue-900:#001F4D; --blue-800:#002E75; --blue-700:#0045B0;
  --blue-600:#005EE6; --blue-500:#0077FF; --blue-400:#3A94FF;
  --blue-300:#7AB6FF; --blue-200:#B3D2FF; --blue-100:#E0EDFF;
  --cyan-600:#00B8FF; --cyan-500:#1FD1FF; --cyan-400:#5FE0FF;
  --hazard-500:#FF6B1F; --hazard-600:#D64A00;
  --green-500:#19B36B; --amber-500:#F4B400; --red-500:#E03131;

  --font-display:'Oswald','Bebas Neue','Arial Narrow',sans-serif;
  --font-sans:'Space Grotesk','Inter',system-ui,sans-serif;
  --font-mono:'JetBrains Mono',ui-monospace,Consolas,monospace;

  --radius-sm:2px; --radius-md:4px; --radius-lg:6px; --radius-xl:10px;
  --dur:160ms; --ease:cubic-bezier(.2,.8,.2,1);

  --density-pad: 12px; --density-gap: 10px;
}

/* dark (default) */
:root, [data-theme="dark"] {
  --bg:#05080F;
  --bg-2:#0A0F1A;
  --panel:#0F1623;
  --panel-2:#141D2E;
  --panel-3:#1A2438;
  --border:#1F2B42;
  --border-strong:#2D3D5E;
  --border-stencil:#3D5276;
  --fg1:#EEF1F6; --fg2:#B8C1D1; --fg3:#8B97AD; --fg4:#5D6B82;
  --accent:var(--blue-500); --accent-hover:var(--blue-400); --accent-press:var(--blue-600);
  --accent-glow:var(--cyan-500);
  --grid-line:rgba(122,182,255,.045);
}

[data-theme="light"] {
  --bg:#F7F9FC;
  --bg-2:#EEF1F6;
  --panel:#FFFFFF;
  --panel-2:#F7F9FC;
  --panel-3:#EEF1F6;
  --border:#DCE2EC;
  --border-strong:#B8C1D1;
  --border-stencil:#5D6B82;
  --fg1:#0A0F1A; --fg2:#2A3446; --fg3:#5D6B82; --fg4:#8B97AD;
  --accent:var(--blue-600); --accent-hover:var(--blue-500); --accent-press:var(--blue-700);
  --accent-glow:var(--cyan-600);
  --grid-line:rgba(0,69,176,.05);
}

/* density */
[data-density="dense"]    { --density-pad: 8px;  --density-gap: 6px; }
[data-density="comfy"]    { --density-pad: 12px; --density-gap: 10px; }
[data-density="spacious"] { --density-pad: 18px; --density-gap: 14px; }

/* palette */
[data-palette="hazard"] {
  --accent:var(--hazard-500); --accent-hover:var(--hazard-600); --accent-press:#B33D00;
  --accent-glow:#FF8C4C;
}
[data-palette="cyan"] {
  --accent:var(--cyan-600); --accent-hover:var(--cyan-500); --accent-press:#0096CC;
}

/* ========== RESET ========== */
*,*::before,*::after { box-sizing: border-box; }
html,body { margin:0; padding:0; }
/* Снижает сдвиг макета при появлении/исчезновении полосы прокрутки (дополняет padding при модалках в app.js). */
html {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border-stencil) var(--panel-2);
}

/* Полосы прокрутки в стиле токенов (Firefox + Chromium/WebKit). */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-stencil) var(--panel-2);
}

*::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

*::-webkit-scrollbar-track {
  background: var(--panel-2);
  border-radius: 5px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--border-strong), var(--border-stencil));
  border-radius: 5px;
  border: 2px solid var(--panel-2);
  min-height: 32px;
}

*::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--accent) 38%, var(--border-strong));
}

*::-webkit-scrollbar-thumb:active {
  background: color-mix(in srgb, var(--accent) 55%, var(--panel-3));
}

*::-webkit-scrollbar-corner {
  background: var(--panel-2);
}

*::-webkit-scrollbar-button {
  width: 0;
  height: 0;
  display: none;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg1);
  min-height: 100dvh;
  line-height: 1.45;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ========== LAYOUT ========== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100dvh;
}

/* Top bar ONLY on mobile (hamburger + lang) */
.topbar {
  position: sticky; top: 0; z-index: 80;
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar .t-brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: 14px;
  color: var(--fg1);
}
.topbar .t-brand img { height: 28px; }
.hamburger {
  width: 40px; height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--panel);
  color: var(--fg1);
  display: inline-flex; align-items: center; justify-content: center;
}
.hamburger svg { width: 18px; height: 18px; }
.topbar-spacer { flex: 1; }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; align-self: flex-start;
  height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 12px 12px;
  gap: 10px;
  overflow-y: auto;
  z-index: 70;
}

.brand {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 4px 6px 10px;
  border-bottom: 1px dashed var(--border-stencil);
  margin-bottom: 4px;
}
.brand img {
  height: 96px;
  filter: drop-shadow(0 0 18px rgba(31, 209, 255, .35));
}
.brand .brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--fg1);
  text-align: center;
  line-height: 1.1;
}
.brand .brand-sub {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg3);
  text-transform: uppercase;
  letter-spacing: .18em;
}

/* price source buttons */
.price-src {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 4px 0 8px;
}
.price-src-btn {
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 7px 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--fg3);
  transition: all var(--dur) var(--ease);
  min-width: 0;
}
.price-src-btn:hover { color: var(--fg1); border-color: var(--accent); }
.price-src-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 12px color-mix(in srgb, var(--accent-glow) 40%, transparent);
}

.nav {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: 6px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--fg2);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  border-left: 2px solid transparent;
  transition: all var(--dur) var(--ease);
}
.nav-btn:hover { background: var(--panel-2); color: var(--fg1); }
.nav-btn.active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--fg1);
  border-left-color: var(--accent);
}
.nav-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-btn .lbl {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.nav-btn .num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg4);
  margin-left: auto;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px dashed var(--border-stencil);
  display: flex; flex-direction: column; gap: 8px;
}

.status-row {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg3);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green-500);
  box-shadow: 0 0 8px var(--green-500);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }

.theme-toggle {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.theme-toggle button {
  flex: 1;
  padding: 6px 8px;
  border: none;
  background: var(--panel-2);
  color: var(--fg3);
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: .06em;
}
.theme-toggle button.active {
  background: var(--accent);
  color: #fff;
}

/* Main */
main {
  min-width: 0;
  padding: 24px clamp(16px, 2vw, 32px) 80px;
  position: relative;
}

.main-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.main-head .eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--fg3);
  margin-bottom: 4px;
}
.main-head h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 3vw, 32px);
  text-transform: uppercase;
  letter-spacing: .02em;
  line-height: 1.1;
  color: var(--fg1);
  margin: 0;
}

/* Главный заголовок режима: медленный «неон», в ритме с .status-dot (ease-in-out), чуть дольше цикл */
#head-title {
  animation: head-title-neon 2.5s ease-in-out infinite;
}

@keyframes head-title-neon {
  0%, 100% {
    text-shadow:
      0 0 4px rgba(255, 255, 255, 0.2),
      0 0 10px rgba(255, 255, 255, 0.12);
    opacity: 1;
  }
  50% {
    text-shadow:
      0 0 6px rgba(255, 255, 255, 0.55),
      0 0 18px rgba(255, 255, 255, 0.38),
      0 0 28px rgba(230, 240, 255, 0.22);
    opacity: 0.88;
  }
}

[data-theme="light"] #head-title {
  animation-name: head-title-neon-light;
}

/* Светлая тема: голубой + циан «неон», как на фирменном логотипе NSN (blue-600 + cyan) */
@keyframes head-title-neon-light {
  0%, 100% {
    text-shadow:
      0 0 4px rgba(0, 94, 230, 0.2),
      0 0 10px rgba(0, 184, 255, 0.16),
      0 0 18px rgba(31, 209, 255, 0.08);
    opacity: 1;
  }
  50% {
    text-shadow:
      0 0 5px rgba(0, 94, 230, 0.38),
      0 0 12px rgba(0, 184, 255, 0.45),
      0 0 22px rgba(31, 209, 255, 0.35),
      0 0 34px rgba(0, 94, 230, 0.18);
    opacity: 0.92;
  }
}

@media (prefers-reduced-motion: reduce) {
  #head-title {
    animation: none;
    text-shadow: none;
    opacity: 1;
  }
}

.main-head .lead {
  color: var(--fg3);
  font-size: 13.5px;
  margin: 4px 0 0;
}

.head-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Lang switcher */
.lang-sw {
  position: relative;
}
.lang-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  min-height: 38px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--fg1);
  font-size: 13px;
  font-weight: 500;
}
.lang-btn:hover { border-color: var(--accent); }
.lang-btn svg { width: 15px; height: 15px; }
.lang-btn .lang-code {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--fg2);
}
.lang-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  min-width: 160px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  z-index: 50;
  padding: 4px;
  display: none;
}
.lang-menu.open { display: block; }
.lang-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none; background: transparent;
  color: var(--fg1);
  font-size: 13px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.lang-menu button:hover { background: var(--panel-2); }
.lang-menu button.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.lang-menu .ck { margin-left: auto; color: var(--accent); }

.tweak-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  min-height: 38px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--fg1);
  font-size: 13px;
}
.tweak-btn:hover { border-color: var(--accent); }
.tweak-btn svg { width: 15px; height: 15px; }

/* Panels */
.panel { display: none; }
.panel.active { display: block; animation: fadein .24s var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(4px) } to { opacity: 1; transform: none } }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head h2 {
  font-family: var(--font-display);
  font-size: clamp(18px, 2.2vw, 22px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--fg1);
  margin: 0;
  display: flex; align-items: center; gap: 10px;
}
.panel-head h2::before {
  content: "";
  display: inline-block;
  width: 4px; height: 20px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
.panel-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}

/* Cards / blocks */
.block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--density-pad);
  margin-bottom: 14px;
  position: relative;
}
.block > .block-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border-stencil);
}
.block > .block-head h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--fg1);
  margin: 0;
}
.block .sub {
  color: var(--fg3);
  font-size: 12.5px;
  margin: 0 0 10px;
}
.block .meta-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg3);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  min-height: 40px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .02em;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:active:not(:disabled) { background: var(--accent-press); transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn svg { width: 15px; height: 15px; }

.btn.secondary {
  background: var(--panel-2);
  color: var(--fg1);
  border: 1px solid var(--border-strong);
}
.btn.secondary:hover:not(:disabled) { background: var(--panel-3); border-color: var(--accent); }
.btn.ghost {
  background: transparent;
  color: var(--fg2);
  border: 1px solid var(--border-strong);
}
.btn.ghost:hover:not(:disabled) { color: var(--fg1); border-color: var(--accent); }
.btn.hazard { background: var(--hazard-500); }
.btn.hazard:hover:not(:disabled) { background: var(--hazard-600); }

.btn.sm { padding: 6px 10px; min-height: 32px; font-size: 12px; }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--fg3);
  font-weight: 600;
  font-family: var(--font-mono);
}
.field > input,
.field > select,
.field > textarea,
.inp {
  width: 100%;
  padding: 9px 11px;
  min-height: 40px;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--fg1);
  font-size: 13px;
}
.inp.mono, .field .mono { font-family: var(--font-mono); }
.field > input:focus,
.field > select:focus,
.field > textarea:focus,
.inp:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}
textarea.inp { min-height: 140px; resize: vertical; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--density-gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--density-gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--density-gap); }
@media (max-width: 680px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

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

/* Check row */
.check-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px 22px;
  padding: 10px 0 0;
}
.check {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px;
  color: var(--fg2);
  cursor: pointer;
  user-select: none;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* segmented */
.seg {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--panel-2);
}
.seg button {
  padding: 7px 12px;
  min-height: 34px;
  border: none;
  background: transparent;
  color: var(--fg3);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 600;
}
.seg button.active {
  background: var(--accent);
  color: #fff;
}

/* Float wear presets */
.wear-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-top: 6px;
}
.wear-presets button {
  padding: 6px 4px;
  min-height: 30px;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--fg2);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
}
.wear-presets button:hover { border-color: var(--accent); color: var(--fg1); }

/* Item cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--density-gap);
  margin-top: 12px;
}
.item-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  position: relative;
}
.item-card.auto-filled {
  border-color: var(--amber-500);
  background: color-mix(in srgb, var(--amber-500) 10%, var(--panel-2));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--amber-500) 20%, transparent);
}
.item-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px;
}
.item-card-head .title {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--fg3);
}
.item-card-actions { display: flex; gap: 4px; }
.chip-btn {
  padding: 4px 8px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--fg2);
  border-radius: var(--radius-sm);
}
.chip-btn:hover { border-color: var(--accent); color: var(--fg1); }
.chip-btn.danger:hover { border-color: var(--red-500); color: var(--red-500); }

.item-steam-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--fg2);
  min-height: 28px;
}
.item-steam-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-s, .link-csf {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 22px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.link-s {
  background: var(--blue-600); color: #fff;
}
.link-csf {
  background: linear-gradient(145deg, #ffb347, #ff8c00);
  color: #1a1a1a;
}

/* Autocomplete */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute; top: calc(100% + 2px); left: 0; right: 0;
  z-index: 40;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  padding: 4px;
  margin: 0;
  list-style: none;
  display: none;
}
.ac-list.open { display: block; }
.ac-list li {
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 2px;
}
.ac-list li .ac-coll {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg3);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.ac-list li.active, .ac-list li:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Result summary */
.result-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--density-gap);
  margin-bottom: 16px;
}
@media (max-width: 760px) { .result-summary { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute; top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent);
}
.stat-card.profit::before { background: var(--green-500); }
.stat-card.loss::before { background: var(--red-500); }
.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--fg3);
  margin-bottom: 6px;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--fg1);
  line-height: 1;
}
.stat-sub {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg3);
}
.val-pos { color: var(--green-500); }
.val-neg { color: var(--red-500); }

/* Tables */
.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.tbl th {
  padding: 9px 12px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fg3);
  background: var(--panel-3);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  font-weight: 600;
}
table.tbl td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--fg2);
}
table.tbl td.num { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.name { color: var(--fg1); font-weight: 500; }
table.tbl tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
table.tbl tbody tr:last-child td { border-bottom: none; }

.bar {
  display: inline-block;
  height: 5px;
  background: var(--accent);
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 8px;
}

/* Option cards */
.opt-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--density-gap);
  margin-top: 10px;
}
.opt-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
  transition: border-color var(--dur) var(--ease);
  cursor: pointer;
}
.opt-card:hover { border-color: var(--accent); }
.opt-card .rank {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--fg3);
  padding: 3px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  align-self: flex-start;
}
.opt-card .t {
  font-weight: 600;
  font-size: 14px;
  color: var(--fg1);
}
.opt-card .c {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg3);
}
.opt-card .row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.opt-card .row .k { color: var(--fg3); font-family: var(--font-mono); font-size: 11px; }
.opt-card .row .v { font-family: var(--font-mono); font-weight: 600; color: var(--fg1); }
.opt-card .profit-line {
  display: flex; justify-content: space-between;
  padding: 6px 8px;
  margin-top: 4px;
  background: var(--panel);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12.5px;
}

/* FAQ */
.faq-list { display: flex; flex-direction: column; gap: 8px; }
.faq-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.faq-q {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  color: var(--fg1);
}
.faq-q::before {
  content: ""; width: 3px; height: 16px; background: var(--accent);
  margin-right: 10px; flex-shrink: 0;
}
.faq-q .chev {
  transition: transform var(--dur) var(--ease);
  color: var(--fg3);
}
.faq-item.open .faq-q .chev { transform: rotate(180deg); color: var(--accent); }
.faq-a {
  display: none;
  padding: 0 16px 16px 29px;
  color: var(--fg2);
  font-size: 13.5px;
  line-height: 1.6;
}
.faq-item.open .faq-a { display: block; }

/* Templates */
.tpl-list { display: flex; flex-direction: column; gap: 8px; }
.tpl-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.tpl-row .t-nm { font-weight: 600; flex: 1; min-width: 0; }
.tpl-row .t-meta { font-family: var(--font-mono); font-size: 11px; color: var(--fg3); }
.tpl-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--fg3);
  background: var(--panel-2);
  border: 1px dashed var(--border-stencil);
  border-radius: var(--radius-md);
}

/* Arbitrage */
.arb-cmp-row {
  display: flex; flex-wrap: wrap; gap: 16px;
  padding: 10px 0 0;
  border-top: 1px dashed var(--border-stencil);
  margin-top: 10px;
}
.arb-cmp-col { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.arb-cmp-col .cap {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--fg3);
}
.excl-btn {
  padding: 6px 10px;
  min-height: 28px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--fg3);
  border-radius: var(--radius-sm);
}
.excl-btn.active {
  background: var(--hazard-500);
  color: #fff;
  border-color: var(--hazard-500);
}

/* Tweaks panel */
.tweaks {
  position: fixed; top: 0; right: 0;
  width: min(320px, 90vw);
  height: 100dvh;
  background: var(--panel);
  border-left: 1px solid var(--border-strong);
  z-index: 120;
  transform: translateX(100%);
  transition: transform .28s var(--ease);
  padding: 20px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  box-shadow: -12px 0 40px rgba(0,0,0,.4);
}
.tweaks.open { transform: translateX(0); }
.tweaks h3 {
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin: 0 0 4px;
  color: var(--fg1);
}
.tweaks .tw-close {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px;
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--fg2);
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
}
.tweaks .tw-group {
  display: flex; flex-direction: column; gap: 8px;
}
.tweaks .tw-group > label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--fg3);
}
.tweaks .tw-opts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.tweaks .tw-opts button {
  padding: 10px 6px;
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  color: var(--fg2);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.tweaks .tw-opts button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tweaks .tw-swatch {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 6px;
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px var(--border-strong);
}
.tw-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 110;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.tw-overlay.open { opacity: 1; pointer-events: auto; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(3, 6, 12, .72);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 640px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h3 {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin: 0 0 12px;
  color: var(--fg1);
}
.modal .m-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--panel);
  border: 1px solid var(--accent);
  color: var(--fg1);
  padding: 10px 16px;
  font-size: 13px;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0,0,0,.4), 0 0 0 1px var(--accent), 0 0 18px color-mix(in srgb, var(--accent-glow) 40%, transparent);
  z-index: 300;
  opacity: 0;
  transition: transform .25s var(--ease), opacity .25s var(--ease);
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Loader */
.loader {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.loader.hidden { display: none; }

.hidden { display: none !important; }

/* ========== MOBILE ========== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(280px, 86vw);
    transform: translateX(-100%);
    transition: transform .25s var(--ease);
    height: 100dvh;
    padding-top: 14px;
    z-index: 150;
    box-shadow: 8px 0 32px rgba(0,0,0,.5);
  }
  .sidebar.open {
    transform: translateX(0);
    z-index: 220;
    pointer-events: auto;
  }
  .sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 140;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
  }
  /* Затемнение под выезжающим сайдбаром, но с кликом для закрытия */
  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
    z-index: 210;
  }

  main { padding: 14px; }

  .cards { grid-template-columns: 1fr; }
  .opt-list { grid-template-columns: 1fr; }
  .result-summary { grid-template-columns: 1fr 1fr; }
  .main-head h1 { font-size: 20px; }
}

@media (max-width: 480px) {
  .result-summary { grid-template-columns: 1fr; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .panel-actions { justify-content: flex-start; }
  .btn { flex: 1 0 auto; }
}
