/**
 * Morfi Dashboard — мобильная адаптация
 * Один файл, media queries: 992px, 768px, 480px
 * Не ломаем десктоп, mobile-first где возможно
 */

/* Кнопка открытия сайдбара: на десктопе скрыта */
#mobile-sidebar-toggle,
.mobile-sidebar-toggle-btn {
  display: none !important;
}

/* ========== 992px ========== */
@media (max-width: 992px) {
  .dashboard-main-content {
    padding-left: 15px;
    padding-right: 15px;
  }

  .nav-wrapper .container {
    max-width: 100%;
  }

  /* Декоративные элементы начинаем скрывать */
  .footer-waves svg {
    height: 60px;
  }
}

/* ========== 768px — ключевой брейкпоинт (sidebar, таблицы, шапка) ========== */
@media (max-width: 768px) {
  /* --- Sidebar: offcanvas / slide-menu --- */
  .dashboard-layout {
    position: relative;
  }

  .dashboard-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 280px !important;
    max-width: 85vw !important;
    height: 100vh !important;
    min-height: 100vh !important;
    z-index: 1050 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s ease, visibility 0.3s ease !important;
    visibility: hidden !important;
    overflow-y: auto !important;
    background: linear-gradient(180deg, #16151d 0%, #1e1b24 100%) !important;
    border-right: 1px solid rgba(34, 197, 94, 0.2) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4) !important;
  }

  body.sidebar-open .dashboard-sidebar {
    transform: translateX(0) !important;
    visibility: visible !important;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
    opacity: 1;
  }

  /* Кнопка открытия меню — в шапке (добавляется через JS, стили для неё) */
  #mobile-sidebar-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    margin-right: 8px;
    border: 1px solid rgba(34, 197, 94, 0.3);
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border-radius: 10px;
    font-size: 1.25rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-sidebar-toggle:hover {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
  }

  .dashboard-main-content {
    padding-left: 12px;
    padding-right: 12px;
    margin-left: 0;
  }

  /* --- Таблицы: скрыть второстепенные колонки, раскрытие по tap --- */
  .table-mobile-adapt {
    display: table;
    width: 100%;
  }

  .table-mobile-adapt thead th[data-mobile-priority="detail"],
  .table-mobile-adapt tbody td[data-mobile-priority="detail"] {
    display: none;
  }

  .table-mobile-adapt tbody tr {
    display: table-row;
  }

  .table-mobile-adapt tbody td {
    display: table-cell;
    vertical-align: middle;
  }

  /* Раскрытая строка: детали показываем блоком ниже (flex-wrap) */
  .table-mobile-adapt tbody tr.mobile-expanded {
    display: flex;
    flex-wrap: wrap;
  }

  .table-mobile-adapt tbody tr.mobile-expanded td {
    display: block;
    border-top: none;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .table-mobile-adapt tbody tr.mobile-expanded td[data-mobile-priority="detail"] {
    display: block;
    flex: 1 1 100%;
    padding-left: 1rem;
    font-size: 0.9rem;
    color: #94a3b8;
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  }

  .table-mobile-adapt tbody tr.mobile-expanded td[data-mobile-priority="detail"]:last-child {
    border-bottom: none;
    padding-bottom: 12px;
  }

  .mobile-expand-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 8px 12px;
    margin: -8px -12px;
    color: #22c55e;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-expand-btn .fa-chevron-down {
    transition: transform 0.2s ease;
  }

  .table-mobile-adapt tbody tr.mobile-expanded .mobile-expand-btn .fa-chevron-down {
    transform: rotate(180deg);
  }

  /* --- Модальные окна --- */
  .modal-dialog {
    max-width: 100%;
    margin: 0;
    margin-left: 0;
    margin-right: 0;
  }

  .modal-content {
    border-radius: 12px;
    min-height: 100vh;
    max-height: 100vh;
    overflow-y: auto;
  }

  .modal-body,
  .modal-header,
  .modal-footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* --- Формы: высота полей и кнопок --- */
  .modal .form-control,
  .modal select.form-control,
  .modal .btn,
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  select.form-control {
    min-height: 44px;
  }

  .modal .btn-success.btn-primary-action,
  .modal .btn.btn-primary-action {
    width: 100%;
  }

  /* --- Шапка: язык, профиль, сервер — объединить в один dropdown (уже в guest_panel, просто делаем компактнее) --- */
  #guest_panel .nav-item {
    margin-left: 4px;
    margin-right: 4px;
  }

  .lang-flag-wrap .lang-flag,
  .lang-switcher-toggle .lang-flag {
    width: 16px !important;
    height: 12px !important;
  }

  .lang-option .lang-flag {
    width: 18px !important;
    height: 14px !important;
  }

  /* Dropdown: увеличенная hit-area для клика */
  .dropdown .nav-a,
  .dropdown-toggle,
  [data-auth-toggle="true"],
  [data-custom-dropdown] {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
  }

  /* Декоративные элементы скрыть */
  .footer-waves {
    display: none;
  }

  .dropdown-menu-arrow {
    display: none;
  }
}

/* ========== 480px ========== */
@media (max-width: 480px) {
  .dashboard-sidebar {
    width: 100%;
    max-width: 100%;
  }

  .dashboard-main-content {
    padding-left: 10px;
    padding-right: 10px;
  }

  .container {
    padding-left: 10px;
    padding-right: 10px;
  }

  /* Primary action кнопки на всю ширину */
  .btn-success.btn-primary-action,
  .btn.btn-primary-action,
  #btn-add-role,
  .icon_dropdown .btn-success,
  button[type="submit"].btn-success {
    width: 100%;
  }

  .d-md-flex.justify-content-between .btn {
    width: 100%;
  }

  .modal-dialog {
    margin: 0;
  }

  .modal-content {
    border-radius: 8px;
  }

  /* Минимум текста: уменьшаем второстепенный текст */
  .text-muted.small,
  .bio.small {
    font-size: 0.8rem;
  }
}

/* ========== Общие правила UX (все ширины) ========== */
/* Никаких hover-only: фокус виден */
@media (hover: none) {
  .sidebar-item:hover,
  .table-dark tbody tr:hover {
    /* оставляем только активное состояние по tap */
  }
}

/* Поддержка от 320px */
@media (max-width: 360px) {
  .nav-wrapper .navbar .navbar-brand img,
  .nav-wrapper #nav > a img {
    max-width: 40px;
  }

  #mobile-sidebar-toggle {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }
}
