/* Apple Design System Inspired Theme */
:root {
    /* Color Palette - Apple System Colors */
    --app-bg: #F5F5F7;          /* Light Gray Background */
    --card-bg: #FFFFFF;         /* Pure White */
    --text-primary: #1D1D1F;    /* Near Black */
    --text-secondary: #86868B;  /* Neutral Gray */
    --text-tertiary: #B1B1B3;   /* Lighter Gray */
    
    /* Accent Colors */
    --accent-blue: #0071E3;     /* Apple Blue */
    --accent-blue-hover: #0077ED;
    --accent-green: #34C759;    /* Apple Green */
    --accent-red: #FF3B30;      /* Apple Red */
    --accent-orange: #FF9500;   /* Apple Orange */
    
    /* Borders & Shadows */
    --border-light: #E5E5EA;    /* Divider color */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.12);
    
    /* Dimensions */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
}

/* Base Typography */
body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    background-color: var(--app-bg);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html.bb-dark-mode-preload,
html.bb-dark-mode-preload body {
    background: #1c1c1c !important;
    color: #e6e6e6 !important;
}

.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-light);
    padding: 0.5rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 20;
}

.user-dropdown {
    position: relative;
}

.account-trigger {
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    background: var(--app-bg);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border-light);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.account-trigger:hover {
    background: rgba(0, 113, 227, 0.06);
    border-color: rgba(0, 113, 227, 0.18);
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    min-width: 150px;
    background: var(--card-bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 0.25rem 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
    z-index: 60;
}

.user-dropdown-menu::before {
    content: "";
    position: absolute;
    top: -0.5rem;
    left: 0;
    right: 0;
    height: 0.5rem;
}

.user-dropdown:hover .user-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown:hover .fa-chevron-down {
    transform: rotate(180deg);
}

.account-menu-item {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.account-menu-item i {
    width: 0.875rem;
    font-size: 0.75rem;
}

.account-menu-item:hover {
    color: var(--accent-blue);
    background: rgba(0, 113, 227, 0.06);
}

.account-menu-item-danger:hover {
    color: var(--accent-red);
    background: rgba(255, 59, 48, 0.08);
}

.form-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

/* Utility Classes (Custom overrides on top of Tailwind) */

/* Cards */
.apple-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0,0,0,0.02);
    /* transition: box-shadow 0.2s ease; 移除動畫以避免崩潰 */
    /* will-change: box-shadow; */
    /* backface-visibility: hidden; */
}
.apple-card:hover {
    box-shadow: var(--shadow-md);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 15px;
    transition: all 0.15s ease-out;
    cursor: pointer;
    user-select: none;
    border: none;
}
.btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
}
.btn-primary:hover {
    background-color: var(--accent-blue-hover);
}

.btn-secondary {
    background-color: rgba(0,0,0,0.05);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background-color: rgba(0,0,0,0.08);
}

.btn-danger {
    background-color: rgba(255, 59, 48, 0.1);
    color: var(--accent-red);
}
.btn-danger:hover {
    background-color: rgba(255, 59, 48, 0.15);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(0,0,0,0.03);
}

/* Inputs */
.apple-input {
    width: 100%;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    border: 1px solid #D1D1D6;
    background-color: rgba(255,255,255,0.8);
    font-size: 15px;
    color: var(--text-primary);
    transition: all 0.2s;
    outline: none;
}
.apple-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
    background-color: #fff;
}

/* Selects */
.apple-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

/* Modals */
.modal-backdrop,
.app-modal-backdrop {
    background-color: rgba(0,0,0,0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.app-modal-backdrop.hidden,
.modal-backdrop.hidden {
    display: none !important;
}
.modal-content,
.app-modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: modalPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: 100%;
    max-width: 28rem;
    padding: 2rem;
    border: 1px solid var(--border-light);
}

.app-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.app-modal-title {
    font-size: 1.25rem;
    line-height: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.app-modal-close {
    border: 0;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.25rem;
}

.app-modal-close:hover {
    color: var(--text-secondary);
}

.app-modal-body {
    color: var(--text-primary);
}

.app-modal-footer {
    margin-top: 2rem;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
}

@keyframes modalPop {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }

/* Toast Notification */
.app-toast {
    position: fixed;
    top: 64%;
    left: 50%;
    transform: translate(-50%, 14px) scale(0.98);
    background: rgba(50, 50, 50, 0.95);
    color: white;
    padding: 18px 34px;
    border-radius: 16px;
    font-size: 19px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    min-width: 240px;
    max-width: min(560px, calc(100vw - 32px));
    text-align: center;
    line-height: 1.45;
}

.app-toast.show {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}

.app-toast-success {
    background: rgba(22, 163, 74, 0.94);
}

.app-toast-error {
    background: rgba(220, 38, 38, 0.94);
}

.app-toast-info {
    background: rgba(31, 41, 55, 0.94);
}

/* Barcode Scanner Styles */
#barcode-reader {
    border: none;
    position: relative;
    background: #000;
    overflow: hidden; /* 確保雷射線不出界 */
}

#barcode-reader video {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

#barcode-canvas {
    display: none;
}

/* 掃描框與雷射線（參考 LINE 造型） */
#barcode-reader::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 280px;
    height: 150px;
    border: 2px solid rgba(255, 255, 255, 0.5); /* 白色半透明框 */
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5); /* 背景壓暗，突顯掃描區 */
    z-index: 10;
    pointer-events: none;
}

/* 紅色雷射掃描線（靜止） */
#barcode-reader::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 260px;
    height: 2px;
    background: #ff0000;
    box-shadow: 0 0 6px rgba(255, 0, 0, 0.6);
    z-index: 11;
    pointer-events: none;
}

/* Display Mode Toggle Buttons */
.display-mode-btn.active {
    background-color: var(--accent-blue);
    color: white;
}

/* Product List Table Style */
.product-list-table {
    width: 100%;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border-collapse: separate;
    border-spacing: 0;
}

.product-list-table thead {
    background: var(--app-bg);
    border-bottom: 2px solid var(--border-light);
}

.product-list-table thead th {
    position: sticky;
    top: 0;
    background: var(--app-bg);
    z-index: 10;
}

.product-list-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.product-list-table td {
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}

.product-list-table tbody tr {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.product-list-table tbody tr:hover {
    background-color: rgba(0, 113, 227, 0.03);
}

.product-list-table tbody tr:last-child td {
    border-bottom: none;
}

.product-list-table tbody tr.no-stock {
    cursor: not-allowed;
    opacity: 0.5;
    background-color: #f9f9f9;
}

.product-list-table tbody tr.no-stock:hover {
    background-color: #f9f9f9;
}

.product-list-table tbody tr.other-stock {
    background-color: rgba(0, 0, 0, 0.02);
}

.product-list-table tbody tr.other-stock:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

/* Responsive adjustments for mobile */
@media (max-width: 640px) {
    #barcode-scanner-modal .modal-content {
        width: 95%;
        margin: 0 auto;
    }
    
    #barcode-reader {
        min-height: 250px !important;
    }
}

#product-container.list-mode {
    padding-top: 0 !important;
}

/* 人員輸入框 placeholder 樣式 */
.placeholder-white::placeholder {
    color: rgba(255, 255, 255, 0.8);
    opacity: 1;
}

.placeholder-white::-webkit-input-placeholder {
    color: rgba(255, 255, 255, 0.8);
    opacity: 1;
}

.placeholder-white::-moz-placeholder {
    color: rgba(255, 255, 255, 0.8);
    opacity: 1;
}

.placeholder-white:-ms-input-placeholder {
    color: rgba(255, 255, 255, 0.8);
    opacity: 1;
}

/* 隱藏 datalist 輸入框的原生下拉箭頭 */
input[list]::-webkit-calendar-picker-indicator {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

input[list]::-webkit-list-button {
    display: none !important;
    opacity: 0;
}

/* Firefox */
input[list]::-moz-calendar-picker-indicator {
    display: none !important;
    opacity: 0;
}

/* 隱藏 number 輸入框的上下箭頭 */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Resizable Panels - 可調整大小的面板 */
.panel-divider {
    width: 4px;
    background-color: var(--border-light);
    cursor: col-resize;
    position: relative;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
    z-index: 5;
}

.panel-divider:hover {
    background-color: var(--accent-blue);
}

/* 分隔線 Tooltip */
.panel-divider::after {
    content: '點三下 - 設定「自訂寬度比例」\A點兩下 - 恢復「自訂寬度比例」';
    position: absolute;
    bottom: 50%;
    left: 12px;
    transform: translateY(50%);
    background: rgba(50, 50, 50, 0.95);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    white-space: pre;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
}

.panel-divider:hover::after {
    opacity: 1;
}

/* Tooltip 箭頭 */
.panel-divider::before {
    content: '';
    position: absolute;
    bottom: 50%;
    left: 8px;
    transform: translateY(50%) rotate(45deg);
    width: 8px;
    height: 8px;
    background: rgba(50, 50, 50, 0.95);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 999;
}

.panel-divider:hover::before {
    opacity: 1;
}

.panel-divider::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    right: -4px;
    /* 擴大點擊區域 */
}

.panel-divider.dragging {
    background-color: var(--accent-blue);
}

/* 拖曳時禁止選擇文字 */
body.no-select {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* 左右面板的基本樣式 */
.resizable-left-panel {
    flex-shrink: 0;
    transition: width 0s; /* 移除過渡效果以獲得更流暢的拖曳體驗 */
}

.resizable-right-panel {
    flex-grow: 1;
    flex-shrink: 0;
    transition: width 0s;
}

/* Cart Draft Badge */
.draft-badge {
    position: absolute;
    top: -5.4px;
    right: -5.4px;
    background: var(--accent-red);
    color: white;
    font-size: 9px;
    font-weight: 700;
    min-width: 16.2px;
    height: 16.2px;
    border-radius: 8.1px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4.5px;
    box-shadow: 0 1.8px 3.6px rgba(255, 59, 48, 0.3);
}

/* Transfer Badge (紅點或灰點) */
.transfer-badge {
    position: absolute;
    top: -5.4px;
    right: -5.4px;
    color: white;
    font-size: 9px;
    font-weight: 700;
    min-width: 16.2px;
    height: 16.2px;
    border-radius: 8.1px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4.5px;
}

.transfer-badge.red {
    background: var(--accent-red);
    box-shadow: 0 1.8px 3.6px rgba(255, 59, 48, 0.3);
}

.transfer-badge.gray {
    background: #9CA3AF;
    box-shadow: 0 1.8px 3.6px rgba(156, 163, 175, 0.3);
}

/* Cart Draft Dropdown */
.draft-dropdown {
    position: relative;
}

.draft-dropdown:hover .draft-dropdown-menu:not(.empty) {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.draft-dropdown-menu {
    transform: translateY(-10px);
}

.draft-dropdown-menu.empty {
    display: none;
}

/* Draft list scrollbar styling */
#draft-list-container::-webkit-scrollbar {
    width: 6px;
}

#draft-list-container::-webkit-scrollbar-track {
    background: transparent;
}

#draft-list-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 3px;
}

#draft-list-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

/* Low Performance Mode Card (Added for optimization) */
.simple-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(0,0,0,0.1); /* 稍微加深邊框以彌補無陰影 */
    box-shadow: none !important;
    transition: none !important;
    will-change: auto !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

.simple-card:hover {
    box-shadow: none !important;
    transform: none !important;
    background-color: #f9f9f9; /* 簡單的背景色變化替代陰影 */
}

/* =========================================================
   Global Dark Mode (BB only toggle handled in navigation.js)
   Color tiers: #1c1c1c / #212121 / #2c2c2c
   ========================================================= */
body.bb-dark-mode {
    --app-bg: #1c1c1c;
    --card-bg: #212121;
    --text-primary: #e6e6e6;
    --text-secondary: #b8b8b8;
    --text-tertiary: #909090;
    --border-light: #2c2c2c;
}

body.bb-dark-mode,
body.bb-dark-mode #app,
body.bb-dark-mode .min-h-screen {
    background: #1c1c1c !important;
    color: var(--text-primary);
}

body.bb-dark-mode .bg-\[var\(--app-bg\)\] {
    background-color: #1c1c1c !important;
}

/* 導航列姓名按鈕在深色模式提高亮度，避免被背景吃掉 */
body.bb-dark-mode #current-staff-name,
body.bb-dark-mode #header-staff-name-mobile,
body.bb-dark-mode .account-trigger {
    background: #262626 !important;
    border-color: #3a3a3a !important;
    color: #e6e6e6 !important;
}

body.bb-dark-mode #current-staff-name:hover,
body.bb-dark-mode #header-staff-name-mobile:hover,
body.bb-dark-mode .account-trigger:hover {
    background: #2e2e2e !important;
    border-color: #4a4a4a !important;
}

body.bb-dark-mode .app-header {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .apple-card,
body.bb-dark-mode .modal-content,
body.bb-dark-mode .app-modal-content,
body.bb-dark-mode .bg-white,
body.bb-dark-mode .bg-gray-50,
body.bb-dark-mode .bg-gray-100,
body.bb-dark-mode .bg-gray-200,
body.bb-dark-mode .user-dropdown-menu,
body.bb-dark-mode .store-dropdown-menu,
body.bb-dark-mode .hover-dropdown-menu,
body.bb-dark-mode .date-picker-calendar,
body.bb-dark-mode .sales-date-picker-calendar {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .border-\[var\(--border-light\)\],
body.bb-dark-mode .border-gray-100,
body.bb-dark-mode .border-gray-200,
body.bb-dark-mode .border-gray-300,
body.bb-dark-mode .border-gray-400 {
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .panel-divider {
    background-color: #2c2c2c !important;
}

body.bb-dark-mode input,
body.bb-dark-mode textarea,
body.bb-dark-mode select,
body.bb-dark-mode .apple-input,
body.bb-dark-mode .date-picker-display,
body.bb-dark-mode .sales-date-picker-display,
body.bb-dark-mode .hover-dropdown-button,
body.bb-dark-mode .btn-secondary,
body.bb-dark-mode .btn-ghost,
body.bb-dark-mode .payment-btn-new {
    background: #212121 !important;
    color: var(--text-primary) !important;
    border: 1px solid #2c2c2c !important;
    box-shadow: inset 0 0 0 1px #2c2c2c;
}

body.bb-dark-mode input::placeholder,
body.bb-dark-mode textarea::placeholder {
    color: var(--text-tertiary) !important;
}

body.bb-dark-mode .account-menu-item {
    color: var(--text-secondary) !important;
}

body.bb-dark-mode .account-menu-item:hover {
    background: #2a3446 !important;
    color: #dbe7ff !important;
}

body.bb-dark-mode .account-menu-item-danger:hover {
    background: #402626 !important;
    color: #ffb4ae !important;
}

body.bb-dark-mode .text-gray-400,
body.bb-dark-mode .text-gray-500,
body.bb-dark-mode .text-gray-600,
body.bb-dark-mode .text-gray-700 {
    color: #b8b8b8 !important;
}

/* 桌機導航：統一 active/inactive 視覺（含 pos/orders） */
body.bb-dark-mode #desktop-nav-container > a.nav-link-inactive,
body.bb-dark-mode #desktop-nav-container .nav-dropdown > a.nav-link-inactive {
    color: #b8b8b8 !important;
    border-color: transparent !important;
    background: transparent !important;
    box-shadow: none !important;
}

body.bb-dark-mode #desktop-nav-container > a.nav-link-inactive:hover,
body.bb-dark-mode #desktop-nav-container .nav-dropdown > a.nav-link-inactive:hover {
    color: #d6def0 !important;
    background: #262f3f !important;
    border-color: transparent !important;
}

body.bb-dark-mode #desktop-nav-container > a.nav-link-active,
body.bb-dark-mode #desktop-nav-container .nav-dropdown > a.nav-link-active {
    color: #dbe7ff !important;
    background: #2a3446 !important;
    border: 1px solid #3a465c !important;
    box-shadow: none !important;
}

body.bb-dark-mode #desktop-nav-container > a.nav-link-active:hover,
body.bb-dark-mode #desktop-nav-container .nav-dropdown > a.nav-link-active:hover {
    background: #33405a !important;
    color: #edf2ff !important;
}

/* 導覽下拉選中項目也走同一套暗藍層次 */
body.bb-dark-mode #desktop-nav-container .nav-sublink-active {
    background: #2a3446 !important;
    color: #dbe7ff !important;
}

body.bb-dark-mode .hover\:bg-gray-50:hover,
body.bb-dark-mode .hover\:bg-gray-100:hover,
body.bb-dark-mode .hover\:bg-gray-200:hover,
body.bb-dark-mode .hover\:bg-blue-50:hover,
body.bb-dark-mode .hover\:bg-blue-100:hover,
body.bb-dark-mode .hover-dropdown-item:hover,
body.bb-dark-mode .calendar-nav-btn:hover,
body.bb-dark-mode .calendar-footer-btn:hover {
    background: #2a3446 !important;
}

body.bb-dark-mode .calendar-header,
body.bb-dark-mode .calendar-footer {
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .calendar-day.today {
    background: #2c2c2c !important;
}

body.bb-dark-mode input[type="date"] {
    color-scheme: dark;
}

body.bb-dark-mode input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.8) saturate(0);
}

body.bb-dark-mode .product-list-table,
body.bb-dark-mode .orders-table,
body.bb-dark-mode .orders-table-clone-header {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .orders-table thead,
body.bb-dark-mode .orders-table thead th {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .order-group.row-even td,
body.bb-dark-mode .order-selected td,
body.bb-dark-mode .order-actions-row.order-selected td {
    background-color: #272727 !important;
}

body.bb-dark-mode .order-group:hover td {
    background-color: #2a3446 !important;
}

body.bb-dark-mode .simple-card {
    background: #212121 !important;
    border: 1px solid #2c2c2c !important;
}

body.bb-dark-mode .simple-card:hover,
body.bb-dark-mode .simple-card:active,
body.bb-dark-mode .simple-card.border-blue-500 {
    background: #2c2c2c !important;
    border-color: #4a4a4a !important;
}

/* Desktop nav active/inactive styles are unified by navigation.js classes. */

/* =========================================================
   Global Dark Mode Core - Data grids & legacy light styles
   ========================================================= */
body.bb-dark-mode table {
    background: #212121 !important;
    color: var(--text-primary) !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode table thead,
body.bb-dark-mode table thead th,
body.bb-dark-mode table th {
    background: #212121 !important;
    color: var(--text-secondary) !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode table td {
    background: transparent !important;
    color: var(--text-primary) !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode table tbody tr {
    background: #212121 !important;
}

body.bb-dark-mode table tbody tr:nth-child(even) {
    background: #272727 !important;
}

body.bb-dark-mode table tbody tr:hover {
    background: #2a3446 !important;
}

/* stock/order list 類型表格：覆蓋頁內寫死的淺藍 hover */
body.bb-dark-mode .stock-table tbody tr.row-even td {
    background-color: #272727 !important;
}

body.bb-dark-mode .stock-table tbody tr[data-row-index]:not(.bg-blue-50):hover td,
body.bb-dark-mode .stock-table tbody tr:hover td {
    background-color: #2a3446 !important;
}

body.bb-dark-mode .stock-table tbody tr.bg-blue-50 td {
    background-color: #2a3446 !important;
}

body.bb-dark-mode .stock-table tbody tr.bg-blue-50:hover td {
    background-color: #33405a !important;
}

/* 保留刪除模式警示，但降亮避免刺眼 */
body.bb-dark-mode .stock-table tbody tr.bulk-delete-selected td {
    background-color: #402626 !important;
}

body.bb-dark-mode .stock-table tbody tr.bulk-delete-selected:hover td {
    background-color: #4a2b2b !important;
}

/* 條列表格（多頁共用）覆蓋頁內白底/淺藍規則 */
body.bb-dark-mode .custom-orders-table tbody tr {
    background: #212121 !important;
}

body.bb-dark-mode .custom-orders-table tbody tr td {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .custom-orders-table tbody tr:nth-child(even) td,
body.bb-dark-mode .custom-orders-table tbody tr.record-even td {
    background: #272727 !important;
}

body.bb-dark-mode .custom-orders-table tbody tr:hover td,
body.bb-dark-mode .custom-orders-table tbody tr.record-hover td {
    background: #2a3446 !important;
}

/* 常見 Tailwind 灰階底色（多頁共用） */
body.bb-dark-mode .bg-gray-500,
body.bb-dark-mode .bg-gray-600,
body.bb-dark-mode .bg-slate-100,
body.bb-dark-mode .bg-slate-200 {
    background-color: #2c2c2c !important;
    color: var(--text-primary) !important;
}

/* 修正 legacy inline 淺底（多頁 JS 內嵌 HTML） */
body.bb-dark-mode [style*="background-color: #fff"],
body.bb-dark-mode [style*="background-color:#fff"],
body.bb-dark-mode [style*="background-color: #ffffff"],
body.bb-dark-mode [style*="background-color:#ffffff"],
body.bb-dark-mode [style*="background-color: white"],
body.bb-dark-mode [style*="background: #fff"],
body.bb-dark-mode [style*="background:#fff"],
body.bb-dark-mode [style*="background: #ffffff"],
body.bb-dark-mode [style*="background:#ffffff"],
body.bb-dark-mode [style*="background: white"],
body.bb-dark-mode [style*="background-color: #f5f5f5"],
body.bb-dark-mode [style*="background-color:#f5f5f5"],
body.bb-dark-mode [style*="background-color: #f9fafb"],
body.bb-dark-mode [style*="background-color:#f9fafb"],
body.bb-dark-mode [style*="background-color: #eff6ff"],
body.bb-dark-mode [style*="background-color:#eff6ff"],
body.bb-dark-mode [style*="background-color: #e3f2fd"],
body.bb-dark-mode [style*="background-color:#e3f2fd"] {
    background: #212121 !important;
}

/* =========================================================
   Message/Brand Message shared dark-mode fixes
   ========================================================= */
body.bb-dark-mode #conversation-list-panel,
body.bb-dark-mode #conversation-chat-panel,
body.bb-dark-mode #canned-panel-shell,
body.bb-dark-mode #conversation-header-bar,
body.bb-dark-mode #canned-message-list-wrap,
body.bb-dark-mode #canned-message-form-wrap {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

/* 品牌訊息頁：深色模式保留識別色（低飽和暗藍） */
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b,
body.brand-message-page.bb-dark-mode #conversation-header-bar {
    background: #2a3446 !important;
    border-color: #3a465c !important;
}

body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b h2,
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-\[var\(--text-primary\)\],
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-\[var\(--text-secondary\)\],
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-gray-400,
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-gray-500,
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-gray-600,
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-gray-700,
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-gray-800,
body.brand-message-page.bb-dark-mode #conversation-list-panel > .p-3.border-b .text-gray-900,
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-\[var\(--text-primary\)\],
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-\[var\(--text-secondary\)\],
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-gray-400,
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-gray-500,
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-gray-600,
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-gray-700,
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-gray-800,
body.brand-message-page.bb-dark-mode #conversation-header-bar .text-gray-900 {
    color: #e6ecf8 !important;
}

/* 對話文字/人名/說明文字被吃掉 */
body.bb-dark-mode .text-gray-800,
body.bb-dark-mode .text-gray-900,
body.bb-dark-mode .text-\[\#111827\],
body.bb-dark-mode .text-\[\#374151\],
body.bb-dark-mode .text-\[\#1f2937\] {
    color: #e6e6e6 !important;
}

/* 排行榜姓名與分數 */
body.bb-dark-mode .ranking-name,
body.bb-dark-mode .ranking-value,
body.bb-dark-mode .ranking-name-btn,
body.bb-dark-mode .ranking-value-btn,
body.bb-dark-mode .ranking-name-label {
    color: #e6e6e6 !important;
}

/* 分段控制按鈕（未回覆/處理中/已完成） */
body.bb-dark-mode .segmented {
    background: #2c2c2c !important;
}

body.bb-dark-mode .segmented button {
    background: transparent !important;
    color: #b8b8b8 !important;
}

body.bb-dark-mode .segmented button.active {
    background: #212121 !important;
    color: #e6e6e6 !important;
}

/* 查詢下拉與 hover */
body.bb-dark-mode .query-menu-trigger,
body.bb-dark-mode .query-menu-dropdown,
body.bb-dark-mode .query-menu-dropdown button {
    background: #212121 !important;
    color: #e6e6e6 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .query-menu-trigger:hover,
body.bb-dark-mode .query-menu-dropdown button:hover {
    background: #2c2c2c !important;
}

/* 罐頭訊息區 emoji picker 白底修正 */
body.bb-dark-mode .emoji-picker {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .emoji-picker-btn {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .emoji-picker-btn:hover {
    background: #2c2c2c !important;
}

/* Message twin pages: canned/quick-order/search strict overrides */
body.bb-dark-mode #quick-order-panel,
body.bb-dark-mode #customer-orders-panel,
body.bb-dark-mode #composer-wrapper,
body.bb-dark-mode #mobile-canned-shortcuts,
body.bb-dark-mode #conversation-list {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

/* 訊息頁客戶頭像 fallback 圈圈：避免被深色背景吃掉 */
body.bb-dark-mode #conversation-list .rounded-full.bg-gray-200,
body.bb-dark-mode #chat-title .rounded-full.bg-gray-200 {
    background: #2f3746 !important;
    color: #e6ecf8 !important;
    border: 1px solid #3a465c !important;
}

/* 訊息區：我方訊息泡泡需明顯區隔（避免與背景同色被吃掉） */
body.bb-dark-mode #message-list .justify-end .bg-gray-200 {
    background: #2c2c2c !important;
    color: #f3f4f6 !important;
}

/* 對話內容捲動軸：統一深色，避免亮軸 */
body.bb-dark-mode .chat-scroll {
    scrollbar-color: #2c2c2c #1c1c1c;
}

body.bb-dark-mode .chat-scroll::-webkit-scrollbar-track {
    background: #1c1c1c !important;
}

body.bb-dark-mode .chat-scroll::-webkit-scrollbar-thumb {
    background: #2c2c2c !important;
    border-radius: 6px;
}

body.bb-dark-mode .chat-scroll::-webkit-scrollbar-thumb:hover {
    background: #343434 !important;
}

body.bb-dark-mode #quick-order-product-results,
body.bb-dark-mode #quick-order-processing-menu,
body.bb-dark-mode #quick-order-deposit-menu,
body.bb-dark-mode #canned-scope-menu {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

/* 客訂商品區塊（原本 bg-gray-50/60 會偏亮） */
body.bb-dark-mode #quick-order-panel .bg-gray-50\/60 {
    background: #212121 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode .search-result-row,
body.bb-dark-mode .canned-message-row {
    background: #212121 !important;
    color: #e6e6e6 !important;
    border-bottom-color: #2c2c2c !important;
}

body.bb-dark-mode .search-result-row:hover,
body.bb-dark-mode .search-result-row.active,
body.bb-dark-mode .canned-message-row:hover,
body.bb-dark-mode .canned-row-wrap:hover .canned-message-row,
body.bb-dark-mode #quick-order-processing-menu button:hover,
body.bb-dark-mode #quick-order-deposit-menu button:hover,
body.bb-dark-mode #canned-scope-menu button:hover {
    background: #2c2c2c !important;
    color: #e6e6e6 !important;
}

body.bb-dark-mode .canned-message-row *,
body.bb-dark-mode .search-result-row * {
    color: inherit !important;
}

body.bb-dark-mode .canned-row-wrap:hover .canned-message-row,
body.bb-dark-mode .canned-row-wrap:hover .canned-message-row *,
body.bb-dark-mode .canned-message-row:hover,
body.bb-dark-mode .canned-message-row:hover * {
    color: #e6e6e6 !important;
}

body.bb-dark-mode #canned-scope-menu button,
body.bb-dark-mode #canned-scope-menu button *,
body.bb-dark-mode #canned-scope-trigger,
body.bb-dark-mode #canned-scope-trigger * {
    color: #e6e6e6 !important;
}

body.bb-dark-mode #canned-add-btn,
body.bb-dark-mode #mobile-canned-close-btn,
body.bb-dark-mode #quick-order-add-item-btn,
body.bb-dark-mode #quick-order-save-btn,
body.bb-dark-mode #quick-order-back-btn,
body.bb-dark-mode #quick-order-to-list-btn,
body.bb-dark-mode #quick-order-to-form-btn,
body.bb-dark-mode #conversation-status-btn,
body.bb-dark-mode #notification-permission-btn,
body.bb-dark-mode #canned-scope-trigger {
    background: #212121 !important;
    color: #e6e6e6 !important;
    border-color: #2c2c2c !important;
}

body.bb-dark-mode #canned-add-btn:hover,
body.bb-dark-mode #mobile-canned-close-btn:hover,
body.bb-dark-mode #quick-order-add-item-btn:hover,
body.bb-dark-mode #quick-order-save-btn:hover,
body.bb-dark-mode #quick-order-back-btn:hover,
body.bb-dark-mode #quick-order-to-list-btn:hover,
body.bb-dark-mode #quick-order-to-form-btn:hover,
body.bb-dark-mode #conversation-status-btn:hover,
body.bb-dark-mode #notification-permission-btn:hover,
body.bb-dark-mode #canned-scope-trigger:hover {
    background: #2c2c2c !important;
}

body.bb-dark-mode #emoji-picker,
body.bb-dark-mode .emoji-picker {
    background: #212121 !important;
    border: 1px solid #2c2c2c !important;
}

/* 罐頭訊息列表分隔線 */
body.bb-dark-mode #canned-message-list-wrap.divide-y > :not([hidden]) ~ :not([hidden]) {
    border-top-color: #2c2c2c !important;
}

/* 對話列表 swipe 刪除背景：避免未展開時滲出亮紅線 */
body.bb-dark-mode .conversation-swipe-actions {
    background: #212121 !important;
}

body.bb-dark-mode .conversation-swipe-delete-btn {
    background: #212121 !important;
    color: transparent !important;
}

/* 只有在滑開狀態才顯示刪除紅底，避免平時滲色 */
body.bb-dark-mode [data-swipe-opened="1"] .conversation-swipe-delete-btn {
    background: #6b1f1f !important;
    color: #f3f4f6 !important;
}

/* 對話列容器先鋪底，分隔線不會透出下層刪除區顏色 */
body.bb-dark-mode #conversation-list > [data-conversation-id] {
    background: #212121 !important;
}

body.bb-dark-mode .conversation-swipe-status-actions,
body.bb-dark-mode .conversation-swipe-status-stack {
    background: #212121 !important;
}

body.bb-dark-mode .conversation-swipe-status-stack .row-action-btn,
body.bb-dark-mode .conversation-swipe-status-stack .row-action-btn.row-action-btn--pending,
body.bb-dark-mode .conversation-swipe-status-stack .row-action-btn.row-action-btn--done,
body.bb-dark-mode .conversation-swipe-status-stack .row-action-btn.row-action-btn--inactive {
    background: #212121 !important;
    color: #b8b8b8 !important;
    border: none !important;
}

body.bb-dark-mode .conversation-swipe-status-stack .row-action-btn + .row-action-btn {
    border-left: 1px solid #2c2c2c !important;
}

/* 對話列表：分隔線與捲軸降亮度 */
body.bb-dark-mode #conversation-list.divide-y > :not([hidden]) ~ :not([hidden]) {
    border-top-color: #2c2c2c !important;
}

body.bb-dark-mode #conversation-list {
    scrollbar-color: #2c2c2c #1c1c1c;
}

body.bb-dark-mode #conversation-list::-webkit-scrollbar-track {
    background: #1c1c1c;
}

body.bb-dark-mode #conversation-list::-webkit-scrollbar-thumb {
    background: #2c2c2c;
    border-radius: 6px;
}

body.bb-dark-mode #conversation-list::-webkit-scrollbar-thumb:hover {
    background: #343434;
}
