/* ===================== 主題變數 ===================== */
:root,
html[data-theme="light"] {
    --cbn-primary: #1f6feb;
    --cbn-primary-dark: #14488f;
    --cbn-brand: #14488f;

    --cbn-page-bg: #f4f6f9;
    --cbn-surface: #ffffff;
    --cbn-surface-2: #f1f3f5;
    --cbn-bg: #eef1f5;
    --cbn-dot: rgba(20, 40, 80, 0.10);
    --cbn-border: #e3e7ee;
    --cbn-text: #2a2f38;
    --cbn-muted: #8a93a2;
    --cbn-shadow: rgba(20, 40, 80, 0.08);

    --cbn-scrollbar-track: transparent;
    --cbn-scrollbar-thumb: #c4ccd6;
    --cbn-scrollbar-thumb-hover: #a7b1be;

    --cbn-login-bg: linear-gradient(135deg, #14488f 0%, #1f6feb 60%, #4a93ff 100%);

    --cbn-error-bg: #fdecec;
    --cbn-error-border: #f5c2c2;
    --cbn-error-text: #b42318;
}

html[data-theme="dark"] {
    --cbn-primary: #4a93ff;
    --cbn-primary-dark: #1f6feb;
    --cbn-brand: #8fbaff;

    --cbn-page-bg: #161b22;
    --cbn-surface: #1f262e;
    --cbn-surface-2: #283039;
    --cbn-bg: #12171d;
    --cbn-dot: rgba(255, 255, 255, 0.06);
    --cbn-border: #2e3742;
    --cbn-text: #e6e9ee;
    --cbn-muted: #97a1b0;
    --cbn-shadow: rgba(0, 0, 0, 0.45);

    --cbn-scrollbar-track: transparent;
    --cbn-scrollbar-thumb: #3a4450;
    --cbn-scrollbar-thumb-hover: #4f5c6b;

    --cbn-login-bg: linear-gradient(135deg, #0b1b30 0%, #102a4d 55%, #14488f 100%);

    --cbn-error-bg: #3a1d1d;
    --cbn-error-border: #6a2b2b;
    --cbn-error-text: #ff9b94;
}

* {
    box-sizing: border-box;
}

/* 全站字型：思源黑體 Noto Sans TC（self-host 完整版，跨 Windows/Linux/手機一致），英數沿用 Segoe UI，
   最後才退回系統字型。字型檔載於 /lib/fonts/noto-sans-tc/noto-sans-tc.css。 */
:root {
    --cbn-font: "Noto Sans TC", "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--cbn-font);
    color: var(--cbn-text);
}

/* DevExtreme 元件（dxDataGrid/dxForm/dxPopup…）預設使用 Roboto，覆寫為全站字型，使中文一致為思源黑體。 */
.dx-theme-material-typography,
.dx-theme-material-typography input,
.dx-theme-material-typography textarea,
.dx-widget,
.dx-widget input,
.dx-widget textarea {
    font-family: var(--cbn-font);
}

/* ===================== 全域捲動軸（隨 light / dark 主題） =====================
   一律使用主題變數：--cbn-scrollbar-track / --cbn-scrollbar-thumb / --cbn-scrollbar-thumb-hover
   （定義於上方主題區）。新增可捲動元件無需再各自設定，沿用此處即可統一。 */

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--cbn-scrollbar-thumb) var(--cbn-scrollbar-track);
}

/* WebKit / Chromium / Edge / Safari */
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: var(--cbn-scrollbar-track);
}

*::-webkit-scrollbar-thumb {
    background: var(--cbn-scrollbar-thumb);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--cbn-scrollbar-thumb-hover);
    border: 2px solid transparent;
    background-clip: content-box;
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* ===================== 登入頁 ===================== */
.cbn-login-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cbn-login-bg);
}

.cbn-login-wrapper {
    width: 100%;
    max-width: 420px;
    padding: 24px;
    position: relative;
}

.cbn-login-card {
    background: var(--cbn-surface);
    border-radius: 14px;
    box-shadow: 0 18px 48px var(--cbn-shadow);
    padding: 36px 32px 28px;
}

.cbn-login-card--message {
    text-align: center;
}

.cbn-login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
}

.cbn-login-titles h1 {
    font-size: 18px;
    margin: 0;
    color: var(--cbn-brand);
}

.cbn-login-titles p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--cbn-muted);
}

.cbn-logo-mark {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--cbn-primary), var(--cbn-primary-dark));
    color: #fff;
    font-weight: 700;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.cbn-field {
    margin-bottom: 16px;
}

.cbn-field > label {
    display: block;
    font-size: 13px;
    color: var(--cbn-muted);
    margin-bottom: 6px;
}

.cbn-field-inline {
    display: flex;
    align-items: center;
}

.cbn-login-errors {
    background: var(--cbn-error-bg);
    border: 1px solid var(--cbn-error-border);
    color: var(--cbn-error-text);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.cbn-login-footer {
    margin-top: 18px;
    text-align: center;
    font-size: 12px;
    color: var(--cbn-muted);
}

.cbn-text-link {
    color: var(--cbn-primary);
    text-decoration: none;
}

/* ===== 登入頁（重新設計，原生元件） ===== */
.cbn-login-card--v2 {
    padding: 38px 36px 34px;
    border: 1px solid var(--cbn-border);
}

.cbn-login-logo {
    flex: 0 0 auto;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--cbn-border);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px;
    box-shadow: 0 4px 14px var(--cbn-shadow, rgba(0,0,0,.12));
}
.cbn-login-logo img { width: 100%; height: 100%; object-fit: contain; }
html[data-theme="dark"] .cbn-login-logo { background: rgba(255,255,255,.06); }

.cbn-login-welcome { margin: 6px 0 22px; }
.cbn-login-welcome h2 { margin: 0; font-size: 22px; font-weight: 700; color: var(--cbn-text); }
.cbn-login-welcome p { margin: 4px 0 0; font-size: 13px; color: var(--cbn-muted); }

/* 帶圖示的輸入框 */
.cbn-input {
    position: relative;
    display: flex;
    align-items: center;
}
.cbn-input-ico {
    position: absolute;
    left: 13px;
    color: var(--cbn-muted);
    font-size: 14px;
    pointer-events: none;
}
.cbn-input input {
    width: 100%;
    box-sizing: border-box;
    height: 46px;
    padding: 0 14px 0 38px;
    border: 1px solid var(--cbn-border);
    border-radius: 10px;
    background: var(--cbn-surface);
    color: var(--cbn-text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.cbn-input input::placeholder { color: var(--cbn-muted); opacity: .8; }
.cbn-input input:focus {
    border-color: var(--cbn-primary);
    box-shadow: 0 0 0 3px rgba(31, 111, 235, .18);
}
.cbn-input-eye {
    position: absolute;
    right: 6px;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: var(--cbn-muted);
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cbn-input-eye:hover { color: var(--cbn-text); background: var(--cbn-hover, rgba(127,127,127,.12)); }

/* 記住我 */
.cbn-login-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.cbn-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; color: var(--cbn-text); user-select: none; }
.cbn-check input { width: 16px; height: 16px; accent-color: var(--cbn-primary); cursor: pointer; }
.cbn-login-link { font-size: 13.5px; color: var(--cbn-primary); text-decoration: none; font-weight: 500; transition: color .15s; }
.cbn-login-link:hover { color: var(--cbn-primary-dark); text-decoration: underline; }

/* 登入按鈕 */
.cbn-login-submit {
    width: 100%;
    height: 46px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--cbn-primary), var(--cbn-primary-dark));
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 2px;
    cursor: pointer;
    font-family: inherit;
    transition: filter .15s ease, transform .05s ease;
}
.cbn-login-submit:hover { filter: brightness(1.06); }
.cbn-login-submit:active { transform: translateY(1px); }

.cbn-login-errors i { margin-right: 4px; }

/* 登入頁主題分段切換（卡片下方，置中；位於彩色背景上故白字） */
.cbn-login-themebar {
    margin: 18px auto 0;
    width: fit-content;
    display: flex;
    gap: 0;
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 10px;
    overflow: hidden;
    backdrop-filter: blur(4px);
}
.cbn-login-themebar .cbn-theme-opt {
    border: none;
    background: transparent;
    color: #fff;
    padding: 7px 14px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.cbn-login-themebar .cbn-theme-opt + .cbn-theme-opt { border-left: 1px solid rgba(255, 255, 255, .22); }
.cbn-login-themebar .cbn-theme-opt:hover { background: rgba(255, 255, 255, .12); }
.cbn-login-themebar .cbn-theme-opt.active { background: rgba(255, 255, 255, .28); font-weight: 600; }

/* ===================== 主框架 ===================== */
.cbn-app-body {
    margin: 0;
    background: var(--cbn-page-bg);
}

.cbn-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.cbn-header {
    height: 56px;
    background: var(--cbn-surface);
    border-bottom: 1px solid var(--cbn-border);
    box-shadow: 0 1px 4px var(--cbn-shadow);
    z-index: 10;
    display: flex;
    align-items: center;
    padding: 0 8px;
}

.cbn-header .dx-toolbar {
    width: 100%;
    background: transparent;
}

.cbn-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 4px;
}

.cbn-brand .cbn-logo-mark {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    font-size: 13px;
}

.cbn-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.cbn-brand-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--cbn-brand);
}

.cbn-brand-sub {
    font-size: 11px;
    color: var(--cbn-muted);
}

.cbn-user {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 2px 8px 2px 4px;
    min-height: 38px;
}

.cbn-user .dx-icon-user {
    font-size: 22px;
    line-height: 1;
    color: var(--cbn-primary);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}

.cbn-user-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.25;
}

.cbn-user-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--cbn-text);
}

.cbn-user-role {
    font-size: 11px;
    color: var(--cbn-muted);
}

.cbn-main {
    flex: 1;
    display: flex;
    min-height: 0;
}

.cbn-sidebar {
    width: 248px;
    flex: 0 0 auto;
    background: var(--cbn-surface);
    border-right: 1px solid var(--cbn-border);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, margin-left 0.2s ease;
    padding-top: 8px;
}

.cbn-sidebar > #cbnMenu {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

/* 側邊選單頁尾：著作權 + 系統版本 */
.cbn-menu-foot {
    flex: 0 0 auto;
    padding: 10px 14px;
    border-top: 1px solid var(--cbn-border);
    color: var(--cbn-muted);
    font-size: 11px;
    line-height: 1.5;
    white-space: nowrap;
}

.cbn-sidebar--collapsed .cbn-menu-foot { display: none; }

/* 品牌 Logo：方框內顯示 Logo（淺色＝原圖；深色＝改用白色版 SVG，由 cbn-theme.js 換 src，不再用 CSS 濾鏡） */
.cbn-logo-box {
    background: #fff;
    border: 1px solid var(--cbn-border);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.cbn-logo-box .cbn-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

html[data-theme="dark"] .cbn-logo-box {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.18);
}

.cbn-user-dept {
    font-size: 12.5px;
    color: var(--cbn-text);
}

/* 使用者選單彈出視窗頂部：部門（大）＋職稱（小） */
.cbn-menu-userhead { padding: 4px 6px; line-height: 1.35; }
.cbn-mh-dept { font-size: 14px; font-weight: 600; color: var(--cbn-text); }
.cbn-mh-pos { font-size: 11px; color: var(--cbn-muted); }

/* 使用者選單：主題分段選擇（直接在旁切換，不開子選單） */
.cbn-theme-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 3px 6px; }
.cbn-theme-label { color: var(--cbn-text); font-size: 13px; white-space: nowrap; }
.cbn-theme-opts { display: inline-flex; border: 1px solid var(--cbn-border); border-radius: 7px; overflow: hidden; }
.cbn-theme-opt, .cbn-lang-opt { border: none; background: transparent; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--cbn-text); font-family: inherit; }
.cbn-theme-opt + .cbn-theme-opt, .cbn-lang-opt + .cbn-lang-opt { border-left: 1px solid var(--cbn-border); }
.cbn-theme-opt:hover, .cbn-lang-opt:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); }
.cbn-theme-opt.active, .cbn-lang-opt.active { background: var(--cbn-primary); color: #fff; }

/* ===== 自製頂部列 + 使用者下拉（不使用 DevExpress） ===== */
.cbn-header--flex { justify-content: space-between; gap: 12px; }
.cbn-header-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cbn-header-right { display: flex; align-items: center; }

.cbn-iconbtn {
    width: 40px; height: 40px; border: none; background: transparent; cursor: pointer;
    border-radius: 8px; color: var(--cbn-text); font-size: 18px;
    display: flex; align-items: center; justify-content: center;
}
.cbn-iconbtn:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); }

.cbn-usermenu { position: relative; }
.cbn-user-btn {
    display: flex; align-items: center; gap: 9px; background: transparent; border: none; cursor: pointer;
    padding: 4px 8px; border-radius: 8px; color: var(--cbn-text); font-family: inherit; min-height: 42px;
}
.cbn-user-btn:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); }
.cbn-user-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--cbn-primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 14px; flex: 0 0 auto;
}
.cbn-user-btn .cbn-user-info { align-items: flex-start; }
.cbn-user-caret { font-size: 11px; color: var(--cbn-muted); transition: transform .15s ease; }
.cbn-usermenu.open .cbn-user-caret { transform: rotate(180deg); }

.cbn-user-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0; min-width: 248px;
    background: var(--cbn-surface); border: 1px solid var(--cbn-border); border-radius: 10px;
    box-shadow: 0 10px 30px var(--cbn-shadow, rgba(0,0,0,.2)); padding: 6px; z-index: 1200;
    opacity: 0; visibility: hidden; transform: translateY(-4px);
    transition: opacity .12s ease, transform .12s ease;
}
.cbn-usermenu.open .cbn-user-dropdown { opacity: 1; visibility: visible; transform: none; }

.cbn-menu-sep { height: 1px; background: var(--cbn-border); margin: 6px 4px; }
.cbn-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; background: transparent; border: none;
    padding: 9px 10px; border-radius: 7px; cursor: pointer; color: var(--cbn-text);
    font-size: 14px; font-family: inherit; text-align: left;
}
.cbn-menu-item:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); }
.cbn-menu-item i { width: 18px; text-align: center; color: var(--cbn-muted); }

.cbn-sidebar--collapsed {
    width: 0;
    margin-left: 0;
    padding: 0;
    overflow: hidden;
    border-right: none;
}

/* ===== 自製左側選單（不使用 DevExpress） ===== */
.cbn-nav { padding: 6px 8px; }
.cbn-nav-group { margin-bottom: 2px; }

.cbn-nav-header,
.cbn-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    border: none;
    background: transparent;
    color: var(--cbn-text);
    font-family: inherit;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.cbn-nav-header { padding: 9px 10px; font-weight: 600; }
.cbn-nav-header:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); }

.cbn-nav-ico { width: 18px; text-align: center; font-size: 14px; color: var(--cbn-muted); flex: 0 0 auto; }
.cbn-nav-text { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.cbn-nav-caret { font-size: 11px; color: var(--cbn-muted); transition: transform .18s ease; flex: 0 0 auto; }
.cbn-nav-group.open > .cbn-nav-header .cbn-nav-caret { transform: rotate(180deg); }

/* 子項：預設收合，展開時以 max-height 動畫展開 */
.cbn-nav-children { display: block; max-height: 0; overflow: hidden; transition: max-height .22s ease; }
.cbn-nav-group.open > .cbn-nav-children { max-height: 600px; }

.cbn-nav-link { padding: 8px 10px 8px 12px; }
.cbn-nav-children .cbn-nav-link { padding-left: 38px; font-weight: 400; }
.cbn-nav-children .cbn-nav-link .cbn-nav-ico { font-size: 13px; }
.cbn-nav-link:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); }

.cbn-nav-link.active {
    background: var(--cbn-primary);
    color: #fff;
}
.cbn-nav-link.active .cbn-nav-ico { color: #fff; }

/* ===================== AI Bot（自製，主題配色） ===================== */
.cbn-aibot { position: fixed; right: 22px; bottom: 22px; z-index: 3000; }
.cbn-aibot-fab {
    width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
    background: linear-gradient(135deg, var(--cbn-primary), var(--cbn-primary-dark));
    color: #fff; font-size: 22px; box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
    display: flex; align-items: center; justify-content: center; transition: transform .12s ease, box-shadow .12s ease;
}
.cbn-aibot-fab:hover { transform: scale(1.06); box-shadow: 0 8px 26px rgba(0, 0, 0, .34); }
.cbn-aibot.open .cbn-aibot-fab { transform: scale(.96); }

.cbn-aibot-panel {
    position: absolute; right: 0; bottom: 70px;
    width: 380px; max-width: calc(100vw - 32px); height: 540px; max-height: calc(100vh - 120px);
    background: var(--cbn-surface); border: 1px solid var(--cbn-border); border-radius: 14px;
    box-shadow: 0 16px 48px var(--cbn-shadow, rgba(0, 0, 0, .3));
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; visibility: hidden; transform: translateY(12px); transition: opacity .15s ease, transform .15s ease;
}
.cbn-aibot.open .cbn-aibot-panel { opacity: 1; visibility: visible; transform: none; }

.cbn-aibot-head {
    display: flex; align-items: center; justify-content: space-between; padding: 12px 14px;
    background: linear-gradient(135deg, var(--cbn-primary), var(--cbn-primary-dark)); color: #fff;
}
.cbn-aibot-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.cbn-aibot-x { background: transparent; border: none; color: #fff; cursor: pointer; font-size: 18px; opacity: .9; }
.cbn-aibot-x:hover { opacity: 1; }

.cbn-aibot-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--cbn-page-bg); }
.cbn-aimsg { display: flex; }
.cbn-aimsg--user { justify-content: flex-end; }
.cbn-aimsg-bubble { max-width: 82%; padding: 8px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.cbn-aimsg--user .cbn-aimsg-bubble { background: var(--cbn-primary); color: #fff; border-bottom-right-radius: 4px; }
.cbn-aimsg--bot .cbn-aimsg-bubble { background: var(--cbn-surface); color: var(--cbn-text); border: 1px solid var(--cbn-border); border-bottom-left-radius: 4px; }
.cbn-aimsg--typing .cbn-aimsg-bubble { color: var(--cbn-muted); }

.cbn-aibot-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--cbn-border); background: var(--cbn-surface); align-items: flex-end; }
.cbn-aibot-input textarea {
    flex: 1; resize: none; max-height: 120px; border: 1px solid var(--cbn-border); border-radius: 10px;
    padding: 8px 10px; font-family: inherit; font-size: 13.5px; background: var(--cbn-surface); color: var(--cbn-text); outline: none;
}
.cbn-aibot-input textarea:focus { border-color: var(--cbn-primary); }
.cbn-aibot-send { width: 38px; height: 38px; border: none; border-radius: 10px; cursor: pointer; background: var(--cbn-primary); color: #fff; font-size: 15px; flex: 0 0 auto; }
.cbn-aibot-send:hover { filter: brightness(1.08); }
.cbn-aibot-iconbtn { width: 38px; height: 38px; border: none; border-radius: 10px; cursor: pointer; background: transparent; color: var(--cbn-muted); font-size: 16px; flex: 0 0 auto; }
.cbn-aibot-iconbtn:hover { background: var(--cbn-hover, rgba(127,127,127,.12)); color: var(--cbn-text); }

/* 待送出附件 chips */
.cbn-aibot-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 10px; }
.cbn-aibot-chips:not(:empty) { padding: 8px 10px 0; }
.cbn-aichip { display: inline-flex; align-items: center; gap: 6px; max-width: 160px; padding: 3px 6px 3px 4px; border: 1px solid var(--cbn-border); border-radius: 8px; background: var(--cbn-surface); font-size: 12px; color: var(--cbn-text); }
.cbn-aichip img { width: 26px; height: 26px; object-fit: cover; border-radius: 5px; }
.cbn-aichip i { color: var(--cbn-muted); }
.cbn-aichip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cbn-aichip-x { border: none; background: transparent; cursor: pointer; color: var(--cbn-muted); font-size: 15px; line-height: 1; padding: 0 2px; }
.cbn-aichip-x:hover { color: #e03131; }

/* 對話泡泡中的附件 */
.cbn-aimsg-atts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.cbn-aimsg-img { max-width: 160px; max-height: 160px; border-radius: 8px; display: block; }
.cbn-aimsg-file { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; opacity: .9; }

@media (max-width: 520px) {
    .cbn-aibot-panel { width: calc(100vw - 24px); height: 72vh; }
}

.cbn-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    min-width: 0;
    transition: opacity 0.12s ease;
}

/* 局部導覽載入中的淡化效果 */
.cbn-content--loading {
    opacity: 0.55;
}

/* 含「填滿型頁面」時，內容區改為不外捲的彈性容器（由 Grid 內部捲動）。 */
.cbn-content:has(.cbn-page--fill) {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cbn-page--fill {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.cbn-page--fill .cbn-page-header {
    flex: 0 0 auto;
}

/* DataGrid 填滿剩餘高度 */
.cbn-grid-fill {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.cbn-grid-fill > .dx-widget {
    flex: 1 1 auto;
    min-height: 0;
}

/* ===================== 內容/儀表板 ===================== */
.cbn-page-header h2 {
    margin: 0 0 4px;
    font-size: 22px;
    color: var(--cbn-text);
}

.cbn-page-header p {
    margin: 0 0 20px;
    color: var(--cbn-muted);
}

.cbn-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.cbn-stat-card {
    background: var(--cbn-surface);
    border: 1px solid var(--cbn-border);
    border-radius: 12px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 1px 3px var(--cbn-shadow);
}

.cbn-stat-icon {
    font-size: 26px;
    color: #fff;
    background: linear-gradient(135deg, var(--cbn-primary), var(--cbn-primary-dark));
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cbn-stat-body {
    display: flex;
    flex-direction: column;
}

.cbn-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--cbn-text);
}

.cbn-stat-label {
    font-size: 13px;
    color: var(--cbn-muted);
}

.cbn-card {
    background: var(--cbn-surface);
    border: 1px solid var(--cbn-border);
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: 0 1px 3px var(--cbn-shadow);
    margin-bottom: 16px;
}

.cbn-card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--cbn-text);
}

/* 報價單編輯頁 */
.cbn-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.cbn-editor-toolbar {
    display: flex;
    gap: 8px;
}

.cbn-qno {
    color: var(--cbn-muted);
    font-size: 16px;
    font-weight: 500;
}

/* 內建/標記用小徽章 */
.cbn-badge {
    display: inline-block;
    padding: 1px 7px;
    font-size: 11px;
    border-radius: 999px;
    background: var(--cbn-hover, rgba(127,127,127,.16));
    color: var(--cbn-muted);
    vertical-align: middle;
}

/* DataGrid 操作欄：每列的按鈕群（使用真正的 dxButton，縮小約 30%） */
.cbn-row-actions {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
}

.cbn-row-actions .dx-button {
    min-height: 0;
}

.cbn-row-actions .dx-button .dx-button-content {
    padding: 3px 9px;
}

.cbn-row-actions .dx-button .dx-button-text {
    font-size: 11px;
    line-height: 1.4;
}

/* 工具列（新增/搜尋）對齊資料表左右邊界 */
.dx-datagrid .dx-datagrid-header-panel {
    padding-left: 0;
    padding-right: 0;
}

/* ===================== 自適應版面（RWD） ===================== */

/* 平板與以下：縮小內容內距、統計卡單欄化交給 auto-fit */
@media (max-width: 1024px) {
    .cbn-content { padding: 16px; }
}

/* 手機 / 小平板：側邊欄改為覆蓋式抽屜，內容滿版 */
@media (max-width: 860px) {
    .cbn-sidebar {
        position: fixed;
        top: 56px;
        bottom: 0;
        left: 0;
        width: 250px;
        z-index: 60;
        box-shadow: 2px 0 14px var(--cbn-shadow);
        transform: translateX(0);
        transition: transform 0.22s ease;
    }

    /* 收合時滑出畫面（手機預設收合）*/
    .cbn-sidebar.cbn-sidebar--collapsed {
        width: 250px;            /* 維持寬度，用位移隱藏 */
        padding-top: 8px;
        border-right: 1px solid var(--cbn-border);
        transform: translateX(-110%);
    }

    /* 點選遮罩（開啟側邊欄時顯示） */
    .cbn-sidebar-backdrop {
        position: fixed;
        inset: 56px 0 0 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 55;
    }

    .cbn-content { padding: 12px; }

    /* 標題列精簡：隱藏次要文字 */
    .cbn-brand-sub { display: none; }
    .cbn-user-info { display: none; }
    .cbn-header { padding: 0 4px; }

    .cbn-page-header h2 { font-size: 19px; }
    .cbn-page-header p { margin-bottom: 12px; font-size: 13px; }
}

/* 極小螢幕：品牌標題縮短 */
@media (max-width: 480px) {
    .cbn-brand-title { font-size: 13px; }
    .cbn-brand .cbn-logo-mark { width: 30px; height: 30px; }
}

/* ===================== 彈窗自適應（全站 dxPopup 不超出視窗） =====================
   多數編輯彈窗使用固定像素寬（最大達 ~1274px），在手機 / 平板會溢出。
   以下讓任何 dxPopup 都被視窗尺寸夾住、內容可捲動，無需逐一修改各頁。 */
.dx-overlay-content.dx-popup-normal {
    max-width: 96vw !important;
    max-height: 94vh !important;
}

@media (max-width: 860px) {
    /* 小螢幕：彈窗內容可捲動，避免被裁切 */
    .dx-overlay-content.dx-popup-normal .dx-popup-content {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* 彈窗內的左右兩欄版面（表單 ｜ 副面板）改為上下堆疊 */
    .cbn-split { flex-direction: column !important; height: auto !important; gap: 12px !important; }
    .cbn-split > * { flex: none !important; border-left: none !important; padding-left: 0 !important; min-width: 0 !important; overflow: visible !important; }
}

/* ===================== 法律文件彈窗（服務條款/隱私/免責） ===================== */
.cbn-legal { color: var(--cbn-text); line-height: 1.8; }
.cbn-legal h3 { margin: 4px 0 4px; font-size: 20px; color: var(--cbn-text); }
.cbn-legal h4 { margin: 22px 0 6px; font-size: 16px; color: var(--cbn-text); }
.cbn-legal .cbn-legal-updated { color: var(--cbn-muted); font-size: 13px; margin-bottom: 14px; }
.cbn-legal p, .cbn-legal li { color: var(--cbn-text); font-size: 14px; }
.cbn-legal ul { padding-left: 22px; margin: 6px 0; }
.cbn-legal li { margin: 3px 0; }
.cbn-legal .cbn-legal-muted { color: var(--cbn-muted); font-size: 13px; }

/* 法律彈窗：上方分頁切換 */
.cbn-legal-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--cbn-border); padding-bottom: 8px; flex-wrap: wrap; }
.cbn-legal-tab { border: 1px solid var(--cbn-border); background: var(--cbn-surface-2); color: var(--cbn-muted); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.cbn-legal-tab:hover { color: var(--cbn-text); }
.cbn-legal-tab.active { background: var(--cbn-primary); border-color: var(--cbn-primary); color: #fff; }
.cbn-legal h3 { display: none; }   /* 標題改由分頁呈現，省版面 */
.cbn-legal h4:first-of-type { margin-top: 6px; }

/* ===== 試用到期橫幅（租戶試用過期時，_Layout 顯示；橫跨內容區上方、AJAX 導覽持續） ===== */
.cbn-trial-banner { display:flex; align-items:center; gap:14px; flex-wrap:wrap; padding:10px 18px; background:#e8590c; color:#fff; font-size:14px; line-height:1.5; }
.cbn-trial-banner .cbn-trial-cta { margin-left:auto; background:#fff; color:#e8590c; padding:6px 16px; border-radius:8px; font-weight:700; text-decoration:none; white-space:nowrap; }
.cbn-trial-banner .cbn-trial-cta:hover { opacity:.9; }
