/* ──────────────────────────────────────────
 * Капсула — universal mobile / tablet adaptation
 * Loaded LAST. Only touches what matters.
 * Goal: no horizontal scroll, clean layout
 *       on any screen 320px → 1280px+.
 * ────────────────────────────────────────── */

/* === 1. Anti horizontal-scroll (global) ============================= */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}
body { -webkit-text-size-adjust: 100%; }

img, video, iframe, canvas, svg, embed, object {
  max-width: 100%;
  height: auto;
}
iframe { display: block; }

/* Long words / URLs / emails wrap instead of pushing layout */
p, li, dd, dt, td, th,
.foot-desc, .lead, .note, .endpoint, .dd-email, .mobile-email {
  overflow-wrap: anywhere;
  word-wrap: break-word;
}

/* Code blocks: scroll inside, never push the page */
pre, .code-body, .flow-diagram, .flow-card {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tbl-card, .tbl-wrap, .pay-table-wrap, .tx-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Min-width safety on flex/grid children — without breaking icon buttons */
main, section, header, footer, .container, .layout, .header-inner, .h-inner,
.row, .grid, [class*="-row"], [class*="-grid"] {
  min-width: 0;
}

/* === 1b. Off-screen layers must stay fixed (cannot occupy flow) ==== */
/* Защита от регрессий: даже если кто-то выставит position:relative,
   мобильное меню и оверлеи остаются вне потока. */
.mobile-menu, #mobile-menu {
  position: fixed !important;
}
.overlay, .mob-overlay, .modal-overlay {
  position: fixed !important;
}

/* На мобиле меню всегда должно быть в DOM (display:flex), но скрыто
   через transform:translateX(-100%). Класс .open даёт translateX(0).
   Некоторые страницы (shops.html и др.) забывают это правило в своём
   @media — поэтому форсим тут. */
@media (max-width: 1024px) {
  .mobile-menu, #mobile-menu {
    display: flex !important;
    flex-direction: column !important;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
  }
  .mobile-menu.open, #mobile-menu.open {
    transform: translateX(0) !important;
  }
}

/* === 2. Cabinet header (sticky, dashboard/shops/etc.) ============== */
/* Tighten the header on tablet+ phone so logo / burger / actions
   don't have giant 32px gaps and the row never overflows. */
@media (max-width: 1024px) {
  .header-inner {
    padding: 0 16px !important;
    gap: 10px !important;
    height: 60px !important;
  }
  .header-inner nav { display: none !important; }
  .header-inner .burger { display: flex !important; }
  .balance-pill { display: none !important; }

  /* Burger sits LEFT, logo next to it, actions on right.
     Keep them all visible inside the header. */
  .burger {
    width: 40px !important;
    height: 40px !important;
    order: -1;
    z-index: 2;
  }
  .header-inner .logo {
    font-size: 18px !important;
    flex: 1 1 auto;
    min-width: 0;
  }
  .header-inner .logo img {
    width: 26px !important;
    height: 26px !important;
  }
  .hright {
    gap: 8px !important;
    flex-shrink: 0;
  }
}
@media (max-width: 480px) {
  .header-inner {
    padding: 0 12px !important;
    gap: 8px !important;
    height: 56px !important;
  }
  .header-inner .logo { font-size: 16px !important; }
  .header-inner .logo img { width: 24px !important; height: 24px !important; }
  .profile-btn { width: 34px !important; height: 34px !important; }
  /* If the page anchored mobile-menu to top:64px in its inline CSS,
     pull it down to match the new shorter header. */
  .mobile-menu { top: 56px !important; }
}
@media (min-width: 481px) and (max-width: 1024px) {
  .mobile-menu { top: 60px !important; }
}

/* === 3. Theme toggle — clean, never inflated by global rules ======= */
/* The page CSS sets `.theme-toggle { width:52px; height:28px }`. Make sure
   no other rule in this file fattens or distorts it. */
.theme-toggle {
  flex-shrink: 0 !important;
  font-size: 0 !important;          /* kills baseline drift inside the knob */
  line-height: 1 !important;
  min-height: 0 !important;          /* override the touch-target rule below */
  padding: 0 !important;
}
.theme-toggle .theme-toggle-knob {
  font-size: 0 !important;
  line-height: 1 !important;
}
.theme-toggle img,
.theme-toggle-knob img {
  display: block !important;
  width: 14px !important;
  height: 14px !important;
  margin: 0 !important;
}
/* Slightly bigger touch target on mobile, keep it clean and centered */
@media (max-width: 1024px) {
  .theme-toggle {
    width: 50px !important;
    height: 28px !important;
    border-radius: 100px !important;
    padding: 0 !important;
  }
  .theme-toggle .theme-toggle-knob {
    width: 22px !important;
    height: 22px !important;
    top: 1px !important;
    left: 1px !important;
    border-radius: 50% !important;
  }
  [data-theme="dark"] .theme-toggle .theme-toggle-knob {
    transform: translateX(22px) !important;
  }
  .theme-toggle img,
  .theme-toggle-knob img {
    width: 13px !important;
    height: 13px !important;
  }
}

/* Burger should also stay its native size — never inflated by global button rule */
.burger {
  min-height: 0 !important;
  font-size: 0 !important;
  padding: 4px !important;
  line-height: 1 !important;
}

/* === 4. Containers — landing/docs/legal ============================ */
@media (max-width: 1024px) {
  .h-inner, .container {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
  .layout { padding: 24px 18px 60px !important; }
}
@media (max-width: 560px) {
  .h-inner, .container {
    padding-left: 16px !important;
    padding-right: 16px !important;
    gap: 12px !important;
  }
  .layout { padding: 18px 14px 50px !important; }
}

/* === 5. Landing page (index.html) ================================== */
@media (max-width: 960px) {
  .hero-mark { width: 380px !important; height: 380px !important; }
  .features-grid { grid-template-columns: 1fr 1fr !important; gap: 16px !important; }
  .feature { padding: 22px !important; }
  .price-card { padding: 36px 24px !important; }
}
@media (max-width: 640px) {
  .hero-mark { width: 280px !important; height: 280px !important; opacity: 0.12 !important; }
  .features-grid { grid-template-columns: 1fr !important; }
  .h-display { font-size: clamp(34px, 9vw, 48px) !important; line-height: 1.1 !important; }
  .h-section { font-size: clamp(26px, 7vw, 34px) !important; }
  .price-amount { font-size: 64px !important; }
  .price-amount sup { font-size: 26px !important; }
  .cta-big { padding: 80px 0 !important; }
  section { padding: 64px 0 !important; }
  .hero { padding-top: 110px !important; padding-bottom: 60px !important; }
  .scroll-hint { display: none !important; }
  .foot-grid { grid-template-columns: 1fr !important; gap: 28px !important; }
  .foot-bottom { flex-direction: column; align-items: flex-start; gap: 8px; text-align: left !important; }
  .code-body { font-size: 11px !important; padding: 16px !important; }
  .hero-bullets { gap: 14px 20px !important; }
}
@media (max-width: 380px) {
  .h-display { font-size: 30px !important; }
  .h-section { font-size: 24px !important; }
  .price-amount { font-size: 56px !important; }
  .btn { padding: 14px 22px !important; font-size: 14px !important; }
}

/* === 6. Docs page ================================================== */
@media (max-width: 1024px) {
  main { min-width: 0 !important; }
  pre { font-size: 12px !important; padding: 14px 16px !important; }
  .endpoint { font-size: 12px !important; word-break: break-all; }
}
@media (max-width: 640px) {
  h1 { font-size: 26px !important; line-height: 1.2 !important; }
  h2 { font-size: 20px !important; margin-top: 36px !important; }
  h3 { font-size: 16px !important; }
  .lead { font-size: 15px !important; }
  main table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  main table th, main table td { padding: 8px 10px !important; font-size: 13px !important; }
  pre { font-size: 11px !important; border-radius: 10px !important; }
  pre .copy-btn { font-size: 10px !important; padding: 4px 7px !important; }
  .flow-diagram { font-size: 10px !important; padding: 14px !important; }
}

/* === 7. Cabinet content (dashboard, shops, transactions, …) ======== */
@media (max-width: 768px) {
  main { padding: 18px 14px !important; }
  .page-head { flex-direction: column; align-items: flex-start !important; gap: 12px !important; }
  .page-head > a, .page-head > button, .page-head .action-btn, .page-head .btn { width: 100% !important; justify-content: center !important; }
  .page-title { font-size: 24px !important; }
  .kpi-grid, .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  .two-col, .shops-grid, .shop-info-grid { grid-template-columns: 1fr !important; }
  .filters {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .filters input, .filters select, .filters .search {
    flex: 1 1 140px !important;
    min-width: 0 !important;
    width: auto !important;
  }
  .tx-table, .pay-table { min-width: 600px; }
  .section-box-head, .full-box-head { padding: 16px 18px !important; }
  .section-box-body { padding: 16px 18px !important; }
}
@media (max-width: 560px) {
  main { padding: 14px 12px !important; }
  .page-title { font-size: 22px !important; }
  .kpi-grid, .stats-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .kpi, .stat-card { padding: 16px 14px !important; }
  .stat-val { font-size: 22px !important; }
  .card, .section-box, .full-box { border-radius: 14px !important; }
  table th, table td { padding: 9px 10px !important; font-size: 12.5px !important; }
  .modal, .test-modal, .modal-content {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 24px) !important;
    overflow-y: auto;
    padding: 22px !important;
  }
  .key-box, .key-actions { flex-wrap: wrap !important; }
  .empty-card { padding: 32px 20px !important; }
}
@media (max-width: 380px) {
  main { padding: 12px 10px !important; }
  .kpi-grid, .stats-grid { grid-template-columns: 1fr !important; }
  .page-title { font-size: 20px !important; }
}

/* === 8. Auth, payment ============================================= */
@media (max-width: 480px) {
  .auth-card, .pay .card {
    width: 100% !important;
    max-width: calc(100vw - 24px) !important;
    margin: 12px auto !important;
  }
}

/* === 9. Admin panel =============================================== */
@media (max-width: 768px) {
  .admin-content, .content { padding: 14px !important; }
  .topbar { padding: 0 14px !important; }
  .tbl-wrap { max-width: 100%; overflow-x: auto; }
  .tbl-wrap table { min-width: 720px; }
  .kpi-row, .stats-row { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .gw-grid { grid-template-columns: 1fr !important; }
  .tabs-wrap { overflow-x: auto; flex-wrap: nowrap !important; }
  .test-modal {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100vh - 16px) !important;
  }
}
@media (max-width: 420px) {
  .kpi-row, .stats-row { grid-template-columns: 1fr !important; }
}

/* === 9b. Profile button — clean white user icon (replaces twemoji) = */
.profile-btn {
  position: relative;
  overflow: hidden;
}
.profile-btn img,
.profile-btn svg {
  display: none !important;
}
.profile-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='8' r='4'/><path d='M4 21v-1a6 6 0 0 1 6-6h4a6 6 0 0 1 6 6v1'/></svg>");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 56% 56%;
  pointer-events: none;
}

/* === 9c. Profile dropdown — always on top, never overflow ========= */
header { z-index: 1000 !important; }              /* шапка над любым контентом */
.profile-wrap { position: relative; z-index: 1001 !important; }
.dropdown { z-index: 1002 !important; }

@media (max-width: 768px) {
  .dropdown {
    position: fixed !important;
    top: 64px !important;
    right: 8px !important;
    left: auto !important;
    min-width: 220px !important;
    max-width: calc(100vw - 16px) !important;
  }
}
@media (max-width: 480px) {
  .dropdown { top: 60px !important; }
}

/* === 10. Inputs (anti iOS auto-zoom) and touch targets ============= */
@media (max-width: 640px) {
  input, select, textarea {
    font-size: 16px !important;
  }
  /* Touch targets — only for real action buttons. Excludes icon toggles. */
  .btn, .h-cta, .h-login,
  .action-btn, .shop-btn, .btn-save, .btn-payout,
  .btn-primary, .btn-ghost, .btn-secondary,
  .mobile-logout, .modal-actions button {
    min-height: 44px;
  }
  /* Compact chips */
  .tag-method, .status-badge, .tx-status, .pay-status,
  .foot-license, .eyebrow, .sb-badge {
    font-size: 11px !important;
  }
}
