.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e6ea);
  border-radius: 12px;
  padding: 16px;
}

.master h2,
.detail h2 {
  margin-top: 0;
  font-size: 16px;
}

.instruments {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}

.instrument {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border, #eee);
}

.instrument .inst-name {
  flex: 0 0 auto;
  font-weight: 600;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.instrument .muted {
  flex: 1;
  font-size: 12px;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

.add-form input,
.add-form select {
  padding: 6px 8px;
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  font-size: 13px;
}

.btn {
  cursor: pointer;
  border: 1px solid var(--border, #ccc);
  background: #f6f8fa;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.btn:hover {
  background: #eef1f4;
}

.btn-primary,
.btn-add {
  background: #1976d2;
  color: #fff;
  border-color: #1976d2;
  width: 100%;
  font-weight: 600;
}

.btn-del {
  border: none;
  background: transparent;
  color: #b42318;
  font-size: 16px;
  padding: 0 4px;
}

.btn-audit {
  font-size: 12px;
  padding: 2px 8px;
  margin-left: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-v {
  font-size: 22px;
  font-weight: 700;
}

.stat-v.win {
  color: #1a7f37;
}

.stat-v.loss {
  color: #b42318;
}

.stat-k {
  font-size: 12px;
  color: var(--muted, #6b7280);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border, #eee);
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted, #6b7280);
}

.empty {
  color: var(--muted, #6b7280);
  padding: 12px 0;
}

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.badge-win {
  background: #dcfce7;
  color: #166534;
}

.badge-loss {
  background: #fee2e2;
  color: #991b1b;
}

.badge-be {
  background: #fef9c3;
  color: #854d0e;
}

.badge-open {
  background: #e5e7eb;
  color: #374151;
}

.dir {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.tf {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #eef2ff;
  color: #3730a3;
  font-weight: 600;
}

.dir-long {
  color: #1a7f37;
}

/* --- Блок «Рынок сейчас» --- */
.wl-head {
  margin-top: 20px;
}

.market-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.live-dot {
  font-size: 12px;
  color: #1a7f37;
  font-weight: 600;
}

.live-dot.busy {
  opacity: 0.5;
}

.live-dot.stale {
  color: #b42318;
}

/* Плашка источника котировок и счётчик успешных обновлений. */
.src-chip {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border, rgb(27 36 48 / 18%));
  color: var(--text-soft, #556270);
  background: var(--surface-sunken, #f7f9fb);
  white-space: nowrap;
}
.src-chip.src-browser {
  color: #1a7f37;
  border-color: rgb(26 127 55 / 35%);
  background: rgb(26 127 55 / 10%);
}
.src-chip.src-server {
  color: #2f5d8a;
  border-color: rgb(47 93 138 / 35%);
  background: rgb(47 93 138 / 10%);
}
.src-chip.src-down {
  color: #b42318;
  border-color: rgb(180 35 24 / 35%);
  background: rgb(180 35 24 / 8%);
}
.src-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted, #7d8a98);
  white-space: nowrap;
}
.src-count.src-count-ok {
  color: #1a7f37;
}

#market-filter {
  padding: 4px 6px;
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  font-size: 13px;
  flex: 1;
}

.btn-refresh {
  padding: 4px 8px;
}

.market-wrap {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border, #eee);
  border-radius: 10px;
}

.market-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.market-table th {
  position: sticky;
  top: 0;
  background: #f3f5f7;
  cursor: pointer;
  user-select: none;
  z-index: 1;
}

.market-table th.sorted {
  color: #1976d2;
}

.market-table td.act {
  white-space: nowrap;
}

.btn-mini {
  font-size: 11px;
  padding: 2px 6px;
  margin: 1px 2px 1px 0;
}

.chg {
  font-weight: 600;
}

.chg.up {
  color: #1a7f37;
}

.chg.down {
  color: #b42318;
}

/* --- Спред/глубина, спарклайн диапазона, массовый анализ --- */
.market-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 6px;
}

.btn-top {
  flex: 1;
  background: #7c3aed;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}

.btn-top:disabled {
  opacity: 0.6;
  cursor: progress;
}

#top-n-input {
  width: 52px;
  padding: 6px;
  border: 1px solid var(--border, #ccc);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
}

.spark-cell {
  width: 86px;
}

.spark {
  position: relative;
  height: 12px;
  width: 80px;
}

.spark-band {
  position: absolute;
  top: 5px;
  left: 0;
  right: 0;
  height: 2px;
  background: #d9dee3;
  border-radius: 2px;
}

.spark-dot {
  position: absolute;
  top: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translateX(-50%);
  border: 1px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.dir-short {
  color: #b42318;
}

.dir-neutral {
  color: #6b7280;
}
