:root {
  --bg: #080b11;
  --bg-2: #0b1019;
  --surface: #101724;
  --surface-2: #151e2e;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text: #e9eef7;
  --muted: #8a97ad;
  --green: #3ddc84;
  --red: #ff5d6c;
  --accent: #6c8cff;
  --accent-2: #9b7bff;
  --radius: 20px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(108, 140, 255, 0.18), transparent 60%),
    radial-gradient(700px 500px at 90% 0%, rgba(155, 123, 255, 0.12), transparent 55%),
    linear-gradient(180deg, #0a0f17 0%, #080b11 55%);
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) clamp(16px, 4vw, 40px) 14px;
  background: rgba(8, 11, 17, 0.72);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

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

.logo-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-weight: 800;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px rgba(108, 140, 255, 0.35);
}

.logo-text {
  display: flex;
  flex-direction: column;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.logo-text small {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--muted);
  text-transform: uppercase;
}

.top-actions { display: flex; align-items: center; gap: 10px; }

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  border-radius: 7px;
  color: #9ed8ff;
  background: rgba(80, 170, 255, 0.12);
  border: 1px solid rgba(80, 170, 255, 0.25);
}

.hidden { display: none !important; }

.error-banner {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  color: #ffb9c1;
  background: rgba(255, 93, 108, 0.12);
  border: 1px solid rgba(255, 93, 108, 0.35);
}

/* ---------------------------------------------------------------- layout */
.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px clamp(14px, 4vw, 40px) calc(70px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.hero {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 26px;
  padding: clamp(22px, 3vw, 34px);
  border-radius: 26px;
  border: 1px solid var(--border);
  background:
    radial-gradient(600px 220px at 8% 0%, rgba(108, 140, 255, 0.22), transparent 65%),
    radial-gradient(500px 240px at 95% 110%, rgba(155, 123, 255, 0.16), transparent 60%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.012));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  right: -80px;
  top: -120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(108, 140, 255, 0.2), transparent 70%);
  filter: blur(6px);
  pointer-events: none;
}

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.hero-value {
  font-size: clamp(38px, 6vw, 56px);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.hero-sub { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.hero-metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.metric {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  padding: 5px 10px;
  border-radius: 9px;
}

.metric b { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--muted);
}

.chip.up { color: var(--green); background: rgba(61, 220, 132, 0.1); border-color: rgba(61, 220, 132, 0.25); }
.chip.down { color: var(--red); background: rgba(255, 93, 108, 0.1); border-color: rgba(255, 93, 108, 0.25); }

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 12px;
  min-width: min(46%, 430px);
}

.stat {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(9, 13, 20, 0.55);
  border: 1px solid var(--border);
}

.stat span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.stat b {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ----------------------------------------------------------------- cards */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 20px;
}

.card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.012));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  padding: 20px 22px;
  min-width: 0;
  animation: rise 0.5s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chart-box { height: 320px; position: relative; }
.donut-box { height: 230px; position: relative; }

/* ------------------------------------------------------------- chart tools */
.chart-tools { display: flex; gap: 6px; }

.mini-tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 650;
  padding: 5px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.15s ease;
}

.mini-tab.active {
  color: #fff;
  border-color: rgba(108, 140, 255, 0.55);
  background: rgba(108, 140, 255, 0.2);
}

/* ----------------------------------------------------------------- сделки */
.trades { display: flex; flex-direction: column; }

.trade {
  display: grid;
  grid-template-columns: 24px 70px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.trade:first-child { border-top: none; }
.trade b { font-weight: 650; }
.trade span { color: var(--muted); }
.trade time { color: var(--muted); font-size: 11px; }

/* ------------------------------------------------------------------ tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 100%;
  margin: -4px 0 14px;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  padding: 6px 11px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: 0.15s ease;
}

.tab:hover { color: var(--text); border-color: var(--border-strong); }

.tab.active {
  color: #fff;
  border-color: rgba(108, 140, 255, 0.55);
  background: linear-gradient(135deg, rgba(108, 140, 255, 0.3), rgba(155, 123, 255, 0.18));
}

/* ---------------------------------------------------------------- donut */
.legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  margin-top: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}

.legend-item i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
}

.legend-item b { color: var(--text); font-weight: 650; }

.legend-item span { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- positions */
.positions { display: flex; flex-direction: column; }

.pos {
  display: grid;
  grid-template-columns: minmax(150px, 1.5fr) minmax(110px, 1fr) minmax(120px, 1fr) auto;
  grid-template-areas: "id price value actions";
  align-items: center;
  gap: 14px;
  padding: 14px 4px;
  border-top: 1px solid var(--border);
}

.pos:first-child { border-top: none; }

.pos-id { grid-area: id; display: flex; align-items: center; gap: 12px; min-width: 0; }

.ticker-badge {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #e6ecff;
  background: linear-gradient(
    135deg,
    hsl(var(--badge-hue, 230) 65% 55% / 0.38),
    hsl(var(--badge-hue, 230) 65% 45% / 0.16)
  );
  border: 1px solid hsl(var(--badge-hue, 230) 65% 60% / 0.42);
}

.ticker-badge.bond { color: #ffe2b8; background: linear-gradient(135deg, rgba(247, 185, 85, 0.22), rgba(255, 140, 90, 0.12)); border-color: rgba(247, 185, 85, 0.3); }

.ticker-badge.icon {
  background: #ffffff;
  padding: 5px;
  border-color: rgba(255, 255, 255, 0.18);
}

.ticker-badge.icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  display: block;
}

.ticker-badge.icon.bond-icon {
  box-shadow: 0 0 0 2px rgba(247, 185, 85, 0.55);
}

.pos-name { min-width: 0; }
.pos-name b { display: block; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-name span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-name .pos-track { font-size: 11px; color: rgba(138, 151, 173, 0.8); }

.pos-price { grid-area: price; text-align: right; font-variant-numeric: tabular-nums; }
.pos-price b { display: block; font-size: 14px; font-weight: 650; }
.pos-price .delta { font-size: 12px; font-weight: 650; }
.pos-value { grid-area: value; text-align: right; font-variant-numeric: tabular-nums; }
.pos-value b { display: block; font-size: 14px; font-weight: 650; }
.pos-value span { font-size: 12px; color: var(--muted); }

.up { color: var(--green); }
.down { color: var(--red); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.weight-bar {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
  margin-top: 6px;
  overflow: hidden;
}

.weight-bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.pos-actions { grid-area: actions; display: flex; gap: 6px; }

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: 0.15s ease;
}

.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, 0.07); }

.empty {
  padding: 26px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* --------------------------------------------------------------- signals */
.advice { display: flex; flex-direction: column; gap: 10px; }

.advice-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.advice-item.warning { border-left: 3px solid #f7b955; }
.advice-item.critical { border-left: 3px solid var(--red); }
.advice-item.info { border-left: 3px solid var(--accent); }

.advice-icon { font-size: 15px; line-height: 1.5; }
.advice-body b { font-size: 13px; font-weight: 650; display: block; }
.advice-body p { margin: 4px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.advice-body code {
  display: inline-block;
  margin-top: 7px;
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 11px;
  font-family: "Cascadia Mono", Consolas, monospace;
  background: rgba(108, 140, 255, 0.14);
  color: #c9d6ff;
}

/* --------------------------------------------------------------- signals */
.signals { display: flex; flex-direction: column; gap: 10px; }

.signal {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.signal .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  background: var(--accent);
  box-shadow: 0 0 12px currentColor;
}

.signal.info .dot { background: var(--accent); }
.signal.warning .dot { background: #f7b955; }
.signal.critical .dot { background: var(--red); }

.signal b { font-size: 13px; font-weight: 650; display: block; }
.signal p { margin: 3px 0 0; font-size: 12px; color: var(--muted); line-height: 1.45; }
.signal time { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 15px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  color: var(--text);
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 10px 26px rgba(108, 140, 255, 0.3);
}

.btn.primary:hover { filter: brightness(1.08); }

.btn.ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
  color: var(--text);
}

.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }

.btn.danger {
  background: rgba(255, 93, 108, 0.12);
  border-color: rgba(255, 93, 108, 0.35);
  color: var(--red);
}

/* ----------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 6, 10, 0.66);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade 0.18s ease;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(420px, 100%);
  border-radius: 22px;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, #131b29, #0e1520);
  box-shadow: var(--shadow);
  padding: 22px;
  animation: rise 0.22s ease;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 17px; }

.form { display: flex; flex-direction: column; gap: 12px; }

.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.form label small { font-weight: 500; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus { border-color: rgba(108, 140, 255, 0.7); }

.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------------------------------------------------------------- toasts */
.toast-wrap {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px solid var(--border-strong);
  background: rgba(20, 28, 42, 0.96);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.4;
  animation: rise 0.2s ease;
}

.toast.error { border-color: rgba(255, 93, 108, 0.4); }

/* ------------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: stretch; gap: 20px; }
  .hero-stats { min-width: 0; }
  .tabs { max-width: 100%; }
}

@media (max-width: 700px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .logo-text { font-size: 14px; }
  #updated { display: none; }
  .btn-label { display: none; }
  .wrap { padding: 18px 14px 60px; gap: 14px; }
  .hero-value { font-size: 38px; }
  .card { padding: 16px; }
  .hero-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: clamp(13px, 3.6vw, 16px); }
  .tabs { flex-wrap: nowrap; justify-content: flex-start; margin-bottom: 12px; }
  .pos {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "id actions"
      "price value";
    row-gap: 8px;
  }
  .pos-price, .pos-value { text-align: left; }
  .pos-price b, .pos-value b { font-size: 13px; }
  .chart-box { height: 260px; }
  .legend { grid-template-columns: 1fr; }
}
