/* =============================================================
   mobile.css — Spade's Life Explained · responsive layer
   Loaded AFTER styles.css. Two tiers:
     ≤ 900px  — sidebar collapses → docked tab bar (reference
                style) + glowing spade FAB + "المزيد" side drawer
     ≤ 520px  — phone-density adjustments
   ============================================================= */

/* chart-merge wrapper — invisible on desktop, one card on mobile */
.chart-merge { display: contents; }

/* home features grid when Labs is hidden (non-admin) */
.features-grid.features-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* dock + drawer hidden on desktop */
.mnav-wrap, .mdrawer, .mdrawer-dim { display: none; }

@media (max-width: 900px) {

  /* ── shell ──────────────────────────────────────────────── */
  .sidebar { display: none; }
  .topbar { padding: 0 14px; height: 58px; }
  .page { padding: 16px 14px 132px; }
  .tabs-row, .labs-filters, .gates-filters, .notif-filters {
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    min-width: 0; max-width: 100%; align-self: stretch; flex-wrap: nowrap;
  }
  .tabs-row::-webkit-scrollbar, .labs-filters::-webkit-scrollbar { display: none; }

  /* ── docked tab bar (reference style) + spade FAB ───────── */
  .mnav-wrap {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    pointer-events: none;
  }
  .mnav {
    pointer-events: auto;
    display: grid; grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    background: rgba(8,10,24,0.92);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-top: 1px solid rgba(162,141,254,0.25);
    box-shadow: 0 -10px 36px rgba(0,0,0,0.45);
  }
  .mnav-it {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; min-height: 52px; padding: 6px 2px;
    background: none; border: 1px solid transparent; border-radius: 14px;
    cursor: pointer; font-family: inherit;
    color: #8E88A8; font-size: 10.5px; font-weight: 600;
    transition: color 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  }
  /* active tab — the reference's rounded purple highlight */
  .mnav-it.on {
    color: #fff;
    background: linear-gradient(180deg, rgba(138,92,255,0.28), rgba(138,92,255,0.10));
    border-color: rgba(162,141,254,0.55);
    box-shadow: 0 0 18px rgba(138,92,255,0.25), inset 0 1px 0 rgba(255,255,255,0.08);
  }
  .mnav-it.on .mnav-ic { color: #C4B5FF; filter: drop-shadow(0 0 7px rgba(162,141,254,0.9)); }
  .mnav-ic { display: grid; place-items: center; height: 23px; transition: filter 0.2s ease; }

  .mnav-fab {
    position: relative; width: 60px; height: 60px; margin-top: -28px; justify-self: center; align-self: start;
    border-radius: 50%; display: grid; place-items: center; cursor: pointer;
    background: radial-gradient(circle at 35% 30%, #B79CFF, #6C46D6 60%, #3A2280);
    border: 1px solid rgba(220,200,255,0.55); color: #fff;
    box-shadow: 0 0 0 6px rgba(8,10,24,0.92), 0 6px 26px rgba(130,90,255,0.55), 0 0 30px rgba(130,90,255,0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  .mnav-fab:active { transform: scale(0.94); }
  .mnav-fab.on { box-shadow: 0 0 0 6px rgba(8,10,24,0.92), 0 6px 30px rgba(150,110,255,0.75), 0 0 44px rgba(150,110,255,0.55); }
  .mnav-fab-ring {
    position: absolute; inset: -7px; border-radius: 50%;
    border: 1px dashed rgba(190,160,255,0.5);
    animation: mnavSpin 14s linear infinite;
  }
  .mnav-fab-dot {
    position: absolute; top: -9px; left: 50%; width: 4px; height: 4px; border-radius: 50%;
    background: #F8C648; box-shadow: 0 0 8px 2px rgba(248,198,72,0.7);
  }
  @keyframes mnavSpin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { .mnav-fab-ring { animation: none; } }

  /* ── "المزيد" side drawer (reference style) ─────────────── */
  .mdrawer-dim {
    display: block; position: fixed; inset: 0; z-index: 58;
    background: rgba(2,4,13,0.6);
    -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
    animation: mnavFade 0.25s ease both;
  }
  .mdrawer-dim.out { animation: mnavFade 0.25s ease reverse both; }
  @keyframes mnavFade { from { opacity: 0; } to { opacity: 1; } }

  .mdrawer {
    --mdx: -40px;
    display: flex; flex-direction: column; gap: 14px;
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 59;
    width: min(330px, 86vw);
    padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto; overscroll-behavior: contain;
    background: linear-gradient(200deg, rgba(20,16,44,0.98), rgba(8,8,24,0.98));
    border-right: 1px solid rgba(162,141,254,0.35);
    box-shadow: 18px 0 60px rgba(0,0,0,0.6);
    border-radius: 0 26px 26px 0;
    animation: mdrawerIn 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  /* the shell forces direction:ltr internally, so logical anchoring
     resolves wrong — anchor with PHYSICAL sides off html[dir] */
  html[dir="rtl"] .mdrawer {
    --mdx: 40px;
    direction: rtl; text-align: right;
    left: auto; right: 0;
    border-right: none; border-left: 1px solid rgba(162,141,254,0.35);
    box-shadow: -18px 0 60px rgba(0,0,0,0.6);
    border-radius: 26px 0 0 26px;
  }
  .mdrawer.out { animation: mdrawerIn 0.26s ease reverse both; }
  @keyframes mdrawerIn {
    from { opacity: 0; transform: translateX(var(--mdx, -40px)); }
    to   { opacity: 1; transform: translateX(0); }
  }

  .mdrawer-brand { display: flex; align-items: center; gap: 12px; padding: 2px 4px; flex-shrink: 0; }
  .mdb-text { display: flex; flex-direction: column; gap: 2px; }
  .mdb-text strong { font-size: 15px; letter-spacing: 0.04em; color: #fff; }
  .mdb-text span { font-size: 11.5px; color: var(--gold, #F8C648); }

  .mdrawer-account {
    display: flex; flex-direction: column; flex-shrink: 0;
    border-radius: 16px; overflow: hidden;
    background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1);
  }
  .mda-row {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 14px; min-height: 48px;
    background: none; border: none; cursor: pointer; font-family: inherit;
    color: var(--text-soft, #D5D7F2); font-size: 13.5px; font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    text-align: start;
  }
  .mda-row:last-child { border-bottom: none; }
  .mda-ic { color: #C4B5FF; display: grid; place-items: center; }
  .mda-t { flex: 1; }
  .mda-chev { color: var(--text-dim, #686878); display: grid; place-items: center; }
  [dir="ltr"] .mda-chev svg { transform: scaleX(-1); }

  .mdrawer-nav { display: flex; flex-direction: column; }
  .mdn-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 10px; min-height: 48px;
    background: none; border: 1px solid transparent; border-radius: 14px;
    cursor: pointer; font-family: inherit;
    color: var(--text-soft, #D5D7F2); font-size: 14px; font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    text-align: start;
  }
  /* cluster text next to the gold icon (reference style) */
  html[dir="rtl"] .mdn-row { flex-direction: row-reverse; justify-content: flex-end; }
  .mdn-row .mdn-ic { color: var(--gold, #F8C648); display: grid; place-items: center; }
  .mdn-row.on {
    background: linear-gradient(180deg, rgba(138,92,255,0.26), rgba(138,92,255,0.08));
    border-color: rgba(162,141,254,0.55); border-bottom-color: rgba(162,141,254,0.55);
    color: #fff;
    box-shadow: 0 0 16px rgba(138,92,255,0.2);
  }
  .mdn-row.on .mdn-ic { color: #C4B5FF; }

  /* ── layout collapses ───────────────────────────────────── */
  .home-grid, .features-grid, .overview-grid, .centers-grid, .planets-grid,
  .gates-grid, .compare-profiles, .compare-bottom, .guide-grid, .guide-intro {
    grid-template-columns: minmax(0, 1fr);
  }
  /* a 1fr track can't shrink below min-content — force children shrinkable
     so wide rows (planet columns etc.) ellipsize instead of overflowing */
  .home-grid > *, .features-grid > *, .overview-grid > *, .centers-grid > *,
  .planets-grid > *, .gates-grid > *, .compare-profiles > *, .compare-bottom > *,
  .guide-grid > *, .guide-intro > * { min-width: 0; }
  .prow { min-width: 0; }
  .prow > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .prow .planet-glyph, .prow .planet-num { overflow: visible; }
  .hero-card { grid-template-columns: 1fr; padding: 22px 20px; }
  .hero-figure { order: -1; margin: 0 auto; }
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
  .insights-grid { grid-template-columns: repeat(2, 1fr); }
  .action-bar { grid-template-columns: 1fr 1fr; }
  .centers-detail-grid { grid-template-columns: repeat(2, 1fr); }
  .center-card, .center-half { grid-column: span 1; }
  .planet-chips { grid-template-columns: repeat(4, 1fr); }
  .pd-cards { grid-template-columns: 1fr; }
  .deep-cta, .ready-cta, .vision-card, .deep-compare { grid-template-columns: 1fr; text-align: center; }
  .deep-cta .dc-figure, .ready-cta > :first-child { margin: 0 auto; }
  .dc-actions { justify-content: center; flex-wrap: wrap; }
  .labs-hero { grid-template-columns: minmax(0, 1fr); padding: 8px 16px 4px; }
  .labs-hero > * { min-width: 0; max-width: 100%; }
  .labs-hero-figure { width: 100%; max-width: 420px; margin: 0 auto; }
  .labs-hero-figure image-slot { width: min(400px, calc(100vw - 64px)) !important; max-width: 100%; }
  .labs-hero-rings { width: min(360px, 86vw); }
  .labs-grid { padding: 4px 16px 16px; }
  .labs-filters { padding: 14px 16px 4px; display: flex; }
  .hs-rows { grid-template-columns: 1fr; }

  /* insights stack on mobile */
  .ov-insights, .home-insights { grid-template-columns: 1fr; }

  /* pricing tiers stack on mobile */
  .tier-grid { grid-template-columns: 1fr; }

  /* planets: breadcrumb row wraps instead of forcing width */
  .pl-breadcrumb { flex-wrap: wrap; row-gap: 8px; }
  .pl-breadcrumb > * { min-width: 0; }
  .pl-actions { flex-wrap: wrap; }

  /* ── overview: bodygraph + both gate columns as ONE card ─── */
  .chart-merge {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0;
    grid-column: 1 / -1;
    border-radius: 18px; overflow: hidden;
    border: 1px solid rgba(152,114,255,0.4);
    background: linear-gradient(180deg, rgba(10,9,30,0.78), rgba(3,4,16,0.88));
    -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  }
  .chart-merge > .bodygraph-wrap {
    order: -1; grid-column: 1 / -1;
    border: none; border-radius: 0; background: transparent;
    box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
    padding: 10px 6px 4px;
  }
  .chart-merge > .planet-col {
    min-width: 0;
    border: none; border-radius: 0;
    backdrop-filter: none; -webkit-backdrop-filter: none;
    border-top: 1px solid rgba(255,255,255,0.08);
  }
  .chart-merge > .planet-col.design { border-inline-start: 1px solid rgba(255,255,255,0.08); }
  .chart-merge .pcol-header { padding: 10px 12px 8px; }
  .chart-merge .pcol-title { font-size: 14px; }

  /* bodygraph: scaled to always fit the viewport */
  .centers-chart-card svg, .overview-grid svg.bodygraph, .bodygraph-wrap svg {
    width: 100%; height: auto; max-height: 68vh;
  }

  /* ── compare table → stacked cards ──────────────────────── */
  .ct-head { display: none; }
  .ct-row {
    grid-template-columns: 1fr 1fr; row-gap: 8px; padding: 14px 16px;
  }
  .ct-asp { grid-column: 1 / -1; order: -1; font-size: 13.5px; }
  .ct-note { grid-column: 1 / -1; order: 3; font-size: 12px; opacity: 0.9; }
  .ct-row > span[data-cl] { order: 2; }
  .ct-row > span[data-cl]::before {
    content: attr(data-cl);
    display: block; font-size: 10.5px; font-weight: 700;
    color: var(--text-dim, #686878); margin-bottom: 2px;
  }
  .cp-body { grid-template-columns: 1fr 92px; }
  .cp-summary { grid-column: 1 / -1; }
  .cb-row3 { grid-template-columns: 1fr; }

  /* ── touch wakes hover animations (paired with .tap-hover) ── */
  .labs-hero-figure.tap-hover .labs-hero-rings,
  .labs-hero-figure.tap-hover .labs-hero-rings::after { animation-play-state: running; }
  .labs-hero-figure.tap-hover .labs-hero-rings::after { opacity: 1; }
  .feature-card.tap-hover, .lab-card.tap-hover { border-color: rgba(162,141,254,0.45); }
}

/* ── laptop tier (narrow desktop, sidebar still visible) ────── */
@media (min-width: 901px) and (max-width: 1200px) {
  /* home: hero + today stack */
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-grid > * { min-width: 0; }
  .features-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .features-grid > * { min-width: 0; }

  /* overview: summary drops below; bodygraph shrinks to fit */
  .overview-grid { grid-template-columns: 150px minmax(0, 1fr) 150px; }
  .overview-grid > *, .chart-merge > * { min-width: 0; }
  .summary-card { grid-column: 1 / -1; }
  .overview-grid .bodygraph-wrap svg { width: 100%; height: auto; max-height: 64vh; }
  .prow > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .prow .planet-glyph, .prow .planet-num { overflow: visible; }

  /* gates: let both columns shrink */
  .gates-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.5fr); }
  .gates-grid > * { min-width: 0; }

  /* compare: profile cards + bottom cards stack */
  .compare-profiles, .compare-bottom { grid-template-columns: minmax(0, 1fr); }
  .compare-profiles > *, .compare-bottom > * { min-width: 0; }
}

/* ── phone-density tier ───────────────────────────────────── */
@media (max-width: 520px) {
  .topbar-name { display: none; }
  .page-title { font-size: 22px; }
  .page-subtitle { font-size: 12.5px; }
  .quick-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .insights-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .action-bar { grid-template-columns: 1fr; }
  .gates-tiles { grid-template-columns: repeat(3, 1fr); }
  .planet-chips { grid-template-columns: repeat(4, 1fr); }
  .centers-detail-grid { grid-template-columns: 1fr; }
  .cp-body { grid-template-columns: 1fr 86px; }
  .help-btn { font-size: 11px; }
  .page-header { flex-wrap: wrap; gap: 10px; }
}
