* { box-sizing: border-box; }

/* 基礎版面防跑位設定 */
html, body { 
    font-family: 'PingFang TC', 'Microsoft JhengHei', sans-serif; 
    background-color: #f4f7f6; margin: 0; padding: 20px; color: #333; 
    display: flex; flex-direction: column; min-height: 100vh;
    -webkit-text-size-adjust: 100%; 
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.header { text-align: center; margin-bottom: 20px; color: #2c3e50; }
.header h1 { margin-bottom: 10px; }
.header p { margin-top: 0; color: #666; }

/* 雙模式切換開關 */
.mode-switch-container { display: flex; justify-content: center; margin-bottom: 25px; }
.mode-btn { background: #e0e0e0; border: none; padding: 12px 25px; font-size: 16px; font-weight: bold; color: #555; cursor: pointer; transition: 0.3s; }
.mode-btn:first-child { border-radius: 30px 0 0 30px; }
.mode-btn:last-child { border-radius: 0 30px 30px 0; }
.mode-btn.active-clinical { background: #0288d1; color: white; box-shadow: inset 0 2px 5px rgba(0,0,0,0.2); }
.mode-btn.active-learning { background: #8e44ad; color: white; box-shadow: inset 0 2px 5px rgba(0,0,0,0.2); }

.main-content { flex: 1; }
.container { display: flex; gap: 20px; max-width: 1200px; margin: 0 auto; align-items: flex-start; }
.column { background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.left-col { flex: 1.2; }
.right-col { flex: 0.8; background-color: #fafbfc; position: sticky; top: 20px; }

input, select, button { padding: 10px; margin: 5px 0; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; }

/* 搜尋列 */
.search-bar-wrapper { position: relative; margin-bottom: 20px; }
.search-bar-wrapper input { width: 100%; padding: 14px 15px 14px 45px; font-size: 16px; border: 2px solid #0288d1; border-radius: 8px; box-shadow: 0 4px 6px rgba(2, 136, 209, 0.1); transition: 0.3s;}
.search-bar-wrapper input:focus { outline: none; box-shadow: 0 4px 12px rgba(2, 136, 209, 0.3); }
.search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 20px; color: #0288d1; pointer-events: none;}

/* 篩選表單 */
.brand-filters-container { background: #f8f9fa; border: 1px solid #e9ecef; border-radius: 8px; padding: 10px 15px; margin-bottom: 15px; }
.brand-filters-container summary { font-size: 15px; font-weight: bold; cursor: pointer; outline: none; color: #2c3e50; display: flex; align-items: center; user-select: none; }
.brand-filters-container summary:hover { color: #0288d1; }
.filters-actions { margin: 10px 0; }
.brand-filters { display: flex; flex-wrap: wrap; gap: 10px; max-height: 150px; overflow-y: auto; font-size: 14px; padding-top: 5px;}
.brand-filters label { display: flex; align-items: center; cursor: pointer; background: #fff; padding: 6px 10px; border-radius: 20px; border: 1px solid #ddd; transition: 0.2s;}
.brand-filters label:hover { background: #eef2f5; }
.brand-count { color: #888; font-size: 12px; margin-left: 4px; }

.category-wiki { margin-top: 10px; background: #e3f2fd; border: 1px solid #bbdefb; border-radius: 6px; font-size: 13px; }
.category-wiki summary { padding: 10px; font-weight: bold; color: #0277bd; cursor: pointer; user-select: none; outline: none; }
.category-wiki summary:hover { background: #bbdefb; border-radius: 6px; }
.wiki-content { padding: 0 15px 15px 15px; color: #444; line-height: 1.6; }
.wiki-content h4 { color: #01579b; margin: 10px 0 5px 0; border-bottom: 1px dashed #bbdefb; padding-bottom: 4px;}
.wiki-content p { margin: 4px 0; }

.btn-small { padding: 4px 12px; font-size: 14px; cursor: pointer; background: #6c757d; color: white; border: none; border-radius: 4px; }
.btn-small:hover { background: #5a6268; }

/* AI 分析區塊 */
.opt-section { background: #fff; border: 2px dashed #0288d1; padding: 15px; border-radius: 8px; margin-top: 20px; }
.opt-title { font-weight: bold; color: #0277bd; display: flex; align-items: center; gap: 5px; font-size: 16px; cursor: pointer; user-select: none; outline: none;}

.plan-card { background: #f8fbff; border: 1px solid #b3e5fc; border-radius: 6px; padding: 12px; margin-bottom: 15px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); }
.plan-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #e1f5fe; padding-bottom: 8px; margin-bottom: 8px; }
.plan-title { font-weight: bold; color: #0277bd; font-size: 15px; }
.plan-item { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; border-bottom: 1px dashed #eee; align-items: center;}

.struct-card { background: #fff8e1; border: 1px solid #ffecb3; border-radius: 6px; padding: 12px; margin-bottom: 10px; }
.struct-header { font-weight: bold; color: #f57f17; font-size: 14px; margin-bottom: 8px; border-bottom: 1px dashed #ffe082; padding-bottom: 4px;}
.struct-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center;}

/* 各式標籤設計 */
.tag-formula { background: #ffcc80; color: #e65100; padding: 4px 8px; border-radius: 12px; font-size: 13px; font-weight: bold; border: 1px solid #ffa726; cursor: help;}
.tag-single { background: #fff3e0; color: #ef6c00; padding: 4px 8px; border-radius: 12px; font-size: 13px; border: 1px solid #ffe0b2; cursor: help;}
.tag-minus { background: #ffebee; color: #c62828; padding: 4px 8px; border-radius: 12px; font-size: 13px; font-weight: bold; border: 1px solid #ffcdd2; cursor: default; }
.tag-animal { background: #ffe0b2; color: #d84315; padding: 2px 6px; border-radius: 6px; font-size: 11px; margin-left: 6px; border: 1px solid #ffb74d; }
.tag-radar-match { background: #e8f5e9; color: #2e7d32; padding: 4px 8px; border-radius: 6px; font-size: 12px; border: 1px solid #c8e6c9;}

/* 🌟 特殊防呆標籤 */
.tag-g6pd { background: #e1bee7; color: #4a148c; padding: 2px 6px; border-radius: 6px; font-size: 11px; margin-left: 6px; border: 1px solid #ce93d8; }
.tag-doping { background: #cfd8dc; color: #212121; padding: 2px 6px; border-radius: 6px; font-size: 11px; margin-left: 6px; border: 1px solid #b0bec5; font-weight: bold;}

/* 清單與卡片設計 */
.drug-list, .prescription-list, .result-list { list-style: none; padding: 0; margin: 0; }
.drug-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-bottom: 1px solid #eee; position: relative; }
.drug-item:hover { background-color: #f9f9f9; }

.has-hover { position: relative; cursor: help; }
.hover-card {
    display: none; position: absolute; left: 0; top: 100%; width: max-content; max-width: 300px; z-index: 999;
    background: #fff; border: 1px solid #2c3e50; border-radius: 6px; padding: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25); font-size: 13px; line-height: 1.6; color: #333; text-align: left;
}
@media (hover: hover) { .has-hover:hover .hover-card { display: block; } }
.hover-card-title { font-weight: bold; color: #2c3e50; border-bottom: 1px solid #eee; padding-bottom: 4px; margin-bottom: 6px; }
.hover-card p { margin: 3px 0; }

.add-btn { background-color: #4CAF50; color: white; border: none; cursor: pointer; padding: 8px 15px; border-radius:4px; font-weight: bold; white-space: nowrap;}
.add-btn:hover { background-color: #45a049; }
.remove-btn { background-color: #f44336; color: white; border: none; cursor: pointer; padding: 8px 12px; border-radius:4px; font-weight: bold;}
.apply-btn { background-color: #0288d1; color: white; border: none; cursor: pointer; padding: 6px 12px; border-radius:4px; font-size: 13px; font-weight: bold;}

.presc-item { background: #e8f4f8; padding: 12px; margin-bottom: 10px; border-radius: 4px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;}
.presc-item-info { flex: 1; min-width: 150px;}
.presc-item-controls { display: flex; align-items: center; gap: 8px; }
.presc-item input { width: 80px; text-align: center; font-size: 16px; font-weight: bold; color: #2c3e50;}
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

.result-item { padding: 12px 0; border-bottom: 1px dashed #ccc; display: flex; justify-content: space-between; font-weight: bold; align-items: flex-start;}
.result-item-left { flex: 1; }
.result-item-right { white-space: nowrap; padding-left: 10px;}
.source-abbr { display: inline-block; font-size: 11px; color: #888; background: #eee; padding: 2px 6px; border-radius: 4px; margin-top: 4px; margin-right: 4px; font-weight: normal;}

/* 警告文字與區塊 */
.toxic-alert, .incompat-alert { font-weight: bold;}
.toxic-alert { color: #d32f2f; font-size: 12px; display: block; margin-top: 3px; font-weight: normal;} 
.niuxi-alert { color: #e67e22; font-size: 12px; display: block; margin-top: 3px; font-weight: normal;}

.incompat-alert-box { 
    background-color: #ffebee; color: #c62828; border: 2px solid #ef5350; 
    padding: 12px; border-radius: 6px; margin-top: 15px; font-weight: bold; 
    font-size: 14px; display: none; line-height: 1.5;
}

.total-weight { font-size: 18px; color: #d32f2f; margin-top: 15px; text-align: right; font-weight: bold;}

#statusMessage { background: #fff3cd; color: #856404; padding: 12px; text-align: center; border-radius: 4px; margin-bottom: 15px; font-weight: bold; }
.warning-bg { background-color: #ffebee !important; }
.warning-text { color: #d32f2f !important; }

/* 頁籤設計 */
.tab-container { display: flex; margin-bottom: 15px; border-bottom: 2px solid #ddd; }
.tab-btn { flex: 1; padding: 10px; text-align: center; cursor: pointer; font-weight: bold; color: #666; background: #f8f9fa; border: none; outline: none;}
.tab-btn.active { color: #0277bd; border-bottom: 3px solid #0277bd; background: #fff; }

/* 方劑雷達區塊 */
.radar-card { background: #fdfefe; border: 1px solid #d5dbdb; border-radius: 8px; padding: 15px; margin-bottom: 15px; border-left: 4px solid #8e44ad; }
.radar-title { font-size: 16px; font-weight: bold; color: #8e44ad; margin-bottom: 10px; display: flex; justify-content: space-between;}
.radar-score { font-size: 13px; color: #fff; background: #8e44ad; padding: 2px 8px; border-radius: 12px;}

/* 🌟 開發者統計網格設計 */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 20px;}
.stat-item { background: #fdfefe; border: 1px solid #e0e0e0; padding: 12px; border-radius: 6px; display: flex; justify-content: space-between; font-size: 15px; font-weight: bold; color: #2c3e50;}
.stat-count { color: #e67e22; font-size: 13px; font-weight: normal; background: #fff3e0; padding: 2px 6px; border-radius: 4px;}

/* 🌟 專業學術頁尾設計 */
.platform-footer { margin-top: 40px; padding: 40px 20px 20px; background-color: #2c3e50; color: #ecf0f1; font-size: 14px; border-top: 4px solid #0288d1; }
.footer-grid { display: flex; justify-content: space-between; flex-wrap: wrap; max-width: 1000px; margin: 0 auto; gap: 30px; text-align: left; }
.footer-col { flex: 1; min-width: 280px; }
.footer-col h4 { color: #81d4fa; margin-top: 0; margin-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 8px; font-size: 16px; }
.footer-col p { margin: 8px 0; line-height: 1.6; color: #bdc3c7;}
.footer-col ul { list-style: none; padding: 0; margin: 0; }
.footer-col ul li { margin-bottom: 10px; }
.footer-col a { color: #bdc3c7; text-decoration: none; transition: 0.3s; display: block;}
.footer-col a:hover { color: #fff; text-decoration: underline; }
.footer-links-vertical { display: flex; flex-direction: column; gap: 10px; }
.footer-links-vertical a { display: block; background: rgba(255,255,255,0.05); padding: 8px 12px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.1); width: 100%; text-align: center; color: #fff; font-weight: bold;}
.footer-links-vertical a:hover { background: rgba(255,255,255,0.15); text-decoration: none;}

.feedback-box { margin: 40px auto 0 auto; max-width: 1000px; padding: 20px; background: rgba(0,0,0,0.25); border-radius: 8px; border: 1px dashed rgba(255,255,255,0.2); text-align: center; }

/* RWD 手機版優化 */
@media (max-width: 768px) {
    body { padding: 8px 5px; } 
    .header h1 { font-size: 20px; line-height: 1.3; margin-bottom: 5px;} 
    .header p { font-size: 12px; margin-top: 0; }
    .container { flex-direction: column; gap: 10px; width: 100%; max-width: 100%; }
    .column { width: 100%; padding: 12px 10px; border-radius: 4px; }
    .right-col { position: relative; top: 0; } 
    .mode-switch-container { width: 100%; margin-bottom: 15px; }
    .mode-btn { flex: 1; padding: 10px 5px; font-size: 14px; white-space: nowrap;}
    
    .result-item { padding: 10px 0; align-items: center; }
    .result-item-left { word-break: keep-all; font-size: 15px; }
    .result-item-right { white-space: nowrap; padding-left: 8px; font-size: 16px; font-weight: 900; }
    .source-abbr { font-size: 10px; padding: 2px 4px; margin-right: 2px; }
    
    .footer-grid { flex-direction: column; gap: 20px; }
    .footer-col { text-align: center; }
}
