*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #0b0f14;
  color: #e5e7eb;
  line-height: 1.45;
}

.app-root {
  min-height: 100vh;
  padding: 1rem 1.25rem 2rem;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: 0.35rem;
  padding-bottom: 0.75rem;
  margin-top: -0.35rem;
  background: #0b0f14;
  border-bottom: 1px solid #1f2937;
}

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(26rem, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem 0.65rem 1rem;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.22s ease-out;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.toast--error {
  background: #1c1410;
  border-color: rgba(180, 83, 9, 0.55);
  color: #fde68a;
}

.toast--info {
  background: #111827;
  border-color: rgba(59, 130, 246, 0.45);
  color: #bfdbfe;
}

.toast__text {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  max-height: 12rem;
  overflow-y: auto;
  word-break: break-word;
}

.toast__close {
  flex-shrink: 0;
  margin: -0.15rem -0.1rem 0 0;
  padding: 0 0.35rem;
  line-height: 1.2;
  font-size: 1.25rem;
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.75;
  cursor: pointer;
  border-radius: 4px;
}

.toast__close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.toast--out {
  opacity: 0;
  transform: translateX(0.75rem);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(0.75rem);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.app-header__text {
  min-width: 0;
}

.app-header__right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-top: 0.2rem;
}

.app-header__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.app-header__actions--grow {
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.app-header__actions .btn--ghost {
  font-size: 0.8125rem;
}

/* Блокировка + спиннер поверх элемента */
.ui-busy-anchor {
  position: relative;
}

.ui-busy-anchor.is-busy {
  pointer-events: none;
}

.ui-busy-shim {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 20, 0.48);
  border-radius: inherit;
  pointer-events: auto;
}

.ui-busy-anchor.is-busy .ui-busy-shim {
  display: flex;
}

.ui-busy-shim::after {
  content: '';
  width: 22px;
  height: 22px;
  box-sizing: border-box;
  border: 2px solid rgba(147, 197, 253, 0.22);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: ui-busy-spin 0.65s linear infinite;
}

@keyframes ui-busy-spin {
  to {
    transform: rotate(360deg);
  }
}

/* mock · live — переключатель режима */
.trading-mode {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.45rem;
  padding: 0.25rem 0;
  border-radius: 8px;
  border: 0;
  background: none;
  font-size: 0.78rem;
}

.trading-mode--live {
  border: 0;
  background: none;
  box-shadow: none;
}

.trading-mode__side {
  font-weight: 700;
  text-transform: lowercase;
  letter-spacing: 0.02em;
  color: #6b7280;
  user-select: none;
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

.trading-mode__side--mock.trading-mode__side--active {
  color: #e5e7eb;
}

.trading-mode__side--live.trading-mode__side--active {
  color: #fca5a5;
}

.trading-mode__track {
  position: relative;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid #4b5563;
  border-radius: 14px;
  background: #374151;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.trading-mode__track:hover {
  border-color: #6b7280;
}

.trading-mode__track:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.45);
}

.trading-mode--live .trading-mode__track {
  background: rgba(127, 29, 29, 0.55);
  border-color: #dc2626;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.35);
}

.trading-mode--live .trading-mode__track:focus {
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.5);
}

.trading-mode__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e5e7eb;
  transition: transform 0.2s ease, background 0.2s ease;
}

.trading-mode--live .trading-mode__thumb {
  transform: translateX(24px);
  background: #fecaca;
}

/* Модалка пароля для Live */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 1.35rem 1.5rem;
  border-radius: 10px;
  border: 1px solid #374151;
  background: #111827;
  color: #e5e7eb;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.modal__title {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.modal__text {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: #9ca3af;
  line-height: 1.45;
}

.modal__field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1.15rem;
}

.modal__field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal__input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #4b5563;
  background: #0b0f14;
  color: #f3f4f6;
  font-size: 0.9rem;
}

.modal__input--password {
  border-color: #b91c1c;
  background: rgba(127, 29, 29, 0.12);
}

.modal__input--password:focus {
  outline: none;
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn--sm {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
}

.position-tile__stall {
  margin: 0 0 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #b45309;
  background: rgba(180, 83, 9, 0.15);
  color: #fcd34d;
  font-size: 0.82rem;
}

.position-tile__stall[hidden] {
  display: none !important;
}

.position-tile__stall-text {
  margin: 0 0 0.45rem;
  line-height: 1.35;
}

.position-tile__stall .btn-stall-retry {
  font-size: 0.78rem;
}

.app-header__ws {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.ws-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.ws-indicator__label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #9ca3af;
  user-select: none;
}

.ws-status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-sizing: border-box;
  vertical-align: middle;
  cursor: default;
}

.ws-status-dot--idle {
  background: #4b5563;
  box-shadow: 0 0 0 0 rgba(75, 85, 99, 0.5);
}

.ws-status-dot--connecting {
  background: #eab308;
}

.ws-status-dot--open {
  background: #22c55e;
}

.ws-status-dot--reconnecting {
  background: #f97316;
}

.ws-status-dot--closed {
  background: #6b7280;
}

.ws-status-dot--connecting,
.ws-status-dot--open,
.ws-status-dot--reconnecting {
  animation: ws-status-pulse 1.6s ease-out infinite;
}

@keyframes ws-status-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(255, 255, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.app-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.app-subtitle {
  margin: 0.25rem 0 0;
  color: #9ca3af;
  font-size: 0.9rem;
}

.layout {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;
}

.layout-col {
  flex: 1 1 360px;
  min-width: 280px;
}

.layout-col--left {
  flex: 0 0 20%;
  max-width: 20%;
  min-width: 0;
}

.layout-col--right {
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
}

.panel {
  background: #111827;
  border: 1px solid #1f2937;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.panel--tiles {
  min-height: 200px;
}

.panel__title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.deposit-table__grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.deposit-table__grid thead th {
  text-align: left;
  font-weight: 600;
  color: #9ca3af;
  padding: 0.4rem 0.5rem 0.5rem 0;
  border-bottom: 1px solid #374151;
}

.deposit-table__grid thead th:nth-child(2),
.deposit-table__grid thead th:nth-child(3) {
  text-align: right;
}

.deposit-table__row td {
  padding: 0.4rem 0.5rem 0.4rem 0;
  vertical-align: top;
}

.deposit-table__coin {
  font-weight: 500;
  text-align: left;
}

.deposit-table__usdt,
.deposit-table__pnl {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.deposit-table__row--total {
  font-weight: 700;
}

.deposit-table__row--total td {
  border-top: 1px solid #374151;
  padding-top: 0.55rem;
  margin-top: 0.25rem;
}

.deposit-table__empty {
  margin: 0;
  color: #6b7280;
  font-size: 0.9rem;
}

.global-tpsl-panel {
  margin: 0 0 0.7rem;
  padding: 0.6rem 0.65rem;
  border: 1px solid #1f2937;
  border-radius: 8px;
  background: #0f1419;
  display: block;
}

.global-tpsl-panel__row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.global-tpsl-panel__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.global-tpsl-panel__label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.global-tpsl-panel__label--gtp {
  color: #22c55e;
}

.global-tpsl-panel__label--gsl {
  color: #ef4444;
}

.global-tpsl-panel__value {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  min-width: 3.25rem;
}

.global-tpsl-panel__value--editable {
  cursor: pointer;
}

.global-tpsl-panel__input {
  width: 5.2rem;
  max-width: 100%;
  font-size: 0.85rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid #4b5563;
  border-radius: 3px;
  background: #111827;
  color: #f9fafb;
}

.global-tpsl-panel__input[hidden] {
  display: none !important;
}

.global-tpsl-panel__item.is-editing .global-tpsl-panel__value {
  display: none;
}

.global-tpsl-panel__item.is-editing .global-tpsl-panel__input {
  display: inline-block !important;
}

.pnl-pos {
  color: #22c55e;
}

.pnl-neg {
  color: #ef4444;
}

.pnl-zero {
  color: #d1d5db;
}

.mini-chart-wrap {
  margin-bottom: 0.75rem;
}

.mini-chart {
  display: block;
  width: 100%;
  height: 240px;
  border-radius: 6px;
  background: #0f1419;
  position: relative;
  min-height: 240px;
}

.mini-chart.in_progress {
  opacity: 0.65;
  pointer-events: none;
}

.timeframe-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.tf-btn {
  border: 1px solid #374151;
  background: #1f2937;
  color: #d1d5db;
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.tf-btn:hover {
  background: #374151;
}

.tf-btn--active {
  border-color: #3b82f6;
  background: #1e3a5f;
  color: #fff;
}

.order-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.55rem;
}

.order-form .form-row--inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
  align-items: end;
}

.order-form .form-row--order-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  box-sizing: border-box;
  margin-top: 0.45rem;
  margin-bottom: 0.15rem;
}

.order-form .form-row--order-actions .btn {
  flex: 0 0 auto;
}

.order-form__actions-trailing {
  flex: 0 0 auto;
  text-align: right;
}

.order-form__text-btn {
  padding: 0;
  border: none;
  background: none;
  color: #93c5fd;
  font-size: 0.82rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font-family: inherit;
}

.order-form__text-btn:hover {
  color: #bfdbfe;
}

.order-form__advanced {
  margin-top: 0.35rem;
  padding-top: 0.45rem;
  border-top: 1px solid #1f2937;
  margin-bottom: 0.15rem;
}

.order-form .form-row--order-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.85rem;
  align-items: start;
}

.order-form__type-col .order-form__type-stack {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.order-form__type-col .order-type-tile {
  width: 100%;
  box-sizing: border-box;
}

.order-form__tpsl-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.order-form__tpsl-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.order-form__tpsl-group--sl {
  padding-left: 0.45rem;
  border-left: 1px solid #1f2937;
  margin-left: 0.1rem;
}

.order-form__tpsl-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.order-form .order-tpsl-mode {
  flex: 0 0 auto;
  min-width: 5.25rem;
  max-width: 7.25rem;
  font-size: 0.78rem;
  padding: 0.4rem 0.35rem;
}

.order-form .order-tpsl-input {
  flex: 1 1 auto;
  min-width: 0;
}

.order-form .form-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.order-form label,
.order-form .form-label {
  font-size: 0.8rem;
  color: #9ca3af;
}

.order-form .form-row--type-tiles-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}

.order-form .form-row--type-tiles-inner {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 0.75rem;
  align-items: stretch;
}

/* Совместимость: старые разметки с двумя плитками в ряд */
.order-form .form-row--type-tiles-inner .order-type-tile {
  width: auto;
}

.order-form .order-type-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid #374151;
  border-radius: 8px;
  background: #111827;
  cursor: pointer;
  min-height: 3.35rem;
  box-sizing: border-box;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.order-form .order-type-tile--market {
  justify-content: left;
  align-items: flex-start;
}

.order-form .order-type-tile--active {
  border-color: #2563eb;
  background: #1e3a5f;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

.order-form .order-type-tile:hover:not(.order-type-tile--active) {
  border-color: #4b5563;
}

.order-form .order-type-tile:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.order-form .order-type-tile__label {
  font-size: 0.85rem;
  font-weight: 500;
  color: #e5e7eb;
  text-align: center;
}

.order-form .order-type-tile--limit .order-type-tile__label {
  text-align: left;
}

.order-form .order-type-tile--active .order-type-tile__label {
  color: #f9fafb;
}

.order-form .order-type-tile__input {
  width: 100%;
  box-sizing: border-box;
}

/* Клики по отключённому полю лимита проходят к плашке (как клик по плашке). */
.order-form .order-type-tile__input:disabled {
  pointer-events: none;
}

.order-form input,
.order-form select {
  background: #0f1419;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 0.45rem 0.5rem;
  color: #f9fafb;
  font-size: 0.9rem;
}

.order-form input[type='number'] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.order-form input[type='number']::-webkit-outer-spin-button,
.order-form input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.order-form input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.order-form .input--error {
  border-color: #ef4444;
}

.field-error {
  font-size: 0.75rem;
  color: #fca5a5;
}

.form-hint {
  font-size: 0.75rem;
  color: #6b7280;
  margin: 0 0 0.75rem;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn--primary {
  background: #2563eb;
  color: #fff;
}

.btn--primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--secondary {
  background: #374151;
  color: #e5e7eb;
}

.btn--danger {
  background: #b91c1c;
  color: #fff;
}

.btn--ghost {
  background: transparent;
  color: #9ca3af;
  border: 1px solid #374151;
}

.history-list {
  overflow-x: auto;
  margin: 0 -0.15rem;
  padding: 0 0.15rem;
}

.history-section {
  margin-top: 0.85rem;
}

.history-section:first-child {
  margin-top: 0;
}

.history-section__title {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #9ca3af;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.history-table__empty-row {
  color: #6b7280;
  font-size: 0.78rem;
  text-align: center;
  padding: 0.5rem 0.35rem;
  cursor: default;
}

.history-table tbody tr.history-table__tr--empty {
  cursor: default;
}

.history-table tbody tr.history-table__tr--empty:hover {
  background: transparent;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.history-table thead th {
  text-align: left;
  font-weight: 600;
  color: #9ca3af;
  padding: 0.35rem 0.45rem 0.5rem;
  border-bottom: 1px solid #374151;
  white-space: nowrap;
}

.history-table__th--badge {
  width: 1%;
  padding: 0.35rem 0.08rem 0.5rem 0.12rem;
  white-space: nowrap;
}

.history-table__th--pnl {
  text-align: right;
  width: 1%;
}

.history-table tbody tr {
  cursor: pointer;
  border-bottom: 1px solid #1f2937;
}

.history-table tbody tr:hover {
  background: #1a2332;
}

.history-table tbody td {
  padding: 0.38rem 0.45rem;
  vertical-align: middle;
  color: #e5e7eb;
}

.history-table__td--badge {
  width: 1%;
  padding: 0.38rem 0.06rem 0.38rem 0.12rem;
  white-space: nowrap;
  text-align: center;
  vertical-align: middle;
}

.history-table__td--pnl {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Выше специфичность, чем у `.history-table tbody td { color }` */
.history-table tbody td.history-table__td--pnl.pnl-pos {
  color: #22c55e;
}

.history-table tbody td.history-table__td--pnl.pnl-neg {
  color: #ef4444;
}

.history-table tbody td.history-table__td--pnl.pnl-zero {
  color: #d1d5db;
}

.history-table tbody td.history-table__td--pnl.history-table__muted {
  color: #9ca3af;
}

.history-table tbody td.history-table__td--pnl.history-table__pnl-pending-fill {
  color: #eab308;
}

.history-table__dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  vertical-align: middle;
}

.history-table__dot--open-pos {
  background: #22c55e;
  box-shadow: 0 0 0 0.5px rgba(34, 197, 94, 0.45);
}

.history-table__dot--open-neg {
  background: #ef4444;
  box-shadow: 0 0 0 0.5px rgba(239, 68, 68, 0.45);
}

.history-table__dot--open-neutral {
  background: #6b7280;
  box-shadow: 0 0 0 0.5px rgba(107, 114, 128, 0.45);
}

.history-table__dot--open {
  background: #22c55e;
  box-shadow: 0 0 0 0.5px rgba(34, 197, 94, 0.45);
}

.history-table__dot--pending {
  background: #eab308;
  box-shadow: 0 0 0 0.5px rgba(234, 179, 8, 0.45);
}

.history-table__dot--closed {
  background: #ef4444;
  box-shadow: 0 0 0 0.5px rgba(239, 68, 68, 0.45);
}

.history-table__dot--unknown {
  background: #6b7280;
  box-shadow: 0 0 0 0.5px rgba(107, 114, 128, 0.45);
}

.history-table__coin {
  font-weight: 600;
}

.history-table__muted {
  color: #9ca3af;
}

.history-list__empty {
  color: #6b7280;
  font-size: 0.9rem;
  margin: 0;
}

.positions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: stretch;
}

.position-tile {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Не растягивать на всю строку при одной плитке: ширина строки ≈50% (две колонки с gap). */
  flex: 0 1 calc(50% - 0.375rem);
  min-width: min(100%, 280px);
  max-width: 100%;
  box-sizing: border-box;
  position: relative;
  background: #0f1419;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.75rem;
}

.position-tile--live {
  border-color: rgba(59, 130, 246, 0.9);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.22);
}

.position-tile--closed {
  opacity: 0.95;
  border-style: dashed;
}

.position-tile--dragging {
  opacity: 0.55;
}

.position-tile__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.15rem 0.25rem 0.15rem 0;
  margin-left: -0.15rem;
  margin-right: -0.15rem;
  border-radius: 6px;
  cursor: grab;
  user-select: none;
}

.position-tile__head:active {
  cursor: grabbing;
}

.position-tile__exec-label {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.12rem 0.38rem;
  border-radius: 4px;
  border: 1px solid transparent;
  line-height: 1.2;
  user-select: none;
}

.position-tile__exec-label--live {
  color: #93c5fd;
  background: rgba(37, 99, 235, 0.22);
  border-color: rgba(59, 130, 246, 0.55);
}

.position-tile__exec-label--mock {
  color: #9ca3af;
  background: rgba(75, 85, 99, 0.35);
  border-color: #4b5563;
}

.position-tile__head-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-left: auto;
}

.position-tile__dismiss {
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
  border-radius: 4px;
}

.position-tile__dismiss:hover {
  color: #f9fafb;
  background: #1f2937;
}

.position-tile__title {
  margin: 0;
  font-size: 1rem;
}

.position-tile__badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  color: #0b0f14;
}

.position-tile__badge--open {
  background: #22c55e;
  color: #052e16;
}

.position-tile__badge--pending {
  background: #eab308;
  color: #422006;
}

.position-tile__badge--closed {
  background: #ef4444;
  color: #fff;
}

.position-tile__badge--unknown {
  background: #374151;
  color: #e5e7eb;
}

.position-tile__metrics {
  display: grid;
  grid-template-columns: repeat(var(--position-metric-cols, 7), minmax(0, 1fr));
  gap: 0.35rem 0.4rem;
  align-items: start;
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}

.position-tile__metric {
  min-width: 0;
}

.position-tile__metric-label {
  display: block;
  color: #9ca3af;
  font-size: 0.72rem;
  line-height: 1.25;
  min-height: 1.25rem;
}

.position-tile__metric-label--re {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.15rem;
  flex-wrap: nowrap;
}

.position-tile__metric-value {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  min-height: 1.25rem;
}

.position-tile__metric-value strong {
  font-size: 0.85rem;
}

.position-tile__re-line {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  min-height: 1.25rem;
  width: 100%;
}

.position-tile__re-line.ui-busy-anchor {
  border-radius: 4px;
  min-height: 1.75rem;
}

.position-tile__btn-re-clear {
  flex-shrink: 0;
  margin: 0;
  padding: 0 0.12rem;
  border: none;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  border-radius: 3px;
}

.position-tile__btn-re-clear:hover:not(:disabled),
.position-tile__btn-re-clear:focus-visible:not(:disabled) {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.12);
}

.position-tile__re-line.is-editing .position-tile__btn-re-edit {
  display: none;
}

.position-tile__metric--entry .position-tile__entry-line {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  min-height: 1.25rem;
  width: 100%;
}

.position-tile__metric--entry .position-tile__entry-line.ui-busy-anchor {
  border-radius: 4px;
  min-height: 1.75rem;
}

.position-tile__entry-price-view--editable {
  cursor: pointer;
}

.position-tile__entry-line.is-editing .position-tile__btn-edit-entry {
  display: none;
}

.position-tile__btn-edit-entry {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  padding: 0.15rem;
  margin: 0;
  border: none;
  background: transparent;
  color: #9ca3af;
  cursor: pointer;
  border-radius: 3px;
}

.position-tile__btn-edit-entry-icon {
  display: block;
  width: 0.95rem;
  height: 0.95rem;
}

.position-tile__btn-edit-entry:hover:not(:disabled),
.position-tile__btn-edit-entry:focus-visible:not(:disabled) {
  color: #e5e7eb;
  background: rgba(255, 255, 255, 0.06);
}

.position-tile__entry-price-input {
  width: 6.5rem;
  max-width: 100%;
  font-size: 0.85rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid #4b5563;
  border-radius: 3px;
  background: #111827;
  color: #f9fafb;
}

.position-tile__chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0.5rem 0;
}

.position-tile__crosshair-pop {
  position: absolute;
  z-index: 25;
  min-width: 9.75rem;
  max-width: calc(100% - 0.5rem);
  border-radius: 6px;
  border: 1px solid #374151;
  background: #1f2937;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.position-tile__crosshair-pop-inner {
  padding: 0.4rem 0.5rem 0.5rem;
}

.position-tile__crosshair-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}

.position-tile__crosshair-pop-price {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: #f9fafb;
  line-height: 1.2;
  word-break: break-all;
}

.position-tile__crosshair-pop-close {
  flex-shrink: 0;
  margin: 0;
  padding: 0 0.25rem;
  line-height: 1.1;
  font-size: 1.15rem;
  color: #9ca3af;
  background: transparent;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

.position-tile__crosshair-pop-close:hover,
.position-tile__crosshair-pop-close:focus-visible {
  color: #f3f4f6;
  background: rgba(255, 255, 255, 0.06);
}

.position-tile__crosshair-pop-actions {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.position-tile__crosshair-pop-btn {
  width: 100%;
  justify-content: center;
  margin: 0;
  font-size: 0.75rem;
  padding: 0.22rem 0.45rem;
}

.position-tile__chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

/* Таймфреймы слева; справа — кроссхайр и будущие кнопки */
.position-tile__chart-head .timeframe-bar--tile {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: flex-start;
  margin-top: 0;
}

.position-tile__chart-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.timeframe-bar--tile {
  flex-wrap: wrap;
  gap: 0.2rem;
}

.timeframe-bar--tile .tf-btn {
  padding: 0.15rem 0.35rem;
  font-size: 0.7rem;
}

.position-tile__chart-actions .tf-btn--crosshair {
  padding: 0.15rem 0.4rem;
  font-size: 0.85rem;
  line-height: 1;
}

.position-tile__plotly {
  min-height: 260px;
  height: 312px;
  width: 100%;
  border-radius: 6px;
  background: #111827;
}

.position-tile__controls {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

.position-tile__actions-busy {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  flex: 1 1 100%;
  min-width: 0;
  border-radius: 6px;
}

.position-tile__edit-form {
  margin: 0;
  min-width: 0;
}

.position-tile__controls-main {
  flex: 1 1 auto;
  min-width: 0;
}

.position-tile__btn-close {
  flex: 0 0 auto;
  margin-left: auto;
  align-self: flex-end;
}

.position-tile__edit {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.position-tile__edit--compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.45rem;
}

.position-tile__edit--tpsl-row {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.35rem;
}

.position-tile__edit-block {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.position-tile__edit-block--sl {
  margin-left: 0.45rem;
}

.position-tile__edit--tpsl-row .position-tile__edit-block--sl {
  margin-left: 0;
}

.btn-tile-icon {
  padding: 0.28rem 0.45rem;
  min-width: 2.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-tile-icon svg {
  display: block;
}

.position-tile__sel-mode {
  min-width: 5.25rem;
  max-width: 7.5rem;
  font-size: 0.72rem;
  background: #0b0f14;
  border: 1px solid #374151;
  border-radius: 4px;
  color: #f9fafb;
  padding: 0.2rem 0.2rem;
}

/* Числовые поля правки TP/SL: без стрелок stepper (на случай type=number) */
.position-tile__edit-input-num::-webkit-outer-spin-button,
.position-tile__edit-input-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.position-tile__edit-input-num[type='number'] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.position-tile__edit label {
  font-size: 0.75rem;
  color: #9ca3af;
}

.position-tile__edit input {
  width: 5.25rem;
  background: #0b0f14;
  border: 1px solid #374151;
  border-radius: 4px;
  color: #f9fafb;
  padding: 0.2rem 0.35rem;
}

.position-tile__edit .btn-save-edit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 720px) {
  .layout-col--left,
  .layout-col--right {
    flex: 1 1 100%;
    max-width: 100%;
    min-width: 0;
  }

  .position-tile {
    flex: 1 1 100%;
  }
}
