/* ──────────────────────────────────────────────────────────────────────────
 * cabinet-responsive.css — mobile/tablet adaptation layer.
 *
 * Loaded LAST (after kit.css, auth.css, pages.css, overrides.css) so its
 * media-query rules win.  Touches the skeleton class names plus the
 * inline-styled blocks used by newer client components (sessions panel,
 * devices QR-modal, trial-device QR layout, onboarding plan picker, etc.)
 * ────────────────────────────────────────────────────────────────────────── */


/* ════════════════ Global safety: prevent horizontal overflow ════════════════ */
html, body { max-width: 100vw; overflow-x: hidden; }
img, svg, video, iframe { max-width: 100%; height: auto; }
.main, .cabinet, .au-page, .rl-main, .ts-main, .ct-main, .tro-main { max-width: 100vw; overflow-x: hidden; }


/* ════════════════ Tablet ≤ 1024px ════════════════ */
@media (max-width: 1024px) {
  /* Hero typography softens */
  .card-obsidian-active h1,
  .card-obsidian h1,
  .hero-short h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.08; }
  .card-obsidian-active p,
  .card-obsidian p { font-size: 14px; }

  /* Top action rows wrap */
  .h-actions { flex-wrap: wrap; gap: 10px; }
  .h-actions .btn { flex: 1 1 auto; justify-content: center; min-width: 200px; }

  /* Trial-device 2-column QR layout — collapse to single col */
  .au-page,
  .cabinet { /* no-op anchor */ }
}


/* ════════════════ Sidebar drawer ≤ 960px ════════════════ */
@media (max-width: 960px) {
  .cabinet {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
  }
  .main {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: auto;
    touch-action: pan-y;
  }

  /* Skeleton hides sidebar by default — bring it back as a slide-in drawer
     when CabinetShell adds the `is-open` class via the burger. */
  .sidebar {
    display: flex !important;
    position: fixed !important;
    top: 0; left: 0; bottom: 0;
    width: min(280px, 86vw);
    height: 100vh;
    z-index: 100;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 0 12px 80px rgba(0,0,0,0.55);
    pointer-events: none;
    visibility: hidden;
  }
  .sidebar.is-open {
    transform: translateX(0);
    pointer-events: auto;
    visibility: visible;
  }

  /* Topbar adjustments */
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding-bottom: 16px;
    margin-bottom: 18px;
  }
  .topbar .crumbs { font-size: 10px; flex: 1; min-width: 0; }
  .topbar .pill { font-size: 10px; padding: 4px 8px; }
}


/* ════════════════ Phone ≤ 720px ════════════════ */
@media (max-width: 720px) {
  .main { padding: 16px 14px 64px; }

  /* The decorative glowing hero-mark orb overlaps heading text on narrow
     screens — hide the purely-decorative ornaments (hero-wrap, trial-
     onboarding welcome). Keeps meaningful UI like brand mark, check
     indicator on trial/success, etc. */
  .hero-wrap > .hero-mark,
  .tro-mark { display: none !important; }
  .hero-wrap { padding-left: 0 !important; }

  /* Hero card softens further */
  .hero-wrap { margin-bottom: 16px; }
  .card-obsidian-active,
  .hero-short { padding: 22px 20px !important; border-radius: 18px; }
  .card-obsidian-active h1,
  .hero-short h1 { font-size: clamp(24px, 6vw, 32px); }
  .h-meta { gap: 8px; flex-wrap: wrap; }
  .h-meta .pill,
  .h-meta .eyebrow { font-size: 10px; padding: 3px 8px; }

  /* Common 2-col → 1-col */
  .grid-2,
  .stat-strip,
  .bento,
  .co-grid,
  .rf-top,
  .rn-grid,
  .tdp-grid { grid-template-columns: 1fr !important; }

  /* Devices grid */
  .dv-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .dv-bar { flex-direction: column; gap: 10px; }
  .dv-bar .dv-search-wrap { width: 100%; }
  .dv-filters { flex-wrap: wrap; gap: 6px; }
  .dv-card { padding: 16px; }
  .dv-card-head { flex-wrap: wrap; gap: 10px; }
  .dv-card-actions {
    grid-template-columns: minmax(0, 1fr) 44px 44px;
    align-items: stretch;
    gap: 8px;
  }
  .dv-card-actions .dv-action-btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .dv-card-actions .dv-action-icon-btn {
    width: 44px;
    height: 44px;
    justify-self: end;
  }

  /* Renew panel */
  .rn-status {
    gap: 12px;
    padding: 16px;
    border-radius: 20px;
  }
  .rn-status-card__top { align-items: flex-start; flex-wrap: wrap; }
  .rn-status-card__main { grid-template-columns: 1fr; gap: 14px; }
  .rn-status-card__copy h2 {
    gap: 5px;
    font-size: clamp(1.38rem, 6.4vw, 1.82rem);
    line-height: 1.08;
    overflow-wrap: anywhere;
  }
  .rn-status-card__copy h2 .rn-status-date { font-size: 0.62em; }
  .rn-status-card__copy p { font-size: 13px; line-height: 1.45; }
  .rn-status-meter {
    grid-template-columns: auto minmax(0, 1fr);
    align-self: stretch;
    border-radius: 18px;
    padding: 10px;
  }
  .rn-status-dial { width: 58px; height: 58px; }
  .rn-status-meter__note b { font-size: 1.1rem; }
  .rn-status-card__foot {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 8px 12px;
    font-size: 9px;
    line-height: 1.45;
  }
  .rn-status-card__foot span:nth-child(2) { display: none; }
  .rn-plans { grid-template-columns: 1fr !important; gap: 10px; }
  .rn-plan { padding: 14px 16px; }
  .rn-periods { grid-template-columns: 1fr !important; gap: 10px; }
  .rn-sum { padding: 18px; }

  /* Checkout */
  .co-main { padding: 0 0 42px; }
  .co-head {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 20px 16px;
    border-radius: 20px;
    margin-bottom: 12px;
  }
  .co-kicker {
    margin-bottom: 11px;
    font-size: 9px;
    letter-spacing: 0.18em;
  }
  .co-head h1 {
    font-size: clamp(1.65rem, 9vw, 2.05rem);
    line-height: 1.02;
    overflow-wrap: anywhere;
  }
  .co-head p { font-size: 13px; line-height: 1.45; }
  .co-head-meta { justify-content: flex-start; max-width: none; gap: 6px; }
  .co-head-meta span {
    min-height: 28px;
    padding: 6px 9px;
    font-size: 9px;
  }
  .co-ref-status {
    width: 100%;
    font-size: 11px;
  }
  .co-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .co-flow { gap: 12px; }
  .co-sum {
    order: -1;
    position: relative;
    top: auto;
    padding: 18px;
    border-radius: 20px;
  }
  .co-sum h2 { font-size: 1.2rem; margin-bottom: 14px; }
  .co-sum-row { font-size: 13px; gap: 12px; }
  .co-sum-total {
    margin: 14px 0;
    padding: 14px;
    border-radius: 16px;
  }
  .co-sum-total .v { font-size: 1.85rem; }
  .co-pay-btn { min-height: 52px; font-size: 14px; border-radius: 14px; }
  .co-step {
    padding: 16px;
    border-radius: 18px;
  }
  .co-step-head {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    align-items: start;
    gap: 8px 10px;
    margin-bottom: 14px;
  }
  .co-step-num { width: 32px; height: 32px; border-radius: 11px; }
  .co-step h2 { min-width: 0; line-height: 1.1; font-size: 1.18rem; }
  .co-step .sub {
    grid-column: 2;
    margin-left: 0;
    min-width: 0;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }
  .co-plan-mini {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    padding: 14px;
    border-radius: 15px;
  }
  .co-plan-mini .text { min-width: 0; gap: 3px; }
  .co-plan-mini .name { font-size: 1rem; line-height: 1.12; overflow-wrap: anywhere; }
  .co-plan-mini .meta { font-size: 12px; }
  .co-plan-mini .change { grid-column: 2; justify-self: start; margin-top: 2px; }
  .co-methods { grid-template-columns: 1fr; gap: 8px; }
  .co-method {
    min-height: 68px;
    display: flex;
    text-align: center;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
  }
  .co-method .name { font-size: 0.98rem; }
  .co-method .meta { font-size: 8px; }
  .co-checkbox input { width: 18px; height: 18px; }

  /* Trial onboarding */
  .tro-card { padding: 26px 22px; }
  .tro-h1 { font-size: clamp(26px, 6vw, 32px); }
  .tro-highlights { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tro-cta { padding: 16px 18px !important; font-size: 14px; }
  .tro-meta { flex-direction: column; align-items: flex-start; gap: 6px; }

  /* Trial device picker (the platform tiles) */
  .td-grid { grid-template-columns: 1fr 1fr !important; }
  .td-platform { padding: 16px; }

  /* Trial success */
  .ts-card { padding: 26px 22px; }
  .ts-h1 { font-size: clamp(24px, 6vw, 32px); }
  .ts-info { grid-template-columns: 1fr 1fr; }
  .ts-actions { flex-direction: column; gap: 10px; }
  .ts-actions .ts-btn { width: 100%; text-align: center; }

  /* Members + Referral + Help cards */
  .mem-list .row, .mem-row { flex-wrap: wrap; gap: 10px; }
  .hp-qcards { grid-template-columns: 1fr !important; }

  /* Settings */
  .st-grid { grid-template-columns: 1fr !important; gap: 16px; }
  .st-side {
    position: static !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  .st-side a { white-space: nowrap; padding: 8px 12px; font-size: 12px; }
  .st-panel { padding: 20px 18px; }
  .st-form-head { flex-direction: column; align-items: flex-start; }
  .st-row { flex-wrap: wrap; gap: 10px; padding: 12px 0; }
  .st-row .ctrl { width: 100%; justify-content: flex-start; }
  .st-row > .text { width: 100%; }

  /* Auth / public pages */
  .au-form-wrap { padding: 24px 18px !important; }
  .au-title { font-size: clamp(28px, 7vw, 38px) !important; line-height: 1.05 !important; }
  .au-otp { gap: 6px; }
  .au-otp input { width: 40px !important; height: 48px !important; font-size: 20px !important; }
  .au-btn { padding: 14px 18px; font-size: 14px; }
  :is(
    .btn-primary,
    .co-pay-btn,
    .rn-pay-btn,
    .au-btn--primary,
    .sc-btn--primary,
    .ts-btn--primary,
    .pf-btn--primary,
    .tro-cta,
    .rl-cta,
    .tdp-cta-bottom .btn
  ) {
    min-height: 56px;
    border-radius: 16px;
    font-size: 15px;
    font-weight: 800;
    text-shadow: none;
  }

  /* Ref/invite recipient landings */
  .rl-main { padding: 20px 14px 40px; }
  .rl-card { padding: 24px 20px; border-radius: 18px; }
  .rl-h1 { font-size: clamp(24px, 6vw, 32px) !important; }
  .rl-bonus-box { grid-template-columns: 1fr !important; gap: 8px; padding: 12px 14px; }
  .rl-meta { flex-direction: column; gap: 4px; align-items: flex-start; }

  /* Connect Telegram page */
  .ct-card { padding: 26px 22px; }
  .ct-h1 { font-size: clamp(24px, 6vw, 32px); }
  .ct-code-box { padding: 14px 16px; }
  .ct-code-box .code { font-size: 18px !important; word-break: break-all; }

  /* Billing table */
  .bl-summary { grid-template-columns: 1fr 1fr !important; gap: 8px; }
  .bl-stat { padding: 16px 14px 14px; }
  .bl-bar {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 10px;
  }
  .bl-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .bl-tab { flex: 0 0 auto; }
  .bl-period { justify-self: start; flex-wrap: wrap; }
  .bl-tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .bl-tbl { min-width: 680px; font-size: 12px; }
  .bl-tbl th, .bl-tbl td { padding: 8px 6px; }

  /* QR / generic modal */
  .qr-modal { padding: 16px !important; }
  .qr-modal__inner { padding: 22px 18px !important; }
}


/* ════════════════ Small phone ≤ 480px ════════════════ */
@media (max-width: 480px) {
  /* Tighten more */
  .main { padding: 12px 12px 56px; }

  .hero-wrap { margin-bottom: 12px; }
  .card-obsidian-active,
  .hero-short { padding: 18px 16px !important; }
  .card-obsidian-active h1,
  .hero-short h1 { font-size: 22px; }
  .card-obsidian-active p,
  .hero-short p { font-size: 13px; }

  /* Trial device tiles single column on tiny phones */
  .td-grid { grid-template-columns: 1fr !important; }

  /* Trial-success info strip */
  .ts-info { grid-template-columns: 1fr; }

  /* Onboarding plan picker — single column at smallest size */
  .tro-highlights { grid-template-columns: 1fr; }

  /* Topbar email pill hidden — saves space */
  .topbar .pill { display: none; }

  .rn-v6a-period-grid,
  .bl-summary { grid-template-columns: 1fr !important; }
}


/* ════════════════ Inline-style overrides for newer client components ══════
 * These components use inline CSS-in-JS and can't be touched via class media.
 * Use selector-based attribute targeting where possible.
 * ══════════════════════════════════════════════════════════════════════════ */

/* Trial-device page: the inline two-column grid (320px QR + content) */
@media (max-width: 900px) {
  /* The grid is rendered via inline `gridTemplateColumns: "minmax(0,320px) 1fr"`
     — override by targeting any direct grid that contains both .qr (we use
     a known data attribute via parent class). Use a generic safe selector. */
  [data-trial-device-content] { grid-template-columns: 1fr !important; }
  [data-trial-device-content] > aside { max-width: 100% !important; }
}

/* Sessions panel rows in /settings (inline-styled) */
@media (max-width: 720px) {
  .st-row .text h4 { font-size: 14px; gap: 6px !important; flex-wrap: wrap; }
  .st-row .text p { font-size: 11px !important; }
}


/* ════════════════ Touch-friendly tweaks ════════════════ */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .au-btn,
  .ts-btn,
  .tro-cta,
  .rl-cta,
  .st-btn,
  .dv-action-btn,
  .dv-action-icon-btn { min-height: 44px; }
}
