/**
 * SakiMed 統一主題樣式
 * 建立時間: 2025-12-04
 * 重構時間: 2026-01-03 (V3 Full Refactor)
 * 
 * 變更記錄:
 * - V3: 引入 colors.css，修正捲動問題，強化響應式設計
 * - V2: Emergency Fix (2026-01-01)
 * - V1: Initial Release
 */

/* 引入色系變數 */
@import url('colors.css');

/* ==================== 回退色系 (若 colors.css 載入失敗) ==================== */
:root {
  /* 主要配色 - 使用 colors.css 定義，此處為備援 */
  --primary: var(--saki-purple, #c6a4cf);
  --primary-dark: var(--saki-purple-dark, #9b7aa3);
  --primary-light: var(--saki-purple-light, #e8d5ec);
  --secondary: var(--saki-cyan, #89c3eb);
  --secondary-dark: var(--saki-cyan-dark, #6ba3cb);
  --secondary-light: var(--saki-cyan-light, #b8ddf5);

  /* 漸層背景 */
  --gradient-primary: var(--saki-gradient, linear-gradient(135deg, #c6a4cf 0%, #89c3eb 100%));
  --gradient-card: var(--saki-gradient-soft, linear-gradient(135deg, #c6a4cf20, #89c3eb20));

  /* 文字顏色 */
  --text-primary: var(--saki-text-primary, #2c3e50);
  --text-secondary: var(--saki-text-secondary, #5a6c7d);
  --text-muted: var(--saki-text-muted, #95a5a6);
  --text-light: #fff;

  /* 背景顏色 */
  --bg-body: var(--saki-bg-body, #f5f7fa);
  --bg-card: var(--saki-bg-card, #fff);
  --bg-hover: var(--saki-bg-hover, #f8f9fa);
  --bg-active: var(--saki-bg-active, #e8f0fe);

  /* 狀態顏色 */
  --success: var(--saki-success, #28a745);
  --warning: var(--saki-warning, #ffc107);
  --danger: var(--saki-danger, #dc3545);
  --info: var(--secondary);

  /* 邊框 */
  --border-color: var(--saki-border, #e0e6ed);
  --border-radius: var(--saki-radius-md, 8px);
  --border-radius-lg: var(--saki-radius-lg, 12px);

  /* 陰影 */
  --shadow-sm: var(--saki-shadow-sm, 0 1px 3px rgba(0,0,0,0.08));
  --shadow-md: var(--saki-shadow-md, 0 4px 12px rgba(0,0,0,0.1));
  --shadow-lg: var(--saki-shadow-lg, 0 10px 30px rgba(0,0,0,0.12));

  /* 字體 */
  --font-family: 'Microsoft JhengHei', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Consolas', 'Monaco', monospace;
  
  /* Layout Dimensions */
  --sidebar-width: var(--saki-sidebar-width, 260px);
  --header-height: var(--saki-header-height, 0px);
}

/* ==================== 基礎重置 ==================== */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden; /* 防止外層捲動 */
}

body {
  font-family: var(--font-family);
  background: var(--bg-body);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  min-height: 100vh;
}

/* ==================== 核心佈局 - V4 強化版 ==================== */

/* [2026-01-09] 移除 !important，使用選擇器優先級 */
html body .layout {
  display: flex;
  flex-direction: row; /* 明確橫向排列 */
  flex: 1 1 auto;
  overflow: hidden;
  position: relative;
  height: 100vh;
  width: 100%;
  min-height: 0;
}

/* 側邊欄 */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  max-width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  flex-shrink: 0;
  transition: transform 0.3s ease, width 0.3s ease;
  height: 100%;
}

/* 側邊欄品牌區塊 */
.sidebar-brand {
  padding: 1.5rem;
  background: var(--gradient-primary);
  color: white;
  flex-shrink: 0;
}

.sidebar-brand h3 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.sidebar-brand .version {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-top: 4px;
}

/* 主內容區 - V4 強化版 */
.main {
  flex: 1 1 0%;
  background: var(--bg-body);
  overflow-y: auto; /* 內容區獨立捲動 */
  overflow-x: hidden;
  position: relative;
  z-index: 500;
  min-width: 0;
  height: 100%;
  width: calc(100% - var(--sidebar-width)); /* 明確寬度 */
  padding: 0; /* 由 .page 控制內距 */
}

/* ==================== 頁面容器 - V4 強化版 ==================== */

.page {
  display: none !important; /* 確保非 active 頁面絕對隱藏 */
  width: 100%;
  min-height: 0; /* 移除最小高度限制 */
  height: auto; /* 自動高度 */
  padding: var(--saki-page-padding, 2rem);
  padding-bottom: 3rem; /* 底部額外間距 */
  animation: pageSlideIn 0.3s ease;
  box-sizing: border-box;
}

.page.active {
  display: block !important; /* active 頁面顯示 */
}

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

/* 頁面標頭 - 統一風格 */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid transparent;
  border-image: var(--gradient-primary) 1;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 60%; /* 限制最大寬度避免過寬 */
}

.page-header h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* 返回按鈕 */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--saki-purple-pale, #f4eef6);
  color: var(--primary-dark);
  border: 1px solid var(--saki-purple-light, #e8d5ec);
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-back:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  transform: translateX(-2px);
}

/* ==================== 導航選單 ==================== */

.nav-group {
  margin-bottom: 0.5rem;
  padding: 0.5rem 0;
}

.nav-header {
  padding: 0.75rem 1.5rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.5rem;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  font-size: 0.95rem;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--primary-dark);
  border-left-color: var(--primary-light);
}

.nav-item.active {
  background: var(--saki-gradient-pale, linear-gradient(135deg, #f4eef6, #e8f4fc));
  color: var(--primary-dark);
  border-left-color: var(--primary);
  font-weight: 500;
}

.nav-icon {
  margin-right: 12px;
  width: 20px;
  text-align: center;
  font-size: 1rem;
}

/* ==================== 卡片元件 ==================== */

.card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  background: var(--saki-gradient-pale, linear-gradient(135deg, #f9f5fa, #f0f7fc));
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.card-body {
  padding: 1.25rem;
}

.card-body.p-0 {
  padding: 0;
}

/* 狀態卡片 */
.status-card {
  border-left: 4px solid var(--primary);
}

.status-card.success { border-left-color: var(--success); }
.status-card.warning { border-left-color: var(--warning); }
.status-card.danger { border-left-color: var(--danger); }

/* ==================== 統計卡片網格 ==================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  padding: 1.25rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  border-top: 4px solid;
  border-image: var(--gradient-primary) 1;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card h4 {
  margin: 0 0 8px 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ==================== 表格 ==================== */

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

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

.table th {
  background: var(--saki-gradient-pale, #f8f9fa);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.table tr:hover {
  background: var(--bg-hover);
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 深色表格 (用於特定模組) */
.table-dark {
  background: #1e1e2e;
  color: #e4e4e7;
}

.table-dark th {
  background: #2a2a3e;
  color: #a1a1aa;
}

.table-dark td {
  border-bottom-color: #3a3a4e;
}

.table-dark tr:hover {
  background: #2a2a3e;
}

/* ==================== 按鈕 - V4 統一設計 ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--saki-radius-sm, 4px);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap; /* 防止按鈕文字換行 */
  flex-shrink: 0; /* 防止壓縮 */
  min-height: 36px;
  box-sizing: border-box;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
}

.btn-primary:hover {
  box-shadow: var(--saki-shadow-primary, 0 4px 15px rgba(198, 164, 207, 0.4));
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover {
  background: var(--secondary-dark);
  box-shadow: var(--saki-shadow-secondary, 0 4px 15px rgba(137, 195, 235, 0.4));
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

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

.btn-outline-secondary {
  background: transparent;
  border: 1px solid var(--secondary);
  color: var(--secondary-dark);
}

.btn-outline-secondary:hover {
  background: var(--secondary);
  color: white;
}

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #218838; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c82333; }

.btn-warning { background: var(--warning); color: #212529; }

.btn-info { background: var(--info); color: white; }

.btn-sm { 
  padding: 5px 10px; 
  font-size: 0.85rem; 
}

.btn-block { 
  width: 100%; 
}

/* Tab 按鈕 */
.tab-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 16px;
}

.tab-btn.active {
  background: var(--gradient-primary);
  border-color: var(--primary);
  color: white;
}

.tab-btn:hover:not(.active) {
  background: var(--bg-hover);
  border-color: var(--primary-light);
}

/* ==================== Badge ==================== */

.badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.badge-success { background: var(--saki-success-light, #e6f4ea); color: #1e7e34; }
.badge-warning { background: var(--saki-warning-light, #fff8e1); color: #856404; }
.badge-danger { background: var(--saki-danger-light, #ffeef0); color: #d93025; }
.badge-info { background: var(--saki-info-light, #e8f4fc); color: #1967d2; }
.badge-secondary { background: #e9ecef; color: #6c757d; }

/* ==================== 表單控制項 ==================== */

.form-group { 
  margin-bottom: 1rem; 
}

.form-group label { 
  display: block; 
  margin-bottom: 0.5rem; 
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--saki-radius-sm, 4px);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--bg-card);
}

.form-control:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(198, 164, 207, 0.2);
}

.form-control-sm {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-check-input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ==================== Modal ==================== */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--border-radius-lg);
  width: 600px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease;
}

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

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--saki-gradient-pale);
  border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #fafafa;
  border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

.modal-close {
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--text-muted);
  line-height: 1;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--danger);
}

/* ==================== Toast 通知 ==================== */

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #333;
  color: #fff;
  padding: 14px 24px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.toast.show { 
  opacity: 1; 
  transform: translateX(0);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); color: #212529; }

/* ==================== Loading Overlay ==================== */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 1rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ==================== 狀態指示燈 ==================== */

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #6c757d;
  flex-shrink: 0;
}

.status-dot.online { 
  background: var(--success); 
  box-shadow: 0 0 8px var(--success);
  animation: pulse-status 2s infinite;
}

.status-dot.offline { 
  background: var(--danger); 
}

@keyframes pulse-status {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* 大型狀態指示燈 */
.status-indicator-large {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #6c757d;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-indicator-large.online { 
  background: var(--gradient-primary);
  box-shadow: 0 0 20px rgba(137, 195, 235, 0.5);
}

.status-indicator-large.offline { 
  background: linear-gradient(135deg, var(--danger), #e74c3c);
}

/* ==================== 診斷頁面專用 ==================== */

.diag-light {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin: 0 auto;
  background: #444;
  transition: all 0.3s;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.diag-light.pending { background: #555; }
.diag-light.success { background: #00e676; box-shadow: 0 0 20px #00e676; }
.diag-light.warning { background: #ffea00; box-shadow: 0 0 20px #ffea00; }
.diag-light.error { 
  background: #ff1744; 
  box-shadow: 0 0 20px #ff1744; 
  animation: pulse-error 1s infinite; 
}

@keyframes pulse-error {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.term-line { 
  margin-bottom: 2px; 
  border-bottom: 1px solid #333; 
  padding-bottom: 2px; 
}

.term-line.info { color: #81d4fa; }
.term-line.success { color: #b9f6ca; }
.term-line.warning { color: #ffff8d; }
.term-line.error { color: #ff8a80; }

/* ==================== 佈局工具類別 ==================== */

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
}

.col-12 { flex: 0 0 100%; max-width: 100%; }
.col-lg-6 { flex: 0 0 calc(50% - 0.75rem); max-width: calc(50% - 0.75rem); }
.col-lg-8 { flex: 0 0 calc(66.666% - 0.75rem); max-width: calc(66.666% - 0.75rem); }
.col-lg-4 { flex: 0 0 calc(33.333% - 0.75rem); max-width: calc(33.333% - 0.75rem); }
.col-md-6 { flex: 0 0 calc(50% - 0.75rem); max-width: calc(50% - 0.75rem); }
.col-3 { flex: 0 0 calc(25% - 1.125rem); max-width: calc(25% - 1.125rem); }

/* Flexbox 工具 */
.d-flex { display: flex; }
.flex-column { flex-direction: column; }
.justify-content-between { justify-content: space-between; }
.justify-content-end { justify-content: flex-end; }
.align-items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* 間距工具 */
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 0.75rem; }
.mb-3 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.75rem; }
.mt-3 { margin-top: 1rem; }
.ml-2 { margin-left: 0.5rem; }
.ml-auto { margin-left: auto; }
.p-0 { padding: 0 !important; }
.p-4 { padding: 1.5rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }

/* 文字工具 */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.h-100 { height: 100%; }
.w-100 { width: 100%; }

/* ==================== 響應式設計 ==================== */

/* Tablet */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 220px;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .col-lg-6,
  .col-lg-8,
  .col-lg-4 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  
  .col-3 {
    flex: 0 0 calc(50% - 0.75rem);
    max-width: calc(50% - 0.75rem);
  }
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main {
    width: 100%;
  }
  
  .page {
    padding: var(--saki-page-padding-mobile, 1rem);
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  .page-header-right {
    max-width: 100%;
    width: 100%;
    justify-content: flex-start;
  }
  
  .page-header h2 {
    font-size: 1.2rem;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .col-md-6,
  .col-3 {
    flex: 0 0 100%;
    max-width: 100%;
  }
  
  .modal-content {
    width: 95vw;
    max-height: 90vh;
  }
  
  .btn-group,
  .tabs {
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }
  
  .btn-group .btn,
  .tabs .btn {
    width: 100%;
  }
  
  /* 頁面標頭按鈕換行後全寬 */
  .page-header-right .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }
}

/* ==================== 按鈕群組與工具列 ==================== */

.btn-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
}

.btn-group .btn {
  border-radius: 0;
}

.btn-group .btn:first-child {
  border-radius: var(--saki-radius-sm, 4px) 0 0 var(--saki-radius-sm, 4px);
}

.btn-group .btn:last-child {
  border-radius: 0 var(--saki-radius-sm, 4px) var(--saki-radius-sm, 4px) 0;
}

.btn-group .btn:only-child {
  border-radius: var(--saki-radius-sm, 4px);
}

/* 工具列 */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-hover);
  border-radius: var(--border-radius);
  margin-bottom: 1rem;
}

.toolbar-left {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

/* Tab 群組優化 */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 1.5rem;
}

.tabs .tab-btn {
  flex: 0 0 auto;
}

/* 手機選單切換按鈕 */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gradient-primary);
  color: white;
  border: none;
  box-shadow: var(--shadow-md);
  z-index: 1050;
  cursor: pointer;
  font-size: 1.5rem;
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* 側邊欄遮罩 */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1050;
}

.sidebar-overlay.show {
  display: block;
}

/* ==================== 列印樣式 ==================== */

@media print {
  .sidebar,
  .mobile-menu-toggle,
  .toast-container {
    display: none !important;
  }
  
  .main {
    width: 100%;
    padding: 0;
  }
  
  .page {
    padding: 0;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ==========================================
   [2026-01-12] 全域按鍵可讀性修復
   修復任務 8, 10, 17, 21: 白底白字問題
   ========================================== */

/* Tab 按鈕樣式 */
.tabs .btn.btn-outline,
.tabs .tab-btn,
button.tab-btn {
  background: rgba(137, 195, 235, 0.15);
  color: var(--text-primary, #e0e0e0);
  border: 1px solid rgba(137, 195, 235, 0.4);
  transition: all 0.2s ease;
}

.tabs .btn.btn-outline:hover,
.tabs .tab-btn:hover,
button.tab-btn:hover {
  background: rgba(137, 195, 235, 0.3);
  color: #fff;
  border-color: var(--secondary, #89c3eb);
}

.tabs .btn.btn-outline.active,
.tabs .tab-btn.active,
button.tab-btn.active {
  background: var(--secondary, #89c3eb);
  color: #000;
  border-color: var(--secondary, #89c3eb);
}

/* 系統設定頁面按鈕 */
#sys-tab-config .btn,
#sys-tab-network .btn,
#sys-tab-backup .btn,
#sys-tab-sms .btn,
#sys-tab-cloud-sam .btn,
#sys-tab-migration .btn,
#sys-tab-his .btn,
#sys-tab-client .btn,
.sys-panel .btn {
  color: var(--text-primary, #e0e0e0);
}

.sys-panel .btn-primary {
  background: var(--primary, #c6a4cf);
  color: #000;
  border-color: var(--primary, #c6a4cf);
}

.sys-panel .btn-secondary {
  background: rgba(108, 117, 125, 0.8);
  color: #fff;
}

.sys-panel .btn-outline-primary,
.sys-panel .btn-outline-secondary,
.sys-panel .btn-outline-info {
  background: transparent;
  color: var(--text-primary, #e0e0e0);
}

.sys-panel .btn-outline-primary:hover {
  background: var(--primary, #c6a4cf);
  color: #000;
}

/* Card header 內按鈕 */
.card-header .btn {
  color: inherit;
}

/* 確保所有 form-control 在深色模式可讀 */
.sys-panel .form-control,
.sys-panel select,
.sys-panel input[type="text"],
.sys-panel input[type="password"],
.sys-panel input[type="number"] {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary, #e0e0e0);
  border: 1px solid rgba(137, 195, 235, 0.3);
}

.sys-panel .form-control:focus {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--secondary, #89c3eb);
  color: #fff;
}

/* ==========================================
   [2026-01-12] 防頁面閃現 (Anti-FOUC)
   修復任務 22, 28: 頁面載入閃現
   ========================================== */

/* 頁面容器初始隱藏 */
.page:empty,
.page[data-loading="true"] {
  opacity: 0;
  transition: opacity 0.15s ease-in;
}

/* 內容載入後顯示 */
.page:not(:empty):not([data-loading="true"]) {
  opacity: 1;
}

/* PageLoader 載入動畫 */
.page-loading-indicator {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background, #1a1a2e);
  z-index: 10;
}

.page-loading-indicator::after {
  content: '';
  width: 32px;
  height: 32px;
  border: 3px solid rgba(137, 195, 235, 0.3);
  border-top-color: var(--secondary, #89c3eb);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

