/*
 * 前台「液態玻璃」風格（後台「個人化預覽 → 前台風格」開關）
 *
 * 只有 <html class="lg"> 時才有效果：
 *   - 開關打開時，src/views/header.php 在 <html> 加上 lg 並載入這個檔案
 *   - 後台預覽框裡由個人化預覽頁即時切換（AdminPreview::pageScript）
 * 後台頁面不載入這個檔案，所以不受影響。
 *
 * 做法：頁面背景鋪一層柔和的光暈（主色、AI 點綴色與兩個輔助色），
 * 導覽列、卡片、底部選單、對話框等改成半透明＋背景模糊（backdrop-filter）的玻璃，
 * 邊緣加一圈高光、按鈕按下時有彈性縮放。顏色都用配色變數，自訂配色、會員配色都會跟著變。
 */

/* ── 材質參數 ─────────────────────────────────────────── */
html.lg {
  --lg-base: #edf3ea;                              /* 光暈下面的底色 */
  --lg-fill: rgba(255, 255, 255, .56);             /* 卡片 */
  --lg-fill-strong: rgba(255, 255, 255, .78);      /* 選單、對話框、輸入框 */
  --lg-fill-soft: rgba(255, 255, 255, .42);        /* 標籤、次要按鈕、卡片裡的卡片 */
  --lg-sheen: linear-gradient(150deg, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 48%);
  --lg-rim: rgba(255, 255, 255, .95);              /* 邊緣高光 */
  --lg-rim-soft: rgba(255, 255, 255, .28);
  --lg-blur: 20px;
  --lg-sat: 180%;
  --lg-shadow: 0 12px 32px -12px rgba(22, 52, 26, .22), 0 2px 6px rgba(22, 52, 26, .06);
  --lg-inner: inset 0 1px 0 rgba(255, 255, 255, .8), inset 0 -1px 0 rgba(255, 255, 255, .25);
  --lg-spring: cubic-bezier(.34, 1.56, .64, 1);
  /* 原本不透明的面改成半透明 */
  --sp-surface: rgba(255, 255, 255, .62);
  --sp-chip-bg: rgba(255, 255, 255, .55);
  --sp-upload-bg: rgba(255, 255, 255, .38);
  --sp-line: rgba(30, 60, 30, .08);
  --sp-line-strong: rgba(30, 60, 30, .13);
  --sp-muted: #5c665c;                             /* 半透明底上的灰字加深一點，維持對比 */
  --bs-border-color: rgba(30, 60, 30, .16);
}
html.lg[data-bs-theme="dark"] {
  --lg-base: #0e1410;
  --lg-fill: rgba(34, 38, 35, .55);
  --lg-fill-strong: rgba(36, 40, 37, .82);
  --lg-fill-soft: rgba(255, 255, 255, .07);
  --lg-sheen: linear-gradient(150deg, rgba(255, 255, 255, .09), rgba(255, 255, 255, 0) 48%);
  --lg-rim: rgba(255, 255, 255, .26);
  --lg-rim-soft: rgba(255, 255, 255, .05);
  --lg-shadow: 0 14px 34px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
  --lg-inner: inset 0 1px 0 rgba(255, 255, 255, .13), inset 0 -1px 0 rgba(255, 255, 255, .04);
  --sp-surface: rgba(40, 44, 41, .62);
  --sp-chip-bg: rgba(255, 255, 255, .08);
  --sp-upload-bg: rgba(255, 255, 255, .04);
  --sp-line: rgba(255, 255, 255, .07);
  --sp-line-strong: rgba(255, 255, 255, .11);
  --sp-muted: #a3aca3;
  --bs-border-color: rgba(255, 255, 255, .14);
}
@media (max-width: 575.98px) { html.lg { --lg-blur: 16px; } }

/* ── 背景光暈（固定不動，捲動時玻璃後面的顏色才會流動） ─── */
html.lg body { background: var(--lg-base); }
html.lg body::before {
  content: ""; position: fixed; inset: -10vmax; z-index: -1; pointer-events: none;
  /* 不支援 color-mix 的瀏覽器用這組固定顏色 */
  background:
    radial-gradient(40vmax 40vmax at 12% 8%, rgba(46, 125, 50, .34), transparent 70%),
    radial-gradient(36vmax 36vmax at 92% 20%, rgba(239, 108, 0, .22), transparent 70%),
    radial-gradient(44vmax 44vmax at 80% 92%, rgba(38, 166, 154, .26), transparent 70%),
    radial-gradient(34vmax 34vmax at 8% 84%, rgba(255, 213, 79, .3), transparent 70%),
    var(--lg-base);
  background:
    radial-gradient(40vmax 40vmax at 12% 8%, color-mix(in srgb, var(--sp-green) 34%, transparent), transparent 70%),
    radial-gradient(36vmax 36vmax at 92% 20%, color-mix(in srgb, var(--sp-ai-icon) 24%, transparent), transparent 70%),
    radial-gradient(44vmax 44vmax at 80% 92%, color-mix(in srgb, #26a69a 26%, transparent), transparent 70%),
    radial-gradient(34vmax 34vmax at 8% 84%, color-mix(in srgb, #ffd54f 30%, transparent), transparent 70%),
    var(--lg-base);
}
html.lg[data-bs-theme="dark"] body::before { opacity: .55; }

/* ── 玻璃面 ───────────────────────────────────────────── */
html.lg .card,
html.lg .modal-content,
html.lg .dropdown-menu,
html.lg .offcanvas,
html.lg .toast,
html.lg .bottom-nav {
  background-color: var(--lg-fill);
  background-image: var(--lg-sheen);
  -webkit-backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-sat));
  backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-sat));
  border: 0;
  box-shadow: var(--lg-shadow), var(--lg-inner);
}
html.lg .modal-content, html.lg .dropdown-menu, html.lg .offcanvas, html.lg .toast { background-color: var(--lg-fill-strong); }
/* 下拉選單通常在玻璃卡片裡，背景模糊只作用在那張卡片內、模糊不到隔壁卡片：用不透明的底，文字才清楚 */
html.lg .dropdown-menu { background-color: #fff; }
html.lg[data-bs-theme="dark"] .dropdown-menu { background-color: #2b2e2c; }
html.lg .card { border-radius: 20px; }
html.lg .card-header { border-radius: 20px 20px 0 0 !important; }
html.lg .card-footer { border-radius: 0 0 20px 20px !important; }
/* 卡片邊緣一圈高光（左上亮、右下淡），像玻璃的厚度 */
html.lg .card::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(145deg, var(--lg-rim), var(--lg-rim-soft) 28%, transparent 55%, var(--lg-rim-soft) 82%, var(--lg-rim));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
/* 玻璃卡片會自成一個圖層：裡面的下拉選單（例如庫存的「⋯」）打開時，把整張卡片提到最上層，選單才不會被下一張卡片蓋住 */
html.lg .card:has(.dropdown-menu.show) { z-index: 1000; }
/* 卡片裡的卡片：不再模糊一次（省效能），只留淡淡的面 */
html.lg .card .card { background-color: var(--lg-fill-soft); -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: var(--lg-inner); }
/* 卡片裡原本白底的標頭、頁尾、表格、清單改成透明，透出玻璃 */
html.lg .card-header, html.lg .card-footer,
html.lg .card .bg-white, html.lg .card .bg-body, html.lg .card .bg-light { background-color: transparent !important; }
html.lg .table { --bs-table-bg: transparent; }
html.lg .table-light { --bs-table-bg: var(--lg-fill-soft); --bs-table-color: inherit; --bs-table-border-color: var(--sp-line-strong); }
html.lg .list-group { --bs-list-group-bg: transparent; --bs-list-group-border-color: var(--sp-line-strong); }
html.lg .accordion { --bs-accordion-bg: transparent; --bs-accordion-border-color: var(--sp-line-strong); --bs-accordion-active-bg: color-mix(in srgb, var(--sp-green) 10%, transparent); }
/* 有底色意義的卡片保留色調（半透明） */
html.lg .stat-card.is-alert, html.lg .pantry-card.expired { background-color: color-mix(in srgb, var(--sp-expired-bg) 72%, transparent); }
html.lg .ai-card, html.lg .feature-ai { background-image: linear-gradient(150deg, color-mix(in srgb, var(--sp-ai-from) 88%, transparent), transparent 70%); }
html.lg .item-row { border: 0; }
html.lg a.stat-card { transition: transform .35s var(--lg-spring), box-shadow .2s; }

/* ── 導覽列：主色的有色玻璃 ─────────────────────────────── */
html.lg .app-navbar {
  background: transparent;
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  box-shadow: 0 10px 28px -14px rgba(0, 0, 0, .35), inset 0 -1px 0 rgba(255, 255, 255, .2);
}
html.lg .app-navbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background: var(--sp-navbar); opacity: .84;
}
html.lg .app-navbar::after { /* 上緣一道高光 */
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent);
}

/* ── 手機底部選單：浮起來的玻璃膠囊，選中的分頁有一顆玻璃透鏡 ── */
html.lg .bottom-nav {
  left: 10px; right: 10px; bottom: calc(8px + env(safe-area-inset-bottom));
  padding: 7px 4px; border-radius: 28px; background-color: var(--lg-fill-strong);
}
html.lg .bottom-nav a { position: relative; z-index: 0; padding: 3px 0; border-radius: 20px; transition: transform .4s var(--lg-spring), color .2s; }
html.lg .bottom-nav a:active { transform: scale(.9); }
html.lg .bottom-nav a.active:not(.scan)::before {
  content: ""; position: absolute; inset: -3px 6px; z-index: -1; border-radius: 20px;
  background: color-mix(in srgb, var(--sp-green) 13%, rgba(255, 255, 255, .35));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7), 0 2px 8px -2px rgba(0, 0, 0, .12);
}
html.lg[data-bs-theme="dark"] .bottom-nav a.active:not(.scan)::before { background: color-mix(in srgb, var(--sp-green) 26%, rgba(255, 255, 255, .06)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14); }
html.lg .bottom-nav a.scan i {
  border-color: transparent;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .32), rgba(255, 255, 255, 0) 55%);
  box-shadow: 0 8px 18px -6px color-mix(in srgb, var(--sp-green) 75%, transparent), inset 0 1px 0 rgba(255, 255, 255, .55), 0 0 0 4px var(--lg-fill-strong);
}
/* 拖曳用的玻璃透鏡（assets/glass.js）：按住底部選單左右滑動時出現，跟著手指走、放大底下的圖示 */
html.lg .bottom-nav { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.lg .bottom-nav a { -webkit-user-drag: none; }
html.lg .bottom-nav a.active:not(.scan)::before { transition: opacity .2s ease; }
html.lg .bottom-nav.is-lensing a.active::before { opacity: 0; }
html.lg .bottom-nav.is-lensing a:active { transform: none; }
.lg-lens {
  --lens-bg: rgba(249, 251, 249, .97);
  position: absolute; left: 0; z-index: 2; border-radius: 999px; overflow: hidden; pointer-events: none;
  opacity: 0; transform-origin: 50% 50%; will-change: transform, opacity;
  background: var(--lens-bg);
  box-shadow: 0 12px 28px -8px rgba(0, 0, 0, .3), 0 2px 6px rgba(0, 0, 0, .08);
}
html.lg[data-bs-theme="dark"] .lg-lens { --lens-bg: rgba(54, 59, 56, .97); box-shadow: 0 12px 28px -8px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .4); }
/* 放大的選單複本：全部染上主色（像透鏡把顏色聚起來） */
.lg-lens-view { position: absolute; left: 0; top: 0; display: flex; justify-content: space-around; align-items: flex-end; transform-origin: 0 0; pointer-events: none; }
.lg-lens-view a { color: var(--sp-accent) !important; font-weight: 700; }
.lg-lens-view a::before { display: none !important; }
/* 邊緣那一圈放得更大，蓋住中間層的邊緣：看起來像玻璃邊緣的折射扭曲 */
.lg-lens-ring {
  position: absolute; inset: 0; background: var(--lens-bg);
  -webkit-mask: radial-gradient(closest-side, transparent 64%, #000 90%);
  mask: radial-gradient(closest-side, transparent 64%, #000 90%);
}
/* 高光：上緣一道亮光、底部一圈主色的焦散光、邊緣一圈亮邊 */
.lg-lens::before, .lg-lens::after { content: ""; position: absolute; inset: 0; z-index: 3; border-radius: inherit; pointer-events: none; }
.lg-lens::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 36%),
    radial-gradient(120% 60% at 50% 118%, color-mix(in srgb, var(--sp-green) 24%, transparent), transparent 62%);
}
.lg-lens::after { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .8), inset 0 2px 3px rgba(255, 255, 255, .9), inset 0 -3px 8px rgba(0, 0, 0, .07), inset 0 0 14px rgba(255, 255, 255, .45); }
html.lg[data-bs-theme="dark"] .lg-lens::before { background: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 36%), radial-gradient(120% 60% at 50% 118%, color-mix(in srgb, var(--sp-green) 34%, transparent), transparent 62%); }
html.lg[data-bs-theme="dark"] .lg-lens::after { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .22), inset 0 2px 3px rgba(255, 255, 255, .2), inset 0 -3px 8px rgba(0, 0, 0, .3); }
html.lg .has-bottom-nav main { padding-bottom: 96px !important; }
html.lg .has-bottom-nav .app-footer { padding-bottom: 108px !important; }

/* ── 訪客體驗提示列 ───────────────────────────────────── */
html.lg .guest-bar {
  background: color-mix(in srgb, var(--sp-ai-from) 72%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
}

/* ── 按鈕：有光澤的果凍感，按下時彈一下 ─────────────────── */
html.lg .btn { transition: transform .4s var(--lg-spring), box-shadow .2s ease, background-color .2s ease, color .2s ease; }
html.lg .btn:active:not(:disabled) { transform: scale(.95); }
html.lg .btn-success, html.lg .btn-primary {
  border-color: transparent;
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .26), rgba(255, 255, 255, 0) 58%);
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--sp-green) 80%, transparent), inset 0 1px 0 rgba(255, 255, 255, .45), inset 0 -1px 0 rgba(0, 0, 0, .08);
}
/* 外框按鈕：平常是一片淡淡的玻璃（用按鈕的底色變數，選取、滑過、按下時的顏色照常） */
html.lg .card .btn-outline-success, html.lg .card .btn-outline-secondary, html.lg .card .btn-outline-primary,
html.lg .card .btn-outline-danger, html.lg .card .btn-outline-warning, html.lg main > .btn-outline-secondary {
  --bs-btn-bg: var(--lg-fill-soft);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55);
}
html.lg[data-bs-theme="dark"] .card [class*="btn-outline-"] { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08); }

/* ── 輸入框、標籤 ─────────────────────────────────────── */
html.lg .form-control, html.lg .form-select, html.lg .input-group-text { background-color: var(--lg-fill-strong); }
html.lg[data-bs-theme="dark"] .form-control, html.lg[data-bs-theme="dark"] .form-select, html.lg[data-bs-theme="dark"] .input-group-text { background-color: rgba(0, 0, 0, .28); }
html.lg .chip, html.lg .badge.text-bg-light { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5); }

/* ── 開關：液態玻璃開關（膠囊軌道＋會彈的玻璃圓鈕） ─────── */
html.lg .form-switch .form-check-input {
  width: 2.75em; height: 1.55em; margin-top: -.05em; border: 0; border-radius: 1em;
  background-color: rgba(120, 120, 128, .24);
  --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 16 16'%3e%3cdefs%3e%3cfilter id='s' x='-50%25' y='-50%25' width='200%25' height='200%25'%3e%3cfeDropShadow dx='0' dy='.8' stdDeviation='.9' flood-opacity='.28'/%3e%3c/filter%3e%3clinearGradient id='g' x1='0' y1='0' x2='0' y2='1'%3e%3cstop offset='0' stop-color='%23fff'/%3e%3cstop offset='1' stop-color='%23f1f3f1'/%3e%3c/linearGradient%3e%3c/defs%3e%3ccircle r='5.6' fill='url(%23g)' filter='url(%23s)'/%3e%3c/svg%3e");
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .14), inset 0 0 0 1px rgba(255, 255, 255, .25);
  transition: background-position .45s var(--lg-spring), background-color .25s ease, box-shadow .25s ease;
}
html.lg .form-switch .form-check-input:checked {
  background-color: var(--sp-green);
  --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-8 -8 16 16'%3e%3cdefs%3e%3cfilter id='s' x='-50%25' y='-50%25' width='200%25' height='200%25'%3e%3cfeDropShadow dx='0' dy='.8' stdDeviation='.9' flood-opacity='.28'/%3e%3c/filter%3e%3clinearGradient id='g' x1='0' y1='0' x2='0' y2='1'%3e%3cstop offset='0' stop-color='%23fff'/%3e%3cstop offset='1' stop-color='%23f1f3f1'/%3e%3c/linearGradient%3e%3c/defs%3e%3ccircle r='5.6' fill='url(%23g)' filter='url(%23s)'/%3e%3c/svg%3e");
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .35), 0 4px 12px -4px color-mix(in srgb, var(--sp-green) 70%, transparent);
}
html.lg .form-switch .form-check-label { padding-left: .3em; }

/* ── 減少透明度、或瀏覽器不支援背景模糊：改用幾乎不透明的面，文字一定清楚 ── */
@media (prefers-reduced-transparency: reduce) {
  html.lg { --lg-fill: rgba(255, 255, 255, .95); --lg-fill-strong: #fff; --lg-fill-soft: rgba(255, 255, 255, .8); }
  html.lg[data-bs-theme="dark"] { --lg-fill: rgba(36, 38, 36, .96); --lg-fill-strong: #262826; --lg-fill-soft: rgba(255, 255, 255, .06); }
  html.lg .app-navbar::before { opacity: 1; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  html.lg { --lg-fill: rgba(255, 255, 255, .9); --lg-fill-strong: rgba(255, 255, 255, .96); }
  html.lg[data-bs-theme="dark"] { --lg-fill: rgba(36, 38, 36, .92); --lg-fill-strong: rgba(36, 38, 36, .97); }
  html.lg .app-navbar::before { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html.lg .btn, html.lg .bottom-nav a, html.lg .form-switch .form-check-input { transition: none; }
}
