/* 3939 線上簽注系統 — 基礎樣式 */
:root {
    --color-bg: #0f172a;
    --color-surface: #ffffff;
    --color-surface-2: #f8fafc;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-muted: #64748b;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;
    --color-success: #16a34a;
    --color-danger:  #dc2626;
    --color-warn:    #d97706;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, .08);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    --font-base: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-base);
    color: var(--color-text);
    background: var(--color-surface-2);
    line-height: 1.55;
}
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: .9em;
}

/* ===== 通用 ===== */
.container { max-width: 1200px; margin: 0 auto; padding: var(--space-5); }
.muted { color: var(--color-muted); }
.center { text-align: center; }
.warn  { color: var(--color-warn); }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit; font-weight: 500;
    cursor: pointer;
    background: var(--color-surface); color: var(--color-text);
    border-color: var(--color-border);
    transition: background .15s ease, border-color .15s ease, color .15s ease;
    text-decoration: none;
}
.btn:hover  { background: var(--color-surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary {
    background: var(--color-accent); color: #fff;
    border-color: var(--color-accent);
}
.btn.primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn.ghost {
    background: transparent;
    border-color: var(--color-border);
}

/* ===== 表單 ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field > span { font-size: .9rem; color: var(--color-muted); }
.field.inline { flex-direction: row; align-items: center; gap: var(--space-2); margin-bottom: 0; }
.field input, .field select, .field textarea {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.field textarea { resize: vertical; min-height: 60px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.form-error {
    background: #fef2f2;
    color: var(--color-danger);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin: 0 0 var(--space-3);
    font-size: .9rem;
}

/* ===== Login ===== */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a, #1e3a8a);
    padding: var(--space-4);
}
.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-6);
    width: 100%;
    max-width: 380px;
}
.login-card__header h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-card__header { margin-bottom: var(--space-5); }
.login-card__footer {
    margin-top: var(--space-4); text-align: center; font-size: .9rem;
}
.login-form .btn { width: 100%; padding: 10px; font-size: 1rem; }

/* ===== Topbar ===== */
.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-5);
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-sm);
}
.topbar__title { margin: 0; font-size: 1.1rem; }
.topbar__user { display: flex; align-items: center; gap: var(--space-3); }

/* ===== Tabs ===== */
.tabs {
    display: flex;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 var(--space-5);
    gap: var(--space-2);
}
.tab {
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer; font: inherit; color: var(--color-muted);
}
.tab:hover { color: var(--color-text); }
.tab.is-active { color: var(--color-accent); border-bottom-color: var(--color-accent); }

/* ===== 角色選單 (經銷商 role=8 / 管理員 role=9，規格 line 462+) =====
   admin.js 載入後把角色寫到 body[data-role]，CSS 依此隱藏/顯示，避免 JS race。 */
body[data-role="8"] [data-admin-only] { display: none !important; }  /* 經銷商看不到管理員專屬功能 */
[data-dealer-only] { display: none; }                                /* 預設隱藏經銷商專屬提示 */
body[data-role="8"] [data-dealer-only] { display: block; }           /* 僅經銷商顯示 */

/* ===== Filter bar ===== */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: var(--space-3);
    align-items: flex-end;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
}
.filter-bar .field { margin: 0; min-width: 140px; }
.filter-bar__actions { display: flex; gap: var(--space-2); margin-left: auto; }

/* ===== Table ===== */
.table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: auto;
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}
.data-table thead th {
    background: var(--color-surface-2);
    font-weight: 600;
    color: var(--color-muted);
    border-bottom: 2px solid var(--color-border);
    position: sticky; top: 0;
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tfoot tr.total-row {
    background: var(--color-surface-2);
    font-weight: 700;
}
.data-table .ua {
    max-width: 300px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--color-muted); font-size: .85rem;
}

/* ===== 下注明細 — 展開的每碼子表 ===== */
.data-table tr.mb-row { cursor: pointer; }
.data-table tr.mb-row.is-expanded { background: var(--color-surface-2); }
.data-table tr.mb-detail > td.mb-detail__cell {
    padding: 12px 18px;
    background: #fafbfc;
    border-bottom: 2px solid var(--color-border);
}
.mb-items {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.mb-items th, .mb-items td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--color-border);
}
.mb-items thead th {
    color: var(--color-muted);
    font-weight: 500;
    font-family: inherit;
}
.mb-items td.right, .mb-items th.right { text-align: right; }
.badge {
    display: inline-block; padding: 2px 8px;
    border-radius: 999px;
    font-size: .8rem; font-weight: 500;
}
.badge.ok   { background: #dcfce7; color: #166534; }
.badge.fail { background: #fee2e2; color: #991b1b; }

/* === 開獎統計 / 基因圖 (light fallback;Vegas dark theme override 在 vegas.css) === */
.ds-grid {
    margin-top: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.ds-grid h3 {
    margin: 0;
    padding: 10px 16px;
    background: var(--color-surface-2);
    color: var(--color-text);
    font-size: .95rem;
    font-weight: 700;
}
.ds-grid > div { padding: 12px 16px; }

/* 基因圖 */
.genechart-wrap { overflow-x: auto; }
.ds-genechart {
    border-collapse: collapse;
    font-size: .7rem;
    width: max-content;
}
.ds-genechart th,
.ds-genechart td {
    width: 22px;
    height: 22px;
    text-align: center;
    border: 1px solid var(--color-border);
    color: transparent;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.ds-genechart thead th {
    background: var(--color-surface-2);
    color: var(--color-text);
    font-weight: 600;
    position: sticky; top: 0;
}
.ds-genechart .ds-gc-period-header,
.ds-genechart .ds-gc-period {
    width: 56px;
    background: var(--color-surface-2);
    color: var(--color-text);
    font-weight: 600;
    position: sticky; left: 0;
    z-index: 1;
}
.ds-genechart .ds-gc-hit {
    color: var(--color-text);
    font-weight: 600;
}
.ds-genechart .ds-gc-special {
    /* 特碼用底線標記 — 顏色由球色 (.ball-*) 決定,不在這裡寫死 */
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 700;
}

/* ===== Pagination ===== */
.pagination {
    display: flex; align-items: center; justify-content: center; gap: var(--space-3);
    margin-top: var(--space-4);
}

/* ===== 跑馬燈 ===== */
.marquee {
    background: linear-gradient(90deg, #1e3a8a 0%, #2563eb 50%, #1e3a8a 100%);
    color: #fff;
    overflow: hidden;
    border-bottom: 1px solid rgba(255, 255, 255, .15);
}
.marquee__viewport { overflow: hidden; }
.marquee__track {
    display: inline-block;
    white-space: nowrap;
    padding: 8px 0;
    animation: marquee 40s linear infinite;
    font-size: .95rem;
}
.marquee__track:hover { animation-play-state: paused; }
.marquee__item { padding: 0 var(--space-5); }
.marquee__item::before { content: '📣 '; }
.marquee__item + .marquee__item { border-left: 1px solid rgba(255, 255, 255, .25); }
@keyframes marquee {
    from { transform: translateX(100%); }
    to   { transform: translateX(-100%); }
}

/* ===== 歷史開獎 ===== */
.draws-history { display: flex; flex-direction: column; gap: 6px; }
.draws-history__row {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: var(--space-2);
    padding: 6px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    font-size: .9rem;
}
.draws-history__date {
    color: var(--color-muted); font-size: .85rem; align-self: center;
}
.draws-history__numbers {
    display: flex; gap: 4px; flex-wrap: wrap;
}
.ball {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: #fef3c7; color: #92400e;
    font-weight: 600; font-size: .85rem;
    border: 1px solid #fbbf24;
}
/* 彩種球色規則 (3939線上簽注系統.TXT 213-220):
   - h649 三色波 (.h-red / .h-blue / .h-green)
   - t649 全紅   (.t-red)
   - t539 / c539 沿用 default .ball (黃)
   .ball.special 為「特碼」標記;由於 t539/c539 沒有特碼,
   實際上只會出現在 h649/t649,且必伴隨一個遊戲色 class,
   遊戲色 class 寫在 .special 之後以勝出 cascade,讓背景跟正碼一致,
   特碼的「特」由 + 分隔符與位置呈現。 */
.ball.special { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
.ball.h-red   { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
.ball.h-blue  { background: #dbeafe; color: #1e3a8a; border-color: #3b82f6; }
.ball.h-green { background: #dcfce7; color: #14532d; border-color: #22c55e; }
.ball.t-red   { background: #fee2e2; color: #991b1b; border-color: #ef4444; }
.ball.sep { background: transparent; border: none; color: var(--color-muted); }

/* ===== 已漲價號碼 (bet_s.html 右側面板) ===== */
.adjust-list {
    display: flex; flex-wrap: wrap;
    gap: var(--space-2);
}
.adjust-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    font-size: .85rem;
}
.adjust-chip .ball { width: 26px; height: 26px; font-size: .8rem; }
.adjust-chip .delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.adjust-chip.up   { border-color: #ef4444; background: #fef2f2; }
.adjust-chip.up   .delta { color: var(--color-danger); }
.adjust-chip.down { border-color: #16a34a; background: #f0fdf4; }
.adjust-chip.down .delta { color: var(--color-success); }

/* 已封牌號碼 */
.closed-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: #f3f4f6;
    border: 1px solid #9ca3af;
    color: #4b5563;
    font-size: .85rem;
    text-decoration: line-through;
}
.closed-chip .ball {
    width: 26px; height: 26px; font-size: .8rem;
    background: #e5e7eb; color: #6b7280;
    border-color: #9ca3af;
    text-decoration: none;
}
.closed-chip .tag { font-weight: 600; letter-spacing: .05em; }

/* ===== 客戶端 (bet_s.html) ===== */
.balance-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-2);
    background: linear-gradient(135deg, #1e293b, #334155);
    color: #fff;
    padding: var(--space-3) var(--space-5);
}
.balance-bar .kpi {
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .12);
    color: #fff;
}
.balance-bar .kpi-label { color: rgba(255, 255, 255, .65); }
.balance-bar .kpi-value { color: #fff; font-size: 1.3rem; }

.client-grid {
    display: grid;
    grid-template-columns: 3fr 4fr;
    gap: var(--space-4);
    align-items: start;
}
@media (max-width: 900px) {
    .client-grid { grid-template-columns: 1fr; }
}
.client-grid .panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}
.client-grid .panel h2 { margin-top: 0; font-size: 1.05rem; }

.bet-actions {
    display: flex; gap: var(--space-2); justify-content: flex-end;
}
#bet-raw { font-family: ui-monospace, "Cascadia Code", "Consolas", monospace; }

#game-hint {
    font-size: .85rem;
    margin-left: auto;
}

/* ===== Simulator KPI ===== */
.sim-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-3);
    margin: var(--space-4) 0;
}
.kpi {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    display: flex; flex-direction: column; gap: 4px;
}
.kpi-label { font-size: .85rem; color: var(--color-muted); }
.kpi-value { font-size: 1.6rem; font-weight: 600; color: var(--color-text); }

#sim-raw { font-family: ui-monospace, "Cascadia Code", "Consolas", monospace; }

/* ===== Sub-tabs (panel 內的二級分頁，例：盤價設定的彩種切換) ===== */
.subtabs {
    display: flex; gap: var(--space-2);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}
.subtab {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer; font: inherit;
    color: var(--color-muted);
    margin-bottom: -1px;
}
.subtab:hover { color: var(--color-text); background: var(--color-surface-2); }
.subtab.is-active {
    color: var(--color-accent);
    background: var(--color-surface);
    border-color: var(--color-border);
    border-bottom-color: var(--color-surface);
}

/* ===== Odds editor ===== */
.odds-prefix-bar {
    display: flex; align-items: center; gap: var(--space-2);
    margin-bottom: var(--space-3);
}
.odds-prefix-bar select {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
}

.odds-bulk-bar {
    display: flex; align-items: center; gap: var(--space-2);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
}
.odds-bulk-bar input {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
}

/* 表格化外觀:粉紅號碼 header + 緊貼下方 input,號碼/輸入彼此共用邊框 */
.odds-grid {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.odds-cell {
    display: flex; flex-direction: column;
    border-right: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    background: #fff;
    transition: background .15s ease;
}
.odds-cell:nth-child(10n) { border-right: none; }
/* 最後一列(整除 10 的後 10 個)不畫底邊 */
.odds-cell:nth-last-child(-n+10) { border-bottom: none; }

.odds-cell__label {
    background: #fecaca;       /* 粉紅 header,對齊截圖風格 */
    color: #7f1d1d;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 1.05rem;
    font-weight: 700;
    text-align: center;
    padding: 6px 4px;
    border-bottom: 1px solid var(--color-border);
    user-select: none;
}
.odds-cell input {
    width: 100%;
    padding: 6px 8px;
    border: none;
    border-radius: 0;
    background: transparent;
    font: inherit;
    font-size: .9rem;
    text-align: center;
}
.odds-cell input:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
    background: #eff6ff;
}
.odds-cell input[readonly] {
    background: var(--color-surface-2);
    color: var(--color-muted);
    cursor: not-allowed;
}
/* dirty cell:整格淡黃強調 */
.odds-cell.is-dirty { background: #fffbeb; }
.odds-cell.is-dirty .odds-cell__label {
    background: #fde68a;
    color: #78350f;
}
.odds-cell.is-dirty input { font-weight: 600; color: #b45309; }

.odds-fixed {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    text-align: center;
}

@media (max-width: 800px) {
    .odds-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    /* 5 欄時:每 5 個 cell 一列,重設邊框 */
    .odds-cell { border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border); }
    .odds-cell:nth-child(10n) { border-right: 1px solid var(--color-border); }
    .odds-cell:nth-child(5n)  { border-right: none; }
    .odds-cell:nth-last-child(-n+10) { border-bottom: 1px solid var(--color-border); }
    .odds-cell:nth-last-child(-n+5)  { border-bottom: none; }
}

/* ===== game_settings 表格內輸入欄 ===== */
.gs-table input[type="number"] {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    text-align: right;
}
.gs-table input[type="number"]:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}
.gs-table input[readonly] { background: var(--color-surface-2); cursor: not-allowed; }
.gs-table th:first-child, .gs-table td:first-child { width: 80px; font-weight: 600; }

/* ===== 盤價設定:玩法為欄、屬性為列的 grid ===== */
.gs-grid { margin-bottom: 24px; }
.gs-grid h3 {
    margin: 0 0 8px;
    padding: 6px 12px;
    background: var(--color-surface-2);
    border-radius: var(--radius-sm);
    font-size: 1rem;
}
.gs-grid table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: .9rem;
}
.gs-grid th, .gs-grid td {
    border: 1px solid var(--color-border);
    padding: 4px 6px;
    text-align: center;
    vertical-align: middle;
}
.gs-grid thead th {
    background: var(--color-surface-2);
    font-weight: 600;
    white-space: nowrap;
}
.gs-grid tbody th {
    background: var(--color-surface-2);
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
    width: 90px;
}
.gs-grid input[type="number"] {
    width: 100%;
    padding: 3px 6px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    text-align: right;
    background: #fff;
}
.gs-grid input[type="number"]:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}
.gs-grid input[readonly], .gs-grid input:disabled {
    background: var(--color-surface-2);
    color: var(--color-muted);
    cursor: not-allowed;
}
.gs-grid .gs-readonly-cell {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: var(--color-muted);
}

/* ===== Action buttons in tables ===== */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.danger {
    background: #fef2f2; color: var(--color-danger);
    border-color: #fecaca;
}
.btn.danger:hover { background: #fee2e2; }

/* ===== Modal ===== */
.modal {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 50;
    padding: var(--space-4);
}
.modal[hidden] { display: none; }
.modal__backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(2px);
}
.modal__dialog {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow: hidden;
    display: flex; flex-direction: column;
}
.modal__dialog--wide { max-width: 800px; }
.modal__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
}
.modal__header h3 { margin: 0; font-size: 1.1rem; }
.modal__close {
    background: transparent; border: none;
    font-size: 1.5rem; cursor: pointer; color: var(--color-muted);
    line-height: 1; padding: 0 4px;
}
.modal__close:hover { color: var(--color-text); }
.modal__body { padding: var(--space-4) var(--space-5); overflow-y: auto; flex: 1; }
.modal__footer {
    display: flex; justify-content: flex-end; gap: var(--space-2);
    padding-top: var(--space-3);
    margin-top: var(--space-3);
    border-top: 1px solid var(--color-border);
}

/* ===== Rebates grid ===== */
.rebates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-4);
}
.rebates-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
}
.rebates-card h4 {
    margin: 0 0 var(--space-2);
    font-size: .95rem;
    color: var(--color-accent);
}
.rebates-row {
    display: grid;
    grid-template-columns: 1fr 100px 30px;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    font-size: .9rem;
}
.rebates-row input[type="number"] {
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    text-align: right;
}
.rebates-row .pct { color: var(--color-muted); font-size: .85rem; }

/* ===== Setup page ===== */
.setup .card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    margin-top: var(--space-4);
    border-left: 4px solid var(--color-accent);
}
.setup .card.success { border-left-color: var(--color-success); }
.setup .card.error   { border-left-color: var(--color-danger); }
.setup .card pre {
    background: #f1f5f9; padding: 12px; border-radius: 6px;
    overflow: auto; white-space: pre-wrap;
}
.setup .card ul { padding-left: 20px; line-height: 1.9; }


/* ===== 大盤表 (Big Board) ===== */
.bb-controls {
    display: flex;
    gap: 16px;
    align-items: center;
    margin: 12px 0;
    padding: 8px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: .9rem;
}
.bb-controls label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.bb-controls__spacer { flex: 1; }

.bb-board {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px;
    overflow: auto;
}
.bb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .92rem;
    table-layout: fixed;
}
.bb-table thead th {
    background: var(--color-surface-2);
    color: var(--color-muted);
    font-weight: 600;
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
    font-size: .85rem;
    text-align: center;
}
.bb-table tbody td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--color-border);
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.bb-table .bb-code {
    text-align: center;
    background: var(--color-surface-2);
    color: var(--color-muted);
    font-weight: 600;
    width: 48px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}
.bb-table .bb-amount { font-weight: 500; }
/* 熱號:前 5%(紅)/前 5-20%(黃) */
.bb-table .bb-amount.bb-hot  { background: #fce7f3; color: #9d174d; }
.bb-table .bb-amount.bb-warm { background: #fef9c3; color: #854d0e; }
.bb-table tbody tr:hover .bb-amount:not(.bb-hot):not(.bb-warm) {
    background: #f8fafc;
}

.bb-summary {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: .95rem;
}
.bb-summary strong { color: var(--color-text); }

/* ===== 大盤表 — 組合排行 (二/三/四星) ===== */
.bb-combos {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin-bottom: 12px;
}
.bb-combos__title {
    color: var(--color-muted);
    font-size: .85rem;
    margin-bottom: 8px;
    font-weight: 500;
}
/* CSS Grid 自動排版:容器塞不下就自動減少每列欄數,絕不重疊 */
.bb-combos-grid {
    display: grid;
    gap: 4px;
    --bb-cell-min: 110px;
    grid-template-columns: repeat(auto-fill, minmax(var(--bb-cell-min), 1fr));
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: .88rem;
}
/* 不同玩法 cell 寬度不同 (四星最長 ~14 字元 + padding) */
.bb-combos-grid--erxing  { --bb-cell-min: 110px; }
.bb-combos-grid--sanxing { --bb-cell-min: 138px; }
.bb-combos-grid--sixing  { --bb-cell-min: 168px; }

.bb-combo-cell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: #fff;
    white-space: nowrap;
    overflow: hidden;
    line-height: 1.4;
}
.bb-combo-cell .bb-combo-code { color: var(--color-muted); }
.bb-combo-cell .bb-combo-amt  { color: var(--color-accent); font-weight: 600; }
.bb-combos-grid .bb-hot  { background: #fce7f3; border-color: #fbcfe8; }
.bb-combos-grid .bb-hot  .bb-combo-amt { color: #9d174d; }
.bb-combos-grid .bb-warm { background: #fef9c3; border-color: #fde68a; }
.bb-combos-grid .bb-warm .bb-combo-amt { color: #854d0e; }
.bb-combos--empty { padding: 18px; text-align: center; }

/* ===== 期間快選按鈕群 (當天/週/月/年) ===== */
.period-picks {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    padding: 2px;
    margin-right: 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
}
.period-picks .btn { padding: 4px 10px; font-size: .85rem; }
.period-picks .btn.is-active {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}

/* ===== 系統設定面板 ===== */
.sys-fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 18px 18px;
    margin-bottom: 18px;
    background: var(--color-surface);
}
.sys-fieldset legend {
    padding: 0 8px;
    font-weight: 600;
    color: var(--color-text);
}
.sys-fieldset__hint { font-size: .85rem; margin: 4px 0 12px; }
.sys-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px 16px;
}
.sys-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
}
.sys-row > span:first-child {
    flex: 1;
    color: var(--color-muted);
    font-size: .9rem;
}
.sys-row input[type="number"] {
    width: 110px;
    padding: 5px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.sys-row input.sys-range-lo,
.sys-row input.sys-range-hi { width: 70px; }
.sys-range-sep { color: var(--color-muted); padding: 0 2px; }
.sys-unit { color: var(--color-muted); font-size: .85rem; min-width: 36px; }
.sys-row--toggle {
    margin-bottom: 8px;
    cursor: pointer;
}
.sys-row--toggle input { transform: scale(1.2); margin-right: 4px; }
.sys-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
}
.sys-msg {
    font-size: .9rem;
    padding: 4px 10px;
    border-radius: 4px;
}
.sys-msg--ok  { background: #dcfce7; color: #166534; }
.sys-msg--err { background: #fee2e2; color: #991b1b; }

/* ===== 大盤表 — 目前已漲價號碼 ===== */
.bb-risen {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}
.bb-risen__label {
    color: var(--color-muted);
    font-size: .85rem;
    line-height: 1.8;
    flex-shrink: 0;
}
.bb-risen__list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bb-risen-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid #fbcfe8;
    background: #fce7f3;
    border-radius: 999px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: .85rem;
    color: #9d174d;
}
.bb-risen-pill strong { font-weight: 700; }

/* ===== 全車設定 (per-號碼) ===== */
.ns-group { margin-bottom: 16px; }
.ns-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: .9rem;
}
.ns-table th, .ns-table td {
    border: 1px solid var(--color-border);
    padding: 4px 6px;
    text-align: center;
    vertical-align: middle;
}
.ns-table thead th {
    background: #fee2e2;     /* 截圖風格:粉紅號碼列 */
    font-weight: 700;
    color: #991b1b;
    font-size: 1rem;
    height: 32px;
}
.ns-table thead th.ns-all-col {
    background: #fde68a;     /* 「全部」用黃色強調 */
    color: #78350f;
}
.ns-table tbody th.ns-row-label {
    background: var(--color-surface-2);
    font-weight: 600;
    color: var(--color-muted);
    text-align: right;
    width: 80px;
    white-space: nowrap;
}
.ns-table input[type="number"] {
    width: 100%;
    padding: 3px 6px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font: inherit;
    text-align: right;
    background: #fff;
}
.ns-table input[type="number"]:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}
.ns-table input[readonly] {
    background: var(--color-surface-2);
    cursor: not-allowed;
}
.ns-table td.ns-all-col input {
    background: #fffbeb;
    border-color: #f59e0b;
}
.ns-table .ns-empty { background: var(--color-surface-2); }

/* ===== 賠率表 — 線倍率區 (對齊截圖粉紅表格風格) ===== */
.odds-lines {
    margin-bottom: 12px;
    overflow-x: auto;
}
.odds-lines__hint {
    font-size: .85rem;
    margin-bottom: 6px;
}
.odds-lines-table {
    border-collapse: collapse;
    table-layout: fixed;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-width: max-content;
}
.odds-lines-table th, .odds-lines-table td {
    border: 1px solid var(--color-border);
    padding: 0;
    text-align: center;
    width: 56px;
    height: 32px;
}
.odds-lines-table th.odds-line-label {
    background: #fecaca;
    color: #7f1d1d;
    font-weight: 700;
    font-size: 1rem;
    width: 48px;
    user-select: none;
}
.odds-lines-table th.odds-line-head {
    background: #fecaca;
    color: #7f1d1d;
    font-weight: 700;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 1rem;
}
.odds-lines-table th.odds-line-head.is-dirty,
.odds-lines-table td.odds-line-cell.is-dirty {
    background: #fde68a;
    color: #78350f;
}
.odds-lines-table td.odds-line-cell input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font: inherit;
    font-size: .9rem;
    padding: 4px;
}
.odds-lines-table td.odds-line-cell input:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
    background: #eff6ff;
}
.odds-lines-table td.odds-line-cell input[readonly] {
    background: var(--color-surface-2);
    color: var(--color-muted);
    cursor: not-allowed;
}

/* 大盤表 — 超限 cell 警示 */
.bb-table .bb-amount.bb-over {
    background: #fee2e2;
    color: #991b1b;
    font-weight: 700;
}
.bb-table .bb-over-tag {
    display: block;
    font-size: .75rem;
    color: #b91c1c;
    font-weight: 700;
    margin-top: 1px;
    line-height: 1.2;
}
.bb-over-summary {
    color: #991b1b;
    font-weight: 600;
}

/* ===== 客戶端主選單 (bet_s.html) ===== */
.client-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.client-tabs .tab {
    flex: 0 0 auto;
    padding: 10px 14px;
    font-size: .95rem;
}
.client-tabs .tab--danger {
    color: #dc2626;
}
.client-tabs .tab--danger.is-active {
    color: #fff;
    background: #dc2626;
    border-bottom-color: #dc2626;
    border-radius: 6px 6px 0 0;
}

/* 巢狀 panel.sub — 線上下注的左右兩欄 */
.client-grid .panel.sub h2 {
    margin-top: var(--space-4);
}
.client-grid .panel.sub h2:first-child {
    margin-top: 0;
}

/* 規則說明卡片 */
.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-3);
}
.rule-card {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}
.rule-card h4 {
    margin: 0 0 var(--space-2);
    color: var(--color-accent);
    font-size: 1rem;
}
.rule-card p {
    margin: 0;
    font-size: .9rem;
    line-height: 1.55;
}

/* 個人資料 */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
}
.profile-grid .kpi { background: var(--color-surface); }

/* AI 輸入法列印模式 */
@media print {
    body.client-page > *:not(main) { display: none !important; }
    .container > section { display: none !important; }
    #panel-ai-help { display: block !important; }
    #panel-ai-help button { display: none !important; }
    .client-tabs { display: none !important; }
}

/* 總帳卡片 */
.ledger-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
}
.ledger-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}
.ledger-card h4 {
    margin: 0 0 var(--space-2);
    font-size: .95rem;
}
.ledger-card .pl-pos { color: #15803d; font-weight: 700; }
.ledger-card .pl-neg { color: #b91c1c; font-weight: 700; }
.ledger-card .pl-zero { color: var(--color-muted); font-weight: 600; }
.ledger-card dl {
    margin: 0; display: grid; grid-template-columns: auto 1fr;
    gap: 4px 12px; font-size: .85rem;
}
.ledger-card dt { color: var(--color-muted); }
.ledger-card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* 公告列表 */
.news-list { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-3); }
.news-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
}
.news-item .news-meta { font-size: .8rem; color: var(--color-muted); margin-bottom: 4px; }
.news-item .news-content { white-space: pre-wrap; line-height: 1.55; }
