/* ============================================================
   望遠鏡工作台的器材槽：OWL 的外框與主題對應（2026-10-08 第四階段 #19 的 /tools/owl；2026-10-09 合併計畫 S5 搬進工作台）
   docs/telescope_owl_merge_plan.md §6.2、D8；docs/owl_stage4_plan.md §4、決定 E9；OWL 的 host contract 在 OWL 的
   packages/owlastro-web/src/owlastro_web/frontend/README.md（Theme tokens）。

   · 槽＝模板「器材」工作區裡的 div.owl-host#owlHost[data-owl-slot]（owl_host.js 掛在這裡）；版面（填滿任務面板、全寬時讓出天空小窗）
     在 telescope_shell.css。這裡只管 OWL 讀的 token、殼層高度、檢查中與連不上的樣子。
   · OWL 用 theme:"host"：讀這裡定義的 --kw-*（Kinder／castorGUI 的名字），沒定義的才用它的深色預設；
     OWL 自己的 css 全部在 .owl-app 底下，不會改到本站其他東西。切主題只靠 CSS 變數，不需要 JS。
   · 語意色（danger／warning／success）EAU 沒有，這裡給深、亮兩組明確的值；
     對比用 scripts/owl_host_contrast.py 驗（文字 ≥ 4.5:1、控制項邊框與焦點框 ≥ 3:1，WCAG 2.2 SC 1.4.3／1.4.11）。
     改了 theme.css 或這裡的色值就重跑一次。
   · 天文紅光（data-theme="astro"）沿用深色 token，整頁濾鏡由 theme.css 負責；OWL 自己的紅光開關由 night:false 藏起來。
   · 選擇器保持「一個區塊一個選擇器、不放進 @media」：對比腳本照選擇器字面讀這幾塊。
   ============================================================ */

/* ── 深色（預設；astro 也用這組）── */
.owl-host {
    --kw-text-primary: var(--color-text);
    --kw-text-muted: var(--color-text-muted);
    --kw-glass-bg: var(--color-surface);
    --kw-border: var(--color-border);
    --kw-accent: var(--color-accent);
    --kw-accent-hover: var(--color-accent-hover);
    /* 2026-10-11 望遠鏡工作台 v2 第 1 期：OWL 新版器材區的實心按鈕字色、清單列的浮起底色（亮色主題跟著 theme.css 換） */
    --kw-accent-text: var(--color-accent-text);
    --kw-surface-elevated: var(--color-surface-elevated);
    --kw-color-danger: #f87171;
    --kw-color-warning: #fbbf24;
    --kw-color-success: #4ade80;

    /* OWL 站多高（host contract 第 6 步）：槽的高度，由 owl_host.js 用 ResizeObserver 量了寫進來（2026-10-09，不再是「視窗 − 導覽列 − 標題列」）；
       量到之前用這個保守值（OWL 只在打開「器材」之後才掛上，那時已經量好） */
    --owl-shell-height: 480px;

    display: flex; flex-direction: column;
    min-width: 0;
    background: transparent;    /* 透出任務面板的底；OWL 的 host 主題也不畫自己的底 */
}

/* ── 亮色：語意色換成 OWL 亮色主題的值（owl.css 的 .owl-app[data-owl-theme="light"]），器材槽墊平的底 ── */
:root[data-theme="light"] .owl-host {
    --kw-color-danger: #b91c1c;
    --kw-color-warning: #92400e;
    --kw-color-success: #166534;
    /* 亮色 body 的暖色光暈在左上角最濃，淡色文字（--color-text-muted）在那裡只剩 4.1:1；
       OWL 很多字直接寫在底上，所以器材槽墊平的 --color-bg（4.8:1） */
    background: var(--color-bg);
}
/* OWL 的 host 主題是「host token 疊在深色預設上」，它自己的控制項底色（--owl-surface）、提示框底色、直方圖色與
   color-scheme 沒有對應的 --kw-*，亮色主題下會變成深底深字；這裡換成 OWL 亮色主題的值，控制項底色用本站的卡片底色。
   紅光模式（.owl-night）不動（night:false，OWL 不會進紅光）。 */
:root[data-theme="light"] .owl-host .owl-app[data-owl-theme="host"]:not(.owl-night) {
    --owl-surface: var(--color-surface);
    --owl-danger-bg: #fdecec;
    --owl-warning-bg: #fdf3e3;
    --owl-hist-r: #b91c1c;
    --owl-hist-g: #166534;
    --owl-hist-b: #1d4ed8;
    color-scheme: light;
}
/* castorGUI（ETC 分頁）沒有亮色主題（OWL owl.css 的 .owl-etc-mount 註解；CASTOR U17 第 5 項）：
   亮色主題下讓它維持深色，墊本站深色底、token 換回本站深色值，像一塊深色的計算機。 */
:root[data-theme="light"] .owl-host .owl-etc-mount {
    --kw-text-primary: #eae8f0;
    --kw-text-muted: #8b85a5;
    --kw-glass-bg: rgba(22, 19, 44, 0.58);
    --kw-border: rgba(255, 255, 255, 0.08);
    --kw-accent: #F39F5A;
    --kw-accent-hover: #f5b278;
    --kw-color-danger: #f87171;
    --kw-color-warning: #fbbf24;
    --kw-color-success: #4ade80;
    color: #eae8f0;
    background: #0c0a1a;
}

/* ── OWL 掛載點：.owl-app 自己用 --owl-shell-height 撐高、裡面各面板自己捲 ── */
.owl-host-mount { flex: none; min-width: 0; padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }   /* 橫拿手機時避開瀏海（2026-10-08） */
.owl-host-mount:empty { display: none; }
/* 本站的全域重設（theme.css 的 * { margin: 0; padding: 0 }）會蓋到 OWL 沒特別寫間距的元素（清單縮排、段落間距…）。
   OWL 是照瀏覽器預設樣式寫的，所以在 OWL 裡把 margin／padding 退回瀏覽器預設（revert）。
   :where() 讓這條的權重是 0：只壓過同樣是 0 的 * 重設（這檔在 theme.css 之後載入），OWL 自己有寫的一律照 OWL。 */
:where(.owl-host .owl-app *) { margin: revert; padding: revert; }
/* 同一個全域重設的 a { color: inherit; text-decoration: none } 會讓 OWL 沒寫樣式的一般連結（每個數字的出處網址、
   結果的 Credits 網址）看起來跟內文一樣（WCAG 1.4.1）。這裡給沒有 class 的連結本站強調色＋底線（2026-10-08）。
   權重 (0,1,1)：要壓過 theme.css 的 a（:where() 的 0 壓不過）；有 class 的（.owl-button 下載鈕等）不碰，OWL 之後載入的同權重規則仍照 OWL。 */
:where(.owl-host .owl-app) a:not([class]) { color: var(--kw-accent); text-decoration: underline; text-underline-offset: 2px; }
:where(.owl-host .owl-app) a:not([class]):hover { color: var(--kw-accent-hover); }

/* ── 檢查中／不能用：在槽裡置中 ── */
.owl-host-state {
    flex: 1 1 auto;
    display: flex; align-items: center; justify-content: center;
    min-height: 0;
    padding: 24px 16px;
}
/* idle（還沒打開）／checking：轉圈；loading：轉圈到 OWL 把片段放進 #owl-mount 為止；ready：只剩 OWL；down：只剩卡片（OWL 沒起來就整個收掉） */
.owl-host[data-state="ready"] .owl-host-state,
.owl-host[data-state="loading"] .owl-host-mount:not(:empty) ~ .owl-host-state,
.owl-host[data-state="down"] .owl-host-mount,
.owl-host[data-state="down"] .owl-host-checking { display: none; }

.owl-host-checking {
    display: inline-flex; align-items: center; gap: 10px;
    font-size: 0.84rem; color: var(--color-text-muted);
}
.owl-host-spinner {
    width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid var(--color-border); border-top-color: var(--color-accent);
    animation: owl-host-spin 0.9s linear infinite;
}
@keyframes owl-host-spin { to { transform: rotate(360deg); } }

/* 連不上的卡片（§6.5）：一句「哪裡不對：怎麼辦」＋原因＋〔重試〕〔先去構圖〕；左邊的「!」是圖示＋顏色＋文字（不只靠顏色） */
.owl-host-card {
    display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 12px; align-items: start;
    width: 100%; max-width: 520px;
    padding: 16px 18px;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-amber);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}
.owl-host-card[hidden] { display: none; }
.owl-host-card-ico {
    display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; margin-top: 1px;
    border-radius: 50%; background: var(--color-amber); color: #2a1a02;
    font-size: 0.86rem; font-weight: var(--font-weight-bold); line-height: 1;
}
.owl-host-card-tx { min-width: 0; }
.owl-host-msg { margin: 0; font-size: 0.9rem; font-weight: var(--font-weight-normal); line-height: 1.6; color: var(--color-text); }
.owl-host-msg b { font-weight: var(--font-weight-semibold); }
.owl-host-msg [hidden] { display: none; }
.owl-host-reason { margin-top: 6px; font-size: 0.78rem; color: var(--color-text-secondary); line-height: 1.6; overflow-wrap: anywhere; }
.owl-host-reason:empty { display: none; }
.owl-host-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.owl-host-actions .btn { min-height: 36px; }
.owl-host-actions .btn-outline { color: var(--color-text); border-color: var(--color-text-muted); }
.owl-host-actions .btn[aria-disabled="true"] { opacity: 0.6; cursor: progress; }
.owl-host-checked { margin-top: 10px; font-size: 0.72rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.owl-host-checked:empty { display: none; }

@media (max-width: 860px) {
    .owl-host-actions .btn { min-height: 44px; }
}
