:root {
    /* Theme Colors - Light Mode */
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #fafafa;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --border-color: #dddddd;
    --border-light: #eeeeee;
    --shadow-sm: rgba(0, 0, 0, 0.05);
    --shadow-md: rgba(0, 0, 0, 0.1);
    --shadow-lg: rgba(0, 0, 0, 0.15);

    /* Functional Colors */
    --color-primary: #2196F3;
    --color-primary-hover: #1976D2;
    --color-success: #4CAF50;
    --color-danger: #f44336;
    --color-warning: #FF9800;
    --color-warning-bg: #fff3cd;
    --color-warning-text: #856404;
    --color-oh-bg: rgba(54, 162, 235, 0.1);
    --color-nco-bg: rgba(255, 99, 132, 0.1);
    --color-custom-bg: rgba(128, 128, 128, 0.1);
    --color-additive-bg: rgba(152, 251, 152, 0.1);

    /* Input Styles */
    --input-bg: #ffffff;
    --input-border: #dddddd;
    --input-focus-border: #2196F3;
    --input-text: #333333;

    /* Comparison Feature */
    --cmp-bg: #ffffff;
    --cmp-header-bg: linear-gradient(135deg, #3b82f6, #1d4ed8);
    --cmp-card-bg: #ffffff;
    --cmp-card-border: #e2e8f0;
    --cmp-baseline-border: #3b82f6;
    --cmp-baseline-bg: rgba(59, 130, 246, 0.08);
    --cmp-baseline-badge: linear-gradient(135deg, #3b82f6, #6366f1);
    --cmp-text-accent: #6366f1;
    --cmp-table-header: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    --cmp-table-border: #f1f5f9;
    --cmp-section-bg: linear-gradient(90deg, #f8fafc, transparent);
    --cmp-sticky-bg: #ffffff;
    --cmp-switcher-bg: #f3f4f6;
    --cmp-info-bg: #f0f9ff;
    --cmp-info-border: #cbd5e1;
    --cmp-stats-bg: #f9fafb;
}

[data-theme="dark"] {
    /* Theme Colors - Dark Mode */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #242424;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --text-tertiary: #808080;
    --border-color: #404040;
    --border-light: #333333;
    --shadow-sm: rgba(0, 0, 0, 0.2);
    --shadow-md: rgba(0, 0, 0, 0.3);
    --shadow-lg: rgba(0, 0, 0, 0.4);

    /* Functional Colors - Dark Mode */
    --color-primary: #4dabf7;
    --color-primary-hover: #339af0;
    --color-success: #66BB6A;
    --color-danger: #ef5350;
    --color-warning: #FFB74D;
    --color-warning-bg: rgba(255, 193, 7, 0.15);
    --color-warning-text: #ffd54f;
    --color-oh-bg: rgba(54, 162, 235, 0.2);
    --color-nco-bg: rgba(255, 99, 132, 0.2);
    --color-custom-bg: rgba(128, 128, 128, 0.2);
    --color-additive-bg: rgba(152, 251, 152, 0.2);

    /* Input Styles - Dark Mode */
    --input-bg: #333333;
    --input-border: #404040;
    --input-focus-border: #4dabf7;
    --input-text: #ffffff;

    /* Comparison Feature - Dark Mode */
    --cmp-bg: #1a1a2e;
    --cmp-header-bg: linear-gradient(135deg, #2c3e50, #34495e);
    --cmp-card-bg: #1a1a2e;
    --cmp-card-border: #2d3748;
    --cmp-baseline-border: #6366f1;
    --cmp-baseline-bg: rgba(99, 102, 241, 0.1);
    --cmp-baseline-badge: linear-gradient(135deg, #6366f1, #8b5cf6);
    --cmp-text-accent: #a78bfa;
    --cmp-table-header: linear-gradient(135deg, #2a2a3e, #26314e);
    --cmp-table-border: #2d3748;
    --cmp-section-bg: linear-gradient(90deg, #2d3748, transparent);
    --cmp-sticky-bg: #1a1a2e;
    --cmp-switcher-bg: #333333;
    --cmp-info-bg: rgba(99, 102, 241, 0.1);
    --cmp-info-border: #4a5568;
    --cmp-stats-bg: #2a2a2a;
}

/* Smooth theme transition */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: Arial, sans-serif;
    background-color: var(--bg-primary);
    margin: 0;
    padding: 20px;
    line-height: 1.6;
    color: var(--text-primary);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

.card {
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow-md);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

.card-header {
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-light);
    padding-bottom: 15px;
    position: relative;
}

.card-title {
    font-size: 1.8em;
    color: var(--text-primary);
    margin: 0;
    text-align: center;
}

/* Theme Toggle Button */
.theme-toggle {
    position: absolute;
    right: 0;
    top: 0;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--color-primary);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.input-group {
    display: flex;
    align-items: center;
    margin: 20px 0;
    gap: 12px;
}

.input-label {
    min-width: 180px;
    font-weight: bold;
}

input,
select {
    padding: 8px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
    background-color: var(--input-bg);
    color: var(--input-text);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

/* PubChem 整合相關樣式 */
.input-with-button {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-button input {
    flex: 1;
}

.btn-pubchem {
    padding: 8px 12px;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-width: 40px;
}

.btn-pubchem:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-pubchem:active {
    transform: translateY(0);
}



.input-with-dropdown {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-with-dropdown input {
    flex: 1;
}

.pubchem-loading {
    background: linear-gradient(135deg, #ff9800, #f57c00) !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

.pubchem-result {
    margin-top: 10px;
    padding: 10px;
    background: #e8f5e8;
    border: 1px solid #4CAF50;
    border-radius: 6px;
    font-size: 12px;
}

.pubchem-error {
    margin-top: 10px;
    padding: 10px;
    background: #ffebee;
    border: 1px solid #f44336;
    border-radius: 6px;
    color: #d32f2f;
    font-size: 12px;
}

/* 新增重量單位選單的特定樣式 */
#weightUnit {
    width: auto;
    min-width: 80px;
    padding-right: 20px;
}

/* 調整總重量輸入框的寬度 */
#totalWeightInput {
    width: 150px;
}

/* 理論模式時的視覺反饋 */
#totalWeightInput.theoretical-mode {
    background-color: #eff6ff;
    border: 2px solid #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 輸入驗證樣式 */
#totalWeightInput.input-error {
    border: 2px solid #ef4444 !important;
    background-color: #fef2f2 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

#totalWeightInput.input-warning {
    border: 2px solid #f59e0b !important;
    background-color: #fffbeb !important;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* 模式指示器樣式 */
.mode-indicator {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    background-color: #f0f9ff;
    transition: all 0.3s ease;
    font-weight: 500;
}

.mode-indicator.theoretical {
    color: #3b82f6;
    background-color: #eff6ff;
    border: 1px solid #3b82f6;
}

.mode-indicator.smart-adjust {
    color: #10b981;
    background-color: #ecfdf5;
    border: 1px solid #10b981;
}

.material-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.6));
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

.material-content {
    background: linear-gradient(135deg, #ffffff, #f8fafe);
    padding: 15px;
    border-radius: 8px;
    width: 96vw;
    max-width: 96vw;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    box-sizing: border-box;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: slideIn 0.4s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.material-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px 0;
    border-bottom: 2px solid #e8f0fe;
    background: linear-gradient(135deg, #f8fafe, #e8f0fe);
    margin: -30px -30px 30px -30px;
    padding: 25px 30px;
    border-radius: 20px 20px 0 0;
}

.material-header h2 {
    margin: 0;
    color: #1a365d;
    font-size: 1.8em;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.material-header h2::before {
    content: "🧪";
    font-size: 1.2em;
}

.material-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.material-form .input-group {
    margin: 0;
}

.table-container {
    position: relative;
    overflow-x: auto;
    margin: 25px 0;
    border-radius: 16px;
    box-shadow: 
        0 8px 25px rgba(0, 0, 0, 0.08),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    background: linear-gradient(135deg, #ffffff, #fafbff);
    border: 1px solid #e2e8f0;
}

.table-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #3b82f6, #06b6d4, #10b981);
    border-radius: 16px 16px 0 0;
    z-index: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    table-layout: auto;
    box-sizing: border-box;
    min-width: 1200px;
}

th,
td {
    padding: 16px 12px;
    text-align: left;
    border: none;
    border-bottom: 1px solid var(--border-color);
    min-width: 100px;
    position: relative;
    box-sizing: border-box;
    vertical-align: middle;
    color: var(--text-primary);
}

th {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
    font-weight: 700;
    color: white;
    font-size: 0.875em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: sticky;
    top: 0;
    z-index: 10;
}

th:first-child {
    border-radius: 0 0 0 0;
}

th:last-child {
    border-radius: 0 0 0 0;
}

tbody tr {
    transition: all 0.2s ease;
}

tbody tr:hover {
    background: linear-gradient(135deg, #f8fafc, #e2e8f0);
    transform: scale(1.01);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

tbody tr:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}

tr.type-OH {
    background-color: var(--color-oh-bg);
}

tr.type-NCO {
    background-color: var(--color-nco-bg);
}

tr.type-custom {
    background-color: var(--color-custom-bg);
}

tr.type-additive {
    background-color: var(--color-additive-bg);
}

tr:hover {
    background-color: var(--bg-tertiary);
}

.button-group {
    display: flex;
    gap: 8px;
    margin: 15px 0 10px 0;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: center;
    box-sizing: border-box;
}

/* 選中配方後顯示的操作按鈕區域 */
.selected-recipe-actions {
    background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
    border: 2px solid #2196f3;
    border-radius: 12px;
    padding: 15px;
    margin: 15px 0;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.15);
    animation: slideDown 0.3s ease-out;
}

/* Dark mode styles for selected recipe actions */
[data-theme="dark"] .selected-recipe-actions {
    background: linear-gradient(135deg, rgba(77, 171, 247, 0.1) 0%, rgba(156, 39, 176, 0.1) 100%);
    border: 2px solid #4dabf7;
    box-shadow: 0 4px 12px rgba(77, 171, 247, 0.2);
}

.selected-recipe-actions .button-group {
    margin: 0;
    justify-content: center;
}

.selected-recipe-actions .button-group button {
    font-weight: 600;
    min-width: 150px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

.selected-recipe-actions .button-group button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

button {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    color: white;
    font-weight: 600;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

button::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

button:hover::before {
    left: 100%;
}

button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(-1px) scale(1.02);
    transition: all 0.1s;
}

button span {
    font-size: 1.1em;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669, #047857);
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-warning:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.4);
}

/* 進度指示器樣式 */
.progress-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    z-index: 10000;
    min-width: 350px;
}

.progress-header {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1f2937;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-message {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 8px;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #9ca3af;
}

/* 匯入預覽對話框樣式 */
.import-preview-dialog .material-content {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.import-preview-header {
    margin-bottom: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-radius: 12px;
    border-left: 4px solid #3b82f6;
}

.import-preview-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.import-preview-title h2 {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.import-preview-count {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background: #3b82f6;
    color: white;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

.import-preview-subtitle {
    color: #6b7280;
    font-size: 14px;
    margin-top: 4px;
}

.import-recipe-list {
    margin: 16px 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    max-height: 400px;
    overflow-y: auto;
}

.import-recipe-list::-webkit-scrollbar {
    width: 8px;
}

.import-recipe-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.import-recipe-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.import-recipe-list::-webkit-scrollbar-thumb:hover {
    background: #666;
}

.import-recipe-item {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: flex-start;
    transition: all 0.2s;
    position: relative;
}

.import-recipe-item:last-child {
    border-bottom: none;
}

.import-recipe-item:hover {
    background: linear-gradient(to right, #f0f9ff, #ffffff);
    padding-left: 20px;
}

.import-recipe-checkbox {
    margin-right: 16px;
    margin-top: 2px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #3b82f6;
}

.import-recipe-info {
    flex: 1;
}

.import-recipe-name {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.import-recipe-badge {
    display: inline-block;
    padding: 2px 8px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.import-recipe-details {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
}

.import-recipe-detail-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #6b7280;
    padding: 4px 10px;
    background: #f9fafb;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.import-recipe-detail-item strong {
    color: #374151;
    font-weight: 600;
}

.import-recipe-detail-icon {
    font-size: 14px;
    opacity: 0.8;
}

.import-preview-actions {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.import-preview-actions-left {
    font-size: 13px;
    color: #6b7280;
}

.import-preview-actions-right {
    display: flex;
    gap: 12px;
}

.import-select-all {
    margin: 16px 0;
    padding: 12px 16px;
    background: #f9fafb;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #e5e7eb;
}

.import-select-all-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.import-select-all-left input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #3b82f6;
}

.import-select-all-left label {
    font-weight: 600;
    color: #1f2937;
    cursor: pointer;
    font-size: 15px;
}

/* 多配方比較樣式 */
.multi-recipe-comparison {
    padding: 20px;
}

.comparison-view-switcher {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    padding: 10px;
    background: #f9fafb;
    border-radius: 8px;
}

.view-switch-btn {
    padding: 8px 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}

.view-switch-btn.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.view-switch-btn:hover:not(.active) {
    background: #f3f4f6;
}

.multi-recipe-grid {
    display: grid;
    gap: 20px;
    margin-top: 20px;
}

.multi-recipe-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.multi-recipe-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.multi-recipe-grid.cols-4 {
    grid-template-columns: repeat(2, 1fr);
}

.recipe-comparison-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    position: relative;
}

.recipe-comparison-card.baseline {
    border: 2px solid #3b82f6;
    background: linear-gradient(to right, #eff6ff, #ffffff);
}

.baseline-badge {
    position: absolute;
    top: -10px;
    right: 10px;
    background: #3b82f6;
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.recipe-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.recipe-card-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

.recipe-card-params {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.param-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px;
    background: #f9fafb;
    border-radius: 6px;
}

.param-label {
    font-size: 13px;
    color: #6b7280;
}

.param-value {
    font-size: 14px;
    font-weight: 500;
    color: #1f2937;
}

.param-diff {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

.param-diff.positive {
    background: #dcfce7;
    color: #166534;
}

.param-diff.negative {
    background: #fee2e2;
    color: #991b1b;
}

.param-diff.neutral {
    background: #f3f4f6;
    color: #6b7280;
}

.multi-recipe-table-container {
    overflow-x: auto;
    margin-top: 20px;
}

.multi-recipe-table {
    width: 100%;
    border-collapse: collapse;
}

.multi-recipe-table th {
    background: linear-gradient(to bottom, #f9fafb, #f3f4f6);
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 10;
}

.multi-recipe-table td {
    padding: 10px;
    border: 1px solid #e5e7eb;
    font-size: 14px;
}

.multi-recipe-table tr:hover {
    background: #f9fafb;
}

.multi-recipe-table .baseline-column {
    background: #eff6ff;
    font-weight: 500;
}

.materials-overlap-chart {
    margin-top: 20px;
    padding: 16px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.import-select-count {
    font-size: 13px;
    color: #6b7280;
    background: white;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin: 24px 0;
}

.chart-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 4px var(--shadow-sm);
    min-height: 400px;
    display: flex;
    flex-direction: column;
    resize: both;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.chart-title {
    font-size: 1.2em;
    color: var(--text-primary);
    margin: 0 0 16px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-light);
}

.chart-container {
    flex: 1;
    position: relative;
    min-height: 300px;
    min-width: 0;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.result-card {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.result-title {
    font-size: 1.1em;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.result-value {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--color-primary);
    margin: 8px 0;
}

.adjustment {
    margin-top: 12px;
    padding: 12px;
    border-radius: 6px;
    font-weight: 500;
    background: rgba(33, 150, 243, 0.1);
    color: var(--color-primary);
    border: 1px solid rgba(33, 150, 243, 0.2);
}

[data-theme="dark"] .adjustment {
    background: rgba(77, 171, 247, 0.15);
    color: var(--color-primary);
    border: 1px solid rgba(77, 171, 247, 0.3);
}

.adjustment.perfect {
    background: rgba(76, 175, 80, 0.15);
    color: #2E7D32;
    border: 1px solid rgba(76, 175, 80, 0.3);
}

[data-theme="dark"] .adjustment.perfect {
    background: rgba(76, 175, 80, 0.2);
    color: #66BB6A;
    border: 1px solid rgba(76, 175, 80, 0.4);
}

.adjustment.increase {
    background: rgba(255, 152, 0, 0.15);
    color: #E65100;
    border: 1px solid rgba(255, 152, 0, 0.3);
}

[data-theme="dark"] .adjustment.increase {
    background: rgba(255, 152, 0, 0.2);
    color: #FFB74D;
    border: 1px solid rgba(255, 152, 0, 0.4);
}

.adjustment.decrease {
    background: rgba(244, 67, 54, 0.15);
    color: #C62828;
    border: 1px solid rgba(244, 67, 54, 0.3);
}

[data-theme="dark"] .adjustment.decrease {
    background: rgba(244, 67, 54, 0.2);
    color: #ef5350;
    border: 1px solid rgba(244, 67, 54, 0.4);
}

#purityWarning {
    background: #E3F2FD;
    color: #1565C0;
}

.custom-type {
    display: none;
    margin-top: 5px;
    width: 100%;
    box-sizing: border-box;
}

.export-options {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
    flex-wrap: wrap;
    box-sizing: border-box;
    width: 100%;
}

.export-name {
    flex: 1;
    max-width: 180px;
    min-width: 120px;
    box-sizing: border-box;
}

@media (max-width: 1400px) {
    .container {
        padding: 10px;
    }
}

/* 中等尺寸設備優化 */
@media (max-width: 1024px) and (min-width: 769px) {
    .container {
        padding: 8px;
    }
    
    table {
        min-width: 800px;
        font-size: 0.9em;
    }
    
    th, td {
        padding: 14px 10px;
    }
}

/* 通知動畫 */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* 材料確認對話框樣式 */
.duplicate-material-item:hover {
    background: #fed7aa !important;
    transition: background 0.2s ease;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

@media (max-width: 768px) {
    .container {
        padding: 6px;
    }
    .card {
        padding: 16px;
    }

    .input-group {
        flex-direction: column;
        align-items: stretch;
    }

    .input-label {
        min-width: auto;
    }

    .button-group {
        flex-direction: column;
    }

    button {
        width: 100%;
    }

    .export-options {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .export-name {
        max-width: 100%;
        width: 100%;
    }

    .material-search-container {
        min-width: 150px;
    }
    
    .material-search-container input.material-search {
        min-width: 150px;
    }
    
    .material-search-container .material-select {
        min-width: 200px;
        max-width: 300px;
    }
}

.material-form-container {
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    max-width: 600px;
    margin: 0 auto;
}

.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    flex: 1;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.material-actions {
    text-align: right;
    margin-top: 20px;
}

.input-error {
    border: 1px solid var(--color-danger);
}

.material-search-container {
    width: 100%;
    min-width: 150px;
    position: relative;
    box-sizing: border-box;
}

.material-search-container input.material-search {
    width: 100%;
    box-sizing: border-box;
}

.material-search-container input.material-search.selected-material {
    background-color: #eff6ff;
    border-color: var(--color-primary);
    cursor: pointer;
}

.material-search-container input.material-search.selected-material:hover {
    background-color: #dbeafe;
    border-color: #1d4ed8;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
    transform: scale(1.01);
    transition: all 0.2s ease;
}

/* Dark mode styles for material search */
[data-theme="dark"] .material-search-container input.material-search.selected-material {
    background-color: rgba(77, 171, 247, 0.15);
    border-color: #4dabf7;
    color: var(--text-primary);
}

[data-theme="dark"] .material-search-container input.material-search.selected-material:hover {
    background-color: rgba(77, 171, 247, 0.25);
    border-color: #339af0;
    box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.3);
}

.material-search-container input.material-search:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

.material-search-container .material-select {
    width: 100%;
    box-sizing: border-box;
}

.material-search-container .material-select option {
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: normal;
    word-wrap: break-word;
    min-height: 36px;
    display: block;
    line-height: 1.4;
}

.material-search-container .material-select option:hover {
    background-color: rgba(33, 150, 243, 0.1);
}

.type-container {
    width: 100%;
    position: relative;
    box-sizing: border-box;
}

.input-container {
    width: 100%;
    position: relative;
    box-sizing: border-box;
}

.input-error {
    position: absolute;
    bottom: -20px;
    left: 0;
    color: var(--color-danger);
    font-size: 12px;
    display: none;
    white-space: nowrap;
}

.custom-type-container {
    margin-top: 8px;
}

.type-container select,
.input-container input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

.type-container select:focus,
.input-container input:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1);
}

.input-container input.error {
    border-color: var(--color-danger);
}

.input-container input:disabled {
    background-color: var(--bg-tertiary);
    cursor: not-allowed;
    opacity: 0.7;
}

.field-transition {
    transition: opacity 0.3s, transform 0.3s;
}

.field-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.table-container {
    margin-bottom: 40px;
}



.material-search-container .material-select option {
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.material-search-container .material-select option:hover {
    background-color: rgba(33, 150, 243, 0.1);
}

/* 確保表格容器有正確的定位上下文 */
.table-container {
    position: relative;
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* 調整表格單元格的樣式 */
td {
    position: relative;
}

/* 當下拉選單開啟時的容器樣式 */
.material-search-container.active {
    z-index: 1000;
}

/* Custom material dropdown */
.material-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #ddd);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1001;
}

.material-dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.15s;
    font-size: 0.9em;
    line-height: 1.4;
    color: var(--text-primary);
}

.material-dropdown-item:hover,
.material-dropdown-item.highlighted {
    background-color: rgba(33, 150, 243, 0.1);
}

[data-theme="dark"] .material-dropdown {
    background: var(--bg-primary, #1e1e2e);
    border-color: var(--border-color, #444);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

[data-theme="dark"] .material-dropdown-item:hover,
[data-theme="dark"] .material-dropdown-item.highlighted {
    background-color: rgba(77, 171, 247, 0.15);
}

/* 確保下拉選單在滾動時保持可見 */
.table-container::-webkit-scrollbar {
    height: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.table-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 在 CSS 部分添加以下樣式 */
.checkbox-container {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 20px;
}

.checkbox-container input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    cursor: pointer;
}

.checkbox-container label {
    cursor: pointer;
    user-select: none;
}

/* 浮動資訊框樣式 */
.material-tooltip {
    position: fixed;
    background: white;
    border: 2px solid #007bff;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    z-index: 10000;
    max-width: 400px;
    min-width: 300px;
    font-size: 13px;
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    pointer-events: none;
    max-height: 500px;
    overflow-y: auto;
}

/* Y軸高度對齊：確保彈窗與觸發元素的視覺一致性 */
.material-tooltip.height-aligned {
    min-height: 36px; /* 與搜尋輸入框的標準高度一致 */
}



.material-tooltip.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.material-tooltip-header {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 12px 15px;
    border-radius: 6px 6px 0 0;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 0;
    cursor: move;
    user-select: none;
}

.material-tooltip-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.material-tooltip-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tooltip-control-btn {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s ease;
}

.tooltip-control-btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.5);
}

.tooltip-control-btn.active {
    background: rgba(255,255,255,0.4);
    border-color: rgba(255,255,255,0.6);
    font-weight: bold;
}

.material-tooltip.dragging {
    transition: none;
    z-index: 10001;
}

.material-tooltip-body {
    padding: 15px;
}

.material-tooltip-loading {
    text-align: center;
    padding: 30px;
    color: #666;
}

.material-tooltip-loading::before {
    content: "🔄";
    display: block;
    font-size: 24px;
    margin-bottom: 10px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.material-tooltip-content {
    display: grid;
    gap: 12px;
}

.material-tooltip-section {
    border-left: 3px solid var(--border-light);
    padding-left: 12px;
    margin-bottom: 10px;
}

.material-tooltip-section.basic { border-left-color: #28a745; }
.material-tooltip-section.physical { border-left-color: #17a2b8; }
.material-tooltip-section.molecular { border-left-color: #ffc107; }
.material-tooltip-section.safety { border-left-color: #dc3545; }

.material-tooltip-section.stage-hidden {
    display: none;
}

.data-source-info {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-left: 4px solid var(--color-success);
    padding: 8px 12px;
    margin: 10px 0;
    font-size: 11px;
    color: var(--text-secondary);
    border-radius: 0 4px 4px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.data-source-info .source-icon {
    color: #28a745;
    font-size: 14px;
}

.stage-1-info {
    border-left-color: #007bff;
}

.stage-1-info .source-icon {
    color: #007bff;
}

[data-theme="dark"] .stage-1-info {
    background: rgba(77, 171, 247, 0.15) !important;
    border-left-color: #4dabf7;
}

[data-theme="dark"] .stage-1-info .source-icon {
    color: #4dabf7;
}

.stage-2-info {
    border-left-color: #28a745;
}

.stage-2-info .source-icon {
    color: #28a745;
}

[data-theme="dark"] .stage-2-info {
    background: rgba(76, 175, 80, 0.15) !important;
    border-left-color: #66BB6A;
}

[data-theme="dark"] .stage-2-info .source-icon {
    color: #66BB6A;
}

.material-tooltip-section h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: #333;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 6px;
}

.material-tooltip-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 10px;
    font-size: 12px;
    margin-bottom: 4px;
    align-items: start;
}

.material-tooltip-label {
    color: #666;
    font-weight: 500;
    white-space: nowrap;
}

.material-tooltip-value {
    color: #333;
    word-break: break-word;
}

.material-tooltip-links {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.material-tooltip-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    text-decoration: none;
    font-size: 11px;
    color: #495057;
    transition: all 0.2s ease;
}

.material-tooltip-link:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    text-decoration: none;
    transform: translateY(-1px);
}

.material-tooltip-error {
    color: #dc3545;
    text-align: center;
    padding: 20px;
    font-style: italic;
}

/* 材料選擇下拉選單懸停效果 */
.material-select {
    transition: all 0.2s ease;
}

.material-select:hover {
    background-color: rgba(0, 123, 255, 0.05);
    border-color: #007bff;
    cursor: help;
}

.material-select:hover:not(:empty) {
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.1);
}

/* 操作按鈕優化樣式 */
.operation-buttons {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.operation-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    color: white;
    font-weight: 600;
}

.operation-btn:hover {
    transform: translateY(-2px) scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.operation-btn:active {
    transform: translateY(0) scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.1s;
}

.btn-info.operation-btn {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
    box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}

.btn-info.operation-btn:hover {
    background: linear-gradient(135deg, #0891b2, #0e7490);
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.4);
}

.btn-warning.operation-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-warning.operation-btn:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-primary.operation-btn {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary.operation-btn:hover {
    background: linear-gradient(135deg, #2563eb, #1e40af);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-danger.operation-btn {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.btn-danger.operation-btn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

/* 操作按鈕通用文字樣式 */
.operation-btn .btn-text {
    font-size: 11px;
    font-weight: 600;
    margin-left: 3px;
    opacity: 0;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

.operation-btn:hover .btn-text {
    opacity: 1;
}

/* 編輯按鈕特殊樣式 */
.edit-material-btn {
    position: relative;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.edit-material-btn::after {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.6s;
}

.edit-material-btn:hover::after {
    left: 100%;
}

/* 助劑重量輸入視覺反饋樣式 */
.weight-input.additive-manual {
    background-color: #e6f3ff !important;  /* 淺藍色：已設定基準值 */
    border: 1px solid #99ccff;
}

.weight-input.additive-auto-adjusted {
    background-color: #cce7ff !important;  /* 較深藍色：已自動調整 */
    border: 1px solid #66b3ff;
    font-weight: 500;
}

.weight-input.additive-no-smart {
    background-color: transparent;  /* 無智能調整 */
    border: 1px solid #ddd;
}

/* 提示文字樣式 */
.weight-input[title]:hover {
    box-shadow: 0 0 5px rgba(37, 99, 235, 0.3);
    cursor: help;
}

/* 輸入模式指示器樣式 - 用量模式 */
tr.weight-mode .weight-input {
    background-color: #e6f3ff !important;
    border: 2px solid #3b82f6 !important;
}
tr.weight-mode .mole-ratio {
    opacity: 0.5;
    background-color: #f5f5f5;
}

/* 輸入模式指示器樣式 - 莫爾比模式 */
tr.mole-ratio-mode .mole-ratio {
    background-color: #e6ffe6 !important;
    border: 2px solid #22c55e !important;
}
tr.mole-ratio-mode .weight-input {
    opacity: 0.7;
    background-color: #f5f5f5;
}

/* 深色模式下的輸入模式樣式 */
[data-theme="dark"] tr.weight-mode .weight-input {
    background-color: rgba(59, 130, 246, 0.2) !important;
    border-color: #60a5fa !important;
}
[data-theme="dark"] tr.weight-mode .mole-ratio {
    background-color: #2a2a2a;
}
[data-theme="dark"] tr.mole-ratio-mode .mole-ratio {
    background-color: rgba(34, 197, 94, 0.2) !important;
    border-color: #4ade80 !important;
}
[data-theme="dark"] tr.mole-ratio-mode .weight-input {
    background-color: #2a2a2a;
}

/* 詳細資料按鈕樣式 */
.detail-material-btn {
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* 安全資料按鈕樣式 */
.safety-material-btn {
    border: 2px solid rgba(0, 0, 0, 0.1);
    position: relative;
}

.safety-material-btn::before {
    content: "⚡";
    position: absolute;
    top: -2px;
    right: -2px;
    font-size: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.safety-material-btn:hover::before {
    opacity: 1;
}

/* 刪除按鈕樣式 */
.delete-material-btn {
    border: 2px solid rgba(255, 255, 255, 0.3);
    position: relative;
}

.delete-material-btn:hover {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0) translateY(-2px) scale(1.1); }
    25% { transform: translateX(-2px) translateY(-2px) scale(1.1); }
    75% { transform: translateX(2px) translateY(-2px) scale(1.1); }
}

/* 排序指示器樣式 */
.sortable {
    user-select: none;
    position: relative;
    padding-right: 20px;
}

.sortable:hover {
    background: rgba(0, 123, 255, 0.05);
}

.sort-indicator {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    color: #007bff;
    font-size: 0.8em;
}

/* 配方表格優化樣式 */
#recipeManagerTable {
    border-collapse: collapse;
    table-layout: fixed;
}

#recipeManagerTable th,
#recipeManagerTable td {
    padding: 8px 12px;
    border-bottom: 1px solid #e9ecef;
    vertical-align: middle;
}

#recipeManagerTable th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
    position: sticky;
    top: 0;
    z-index: 10;
}

#recipeManagerTable tbody tr {
    transition: all 0.2s ease;
}

#recipeManagerTable tbody tr:hover {
    background-color: #f8f9fa;
}

#recipeManagerTable tbody tr[draggable="true"]:hover {
    background-color: #e3f2fd;
}

#recipeManagerTable tbody tr.dragging {
    opacity: 0.5;
}

/* 主頁原料表格拖曳樣式 */
#materialsTable tbody tr[draggable="true"] {
    cursor: grab;
}

#materialsTable tbody tr[draggable="true"]:active {
    cursor: grabbing;
}

#materialsTable tbody tr.material-dragging {
    opacity: 0.5;
    background: var(--drag-highlight, #e3f2fd) !important;
}

#materialsTable tbody tr.drag-over-top {
    border-top: 3px solid #2196f3 !important;
}

#materialsTable tbody tr.drag-over-bottom {
    border-bottom: 3px solid #2196f3 !important;
}

/* 確保按鈕在表格中的樣式 */
#recipeManagerTable .btn-info,
#recipeManagerTable .btn-primary,
#recipeManagerTable .btn-warning,
#recipeManagerTable .btn-danger {
    min-width: auto;
    padding: 3px 6px;
    font-size: 0.7em;
    border-radius: 3px;
    border: none;
    cursor: pointer;
}

#recipeManagerTable .btn-info {
    background-color: #17a2b8;
    color: white;
}

#recipeManagerTable .btn-primary {
    background-color: #007bff;
    color: white;
}

#recipeManagerTable .btn-warning {
    background-color: #ffc107;
    color: #212529;
}

#recipeManagerTable .btn-danger {
    background-color: #dc3545;
    color: white;
}

/* 批次表格優化樣式 */
#selectedRecipeBatchTable {
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 12px;
}

#selectedRecipeBatchTable th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 2px solid #dee2e6;
}

#selectedRecipeBatchTable td {
    vertical-align: middle;
}

#selectedRecipeBatchTable tbody tr:hover {
    background-color: #f8f9fa !important;
}

/* 批次狀態標籤樣式優化 */
#selectedRecipeBatchTable .status-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 500;
    text-align: center;
    min-width: 50px;
}

/* 響應式設計 */
@media (max-width: 1400px) {
    #recipeManagerTable {
        min-width: 800px;
    }

    #recipeManagerTable th:nth-child(2),
    #recipeManagerTable td:nth-child(2) {
        width: 200px;
    }

    #recipeManagerTable th:nth-child(3),
    #recipeManagerTable td:nth-child(3) {
        width: 350px;
    }

    #recipeManagerTable th:nth-child(4),
    #recipeManagerTable td:nth-child(4) {
        width: 130px;
    }

    /* 批次表格在小螢幕的優化 */
    #selectedRecipeBatchTable {
        font-size: 11px;
    }

    #selectedRecipeBatchTable th,
    #selectedRecipeBatchTable td {
        padding: 8px 6px;
    }
}

/* 脈衝動畫效果 */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}

/* 批次創建表單動畫 */
@keyframes modalSlideIn {
    from {
        transform: scale(0.9) translateY(30px);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.02) translateY(-5px);
        opacity: 0.9;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* 批次創建表單樣式 */
.batch-creation-overlay {
    backdrop-filter: blur(4px);
    /* z-index 現在由 JavaScript 動態設定 */
}

.batch-creation-overlay input,
.batch-creation-overlay textarea {
    transition: border-color 0.2s, box-shadow 0.2s;
    border: 1px solid #dee2e6;
    padding: 10px;
    border-radius: 6px;
}

.batch-creation-overlay input:focus,
.batch-creation-overlay textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

.batch-creation-overlay button {
    transition: all 0.2s;
    font-weight: 600;
}

.batch-creation-overlay button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* 批次狀態標籤閃爍動畫 */
@keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* 批次表格行hover效果增強 */
#selectedRecipeBatchTable tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05) !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* 空狀態彈跳動畫 */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

.drag-handle {
    cursor: move;
    user-select: none;
}

.drag-handle:hover {
    color: #007bff !important;
}

/* 響應式文字顯示 */
@media (max-width: 768px) {
    .operation-btn .btn-text {
        display: none;
    }

    /* 配方表格響應式優化 - 修復配方名稱被擠壓問題 */
    #recipeManagerTable tbody td:nth-child(2) {
        width: auto !important;
        min-width: 100px;
        max-width: 50vw;
    }

    /* 縮小按鈕間距 */
    #recipeManagerTable tbody td:nth-child(2) > div {
        gap: 4px !important;
    }

    /* 預覽按鈕微調 - 防止擠壓配方名稱 */
    #recipeManagerTable .btn-info {
        padding: 2px 4px !important;
        font-size: 0.6em !important;
        min-width: 24px !important;
        max-width: 30px !important;
        flex-shrink: 1 !important;  /* 允許按鈕縮小 */
    }

    /* 操作按鈕欄位自適應 */
    #recipeManagerTable tbody td:nth-child(4) {
        width: auto !important;
        min-width: 120px;
    }

    /* 操作按鈕間距優化 */
    #recipeManagerTable tbody td:nth-child(4) > div {
        gap: 2px !important;
    }

    /* 操作按鈕大小微調 */
    #recipeManagerTable .btn-primary,
    #recipeManagerTable .btn-warning,
    #recipeManagerTable .btn-danger {
        padding: 2px 4px !important;
        font-size: 0.65em !important;
    }
}

/* 響應式設計優化 */
@media (max-width: 1200px) {
    .material-content {
        width: 95vw;
        max-width: 95vw;
        padding: 15px;
        box-sizing: border-box;
    }
    
    .material-header {
        margin: -15px -15px 20px -15px;
        padding: 15px;
    }
    
    .material-header h2 {
        font-size: 1.5em;
    }
}

@media (max-width: 768px) {
    .material-content {
        width: 94vw;
        max-width: 94vw;
        padding: 12px;
        max-height: 95vh;
        box-sizing: border-box;
    }
    
    .material-header {
        margin: -12px -12px 15px -12px;
        padding: 12px;
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .export-options {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .export-name {
        max-width: 100%;
        width: 100%;
        margin-bottom: 4px;
    }
    
    .material-header h2 {
        font-size: 1.3em;
    }
    
    .button-group {
        justify-content: center;
        gap: 10px;
    }
    
    button {
        padding: 10px 16px;
        font-size: 0.8em;
    }
    
    .operation-buttons {
        flex-direction: column;
        gap: 4px;
    }
    
    .operation-btn {
        min-width: 32px;
        min-height: 32px;
        padding: 6px 8px;
        font-size: 13px;
    }
    
    .table-container {
        margin: 15px 0;
        border-radius: 12px;
    }
    
    table {
        min-width: 100%; /* 改為自適應寬度 */
        width: 100%;
    }
    
    th, td {
        padding: 8px 6px; /* 減少padding */
        font-size: 0.85em;
    }
}

/* 專為三星S25 Ultra等高端設備優化 */
@media (max-width: 430px) and (min-width: 400px) and (-webkit-min-device-pixel-ratio: 3) {
    .container {
        padding: 3px;
    }
    
    .material-content {
        width: 99vw !important;
        max-width: 99vw !important;
        padding: 10px !important;
        margin: 1px !important;
    }
    
    table {
        min-width: 100%;
        width: 100%;
        font-size: 0.82em;
    }
    
    th, td {
        padding: 5px 3px;
        font-size: 0.78em;
        line-height: 1.2;
    }
    
    .material-search-container input.material-search {
        min-width: 120px;
        font-size: 0.85em;
    }
    
    .button-group button {
        padding: 6px 10px;
        font-size: 0.7em;
        min-width: 60px;
    }

    .export-options button {
        font-size: 0.7em;
        padding: 6px 8px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* 高DPI設備通用優化 (包含S25 Ultra) */
@media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 3dppx) {
    .material-table {
        border-spacing: 0;
        border-collapse: separate;
    }
    
    th, td {
        border-width: 0.5px;
    }
    
    button {
        border-width: 0.5px;
    }
    
    input[type="number"], input[type="text"], select {
        border-width: 0.5px;
    }
}

/* 超寬屏幕設備優化 (19.5:9 比例) */
@media (max-aspect-ratio: 9/19) and (max-width: 430px) {
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .material-content {
        width: 99.5vw !important;
        max-width: 99.5vw !important;
    }
    
    .container {
        padding: 2px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 4px;
    }

    .material-content {
        padding: 8px !important;
        margin: 2px !important;
    }

    /* 極窄屏幕下的配方表格優化 */
    #recipeManagerTable tbody td:nth-child(2) {
        max-width: 65vw !important;
    }

    /* 預覽按鈕在極窄屏幕下進一步縮小 */
    #recipeManagerTable .btn-info {
        padding: 1px 3px !important;
        font-size: 0.9em !important;  /* 稍微加大emoji */
        min-width: 20px !important;
        max-width: 24px !important;
    }

    /* 減少按鈕與配方名稱的間距 */
    #recipeManagerTable tbody td:nth-child(2) > div {
        gap: 2px !important;
    }

    /* 隱藏備註欄位以節省空間 */
    #recipeManagerTable thead th:nth-child(3),
    #recipeManagerTable tbody td:nth-child(3) {
        display: none;
    }

    /* 進一步縮小操作按鈕 */
    #recipeManagerTable tbody td:nth-child(4) {
        min-width: 100px !important;
    }
    
    .material-header h2 {
        font-size: 1.1em;
    }
    
    .button-group {
        gap: 8px;
    }
    
    button {
        padding: 8px 12px;
        font-size: 0.75em;
    }

    .export-options {
        gap: 4px;
    }

    .export-options button {
        padding: 6px 8px;
        font-size: 0.7em;
        min-width: 0;
    }
    
    /* 極小屏幕的表格優化 */
    table {
        min-width: 100%;
        width: 100%;
    }
    
    th, td {
        padding: 6px 4px; /* 進一步減少padding */
        font-size: 0.8em;
    }
    
    .operation-btn {
        min-width: 28px;
        min-height: 28px;
        padding: 4px 6px;
        font-size: 12px;
    }
}

 /* 詳細資料顯示樣式 */
 .details-content {
     padding: 20px;
     max-height: 60vh;
     overflow-y: auto;
 }

 .loading-indicator {
     text-align: center;
     padding: 40px;
     color: #666;
     font-size: 16px;
 }

 .detailed-properties, .safety-data {
     display: grid;
     gap: 20px;
 }

 .property-section, .safety-section {
     background: #f8f9fa;
     border-radius: 8px;
     padding: 16px;
     border-left: 4px solid #007bff;
 }

 .property-section h3, .safety-section h3 {
     margin: 0 0 12px 0;
     color: #333;
     font-size: 16px;
     display: flex;
     align-items: center;
     gap: 8px;
 }

 .property-grid {
     display: grid;
     grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
     gap: 12px;
 }

 .property-item {
     display: flex;
     flex-direction: column;
     gap: 4px;
 }

 .property-item label {
     font-weight: 600;
     color: #555;
     font-size: 13px;
 }

 .property-item span {
     color: #333;
     font-size: 14px;
     background: white;
     padding: 6px 10px;
     border-radius: 4px;
     border: 1px solid #ddd;
 }

 .notes-content {
     background: white;
     padding: 12px;
     border-radius: 4px;
     border: 1px solid #ddd;
     font-size: 14px;
     line-height: 1.5;
 }

 .property-links, .safety-links {
     text-align: center;
     margin-top: 16px;
 }

 .property-links a, .safety-links a {
     display: inline-flex;
     align-items: center;
     gap: 6px;
     padding: 10px 20px;
     border-radius: 6px;
     text-decoration: none;
     font-weight: 500;
     transition: all 0.2s ease;
 }

 .property-links a:hover, .safety-links a:hover {
     transform: translateY(-1px);
     box-shadow: 0 4px 12px rgba(0,0,0,0.15);
     text-decoration: none;
 }

 .no-pubchem-notice, .no-safety-data-notice {
     background: #fff3cd;
     border: 1px solid #ffeaa7;
     border-radius: 6px;
     padding: 12px;
     text-align: center;
     color: #856404;
     font-style: italic;
 }

 .hazard-info, .precaution-info {
     display: grid;
     gap: 8px;
 }

 .hazard-item, .precaution-item {
     display: flex;
     gap: 10px;
     align-items: flex-start;
     background: white;
     padding: 10px;
     border-radius: 4px;
     border-left: 3px solid #dc3545;
 }

 .precaution-item {
     border-left-color: #28a745;
 }

 .hazard-code, .precaution-code {
     background: #e9ecef;
     padding: 2px 6px;
     border-radius: 3px;
     font-family: monospace;
     font-size: 12px;
     font-weight: bold;
     min-width: 60px;
     text-align: center;
 }

 .hazard-text, .precaution-text {
     flex: 1;
     font-size: 13px;
     line-height: 1.4;
 }

 .first-aid-info {
     display: grid;
     gap: 8px;
 }

 .first-aid-item {
     display: flex;
     gap: 10px;
     background: white;
     padding: 10px;
     border-radius: 4px;
     border-left: 3px solid #17a2b8;
 }

 .first-aid-item label {
     font-weight: 600;
     min-width: 80px;
     color: #555;
 }

 .first-aid-item span {
     flex: 1;
     font-size: 13px;
     line-height: 1.4;
 }

 .general-precautions, .emergency-info {
     margin-top: 16px;
 }

 .general-precautions h4, .emergency-info h4 {
     margin: 0 0 8px 0;
     font-size: 14px;
     color: #333;
 }

 .general-precautions ul, .emergency-info ul {
     margin: 0;
     padding-left: 20px;
 }

 .general-precautions li, .emergency-info li {
     margin-bottom: 4px;
     font-size: 13px;
     line-height: 1.4;
 }

/* 配方比較功能樣式 */
.comparison-container {
    margin-top: 20px;
}

.comparison-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 12px;
}

.recipe-info-card {
    flex: 1;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    text-align: center;
}

.recipe-info-card h3 {
    margin: 0 0 8px 0;
    color: #2196F3;
    font-size: 1.2em;
}

.recipe-info-card p {
    margin: 0;
    color: #666;
    font-size: 0.9em;
}

.comparison-vs {
    margin: 0 20px;
    font-size: 2em;
    font-weight: bold;
    color: #FF9800;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.comparison-sections {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.comparison-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid #e0e0e0;
}

.section-title {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.1em;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    color: var(--text-primary);
}

.comparison-table th,
.comparison-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
    background: var(--bg-tertiary);
    font-weight: bold;
    color: var(--text-primary);
}

.comparison-table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

/* 差異狀態樣式 */
.diff-added {
    background: rgba(76, 175, 80, 0.1);
    border-left: 4px solid var(--color-success);
}

[data-theme="dark"] .diff-added {
    background: rgba(76, 175, 80, 0.15);
}

.diff-removed {
    background: rgba(244, 67, 54, 0.1);
    border-left: 4px solid #f44336;
}

.diff-modified {
    background: rgba(33, 150, 243, 0.1);
    border-left: 4px solid #2196F3;
}

.diff-unchanged {
    background: rgba(158, 158, 158, 0.05);
}

.diff-value {
    font-weight: bold;
}

.diff-value.added {
    color: #4CAF50;
}

.diff-value.removed {
    color: #f44336;
}

.diff-value.modified {
    color: #2196F3;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.status-added {
    background: #4CAF50;
    color: white;
}

.status-removed {
    background: #f44336;
    color: white;
}

.status-modified {
    background: #2196F3;
    color: white;
}

.status-unchanged {
    background: #9E9E9E;
    color: white;
}

.change-indicator {
    font-weight: bold;
    font-size: 1.1em;
}

.change-up {
    color: var(--color-success);
}

.change-down {
    color: var(--color-danger);
}

.change-same {
    color: var(--text-tertiary);
}

/* === Comparison Feature V2 Styles === */

/* Diff grading levels (Phase 5a) */
.diff-level-0 { color: var(--text-tertiary); }
.diff-level-1 { color: #f59e0b; font-weight: 500; }
.diff-level-2 { color: #ea580c; font-weight: 600; }
.diff-level-3 { color: #dc2626; font-weight: 700; }
.diff-level-1.is-decrease { color: #3b82f6; }
.diff-level-2.is-decrease { color: #2563eb; }
.diff-level-3.is-decrease { color: #1d4ed8; }
[data-theme="dark"] .diff-level-1 { color: #fbbf24; }
[data-theme="dark"] .diff-level-2 { color: #fb923c; }
[data-theme="dark"] .diff-level-3 { color: #f87171; }
[data-theme="dark"] .diff-level-1.is-decrease { color: #60a5fa; }
[data-theme="dark"] .diff-level-2.is-decrease { color: #93c5fd; }
[data-theme="dark"] .diff-level-3.is-decrease { color: #bfdbfe; }

.diff-new-tag, .diff-removed-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}
.diff-new-tag { background: rgba(16, 185, 129, 0.15); color: #059669; }
.diff-removed-tag { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
[data-theme="dark"] .diff-new-tag { background: rgba(16, 185, 129, 0.25); color: #34d399; }
[data-theme="dark"] .diff-removed-tag { background: rgba(239, 68, 68, 0.25); color: #f87171; }

/* Comparison container */
.cmp-container { background: var(--cmp-bg) !important; max-width: 1400px; }
.cmp-header {
    background: var(--cmp-header-bg);
    color: white;
    padding: 24px;
    border-radius: 12px 12px 0 0;
    margin: -30px -30px 30px -30px;
}
.cmp-header h2 { color: white; margin-bottom: 16px; font-size: 24px; }
.cmp-header .cmp-badge {
    background: rgba(255, 255, 255, 0.25);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 14px;
    margin-left: 12px;
}
.cmp-header .button-group { gap: 12px; }

/* Comparison buttons */
.cmp-btn-baseline {
    background: var(--cmp-baseline-badge);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
}
.cmp-btn-export {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
    border: 1px solid rgba(245,158,11,0.3);
}
[data-theme="dark"] .cmp-btn-export {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}
.cmp-btn-close {
    background: linear-gradient(135deg, #fee2e2, #fecaca);
    color: #991b1b;
    border: 1px solid rgba(239,68,68,0.3);
}
[data-theme="dark"] .cmp-btn-close {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

/* View switcher */
.cmp-switcher {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    padding: 8px;
    background: var(--cmp-switcher-bg);
    border-radius: 12px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
}
[data-theme="dark"] .cmp-switcher {
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}
.cmp-switcher .view-switch-btn {
    flex: 1;
    padding: 12px 20px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}
.cmp-switcher .view-switch-btn.active {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Multi-recipe table */
.cmp-table-wrap {
    overflow-x: auto;
    border-radius: 12px;
    background: var(--cmp-bg);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 20px;
}
.cmp-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}
.cmp-table thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--cmp-table-header);
    padding: 12px;
    font-weight: 600;
    text-align: left;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}
.cmp-table tbody td {
    padding: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--cmp-table-border);
}
.cmp-table tbody tr:hover { background: var(--cmp-table-header); }
.cmp-table .cmp-sticky-col {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--cmp-sticky-bg);
}
.cmp-table thead .cmp-sticky-col { z-index: 11; }
.cmp-table .baseline-col { background: var(--cmp-baseline-bg) !important; }
.cmp-table .cmp-section-row td {
    background: var(--cmp-section-bg);
    font-weight: 600;
    color: var(--cmp-text-accent);
    padding: 8px 12px !important;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Baseline badge */
.cmp-baseline-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 8px;
    background: var(--cmp-baseline-badge);
    color: white;
}

/* Stat value in table */
.cmp-stat { font-weight: 600; color: var(--text-primary); }

/* Param diff badges */
.cmp-diff {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}
.cmp-diff.positive { color: #10b981; background: rgba(16, 185, 129, 0.1); }
.cmp-diff.negative { color: #ef4444; background: rgba(239, 68, 68, 0.1); }
.cmp-diff.neutral { color: var(--text-tertiary); background: rgba(107, 114, 128, 0.1); }
[data-theme="dark"] .cmp-diff.positive { color: #34d399; background: rgba(16, 185, 129, 0.2); }
[data-theme="dark"] .cmp-diff.negative { color: #f87171; background: rgba(239, 68, 68, 0.2); }

/* Info box */
.cmp-info {
    margin-top: 20px;
    padding: 16px;
    background: var(--cmp-info-bg);
    border-radius: 8px;
    border: 1px solid var(--cmp-info-border);
    font-size: 13px;
    color: var(--text-secondary);
}
.cmp-info ul { margin: 8px 0 0; padding-left: 20px; color: var(--text-tertiary); }

/* Card grid */
.cmp-card-grid {
    display: grid;
    gap: 20px;
    padding: 20px;
}
.cmp-card {
    background: var(--cmp-card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid var(--cmp-card-border);
}
.cmp-card:hover { transform: translateY(-4px); box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.15); }
.cmp-card.is-baseline { background: var(--cmp-baseline-bg); border-color: var(--cmp-baseline-border); }
.cmp-card .baseline-indicator {
    position: absolute;
    top: -10px;
    right: 20px;
    background: var(--cmp-baseline-badge);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.cmp-card-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--cmp-card-border);
}
.cmp-card-title { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.cmp-card-subtitle { font-size: 12px; color: var(--text-tertiary); }
.cmp-param-section { margin-bottom: 16px; }
.cmp-param-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--cmp-text-accent);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--cmp-table-border);
}
.cmp-param-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}
.cmp-param-row:hover {
    background: var(--cmp-baseline-bg);
    margin: 0 -8px;
    padding: 8px;
    border-radius: 6px;
}
.cmp-param-label { font-size: 13px; color: var(--text-tertiary); }
.cmp-param-val-wrap { display: flex; align-items: center; gap: 8px; }
.cmp-param-val { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.cmp-card-actions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--cmp-table-border);
    display: flex;
    gap: 8px;
}
.btn-cmp-card {
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}
.btn-cmp-card.primary { background: var(--cmp-baseline-badge); color: white; }
.btn-cmp-card.primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3); }
.btn-cmp-card.secondary { background: var(--bg-tertiary); color: var(--text-secondary); }
.btn-cmp-card.secondary:hover { background: var(--border-light); }

/* Material filter (Phase 5b) */
.cmp-mat-filter {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: center;
}
.cmp-mat-search {
    flex: 1;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--input-text);
    font-size: 14px;
}
.cmp-mat-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}
.cmp-mat-toggle.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }

/* Stats box */
.cmp-stats-box {
    margin-top: 20px;
    padding: 16px;
    background: var(--cmp-stats-bg);
    border-radius: 8px;
}
.cmp-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.cmp-stats-grid .stat-label { color: var(--text-tertiary); font-size: 13px; }
.cmp-stats-grid .stat-number { font-size: 24px; font-weight: 600; color: var(--text-primary); }
.cmp-stats-grid .stat-number.green { color: var(--color-success, #10b981); }
.cmp-stats-grid .stat-number.amber { color: var(--color-warning, #f59e0b); }

/* Chart view */
.cmp-chart-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 20px;
}
.cmp-chart-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
}
.cmp-chart-panel h4 {
    margin: 0 0 16px 0;
    color: var(--text-primary);
    font-size: 16px;
}
.cmp-chart-panel canvas { max-height: 350px; }
@media (max-width: 768px) {
    .cmp-chart-container { grid-template-columns: 1fr; }
    .cmp-card-grid { grid-template-columns: 1fr !important; }
}

/* VS comparison (2-recipe) */
.cmp-vs-container { display: grid; grid-template-columns: 1fr auto 1fr; gap: 24px; margin-bottom: 24px; }
.cmp-vs-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    color: var(--color-warning);
}
.cmp-vs-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border-color);
    text-align: center;
}
.cmp-vs-card h3 { color: var(--color-primary); margin: 0 0 8px 0; }
.cmp-vs-card p { color: var(--text-tertiary); margin: 0; font-size: 0.9em; }
.cmp-vs-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
}
.cmp-vs-section h4 {
    margin: 0 0 15px 0;
    color: var(--text-primary);
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-light);
}

/* 成本分析樣式 */
.cost-summary {
    margin-top: 15px;
    padding: 15px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: flex;
    gap: 30px;
    justify-content: space-around;
}

.cost-summary-item {
    text-align: center;
}

.cost-summary-item span:first-child {
    display: block;
    font-weight: bold;
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 5px;
}

.cost-diff-value {
    font-size: 1.2em;
    font-weight: bold;
}

.cost-diff-value.positive {
    color: var(--color-danger, #f44336);
}

.cost-diff-value.negative {
    color: var(--color-success, #4CAF50);
}

.cost-efficiency-value {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--color-primary, #2196F3);
}

.cost-per-unit {
    font-size: 0.9em;
    color: var(--text-tertiary, #666);
}

/* 響應式設計 */
@media (max-width: 1200px) {
    .comparison-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .comparison-vs {
        font-size: 1.5em;
        transform: rotate(90deg);
    }
}

@media (max-width: 768px) {
    .material-content {
        max-width: 98vw !important;
        width: 98vw !important;
        margin: 5px;
        padding: 12px;
    }
    
    .comparison-table-container {
        font-size: 0.8em;
    }
    
    .comparison-table th,
    .comparison-table td {
        padding: 8px 4px;
    }
    
    .cost-summary {
        flex-direction: column;
        gap: 15px;
    }
    
    .button-group {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .button-group button {
        min-width: 120px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .comparison-header {
        padding: 15px 10px;
    }
    
    .recipe-info-card {
        padding: 10px;
    }
    
    .section-title {
        font-size: 1em;
    }
    
    .comparison-table-container {
        font-size: 0.75em;
        overflow-x: auto;
    }
    
    .comparison-table {
        min-width: 600px;
    }
}

/* 未同步材料的視覺提示 */
.material-not-synced .material-search {
    background-color: #FFF3CD !important;
    border-color: #FFEEBA !important;
    position: relative;
}

/* Dark mode styles for unsynchronized materials */
[data-theme="dark"] .material-not-synced .material-search {
    background-color: rgba(255, 193, 7, 0.15) !important;
    border-color: #ffc107 !important;
    color: #ffd43b !important;
}

/* === 配方管理與原料管理深色模式優化 === */

/* 對話框背景 */
[data-theme="dark"] .material-dialog {
    background-color: rgba(0, 0, 0, 0.9) !important;
}

[data-theme="dark"] .material-content {
    background: #2a2a2a !important;
    color: #e0e0e0 !important;
    border: 1px solid #404040 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8) !important;
}

/* 對話框標題 */
[data-theme="dark"] .material-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%) !important;
    color: #ffffff !important;
    border-bottom: 2px solid #4a90e2 !important;
}

[data-theme="dark"] .material-header h2 {
    color: #ffffff !important;
}

[data-theme="dark"] .header-info {
    color: #b0b0b0 !important;
}

/* 搜尋欄位 */
[data-theme="dark"] .search-container {
    background-color: #333333 !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .search-container input {
    background-color: #404040 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
}

[data-theme="dark"] .search-container input:focus {
    background-color: #4a4a4a !important;
    border-color: #4a90e2 !important;
    outline: 1px solid #4a90e2 !important;
}

[data-theme="dark"] .search-container input::placeholder {
    color: #999999 !important;
}

[data-theme="dark"] .search-container select {
    background-color: #404040 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
}

/* 表格樣式 */
[data-theme="dark"] .recipe-table,
[data-theme="dark"] .material-table {
    background-color: #2a2a2a !important;
}

[data-theme="dark"] .recipe-table th,
[data-theme="dark"] .material-table th {
    background: linear-gradient(180deg, #3a4a5c 0%, #2c3e50 100%) !important;
    color: #ffffff !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .recipe-table td,
[data-theme="dark"] .material-table td {
    background-color: #333333 !important;
    color: #e0e0e0 !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .recipe-table tr:hover td,
[data-theme="dark"] .material-table tr:hover td {
    background-color: #3a3a3a !important;
}

[data-theme="dark"] .recipe-table tr.selected td,
[data-theme="dark"] .material-table tr.selected td {
    background-color: rgba(74, 144, 226, 0.2) !important;
}

/* 按鈕樣式優化 */
[data-theme="dark"] .material-content .btn-primary {
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%) !important;
    border: 1px solid #4a90e2 !important;
    color: #ffffff !important;
}

[data-theme="dark"] .material-content .btn-primary:hover {
    background: linear-gradient(135deg, #5ba0f2 0%, #4080c0 100%) !important;
}

[data-theme="dark"] .material-content .btn-success {
    background: linear-gradient(135deg, #5cb85c 0%, #4cae4c 100%) !important;
    border: 1px solid #5cb85c !important;
    color: #ffffff !important;
}

[data-theme="dark"] .material-content .btn-warning {
    background: linear-gradient(135deg, #f0ad4e 0%, #ec971f 100%) !important;
    border: 1px solid #f0ad4e !important;
    color: #ffffff !important;
}

[data-theme="dark"] .material-content .btn-danger {
    background: linear-gradient(135deg, #d9534f 0%, #c9302c 100%) !important;
    border: 1px solid #d9534f !important;
    color: #ffffff !important;
}

[data-theme="dark"] .material-content .btn-info {
    background: linear-gradient(135deg, #5bc0de 0%, #31b0d5 100%) !important;
    border: 1px solid #5bc0de !important;
    color: #ffffff !important;
}

/* 關閉按鈕 */
[data-theme="dark"] .btn-close,
[data-theme="dark"] .close-btn {
    color: #999999 !important;
}

[data-theme="dark"] .btn-close:hover,
[data-theme="dark"] .close-btn:hover {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* 選擇框樣式 */
[data-theme="dark"] input[type="checkbox"] {
    accent-color: #4a90e2 !important;
}

/* 狀態標籤 */
[data-theme="dark"] .status-label {
    background-color: rgba(74, 144, 226, 0.2) !important;
    color: #4dabf7 !important;
    border: 1px solid #4a90e2 !important;
}

/* 分頁控制 */
[data-theme="dark"] .pagination {
    background-color: #2a2a2a !important;
}

[data-theme="dark"] .pagination button {
    background-color: #404040 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
}

[data-theme="dark"] .pagination button:hover {
    background-color: #4a4a4a !important;
    border-color: #4a90e2 !important;
}

[data-theme="dark"] .pagination button.active {
    background-color: #4a90e2 !important;
    color: #ffffff !important;
}

/* 工具提示 */
[data-theme="dark"] .material-tooltip {
    background-color: #333333 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
}

[data-theme="dark"] .material-tooltip-label {
    color: #aaaaaa !important;
}

[data-theme="dark"] .material-tooltip-value {
    color: #ffffff !important;
}

[data-theme="dark"] .material-tooltip-section h4 {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .material-tooltip-links {
    border-top-color: #555555 !important;
}

[data-theme="dark"] .material-tooltip-link {
    background: #404040 !important;
    color: #4dabf7 !important;
    border-color: #555555 !important;
}

[data-theme="dark"] .material-tooltip-link:hover {
    background: #4a4a4a !important;
    border-color: #4dabf7 !important;
}

/* 表單輸入欄位 */
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-group select {
    background-color: #404040 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
}

[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-group select:focus {
    background-color: #4a4a4a !important;
    border-color: #4a90e2 !important;
    outline: 1px solid #4a90e2 !important;
}

[data-theme="dark"] .form-group label {
    color: #e0e0e0 !important;
}

/* 統計資訊區 */
[data-theme="dark"] .stats-container {
    background-color: #333333 !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .stats-item {
    color: #b0b0b0 !important;
}

[data-theme="dark"] .stats-value {
    color: #4dabf7 !important;
}

/* 配方詳情彈窗 */
[data-theme="dark"] .recipe-details {
    background-color: #2a2a2a !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .recipe-details-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%) !important;
    color: #ffffff !important;
}

[data-theme="dark"] .recipe-details-content {
    color: #e0e0e0 !important;
}

/* 滾動條樣式 */
[data-theme="dark"] .material-content::-webkit-scrollbar {
    background-color: #2a2a2a !important;
}

[data-theme="dark"] .material-content::-webkit-scrollbar-thumb {
    background-color: #555555 !important;
    border-radius: 4px;
}

[data-theme="dark"] .material-content::-webkit-scrollbar-thumb:hover {
    background-color: #666666 !important;
}

/* 刪除選中數量標籤 */
[data-theme="dark"] .selected-count {
    background-color: #d32f2f !important;
    color: #ffffff !important;
}

/* === 配方參數與配方資訊深色模式優化 === */

/* 配方資訊卡片 */
[data-theme="dark"] .recipe-info-card {
    background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%) !important;
    border: 1px solid #404040 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5) !important;
}

[data-theme="dark"] .recipe-info-card h3 {
    color: #4dabf7 !important;
}

[data-theme="dark"] .recipe-info-card p {
    color: #b0b0b0 !important;
}

/* 配方參數區塊 */
[data-theme="dark"] div[style*="background: #f8f9fa"][style*="border-left: 4px solid #3498db"] {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.1) 0%, rgba(41, 128, 185, 0.1) 100%) !important;
    border-left-color: #4dabf7 !important;
}

/* 配方資訊區塊 */
[data-theme="dark"] div[style*="background: #f8f9fa"][style*="border-left: 4px solid #9b59b6"] {
    background: linear-gradient(135deg, rgba(155, 89, 182, 0.1) 0%, rgba(142, 68, 173, 0.1) 100%) !important;
    border-left-color: #bb86fc !important;
}

/* 區塊標題 */
[data-theme="dark"] h4[style*="color: #2c3e50"] {
    color: #ffffff !important;
}

/* 參數標籤 */
[data-theme="dark"] span[style*="color: #7f8c8d"] {
    color: #a0a0a0 !important;
}

/* 參數數值 */
[data-theme="dark"] strong[style*="color: #2c3e50"] {
    color: #4dabf7 !important;
}

/* 編輯模式輸入框 */
[data-theme="dark"] input[style*="border: 1px solid #ddd"],
[data-theme="dark"] textarea[style*="border: 1px solid #ddd"] {
    background-color: #404040 !important;
    color: #ffffff !important;
    border-color: #555555 !important;
}

[data-theme="dark"] input[style*="border: 1px solid #ddd"]:focus,
[data-theme="dark"] textarea[style*="border: 1px solid #ddd"]:focus {
    background-color: #4a4a4a !important;
    border-color: #4dabf7 !important;
    outline: 1px solid #4dabf7 !important;
}

/* 導入配方資訊 */
[data-theme="dark"] .import-recipe-info {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .import-recipe-name {
    color: #ffffff !important;
}

[data-theme="dark"] .import-recipe-details {
    color: #b0b0b0 !important;
}

[data-theme="dark"] .import-recipe-item {
    background-color: #2a2a2a !important;
    border-color: #404040 !important;
}

[data-theme="dark"] .import-recipe-item:hover {
    background-color: #333333 !important;
    border-color: #4dabf7 !important;
}

/* 比較對話框 */
[data-theme="dark"] .comparison-header {
    background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%) !important;
}

[data-theme="dark"] .comparison-vs {
    color: #ffa726 !important;
}

/* 配方參數對比圖表 */
[data-theme="dark"] .materials-overlap-chart {
    background-color: #2a2a2a !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .materials-overlap-chart h3 {
    color: #ffffff !important;
}

[data-theme="dark"] .materials-overlap-chart p {
    color: #b0b0b0 !important;
}

/* 比較表格 */
[data-theme="dark"] .comparison-table {
    background-color: #2a2a2a !important;
}

[data-theme="dark"] .comparison-table th {
    background: linear-gradient(180deg, #3a4a5c 0%, #2c3e50 100%) !important;
    color: #ffffff !important;
    border-color: #404040 !important;
}

[data-theme="dark"] .comparison-table td {
    background-color: #333333 !important;
    color: #e0e0e0 !important;
    border-color: #404040 !important;
}

[data-theme="dark"] .comparison-table tr:hover td {
    background-color: #3a3a3a !important;
}

/* 差異高亮 */
[data-theme="dark"] .comparison-table .diff-highlight {
    background-color: rgba(255, 193, 7, 0.2) !important;
    color: #ffd43b !important;
}

[data-theme="dark"] .comparison-table .match-highlight {
    background-color: rgba(76, 175, 80, 0.2) !important;
    color: #66bb6a !important;
}

/* 材料重疊分析 */
[data-theme="dark"] .materials-overlap {
    background-color: #2a2a2a !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .overlap-category {
    background-color: #333333 !important;
    border-color: #404040 !important;
}

[data-theme="dark"] .overlap-category h4 {
    color: #ffffff !important;
}

[data-theme="dark"] .material-chip {
    background-color: #404040 !important;
    color: #e0e0e0 !important;
    border-color: #555555 !important;
}

/* === 新增原料、編輯、詳細、安全頁面深色模式優化 === */

/* 新增原料對話框 */
[data-theme="dark"] .swal2-popup {
    background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%) !important;
    color: #e0e0e0 !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .swal2-title {
    color: #ffffff !important;
}

[data-theme="dark"] .swal2-html-container {
    color: #e0e0e0 !important;
}

[data-theme="dark"] .swal2-input,
[data-theme="dark"] .swal2-select,
[data-theme="dark"] .swal2-textarea {
    background-color: #404040 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
}

[data-theme="dark"] .swal2-input:focus,
[data-theme="dark"] .swal2-select:focus,
[data-theme="dark"] .swal2-textarea:focus {
    background-color: #4a4a4a !important;
    border-color: #4dabf7 !important;
    outline: 1px solid #4dabf7 !important;
}

[data-theme="dark"] .swal2-label {
    color: #b0b0b0 !important;
}

/* SweetAlert2按鈕 */
[data-theme="dark"] .swal2-confirm {
    background: linear-gradient(135deg, #4dabf7 0%, #3a8fd9 100%) !important;
    color: #ffffff !important;
    border: none !important;
}

[data-theme="dark"] .swal2-confirm:hover {
    background: linear-gradient(135deg, #5db8ff 0%, #4a9fe9 100%) !important;
}

[data-theme="dark"] .swal2-cancel {
    background: linear-gradient(135deg, #555555 0%, #444444 100%) !important;
    color: #ffffff !important;
    border: 1px solid #666666 !important;
}

[data-theme="dark"] .swal2-cancel:hover {
    background: linear-gradient(135deg, #666666 0%, #555555 100%) !important;
}

/* 材料表單內容 */
[data-theme="dark"] .material-form {
    background-color: transparent !important;
}

[data-theme="dark"] .material-form .form-group {
    margin-bottom: 15px;
}

[data-theme="dark"] .material-form label {
    color: #b0b0b0 !important;
    font-weight: 600;
}

[data-theme="dark"] .material-form input[type="text"],
[data-theme="dark"] .material-form input[type="number"],
[data-theme="dark"] .material-form select,
[data-theme="dark"] .material-form textarea {
    background-color: #404040 !important;
    color: #ffffff !important;
    border: 1px solid #555555 !important;
    padding: 8px 12px;
    border-radius: 4px;
    width: 100%;
}

[data-theme="dark"] .material-form input[type="text"]:focus,
[data-theme="dark"] .material-form input[type="number"]:focus,
[data-theme="dark"] .material-form select:focus,
[data-theme="dark"] .material-form textarea:focus {
    background-color: #4a4a4a !important;
    border-color: #4dabf7 !important;
    outline: none;
    box-shadow: 0 0 0 2px rgba(77, 171, 247, 0.2);
}

/* 詳細資訊視窗 */
[data-theme="dark"] .material-details-popup {
    background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%) !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .material-details-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%) !important;
    color: #ffffff !important;
    border-bottom: 2px solid #4dabf7 !important;
}

[data-theme="dark"] .material-details-body {
    background-color: #2a2a2a !important;
    color: #e0e0e0 !important;
}

[data-theme="dark"] .material-details-section {
    background-color: #333333 !important;
    border: 1px solid #404040 !important;
    margin-bottom: 10px;
    padding: 15px;
    border-radius: 6px;
}

[data-theme="dark"] .material-details-section h3 {
    color: #4dabf7 !important;
    border-bottom: 1px solid #404040 !important;
    padding-bottom: 8px;
    margin-bottom: 12px;
}

[data-theme="dark"] .material-property {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid #3a3a3a;
}

[data-theme="dark"] .material-property-label {
    color: #a0a0a0 !important;
    font-weight: 500;
}

[data-theme="dark"] .material-property-value {
    color: #ffffff !important;
}

/* 安全資訊視窗 */
[data-theme="dark"] .safety-info-popup {
    background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%) !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .safety-header {
    background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%) !important;
    color: #ffffff !important;
    border-bottom: 2px solid #ff5252 !important;
}

[data-theme="dark"] .safety-section {
    background-color: #333333 !important;
    border: 1px solid #404040 !important;
    margin: 10px 0;
    padding: 15px;
    border-radius: 6px;
}

[data-theme="dark"] .safety-section h4 {
    color: #ff8a80 !important;
    margin-bottom: 10px;
}

[data-theme="dark"] .hazard-statement {
    background-color: rgba(255, 82, 82, 0.1) !important;
    border-left: 3px solid #ff5252 !important;
    color: #ffcdd2 !important;
    padding: 8px 12px;
    margin: 5px 0;
}

[data-theme="dark"] .precaution-statement {
    background-color: rgba(255, 193, 7, 0.1) !important;
    border-left: 3px solid #ffc107 !important;
    color: #fff3cd !important;
    padding: 8px 12px;
    margin: 5px 0;
}

/* 表格樣式優化 */
[data-theme="dark"] .material-details-table,
[data-theme="dark"] .safety-info-table {
    width: 100%;
    border-collapse: collapse;
}

[data-theme="dark"] .material-details-table th,
[data-theme="dark"] .safety-info-table th {
    background: linear-gradient(135deg, #3a4a5c 0%, #2c3e50 100%) !important;
    color: #ffffff !important;
    padding: 10px;
    text-align: left;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .material-details-table td,
[data-theme="dark"] .safety-info-table td {
    background-color: #2a2a2a !important;
    color: #e0e0e0 !important;
    padding: 8px 10px;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .material-details-table tr:hover td,
[data-theme="dark"] .safety-info-table tr:hover td {
    background-color: #333333 !important;
}

/* 標籤和徽章 */
[data-theme="dark"] .material-badge {
    background: linear-gradient(135deg, #4dabf7 0%, #3a8fd9 100%) !important;
    color: #ffffff !important;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    display: inline-block;
    margin: 2px;
}

[data-theme="dark"] .danger-badge {
    background: linear-gradient(135deg, #ff5252 0%, #d32f2f 100%) !important;
}

[data-theme="dark"] .warning-badge {
    background: linear-gradient(135deg, #ffc107 0%, #ffa000 100%) !important;
}

[data-theme="dark"] .success-badge {
    background: linear-gradient(135deg, #66bb6a 0%, #4caf50 100%) !important;
}

/* 關閉按鈕優化 */
[data-theme="dark"] .swal2-close {
    color: #999999 !important;
}

[data-theme="dark"] .swal2-close:hover {
    color: #ff5252 !important;
}

[data-theme="dark"] .material-chip:hover {
    background-color: #4a4a4a !important;
    border-color: #4dabf7 !important;
}

/* 參數比較卡片 */
[data-theme="dark"] .parameter-card {
    background-color: #333333 !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .parameter-card-header {
    background: linear-gradient(135deg, #3a4a5c 0%, #2c3e50 100%) !important;
    color: #ffffff !important;
}

[data-theme="dark"] .parameter-value {
    color: #4dabf7 !important;
}

[data-theme="dark"] .parameter-label {
    color: #a0a0a0 !important;
}

/* 統計數據 */
[data-theme="dark"] .stat-card {
    background-color: #333333 !important;
    border: 1px solid #404040 !important;
}

[data-theme="dark"] .stat-card-title {
    color: #ffffff !important;
}

[data-theme="dark"] .stat-card-value {
    color: #4dabf7 !important;
}

[data-theme="dark"] .stat-card-label {
    color: #a0a0a0 !important;
}

.material-not-synced .material-search-container {
    position: relative;
}

.material-not-synced td:first-child {
    position: relative;
}

.material-not-synced td:first-child::before {
    content: "⚠️";
    position: absolute;
    left: 5px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    cursor: help;
    z-index: 1;
}

/* 懸停時顯示提示 */
.material-not-synced .material-search:hover::after {
    content: "材料未同步 - 請選擇或創建材料";
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #856404;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    margin-bottom: 5px;
    z-index: 1000;
}

/* ====== 行動裝置優化 v2 — 保留原生表格方案 ====== */

/* --- Phase 1: 主表格欄位隱藏 + 寬度優化 --- */

/* ≤768px: 隱藏 莫爾數(6) 和 純度(9) */
@media (max-width: 768px) {
    #materialsTable th:nth-child(6),
    #materialsTable td:nth-child(6),
    #materialsTable th:nth-child(9),
    #materialsTable td:nth-child(9) {
        display: none;
    }

    /* 移除全域 min-width 限制 */
    #materialsTable {
        min-width: 0;
        width: 100%;
    }
    #materialsTable th,
    #materialsTable td {
        min-width: 0;
    }

    /* 欄位專屬最小寬度 */
    /* 原料名稱 — 搜尋框 */
    #materialsTable th:nth-child(1),
    #materialsTable td:nth-child(1) { min-width: 120px; }
    /* 類型 — 下拉選單 */
    #materialsTable th:nth-child(2),
    #materialsTable td:nth-child(2) { min-width: 80px; }
    /* 官能基數 / 分子量 / 莫爾比 */
    #materialsTable th:nth-child(3),
    #materialsTable td:nth-child(3),
    #materialsTable th:nth-child(4),
    #materialsTable td:nth-child(4),
    #materialsTable th:nth-child(5),
    #materialsTable td:nth-child(5) { min-width: 60px; }
    /* 重量(7) */
    #materialsTable th:nth-child(7),
    #materialsTable td:nth-child(7) { min-width: 55px; }
    /* 用量(10) */
    #materialsTable th:nth-child(10),
    #materialsTable td:nth-child(10) { min-width: 65px; }
    /* 操作(11) */
    #materialsTable th:nth-child(11),
    #materialsTable td:nth-child(11) { min-width: 36px; width: 36px; }

    /* 搜尋容器縮減 */
    .material-search-container { min-width: 0 !important; }
    .material-search-container input.material-search { min-width: 0 !important; }
    .material-search-container .material-select { min-width: 0 !important; max-width: none !important; }

    /* --- Phase 2: Sticky 首欄（原料名稱） --- */
    #materialsTable th:first-child,
    #materialsTable td:first-child {
        position: sticky;
        left: 0;
        z-index: 5;
        background: var(--bg-secondary);
    }
    #materialsTable th:first-child {
        z-index: 15;
        background: var(--color-primary);
    }
    /* 行類型背景色繼承 */
    #materialsTable tr.type-OH td:first-child { background: var(--color-oh-bg); }
    #materialsTable tr.type-NCO td:first-child { background: var(--color-nco-bg); }
    #materialsTable tr.type-additive td:first-child { background: var(--color-additive-bg); }
    #materialsTable tr.type-custom td:first-child { background: var(--color-custom-bg); }
    /* 右側陰影分隔線 */
    #materialsTable td:first-child::after {
        content: '';
        position: absolute;
        right: -6px;
        top: 0;
        bottom: 0;
        width: 6px;
        background: linear-gradient(to right, rgba(0,0,0,0.08), transparent);
        pointer-events: none;
    }

    /* --- Phase 3: 捲動提示 --- */
    .table-container::after {
        content: '\2190 \6ED1\52D5\67E5\770B\66F4\591A \2192';
        display: block;
        text-align: center;
        font-size: 0.7em;
        color: var(--text-secondary, #999);
        padding: 6px 0 2px;
        opacity: 0.7;
    }

    /* --- Phase 4: 其他固定寬度溢出修復 --- */
    /* 全域 th/td min-width */
    th, td { min-width: 0; }

    /* 配方管理雙欄 → 垂直堆疊 */
    .recipe-manager-panels {
        flex-direction: column !important;
        height: auto !important;
        min-height: 0 !important;
    }
    .recipe-panel-left, .recipe-panel-right {
        min-width: 0 !important;
        width: 100% !important;
        flex: none !important;
        max-height: 50vh;
        overflow-y: auto;
    }
    #recipeManagerTable {
        min-width: 0 !important;
        table-layout: auto !important;
    }
    #recipeManagerTable th, #recipeManagerTable td {
        padding: 8px 6px;
        width: auto !important;
    }

    /* 配方預覽 Dialog */
    .material-dialog .material-content {
        width: 96vw !important;
        max-width: 96vw !important;
    }
    .material-table[style*="min-width: 800px"] { min-width: 0 !important; }
    #recipe-preview-dialog td, .multi-recipe-table td,
    #selectedRecipeBatchTable td, #recipeManagerTable td {
        white-space: normal !important;
        word-break: break-word;
    }

    /* 比較表格滑動提示 */
    .comparison-table-container::before {
        content: '\2190 \5DE6\53F3\6ED1\52D5\67E5\770B \2192';
        display: block;
        text-align: center;
        font-size: 0.75em;
        color: var(--text-secondary, #999);
        padding: 4px;
    }
}

/* ≤480px: 額外隱藏 佔比(8) */
@media (max-width: 480px) {
    #materialsTable th:nth-child(8),
    #materialsTable td:nth-child(8) {
        display: none;
    }

    /* 進度指示器 */
    .progress-indicator {
        min-width: 0 !important;
        width: calc(100vw - 32px);
        max-width: 350px;
    }

    /* 配方搜尋欄 */
    .search-filter-container div[style*="min-width: 300px"] {
        min-width: 0 !important;
        width: 100% !important;
    }
    .search-filter-container div[style*="display: flex"] {
        flex-direction: column !important;
    }

    /* 配方預覽 info grid */
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Grid 佈局 */
    .results-grid { grid-template-columns: 1fr !important; gap: 12px; }
    .charts-container { grid-template-columns: 1fr !important; gap: 16px; }
    .chart-card { min-height: 280px; }
    .chart-container { min-height: 220px; }
    #batchStatistics div[style*="repeat(4"] { grid-template-columns: repeat(2, 1fr) !important; }
    #batchStatistics div[style*="repeat(3"] { grid-template-columns: repeat(2, 1fr) !important; }
}

/* --- Phase 5: 觸控 UX --- */
@media (pointer: coarse) {
    button, .btn-primary, .btn-success, .btn-warning, .btn-danger { min-height: 44px; }
    input[type="number"], input[type="text"], select { min-height: 44px; font-size: 16px; }
    tbody tr:hover { transform: none !important; box-shadow: none !important; }
    .operation-btn:hover { transform: none !important; }
}

/* ====== 行動裝置優化 v2 結束 ====== */

/* Loading overlay styles */
@keyframes kesth-spin { to { transform: rotate(360deg); } }
@media (prefers-color-scheme: dark) {
    #kesth-loading-overlay { background: #1a1a2e; }
    #kesth-loading-overlay div div:last-child { color: #aaa; }
}
[data-theme="dark"] #kesth-loading-overlay { background: #1a1a2e; }
[data-theme="dark"] #kesth-loading-overlay div div:last-child { color: #aaa; }

/* ====== 替換原料對話框 ====== */
.replace-material-body { padding: 0 10px; color: var(--text-primary); }

.replace-material-recipes {
    max-height: 120px; overflow-y: auto;
    padding: 10px; margin: 10px 0;
    background: var(--bg-tertiary);
    border-radius: 8px; font-size: 0.9em;
}
.replace-material-recipes ul { margin: 0; padding-left: 18px; }

.replace-material-divider {
    border-top: 1px solid var(--border-color);
    margin: 12px 0; padding-top: 12px;
}

.replace-material-radio label {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; cursor: pointer; font-weight: 600;
    color: var(--text-primary);
}

.replace-material-sub { padding-left: 32px; margin-top: 8px; }

.replace-material-sub select {
    width: 100%; padding: 8px; border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--input-bg); color: var(--input-text);
    margin-bottom: 8px;
}

.replace-option-label {
    display: flex; align-items: center; gap: 6px;
    margin-top: 8px; font-size: 0.9em; cursor: pointer;
}

.replace-material-preview {
    display: grid; grid-template-columns: auto 1fr 1fr;
    gap: 4px 12px; padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 8px; font-size: 0.85em;
}
.replace-material-preview .label { font-weight: 600; color: var(--text-secondary); }
.replace-material-preview .diff { color: var(--color-warning); font-weight: 600; }

.replace-material-warning {
    padding: 8px 12px; margin: 8px 0;
    background: var(--color-warning-bg);
    border-left: 4px solid var(--color-warning);
    border-radius: 4px; font-size: 0.85em;
    color: var(--color-warning-text);
}

.replace-material-actions {
    display: flex; justify-content: flex-end;
    gap: 10px; margin-top: 15px; padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.cancel-replace-btn {
    padding: 8px 18px; border-radius: 6px; cursor: pointer;
    background: var(--bg-tertiary); color: var(--text-secondary);
    border: 1px solid var(--border-color); font-weight: 500;
    transition: background 0.2s ease;
}
.cancel-replace-btn:hover { background: var(--bg-secondary); }
