/* Mobile-only styles — desktop (769px+) is unchanged */

.mobile-menu-btn,
.mobile-nav-checkbox,
.sidebar-backdrop {
  display: none;
}

@media (min-width: 769px) {
  .header-left {
    display: contents;
  }
}

@media (max-width: 768px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
    -webkit-tap-highlight-color: transparent;
  }

  .screen {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
  }

  #screen-app.screen {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  /* Auth */
  .auth-card {
    margin: 1.25rem auto;
    padding: 1.35rem 1.15rem;
    max-width: calc(100% - 1.5rem);
    border-radius: 14px;
  }

  .auth-card h1 { font-size: 1.45rem; }

  label input,
  label select,
  label textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
    padding: .65rem 1rem;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  /* Header */
  .app-header {
    flex-shrink: 0;
    padding: .55rem .65rem;
    padding-top: max(.55rem, env(safe-area-inset-top));
    gap: .5rem;
    z-index: 200;
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
    flex: 1;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    position: relative;
    z-index: 210;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-menu-btn:active {
    background: var(--border);
  }

  .mobile-menu-icon,
  .mobile-menu-icon::before,
  .mobile-menu-icon::after {
    display: block;
    width: 18px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    position: relative;
  }

  .mobile-menu-icon::before,
  .mobile-menu-icon::after {
    content: '';
    position: absolute;
    left: 0;
  }

  .mobile-menu-icon::before { top: -6px; }
  .mobile-menu-icon::after { top: 6px; }

  .logo {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-right {
    gap: .35rem;
    flex-shrink: 0;
  }

  #user-info {
    display: none;
  }

  .header-right .btn-sm {
    min-height: 40px;
    padding: .4rem .55rem;
    font-size: .75rem;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  body:has(#mobile-nav-toggle:checked) {
    overflow: hidden;
  }

  /* Sidebar drawer */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 1200;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
  }

  body.mobile-nav-open .sidebar-backdrop,
  body:has(#mobile-nav-toggle:checked) #sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .app-body {
    flex: 1;
    min-height: 0;
    height: auto;
    position: relative;
    overflow: hidden;
  }

  #sidebar.sidebar,
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 86vw);
    z-index: 1300;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .45);
    padding-top: max(.5rem, env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
    visibility: visible;
  }

  body.mobile-nav-open #sidebar,
  body:has(#mobile-nav-toggle:checked) #sidebar {
    transform: translateX(0);
  }

  .nav-item {
    padding: .85rem 1.1rem;
    font-size: .95rem;
    min-height: 48px;
  }

  .content {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .85rem .75rem;
    padding-bottom: max(.85rem, env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .pa-proxy-block {
    flex-direction: column;
    align-items: stretch;
  }

  .pa-proxy-input {
    font-size: 16px;
    min-height: 44px;
  }

  /* Page layout */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: .65rem;
    margin-bottom: .85rem;
  }

  .page-header h1 {
    font-size: 1.15rem;
    line-height: 1.3;
  }

  .toolbar {
    width: 100%;
    gap: .45rem;
  }

  .toolbar .btn {
    flex: 1 1 auto;
    min-width: calc(50% - .25rem);
    justify-content: center;
    text-align: center;
  }

  .toolbar .btn:only-child {
    width: 100%;
    flex: 1 1 100%;
  }

  .filters {
    flex-direction: column;
    align-items: stretch;
    gap: .65rem;
  }

  .filters select,
  .filters input,
  .filter-status-wrap select,
  .filters .filter-game-wrap {
    width: 100%;
    min-width: 0;
    max-width: none;
    font-size: 16px;
    min-height: 44px;
  }

  .filter-status-wrap,
  .filters .filter-game-wrap,
  .game-filter-group,
  .rental-filters .rental-filter-field {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .btn-add-order {
    width: 100%;
    min-height: 44px;
  }

  .orders-stat-source-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .segmented-control {
    display: flex;
    width: 100%;
  }

  .segmented-btn {
    flex: 1;
    min-height: 40px;
    text-align: center;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .55rem;
  }

  .stat-grid-orders-public {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: .75rem;
  }

  .stat-card .value {
    font-size: 1.05rem;
  }

  /* Tables */
  .table-wrap {
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  table {
    font-size: .8rem;
  }

  th,
  td {
    padding: .5rem .55rem;
  }

  .actions {
    gap: .4rem;
  }

  .actions .btn {
    min-height: 36px;
  }

  /* Cards board */
  .card-group-block-header {
    flex-direction: column;
    align-items: stretch;
    gap: .55rem;
  }

  .card-group-block-toolbar {
    margin-left: 0;
    width: 100%;
  }

  .card-group-block-toolbar .btn {
    flex: 1;
    min-height: 40px;
  }

  .card-group-block-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
    padding: .65rem .75rem .85rem;
  }

  .bank-card-tile {
    min-height: 88px;
  }

  /* Certificates */
  .cert-stock-grid {
    gap: .45rem;
  }

  .cert-stock-slot {
    width: calc(33.333% - .3rem);
    min-width: 72px;
  }

  .cert-stock-split {
    gap: .75rem;
  }

  /* Modals */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-width: none;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    margin: 0;
  }

  .modal-lg {
    max-width: none;
  }

  .modal-header {
    padding: .85rem 1rem;
  }

  .modal-header h2 {
    font-size: 1rem;
    padding-right: .5rem;
  }

  .modal-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    padding: .75rem 1rem;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
    flex-wrap: wrap;
    justify-content: stretch;
  }

  .modal-footer .btn {
    flex: 1 1 calc(50% - .25rem);
    min-height: 44px;
  }

  .modal .form-row {
    flex-direction: column;
  }

  .modal .form-row label {
    min-width: 0;
    width: 100%;
  }

  .confirm-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .confirm-box {
    width: 100%;
    max-width: none;
    border-radius: 16px 16px 0 0;
    padding: 1.15rem 1rem;
    padding-bottom: max(1.15rem, env(safe-area-inset-bottom));
  }

  .confirm-actions {
    flex-direction: column-reverse;
  }

  .confirm-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  /* Toast */
  .toast {
    left: .75rem;
    right: .75rem;
    bottom: max(1rem, env(safe-area-inset-bottom));
    text-align: center;
  }

  /* Combobox */
  .game-combobox-dropdown {
    max-height: 45vh;
    max-height: 45dvh;
  }

  /* Ozon */
  .ozon-queue-banner {
    font-size: .82rem;
    padding: .65rem .75rem;
  }

  /* Rental */
  .rental-page .rental-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rental-group-table-wrap {
    max-height: calc(100dvh - 12rem);
  }

  .rental-group-block-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: .35rem;
  }

  .rental-group-block .card-group-block-toolbar {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .rental-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: .35rem;
  }

  .rental-game-picker-title {
    font-size: 1.35rem;
  }

  .rental-game-picker-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .rental-game-picker-controls select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: 16px;
  }

  .rental-game-picker-meta {
    flex-wrap: wrap;
  }

  .rental-game-picker-summary {
    margin-left: 0;
    width: 100%;
  }

  .rental-game-picker-table-wrap {
    max-height: 55dvh;
  }

  .rental-date-popover {
    left: .75rem !important;
    right: .75rem !important;
    width: auto;
    min-width: 0;
  }

  .rental-catalog-split {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .rental-catalog-groups-pane {
    max-height: 38dvh;
  }

  .rental-catalog-detail-pane {
    max-height: 42dvh;
  }

  .rental-cat-game-item {
    flex-direction: column;
    align-items: stretch;
  }

  .rental-cat-item-actions {
    justify-content: flex-end;
  }

  .rental-catalog-board {
    max-height: calc(100dvh - 14rem);
  }

  /* Ozon stocks */
  .ozon-stocks-card {
    max-width: none;
    padding: .85rem;
  }

  .ozon-stocks-header {
    flex-direction: column;
    align-items: stretch;
  }

  .ozon-stocks-header .btn {
    width: 100%;
    justify-content: center;
  }

  .ozon-stock-row {
    flex-direction: column;
    align-items: stretch;
    padding: .65rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg2, transparent);
  }

  .ozon-stock-offer,
  .ozon-stock-field-qty {
    width: 100%;
  }

  .ozon-stock-offer,
  .ozon-stock-count {
    min-height: 44px;
    font-size: 16px;
  }

  .ozon-stock-row .ozon-stock-remove {
    width: 100%;
    min-height: 40px;
    margin-bottom: 0;
  }

  .ozon-stocks-actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  /* 2FA */
  .totp-backup-codes-grid {
    grid-template-columns: 1fr;
  }

  .totp-qr {
    width: min(220px, 70vw);
    height: min(220px, 70vw);
  }

  /* P3 */
  .p3-buttons .btn {
    min-width: calc(50% - .25rem);
    min-height: 44px;
  }

  .empty {
    padding: 2rem 1rem;
  }
}

@media (max-width: 380px) {
  .stat-grid,
  .rental-page .rental-stat-grid {
    grid-template-columns: 1fr;
  }

  .card-group-block-cards {
    grid-template-columns: 1fr;
  }

  .cert-stock-slot {
    width: calc(50% - .25rem);
  }
}
