/* 通用重置或自定義 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body, html {
  width: 100%;
  height: 100%;
  font-family: Arial, sans-serif;
  overflow: hidden; /* 禁用滾動條 */
  touch-action: manipulation; /* 允許基本觸控操作，但禁用雙指縮放等手勢 */
  position: fixed; /* 防止整頁滾動 */
  top: 0;
  left: 0;
}

/* 左側面板頭部樣式 */
.device-list-header {
  padding: 5px;
  flex-shrink: 0; /* 確保標題區不會縮小 */
}

.device-list-dropdown {
  width: 100%;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: white;
  color: #333;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
}

.device-list-dropdown:hover {
  box-shadow: 0 2px 8px rgba(121, 180, 80, 0.2);
}

.device-list-dropdown:focus {
  box-shadow: 0 0 0 3px rgba(121, 180, 80, 0.1);
}

/* 左側裝置資訊面板樣式 */
.left-content {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-width: 176px; /* 200px - 24px padding */
  overflow-x: hidden;
  touch-action: pan-y; /* 允許垂直滾動 */
  flex: 1; /* 讓內容區域佔滿剩餘空間並可捲動 */
}

/* 空狀態樣式 */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
}
.device-info {
  padding: 10px;
  border: 2px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  cursor: move; /* 修改游標樣式 */
  user-select: none;
  touch-action: none; /* 允許自定義觸控拖拉 */
}

.device-info:active {
  cursor: grabbing;
}

.device-info.dragging {
  opacity: 0.6;
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  cursor: grabbing;
}

.tab-content .device-info {
  position: absolute;
  min-width: 200px;
  cursor: move;
  border: 2px solid #ccc; /* 確保邊框樣式一致 */
}

/* TitlePanel */
.title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  background-color: #79b450;
  color: #fff;
  padding: 0 16px;
}
.title-bar .logo {
  font-size: 18px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 幫助按鈕樣式 */
.help-button {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.help-button:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.6);
  transform: scale(1.1);
}

.help-button svg {
  display: block;
}
.title-bar .user-icon {
  background: none;
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info span {
  font-size: 14px;
  font-weight: 500;
}

.logout-button {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s;
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-1px);
}

/* 容器：包含左右分割區域 + 分隔條 */
.container {
  display: flex;
  width: 100%;
  height: calc(100% - 50px); /* 扣掉 TitlePanel 高度 */
  position: relative;
  overflow: hidden; /* 禁用滾動條 */
}

/* 左邊區域 */
.left-panel {
  width: 200px;
  background-color: #f4f4f4;
  display: flex;
  flex-direction: column;
  min-width: 0; /* 新增這行允許縮小到0 */
  transition: width 0.3s ease; /* 可選的過渡效果 */
  isolation: isolate; /* 建立獨立的堆疊上下文，防止受縮放影響 */
  z-index: 10; /* 確保左側面板在上層 */
  overflow: hidden; /* 防止內容溢出 */
}

/* 折疊狀態樣式 */
.left-panel.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  overflow: hidden !important;
}

/* 分隔條 */
.divider {
  width: 5px;
  cursor: col-resize;
  background-color: #ccc;
  z-index: 1;
  position: relative;
}

/* 右邊區域 */
.right-panel {
  flex: 1; /* 自動填滿剩餘空間 */
  background-color: #d4eacf;
  display: flex;
  flex-direction: column;
  contain: layout style; /* 防止內部樣式影響外部 */
  isolation: isolate; /* 建立新的堆疊上下文 */
  overflow: hidden; /* 禁用滾動條 */
}

/* ---- Tab Panel 區 ---- */
.tabs-wrapper {
  display: flex;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
  position: relative;
}
.tabs-scroll-btn {
  background: #ddd;
  border: none;
  cursor: pointer;
  padding: 0 6px;
  height: 32px;
  font-size: 12px;
  color: #555;
  flex-shrink: 0;
  border-radius: 4px 4px 0 0;
  z-index: 1;
}
.tabs-scroll-btn:hover {
  background: #ccc;
  color: #333;
}
.tabs {
  display: flex;
  background: #eee;
  padding: 8px 4px 0 4px;
  border-bottom: none;
  align-items: flex-end;
  height: 40px;
  overflow-x: hidden;
  overflow-y: hidden;
  flex: 1;
  min-width: 0;
  scroll-behavior: smooth;
}
.tabs .tab-button {
  background: #79b450;
  border: none;
  border-bottom: none;
  padding: 8px 20px;
  margin-right: 5px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  user-select: none;
  color: white;
  border-radius: 8px 8px 0 0;
  transition: all 0.3s ease;
  position: relative;
  min-width: 100px;
  flex-shrink: 0;
  white-space: nowrap;
  text-align: center;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation; /* 允許觸控點擊 */
}
.tabs .tab-button:hover:not(.active) {
  background: #6da241;
  color: white;
}
.tabs .tab-button.active {
  background: white;
  color: black;
  border: 2px solid #79b450;
  font-weight: bold;
  box-shadow: none;
  position: relative;
  z-index: 2;
  height: 36px;
  margin-bottom: -1px;
  padding: 6px 18px;
}
/* Tab 拖拉樣式 */
.tabs .tab-button[draggable="true"] {
  cursor: move;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.tabs .tab-button.dragging {
  opacity: 0.3 !important;
}
.tabs .tab-placeholder {
  display: inline-block;
  background: linear-gradient(90deg, #79b450 0%, #6da241 100%);
  border-radius: 8px 8px 0 0;
  opacity: 0.3;
  transition: all 0.2s ease;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 0.3;
  }
}
/* 為 Tab 容器添加過渡效果 */
.tabs {
  transition: all 0.2s ease;
}
/* 拖拉時的 Tab hover 效果 */
.tabs .tab-button:not(.dragging) {
  transition: margin 0.2s ease, transform 0.2s ease;
}
/* 放大(全螢幕) 按鈕 */
.fullscreen-button {
  margin-left: auto; /* 推到最右 */
  color: #fff;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 14px;
}

/* Tab 內容容器外層 */
#tabContentContainer {
  position: relative;
  width: 100%;
  height: calc(100vh - 92px); /* 設定固定高度，減去頂部和工具列的高度 */
  overflow: hidden; /* 禁用滾動條 */
  contain: layout; /* 使用 CSS containment 防止影響外部 */
}

/* Tab 內容容器 */
.tab-content {
  position: relative; /* 預設相對定位，縮放時會改為絕對定位 */
  width: 100%;        /* 填滿父容器 */
  height: 100%;       /* 填滿父容器 */
  display: none;
  padding: 16px;
  min-height: 400px;  /* 確保有足夠的拖放區域 */
  background-color: #f1ffee;
  box-sizing: border-box; /* 確保 padding 包含在寬高內 */
  transform-origin: 0 0; /* 設定變換原點在左上角 */
}
.tab-content.active {
  display: block; /* 只有被選中的 Tab 顯示 */
}
.tab-content.device-drag-over {
  border-color: #4CAF50; /* 設備拖拉時顯示綠色虛線邊框 */
  background-color: rgba(76, 175, 80, 0.1); /* 淺綠背景 */
}

/* 雙背景層 - 用於無閃爍背景圖切換 */
.bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #f1ffee;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  transition: opacity 0.5s ease-in-out;
  z-index: 0;
  pointer-events: none;
}
.bg-layer-a {
  opacity: 1;
}
.bg-layer-b {
  opacity: 0;
}

/* ---- 全螢幕 Overlay ---- */
.fullscreen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  display: none; /* 預設隱藏 */
  z-index: 999;
}

/* 全螢幕右上角的「恢復」按鈕 */
.fullscreen-overlay .exit-fullscreen-button {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #333;
  color: #fff;
  border: none;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
}

/* 全螢幕內的內容區域 */
.fullscreen-content {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 60px 20px 20px 20px; 
  /* 因為右上有按鈕，所以上方留點空間，以免內容蓋住按鈕 */
  overflow: hidden; /* 禁用滾動條 */
}

/* 右鍵選單樣式 */
.context-menu {
  position: fixed;
  background: white;
  border: 1px solid #ccc;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
  padding: 5px 0;
  min-width: 150px;
  z-index: 1000;
  display: none;
}

.context-menu-item {
  padding: 8px 15px;
  cursor: pointer;
  font-size: 14px;
  color: #333;
}

.context-menu-item:hover {
  background-color: #f0f0f0;
}

/* 對話框樣式 */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1001;
}

.dialog {
  background: white;
  padding: 20px;
  border-radius: 4px;
  min-width: 300px;
}

.dialog h3 {
  margin: 0 0 15px 0;
  font-size: 16px;
}

.dialog input {
  width: 100%;
  padding: 8px;
  margin-bottom: 15px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-button {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.dialog-button.primary {
  background: #4CAF50;
  color: white;
}

.dialog-button.secondary {
  background: #ccc;
  color: white;
}

/* 工具列樣式 */
.toolbar {
  display: flex;
  justify-content: space-between;
  background: #eee;
  padding: 0px;
  align-items: stretch;
  border-bottom: 2px solid #79b450;
  height: 42px;
  touch-action: manipulation; /* 允許工具列按鈕點擊 */
}

/* 新增按鈕容器樣式 */
.toolbar-buttons {
  display: flex;
  margin-left: auto;
  align-items: center;
  padding-right: 10px;
  touch-action: manipulation; /* 允許按鈕點擊 */
}

/* 儲存版面按鈕樣式 */
.save-layout-button {
  background: #79b450;
  color: white;
  border: 1px solid #6aa040;
  padding: 6px 16px;
  margin: 6px 15px 6px 0;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.save-layout-button:hover {
  background: #6aa040;
  border-color: #5a8c3a;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.save-layout-button:active {
  background: #5a8c3a;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
  transform: translateY(1px);
}

.save-layout-button .save-icon {
  font-size: 14px;
}

/* 全螢幕按鈕 */
.fullscreen-button {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 8px 8px;
  margin-right: 8px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  transition: background 0.3s;
}

/* 新增背景設定相關樣式 */
#backgroundDialog .dialog {
  padding: 20px;
}

.bg-option-tabs {
  margin: 15px 0;
}

.bg-option-tabs label {
  padding: 10px 15px;
  background: #f0f0f0;
  cursor: pointer;
  border-radius: 4px;
  margin-right: 5px;
}

.bg-option-tabs input[type="radio"] {
  display: none;
}

.bg-option-tabs input[type="radio"]:checked + label {
  background: #007bff;
  color: white;
}

.bg-tab-content {
  display: none;
  margin-top: 15px;
}

#urlPanel { display: block; }
#uploadPanel { display: none; }

#bgImageUrl, #bgImageUpload {
  width: 100%;
  padding: 8px;
  margin-bottom: 10px;
}

#imagePreview {
  max-width: 100%;
  max-height: 200px;
  margin-top: 10px;
  border: 1px solid #ddd;
  padding: 5px;
}

/* 在拖放時增加視覺回饋 - 已合併到上面的 .tab-content.drag-over */

/* 設備卡片容器樣式 */
.device-card {
  margin: 0;
  padding: 0;
  transition: transform 0.2s ease;
}

.device-card:hover {
  transform: translateY(-2px);
}

.device-card.dragging {
  opacity: 0.7;
  transform: scale(1.02);
}

/* 右側 TabPanel 中的裝置樣式 */
.tab-panel-device {
  user-select: none;
  transition: box-shadow 0.2s ease;
  touch-action: none; /* 允許自定義觸控拖拉 */
}

.tab-panel-device:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.tab-panel-device:active {
  cursor: grabbing;
}

/* 簡單設備卡片樣式 */
.simple-device-card {
  border: 2px solid #e0e0e0 !important;
  border-radius: 10px !important;
  padding: 14px !important;
  margin: 0 !important;
  background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%) !important;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08) !important;
  cursor: grab !important;
  text-align: center !important;
  min-width: 150px !important;
  width: 100%;
  transition: all 0.3s ease !important;
  position: relative;
  box-sizing: border-box;
}

.simple-device-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.15) !important;
  border-color: #79b450 !important;
}

.simple-device-card .device-ssid {
  font-size: 14px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 8px;
  letter-spacing: 0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
}

.simple-device-card .device-image {
  margin: 10px auto;
  width: 80px;
  height: 80px;
  padding: 12px;
  background: rgba(121, 180, 80, 0.05);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.simple-device-card .device-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.simple-device-card .device-name {
  font-size: 12px;
  color: #666;
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  padding: 0 4px;
  word-break: break-word;
}

/* 左側面板裝置卡片拖拉時的樣式 */
.simple-device-card:active,
device-m101:active, 
device-m200:active, 
device-m201:active, 
device-m207:active, 
device-m208:active, 
device-m508:active {
  cursor: grabbing;
}

/* 右鍵選單樣式改進 */
.context-menu {
  border-radius: 4px;
  overflow: hidden;
  font-family: Arial, sans-serif;
}

.context-menu-item {
  transition: background-color 0.2s ease;
}

.context-menu-item:first-child {
  border-top: none;
}

.context-menu-item:last-child {
  border-bottom: none;
}

/* 新增通知樣式 */
.save-notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 15px 25px;
  border-radius: 5px;
  color: white;
  font-size: 14px;
  font-weight: bold;
  box-shadow: 0 3px 6px rgba(0,0,0,0.16);
  z-index: 9999;
  display: none; /* 初始隱藏 */
  transition: opacity 0.3s ease;
  transform: translateZ(0); /* 硬體加速 */
}

/* 新增動畫效果 */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.save-notification[style*="display: block"] {
  animation: slideIn 0.3s ease-out;
}

/* 右下角錯誤通知樣式 */
.error-notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  min-width: 300px;
  max-width: 400px;
  padding: 16px 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  display: none;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid #ff4444;
}

.error-notification.show {
  display: block;
  animation: slideIn 0.3s ease-out;
}

.error-notification.hide {
  animation: slideOut 0.3s ease-out;
}

.error-notification-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.error-notification-icon {
  font-size: 20px;
  margin-right: 10px;
  color: #ff4444;
}

.error-notification-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.error-notification-body {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  white-space: pre-line;
}

/* Popup 訊息樣式 */
.popup-message {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

.popup-content {
  background: white;
  border-radius: 12px;
  padding: 30px;
  min-width: 350px;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  text-align: center;
  animation: slideUp 0.3s ease;
  position: relative;
}

.popup-icon {
  font-size: 48px;
  margin-bottom: 15px;
}

.popup-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 15px;
  color: #333;
}

.popup-text {
  font-size: 14px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 25px;
  white-space: pre-wrap;
  text-align: left;
  max-height: 300px;
  overflow-y: auto;
  padding: 10px;
  background: #f5f5f5;
  border-radius: 6px;
}

.popup-confirm {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 10px 30px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.popup-confirm:hover {
  background: #45a049;
}

.popup-confirm:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.3);
}

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

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

/* 載入指示器樣式 */
.loading-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  margin: 20px 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #79b450;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: #666;
  font-weight: 500;
  text-align: center;
}

/* 載入中的淡入淡出效果 */
.loading-indicator.fade-in {
  animation: fadeIn 0.3s ease-in;
}

.loading-indicator.fade-out {
  animation: fadeOut 0.3s ease-out;
}

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

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

/* 綠色圓形功能按鈕樣式 */
.field-menu-button {
  position: absolute;
  top: 60px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #79b450 0%, #6da241 100%);
  border: none;
  box-shadow: 0 4px 12px rgba(121, 180, 80, 0.3);
  cursor: pointer;
  z-index: 100;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.field-menu-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(121, 180, 80, 0.4);
}

.field-menu-button:active {
  transform: scale(0.95);
}

/* 下拉選單樣式 */
.field-menu-dropdown {
  position: absolute;
  top: 115px;
  right: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 99;
  overflow: hidden;
  min-width: 150px;
  animation: slideDown 0.2s ease;
}

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

.field-menu-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  color: #333;
  transition: background-color 0.2s ease;
  border-bottom: 1px solid #f0f0f0;
}

.field-menu-item:last-child {
  border-bottom: none;
}

.field-menu-item:hover {
  background-color: #f8f8f8;
  color: #79b450;
}

/* 縮放控制按鈕樣式 */
.zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px 12px;
  border-radius: 24px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  z-index: 90;
  user-select: none;
  transition: all 0.3s ease;
  touch-action: manipulation; /* 允許按鈕點擊操作 */
}

.zoom-controls:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.zoom-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #79b450;
  background: white;
  color: #79b450;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  touch-action: manipulation; /* 確保觸控點擊可用 */
}

.zoom-button:hover:not(:disabled) {
  background: #79b450;
  color: white;
  transform: scale(1.1);
}

.zoom-button:active:not(:disabled) {
  transform: scale(0.95);
}

.zoom-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.zoom-level {
  min-width: 50px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.zoom-level:hover {
  background: rgba(121, 180, 80, 0.1);
}

/* 桌面版提示 */
.zoom-hint {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
  text-align: center;
}

/* 行動裝置優化 */
@media (max-width: 768px) {
  .zoom-controls {
    bottom: 70px; /* 避免被其他控制項遮擋 */
    right: 10px;
  }
  
  .zoom-button {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
  
  .zoom-level {
    font-size: 16px;
  }
}

/* 背景圖片設定彈出視窗樣式 */
.field-background-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.field-background-popup .popup-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  min-width: 400px;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: popupFadeIn 0.3s ease;
}

.field-background-popup .popup-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 20px;
}

.field-background-popup .popup-body {
  margin-bottom: 24px;
}

.field-background-popup label {
  display: block;
  margin-bottom: 8px;
  color: #666;
  font-size: 14px;
}

.field-background-popup .popup-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.field-background-popup button {
  padding: 8px 20px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.field-background-popup .popup-cancel {
  background: #f0f0f0;
  color: #666;
}

.field-background-popup .popup-cancel:hover {
  background: #e0e0e0;
}

.field-background-popup .popup-confirm {
  background: linear-gradient(135deg, #79b450 0%, #6da241 100%);
  color: white;
}

.field-background-popup .popup-confirm:hover {
  box-shadow: 0 2px 8px rgba(121, 180, 80, 0.3);
}

@keyframes popupFadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 儲存的版面配置JSON彈出視窗樣式 */
.saved-layout-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.saved-layout-popup .popup-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: popupFadeIn 0.3s ease;
}

.saved-layout-popup .popup-title {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #e0e0e0;
}

.saved-layout-popup .popup-body {
  margin-bottom: 20px;
}

.saved-layout-popup .popup-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.saved-layout-popup button {
  padding: 10px 30px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.saved-layout-popup .popup-confirm {
  background: linear-gradient(135deg, #79b450 0%, #6da241 100%);
  color: white;
}

.saved-layout-popup .popup-confirm:hover {
  box-shadow: 0 2px 8px rgba(121, 180, 80, 0.3);
}

/* 即時任務相關樣式 */
/* 配額資訊區域 */
.quota-info {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: linear-gradient(135deg, #79b450 0%, #6da241 100%);
  color: white;
  padding: 16px 20px;
  border-radius: 8px;
  margin: 0 0 20px 0;
  box-shadow: 0 2px 8px rgba(121, 180, 80, 0.3);
}

.quota-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.quota-label {
  font-size: 12px;
  opacity: 0.9;
  font-weight: 500;
}

.quota-value {
  font-size: 24px;
  font-weight: bold;
}

.quota-used {
  color: #fff;
}

.quota-available {
  color: #fff;
}

/* 任務列表容器 */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
}

/* 任務卡片 */
.task-card {
  background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  overflow: hidden;
  border: 2px solid #e0e0e0;
  padding: 0;
  width: 100%;
  box-sizing: border-box;
}

.task-card:hover {
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
  transform: translateY(-3px);
  border-color: #79b450;
}

/* 任務卡片標題區 */
.task-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: none;
  background: transparent;
}

.task-name {
  font-size: 18px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.task-status {
  font-size: 13px;
  padding: 6px 16px;
  border-radius: 16px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.task-status.task-running {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.task-status.task-stopped {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* 任務卡片內容區 */
.task-card-body {
  padding: 0 20px 20px 20px;
}

.task-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

.task-info-item {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
}

.task-info-item strong {
  color: #333;
  font-weight: 600;
}

.blockly-link {
  color: #79b450;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  border-bottom: 1px solid transparent;
}

.blockly-link:hover {
  color: #6da241;
  border-bottom-color: #6da241;
}

/* 任務卡片操作區 */
.task-card-footer {
  padding: 16px 20px;
  border-top: none;
  background: transparent;
  display: flex;
  justify-content: flex-end;
}

/* 任務控制按鈕 */
.task-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.5px;
}

.task-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.task-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.task-btn-start {
  background: linear-gradient(135deg, #79b450 0%, #6da241 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(121, 180, 80, 0.3);
}

.task-btn-start:hover {
  box-shadow: 0 4px 12px rgba(121, 180, 80, 0.5);
}

.task-btn-stop {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(220, 53, 69, 0.3);
}

.task-btn-stop:hover {
  box-shadow: 0 4px 12px rgba(220, 53, 69, 0.5);
}

/* 響應式設計 */
@media (max-width: 768px) {
  .quota-info {
    flex-direction: column;
    gap: 12px;
    margin: 0 0 16px 0;
    padding: 12px 16px;
  }

  .task-list {
    gap: 8px;
  }

  .task-card {
    border-radius: 8px;
  }

  .task-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 16px;
  }

  .task-name {
    font-size: 16px;
    white-space: normal;
    word-break: break-word;
  }

  .task-card-body {
    padding: 0 16px 16px 16px;
  }

  .task-card-footer {
    padding: 12px 16px;
  }

  .task-btn {
    width: 100%;
    justify-content: center;
  }

  .quota-value {
    font-size: 20px;
  }
}

/* 任務確認對話框樣式 */
.task-confirm-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

.task-confirm-dialog.show {
  display: flex;
}

.task-confirm-content {
  background: white;
  border-radius: 12px;
  padding: 30px;
  min-width: 400px;
  max-width: 500px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: popupFadeIn 0.3s ease;
}

.task-confirm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.task-confirm-icon {
  font-size: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.task-confirm-icon.start {
  background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
  color: #155724;
}

.task-confirm-icon.stop {
  background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
  color: #721c24;
}

.task-confirm-title {
  font-size: 20px;
  font-weight: 700;
  color: #2c3e50;
}

.task-confirm-body {
  margin-bottom: 24px;
  color: #666;
  font-size: 14px;
  line-height: 1.6;
}

.task-confirm-info {
  background: #f8f9fa;
  padding: 12px 16px;
  border-radius: 8px;
  margin-top: 12px;
  border-left: 4px solid #79b450;
}

.task-confirm-info-item {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}

.task-confirm-info-item:last-child {
  margin-bottom: 0;
}

.task-confirm-info-item strong {
  color: #333;
  min-width: 80px;
}

.task-confirm-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.task-confirm-btn {
  padding: 10px 24px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.task-confirm-btn-cancel {
  background: #f0f0f0;
  color: #666;
}

.task-confirm-btn-cancel:hover {
  background: #e0e0e0;
}

.task-confirm-btn-confirm {
  background: linear-gradient(135deg, #79b450 0%, #6da241 100%);
  color: white;
}

.task-confirm-btn-confirm:hover {
  box-shadow: 0 2px 8px rgba(121, 180, 80, 0.3);
  transform: translateY(-1px);
}

.task-confirm-btn-confirm.danger {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
}

.task-confirm-btn-confirm.danger:hover {
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

/* 對話框 Loading 狀態 */
.task-confirm-dialog.loading .task-confirm-buttons {
  pointer-events: none;
  opacity: 0.6;
}

.task-confirm-dialog.loading .task-confirm-btn-confirm {
  position: relative;
  color: transparent;
}

.task-confirm-dialog.loading .task-confirm-btn-confirm::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid white;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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