/* InvTrack — мобильная адаптация для обычных пользователей (не модераторка) */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
}

/* Таблицы: горизонтальный скролл вместо ломки вёрстки */
.table-scroll,
.inv-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.table-scroll > table,
.inv-table-scroll > table {
  min-width: 520px;
}

/* Скрыть ссылки/кнопки модераторки на телефоне */
@media (max-width: 860px) {
  .moderator-desktop-only,
  .footer-link--moderator,
  .hub-moderator-only {
    display: none !important;
  }
  /* Справочник/РЦ/статусы в «Работа с RC» — оставляем, но компактно (см. ниже) */

  /* Операционные дашборды (RC / e-bike) — без заглушки «только ПК» */
  body.mod-allow-mobile .mod-desktop-gate {
    display: none !important;
  }
  body.mod-allow-mobile .layout.mod-desktop-restricted.mod-mobile-ok {
    display: block !important;
  }
  body.mod-allow-mobile .sidebar {
    display: none !important;
  }
  body.mod-allow-mobile .content {
    margin: 0 !important;
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 8px !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    border: none !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  body.mod-allow-mobile .content-inner {
    padding: 10px !important;
    border-radius: 12px !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }
  body.mod-allow-mobile {
    padding: 6px !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }
}

@media (max-width: 700px) {
  body:not(.mod-allow-mobile) {
    padding: 12px !important;
  }

  /* base.html */
  .container {
    padding: 16px !important;
    border-radius: 16px !important;
  }
  .user-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }
  .user-info {
    min-width: 0;
  }
  .nav-links {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .nav-links a,
  .logout-btn {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }
  .ebike-productivity-nag-btn--primary,
  .ebike-productivity-nag-btn--secondary {
    min-width: 0 !important;
    width: 100%;
  }
  .nag-actions {
    flex-direction: column !important;
  }

  /* base_public */
  .public-container {
    max-width: 100%;
  }
  .top-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    padding: 12px 14px !important;
  }
  .content {
    padding: 14px !important;
    border-radius: 16px !important;
  }
  body.mod-allow-mobile .content {
    padding: 8px !important;
    border-radius: 0 !important;
  }

  /* forms / inputs: удобный тап */
  select,
  input,
  textarea,
  button {
    font-size: 16px !important; /* iOS zoom fix */
  }
  button,
  .btn,
  .logout-btn,
  .profile-link,
  .app-link {
    min-height: 44px;
  }

  /* Hub */
  .hub-container {
    max-width: 100%;
  }
  .logo-img {
    max-width: 220px !important;
  }
  .profile-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 14px !important;
    padding: 14px !important;
    margin-bottom: 22px !important;
  }
  .profile-actions {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .profile-actions .profile-link,
  .profile-actions .logout-btn {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
    justify-content: center;
    display: inline-flex;
    align-items: center;
  }
  .hub-tools-row {
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
  }
  .hub-tool-tile,
  .hub-kb-card {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    align-self: stretch !important;
  }
  .hub-kb-block,
  .hub-qr-body {
    max-width: 100% !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .hub-qr-btn,
  .hub-kb-open-btn {
    width: 100% !important;
    min-height: 44px;
    justify-content: center;
  }
  .app-card,
  .app-card--manager,
  .app-card--pair {
    padding: 16px !important;
  }
  .app-card--manager .app-icon--svg {
    width: 56px !important;
    height: 56px !important;
  }
  .app-card--manager .app-title {
    font-size: 1.15rem !important;
  }

  /* Roll Cage work */
  .rc-topbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .rc-top-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }
  .rc-top-actions:has(> :only-child) {
    grid-template-columns: 1fr !important;
  }
  .rc-top-actions a {
    display: block;
    min-width: 0;
  }
  .rc-top-actions a,
  .rc-top-actions button {
    width: 100%;
  }
  .rc-top-actions button {
    min-height: 42px;
    padding: 8px 10px !important;
    font-size: 12px !important;
    line-height: 1.25;
    white-space: normal;
  }
  .rc-top-actions button[data-short] {
    font-size: 0 !important;
  }
  .rc-top-actions button[data-short]::after {
    content: attr(data-short);
    font-size: 12px;
    font-weight: 600;
  }
  .rc-layout,
  .rc-layout > *,
  .rc-card,
  .rc-pane,
  .rc-reg-board,
  .rc-action-panel {
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .rc-tabs {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    flex-wrap: unset !important;
    flex-direction: unset !important;
  }
  .rc-tab-btn {
    min-width: 0 !important;
    width: 100% !important;
    min-height: 44px;
    white-space: normal !important;
    text-align: center;
  }
  .rc-tab-btn[data-short] {
    font-size: 0 !important;
  }
  .rc-tab-btn[data-short]::after {
    content: attr(data-short);
    font-size: 12px;
    font-weight: 700;
  }
  #rcWorkFilterRow #pf-col-rcWorkshop {
    flex: 1 1 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .popping-wrapper--wide .popping-dropdown,
  .popping-wrapper--medium .popping-dropdown,
  .popping-wrapper--xwide .popping-dropdown {
    min-width: 0 !important;
    width: min(100vw - 24px, 100%) !important;
    max-width: calc(100vw - 24px) !important;
  }
  .rc-table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .rc-unit-table,
  .rc-mod-table {
    width: max-content;
    min-width: 100%;
  }
  .rc-log-day {
    max-width: 100%;
    overflow: hidden;
  }
  .rc-log-day .rc-table-scroll {
    overflow: visible;
  }
  .rc-log-table {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }
  .rc-log-table tr:not(.rc-log-row) {
    display: none;
  }
  .rc-log-table tbody {
    display: block;
  }
  .rc-log-row {
    display: block;
    margin: 0 0 8px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
  }
  .rc-log-row td {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 8px;
    padding: 4px 0;
    border: none;
    width: 100%;
    word-break: break-word;
    white-space: normal;
  }
  .rc-log-row td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
  }

  /* E-bike dashboard */
  .ebike-dash-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .ebike-dash-stat--total {
    grid-column: 1 / -1;
  }
  .ebike-city-bikes-scroll {
    overflow: visible !important;
    overflow-x: visible !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  .ebike-dash-page {
    padding: 0 !important;
  }

  /* Profile */
  .prof-wrap {
    grid-template-columns: 1fr !important;
  }

  /* Mechanic top recalc */
  .mtr-page-head--single-row {
    flex-wrap: wrap !important;
  }
  .mtr-title {
    font-size: 1.2rem !important;
  }

  /* Knowledge / tickets */
  .hub-kb-list {
    max-width: 100% !important;
  }
  .hub-kb-top,
  .ticket-actions,
  .forum-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  /* Writeoff: don't force wide table scroll when cards are used */
  .writeoff-form-card .table-scroll > table.writeoff-sheet-grid,
  .mtr-table-wrap > table.mtr-table {
    min-width: 0 !important;
  }

  /* Nested page containers (RC work, dashboards) */
  .container .container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
  }
  .rc-dashboard-page,
  .ebike-dash-page {
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Safe area for notched phones */
  body:not(.mod-allow-mobile) {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body.mod-allow-mobile {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

@media (max-width: 420px) {
  .profile-actions .profile-link,
  .profile-actions .logout-btn {
    flex: 1 1 100%;
  }
  .ebike-dash-stats {
    grid-template-columns: 1fr !important;
  }
}

/* Модераторка: на телефоне — заглушка «только ПК» */
.mod-desktop-gate {
  display: none;
}
@media (max-width: 860px) {
  .layout.mod-desktop-restricted {
    display: none !important;
  }
  .mod-desktop-gate {
    display: flex;
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: #fafaf8;
    box-sizing: border-box;
  }
  .mod-desktop-gate__card {
    width: min(100%, 420px);
    background: #fff;
    border: 1px solid #c4a882;
    border-radius: 20px;
    padding: 24px 20px;
    box-shadow: 0 12px 28px rgba(0,0,0,0.08);
    text-align: center;
  }
  .mod-desktop-gate__card h1 {
    font-family: Comfortaa, sans-serif;
    font-size: 1.35rem;
    margin: 0 0 10px;
    color: #2c2c2c;
  }
  .mod-desktop-gate__card p {
    margin: 0 0 18px;
    color: #6b5b4e;
    line-height: 1.45;
    font-size: 14px;
  }
  .mod-desktop-gate__card a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 18px;
    border-radius: 12px;
    background: #2e8b57;
    color: #fff;
    text-decoration: none;
    font-weight: 600;
  }
}
