/* NovelPD Omni — 站內客服對話（使用者端）
 *
 * ⚠ 這支會掛在好幾種頁面上，而它們的變數命名並不一致：
 *   首頁 index.html 是硬編碼的深色頁，只有 --bg/--surface/--text/--muted/--border，
 *   沒有 --bg-card / --text-muted；閱讀頁 read.php 則是 --bg-card/--text/--text-muted，
 *   而且可以切換明暗。混著用的結果就是「頁面的 --text（近白）」配上
 *   「自己的 fallback --bg-card（白）」→ 白底白字，整個對話看不見。
 *
 * 所以這裡**完全自帶一套變數**，不去讀宿主頁面的任何顏色；
 * 明暗由 support.js 量測頁面背景亮度後掛 .sup-dark 決定（見該檔的 supApplyTheme）。
 */

#sup-modal {
    /* ── 淺色（預設）── */
    --sup-card:  #ffffff;
    --sup-bg:    #f4f5f7;
    --sup-text:  #16181d;
    --sup-sub:   #5b6472;   /* 次要文字：對 --sup-bg 的對比 ≥ 5.5:1 */
    --sup-line:  rgba(0, 0, 0, .13);
    --sup-chip:  rgba(0, 0, 0, .055);
    --sup-chip-h:rgba(0, 0, 0, .10);
    --sup-accent:#5b52e8;

    /* 連原生捲軸與輸入框的預設外觀一起換 —— 少了這行，深色面板右側會是一條亮白捲軸 */
    color-scheme: light;

    position: fixed; inset: 0; z-index: 12000; display: none;
    align-items: center; justify-content: center; padding: 20px;
    background: rgba(0, 0, 0, .62); backdrop-filter: blur(4px);
}
/* ── 深色 ── */
#sup-modal.sup-dark {
    --sup-card:  #1f2126;
    --sup-bg:    #15171b;
    --sup-text:  #f2f4f7;
    --sup-sub:   #a8b0bd;   /* 對 --sup-bg 的對比 ≥ 7:1 */
    --sup-line:  rgba(255, 255, 255, .14);
    --sup-chip:  rgba(255, 255, 255, .08);
    --sup-chip-h:rgba(255, 255, 255, .15);
    --sup-accent:#8b7cff;
    color-scheme: dark;
}
#sup-modal.show { display: flex; }

.sup-box {
    width: 100%; max-width: 720px; height: min(86vh, 760px);
    display: flex; flex-direction: column; overflow: hidden;
    border-radius: 18px;
    background: var(--sup-card);
    color: var(--sup-text);            /* 明確設定，不讓宿主頁面的 color 繼承進來 */
    border: 1px solid var(--sup-line);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}

/* ── 標題列 ── */
.sup-hd {
    display: flex; align-items: center; gap: 11px; flex-shrink: 0;
    padding: 14px 18px; border-bottom: 1px solid var(--sup-line);
    background: var(--sup-card);
}
.sup-hd-ic {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 19px;
    background: linear-gradient(135deg, #6366f1, #a855f7); color: #fff;
}
.sup-hd-tx { flex: 1; min-width: 0; }
.sup-hd-tx b { display: block; font-size: 15px; font-weight: 800; color: var(--sup-text); }
.sup-hd-tx small { font-size: 11.5px; color: var(--sup-sub); }
.sup-x {
    width: 32px; height: 32px; border: 0; border-radius: 50%; cursor: pointer; flex-shrink: 0;
    font-size: 14px; line-height: 1;
    color: var(--sup-sub); background: var(--sup-chip);
}
.sup-x:hover { color: var(--sup-text); background: var(--sup-chip-h); }

/* ── 訊息區 ── */
.sup-bd {
    flex: 1; overflow-y: auto; padding: 18px;
    display: flex; flex-direction: column; gap: 12px;
    background: var(--sup-bg);
}
.sup-load, .sup-err { margin: auto; font-size: 13px; line-height: 1.9; text-align: center; }
.sup-load { color: var(--sup-sub); }
.sup-err  { color: #f87171; }
.sup-hint {
    margin: auto; text-align: center; font-size: 13.5px; line-height: 2;
    color: var(--sup-sub); padding: 20px;
}
.sup-hint b { color: var(--sup-text); font-size: 14.5px; }
.sup-hint small { font-size: 12px; color: var(--sup-sub); }

.sup-msg { display: flex; flex-direction: column; max-width: 78%; }
.sup-msg.me   { align-self: flex-end; align-items: flex-end; }
.sup-msg.them { align-self: flex-start; }
.sup-who { font-size: 11px; color: var(--sup-sub); margin-bottom: 4px; padding: 0 4px; }
.sup-bub {
    padding: 10px 14px; border-radius: 15px; font-size: 13.5px; line-height: 1.85;
    word-break: break-word; white-space: pre-wrap;
    background: var(--sup-card); color: var(--sup-text);
    border: 1px solid var(--sup-line);
}
.sup-msg.me .sup-bub {
    background: linear-gradient(135deg, #6366f1, #7c5cff); color: #fff;
    border-color: transparent; border-bottom-right-radius: 5px;
}
.sup-msg.them .sup-bub { border-bottom-left-radius: 5px; }
.sup-bub img {
    display: block; max-width: 100%; max-height: 42vh;
    border-radius: 11px; cursor: zoom-in; margin-top: 6px;
    background: var(--sup-chip);
}
.sup-bub img:only-child { margin-top: 0; }
.sup-sys {
    align-self: center; max-width: 100%; font-size: 12px; color: #f87171;
    text-align: center; line-height: 1.8;
}

/* ── 未登入 ── */
.sup-gate { margin: auto; text-align: center; padding: 20px; color: var(--sup-text); }
.sup-gate-ic { font-size: 40px; margin-bottom: 10px; }
.sup-gate p { font-size: 14px; line-height: 1.9; margin: 0; color: var(--sup-text); }
.sup-gate-sub { font-size: 12px !important; color: var(--sup-sub) !important; margin-top: 4px !important; }
.sup-gate-sub b { color: var(--sup-text); }
.sup-gate-btn {
    display: inline-block; margin-top: 16px; padding: 11px 26px; border-radius: 12px;
    background: linear-gradient(135deg, #6366f1, #a855f7); color: #fff;
    font-size: 13.5px; font-weight: 800; text-decoration: none;
}
.sup-gate-btn:hover { filter: brightness(1.08); }

/* ── 輸入列 ── */
.sup-ft {
    flex-shrink: 0; padding: 11px 16px 12px;
    border-top: 1px solid var(--sup-line);
    background: var(--sup-card);
}
.sup-ft:empty { display: none; }
.sup-inbar { display: flex; align-items: flex-end; gap: 8px; }
/* 字級固定 16px：小於 16px 時 iOS Safari 聚焦輸入框會自動放大整頁 */
.sup-inbar textarea {
    flex: 1; resize: none; max-height: 120px; padding: 10px 14px; border-radius: 13px;
    font-family: inherit; font-size: 16px; line-height: 1.6; outline: none;
    border: 1px solid var(--sup-line);
    background: var(--sup-bg); color: var(--sup-text);
}
.sup-inbar textarea::placeholder { color: var(--sup-sub); opacity: 1; }
.sup-inbar textarea:focus { border-color: var(--sup-accent); }
.sup-ic, .sup-send {
    flex-shrink: 0; border: 0; cursor: pointer; font-family: inherit;
    min-height: 42px; border-radius: 13px;
}
.sup-ic {
    width: 42px; font-size: 18px; line-height: 1;
    background: var(--sup-chip); color: var(--sup-text);
    border: 1px solid var(--sup-line);
}
.sup-ic:hover { background: var(--sup-chip-h); }
.sup-send {
    padding: 0 20px; font-size: 13.5px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, #6366f1, #7c5cff);
}
.sup-send:hover { filter: brightness(1.06); }
.sup-send:disabled { opacity: .55; cursor: default; }
.sup-note { font-size: 11px; color: var(--sup-sub); margin: 8px 2px 0; line-height: 1.7; }

#sup-attach:not(:empty) { margin-bottom: 9px; }
.sup-thumb { position: relative; display: inline-block; }
.sup-thumb img { height: 60px; border-radius: 9px; border: 1px solid var(--sup-line); display: block; }
.sup-thumb button {
    position: absolute; top: -7px; right: -7px; width: 22px; height: 22px;
    border: 0; border-radius: 50%; cursor: pointer; font-size: 12px; line-height: 1;
    background: #ef4444; color: #fff;
}

/* ── 聯繫我們 modal 上的「與客服對話」按鈕 ── */
.contact-chat-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    width: 100%; margin-top: 14px; padding: 13px 20px; border: 0; border-radius: 13px;
    cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 800; color: #fff;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    box-shadow: 0 6px 18px rgba(124, 92, 255, .28);
    transition: filter .15s, transform .15s;
}
.contact-chat-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
#sup-badge {
    /* 預設藏起來：supRefreshBadge() 有未讀時才改成 inline-flex。
       少了這行，未讀為 0 的空 span 會露出 padding 那一小條紅色。 */
    display: none;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: #ef4444; color: #fff; font-size: 11px; font-weight: 800;
    align-items: center; justify-content: center; line-height: 1;
}

@media (max-width: 640px) {
    #sup-modal { padding: 0; }
    .sup-box { max-width: 100%; height: 100dvh; border-radius: 0; }
    .sup-msg { max-width: 88%; }
}
