/* JYB ai.xxcvd.com unified mobile polish v4.
   Scope: SPA shell, same-origin iframe pages, safe-area ergonomics, touch reliability,
   and a single visual language across home / library / generator / copywriting /
   douyin-transcribe / douyin-dashboard / newbie-guide / user-admin.
   Editing rules: no API/Firebase config touched, no source secrets added,
   only target files listed in the task. */

:root{
  --jyb-mobile-nav:64px;
  --jyb-mobile-top:56px;
  --jyb-mobile-gap:12px;
  --jyb-radius-sm:10px;
  --jyb-radius-md:14px;
  --jyb-radius-lg:18px;
  --jyb-safe-bottom:env(safe-area-inset-bottom,0px);
  --jyb-safe-top:env(safe-area-inset-top,0px);
  --jyb-safe-left:env(safe-area-inset-left,0px);
  --jyb-safe-right:env(safe-area-inset-right,0px);
  --jyb-bg:#f6f7fb;
  --jyb-bg-soft:#fafbff;
  --jyb-panel:#ffffff;
  --jyb-ink:#172033;
  --jyb-ink-2:#3a4356;
  --jyb-muted:#667085;
  --jyb-line:#e6e8ef;
  --jyb-line-soft:#eef0f5;
  --jyb-gold:#c9a25e;
  --jyb-gold-2:#b08a47;
  --jyb-gold-soft:#f7ecd3;
  --jyb-gold-ink:#7a5a28;
  --jyb-focus:rgba(201,162,94,.24);
  --jyb-shadow:0 1px 2px rgba(15,23,42,.04),0 14px 38px -28px rgba(15,23,42,.45);
  --jyb-shadow-lift:0 2px 4px rgba(15,23,42,.05),0 18px 42px -22px rgba(15,23,42,.32);
}

/* ── Universal anti-overflow + tap polish ─────────────────────────────── */
*{box-sizing:border-box;min-width:0}
html{scroll-behavior:smooth;-webkit-text-size-adjust:100%;text-size-adjust:100%;max-width:100%}
body{color:var(--jyb-ink);max-width:100%}
button,a,input,textarea,select,[role="button"]{-webkit-tap-highlight-color:transparent}
button,a,[role="button"]{touch-action:manipulation}
input,textarea,select{font-size:16px!important}
img,video,canvas,iframe,svg{max-width:100%}
:focus-visible{outline:3px solid var(--jyb-focus)!important;outline-offset:2px!important}

/* ─────────────────────────────────────────────────────────────────────────
   SHARED MOBILE POLISH — applies to every same-origin iframe page that links
   this stylesheet via the SPA's injectMobilePolish() and to the SPA itself.
   Selectors are kept generic so they cover all current pages.
   ───────────────────────────────────────────────────────────────────────── */
@media(max-width:768px){
  html,body{
    background:var(--jyb-bg)!important;
    min-height:100%;
    width:100%;
    max-width:100vw;
    overflow-x:hidden!important;
    overscroll-behavior-y:contain;
  }
  body{
    font-size:15px!important;
    line-height:1.62!important;
    background-image:none!important;
    padding-left:var(--jyb-safe-left)!important;
    padding-right:var(--jyb-safe-right)!important;
  }

  /* page wrappers / containers — full width, padded for safe-area + nav clearance */
  .wrap,.container,.page,.app,.workspace,.layout,.main,.content,.copywriting-app,.dashboard{
    width:100%!important;
    max-width:100vw!important;
    min-width:0!important;
    overflow-x:hidden!important;
  }
  .wrap,.container{
    padding:12px 12px calc(28px + var(--jyb-safe-bottom))!important;
    margin:0!important;
  }
  /* Standalone (non-iframe) pages: extra bottom slack for thumb reach. */
  html:not(.jyb-iframe-page) body .wrap,
  html:not(.jyb-iframe-page) body .container{
    padding-bottom:calc(48px + var(--jyb-safe-bottom))!important;
  }

  /* every surface gets one consistent rounding + shadow + border */
  .card,.section,.shortcuts,.activity,.stat-card,.action-card,
  .panel,.modal,.detail-panel,.paper,.right,.side,.editor-wrap,.preview-wrap,
  .pair-col,.doc,.video-item,.item,.emp-card,.banner{
    border-radius:var(--jyb-radius-md)!important;
    box-shadow:var(--jyb-shadow)!important;
    border-color:var(--jyb-line)!important;
    background:var(--jyb-panel)!important;
  }
  .card,.section,.shortcuts,.activity,.panel{margin-bottom:var(--jyb-mobile-gap)!important}

  /* sticky page headers — top safe-area + soft glass.
     Only true page-level headers (.hdr, .detail-header) and the dashboard
     top-action toolbar get the sticky treatment. Editor toolbars and the
     copywriting/.top bar keep their own positioning. */
  .hdr,.detail-header,.container > .toolbar{
    position:sticky;
    top:0;
    z-index:30;
    background:rgba(246,247,251,.96)!important;
    backdrop-filter:blur(14px);
    -webkit-backdrop-filter:blur(14px);
    border-bottom:1px solid var(--jyb-line)!important;
    padding:calc(10px + var(--jyb-safe-top)) 12px 10px!important;
    margin:0 -12px 12px!important;
    gap:10px!important;
    align-items:center!important;
    flex-wrap:wrap!important;
  }
  .hdr-left h1,.hdr h1,.toolbar-title,.hero-text h1,.hdr h1 .ico{
    font-size:20px!important;
    line-height:1.24!important;
    letter-spacing:0!important;
  }
  .hdr-left .sub,.sub,.hint,.mode-note,.who{
    font-size:13px!important;
    line-height:1.55!important;
    color:var(--jyb-muted)!important;
    overflow-wrap:anywhere;
  }

  /* hero block — single-column, real left alignment, polished surface */
  .hero{
    grid-template-columns:auto minmax(0,1fr)!important;
    text-align:left!important;
    padding:16px!important;
    margin-bottom:var(--jyb-mobile-gap)!important;
    background:#fff!important;
    border-radius:var(--jyb-radius-md)!important;
    box-shadow:var(--jyb-shadow)!important;
  }
  .hero-logo{
    width:48px!important;
    height:48px!important;
    margin:0!important;
    border-radius:12px!important;
    font-size:20px!important;
    flex:0 0 auto!important;
  }
  .hero-right{
    grid-column:1 / -1!important;
    text-align:left!important;
    width:100%!important;
    margin-top:6px;
    color:var(--jyb-muted)!important;
  }

  /* stat strip / quick stats — tile pair with consistent rhythm */
  .stat-strip,.stats-grid,.stats{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:10px!important;
    margin-bottom:var(--jyb-mobile-gap)!important;
  }
  .stat-card,.stat{
    padding:12px 14px!important;
    background:#fff!important;
    border:1px solid var(--jyb-line)!important;
    border-radius:var(--jyb-radius-sm)!important;
    box-shadow:var(--jyb-shadow)!important;
  }
  .stat-value,.stat strong{
    font-size:22px!important;
    line-height:1.18!important;
  }
  .stat-label,.stat span{
    color:var(--jyb-muted)!important;
    font-size:11px!important;
    letter-spacing:.04em!important;
  }

  /* primary action / shortcut grids → single column */
  .primary-grid,.bottom-grid,.rewrite-pair,.form-row,.shortcut-list,.emp-grid{
    grid-template-columns:1fr!important;
    gap:10px!important;
  }

  /* action card refresh */
  .action-card{
    grid-template-columns:48px minmax(0,1fr)!important;
    gap:12px!important;
    padding:14px!important;
    min-height:80px!important;
    background:#fff!important;
    border-radius:var(--jyb-radius-md)!important;
    border:1px solid var(--jyb-line)!important;
    box-shadow:var(--jyb-shadow)!important;
  }
  .action-icon{
    width:48px!important;
    height:48px!important;
    border-radius:12px!important;
    font-size:22px!important;
  }
  .action-arrow{display:none!important}
  .action-body h3{font-size:15.5px!important;line-height:1.32!important}
  .action-body p{font-size:13px!important;line-height:1.55!important;color:var(--jyb-muted)!important}

  /* buttons — uniform 44px touch target, full-width grouping */
  .btn,button:not(.btn-icon):not(.tool):not(.clear-search):not(.tab button):not(.dirty-dot),
  [role="button"]:not(.tab):not(.tool){
    min-height:44px!important;
  }
  .btn{
    border-radius:10px!important;
    justify-content:center!important;
    white-space:normal!important;
    text-align:center!important;
    line-height:1.25!important;
    font-weight:600!important;
  }
  .btn-row,.toolbar-actions,.modal-actions,.editor-actions,.result-hdr .actions,
  .detail-actions,.copy-actions,.preset-row,.section-controls,.hdr-actions{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:8px!important;
    width:100%!important;
  }
  .btn-row .btn,.toolbar-actions .btn,.modal-actions .btn,.editor-actions .btn,
  .result-hdr .actions .btn,.detail-actions .btn,.copy-actions .btn,
  .preset-row .btn,.section-controls .btn,.hdr-actions .btn{
    width:100%!important;
    margin:0!important;
  }
  .btn-row .btn-count,.toolbar-actions .cookie-badge{
    grid-column:1 / -1!important;
    width:100%!important;
    justify-content:center!important;
    margin:0!important;
    text-align:center!important;
  }

  /* inputs */
  textarea{
    min-height:148px!important;
    border-radius:10px!important;
    line-height:1.6!important;
  }
  .search,.select,.date-input,.toolbar input,
  .form-group input,.form-group select{
    min-height:44px!important;
    border-radius:10px!important;
    padding:10px 12px!important;
  }

  /* result containers */
  .result-box,.pair-body,.editor,.editor-ta{
    max-height:none!important;
    overflow:visible!important;
    word-break:break-word!important;
    overflow-wrap:anywhere!important;
  }

  /* rewrite controls */
  .rewrite-ctrl{
    display:grid!important;
    grid-template-columns:1fr!important;
    gap:8px!important;
    padding:12px!important;
    border-radius:var(--jyb-radius-sm)!important;
  }
  .chip-group{
    display:grid!important;
    grid-template-columns:repeat(3,minmax(0,1fr))!important;
    width:100%!important;
    gap:6px!important;
    padding:6px!important;
    border-radius:10px!important;
  }
  .chip{
    min-height:42px!important;
    padding:8px!important;
    border-radius:8px!important;
  }

  /* lists */
  .items-list,.video-list,.doc-list{gap:8px!important;padding:8px!important}
  .item,.video-item,.doc{
    border-radius:var(--jyb-radius-sm)!important;
    background:#fff!important;
    border:1px solid var(--jyb-line)!important;
    padding:12px!important;
  }
  .video-item{
    display:grid!important;
    grid-template-columns:86px minmax(0,1fr)!important;
    align-items:start!important;
    gap:10px!important;
  }
  .video-cover{
    width:86px!important;
    height:118px!important;
    aspect-ratio:3/4!important;
    border-radius:10px!important;
    object-fit:cover!important;
  }
  .video-desc{-webkit-line-clamp:3!important}
  .video-metrics{gap:8px!important}

  /* detail / modal sheets — bottom-sheet on mobile */
  .detail-overlay,.modal-overlay{
    align-items:flex-end!important;
    padding:0!important;
    background:rgba(15,23,42,.42)!important;
  }
  .detail-panel,.modal{
    width:100%!important;
    max-width:none!important;
    max-height:calc(100dvh - var(--jyb-safe-top))!important;
    border-radius:var(--jyb-radius-lg) var(--jyb-radius-lg) 0 0!important;
    overflow:auto!important;
    padding:16px!important;
  }
  .detail-body{padding:14px!important}

  /* toast / notice */
  .toast,.snackbar,.notice{
    left:12px!important;
    right:12px!important;
    bottom:calc(var(--jyb-mobile-nav) + 12px + var(--jyb-safe-bottom))!important;
    max-width:none!important;
    text-align:center!important;
    border-radius:12px!important;
    z-index:1600!important;
    pointer-events:auto!important;
  }

  /* tables → cards on mobile */
  table{display:block!important;width:100%!important;overflow:visible!important}
  thead{display:none!important}
  tbody,tr,td{display:block!important;width:100%!important}
  tr{
    background:#fff!important;
    border:1px solid var(--jyb-line)!important;
    border-radius:var(--jyb-radius-md)!important;
    margin-bottom:10px!important;
    padding:12px!important;
    box-shadow:var(--jyb-shadow)!important;
  }
  td{border:0!important;padding:4px 0!important}
  .action-cell{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    gap:8px!important;
    justify-content:stretch!important;
    margin-top:8px!important;
  }

  /* kill horizontal scroll bars on common shell containers */
  .side,.sidebar,.right,.left-panel,.right-panel,.editor-wrap,.preview-wrap,.workspace-main{
    width:100%!important;
    max-width:none!important;
    min-width:0!important;
    float:none!important;
  }

  /* generic "fixed/sticky element wider than viewport" guard */
  .fixed,.sticky{max-width:100vw!important}

  /* state blocks */
  .empty,.loading,.error,.empty-state,.loading-state,.error-state,.empty-note{
    display:block!important;
    min-height:44px!important;
    padding:14px!important;
    border-radius:var(--jyb-radius-sm)!important;
    overflow-wrap:anywhere!important;
    background:#fff!important;
    border:1px dashed var(--jyb-line)!important;
    color:var(--jyb-muted)!important;
  }

  /* cookie alert / banner standardize */
  .cookie-alert,.banner,.meta-bar{
    position:static!important;
    margin:0 0 var(--jyb-mobile-gap)!important;
    padding:12px!important;
    border-radius:var(--jyb-radius-sm)!important;
  }
  .cookie-badge{
    min-height:38px!important;
    white-space:normal!important;
    text-align:center!important;
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   SPA SHELL FIX — root cause for the "shifted right + clipped cards" bug.
   The bundled React shell renders <aside class="w-72 fixed ..."> with a
   <main> sibling on a flex row. On mobile we hide the aside, force main
   to span the viewport, neutralize any leftover left/margin offsets, and
   pin overlays correctly above the bottom-nav with safe-area math.
   ───────────────────────────────────────────────────────────────────────── */
@media(max-width:768px){
  body.mx-authed{
    padding-bottom:calc(var(--jyb-mobile-nav) + var(--jyb-safe-bottom))!important;
    background:var(--jyb-bg)!important;
  }
  body.douyin-active main{visibility:hidden!important}

  /* Hide every fixed-positioned sidebar variant the bundle could emit. */
  #root aside,
  #root [class*="w-72"][class*="fixed"],
  #root [class*="w-64"][class*="fixed"],
  #root .lg\:w-72,
  #root .md\:w-72{
    display:none!important;
  }

  /* Main content area must occupy full viewport on mobile. */
  #root,
  #root > div,
  #root main,
  #root .flex.h-screen,
  #root [class*="flex-row"],
  #root [class*="flex-col"]{
    width:100%!important;
    max-width:100vw!important;
    margin-left:0!important;
    margin-right:0!important;
    padding-left:0!important;
    padding-right:0!important;
    left:0!important;
  }
  #root .flex.h-screen{
    height:calc(100dvh - var(--jyb-mobile-nav) - var(--jyb-safe-bottom))!important;
    min-height:0!important;
    flex-direction:column!important;
  }
  #root main{
    flex:1 1 auto!important;
    overflow-x:hidden!important;
  }
  /* Generator / library split: stack columns vertically and cap widths. */
  main [class*="flex-row"]{
    flex-direction:column!important;
    overflow:auto!important;
    gap:10px!important;
    padding:10px!important;
  }
  main [class*="w-[65%]"],main [class*="w-[35%]"]{
    width:100%!important;
    max-width:none!important;
    border-radius:var(--jyb-radius-md)!important;
  }
  main [class*="w-[35%]"]{
    padding:10px!important;
    background:#fff!important;
    border:1px solid var(--jyb-line)!important;
  }
  main [class*="w-[65%]"] > .p-3.bg-white.border-t.shrink-0{
    bottom:0!important;
    padding:10px!important;
    border-radius:14px 14px 0 0!important;
    box-shadow:0 -16px 34px -28px rgba(15,23,42,.7)!important;
  }

  /* Iframe overlays: full-bleed below the SPA top bar, above the bottom nav,
     fully neutralizing the desktop "left:18rem" rule. */
  #douyin-overlay,#newbie-overlay,#transcribe-overlay,
  #welcome-overlay,#useradmin-overlay,#copywriting-overlay{
    left:0!important;
    right:0!important;
    top:calc(var(--jyb-mobile-top) + var(--jyb-safe-top))!important;
    bottom:calc(var(--jyb-mobile-nav) + var(--jyb-safe-bottom))!important;
    width:100vw!important;
    max-width:100vw!important;
    background:var(--jyb-bg)!important;
    border-radius:0!important;
    transform:none!important;
  }
  #douyin-overlay iframe,#newbie-overlay iframe,#transcribe-overlay iframe,
  #welcome-overlay iframe,#useradmin-overlay iframe,#copywriting-overlay iframe{
    width:100%!important;
    height:100%!important;
    border:0!important;
    background:var(--jyb-bg)!important;
    display:block!important;
  }

  /* Bottom navigation — five equal columns, safe-area aware */
  #mx-mobile-nav{
    display:none;
    position:fixed;
    left:0;right:0;bottom:0;
    z-index:1200;
    grid-template-columns:repeat(5,minmax(0,1fr));
    height:calc(var(--jyb-mobile-nav) + var(--jyb-safe-bottom));
    padding:6px max(6px,var(--jyb-safe-left)) calc(6px + var(--jyb-safe-bottom)) max(6px,var(--jyb-safe-right));
    background:rgba(255,255,255,.97);
    border-top:1px solid var(--jyb-line);
    box-shadow:0 -20px 42px -34px rgba(15,23,42,.8);
    backdrop-filter:blur(16px);
    -webkit-backdrop-filter:blur(16px);
  }
  body.mx-authed #mx-mobile-nav{display:grid!important}
  #mx-mobile-nav a{
    display:flex;flex-direction:column;align-items:center;justify-content:center;
    gap:3px;text-decoration:none;color:#667085;
    font-size:11px;font-weight:800;border-radius:12px;
    line-height:1;min-width:0;white-space:nowrap;
    transition:background .16s,color .16s,transform .16s;
  }
  #mx-mobile-nav a::before{font-size:18px;line-height:1.1;font-weight:700;color:inherit}
  #mx-mobile-nav a[data-route="welcome"]::before{content:"⌂"}
  #mx-mobile-nav a[data-route="library"]::before{content:"▤"}
  #mx-mobile-nav a[data-route="generator"]::before{content:"✦"}
  #mx-mobile-nav a[data-route="douyin"]::before{content:"⌁"}
  #mx-mobile-nav a[data-route="copywriting"]::before{content:"文"}
  #mx-mobile-nav a.active{
    color:var(--jyb-gold-ink);
    background:var(--jyb-gold-soft);
    box-shadow:inset 0 0 0 1px rgba(201,150,62,.18);
  }
  #mx-mobile-nav a:active{transform:scale(.96)}

  /* Floating "新手训练" shortcut — high-visibility persistent mobile entrance.
     Sits above the bottom nav, right-aligned, never overlaps the 5 primary
     actions. Pinned to safe-area to stay reachable on notch/home-indicator
     devices. Uses fixed width chip so it never causes horizontal overflow. */
  #mx-newbie-shortcut{
    display:none;
  }
  body.mx-authed #mx-newbie-shortcut{
    display:inline-flex!important;
    position:fixed;
    right:calc(10px + var(--jyb-safe-right));
    bottom:calc(var(--jyb-mobile-nav) + var(--jyb-safe-bottom) + 12px);
    z-index:1300;
    align-items:center;
    gap:6px;
    padding:8px 12px;
    border-radius:9999px;
    background:linear-gradient(135deg,var(--jyb-gold) 0%,var(--jyb-gold-2) 100%);
    color:#fff;
    font-size:12.5px;
    font-weight:800;
    letter-spacing:.02em;
    text-decoration:none;
    line-height:1.1;
    box-shadow:0 6px 18px -6px rgba(116,81,28,.55),0 1px 2px rgba(15,23,42,.18);
    border:1px solid rgba(255,255,255,.35);
    max-width:calc(100vw - 20px - var(--jyb-safe-left) - var(--jyb-safe-right));
    white-space:nowrap;
    transition:transform .15s ease,box-shadow .15s ease,filter .15s ease;
  }
  body.mx-authed #mx-newbie-shortcut:active{
    transform:scale(.96);
  }
  body.mx-authed #mx-newbie-shortcut .mx-newbie-ico{
    font-size:14px;
    line-height:1;
    filter:drop-shadow(0 1px 1px rgba(0,0,0,.18));
  }
  body.mx-authed #mx-newbie-shortcut .mx-newbie-label{
    color:#fff;
  }
}

/* Compact phone widths — tighten the floating shortcut so it never overflows
   at 320/360/390 viewport widths. */
@media(max-width:430px){
  body.mx-authed #mx-newbie-shortcut{
    right:calc(8px + var(--jyb-safe-right));
    bottom:calc(var(--jyb-mobile-nav) + var(--jyb-safe-bottom) + 10px);
    padding:7px 11px;
    font-size:12px;
  }
}
@media(max-width:360px){
  body.mx-authed #mx-newbie-shortcut{
    padding:6px 10px;
    font-size:11.5px;
    gap:5px;
  }
}

/* The floating shortcut is mobile-only; ensure it never appears on desktop. */
@media(min-width:769px){
  #mx-newbie-shortcut{display:none!important}
}

/* ── Per-page layout reset (workspace splits) ─────────────────────────── */
@media(max-width:768px){
  .copywriting-layout,.split,.main-grid,.dash-grid,.workspace,.layout{
    display:block!important;
  }
  .paper{
    padding:12px!important;
    min-height:320px!important;
    border-radius:var(--jyb-radius-md)!important;
    box-shadow:var(--jyb-shadow)!important;
  }
  .editor-ta,.editor textarea,.paper textarea{
    width:100%!important;
    max-width:100%!important;
    min-height:260px!important;
    resize:vertical!important;
  }
  .references-list,.archive-list,.history-list,.result-list,.material-list{
    max-height:none!important;
    overflow:visible!important;
  }

  /* user-admin table-as-cards — make rows look like surfaces */
  table tbody tr{
    border-radius:var(--jyb-radius-md)!important;
  }
  .role-pill,.disabled-pill,.pill{
    font-size:11px!important;
    padding:3px 8px!important;
  }

  /* douyin dashboard cookie-alert + toolbar polish */
  .toolbar-title{font-weight:900!important}
  .emp-card{padding:14px!important}
  .emp-stats{gap:14px!important;font-size:12px!important}

  /* newbie-guide section card */
  .section{padding:14px!important;border-radius:var(--jyb-radius-md)!important}
  .section h2,.section h3{font-size:16px!important;line-height:1.35!important}
}

/* ── Compact phone widths (≤430) ──────────────────────────────────────── */
@media(max-width:430px){
  .wrap,.container{padding-left:10px!important;padding-right:10px!important}
  .stat-strip,.stats-grid,.stats{grid-template-columns:1fr 1fr!important}
  .stat-card,.stat{padding:10px 12px!important}
  .stat-value,.stat strong{font-size:20px!important}
  .btn-row,.toolbar-actions,.modal-actions,.editor-actions,
  .result-hdr .actions,.detail-actions,.action-cell{
    grid-template-columns:1fr!important;
  }
  .video-item{grid-template-columns:74px minmax(0,1fr)!important}
  .video-cover{width:74px!important;height:98px!important}
  #mx-mobile-nav a{font-size:10.5px!important}
}

/* ── Very narrow widths (≤360) ─────────────────────────────────────────── */
@media(max-width:360px){
  .stat-strip,.stats-grid,.stats,.chip-group{
    grid-template-columns:1fr!important;
  }
  .hero{grid-template-columns:1fr!important;text-align:left!important}
  .hero-logo{margin-bottom:4px!important}
  .video-item{grid-template-columns:1fr!important}
  .video-cover{
    width:100%!important;height:auto!important;
    max-height:220px!important;aspect-ratio:16/9!important;
  }
  .btn,.shortcut,button,[role="button"]{font-size:13px!important}
  #mx-mobile-nav{padding-left:4px!important;padding-right:4px!important}
  #mx-mobile-nav a{font-size:10px!important;border-radius:10px!important}
  #mx-mobile-nav a::before{font-size:16px!important}
}

/* ── Tablet portrait polish (≤768) for narrow workspaces ──────────────── */
@media(min-width:431px) and (max-width:768px){
  .primary-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}
  .stat-strip,.stats-grid,.stats{grid-template-columns:repeat(3,minmax(0,1fr))!important}
}

/* ── 100dvh fallback for app-shell heights ────────────────────────────── */
@supports(height:100dvh){
  @media(max-width:768px){
    .app,.main{height:100dvh!important}
    .detail-panel,.modal{max-height:calc(100dvh - var(--jyb-safe-top))!important}
  }
}

/* ── Reduced-motion safety ────────────────────────────────────────────── */
@media(prefers-reduced-motion:reduce){
  *,*::before,*::after{
    animation-duration:.01ms!important;
    animation-iteration-count:1!important;
    scroll-behavior:auto!important;
    transition-duration:.01ms!important;
  }
}

/* ═════════════════════════════════════════════════════════════════════════
   SYSTEM POLISH v5 (full-system polish task) — unifies surfaces that were
   previously page-by-page: iframe overlay loading state, mobile table
   scroll, full-sheet modals on phones, and the auth-pending pre-paint hide
   scaffolding. Selectors target existing class names so adoption is
   automatic.
   ═════════════════════════════════════════════════════════════════════════ */

/* Iframe overlay loading background — kills the white flash before the
   embedded SPA paints. Applies at every viewport. The overlay frames are
   the six fixed iframes declared in index.html (#welcome-overlay etc).
   The gradient matches the alliance-home warm palette so the load-in
   feels native rather than a blank slate. */
.detail-overlay,
#welcome-overlay,
#newbie-overlay,
#douyin-overlay,
#transcribe-overlay,
#useradmin-overlay,
#copywriting-overlay{
  background:linear-gradient(110deg,var(--jyb-bg-soft) 0%,var(--jyb-bg) 35%,var(--jyb-bg-soft) 50%,var(--jyb-bg) 65%,var(--jyb-bg-soft) 100%);
  background-size:220% 100%;
  animation:jybOverlayShimmer 2.6s ease-in-out infinite;
}
@keyframes jybOverlayShimmer{0%{background-position:0% 50%}100%{background-position:200% 50%}}
@media (prefers-reduced-motion:reduce){
  .detail-overlay,
  #welcome-overlay,
  #newbie-overlay,
  #douyin-overlay,
  #transcribe-overlay,
  #useradmin-overlay,
  #copywriting-overlay{
    animation:none!important;
    background:linear-gradient(180deg,var(--jyb-bg-soft) 0%,var(--jyb-bg) 100%);
    background-size:auto;
  }
}
.detail-overlay iframe,
#welcome-overlay iframe,
#newbie-overlay iframe,
#douyin-overlay iframe,
#transcribe-overlay iframe,
#useradmin-overlay iframe,
#copywriting-overlay iframe{
  background:linear-gradient(180deg,var(--jyb-bg-soft) 0%,var(--jyb-bg) 100%);
}

/* Auth-pending pre-paint hide (Section J frontend half). Pages that wire
   their inline auth handler to set `<body data-auth="pending">` until the
   first onAuthStateChanged fires can use the hooks below to suppress edit/
   admin affordances pre-paint. Inert until a page sets the attribute, and
   the wiring change is a separate follow-up PR (it touches inline JS in
   newbie-guide.html / user-admin.html, which is out of scope for this CSS
   pass). */
[data-auth="pending"] .jyb-needs-auth,
[data-auth="pending"] .edit-section,
[data-auth="pending"] .admin-only,
[data-auth="pending"] .editor-actions{
  visibility:hidden!important;
}

/* Skeleton helper usable by any page that wants to bridge auth/data load
   without writing its own keyframes. Existing .jyb-skel rules elsewhere
   are preserved; this is a new namespaced helper. */
.jyb-system-skel{
  display:inline-block;
  background:linear-gradient(90deg,var(--jyb-line-soft) 0%,var(--jyb-bg-soft) 50%,var(--jyb-line-soft) 100%);
  background-size:200% 100%;
  border-radius:6px;
  min-height:.85em;
  animation:jybSystemShimmer 1.4s ease-in-out infinite;
}
@keyframes jybSystemShimmer{
  0%{background-position:200% 0}
  100%{background-position:-200% 0}
}

@media(max-width:768px){
  /* Mobile-only: tables that aren't explicitly opted out get a horizontal
     scroll wrapper so they can't cause page-level horizontal overflow
     (the smoke harness's FAIL gate). Pages that already wrap their tables
     can opt out by adding the .no-mobile-wrap class. */
  table:not(.no-mobile-wrap){
    display:block;
    max-width:100%;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
  }
  table:not(.no-mobile-wrap) > *{min-width:540px}

  /* Modal full-sheet on phones — applies to existing .modal-overlay/.modal
     pairs in douyin-dashboard, user-admin, copywriting, etc. Page-local
     z-index inconsistencies between 100 and 1000 are not equalised here
     (changing z-index on already-shipped overlays is risky); only shape
     and safe-area are normalised. */
  .modal-overlay{
    padding:0!important;
    align-items:flex-end!important;
  }
  .modal-overlay .modal,
  .modal-overlay > .modal{
    max-width:100%!important;
    width:100%!important;
    border-radius:var(--jyb-radius-lg) var(--jyb-radius-lg) 0 0!important;
    max-height:92vh!important;
    margin:0!important;
  }

  /* Detail-panel full-sheet on phones (welcome detail panels, douyin-
     dashboard detail-overlay). */
  .detail-overlay > .detail-panel,
  .detail-overlay .detail-panel{
    max-width:100%!important;
    width:100%!important;
    border-radius:var(--jyb-radius-lg) var(--jyb-radius-lg) 0 0!important;
    max-height:92vh!important;
    margin-top:auto!important;
  }

  /* Generator route mobile layout: the React shell sets body.mx-route-
     generator on hash change. Ensure the right-side template/control
     panel doesn't squeeze the main content; let it stack instead.
     This is a defensive shell-level rule; the React component owns its
     internal layout and may already do this — the rule is harmless if
     the component already stacks. */
  body.mx-route-generator main > *{
    grid-template-columns:1fr!important;
  }
  /* Bottom-nav clearance for primary-action sticky bars in any page */
  body.mx-route-generator main,
  body.jyb-page-copywriting #workspace,
  body.jyb-page-douyin-transcribe,
  body.jyb-page-douyin-dashboard{
    padding-bottom:calc(var(--jyb-mobile-nav,64px) + var(--jyb-safe-bottom))!important;
  }

  /* ── Generator route mobile fallback (no React source available) ────
     The shell-level enhancer at index.html:740-789 (tagGeneratorPanes())
     tags the React-rendered generator's two-column row with
       [data-jyb-generator-wrap="1"]   on the row container
       [data-jyb-generator-main="1"]   on the writing canvas
       [data-jyb-generator-side="1"]   on the template/control rail
     Desktop CSS at desktop-operational-polish.css:619-654 sizes them as a
     2-col grid for >=1024px. Mobile gets stack behavior here so the right
     rail does NOT squeeze the canvas on phones. */
  body.mx-route-generator [data-jyb-generator-wrap="1"]{
    display:flex!important;
    flex-direction:column!important;
    gap:var(--jyb-mobile-gap)!important;
    width:100%!important;
    max-width:100%!important;
  }
  body.mx-route-generator [data-jyb-generator-main="1"]{
    width:100%!important;
    max-width:100%!important;
    flex:0 0 auto!important;
    min-height:54vh!important;
  }
  body.mx-route-generator [data-jyb-generator-side="1"]{
    width:100%!important;
    max-width:100%!important;
    flex:0 0 auto!important;
    max-height:42vh!important;
    overflow-y:auto!important;
    -webkit-overflow-scrolling:touch!important;
    border-top:1px solid var(--jyb-line-soft)!important;
    padding-top:var(--jyb-mobile-gap)!important;
  }

  /* Library copy-button dedup CSS backup. The shell-level enhancer at
     index.html:701-725 (dedupeCopyButtons()) sets inline
       style="display:none !important"
     and tags duplicates with data-jyb-deduped="1". A React re-render that
     replaces the button element would lose the inline style; this CSS
     keeps the dedup stable across re-renders by re-asserting display:none
     for any element still carrying the data attribute. */
  [data-jyb-deduped="1"]{
    display:none!important;
  }
}

/* The data-jyb-deduped guard is also active outside the @media (max-width:768px)
   block — duplicate copy buttons should be hidden at every viewport, not just
   on mobile. */
[data-jyb-deduped="1"]{
  display:none!important;
}
