/* Личный кабинет (/my/*): мобильная вёрстка. */
/* Порядок подключения важен: файл подключается ПОСЛЕДНИМ и перекрывает фиксированные */
/* десктопные размеры (314px / 1046px и т.п.) из 01-12. Всё внутри media-запросов, */
/* поэтому на экранах шире 900px ничего не меняется. */
/* !important использован только там, где его уже ставят прежние правила (отмечено ниже). */

@media (max-width: 900px) {

  /* ===== Общая оболочка кабинета ===== */
  /* Сетка 314px + 1046px превращается в одну колонку: меню сверху, затем заголовок, затем контент. */
  .profile-page {
    width: calc(100% - 32px);
    min-height: 0;
    margin-bottom: 40px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    column-gap: 0;
  }
  .profile-page > * { grid-column: 1; min-width: 0; }
  .profile-sidebar { grid-row: 1; width: 100%; }
  .profile-menu-stack,
  .profile-menu-card { width: 100%; }
  /* Пункты меню ниже (было 62px), чтобы меню не занимало несколько экранов; всё равно >= 44px для пальца. */
  .profile-menu-items > button { height: 48px; min-height: 48px; }
  .profile-page-title {
    grid-row: 2;
    height: auto;
    min-height: 52px;
    margin: 16px 0 8px;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    font-size: 24px;
    line-height: 30px;
  }
  /* Фильтры внутри заголовка (заявки, кампании) были absolute справа и налезали на текст. */
  .profile-page-title .catalog-sort { position: static; width: 100%; min-width: 0; }
  /* Любой основной блок страницы идёт в третью строку и без верхнего отступа 40px. */
  .profile-page > :not(.profile-sidebar):not(.profile-page-title) { grid-row: 3; margin-top: 0; }
  .profile-content,
  .profile-main-stack,
  .profile-main-stack .profile-content-main { width: 100%; max-width: 100%; min-width: 0; }

  /* ===== Профиль (/my/profile, также запасной экран /my/telegram-ads, /my/statistics) ===== */
  .profile-main-stack .profile-content-main,
  .profile-content-main { height: auto; padding: 20px 16px 24px; }
  .profile-id-row { grid-template-columns: minmax(0, 1fr); gap: 16px; }  /* было 479px 479px */
  .profile-id-field { height: auto; }
  .profile-actions { flex-wrap: wrap; }

  /* ===== Баланс (/my/balance) ===== */
  .profile-content-balance,
  .profile-balance-page { width: 100%; max-width: 100%; }
  .profile-balance-page { grid-template-columns: minmax(0, 1fr); }
  .profile-balance-hero,
  .profile-affiliate-card,
  .profile-balance-history { width: 100%; max-width: 100%; }
  /* Две валюты друг под другом вместо двух половин по 523px. */
  .profile-balance-hero { height: auto; grid-template-columns: minmax(0, 1fr); }
  .profile-balance-half { min-height: 96px; }
  .profile-balance-half b { font-size: 36px; line-height: 44px; }
  /* История операций: строка 1 = сумма + дата + время, строка 2 = описание на всю ширину. */
  .profile-history-list { padding: 16px; }
  .profile-history-row { grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 10px; row-gap: 6px; }
  .profile-history-row > span { grid-column: 1; grid-row: 1; }
  .profile-history-row > time:nth-of-type(1) { grid-column: 2; grid-row: 1; justify-self: end; }
  .profile-history-row > time:nth-of-type(2) { grid-column: 3; grid-row: 1; }
  .profile-history-row > b { grid-column: 1 / -1; grid-row: 2; white-space: normal; min-width: 0; overflow-wrap: anywhere; }
  .profile-history-footer { flex-direction: column; align-items: flex-start; gap: 12px; }
  .profile-history-footer nav { flex-wrap: wrap; gap: 8px; }
  .profile-history-footer button { width: 44px; height: 44px; }
  /* Таблица партнёрки (6 колонок, 600px+) прокручивается внутри своей карточки. */
  .profile-affiliate-table { overflow-x: auto; }

  /* ===== Мои каналы (/my/channels) ===== */
  .profile-content-my-channels,
  .my-channels-list { width: 100%; }
  .my-channel-card { width: 100%; max-width: 100%; height: auto; min-height: 0; }
  /* Шапка карточки: аватар | название+статус | стрелка, ниже кнопка действия на всю ширину. */
  .my-channel-summary {
    width: 100%;
    height: auto;
    min-height: 84px;
    padding: 12px;
    grid-template-columns: 52px minmax(0, 1fr) 44px;
    grid-template-areas: "avatar info chevron" "actions actions actions";
    column-gap: 12px;
    row-gap: 10px;
  }
  .my-channel-avatar { grid-area: avatar; width: 52px; height: 52px; }
  .my-channel-info { grid-area: info; width: auto; min-width: 0; height: auto; flex-direction: column; align-items: flex-start; gap: 8px; }
  .my-channel-text { width: auto; max-width: 100%; min-width: 0; height: auto; }
  .my-channel-text strong { white-space: normal; text-align: left; overflow-wrap: anywhere; }
  .my-channel-status { flex: 0 0 auto; width: auto; min-width: 120px; height: 36px; padding: 0 12px; }
  .my-channel-actions { grid-area: actions; width: 100%; height: auto; }
  .my-channel-action,
  .my-channel-action.publish,
  .my-channel-action.pause { width: 100%; height: 44px; }
  .my-channel-chevron { grid-area: chevron; width: 44px; height: 44px; }
  /* Раскрытие: прежний max-height 84px/1800px не подходит (контент выше), поэтому
     закрытая карточка просто скрывает настройки, открытая растёт по содержимому.
     Анимация высоты на мобильном отключена. */
  .my-channel-card:not(.open) { max-height: none; border-radius: 24px; }
  .my-channel-card:not(.open) .my-channel-settings { display: none; }
  .my-channel-card.open { max-height: none !important; border-radius: 24px; }  /* !important: прежнее правило 1800px !important в 08 */
  .my-channel-settings,
  .my-channel-settings-body,
  .my-channel-divider { width: 100%; min-width: 0; }
  .my-channel-card.open .my-channel-settings-body { padding: 16px !important; }  /* !important: в 08 padding 24px !important */
  .my-channel-card.open .settings-line { width: calc(100% + 32px); margin-left: -16px; margin-right: -16px; }
  .my-channel-card.open .settings-delete-line { width: calc(100% + 32px) !important; margin: 20px -16px 0 !important; }  /* !important: в 08 то же правило с !important */
  /* Поля настроек: все сетки в одну колонку. */
  .settings-row.top,
  .settings-row.description,
  .settings-commerce,
  .settings-bottom-row { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .my-channel-card .settings-bottom-row { grid-template-columns: minmax(0, 1fr) !important; column-gap: 16px !important; row-gap: 16px; }  /* !important: в 08 колонки 520px max-content с !important */
  .my-channel-card .settings-flags { width: 100% !important; min-width: 0 !important; }  /* !important: в 08 width/min-width 520px с !important */
  .settings-row.description .settings-field.wide,
  .settings-row.description .settings-field.cover { width: 100%; }
  .settings-ad-availability,
  .settings-flags,
  .settings-normal,
  .settings-hot { width: 100%; min-width: 0; }
  .settings-flags { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; }
  .settings-flags label.settings-check { width: 100%; max-width: 100%; min-height: 30px; align-items: center; }
  .my-channel-card .settings-flags label.settings-check.settings-auto-calc { height: auto; min-height: 20px; }  /* длинная подпись переносится на 2-3 строки */
  .settings-auto-label { white-space: normal; min-width: 0; flex: 1 1 0; }
  .settings-caution-actions { width: 100%; flex-wrap: wrap; }
  .settings-caution-actions button { width: 100%; }
  .settings-channel-actions,
  .my-channel-card .settings-channel-actions { width: 100% !important; grid-template-columns: minmax(0, 1fr); }  /* !important: в 08 width: max-content !important */
  .settings-channel-actions button,
  .my-channel-card .settings-channel-actions button { width: 100%; white-space: normal; margin-left: 0; }
  .my-channel-settings-footer { flex-wrap: wrap; }
  /* Условия размещения: типы и цены помещаются в 311px. */
  .my-condition { grid-template-columns: 92px minmax(0, 1fr) minmax(0, 1fr); }
  .hot-condition-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hot-condition-row > .hot-row-button { grid-column: 1 / -1; width: 100%; }
  /* Дни недели и временные слоты. */
  .ad-week-days { flex-wrap: wrap; }
  .ad-week-day { width: auto; flex: 1 1 0; min-width: 36px; height: 44px; }
  .ad-time-slot-row { grid-template-columns: 44px minmax(0, 1fr) 44px 44px; gap: 6px; }
  .ad-time-slot-row > *,
  .ad-time-slot-picker,
  .ad-time-slot-toggle { width: 100%; min-width: 0; }

  /* ===== Заявки (/my/requests) и Моя реклама (/my/ads): карточки безопасных сделок ===== */
  .safe-deal-order-card { max-width: 100%; }
  .buyer-campaign-card.safe-deal-order-card .buyer-campaign-summary { grid-template-columns: 52px minmax(0, 1fr) 44px; }
  .safe-deal-order-card .buyer-campaign-info { height: auto; min-height: 52px; margin-left: 0; align-self: center; }
  .safe-deal-order-card .buyer-campaign-text { height: auto; flex-wrap: wrap; gap: 8px; }  /* сумма и статус переносятся */
  .safe-deal-order-card .safe-deal-order-final-status-chip { margin-left: 0; }
  .safe-deal-order-card .buyer-campaign-actions > .safe-deal-order-id-copy { transform: none; }
  .safe-deal-order-body { padding: 16px; }
  .safe-deal-order-body > .safe-deal-order-content-divider { width: calc(100% + 32px); margin-left: -16px; margin-right: -16px; }
  .safe-deal-order-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }  /* было 1fr 450px */
  .safe-deal-order-timeline { grid-template-columns: minmax(0, 1fr); }
  .safe-deal-order-stage .safe-deal-order-stage-content > p,
  .safe-deal-order-stage.is-current .safe-deal-order-stage-content > p,
  .safe-deal-order-stage.is-placement-completed .safe-deal-order-stage-content > p { white-space: normal; }
  .safe-deal-order-stage-row { flex-wrap: wrap; width: auto; }
  .safe-deal-order-preview-anchor { width: 100%; min-height: 0; align-items: stretch; }
  .safe-deal-order-preview-anchor > .buyer-creative-post-preview,
  .safe-deal-order-preview-counterparty { width: 100%; max-width: 100%; }
  .safe-deal-order-preview-status-row { width: 100%; max-width: 100%; height: auto; flex-wrap: wrap; }
  .safe-deal-order-placement-info { width: 100%; flex-wrap: wrap; }
  .safe-deal-order-counterparty-row-primary,
  .safe-deal-order-counterparty-row-stats { flex-wrap: wrap; }
  .safe-deal-order-card.open { max-height: none !important; }  /* !important: в 12 max-height 1800px !important */

  /* ===== Мои кампании (/my/campaigns) ===== */
  .profile-content-buyer-campaigns,
  .buyer-campaigns-list { width: 100%; }
  .buyer-campaign-card.expandable-card-primitive { width: 100%; max-width: 100%; height: auto; min-height: 0; }
  .buyer-campaign-card.expandable-card-primitive:not(.open) { max-height: none; border-radius: 24px; }
  .buyer-campaign-card.expandable-card-primitive:not(.open) .expandable-card-settings { display: none; }
  .buyer-campaign-card.expandable-card-primitive.open { border-radius: 24px; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-summary { height: auto; min-height: 84px; padding: 12px; grid-template-columns: 52px minmax(0, 1fr) 44px; gap: 10px; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-avatar { width: 52px; height: 52px; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-info { min-height: 0; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-text { max-width: 100%; height: auto; min-height: 24px; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-text strong { white-space: normal; overflow-wrap: anywhere; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-actions { grid-column: 1 / -1; grid-row: 2; width: 100%; min-width: 0; height: auto; justify-content: flex-start; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-actions:empty { display: none; }
  .buyer-campaign-card.expandable-card-primitive .expandable-card-chevron { grid-column: 3; grid-row: 1; width: 44px; height: 44px; margin: 0; align-self: center; }
  .buyer-campaign-card.expandable-card-primitive .buyer-campaign-creative-body { padding: 16px; }
  /* Зоны «добавить/импортировать креатив» и карусель: одна колонка, карусель листается внутри себя. */
  .buyer-campaign-card.buyer-campaign-expandable .buyer-campaign-creative-workspace { grid-template-columns: minmax(0, 1fr); row-gap: 20px; }
  .buyer-campaign-card.buyer-campaign-expandable .buyer-campaign-creative-zones { grid-column: 1; flex-direction: row; flex-wrap: wrap; }
  .buyer-campaign-card.buyer-campaign-expandable .buyer-company-carousel { grid-column: 1; overflow-x: auto; }
  .buyer-campaign-card .buyer-creative-action-zone { width: 100%; max-width: none; min-height: 96px; height: 96px; }
  .buyer-campaign-card.buyer-campaign-expandable .buyer-campaign-editor-divider,
  .buyer-campaign-card.buyer-campaign-expandable .buyer-campaign-actions-divider { width: calc(100% + 32px); margin-left: -16px; margin-right: -16px; }
  .buyer-campaign-card.buyer-campaign-expandable .buyer-campaign-expanded-actions { justify-content: flex-start; }

  /* ===== Пользователи (/my/users) и Администраторы (/my/administrators) ===== */
  .profile-users-layout { width: 100%; grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .profile-users-list,
  .profile-users-sidebar { width: 100%; min-width: 0; }
  .profile-users-sidebar { order: -1; }  /* поиск и статистика над списком */
  .profile-user-card { width: 100%; max-height: none; border-radius: 24px; }
  .profile-user-card.open { max-height: none; }
  .profile-user-card.open .profile-user-content { height: auto; }
  /* Шапка: аватар + имя + стрелка в первой строке, чипы (username, id) во второй. */
  .profile-user-head { height: auto; min-height: 84px; flex-wrap: wrap; row-gap: 8px; padding: 12px 0 12px 12px; }
  .profile-user-name { flex: 1 1 calc(100% - 150px); max-width: none; }
  .profile-user-toggle.my-channel-chevron { order: 1; flex: 0 0 52px; width: 52px; height: 52px; margin-top: 0; margin-bottom: 0; }
  .profile-user-chip,
  .profile-user-go,
  .profile-user-name + .profile-user-chip { order: 2; margin-left: 0; margin-right: 5px; }
  .profile-user-settings,
  .profile-user-balance { margin-left: 16px; margin-right: 16px; }
  .profile-user-balance-current { flex-direction: column; align-items: stretch; gap: 8px; }
  .profile-user-balance-current span { height: auto; min-height: 34px; white-space: nowrap; }
  .profile-user-balance-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }  /* было 6 колонок */
  .profile-user-referral { grid-template-columns: minmax(0, 1fr) auto; }
  .profile-user-balance-actions button,
  .profile-user-referral button { min-height: 44px; }

  /* ===== Модерация (/my/moderation) ===== */
  .profile-content-moderation { width: 100%; min-height: 0; }
  .moderation-layout { width: 100%; grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .moderation-sidebar { order: -1; width: 100%; }
  .moderation-list { min-width: 0; }
  .moderation-side-card,
  .moderation-search,
  .moderation-stat { width: 100%; box-sizing: border-box; }
  /* Карточка заявки: превью и детали друг под другом (было 338px + 286px, высота 645px). */
  .moderation-card { width: 100%; height: auto; padding: 16px; grid-template-columns: minmax(0, 1fr); grid-template-rows: none; row-gap: 16px; }
  .moderation-preview { width: 100%; max-width: 338px; height: auto; max-height: 489px; margin: 0 auto; }
  .moderation-details { width: 100%; min-width: 0; }
  .moderation-field textarea { width: 100%; box-sizing: border-box; }
  .moderation-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto; }
  .moderation-actions .moderation-reason-selector { grid-column: 1 / -1; grid-row: auto; width: 100%; }
  .moderation-reason-selector { width: 100%; }

  /* ===== Настройки каталога (/my/settings) ===== */
  .profile-content-catalog-settings { width: 100%; }
  .catalog-settings-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }  /* было 515px 515px */
  .catalog-settings-right { min-width: 0; }
  .catalog-settings-block { width: 100%; min-width: 0; box-sizing: border-box; padding: 16px; }
  .catalog-settings-block h2 { font-size: 20px; line-height: 26px; margin-bottom: 16px; }
  .catalog-settings-row { width: 100%; min-width: 0; }
  .catalog-settings-chip,
  .catalog-settings-edit-input { flex: 1 1 auto; max-width: none; }
  .catalog-settings-edit,
  .catalog-settings-delete { margin-left: 8px; width: 36px; height: 36px; }
}

/* ===== Совсем узкие телефоны ===== */
@media (max-width: 480px) {
  .profile-page { width: calc(100% - 24px); }
  .profile-page-title { font-size: 22px; line-height: 28px; }
  .profile-balance-half b { font-size: 30px; line-height: 38px; }
  .profile-history-row > time { font-size: 14px; }
  .my-channel-card.open .my-channel-settings-body { padding: 12px !important; }  /* !important: перекрывает 08 */
  .safe-deal-order-body { padding: 12px; }
}
