/* ==========================================================================
   Mobile Settings — phone-native rebuild of the Settings area.
   Loaded ONLY by settings.html. The desktop is a two-column layout (left nav +
   content pane). On <=600px that becomes a menu → detail push flow:

     MENU (profile + grouped sections)  ──tap a row──▶  SECTION detail

   The real section panels (#tab-account, #tab-branding, …) are relocated into
   the pushed detail screen by settings.js (moving nodes keeps ids + listeners,
   so every section's existing controls/save logic is reused untouched). Post
   Styles opens the shared PostStyleBuilder overlay instead of a pane; Onboarding
   Setup / Admin are links. Light-paper theme is forced on mobile.

   Namespace: .stm-*  (SeTtings Mobile)  · palette = warm-paper (light only)
   ========================================================================== */

.stm-shell { display: none; }

@media (max-width: 600px) {
  .settings-wrapper { display: none !important; }
  html, body { overflow-x: hidden; }
  body { overflow: hidden; }

  .stm-shell {
    display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 30;
    background: #F5F2EC; color: #1A1A18;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    overscroll-behavior: none;
    --ios-nav: 340ms cubic-bezier(.32, .72, 0, 1);
    --ios-tap: 130ms ease;
  }

  /* ── iOS-style nav: menu recedes, detail pushes in from the right ──────── */
  #stm-screen-menu {
    display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative;
    transition: transform var(--ios-nav); will-change: transform;
  }
  .stm-shell.stm-detail-open #stm-screen-menu { transform: translateX(-22%); }
  #stm-screen-menu::after {
    content: ''; position: absolute; inset: 0; z-index: 5; background: #000;
    opacity: 0; pointer-events: none; transition: opacity var(--ios-nav);
  }
  .stm-shell.stm-detail-open #stm-screen-menu::after { opacity: .09; }

  #stm-screen-detail {
    display: flex; flex-direction: column; position: fixed; inset: 0; z-index: 40;
    background: #F5F2EC; transform: translateX(100%);
    transition: transform var(--ios-nav); will-change: transform;
  }
  .stm-shell.stm-detail-open #stm-screen-detail { transform: translateX(0); }

  /* ── Headers ──────────────────────────────────────────────────────────── */
  .stm-head {
    flex-shrink: 0; display: flex; align-items: center; gap: 12px;
    padding: calc(8px + env(safe-area-inset-top)) 16px 12px;
    border-bottom: 1px solid #E6E0D4; background: #F5F2EC;
  }
  .stm-back {
    width: 34px; height: 34px; border-radius: 50%; background: #FFFFFF; border: 1px solid #DDD8CE;
    color: #6B6B64; font-size: 21px; line-height: 1; display: flex; align-items: center;
    justify-content: center; flex-shrink: 0; cursor: pointer;
    transition: transform var(--ios-tap); -webkit-tap-highlight-color: transparent;
  }
  .stm-back:active { transform: scale(.9); }
  .stm-head-titles { flex: 1; min-width: 0; }
  .stm-title { font: 800 21px system-ui; letter-spacing: -.4px; }
  #stm-screen-detail .stm-title { font-size: 19px; }
  .stm-subtitle { font: 500 11px system-ui; color: #888; margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .stm-body {
    flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 16px;
  }

  /* ── Profile card ─────────────────────────────────────────────────────── */
  .stm-profile {
    display: flex; align-items: center; gap: 13px; width: 100%; box-sizing: border-box;
    background: #FFFFFF; border: 1px solid #E6E0D4; border-radius: 14px; padding: 14px;
    margin-bottom: 16px; cursor: pointer; text-align: left; -webkit-tap-highlight-color: transparent;
  }
  .stm-profile:active { background: #FAF7F0; }
  .stm-avatar {
    width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, #8E7BD6, #6D8AD9);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font: 700 16px system-ui;
  }
  .stm-profile-main { flex: 1; min-width: 0; }
  .stm-profile-email {
    font: 700 13.5px system-ui; color: #1A1A18;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .stm-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
  .stm-badge { font: 700 9.5px system-ui; border-radius: 6px; padding: 3px 8px; }
  .stm-badge--plan { color: #A8843A; background: rgba(168,132,58,.12); }
  .stm-badge--billing { color: #2A7A4F; background: rgba(42,122,79,.12); }

  /* ── Grouped menu ─────────────────────────────────────────────────────── */
  .stm-group-label {
    font: 700 10px system-ui; letter-spacing: .07em; text-transform: uppercase;
    color: #9a937f; margin: 4px 4px 8px;
  }
  .stm-group {
    background: #FFFFFF; border: 1px solid #E6E0D4; border-radius: 14px;
    overflow: hidden; margin-bottom: 16px;
  }
  .stm-row {
    display: flex; align-items: center; gap: 12px; width: 100%; box-sizing: border-box;
    background: transparent; border: none; text-align: left; cursor: pointer;
    padding: 13px 14px; text-decoration: none; color: inherit;
    -webkit-tap-highlight-color: transparent; transition: background var(--ios-tap);
  }
  .stm-row + .stm-row { border-top: 1px solid #F0EBE0; }
  .stm-row:active { background: #FAF7F0; }
  .stm-row-icon {
    width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
    background: #F3EEE6; color: #6B6B64;
    display: flex; align-items: center; justify-content: center;
  }
  .stm-row-icon svg { width: 16px; height: 16px; }
  .stm-row-label { flex: 1; min-width: 0; font: 600 13.5px system-ui; color: #1A1A18; }
  .stm-row-chev { flex-shrink: 0; color: #C2B79E; font-size: 20px; line-height: 1; }

  /* ── Detail: the relocated panel fills the screen ─────────────────────── */
  #stm-detail-mount { display: flex; flex-direction: column; }
  #stm-detail-mount .settings-panel { display: flex !important; gap: 13px; animation: none; }
  /* the push header already carries the title — drop the in-panel one */
  #stm-detail-mount .settings-section-header { display: none; }
  #stm-detail-mount .settings-card {
    padding: 14px; border-radius: 14px; box-shadow: none; margin: 0;
  }
  #stm-detail-mount .card-heading { font: 800 14px system-ui; }
  #stm-detail-mount .settings-helper { font-size: 0.8rem; }
  /* keep any full-width controls edge-to-edge inside the card */
  #stm-detail-mount .settings-card > * { max-width: 100%; }

  /* ── Detail footer (a plain Done — sections self-save via their controls) ─ */
  .stm-foot {
    flex-shrink: 0; padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid #E6E0D4; background: #FAF8F3;
  }
  .stm-done {
    width: 100%; background: #A8843A; border: none; border-radius: 11px; color: #fff;
    font: 700 13.5px system-ui; padding: 14px; cursor: pointer;
    transition: transform var(--ios-tap); -webkit-tap-highlight-color: transparent;
  }
  .stm-done:active { transform: scale(.98); }

  @media (prefers-reduced-motion: reduce) {
    #stm-screen-menu, #stm-screen-menu::after, #stm-screen-detail,
    .stm-back, .stm-row, .stm-done, .stm-profile { transition: none !important; }
  }
}
