/* RA10 — unified unit UI styles (companion to unit-ui.js). Uses each unit's own --accent / --surface tokens so subjects keep their colour identity. */
html.ux-unit { scroll-padding-top: 150px; }
html.ux-lock { overflow: hidden; }

/* ── Header: tidy tabs + Jump button ───────────────────────────────── */
html.ux-unit .topbar .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
html.ux-unit .topbar .tabs::-webkit-scrollbar { display: none; }
html.ux-unit .topbar .tab { white-space: nowrap; flex: none; }
.ux-jump { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line-2, #d9d9d9); background: var(--surface, #fff); color: var(--ink, #111); font: 700 0.84rem/1 inherit; cursor: pointer; white-space: nowrap; flex: none; transition: border-color .15s, box-shadow .15s, background .15s; }
.ux-jump svg { width: 18px; height: 18px; }
.ux-jump svg:last-child { width: 15px; height: 15px; opacity: .7; }
.ux-jump:hover, .ux-jump[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-2, #eee); color: var(--accent-ink, var(--ink)); }
.ux-jump:focus-visible, .ux-tile:focus-visible, .ux-mitem:focus-visible, .ux-bottom button:focus-visible, .ux-resume:focus-visible, .ux-back:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, #fff); outline-offset: 2px; }

/* ── Jump-to menu ──────────────────────────────────────────────────── */
html.ux-unit .ux-scrim { position: fixed !important; inset: 0; z-index: 9000; background: rgba(8, 12, 20, .45); opacity: 0; transition: opacity .18s; backdrop-filter: blur(2px); }
html.ux-unit .ux-scrim.open { opacity: 1; }
html.ux-unit .ux-menu { position: fixed !important; z-index: 9001 !important; top: 76px; right: 24px; width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 110px); display: flex; flex-direction: column; border-radius: 20px; background: var(--surface, #fff); color: var(--ink, #111); border: 1px solid var(--line, #ddd); box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .55); opacity: 0; transform: translateY(-8px) scale(.98); transition: opacity .18s, transform .18s; font-family: inherit; }
html.ux-unit .ux-menu.open { opacity: 1; transform: none; }
.ux-mhead { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.ux-mhead strong { font-size: 1.02rem; }
.ux-mclose { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-soft, rgba(0,0,0,.06)); color: inherit; font-size: 1rem; cursor: pointer; }
.ux-mbody { overflow-y: auto; padding: 4px 10px 14px; overscroll-behavior: contain; }
.ux-mgroup { padding: 4px 0 2px; }
.ux-mlabel { margin: 8px 8px 4px; font-size: 0.68rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted, #777); }
.ux-mitem { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border: 0; border-radius: 14px; background: transparent; color: inherit; text-align: left; font: inherit; cursor: pointer; min-height: 52px; }
.ux-mitem:hover { background: var(--surface-soft, rgba(0,0,0,.05)); }
.ux-mitem.on { background: var(--accent-2, #eee); color: var(--accent-ink, inherit); }
.ux-mico { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, var(--surface, #fff)); color: var(--accent); }
.ux-mitem.on .ux-mico { background: var(--accent); color: #fff; }
.ux-mtxt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ux-mtxt b { font-size: 0.95rem; }
.ux-mtxt small { font-size: 0.78rem; color: var(--ink-2, #555); line-height: 1.3; }

/* ── Launchpad ─────────────────────────────────────────────────────── */
.ux-launch { margin: 0 0 22px; display: flex; flex-direction: column; gap: 14px; }
.ux-resume { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; border-radius: 18px; border: 1.5px solid color-mix(in srgb, var(--accent) 40%, var(--line, #ddd)); background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, var(--surface, #fff)), var(--surface, #fff)); color: var(--ink, #111); text-align: left; font: inherit; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.ux-resume:hover { transform: translateY(-1px); box-shadow: 0 12px 30px -18px var(--accent); }
.ux-ricon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: var(--accent); color: #fff; flex: none; }
.ux-resume > span:nth-child(2) { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ux-resume small { font-size: 0.74rem; color: var(--ink-2, #555); }
.ux-resume b { font-size: 1.02rem; }
.ux-resume em { font-style: normal; font-weight: 800; font-size: 0.84rem; color: var(--accent); white-space: nowrap; }
.ux-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.ux-tile { position: relative; display: flex; align-items: center; gap: 14px; padding: 16px; min-height: 84px; border-radius: 18px; border: 1px solid var(--line, #ddd); background: var(--surface, #fff); color: var(--ink, #111); text-align: left; font: inherit; cursor: pointer; transition: transform .15s, border-color .15s, box-shadow .15s; }
.ux-tile:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 55%, var(--line, #ddd)); box-shadow: 0 16px 34px -22px rgba(0, 0, 0, .5); }
.ux-ticon { flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 15px; background: color-mix(in srgb, var(--accent) 12%, var(--surface, #fff)); color: var(--accent); }
.ux-ticon svg { width: 24px; height: 24px; }
.ux-ttxt { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.ux-ttxt b { font-size: 1.02rem; letter-spacing: -.01em; }
.ux-ttxt small { font-size: 0.8rem; line-height: 1.35; color: var(--ink-2, #555); }
.ux-tcount { font-style: normal; font-size: 0.7rem; font-weight: 800; color: var(--accent); margin-top: 2px; }
.ux-tcount:empty { display: none; }
.ux-tile.feat { grid-column: span 2; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 65%, #000)); border-color: transparent; color: #fff; }
.ux-tile.feat .ux-ticon { background: rgba(255, 255, 255, .18); color: #fff; }
.ux-tile.feat .ux-ttxt small, .ux-tile.feat .ux-tcount { color: rgba(255, 255, 255, .88); }
.ux-more { margin: 6px 0 26px; border: 1px solid var(--line, #ddd); border-radius: 18px; background: var(--surface, #fff); }
.ux-more > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; list-style: none; padding: 14px 18px; cursor: pointer; font-weight: 800; font-size: 0.95rem; border-radius: 18px; }
.ux-more > summary::-webkit-details-marker { display: none; }
.ux-more > summary svg { width: 18px; height: 18px; transition: transform .2s; }
.ux-more[open] > summary svg { transform: rotate(180deg); }
.ux-more > summary:hover { background: var(--surface-soft, rgba(0,0,0,.04)); }
.ux-morebody { padding: 0 14px 14px; }

/* ── Breadcrumbs ───────────────────────────────────────────────────── */
.ux-crumb { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; flex-wrap: wrap; }
.ux-back { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px 7px 8px; border-radius: 999px; border: 1px solid var(--line-2, #ddd); background: var(--surface, #fff); color: var(--ink, #111); font: 700 0.82rem/1 inherit; cursor: pointer; }
.ux-back svg { width: 18px; height: 18px; }
.ux-back:hover { border-color: var(--accent); color: var(--accent-ink, inherit); }
.ux-crumb ol { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 0.82rem; color: var(--ink-2, #555); }
.ux-crumb li + li::before { content: '›'; margin-right: 6px; opacity: .6; }
.ux-crumb li button { border: 0; background: none; padding: 2px; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.ux-crumb li[aria-current] { color: var(--ink, #111); font-weight: 700; }

/* ── Mobile bottom navigation ──────────────────────────────────────── */
.ux-bottom { display: none; }
@media (max-width: 820px) {
  html.ux-unit .topbar .ux-jump { display: none !important; }
  html.ux-unit .hero { padding: 18px !important; gap: 14px !important; border-radius: 20px !important; }
  html.ux-unit .hero h2 { font-size: 1.45rem !important; line-height: 1.15 !important; }
  html.ux-unit .hero .eyebrow { font-size: 0.68rem !important; }
  html.ux-unit .hero .lede { font-size: 0.9rem !important; line-height: 1.5 !important; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  html.ux-unit .hero .stats { display: grid !important; grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 8px !important; }
  html.ux-unit .hero .stat { padding: 10px 8px !important; border-radius: 14px !important; min-width: 0; }
  html.ux-unit .hero .stat .num { font-size: 1.2rem !important; }
  html.ux-unit .hero .stat .lbl { font-size: 0.58rem !important; letter-spacing: .03em !important; }
  .ux-bottom { position: fixed !important; z-index: 8000 !important; left: 0; right: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface, #fff) 94%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line, #ddd); box-shadow: 0 -10px 30px -18px rgba(0, 0, 0, .45); }
  .ux-bottom button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 54px; border: 0; border-radius: 14px; background: transparent; color: var(--ink-2, #555); font: inherit; cursor: pointer; }
  .ux-bottom button span { display: grid; place-items: center; width: 44px; height: 28px; border-radius: 999px; transition: background .15s, color .15s; }
  .ux-bottom button svg { width: 22px; height: 22px; }
  .ux-bottom button b { font-size: 0.68rem; font-weight: 700; }
  .ux-bottom button.on { color: var(--accent); }
  .ux-bottom button.on span { background: color-mix(in srgb, var(--accent) 16%, transparent); }
  html.ux-unit main { padding-bottom: 104px; }
  html.ux-unit .ux-menu { top: auto !important; right: 0 !important; left: 0 !important; bottom: 0 !important; width: 100% !important; max-height: 82vh; border-radius: 22px 22px 0 0; transform: translateY(24px); padding-bottom: env(safe-area-inset-bottom); }
  html.ux-unit .ux-menu.open { transform: none; }
  .ux-mhead::before { content: ''; position: absolute; top: 8px; left: 50%; width: 42px; height: 4px; margin-left: -21px; border-radius: 4px; background: var(--line-2, #ccc); }
  .ux-mhead { padding-top: 22px; }
  .ux-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .ux-tile { flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px; min-height: 0; }
  .ux-tile .ux-ticon { width: 42px; height: 42px; border-radius: 13px; }
  .ux-tile .ux-ttxt b { font-size: 0.98rem; }
  .ux-tile .ux-ttxt small { font-size: 0.74rem; }
  .ux-tile.feat { grid-column: span 2; flex-direction: row; align-items: center; gap: 14px; }
  .ux-crumb { margin-bottom: 12px; }
  .ux-crumb ol { display: none; }
  .pp-toolbar { top: 8px !important; }
  .pp-side { top: 0 !important; }
}
@media (prefers-reduced-motion: reduce) {
  .ux-menu, .ux-scrim, .ux-tile, .ux-resume { transition: none; }
}

.ux-tile.wide { grid-column: span 2; }
@media (min-width: 821px) { .ux-tile.wide { grid-column: auto; } }

/* Paper library how-to cards: swipeable strip on phones */
@media (max-width: 820px) {
  html.ux-unit .pp-howto { display: flex !important; overflow-x: auto; gap: 10px; scroll-snap-type: x mandatory; padding-bottom: 6px; }
  html.ux-unit .pp-howto > div { flex: 0 0 82%; scroll-snap-align: start; }
}


/* ── Menu: links back out to the rest of RA10 ─────────────────────────── */
.ux-sitegrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 4px 6px 8px; }
.ux-sitelink { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: 14px; border: 1px solid var(--line, #ddd); background: var(--surface, #fff); color: var(--ink, #111); text-decoration: none; font: 700 0.76rem/1.1 inherit; }
.ux-sitelink svg { width: 20px; height: 20px; color: var(--accent); }
.ux-sitelink:hover, .ux-sitelink:focus-visible { border-color: var(--accent); }

/* ── Mobile header: one compact bar with a swipeable unit-tab strip ───── */
@media (max-width: 820px) {
  html.ux-unit body .topbar, html.ux-unit body.ra10-refresh-enabled .topbar {
    position: sticky !important; top: 0 !important; z-index: 7000 !important;
    display: grid !important; grid-template-columns: auto minmax(0, 1fr) auto !important;
    grid-template-areas: "brand chip actions" "tabs tabs tabs" !important;
    align-items: center !important; gap: 8px 10px !important;
    height: auto !important; min-height: 0 !important; margin: 0 !important; border-radius: 0 0 22px 22px !important;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 10px !important;
    overflow: visible !important;
  }
  html.ux-unit .topbar > .unit-brand { grid-area: brand; display: inline-flex !important; align-items: center; gap: 8px; margin: 0 !important; min-width: 0; }
  html.ux-unit .topbar > .unit-brand img { width: 28px !important; height: 28px !important; border-radius: 8px; }
  html.ux-unit .topbar > .unit-brand span { font-size: 1.1rem; }
  html.ux-unit .topbar > .site-unit-nav { display: none !important; }
  html.ux-unit .topbar .ux-jump { display: none !important; }
  html.ux-unit .topbar > div:not(.site-unit-nav):not(:last-child) { grid-area: chip; justify-self: end; margin: 0 !important; min-width: 0; }
  html.ux-unit .topbar > div:not(.site-unit-nav):not(:last-child) * { white-space: nowrap !important; }
  html.ux-unit .topbar > div:not(.site-unit-nav):not(:last-child) { font-size: 0.78rem; }
  html.ux-unit .topbar > div:not(.site-unit-nav):not(:last-child) button, html.ux-unit .topbar > div:not(.site-unit-nav):not(:last-child) [class*=chip] { padding: 5px 10px !important; min-height: 34px !important; }
  html.ux-unit .topbar > div:last-child { grid-area: actions; display: flex !important; align-items: center; gap: 6px !important; margin: 0 !important; }
  html.ux-unit .topbar > div:last-child .unit-avatar-btn { width: 36px !important; height: 36px !important; min-width: 36px; }
  html.ux-unit .topbar > .tabs, html.ux-unit body .topbar > nav.tabs {
    grid-area: tabs; display: flex !important; justify-content: flex-start !important; flex-wrap: nowrap !important; width: 100% !important; margin: 0 !important; order: 0 !important;
    gap: 4px !important; padding: 4px !important; border-radius: 999px !important; overflow-x: auto !important; scroll-snap-type: x proximity; scrollbar-width: none;
    background: var(--surface-soft, rgba(0, 0, 0, .05)) !important; -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%); mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  }
  html.ux-unit .topbar > .tabs::-webkit-scrollbar { display: none; }
  html.ux-unit .topbar > .tabs .tab { flex: none !important; scroll-snap-align: center; min-height: 40px !important; padding: 0 16px !important; border-radius: 999px !important; font-size: 0.86rem !important; font-weight: 700 !important; white-space: nowrap; display: inline-flex !important; align-items: center; }
  html.ux-unit .topbar > .tabs .tab.active { background: var(--accent) !important; color: #fff !important; box-shadow: 0 6px 14px -8px var(--accent) !important; }
  html.ux-unit main { padding-bottom: 104px; scroll-margin-top: 120px; }
}

/* Inside the site, the site's own bottom navbar is used - hide the unit's duplicate one. */
@media (max-width: 820px) {
  html.ux-embedded .ux-bottom { display: none !important; }
  html.ux-embedded.ux-unit main { padding-bottom: 28px; }
  .ux-menubtn { display: inline-grid !important; }
}
.ux-menubtn { display: none; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line, #ddd); background: var(--surface-soft, rgba(0,0,0,.04)); color: var(--ink, #111); cursor: pointer; }
.ux-menubtn svg { width: 18px; height: 18px; }

/* ── Inside the site: the site navbar is shown above us, so the unit header
      shrinks to just its section tabs (a slim sub-nav). ──────────────────── */
html.ux-embedded.ux-unit body .topbar, html.ux-embedded.ux-unit body.ra10-refresh-enabled .topbar {
  position: sticky !important; top: 0 !important; z-index: 7000 !important;
  display: flex !important; justify-content: center !important; align-items: center !important;
  min-height: 0 !important; height: auto !important; margin: 0 auto !important; padding: 8px 12px !important;
  border-radius: 0 0 20px 20px !important; grid-template-areas: none !important;
}
html.ux-embedded.ux-unit .topbar > .unit-brand,
html.ux-embedded.ux-unit .topbar > .site-unit-nav,
html.ux-embedded.ux-unit .topbar > div,
html.ux-embedded.ux-unit .topbar .ux-jump,
html.ux-embedded.ux-unit .ux-menubtn,
html.ux-embedded.ux-unit .ux-bottom { display: none !important; }
html.ux-embedded.ux-unit .topbar > .tabs, html.ux-embedded.ux-unit body .topbar > nav.tabs {
  display: flex !important; flex-wrap: nowrap !important; justify-content: flex-start !important; overflow-x: auto !important;
  max-width: 100% !important; width: auto !important; margin: 0 auto !important; gap: 4px !important; padding: 4px !important;
  border-radius: 999px !important; scrollbar-width: none; background: var(--surface-soft, rgba(0, 0, 0, .05)) !important;
}
html.ux-embedded.ux-unit .topbar > .tabs::-webkit-scrollbar { display: none; }
html.ux-embedded.ux-unit .topbar > .tabs .tab { flex: none !important; min-height: 38px !important; padding: 0 16px !important; border-radius: 999px !important; font-weight: 700 !important; white-space: nowrap; display: inline-flex !important; align-items: center; }
html.ux-embedded.ux-unit .topbar > .tabs .tab.active { background: var(--accent) !important; color: #fff !important; }
html.ux-embedded.ux-unit main { padding-bottom: 28px; }

/* Jumping to a section (anchors, scrollIntoView) lands below the sticky tab bar. */
html.ux-embedded { scroll-padding-top: calc(var(--ux-header-h, 60px) + 10px); }

/* Inside the site there is no unit header at all: the site navbar's section button
   (showing the current section, e.g. "Dashboard ▾") replaces the tab strip. */
html.ux-embedded.ux-unit body .topbar, html.ux-embedded.ux-unit body.ra10-refresh-enabled .topbar { display: none !important; }

/* ── Phone safety net for every unit: nothing may push the page wider than the screen ── */
@media (max-width: 820px) {
  /* grid/flex children default to min-width:auto, so one wide table stretches the whole column */
  html.ux-unit [class*="grid"] > *, html.ux-unit [class*="layout"] > *, html.ux-unit .papers-insight-card, html.ux-unit .papers-slot-block { min-width: 0; }
  html.ux-unit .papers-insight-card, html.ux-unit .papers-slot-block { max-width: 100%; box-sizing: border-box; }
  html.ux-unit .papers-table-wrap { max-width: 100%; }
  html.ux-unit .appendix { max-width: 100%; box-sizing: border-box; overflow-x: auto; }
  /* wide data tables scroll sideways inside their own box instead of the page */
  html.ux-unit .sql-result-table, html.ux-unit .appendix-table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  html.ux-unit img, html.ux-unit video, html.ux-unit canvas, html.ux-unit iframe, html.ux-unit svg:not([width]) { max-width: 100%; }
  html.ux-unit pre, html.ux-unit code { white-space: pre-wrap; word-break: break-word; }
}
