/* Mobile responsive styles for StrojControl */

/* Tablet (< 1024px) */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed !important;
    z-index: 1000 !important;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 260px !important;
    height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    background: var(--bg-card, #131316) !important;
    border-right: 1px solid var(--border-color, rgba(255,255,255,0.06)) !important;
    overflow-y: auto !important;
  }
  .sidebar.open { transform: translateX(0) !important; }
  .sidebar .nav-item {
    color: var(--text-secondary, #a1a1aa) !important;
    text-decoration: none !important;
  }
  .sidebar .nav-item:hover,
  .sidebar .nav-item.active {
    color: var(--accent-primary, #10b981) !important;
  }
  .sidebar a { text-decoration: none !important; }
  .main-content, .main { margin-left: 0 !important; padding-top: 56px !important; width: 100% !important; }

  .mobile-menu-btn, .hamburger {
    display: block !important;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    background: var(--bg-card, #131316);
    border: 1px solid var(--border-color, rgba(255,255,255,0.06));
    color: var(--text-primary, #fafafa);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
  }
  .mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
  }
  .mobile-overlay.active { display: block; }

  /* Prevent body overflow */
  body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }
  .main-content, main, .content, .main {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Make table containers scrollable horizontally */
  .table-container {
    overflow: visible !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* Fix grid cards on narrow screens */
  .cards-grid {
    grid-template-columns: 1fr !important;
  }

  /* Inputs and filters */
  .filter-bar input, .filter-bar select, .search-input, input[type=search], input[type=text] {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .page-header { flex-direction: column; gap: 12px; }
  .stats-grid, .stat-cards, .stats-row { grid-template-columns: 1fr 1fr !important; }
  table { font-size: 13px; }
  th, td { padding: 8px 6px !important; }
  .modal-content, .modal { width: 95vw !important; max-width: 95vw !important; }
  .filter-bar, .filters { flex-direction: column; }
  .page-header h1, .page-title { font-size: 20px !important; word-break: break-word; }
}

/* Small mobile (< 480px) */
@media (max-width: 480px) {
  .stats-grid, .stat-cards, .stats-row { grid-template-columns: 1fr !important; }
  .page-title { font-size: 18px !important; }
}

/* Desktop - hide mobile elements */
@media (min-width: 1025px) {
  .hamburger { display: none !important; }
  .mobile-menu-btn, .mobile-overlay { display: none !important; }
}

/* =====================================================
   КОМПАКТНЫЕ СТРОКИ ТАБЛИЦ — десктоп
   Перекрывает inline-стили всех страниц через !important
   ===================================================== */
thead th, tbody td { padding: 3px 8px !important; }
thead th:first-child, tbody td:first-child { padding: 2px 1px !important; }
thead th:nth-child(2), tbody td:nth-child(2) { padding: 2px 2px !important; }
tbody td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}
thead th {
  white-space: nowrap;
}

/* =====================================================
   СВОРАЧИВАЕМЫЙ САЙДБАР — десктоп
   ===================================================== */

/* Кнопка toggle */
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: #71717a;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.sidebar-toggle:hover {
  color: #fafafa;
  background: rgba(255,255,255,0.04);
}

/* Текстовые элементы сайдбара (скрываемые при collapse) */
.sidebar-label {
  transition: opacity 0.2s ease, width 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
}

/* Плавная анимация ширины */
.sidebar {
  transition: width 0.25s ease, transform 0.3s ease !important;
}
.main-content {
  transition: margin-left 0.25s ease !important;
}

/* Состояние collapsed — только desktop */
@media (min-width: 1025px) {
  .sidebar.collapsed {
    width: 64px !important;
    overflow: visible;
  }

  .sidebar.collapsed .sidebar-label {
    opacity: 0;
    width: 0;
    pointer-events: none;
  }

  .sidebar.collapsed .sidebar-logo {
    justify-content: center;
    padding: 14px 0 !important;
  }

  .sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0 !important;
    gap: 0;
    position: relative;
  }

  /* Тултип при hover на свёрнутом пункте */
  .sidebar.collapsed .nav-item[data-label]::after {
    content: attr(data-label);
    position: absolute;
    left: 68px;
    top: 50%;
    transform: translateY(-50%);
    background: #1c1c24;
    color: #fafafa;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.1);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 200;
    transition: opacity 0.15s ease;
  }
  .sidebar.collapsed .nav-item[data-label]:hover::after {
    opacity: 1;
  }

  /* Навигация при collapse — центрируем иконки */
  .sidebar.collapsed .sidebar-nav {
    padding: 8px 4px;
  }

  /* Футер при collapse */
  .sidebar.collapsed .sidebar-footer {
    padding: 8px;
    display: flex;
    justify-content: center;
  }
  .sidebar.collapsed .user-info {
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }
  .sidebar.collapsed .btn-logout {
    display: none;
  }
}

/* Скрыть toggle на мобиле (там hamburger) */
@media (max-width: 1024px) {
  .sidebar-toggle {
    display: none !important;
  }
}

/* Fix table overflow on mobile — universal rule */
@media (max-width: 1024px) {
  .table-container, .table-section, .table-responsive, .table-wrapper, .table-scroll {
    overflow: visible !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: calc(100vw - 24px) !important;
    box-sizing: border-box !important;
  }
  table {
    width: 100% !important;
    max-width: none !important;
  }
  /* Allow table to scroll if wider than viewport */
  .table-container > table, .table-section > table,
  .table-responsive > table, .table-wrapper > table {
    display: table;
    overflow: visible;
  }
}

/* Fix panel-body and generic table parents on mobile */
@media (max-width: 1024px) {
  .panel-body, .card-body, [id*="TableContainer"], [id*="tableContainer"] {
    overflow-x: auto \!important;
    -webkit-overflow-scrolling: touch \!important;
    max-width: calc(100vw - 24px) \!important;
  }
}

/* H7: Убрать стрелки (spinners) на числовых полях */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }


/* =====================================================
   МОБИЛЬНЫЕ ФИКСЫ — collapsed sidebar, overlay, тап-зоны
   ===================================================== */
@media (max-width: 1024px) {
  /* Collapsed sidebar на мобиле — полностью скрыт */
  .sidebar.collapsed {
    transform: translateX(-100%) !important;
    pointer-events: none !important;
  }

  /* Открытый sidebar на мобиле — показываем полностью с подписями */
  .sidebar.open,
  .sidebar.collapsed.open {
    transform: translateX(0) !important;
    pointer-events: auto !important;
    width: 260px !important;
  }

  /* Подписи видны когда sidebar открыт на мобиле */
  .sidebar.open .sidebar-label,
  .sidebar.collapsed.open .sidebar-label {
    opacity: 1 !important;
    width: auto !important;
    pointer-events: auto !important;
  }

  /* main-content — убрать inline стили на мобиле */
  .main-content, .main {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* Кнопки действий — увеличить тап-зоны */
  .btn-action-toggle,
  .btn-icon,
  table .btn,
  table button,
  table a.btn {
    min-height: 36px !important;
    min-width: 36px !important;
    padding: 6px 10px !important;
    font-size: 13px !important;
  }

  /* Индикатор горизонтального скролла таблиц */
  .table-container,
  .table-scroll {
    position: relative;
  }
  .table-container::after,
  .table-scroll::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.15));
    pointer-events: none;
    z-index: 1;
  }

  /* Гамбургер — z-index выше sidebar */
  .mobile-menu-btn, .hamburger {
    z-index: 1100 !important;
  }
}

/* Overlay для мобильного меню (универсальный) */
.mobile-overlay, .sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}
.mobile-overlay.active, .sidebar-overlay.active {
  display: block !important;
}
