:root {
  --topbar-height: 53px;
  --toolbar-height: 47px;
  --bottom-nav-height: 66px;
}

@media (max-width: 640px) {
  .canvas-toolbar {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .canvas-toolbar .toolbar-btn {
    flex: 1 1 150px;
    min-width: 0;
    white-space: normal;
    line-height: 1.2;
  }

  .market-quality-table-wrap {
    overflow-x: visible;
  }

  .market-quality-table,
  .market-quality-summary-table {
    display: block;
    min-width: 0;
    width: 100%;
  }

  .market-quality-table thead {
    display: none;
  }

  .market-quality-table tbody,
  .market-quality-table tr {
    display: grid;
    gap: 8px;
  }

  .market-quality-table tr {
    padding: 10px;
    border-top: 1px solid #dbeafe;
  }

  .market-quality-table tbody tr:first-child {
    border-top: 0;
  }

  .market-quality-table th:first-child,
  .market-quality-table td:first-child {
    position: static;
    left: auto;
    z-index: auto;
    background: transparent;
    box-shadow: none;
  }

  .market-quality-table td {
    display: grid;
    grid-template-columns: minmax(96px, 0.42fr) minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    min-width: 0;
    padding: 0;
    border-top: 0;
    background: transparent !important;
    white-space: normal;
  }

  .market-quality-table td:nth-child(2) {
    width: auto;
    white-space: normal;
  }

  .market-quality-table .quality-pill {
    justify-self: start;
    width: max-content;
    max-width: 100%;
    min-width: max-content;
    white-space: nowrap;
  }

  .market-quality-table td::before {
    color: #64748b;
    font-size: 10px;
    font-weight: 950;
    letter-spacing: 0.04em;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .market-quality-summary-table td:nth-child(1)::before { content: "Проверка"; }
  .market-quality-summary-table td:nth-child(2)::before { content: "Статус"; }
  .market-quality-summary-table td:nth-child(3)::before { content: "Значение"; }
  .market-quality-summary-table td:nth-child(4)::before { content: "Детали"; }

  .market-quality-table:not(.market-quality-summary-table) td:nth-child(1)::before { content: "Символ"; }
  .market-quality-table:not(.market-quality-summary-table) td:nth-child(2)::before { content: "Статус"; }
  .market-quality-table:not(.market-quality-summary-table) td:nth-child(3)::before { content: "Свеча"; }
  .market-quality-table:not(.market-quality-summary-table) td:nth-child(4)::before { content: "Live"; }
  .market-quality-table:not(.market-quality-summary-table) td:nth-child(5)::before { content: "Mark"; }
  .market-quality-table:not(.market-quality-summary-table) td:nth-child(6)::before { content: "Объем"; }

  .credential-matrix {
    overflow-x: visible;
  }

  .credential-matrix-head {
    display: none;
  }

  .credential-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    min-width: 0;
    padding: 12px;
  }

  .credential-row > .credential-cell,
  .credential-row > em {
    display: grid;
    grid-template-columns: minmax(88px, 0.35fr) minmax(0, 1fr);
    gap: 8px;
    align-items: start;
  }

  .credential-row > .credential-cell::before,
  .credential-row > em::before {
    color: #64748b;
    font-size: 10px;
    font-style: normal;
    font-weight: 950;
    letter-spacing: 0.04em;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .credential-row > .credential-cell:nth-of-type(1)::before { content: "Production"; }
  .credential-row > .credential-cell:nth-of-type(2)::before { content: "Testnet"; }
  .credential-row > em::before { content: "Выбрано"; }

  .credential-cell-line {
    align-items: flex-start;
  }
}

@media (min-width: 641px) and (max-width: 980px) {
  .portfolio-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .prop-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .canvas-toolbar::-webkit-scrollbar {
    display: none;
  }

  .strategy-fleet-table {
    max-height: none;
    overflow: visible;
    gap: 8px;
  }

  .strategy-fleet-row.fleet-header {
    display: none;
  }

  .strategy-fleet-row:not(.fleet-header) {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: hidden;
    padding: 10px;
  }

  .strategy-fleet-row:not(.fleet-header) .strategy-fleet-cell {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    min-height: 58px;
    padding: 8px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
  }

  .strategy-fleet-row:not(.fleet-header) .strategy-fleet-cell[data-label]::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 10px;
    font-weight: 950;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .strategy-fleet-row:not(.fleet-header) .strategy-name-cell,
  .strategy-fleet-row:not(.fleet-header) .action-cell {
    grid-column: 1 / -1;
  }

  .strategy-fleet-row:not(.fleet-header) .action-cell .strategy-row-actions {
    justify-self: stretch;
    justify-content: flex-start;
  }

  .strategy-fleet-row:not(.fleet-header) .action-cell .btn {
    width: 100%;
  }

  .control-critical-grid,
  .operator-columns {
    grid-template-columns: 1fr;
  }

  .market-quality-table-wrap {
    overflow-x: visible;
  }

  .market-quality-table,
  .market-quality-summary-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  .market-quality-table th,
  .market-quality-table td {
    min-width: 0;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .workspace-node-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-x: visible;
    gap: 10px;
  }

  .workspace-node {
    min-width: 0;
  }

  .workspace-node::after {
    display: none;
  }

  .workspace-bottom-dock {
    flex-wrap: wrap;
    justify-content: center;
    max-width: calc(100% - 20px);
    height: auto;
  }

  .workspace-bottom-dock button {
    flex: 1 1 96px;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-height: 96px;
  }

  html, body {
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* --- Topbar --- */
  .topbar {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 8px 12px;
    min-height: 0;
    overflow: visible;
  }

  .back-btn {
    flex: 0 0 auto;
    order: 1;
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  .runner-name {
    display: none !important;
  }

  .mode-badge {
    flex: 0 0 auto;
    order: 2;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: 30px;
    padding: 0 10px;
  }

  .mode-badge-long {
    display: none;
  }

  .mode-badge-short {
    display: inline;
  }

  .language-toggle {
    flex: 0 0 auto;
    order: 3;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 30px;
  }

  /* Hide all secondary items */
  .runner-status,
  .top-spacer,
  .last-triggered,
  .qats-label,
  #tourButton,
  #runOnceButton,
  #syncButton,
  #reconcileButton,
  #exportButton,
  #logoutButton,
  #historySyncButton {
    display: none !important;
  }

  /* Row 2: Shabbat + Emergency stop, equal width */
  .shabbat-mode-button {
    flex: 1 1 calc(50% - 4px);
    order: 10;
    min-width: 0;
    min-height: 36px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding-inline: 8px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .activate-btn.danger {
    flex: 1 1 calc(50% - 4px);
    order: 11;
    min-width: 0;
    max-width: none;
    min-height: 36px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding-inline: 8px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* --- Canvas toolbar --- */
  .canvas-toolbar {
    top: var(--topbar-height, 96px);
    gap: 7px;
    padding: 8px 12px;
    overflow-x: visible;
    flex-wrap: wrap;
    scrollbar-width: none;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
  }

  .workspace-node-row {
    grid-template-columns: 1fr;
  }

  .workspace-bottom-dock {
    position: static;
    margin: 12px auto 0;
    transform: none;
  }

  .canvas-toolbar .toolbar-btn {
    flex: 1 1 150px;
    min-width: 0;
    white-space: normal;
    line-height: 1.2;
  }

  .canvas-toolbar::-webkit-scrollbar {
    display: none;
  }

  /* --- Layout containers --- */
  .container {
    width: 100%;
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel {
    padding: 12px;
    border-radius: 10px;
  }

  .panel-head {
    flex-wrap: wrap;
    gap: 4px;
  }

  .panel-head > div {
    min-width: 0;
  }

  /* --- Portfolio grid: 2 cols on mobile --- */
  .portfolio-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* --- Control page grids --- */
  .control-critical-grid,
  .operator-columns,
  .control-snapshot-grid,
  .prop-grid,
  .prop-auto-grid,
  .operator-info-map,
  .control-pipeline,
  .service-control-grid,
  .operator-command-grid,
  .go-no-go-panel,
  .operator-pulse,
  .control-monitor-grid {
    grid-template-columns: 1fr !important;
  }

  .control-fleet-layout {
    display: block;
  }

  .control-strategy-details {
    margin-top: 12px;
  }

  .control-strategy-lens,
  .decision-matrix {
    overflow-x: auto;
  }

  /* --- Workspace --- */
  .workspace-details {
    border-top: 1px solid #e5e7eb;
    border-left: none !important;
    padding-top: 12px;
  }

  /* --- State explorer --- */
  .state-explorer-layout {
    display: block;
  }

  .state-strategy-picker {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
  }

  .state-node-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- Strategy data --- */
  .strategy-data-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .strategy-data-grid,
  .strategy-data-lower {
    grid-template-columns: 1fr !important;
  }

  .candle-inspector {
    min-width: 0;
    width: 100%;
  }

  .chart-toolbar,
  .chart-range-control,
  .chart-presets {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* --- Stress lab --- */
  .stress-grid {
    grid-template-columns: 1fr !important;
  }

  /* --- Prop mode --- */
  .prop-layout {
    display: block;
  }

  .prop-verdict {
    margin-top: 12px;
  }

  .prop-form {
    grid-template-columns: 1fr;
  }

  .prop-visual-map {
    overflow-x: auto;
  }

  /* --- Calculation / audit --- */
  .calculation-flow,
  .calculation-strategies {
    grid-template-columns: 1fr !important;
  }

  /* --- Settings --- */
  .client-accounts-panel,
  .credential-matrix {
    overflow-x: visible;
  }

  .capital-settings-grid {
    grid-template-columns: 1fr;
  }

  .credential-row,
  .capital-card,
  .capital-card-head,
  .capital-metric-grid,
  .capital-edit-field {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
  }

  .capital-card-head {
    flex-wrap: wrap;
  }

  .capital-card-head .status-pill {
    max-width: 100%;
  }

  .capital-metric-grid {
    grid-template-columns: 1fr;
  }

  /* --- Tables --- */
  .table-wrap {
    overflow-x: auto;
  }

  .strategy-command-center {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  /* Portfolio: 1 col on very small phones */
  .portfolio-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  /* Smaller table text */
  table {
    font-size: 11px;
  }

  th, td {
    padding: 5px 6px;
  }

  /* Высоты канвасов задаёт JS (canvasLogicalHeight) — CSS !important здесь
     ломал соответствие битмапа и элемента, сплющивая графики на ~40%. */

  .panel {
    padding: 10px;
    border-radius: 8px;
  }

  .prop-form {
    grid-template-columns: 1fr;
  }

  .workspace-canvas,
  .workspace-details {
    min-height: 0 !important;
  }

  .scanner-group-grid {
    grid-template-columns: 1fr;
  }

  .credential-matrix-head,
  .credential-row {
    min-width: 320px;
  }

  /* Tour card: full width */
  .tour-card {
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    left: 12px !important;
    right: 12px !important;
    transform: none !important;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  @media (max-width: 640px) {
    .topbar {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }

    .canvas-toolbar {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }
  }
}

/* Touch targets */
@media (hover: none) and (pointer: coarse) {
  select,
  .select {
    min-height: 40px;
  }

  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  .credential-input,
  .auth-input,
  .prop-input {
    min-height: 42px;
  }

  /* iOS zoom: любое поле < 16px заставляет Safari зумить при фокусе. */
  select,
  .select,
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  textarea,
  .credential-input,
  .auth-input,
  .prop-input {
    font-size: 16px;
  }

  /* Минимальный удобный тап-таргет 44px для ВСЕХ кнопок. */
  .btn,
  .btn.compact,
  .top-action,
  .activate-btn,
  .icon-btn,
  .toolbar-btn,
  .back-btn,
  .credential-unlink-btn,
  .credential-check-btn,
  .navigator-primary a,
  .workspace-bottom-dock button {
    min-height: 44px;
    touch-action: manipulation;
  }

  /* Опасные действия — заметно крупнее и с рамкой. */
  .btn.danger,
  .activate-btn.danger,
  #stopAllButton,
  #manualCloseConfirm {
    min-height: 48px;
    font-size: 14px;
  }

  .credential-unlink-btn {
    font-size: 12px;
    padding: 8px 12px;
  }

  /* Разводим кнопки в общих рядах, чтобы палец не попадал в соседнюю. */
  .card-actions,
  .client-account-row-actions,
  .family-resume-actions,
  .capital-card-actions {
    gap: 12px;
  }

  /* Kill / Arm live / Disable — на всю ширину, отдельно от безобидных кнопок. */
  .card-actions .btn.danger,
  .client-account-row-actions .btn.danger,
  .capital-card-actions .btn.danger {
    flex-basis: 100%;
    grid-column: 1 / -1;
    margin-top: 10px;
    border: 2px solid #7f1d1d;
  }
}

/* ============================================================
   МОБИЛЬНАЯ БЕЗОПАСНОСТЬ И ЧИТАБЕЛЬНОСТЬ (<=640px)
   ============================================================ */
@media (max-width: 640px) {
  /* Аварийный стоп — своя полная строка, крупный, визуально изолирован. Shabbat
     уходит в первый ряд к бейджам, чтобы не соседствовать с опасной кнопкой
     (частая причина ошибочного тапа) и не раздувать высоту топбара. */
  .shabbat-mode-button {
    flex: 1 1 auto;
    order: 4;
    min-height: 44px;
    font-size: 13px;
  }
  .activate-btn.danger {
    flex: 1 1 100%;
    order: 12;
    min-height: 48px;
    margin-top: 4px;
    border: 2px solid #7f1d1d;
    font-weight: 700;
  }

  /* /control не должен быть уже других страниц. */
  body[data-view="controlView"] .container {
    width: 100%;
  }

  /* Полы для мелких операторских подписей (было 8–9.5px). */
  .metric-label {
    font-size: 11px;
  }
  table.responsive-table td::before {
    font-size: 11px;
  }
  .navigator-primary a span {
    font-size: 10px;
  }
  .navigator-primary a strong {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.05;
  }

  /* Карточки для клиентских аккаунтов и стриминга (data-label из JS). */
  .client-account-table,
  .streaming-table {
    display: block;
    min-width: 0 !important;
    width: 100%;
  }
  .client-account-table thead,
  .streaming-table thead {
    display: none;
  }
  .client-account-table tbody,
  .streaming-table tbody {
    display: block;
  }
  .client-account-table tr,
  .streaming-table tr {
    display: block;
    border: 1px solid #dbe3ee;
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #fff;
  }
  .client-account-table td,
  .streaming-table td {
    display: grid;
    grid-template-columns: minmax(96px, 0.4fr) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 6px 0;
    border: none;
    min-width: 0;
  }
  .client-account-table td::before,
  .streaming-table td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  .client-account-table td[data-label=""],
  .streaming-table td[data-label=""] {
    grid-template-columns: 1fr;
  }
  .client-account-table td .btn,
  .streaming-table td .btn {
    width: 100%;
  }
  /* Отменяем горизонтальный скролл-контейнер вокруг карточных таблиц. */
  .client-accounts-panel,
  .streaming-table-wrap {
    overflow-x: visible;
  }

  /* Скрытие малозначимых колонок на телефоне (флаг mobile:"hide" в table()). */
  table.responsive-table td.m-hide,
  table.responsive-table th.m-hide {
    display: none;
  }

  /* Market-quality: липкая первая колонка вместо потери идентификатора символа. */
  .market-quality-table th:first-child,
  .market-quality-table td:first-child {
    position: static;
    left: auto;
    z-index: auto;
    background: transparent;
    box-shadow: none;
  }

  /* Блок «Следующее действие оператора» и чек-листы клиента: сырые слаги
     killswitch занимали пол-экрана. Ограничиваем строками — полный текст в
     тултипе / на десктопе. */
  .navigator-task-panel em,
  .client-launch-verdict span,
  .client-live-checklist span.blocked,
  .client-live-checklist span.ok,
  .client-live-checklist span.client-live-blocker,
  .client-live-blockers {
    display: -webkit-box !important;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-height: 3.4em;
  }
}

/* Final visual-audit overrides: keep dense operator tables inside tablet/mobile viewports. */
@media (max-width: 980px) {
  .workspace-node-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    overflow-x: visible !important;
  }

  .workspace-node {
    width: 100%;
    min-width: 0;
  }

  .workspace-node::after {
    display: none;
  }

  .streaming-table-wrap,
  .product-catalog-table-wrap,
  .strategy-catalog-table-wrap {
    overflow-x: visible !important;
  }

  .streaming-table,
  .product-catalog-table,
  .strategy-catalog-table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    table-layout: auto;
  }

  .streaming-table thead,
  .product-catalog-table thead,
  .strategy-catalog-table thead {
    display: none;
  }

  .streaming-table tbody,
  .product-catalog-table tbody,
  .strategy-catalog-table tbody {
    display: grid;
    gap: 10px;
  }

  .streaming-table tr,
  .product-catalog-table tr,
  .strategy-catalog-table tr {
    display: grid;
    gap: 8px;
    min-width: 0;
    padding: 10px;
    border: 1px solid #dbe3ee;
    border-radius: 8px;
    background: #ffffff;
  }

  .streaming-table td,
  .product-catalog-table td,
  .strategy-catalog-table td {
    display: grid;
    grid-template-columns: minmax(112px, 0.36fr) minmax(0, 1fr);
    gap: 10px;
    min-width: 0;
    width: 100%;
    padding: 0;
    border: 0;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .streaming-table td::before,
  .product-catalog-table td::before,
  .strategy-catalog-table td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .product-catalog-table td:nth-child(1)::before { content: "Product"; }
  .product-catalog-table td:nth-child(2)::before { content: "Use now"; }
  .product-catalog-table td:nth-child(3)::before { content: "Quality"; }
  .product-catalog-table td:nth-child(4)::before { content: "Runtime"; }
  .product-catalog-table td:nth-child(5)::before { content: "OOS"; }
  .product-catalog-table td:nth-child(6)::before { content: "Composition"; }
  .product-catalog-table td:nth-child(7)::before { content: "Action"; }

  .strategy-catalog-table td:nth-child(1)::before { content: "Strategy"; }
  .strategy-catalog-table td:nth-child(2)::before { content: "Entry"; }
  .strategy-catalog-table td:nth-child(3)::before { content: "Live"; }
  .strategy-catalog-table td:nth-child(4)::before { content: "Keys"; }
  .strategy-catalog-table td:nth-child(5)::before { content: "Open"; }
  .strategy-catalog-table td:nth-child(6)::before { content: "P/L"; }
  .strategy-catalog-table td:nth-child(7)::before { content: "Broker"; }
  .strategy-catalog-table td:nth-child(8)::before { content: "Risk"; }
  .strategy-catalog-table td:nth-child(9)::before { content: "Action"; }

  .streaming-table td:nth-child(1)::before { content: "Provider"; }
  .streaming-table td:nth-child(2)::before { content: "Status"; }
  .streaming-table td:nth-child(3)::before { content: "Scope"; }
  .streaming-table td:nth-child(4)::before { content: "Freshness"; }
  .streaming-table td:nth-child(5)::before { content: "Action"; }

  .product-catalog-table .catalog-stack,
  .product-catalog-table .product-metric-grid,
  .product-catalog-table .product-metric-source,
  .strategy-catalog-table span,
  .strategy-catalog-table small {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .product-catalog-table .product-metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .product-catalog-table .product-metric-grid small {
    font-size: 10px;
  }

  .product-action-link,
  .strategy-catalog-table .btn {
    width: 100%;
    max-width: 100%;
    justify-content: center;
  }
}

@media (max-width: 640px) {
  .workspace-node-row {
    grid-template-columns: 1fr !important;
  }

  .workspace-node,
  .workspace-node strong,
  .workspace-node em {
    overflow-wrap: anywhere;
  }

  .workspace-bottom-dock {
    position: static !important;
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    height: auto !important;
    margin: 12px auto 0;
    transform: none !important;
  }

  .workspace-bottom-dock button {
    flex: 1 1 112px;
    min-width: 0;
    white-space: normal;
  }
}

/* Trades + deep analysis: phone-first operator view. */
@media (max-width: 640px) {
  body[data-view="tradesView"] .container,
  body[data-view="strategyDataView"] .container {
    padding-left: 8px;
    padding-right: 8px;
  }

  body[data-view="tradesView"] .panel,
  body[data-view="strategyDataView"] .panel {
    padding: 10px;
    border-radius: 8px;
  }

  body[data-view="tradesView"] .trade-journal {
    gap: 10px;
  }

  body[data-view="tradesView"] .trade-snapshot-meta {
    display: grid;
    gap: 4px;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 11px;
  }

  body[data-view="tradesView"] .trade-section {
    padding: 10px;
    border-radius: 8px;
  }

  body[data-view="tradesView"] .trade-section-head {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 8px;
  }

  body[data-view="tradesView"] .trade-section-head span {
    font-size: 11px;
  }

  body[data-view="tradesView"] .trade-section-head strong {
    font-size: 22px;
    line-height: 1;
  }

  body[data-view="tradesView"] .trade-section-head em {
    padding: 7px 9px;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    background: #f8fafc;
    font-size: 11px;
    line-height: 1.3;
    text-align: left;
  }

  body[data-view="tradesView"] .external-broker-section .trade-section-head em {
    border-color: #fde68a;
    background: #fff7ed;
  }

  body[data-view="tradesView"] .trade-summary-line {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 10px;
  }

  body[data-view="tradesView"] .trade-summary-line span {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    width: 100%;
    white-space: normal;
  }

  body[data-view="tradesView"] .table-wrap.trade-table,
  body[data-view="tradesView"] .table-wrap:has(table.responsive-table) {
    overflow: visible !important;
    border: 0;
    background: transparent;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table,
  body[data-view="tradesView"] .trade-open-table table.responsive-table,
  body[data-view="tradesView"] .external-broker-table table.responsive-table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    font-size: 12px;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table th:first-child,
  body[data-view="tradesView"] .trade-table table.responsive-table td:first-child {
    position: static;
    left: auto;
    z-index: auto;
    min-width: 0;
    box-shadow: none;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table tbody {
    display: grid;
    gap: 10px;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table tr {
    display: grid;
    overflow: hidden;
    border: 1px solid #dbe3ee;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  }

  body[data-view="tradesView"] .trade-table table.responsive-table tr.external-broker-row {
    border-color: #facc15;
    background: #fff7ed;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table td {
    display: grid;
    grid-template-columns: minmax(82px, 0.35fr) minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    min-height: 34px;
    padding: 7px 9px;
    border: 0;
    border-top: 1px solid #eef2f7;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table td:first-child {
    display: block;
    padding: 10px;
    border-top: 0;
    background: #f8fafc;
    text-align: left;
  }

  body[data-view="tradesView"] .external-broker-table table.responsive-table td:first-child {
    background: #fff7ed;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table td:first-child::before {
    display: none;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table td::before {
    content: attr(data-label);
    color: #64748b;
    font-size: 10px;
    font-weight: 950;
    line-height: 1.2;
    text-align: left;
    text-transform: uppercase;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table td > * {
    justify-self: end;
    max-width: 100%;
  }

  body[data-view="tradesView"] .trade-table table.responsive-table td.m-hide {
    display: none;
  }

  body[data-view="tradesView"] .trade-open-table table.responsive-table td:last-child,
  body[data-view="tradesView"] .external-broker-table table.responsive-table td:nth-child(6),
  body[data-view="tradesView"] .risk-position-table table.responsive-table td:last-child {
    display: block;
    padding: 10px;
    text-align: left;
  }

  body[data-view="tradesView"] .trade-open-table table.responsive-table td:last-child::before,
  body[data-view="tradesView"] .external-broker-table table.responsive-table td:nth-child(6)::before,
  body[data-view="tradesView"] .risk-position-table table.responsive-table td:last-child::before {
    display: block;
    margin-bottom: 6px;
  }

  body[data-view="tradesView"] .trade-action-cell,
  body[data-view="tradesView"] .trade-action-cell.compact {
    width: 100%;
    min-width: 0;
    gap: 8px;
  }

  body[data-view="tradesView"] .trade-action-cell .btn,
  body[data-view="tradesView"] .trade-action-cell button {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  body[data-view="tradesView"] .close-fee-preview {
    text-align: left;
  }

  body[data-view="tradesView"] .trade-operation {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
  }

  body[data-view="tradesView"] .trade-operation time {
    grid-column: 2;
    white-space: normal;
  }

  body[data-view="tradesView"] .screen-audit-grid {
    grid-template-columns: 1fr;
  }

  body[data-view="strategyDataView"] .strategy-data-head {
    align-items: stretch;
  }

  body[data-view="strategyDataView"] .strategy-data-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    justify-content: stretch;
  }

  body[data-view="strategyDataView"] .strategy-data-control,
  body[data-view="strategyDataView"] .strategy-data-control.anchor-control,
  body[data-view="strategyDataView"] .strategy-data-control.compact-control,
  body[data-view="strategyDataView"] .strategy-data-control.tiny-control {
    min-width: 0;
    width: 100%;
  }

  body[data-view="strategyDataView"] .strategy-data-control:first-child,
  body[data-view="strategyDataView"] .strategy-data-control.anchor-control,
  body[data-view="strategyDataView"] .segmented,
  body[data-view="strategyDataView"] #strategyDataRefresh {
    grid-column: 1 / -1;
  }

  body[data-view="strategyDataView"] .segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  body[data-view="strategyDataView"] .segmented button {
    min-width: 0;
    min-height: 42px;
  }

  body[data-view="strategyDataView"] #strategyDataRefresh {
    width: 100%;
    min-height: 42px;
  }

  body[data-view="strategyDataView"] .strategy-data-status,
  body[data-view="strategyDataView"] .data-fresh {
    display: block;
    margin: 8px 0;
  }

  body[data-view="strategyDataView"] .strategy-data-grid,
  body[data-view="strategyDataView"] .strategy-data-lower {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  body[data-view="strategyDataView"] .strategy-chart-shell,
  body[data-view="strategyDataView"] .candle-inspector {
    border-radius: 8px;
  }

  body[data-view="strategyDataView"] .chart-topbar,
  body[data-view="strategyDataView"] .chart-toolbar,
  body[data-view="strategyDataView"] .chart-actions,
  body[data-view="strategyDataView"] .strategy-decision-strip {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  body[data-view="strategyDataView"] .chart-legend,
  body[data-view="strategyDataView"] .chart-presets,
  body[data-view="strategyDataView"] .decision-strip-branches {
    justify-content: flex-start;
  }

  body[data-view="strategyDataView"] .chart-range-control {
    grid-template-columns: 42px minmax(0, 1fr) 42px 42px 42px;
    gap: 6px;
  }

  body[data-view="strategyDataView"] .chart-presets {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body[data-view="strategyDataView"] .chart-presets .btn {
    width: 100%;
    min-height: 40px;
  }

  body[data-view="strategyDataView"] #strategyPriceCanvas {
    height: 390px;
  }

  body[data-view="strategyDataView"] #strategyIndicatorCanvas {
    height: 120px;
  }

  body[data-view="strategyDataView"] .strategy-results-panel canvas {
    height: 170px;
  }

  body[data-view="strategyDataView"] .results-stats,
  body[data-view="strategyDataView"] .records-summary,
  body[data-view="strategyDataView"] .inspector-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body[data-view="strategyDataView"] .results-stat,
  body[data-view="strategyDataView"] .record-metric,
  body[data-view="strategyDataView"] .candle-inspector .metric {
    min-width: 0;
    padding: 9px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f8fafc;
  }

  body[data-view="strategyDataView"] .ticker-pnl-table,
  body[data-view="strategyDataView"] .ticker-pnl-table tbody,
  body[data-view="strategyDataView"] .ticker-pnl-table tr {
    display: block;
    width: 100%;
  }

  body[data-view="strategyDataView"] .ticker-pnl-table thead {
    display: none;
  }

  body[data-view="strategyDataView"] .ticker-pnl-table tr {
    margin-bottom: 8px;
    padding: 9px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
  }

  body[data-view="strategyDataView"] .ticker-pnl-table td {
    display: grid;
    grid-template-columns: minmax(78px, 0.35fr) minmax(0, 1fr);
    gap: 8px;
    padding: 5px 0;
    border: 0;
    text-align: right;
  }

  body[data-view="strategyDataView"] .ticker-pnl-table td::before {
    color: #64748b;
    font-size: 10px;
    font-weight: 950;
    text-align: left;
    text-transform: uppercase;
  }

  body[data-view="strategyDataView"] .ticker-pnl-table td:nth-child(1)::before { content: "Монета"; }
  body[data-view="strategyDataView"] .ticker-pnl-table td:nth-child(2)::before { content: "Сделок"; }
  body[data-view="strategyDataView"] .ticker-pnl-table td:nth-child(3)::before { content: "Итог"; }
  body[data-view="strategyDataView"] .ticker-pnl-table td:nth-child(4)::before { content: "Винрейт"; }

  body[data-view="strategyDataView"] .strategy-record-list {
    gap: 10px;
  }

  body[data-view="strategyDataView"] .strategy-record-card,
  body[data-view="strategyDataView"] .observation-card {
    border-radius: 8px;
  }

  body[data-view="strategyDataView"] .record-card-stats,
  body[data-view="strategyDataView"] .trigger-policy,
  body[data-view="strategyDataView"] .anchor-snapshot-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body[data-view="strategyDataView"] .branch-row,
  body[data-view="strategyDataView"] .branch-list.compact .branch-row {
    grid-template-columns: minmax(0, 1fr);
  }

  body[data-view="strategyDataView"] .branch-list.compact .branch-row .branch-name,
  body[data-view="strategyDataView"] .branch-list.compact .branch-row em,
  body[data-view="strategyDataView"] .branch-list.compact .branch-row p,
  body[data-view="strategyDataView"] .branch-list.compact .branch-row span {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 420px) {
  body[data-view="strategyDataView"] .results-stats,
  body[data-view="strategyDataView"] .records-summary,
  body[data-view="strategyDataView"] .record-card-stats,
  body[data-view="strategyDataView"] .trigger-policy,
  body[data-view="strategyDataView"] .anchor-snapshot-grid {
    grid-template-columns: 1fr;
  }
}
