/**
 * Site-wide mobile / touch polish — load after page + design-system CSS.
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.ds-v2,
body {
  overflow-x: clip;
  max-width: 100%;
}

body.ds-v2 .container,
body.ds-v2 .ds-page,
body.ds-v2 main.container {
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
  max-width: 100%;
}

/* Prevent iOS focus zoom on inputs */
body.ds-v2 input:not([type="checkbox"]):not([type="radio"]),
body.ds-v2 select,
body.ds-v2 textarea,
.admin-layout input:not([type="checkbox"]):not([type="radio"]),
.admin-layout select,
.admin-layout textarea {
  font-size: max(16px, 0.94rem);
}

body.ds-v2 .btn,
body.ds-v2 .ds-btn,
.admin-layout .btn,
.lang-switcher-btn,
.sidebar-toggle-btn {
  min-height: 44px;
  touch-action: manipulation;
}

body.ds-v2 img,
body.ds-v2 video {
  max-width: 100%;
  height: auto;
}

/* ─── Public modals ─── */
@media (max-width: 640px) {
  body.ds-v2 .modal-overlay,
  body.ds-v2 .ds-modal {
    align-items: flex-end;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.ds-v2 .modal-box,
  body.ds-v2 .ds-modal-box {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 92vh);
    border-radius: 18px 18px 0 0;
    margin: 0;
  }

  body.ds-v2 .hwid-modal-tabs.ds-tabs--segmented {
    flex-direction: column;
  }

  body.ds-v2 .hwid-modal-tabs .tab-link {
    width: 100%;
    justify-content: center;
  }
}

/* ─── Store ─── */
@media (max-width: 768px) {
  body.ds-sanctum-store .ds-store-hero__grid {
    grid-template-columns: 1fr;
  }

  body.ds-sanctum-store .ds-store-filters-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.35rem;
  }

  body.ds-sanctum-store .store-filters {
    flex-wrap: nowrap;
    width: max-content;
    min-width: 100%;
  }

  body.ds-sanctum-store #store-purchase-view .form-container.card {
    padding: 1rem;
  }

  body.ds-sanctum-store .ds-store-purchase-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  body.ds-sanctum-store .ds-store-purchase-actions .ds-store-action-btn {
    width: 100%;
    justify-content: center;
  }

  body.ds-sanctum-store .ds-store-legal {
    padding: 0.85rem;
  }

  body.ds-sanctum-store .products-grid-deluxe {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body.ds-sanctum-store .purchase-summary img {
    max-width: min(100%, 200px);
    margin-inline: auto;
    display: block;
  }
}

/* ─── Terms ─── */
@media (max-width: 640px) {
  body.ds-v2 main.container[style*="max-width:820px"] {
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px)) !important;
  }

  .terms-toc {
    flex-direction: column;
    align-items: stretch;
  }

  .terms-toc__link {
    text-align: center;
  }

  .terms-installments-block {
    padding: 1rem;
  }

  .terms-installment-live__grid {
    grid-template-columns: 1fr;
  }
}

html[dir="rtl"] .terms-toc {
  align-items: stretch;
}

/* ─── AdminCP ─── */
body.admin-sidebar-open {
  overflow: hidden;
  touch-action: none;
}

body.admin-license-modal-open {
  overflow: hidden;
}

@media (max-width: 992px) {
  .admin-layout {
    min-width: 0;
  }

  .admin-main-container {
    width: 100%;
    min-width: 0;
  }

  .main-content {
    min-width: 0;
    overflow-x: clip;
  }

  #dataContainer {
    min-width: 0;
  }
}

@media (max-width: 768px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .modal-content {
    max-width: 100%;
    width: 100%;
    max-height: min(94dvh, 94vh);
    border-radius: 18px 18px 0 0;
    margin: 0;
  }

  .modal-header {
    padding: 1rem 1.1rem;
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(13, 13, 13, 0.98);
  }

  .modal-body {
    padding: 1rem 1.1rem 1.25rem;
    -webkit-overflow-scrolling: touch;
  }

  .modal-user-info {
    flex-wrap: wrap;
  }

  #modalStatusContainer {
    margin-left: 0;
    width: 100%;
  }

  .license-activity-timeline {
    max-height: none;
  }

  .license-activity-item {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .admin-submodal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .admin-submodal {
    width: 100%;
    max-width: 100%;
    max-height: min(92dvh, 92vh);
    border-radius: 18px 18px 0 0;
    margin: 0;
  }

  .admin-table tbody td {
    grid-template-columns: minmax(88px, 38%) 1fr;
  }

  .table-actions {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .table-actions .btn {
    flex: 1 1 auto;
    min-width: calc(50% - 0.25rem);
  }

  .copy-input-group {
    flex-direction: column;
    align-items: stretch;
  }

  .copy-input-group code {
    white-space: normal;
    word-break: break-all;
    text-overflow: unset;
  }

  .note-editor.note-frame {
    max-width: 100%;
  }

  .note-toolbar {
    flex-wrap: wrap;
  }

  .content-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  #content-header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
  }

  .permissions-editor {
    max-height: min(50vh, 320px);
  }
}

@media (max-width: 768px) {
  .admin-layout .main-header {
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }

  .sidebar-header a {
    font-size: 0.95rem;
  }

  .form-wrapper .form-container {
    padding: 1rem;
  }

  .dashboard-stat-row {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .main-header h2 {
    font-size: 1.05rem;
  }

  .stat-grid .stat-card,
  .stats-grid .stat-card {
    padding: 0.85rem;
  }

  .admin-table tbody td {
    grid-template-columns: 1fr;
  }

  .admin-table tbody td::before {
    margin-bottom: 0.15rem;
  }

  .modal-header h3 {
    font-size: 0.98rem;
  }
}

/* ─── Profile ─── */
@media (max-width: 992px) {
  body.ds-v2 .profile-layout.ds-profile-shell {
    grid-template-columns: 1fr !important;
  }

  body.ds-v2 .ds-profile-sidebar.ds-profile-rail {
    position: static;
    width: 100%;
    max-width: 100%;
  }

  body.ds-v2 .ds-profile-board {
    gap: 1.25rem;
  }

  body.ds-v2 .content-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }
}

/* Horizontal scroll helper for wide tables that stay tabular */
@media (max-width: 768px) {
  .table-container.table-container--scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
