/* ═══════════════════════════════════════════════════════════════════════════
   底部浮層（手機從下面浮上來的一張卡；桌機是畫面中間的對話框）—— 設計系統組件
   計畫書 portal/assets/kit/DESIGN_SYSTEM_PLAN.md 第 4 步；外觀規格 docs/design-system/prototype/next.html 149～157
   （App 庫手機版 .nx-lib：左右 8px、離底 max(8px, 安全區)、圓角 30、把手 38×5）。
   互動 sheet.js（window.YkSheet）；登記檔 kit_registry.php 的 sheet；防線 portal/okr/tests/test_design_kit_sheet.php。

   1. 標記（自己寫的新浮層）：
        <div class="yk-sheet" id="…" hidden role="dialog" aria-modal="true" aria-labelledby="…-t">   ← 整層＝背幕（點了就關）
          <div class="yk-sheet-box">                                                             ← 卡片
            <div class="yk-sheet-head"><h2 class="yk-sheet-title" id="…-t">標題</h2>
              <button type="button" class="yk-sheet-x" data-yk-sheet-close aria-label="關閉">…</button></div>
            <div class="yk-sheet-body">…內容（太長自己捲）…</div>
            <div class="yk-sheet-foot">…按鈕…</div>                                               ← 選填
          </div>
        </div>
      開關：YkSheet.open(el)／YkSheet.close(el)；或頁面自己加減 hidden（屬性、class 都行，sheet.js 接得住）。
   2. 樣子由 sheet.js 依寬度掛在根節點上，**斷點是參數**（預設 640；data-yk-sheet-bp 或 attach 的 bp 改），不是寫死的 media query：
        is-sheet  ≤ 斷點：浮起來的卡片          is-dialog ＞ 斷點：置中的對話框
        is-in     進場的終點（開的轉場跑到這）    is-open   開著（底部分頁列的 data-yk-away 認它）
        is-full   拉成全螢幕（data-yk-sheet-full 的浮層才會）
        is-adopt  收養的既有視窗（舊的 bottom_sheet.* 轉接）：桌機照頁面自己畫、層級照頁面自己定、卡片不改成直的
        is-inner  卡片自己不捲、裡面那一格捲（有底部動作列的）
   3. Tailwind 排在 </head> 最後一行，同特異度時它贏。這支**不用 !important**：每一條會跟頁面 class 打架的規則，
      選擇器都至少兩個 class（.yk-sheet.is-sheet…），比 Tailwind 的單一 class（.z-50／.p-4／.rounded-md／.top-20）高，
      載入先後就不重要了。關著的狀態一律交給 hidden：這支從不在「可能還藏著」的根節點上設 display
      （舊的 bottom_sheet.css 用 display:flex !important 壓過 .hidden，2026-08-10 整頁一片黑就是這樣來的）。
   4. 層級：整層（背幕＋卡片是同一個元素）讀 --yk-z-backdrop，疊第二層往上加 2（sheet.js 寫在 style 上）。
      不放在 10001：選單、挑選器、App 庫在 10001，從浮層裡叫出來的選單要蓋得過浮層（計畫書 D64 同一招）。
      收養的視窗層級照頁面（財務 10000／10002、學習 ⓘ 10049）。
   5. 外觀讀共用數值：底色、細邊、投影、霧面＝--yk-float-*；動畫＝--yk-ease-*／--yk-dur-*（開慢關快）；
      背幕顏色＝--yk-scrim（2026-10 4A2 起，跟 App 庫同一個；留最後一層字面值 rgba(17,24,39,.30)／深色 rgba(0,0,0,.48)）。
      字色＝--yk-ink、✕ 的焦點圈＝--yk-accent、減少透明度時的實色底＝--yk-card（2026-10-10 D93：以前讀 theme_config 的
      --text-primary，沒載它的頁深色時掉回 #1f2937、深字配深底；頁面不必再在自己的浮層上補 --text-primary）。
      把手顏色沒有共用數值，照原型與 App 庫的字面值。
   6. 深色只認 html.dark（頁面切的）與 html.yk-dark（伺服器依 session 掛的）——同 tokens.css。
   7. 組件自己用的變數一律 --yks- 開頭，只在 .yk-sheet 上設；頁面可以調的只有 --sheet-w（桌機對話框最寬）；
      頁面可讀的有 --sheet-safe-bottom（卡片裡最下面那一列還要自己讓開底部橫條多少，見檔尾「頁面可讀」那一段）。
   ═══════════════════════════════════════════════════════════════════════════ */

.yk-sheet {
  --yks-fill: rgba(120,120,128,.13);
  --yks-fill-2: rgba(120,120,128,.21);
  --yks-scrim: var(--yk-scrim, rgba(17,24,39,.30));
  -webkit-tap-highlight-color: transparent;
}
html.dark .yk-sheet,
html.yk-dark .yk-sheet {
  --yks-fill: rgba(255,255,255,.09);
  --yks-fill-2: rgba(255,255,255,.16);
  --yks-scrim: var(--yk-scrim, rgba(0,0,0,.48));
}

/* 關著：hidden 屬性或 class 一律藏（頁面在根節點上多寫了 flex 之類的 class 也藏得住） */
.yk-sheet[hidden],
.yk-sheet.hidden { display: none; }

/* 自己寫的浮層：整層蓋滿畫面（含頂欄、底部分頁列）。收養的視窗本來就是 fixed inset-0，位置照頁面 */
.yk-sheet:not(.is-adopt) {
  position: fixed;
  inset: 0;
  z-index: var(--yk-z-backdrop, 10000);
  margin: 0;
  padding: 0;
  border: 0;
}
.yk-sheet-box { box-sizing: border-box; }
/* 焦點停在卡片本身（打開時移進來的那一下）不畫框：卡片不是可以按的東西 */
.yk-sheet-box:focus { outline: none; }

/* ═════════ 手機（≤ 斷點）：浮起來的卡片 ═════════ */
.yk-sheet.is-sheet {
  overflow: hidden;
  padding: 0;
  overscroll-behavior: contain;
  background-color: transparent;
  transition: background-color var(--yk-dur-close-fade, .18s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1));
}
.yk-sheet.is-sheet.is-in {
  background-color: var(--yks-scrim);
  transition: background-color var(--yk-dur-open-fade, .32s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
}
.yk-sheet.is-sheet > .yk-sheet-box {
  position: fixed;
  left: 8px;
  right: 8px;
  top: auto;
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
  width: auto;
  min-width: 0;
  max-width: none;
  height: auto;
  min-height: 0;
  /* 高度跟著內容，最高到 max(96px, 20vh) 那條線（原型 .nx-lib 的 top）；再多就在裡面捲 */
  max-height: calc(100% - max(96px, 20vh) - max(8px, env(safe-area-inset-bottom, 0px)));
  margin: 0;
  border: 1px solid var(--yk-float-line, rgba(15,23,42,.08));
  border-radius: 30px;
  background: var(--yk-float-bg, rgba(255,255,255,.9));
  -webkit-backdrop-filter: var(--yk-float-blur, saturate(170%) blur(14px));
  backdrop-filter: var(--yk-float-blur, saturate(170%) blur(14px));
  box-shadow: var(--yk-float-shadow, 0 1px 2px rgba(15,23,42,.06), 0 10px 22px -10px rgba(15,23,42,.24), 0 26px 48px -22px rgba(15,23,42,.34));
  transform: translateY(calc(100% + 40px));
  transition: transform var(--yk-dur-close, .24s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1)),
              top .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)), bottom .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)),
              left .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)), right .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)),
              border-radius .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
}
/* 開著的終點是 transform: none（不是 translateY(0)：那樣卡片還是會變成裡面 fixed 東西的定位基準） */
.yk-sheet.is-sheet.is-in > .yk-sheet-box {
  transform: none;
  transition: transform var(--yk-dur-open, .46s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1)),
              top .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)), bottom .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)),
              left .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)), right .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)),
              border-radius .32s var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
}
/* 把手 38×5（原型 .lib-grab::before）：畫在卡片上緣，不佔版面、不擋點擊 */
.yk-sheet.is-sheet > .yk-sheet-box::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 8px;
  width: 38px;
  height: 5px;
  margin-left: -19px;
  border-radius: 999px;
  background: var(--yks-fill-2);
  pointer-events: none;
}
/* 拉成全螢幕（原型 .nx-lib.full）：圓角 0、貼滿；上緣讓開瀏海 */
.yk-sheet.is-sheet.is-full > .yk-sheet-box {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: none;
  border-width: 0;
  border-radius: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);   /* 貼到底了：底下的按鈕讓開 iPhone 的底部橫條 */
}
.yk-sheet.is-sheet.is-full > .yk-sheet-box::before { top: calc(env(safe-area-inset-top, 0px) + 8px); }
/* 收養的視窗：卡片自己捲（舊的 bottom_sheet 也是）；is-inner＝裡面那一格捲，卡片不捲（不然兩層捲軸） */
.yk-sheet.is-sheet.is-adopt > .yk-sheet-box {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.yk-sheet.is-sheet.is-adopt.is-inner > .yk-sheet-box { overflow: hidden; }

/* ═════════ 桌機（＞ 斷點）：置中的對話框（收養的視窗不掛 is-dialog，照頁面自己畫） ═════════ */
.yk-sheet.is-dialog:not([hidden]):not(.hidden) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
/* 背幕另寫一條、特異度比 is-in 低：寫在上面那條（:not 讓它高一截）的話，打開了背幕還是透明的 */
.yk-sheet.is-dialog {
  background-color: transparent;
  transition: background-color var(--yk-dur-close-fade, .18s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1));
}
.yk-sheet.is-dialog.is-in {
  background-color: var(--yks-scrim);
  transition: background-color var(--yk-dur-open-fade, .32s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
}
.yk-sheet.is-dialog > .yk-sheet-box {
  position: relative;
  width: 100%;
  max-width: var(--sheet-w, 560px);
  max-height: min(720px, 100%);
  margin: 0;
  border: 1px solid var(--yk-float-line, rgba(15,23,42,.08));
  border-radius: var(--yk-float-radius, 22px);
  background: var(--yk-float-bg, rgba(255,255,255,.9));
  -webkit-backdrop-filter: var(--yk-float-blur, saturate(170%) blur(14px));
  backdrop-filter: var(--yk-float-blur, saturate(170%) blur(14px));
  box-shadow: var(--yk-float-shadow, 0 1px 2px rgba(15,23,42,.06), 0 10px 22px -10px rgba(15,23,42,.24), 0 26px 48px -22px rgba(15,23,42,.34));
  opacity: 0;
  transform: scale(.96);
  transition: opacity var(--yk-dur-close-fade, .18s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1)),
              transform var(--yk-dur-close, .24s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1));
}
.yk-sheet.is-dialog.is-in > .yk-sheet-box {
  opacity: 1;
  transform: none;
  transition: opacity var(--yk-dur-open-fade, .32s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1)),
              transform var(--yk-dur-open, .46s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
}

/* ═════════ 自己寫的浮層的內部：標題列、內容（自己捲）、底部按鈕 ═════════ */
.yk-sheet:not(.is-adopt) > .yk-sheet-box {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--yk-ink, #1f2937);   /* 組件的字色讀共用數值、跟 --yk-float-bg 同一個深色開關（D93）；標題、✕ 繼承它 */
  text-align: left;
}
.yk-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 10px 8px 4px 20px;
}
/* 手機：上緣 22px 是把手那一條（原型 .lib-grab），標題列從它下面開始；按住標題列可以拖 */
.yk-sheet.is-sheet .yk-sheet-head {
  padding: 22px 6px 0 18px;
  touch-action: none;
  cursor: grab;
}
.yk-sheet-title {
  margin: 0;
  min-width: 0;
  font-size: 17px;
  font-weight: 650;
  line-height: 1.3;
  color: inherit;
  overflow-wrap: anywhere;
}
.yk-sheet .yk-sheet-x {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.yk-sheet .yk-sheet-x svg {
  display: block;
  width: 36px;
  height: 36px;
  padding: 8px;
  border-radius: 999px;
  background: var(--yks-fill);
  transition: background .15s;
}
.yk-sheet .yk-sheet-x:hover svg { background: var(--yks-fill-2); }
.yk-sheet .yk-sheet-x:focus-visible { outline: none; }
.yk-sheet .yk-sheet-x:focus-visible svg { box-shadow: 0 0 0 2px var(--yk-accent, #2563eb); }
.yk-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px 20px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  overflow-wrap: anywhere;
}
.yk-sheet-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 16px 16px;
  border-top: 1px solid var(--yk-float-line, rgba(15,23,42,.08));
}
/* 下緣讀 --sheet-safe-bottom（見下一段；浮起來的卡片＝0，所以就是 14px）：組件自己的按鈕列跟頁面的按鈕列照同一條規則 */
.yk-sheet.is-sheet .yk-sheet-foot { padding: 10px 14px calc(14px + var(--sheet-safe-bottom, 0px)); }

/* 頁面可讀（2026-10 4A2，計畫書 D83③）：卡片裡最下面那一列，還要自己讓開 iPhone 底部橫條多少。
   預設＝整個安全區（組件沒有替它讓：桌機置中的對話框、641 以上照頁面自己畫的收養視窗）；
   浮起來的卡片（含拉成全螢幕）組件已經讓開了＝0——頁面再讓一次就變兩倍（月底認列細節多出約 34px 就是這樣來的）。
   收養視窗裡頁面自己的按鈕列這樣寫（退路＝沒載到組件時照舊自己讓）：
     padding-bottom: calc(12px + var(--sheet-safe-bottom, env(safe-area-inset-bottom, 0px)));
   不要寫成 .yk-sheet.is-sheet .你的列 {…}：頁面規則打到組件的 class 會被 test_design_kit.php ② 擋 */
.yk-sheet { --sheet-safe-bottom: env(safe-area-inset-bottom, 0px); }
.yk-sheet.is-sheet { --sheet-safe-bottom: 0px; }

/* 開著時底下那頁不能捲（舊的 bottom_sheet 也是這一招：body 不捲、捲動位置不動） */
body.yk-sheet-lock { overflow: hidden; }

/* ═════════ 嵌入頁的滑出卡（YkSheet.frame；2026-11-23 鈴鐺 × 待辦小圓 P4b）═════════
   蓋在一張卡片（over）上：整層的位置、大小、圓角由 sheet.js 照 over 寫在 style 上；卡片從它底下滑上來，內容是同源的另一頁（iframe）。
   層級比 over（--yk-z-drawer 那一層的卡片）高一層，確認框、提示訊息照舊蓋在它上面。
   底色：那一頁畫好之前是 --yk-card，畫好之後跟著那一頁（sheet.js 寫進 --yks-frame-bg）；把手照上面浮層的寫法（沒有共用數值） */
.yk-fsheet {
  position: fixed;
  z-index: calc(var(--yk-z-drawer, 10001) + 1);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.yk-fsheet-bg {
  position: absolute;
  inset: 0;
  background: var(--yk-scrim, rgba(17,24,39,.30));
  animation: yk-fsheet-fade var(--yk-dur-open-fade, .32s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
  transition: opacity var(--yk-dur-close-fade, .18s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1));
}
.yk-fsheet.is-closing .yk-fsheet-bg { opacity: 0; }
.yk-fsheet-box {
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  height: 380px;
  max-height: 100%;
  overflow: hidden;
  border-radius: 22px 22px 0 0;
  background: var(--yks-frame-bg, var(--yk-card, #fff));
  color: var(--yk-ink, #1f2937);
  box-shadow: var(--yk-float-shadow, 0 1px 2px rgba(15,23,42,.06), 0 10px 22px -10px rgba(15,23,42,.24), 0 26px 48px -22px rgba(15,23,42,.34));
  animation: yk-fsheet-up var(--yk-dur-open, .46s) var(--yk-ease-open, cubic-bezier(.16,1,.3,1));
  transition: height .28s var(--yk-ease-open, cubic-bezier(.16,1,.3,1)), transform var(--yk-dur-close, .24s) var(--yk-ease-close, cubic-bezier(.4,0,.2,1));
}
/* 整頁的擺法（o.page）：蓋滿畫面，卡片從頂端留一道縫往下鋪滿；那一頁自己捲，外面不捲 */
.yk-fsheet.is-page { inset: 0; height: auto; }
.yk-fsheet.is-page > .yk-fsheet-box { height: calc(100% - env(safe-area-inset-top, 0px) - 10px); }
.yk-fsheet.is-page .yk-fsheet-body { overflow: hidden; }
.yk-fsheet.is-closing .yk-fsheet-box { transform: translateY(108%); }
.yk-fsheet-box.is-drag { transition: none; }
.yk-fsheet-box:focus { outline: none; }
.yk-fsheet-grab {
  flex: 0 0 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.yk-fsheet-grab:active { cursor: grabbing; }
.yk-fsheet-grip { display: block; width: 38px; height: 5px; border-radius: 999px; background: color-mix(in srgb, var(--yk-ink, #1f2937) 22%, transparent); }
.yk-fsheet-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* 畫好之前 iframe 透明（iOS 在 iframe 載入中會先塗白），底下鋪骨架 */
.yk-fsheet-frame { display: block; width: 100%; height: 100%; border: 0; background: transparent; opacity: 0; transition: opacity .22s ease; }
.yk-fsheet.is-ready .yk-fsheet-frame { opacity: 1; }
.yk-fsheet-skel { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px; padding: 16px 22px 18px; pointer-events: none; transition: opacity .2s ease; }
.yk-fsheet.is-ready .yk-fsheet-skel { opacity: 0; visibility: hidden; }
.yk-fsheet-skel i { display: block; height: 12px; border-radius: 7px; background: color-mix(in srgb, var(--yk-ink, #1f2937) 10%, transparent); }
.yk-fsheet-skel i:nth-child(1) { width: 38%; }
.yk-fsheet-skel i:nth-child(2) { width: 72%; height: 22px; }
.yk-fsheet-skel i:nth-child(3) { width: 90%; }
.yk-fsheet-skel i:nth-child(4) { width: 55%; }
.yk-fsheet-skel i:nth-child(5) { width: 100%; height: 56px; margin-top: 6px; border-radius: 12px; }
.yk-fsheet-slow { pointer-events: auto; align-self: center; display: inline-flex; align-items: center; min-height: 44px; margin-top: auto; font-size: 13px; font-weight: 600; color: var(--yk-accent, #2563eb); text-decoration: none; }
.yk-fsheet-slow[hidden] { display: none; }
@keyframes yk-fsheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes yk-fsheet-fade { from { opacity: 0; } to { opacity: 1; } }

/* 減少動態：整個不跑轉場（同 App 庫 D47：一打開就看得見，焦點進得去） */
@media (prefers-reduced-motion: reduce) {
  .yk-sheet.is-sheet,
  .yk-sheet.is-sheet.is-in,
  .yk-sheet.is-dialog,
  .yk-sheet.is-dialog.is-in,
  .yk-sheet.is-sheet > .yk-sheet-box,
  .yk-sheet.is-sheet.is-in > .yk-sheet-box,
  .yk-sheet.is-dialog > .yk-sheet-box,
  .yk-sheet.is-dialog.is-in > .yk-sheet-box { transition: none; }
  .yk-fsheet-bg,
  .yk-fsheet-box,
  .yk-fsheet-frame,
  .yk-fsheet-skel { animation: none; transition: none; }
}
/* 減少透明度：霧面換成實色（同 App 庫） */
@media (prefers-reduced-transparency: reduce) {
  .yk-sheet.is-sheet > .yk-sheet-box,
  .yk-sheet.is-dialog > .yk-sheet-box { background: var(--yk-card, #fff); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
