/* ===== МОБИЛЬНАЯ АДАПТАЦИЯ ===== */

/* Базовые стили (десктоп) */
.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  align-items: center;
  box-sizing: border-box;
}
.filter-group {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.filter-group label {
  display: inline-block;
  margin-right: 4px;
}

/* Верхняя строка: логотип и настройки */
.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  width: 100%;
  box-sizing: border-box;
}
.settings-group {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: nowrap;
}
.filter-logo .logo-wrapper {
  height: 36px;
  display: flex;
  align-items: center;
}
.filter-logo .logo-svg {
  height: 100%;
  width: auto;
}

/* Десктоп: строки-обёртки не влияют, их содержимое встраивается во вторую строку */
@media (min-width: 769px) {
  .filter-row {
    display: contents;
  }
  .top-row {
    width: 100%;
    flex-basis: 100%;
  }
}

/* По умолчанию (десктоп) – кнопка меню скрыта */
.chart-menu-wrapper {
  display: none;
}

@media (max-width: 768px) {
  .filter-form,
  .filter-form * {
    box-sizing: border-box;
  }
  .filter-form {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px;
  }
  .top-row {
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 0;
    margin: 0;
    flex-basis: auto;
  }
  .settings-group {
    gap: 4px;
    margin: 0;
    padding: 0;
  }
  .filter-logo {
    padding: 0;
    margin: 0;
  }
  .settings-group > * {
    margin: 0;
    padding: 0;
  }
  .filter-logo .logo-wrapper {
    height: 38px;
  }
  .filter-group label {
    display: none;
  }
  .icon-btn,
  button,
  .balance-display,
  .dropdown-btn,
  #auth-block input,
  #auth-block button,
  .metric-actions button,
  .export-btn,
  .filter-group.date-field .input-with-icon input {
    height: 38px !important;
    min-height: 38px !important;
    line-height: 1.2;
  }

  /* ========== КАЛЕНДАРЬ (рабочая версия) ========== */
  .filter-group.date-field .input-with-icon {
    position: relative !important;
    display: block !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    height: auto !important;
    width: 100% !important;
  }
  .filter-group.date-field .input-with-icon input {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    padding: 4px 32px 4px 8px !important;
    height: 38px !important;
    line-height: 1.2 !important;
    flex: none !important;
  }
  .filter-group.date-field .input-with-icon .calendar-wrapper {
    position: absolute !important;
    right: 8px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 20px !important;
    height: 20px !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
  }
  .filter-group.date-field .input-with-icon .calendar-wrapper .icon {
    width: 18px !important;
    height: 18px !important;
    background-color: var(--text-color) !important;
  }

  /* Другие элементы */
  #create-campaign-btn,
  #profile-btn,
  #theme-switch {
    width: 38px;
    padding: 0;
  }
  #theme-switch {
    font-size: 0 !important;
    text-indent: -9999px !important;
    overflow: hidden !important;
  }
  #theme-switch .icon {
    font-size: 0;
    text-indent: 0;
    display: inline-block;
    margin: 0 auto;
  }
  .currency-group .dropdown-btn,
  .language-group .dropdown-btn {
    font-size: 12px;
    font-weight: 500;
    width: auto;
    min-width: 50px;
    padding: 0 8px;
  }
  #start-date,
  #end-date {
    width: auto;
    min-width: 100px;
    max-width: 140px;
  }

  /* ========== АДАПТАЦИЯ БЛОКА МЕТРИКИ ========== */
  .metric-panel {
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
  }
  .metric-indicator-block {
    flex: 1 1 auto;
  }
  .roi-summary-inline {
    flex: 1 1 100%;
    margin: 8px 0;
  }
  .metric-actions {
    flex: 0 1 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
  .metric-actions button,
  .metric-actions .export-dropdown {
    width: auto;
    min-width: 40px;
  }
  .summary-columns {
    flex-direction: column;
  }
  .summary-stats,
  .campaign-analysis {
    width: 100%;
  }
  #roi-table {
    font-size: 12px;
  }
  #roi-table th,
  #roi-table td {
    padding: 0.3rem 0.4rem;
  }
  .table-panel {
    overflow-x: auto;
  }
  #roi-table {
    min-width: 600px;
  }
  .report-container {
    flex-direction: column !important;
  }
  .charts-panel,
  .table-panel {
    width: 100%;
  }
  .charts-panel canvas {
    height: 200px;
    max-height: 200px;
  }
  .chart-btn {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .chart-btn .icon {
    width: 16px;
    height: 16px;
  }

  /* ========== СТИЛИ ДЛЯ РЯДОВ ФИЛЬТРОВ ========== */
  .filter-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  .filter-row .filter-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
  }
  .campaign-row .filter-group {
    flex: 0 1 auto;
  }

  /* ========== РАСТЯГИВАНИЕ ЭЛЕМЕНТОВ ВНУТРИ ГРУПП (ДЛЯ РАВНОЙ ШИРИНЫ) ========== */
  .filter-row .filter-group .dropdown-btn,
  .filter-row .filter-group .icon-btn,
  .filter-row .filter-group .balance-display {
    width: 100% !important;
  }
  /* Растягиваем обёртку дропдауна метрики (и любых других дропдаунов в этих строках) */
  .filter-row.actions-row .dropdown,
  .filter-row.finance-row .dropdown {
    width: 100%;
  }

  /* ========== МОБИЛЬНОЕ МЕНЮ ГРАФИКОВ ========== */
  /* Скрываем панель опций под графиком */
  .chart-card .chart-options {
    display: none !important;
  }

  /* Показываем и стилизуем кнопку меню (левая сторона) */
  .chart-menu-wrapper {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 15;
    display: block;
  }

  /* Принудительное выравнивание высоты кнопки меню с кнопками управления */
  .chart-menu-btn {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    padding: 0 !important;
    line-height: 0 !important;
    font-size: 0 !important;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--panel-color);
    box-sizing: border-box !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .chart-menu-btn .icon {
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    display: inline-block;
    background-color: var(--text-color);
  }

  /* Выпадающее меню */
  .chart-menu-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    min-width: 160px;
    background: var(--panel-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    z-index: 20;
    display: none;
    flex-direction: column;
    overflow: hidden;
  }
  .chart-menu-dropdown button {
    padding: 8px 12px;
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
    transition: background 0.2s;
  }
  .chart-menu-dropdown button:hover {
    background: var(--hover-color);
  }
  .chart-menu-dropdown button.active {
    background: var(--active-color);
    color: white;
  }
}

@media (max-width: 480px) {
  .filter-form {
    gap: 4px;
    padding: 8px;
  }
  .filter-group.date-field .input-with-icon input {
    min-width: 85px;
    font-size: 13px;
  }
  .currency-group .dropdown-btn,
  .language-group .dropdown-btn {
    min-width: 44px;
  }
  .charts-panel canvas {
    height: 150px;
  }
  .chart-card .chart-options {
    font-size: 9px;
    margin-right: 70px;
  }
  .chart-btn {
    width: 24px !important;
    height: 24px !important;
  }
  .chart-btn .icon {
    width: 14px;
    height: 14px;
  }
  .top-row {
    gap: 4px;
  }
  .settings-group {
    gap: 4px;
  }
}

@media (min-width: 769px) and (max-width: 1225px) {
  .chart-card .chart-options {
    margin-right: 100px;
  }
  .table-panel {
    overflow-x: auto;
  }
  #roi-table {
    font-size: 12px;
  }
  #roi-table th,
  #roi-table td {
    padding: 0.3rem 0.3rem;
  }
}