/* Desktop-only corrective pass. Mobile layout remains intentionally unchanged. */
.atlas-settings-form-scope {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

/* Literal 4x2 target matrix: empty/switch/empty/switch, then four fields. */
.atlas-journal-settings-page .atlas-settings-target-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.atlas-journal-settings-page .atlas-settings-target-cell,
.atlas-journal-settings-page .atlas-settings-target-item {
  min-width: 0;
}

.atlas-journal-settings-page .atlas-settings-target-cell-empty {
  display: none;
}

.atlas-journal-settings-page .atlas-settings-target-switch {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: flex-start;
}

.atlas-journal-settings-page
  .atlas-settings-target-switch
  .atlas-setting-toggle {
  display: flex;
  width: 100%;
  align-items: center;
  margin: 0;
  padding: 0;
}

.atlas-journal-settings-page
  .atlas-settings-target-switch
  .form-check-input {
  flex: 0 0 auto;
  margin: 0;
}

.atlas-journal-settings-page
  .atlas-settings-target-switch
  .form-check-label {
  margin-left: 10px;
  white-space: nowrap;
}

.atlas-journal-settings-page
  .atlas-settings-target-grid
  .atlas-settings-field {
  grid-template-rows: auto 52px;
  height: auto;
  min-width: 0;
}

.atlas-journal-settings-page
  .atlas-settings-target-grid
  .atlas-settings-field
  > .form-label {
  display: flex;
  min-height: 32px;
  align-items: center;
  margin-bottom: 0;
  padding-bottom: 6px;
}

.atlas-journal-settings-page .atlas-settings-target-help {
  min-height: 0;
  margin: 8px 0 0;
  padding: 0;
}

@media (max-width: 991.98px) {
  .atlas-journal-settings-page .atlas-settings-target-field-final {
    order: 1;
  }

  .atlas-journal-settings-page .atlas-settings-target-switch-tp1 {
    order: 2;
  }

  .atlas-journal-settings-page .atlas-settings-target-field-tp1 {
    order: 3;
  }

  .atlas-journal-settings-page .atlas-settings-target-field-tp1-close {
    order: 4;
  }

  .atlas-journal-settings-page .atlas-settings-target-switch-be {
    order: 5;
  }

  .atlas-journal-settings-page .atlas-settings-target-field-be {
    order: 6;
  }
}

@media (min-width: 992px) {
  /* Keep the journal overview itself on one dense desktop line. */
  .atlas-today-page .atlas-today-journal-card .card-body {
    padding: 10px 12px;
  }

  .atlas-today-page .atlas-today-journal-bar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
  }

  .atlas-today-page .atlas-today-journal-kicker,
  .atlas-today-page .atlas-today-journal-summary > * {
    white-space: nowrap;
  }

  .atlas-today-page .atlas-today-journal-summary {
    grid-template-columns: repeat(4, auto);
    justify-content: space-between;
    gap: 8px 14px;
    margin-top: 0;
    font-size: 0.8rem;
  }

  .atlas-today-page .atlas-today-journal-actions {
    flex-wrap: nowrap;
  }

  .atlas-today-page .atlas-today-journal-actions .btn {
    padding: 0.45rem 0.65rem;
    font-size: 0.84rem;
    white-space: nowrap;
  }

  /* Keep the seven Today counters in one compact desktop row. */
  .atlas-today-page .atlas-today-summary-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
  }

  .atlas-today-page .atlas-today-summary-card {
    min-height: 64px;
    gap: 8px;
    padding: 10px 12px;
  }

  .atlas-today-page .atlas-today-summary-card span {
    font-size: 0.76rem;
    line-height: 1.2;
  }

  .atlas-today-page .atlas-today-summary-card strong {
    flex: 0 0 auto;
    font-size: 1.35rem;
  }

  .atlas-today-page .atlas-today-summary-card-favorite_count {
    grid-column: auto;
    min-height: 64px;
  }

  /* Unified journal shell. */
  .atlas-journal-shell-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
  }

  .atlas-journal-shell-nav .atlas-inline-tab:disabled,
  .atlas-journal-shell-nav .atlas-inline-tab:disabled:hover,
  .atlas-journal-shell-nav .atlas-inline-tab:disabled:active {
    color: #777b72;
    border-color: #34362f;
    background: #20211d;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 1;
    transform: none;
  }

  /* Completed journals are clearly archived without blocking read-only access. */
  .atlas-journal-card-completed {
    background: #292a27 !important;
    border-color: #474942 !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
  }

  .atlas-journals-page .atlas-journal-card .card-body {
    gap: 10px;
    padding: 14px;
  }

  .atlas-journals-page .atlas-journal-metrics > div {
    min-height: 60px;
    padding: 9px 10px;
  }

  .atlas-journals-page .atlas-journal-metrics small {
    display: block;
    margin-top: 2px;
    color: var(--atlas-muted);
    font-size: 0.72rem;
  }

  /* Overview and analytics cards follow content instead of reserving empty height. */
  .atlas-journal-metric-grid {
    --bs-gutter-x: 0.75rem;
    --bs-gutter-y: 0.75rem;
  }

  .atlas-journal-detail-page .atlas-journal-stat .card-body {
    min-height: 76px;
    justify-content: flex-start;
    gap: 3px;
    padding: 10px 12px;
  }

  .atlas-journal-detail-page .atlas-journal-stat strong {
    margin-top: 1px;
    font-size: 1.04rem;
  }

  .atlas-journal-detail-page .atlas-journal-stat small {
    line-height: 1.25;
  }

  .atlas-journal-detail-page .atlas-processing-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .atlas-journal-detail-page .atlas-processing-grid > div,
  .atlas-journal-detail-page .atlas-signal-outcome-card {
    min-height: 0;
    padding: 10px 12px;
  }

  .atlas-journal-detail-page .atlas-signal-outcome-list {
    gap: 8px;
  }

  /* Settings controls use one visual rhythm. */
  .atlas-settings-form-scope {
    min-width: 0;
    margin: 0;
    padding: 0 0 78px;
    border: 0;
  }

  .atlas-journal-settings-page .atlas-settings-section .card-body {
    padding: 14px 16px;
  }

  .atlas-journal-settings-page .form-control,
  .atlas-journal-settings-page .form-select,
  .atlas-journal-settings-page .atlas-settings-static-value {
    min-height: 46px;
    height: 46px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.94rem;
    line-height: 1.4;
  }

  .atlas-journal-settings-page textarea.form-control {
    height: auto;
  }

  .atlas-journal-settings-page .atlas-settings-static-value {
    display: flex;
    align-items: center;
    color: var(--atlas-text-primary);
    background: #20221c;
  }

  .atlas-journal-settings-page .atlas-settings-derived-control:disabled {
    color: #777970;
    background: #1d1f1a;
    border-color: #34362f;
    opacity: 1;
    cursor: not-allowed;
  }

  .atlas-journal-settings-page .atlas-settings-equal-row .atlas-settings-field {
    display: grid;
    grid-template-rows: auto 46px auto;
    align-content: start;
    width: 100%;
  }

  .atlas-journal-settings-page .atlas-settings-equal-row .atlas-settings-field .form-label {
    min-height: 2.45rem;
    margin-bottom: 6px;
    align-items: flex-end;
  }

  .atlas-journal-settings-page .atlas-settings-equal-row .atlas-settings-field .form-text {
    min-height: 0;
    padding-top: 6px;
  }

  .atlas-journal-settings-page .atlas-settings-target-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: 32px auto;
    column-gap: 12px;
    row-gap: 10px;
    align-items: start;
  }

  .atlas-journal-settings-page .atlas-settings-target-cell-empty {
    display: block;
  }

  .atlas-journal-settings-page
    .atlas-settings-target-grid
    .atlas-settings-field {
    grid-template-rows: 32px 46px;
  }

  .atlas-journal-settings-page .atlas-settings-readonly-alert {
    margin-bottom: 12px;
  }

  .atlas-journal-settings-page fieldset:disabled .form-control,
  .atlas-journal-settings-page fieldset:disabled .form-select,
  .atlas-journal-settings-page fieldset:disabled .atlas-settings-static-value {
    color: #aaa99f;
    background: #1d1f1a;
    border-color: #34362f;
    opacity: 1;
  }

  .atlas-journal-settings-page fieldset:disabled .form-check-label,
  .atlas-journal-settings-page fieldset:disabled .form-label,
  .atlas-journal-settings-page fieldset:disabled .form-text {
    color: #85877f !important;
  }

  /* Native desktop dropdowns no longer inherit the old blue palette. */
  select.form-select,
  .form-select {
    color-scheme: dark;
    background-color: #20221c !important;
    border-color: var(--atlas-border) !important;
    color: var(--atlas-text-primary) !important;
  }

  select.form-select option,
  .form-select option {
    color: #e8e7df !important;
    background: #20221c !important;
  }

  select.form-select option:checked,
  select.form-select option:hover,
  .form-select option:checked,
  .form-select option:hover {
    color: #f3f2eb !important;
    background: #4a4f3d !important;
  }

  /* Analytics controls share one compact desktop row. */
  .atlas-journal-detail-page .atlas-analytics-filter-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    align-items: end;
    margin-top: 0.75rem;
  }

  .atlas-journal-detail-page .atlas-analytics-period-control,
  .atlas-journal-detail-page .atlas-analytics-version-control {
    min-width: 0;
  }

  .atlas-journal-detail-page .atlas-analytics-period-control .atlas-journal-filter-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
  }

  .atlas-journal-detail-page .atlas-analytics-filter-grid.is-custom {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  }

  .atlas-journal-detail-page
    .atlas-analytics-filter-grid.is-custom
    .atlas-analytics-period-control
    .atlas-journal-filter-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .atlas-journal-detail-page .atlas-analytics-subnav {
    margin-top: 0.85rem !important;
  }

  .atlas-journal-detail-page .atlas-journal-stat .card-body {
    min-height: 68px;
    padding: 8px 10px;
  }

  /* Three compact journal choices per row. */
  .atlas-comparison-selector-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .atlas-comparison-selector-list label {
    min-width: 0;
    min-height: 76px;
    align-items: flex-start;
    padding: 0.7rem 0.75rem;
  }

  .atlas-comparison-selector-list label > span {
    min-width: 0;
  }

  .atlas-comparison-selector-list label strong,
  .atlas-comparison-selector-list label small {
    overflow-wrap: anywhere;
  }
}

@media (min-width: 992px) {
  /* 1. Пять показателей качества сделок в одной строке. */
  .atlas-today-type-row {
    grid-template-columns: minmax(150px, 0.7fr) minmax(0, 5fr);
    gap: 12px;
  }

  .atlas-today-type-metrics {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
  }

  .atlas-today-type-metrics span {
    min-width: 0;
    gap: 6px;
    padding: 8px 9px;
  }

  .atlas-today-type-metrics small {
    font-size: 0.76rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  /* 2–3. Одинаковая высота фильтров и кнопки сброса. */
  .atlas-signals-page .atlas-signals-filters .form-select,
  .atlas-signals-page .atlas-signals-favorite-filter,
  .atlas-signals-page .atlas-signals-filters > .btn {
    height: 46px;
    min-height: 46px;
  }

  .atlas-signals-page .atlas-signals-filters > .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: 12px;
    white-space: nowrap;
  }

  .atlas-signals-page .atlas-signals-favorite-filter {
    min-width: 0;
    padding-inline: 10px;
  }

  .atlas-signals-page .atlas-signals-favorite-filter .form-check-label {
    white-space: nowrap;
  }

  /* 4. Статус и кнопка избранного одинакового размера. */
  .atlas-signal-modal-toolbar-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(140px, 1fr));
    gap: 8px;
  }

  .atlas-signal-modal-toolbar-actions > .atlas-status-badge,
  .atlas-signal-modal-toolbar-actions > .btn {
    box-sizing: border-box;
    display: inline-flex;
    width: 100%;
    min-width: 0;
    height: 40px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 0.7rem;
    font-size: 0.875rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  /* 5. Четыре поля в строке внутри результата сделки. */
  .atlas-signal-modal-trade-summary .atlas-signal-modal-detail-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .atlas-signal-modal-trade-summary .atlas-signal-modal-fact {
    padding: 0.65rem 0.7rem;
  }

}

/* Шесть фильтров в одной строке на полноценном desktop. */
@media (min-width: 1200px) {
  .atlas-signals-page .atlas-signals-filters {
    grid-template-columns:
      repeat(4, minmax(125px, 1fr))
      minmax(150px, 0.85fr)
      minmax(105px, 0.65fr);
    align-items: stretch;
    gap: 10px;
  }
}
