/*
 * GREATSTORE 統一設計系統
 * 設計理念：簡約、溫暖、人性化
 * 風格：現代簡約主義 - 溫暖橙色系
 */

/* ============================================
   1. CSS Variables - 統一配色系統
   ============================================ */
:root {
  /* 主要品牌色 - 溫暖橙色 */
  --primary: #f97316;
  --primary-light: #fb923c;
  --primary-dark: #ea580c;
  --primary-darker: #c2410c;
  --primary-50: #fff7ed;
  --primary-100: #ffedd5;
  --primary-200: #fed7aa;
  --primary-300: #fdba74;
  --primary-400: #fb923c;
  --primary-500: #f97316;
  --primary-600: #ea580c;
  --primary-700: #c2410c;
  --primary-800: #9a3412;
  --primary-900: #7c2d12;

  /* 狀態配色 */
  --success: #22c55e;
  --success-light: #dcfce7;
  --success-dark: #16a34a;
  --success-50: #f0fdf4;
  --warning: #eab308;
  --warning-light: #fef9c3;
  --warning-dark: #ca8a04;
  --warning-50: #fefce8;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --danger-dark: #dc2626;
  --danger-50: #fef2f2;
  --info: #0ea5e9;
  --info-light: #e0f2fe;
  --info-dark: #0284c7;
  --info-50: #f0f9ff;

  /* 中性配色 - 溫暖灰階 */
  --gray-50: #fafaf9;
  --gray-100: #f5f5f4;
  --gray-200: #e7e5e4;
  --gray-300: #d6d3d1;
  --gray-400: #a8a29e;
  --gray-500: #78716c;
  --gray-600: #57534e;
  --gray-700: #44403c;
  --gray-800: #292524;
  --gray-900: #1c1917;

  /* 背景配色 */
  --bg-primary: #ffffff;
  --bg-secondary: #fafaf9;
  --bg-tertiary: #f5f5f4;

  /* 文字配色 */
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #a8a29e;

  /* 邊框 */
  --border-color: #e7e5e4;
  --border-light: #f5f5f4;

  /* 陰影 - 溫暖色調 */
  --shadow-xs: 0 1px 2px 0 rgba(120, 113, 108, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(120, 113, 108, 0.08), 0 1px 2px -1px rgba(120, 113, 108, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(120, 113, 108, 0.08), 0 2px 4px -2px rgba(120, 113, 108, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(120, 113, 108, 0.1), 0 4px 6px -4px rgba(120, 113, 108, 0.06);
  --shadow-xl: 0 20px 25px -5px rgba(120, 113, 108, 0.1), 0 8px 10px -6px rgba(120, 113, 108, 0.06);
  --shadow-primary: 0 0 0 3px rgba(249, 115, 22, 0.15);
  --shadow-primary-lg: 0 0 0 4px rgba(249, 115, 22, 0.2);
  --shadow-card-hover: 0 8px 25px -5px rgba(249, 115, 22, 0.1), 0 4px 10px -5px rgba(120, 113, 108, 0.08);

  /* 圓角 */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.25rem;
  --radius-full: 9999px;

  /* 動畫 */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  --transition-slower: 400ms ease;

  /* 側邊欄 - 深棕橙色 */
  --sidebar-width: 260px;
  --sidebar-bg: #431407;
  --sidebar-bg-light: #4c1d0a;
  --sidebar-text: rgba(255, 255, 255, 0.9);
  --sidebar-text-muted: rgba(255, 255, 255, 0.6);
  --sidebar-border: rgba(255, 255, 255, 0.1);
  --sidebar-active-bg: #f97316;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.08);
  --sidebar-icon-color: #fdba74;
}

/* ============================================
   2. 全域樣式
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  line-height: 1.5;
}

/* ============================================
   3. 側邊欄 - 統一樣式
   ============================================ */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  max-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0;
  left: 0;
  overflow: hidden;
  z-index: 1000;
  padding: 1.5rem;
  padding-bottom: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.5rem 0;
  margin-bottom: 1.5rem;
  text-decoration: none;
}

.sidebar-brand i {
  font-size: 1.5rem;
  color: var(--sidebar-icon-color);
}

/* 網站切換器 */
.website-switcher {
  margin-bottom: 1.5rem;
}

.website-switcher .dropdown-toggle {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 0.75rem 1rem;
  color: #ffffff !important;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition-base);
  font-size: 0.875rem;
}

.website-switcher .dropdown-toggle:hover,
.website-switcher .dropdown-toggle:focus {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.website-switcher .dropdown-toggle i {
  color: var(--sidebar-icon-color);
  margin-right: 0.5rem;
}

.website-switcher .current-website-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.website-switcher .dropdown-menu {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  margin-top: 0.25rem;
  max-height: 60vh;
  overflow-y: auto;
}

.website-switcher .dropdown-item {
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.website-switcher .dropdown-item:hover {
  background: var(--primary-50);
  color: var(--primary);
}

.website-switcher .dropdown-item.active {
  background: var(--primary);
  color: #ffffff;
}

.website-switcher .dropdown-item .fa-check {
  opacity: 0;
  font-size: 0.75rem;
}

.website-switcher .dropdown-item.active .fa-check {
  opacity: 1;
}

/* 網站切換選單項目樣式 */
.website-switcher .dropdown-menu li {
  list-style: none;
}

.website-switcher .dropdown-menu a.dropdown-item {
  width: 100%;
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* 導航連結 */
.sidebar .nav {
  flex: 1;
}

.sidebar .nav-link {
  color: rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-md);
  padding: 0.625rem 0.875rem;
  margin-bottom: 0.25rem;
  transition: var(--transition-base);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar .nav-link i {
  width: 1.25rem;
  text-align: center;
  font-size: 1rem;
}

.sidebar .nav-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar .nav-link.active {
  color: #ffffff;
  background: var(--primary);
}

/* 側邊欄分隔線 */
.sidebar hr {
  border-color: rgba(255, 255, 255, 0.1);
  margin: 1rem 0;
}

/* 側邊欄用戶區域 */
.sidebar-user {
  margin-top: auto;
  padding-top: 1rem;
  padding-bottom: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sidebar-user .dropdown-toggle {
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  transition: var(--transition-base);
}

.sidebar-user .dropdown-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-user .dropdown-toggle i {
  font-size: 1.25rem;
  margin-right: 0.5rem;
}

/* ============================================
   4. 主內容區域
   ============================================ */
.main-content {
  margin-left: var(--sidebar-width);
  padding: 1.5rem;
  min-height: 100vh;
  background: var(--bg-secondary);
}

/* ============================================
   5. 卡片元件
   ============================================ */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
  border-color: var(--primary-200);
}

.card-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-header:first-child {
  border-radius: calc(var(--radius-xl) - 1px) calc(var(--radius-xl) - 1px) 0 0;
}

.card-body {
  padding: 1.25rem;
}

.card-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

/* ============================================
   6. 按鈕
   ============================================ */
.btn {
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  transition: var(--transition-base);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: 1px solid transparent;
}

.btn:focus {
  outline: none;
  box-shadow: var(--shadow-primary);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -2px rgba(249, 115, 22, 0.25);
}

.btn-primary:active {
  background: var(--primary-darker);
  transform: translateY(0);
}

.btn-secondary {
  background: var(--gray-100);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--gray-200);
  color: var(--text-primary);
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.btn-success:hover {
  background: #16a34a;
  border-color: #16a34a;
  color: #ffffff;
}

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

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

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

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

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

/* ============================================
   7. 表單元素
   ============================================ */
.form-control {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  transition: var(--transition-base);
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-primary);
  outline: none;
}

.form-control:hover {
  border-color: var(--gray-300);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-select {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 0.625rem 2.25rem 0.625rem 0.875rem;
  font-size: 0.875rem;
  transition: var(--transition-base);
  background-color: var(--bg-primary);
}

.form-select:focus {
  border-color: var(--primary);
  box-shadow: var(--shadow-primary);
  outline: none;
}

.form-select:hover {
  border-color: var(--gray-300);
}

.form-label {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
}

.form-text {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ============================================
   8. 表格
   ============================================ */
.table {
  background-color: var(--bg-primary);
  margin-bottom: 0;
}

.table thead th {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-color);
  border-top: none;
}

.table tbody tr {
  transition: var(--transition-fast);
}

.table tbody tr:hover {
  background-color: var(--primary-50);
}

.table tbody td {
  padding: 0.875rem 1rem;
  vertical-align: middle;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
}

.table tbody td:first-child {
  font-weight: 500;
  color: var(--text-primary);
}

/* 表格容器 */
.table-wrapper {
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.table-wrapper .table {
  margin-bottom: 0;
}

/* ============================================
   9. 下拉選單
   ============================================ */
.dropdown-menu {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  background-color: var(--bg-primary);
}

.dropdown-item {
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: var(--transition-fast);
  color: var(--text-secondary);
}

.dropdown-item:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.dropdown-item.active,
.dropdown-item:active {
  background-color: var(--primary);
  color: #ffffff;
}

.dropdown-divider {
  border-top-color: var(--border-color);
  margin: 0.5rem 0;
}

/* ============================================
   10. Badge 標籤
   ============================================ */
.badge {
  border-radius: var(--radius-sm);
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.bg-primary { background-color: var(--primary) !important; }
.bg-success { background-color: var(--success) !important; }
.bg-warning { background-color: var(--warning) !important; }
.bg-danger { background-color: var(--danger) !important; }
.bg-info { background-color: var(--info) !important; }
.bg-secondary { background-color: var(--gray-500) !important; }

/* 淺色標籤 */
.badge-soft-primary {
  background-color: var(--primary-100);
  color: var(--primary);
}

.badge-soft-success {
  background-color: var(--success-light);
  color: #15803d;
}

.badge-soft-warning {
  background-color: var(--warning-light);
  color: #b45309;
}

.badge-soft-danger {
  background-color: var(--danger-light);
  color: #b91c1c;
}

/* ============================================
   11. Alert 提示框
   ============================================ */
.alert {
  border-radius: var(--radius-lg);
  border: none;
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
}

.alert-success {
  background-color: var(--success-light);
  color: #166534;
}

.alert-warning {
  background-color: var(--warning-light);
  color: #92400e;
}

.alert-danger {
  background-color: var(--danger-light);
  color: #991b1b;
}

.alert-info {
  background-color: var(--info-light);
  color: #0e7490;
}

/* ============================================
   12. 分頁
   ============================================ */
.pagination {
  gap: 0.25rem;
}

.page-link {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: var(--transition-base);
}

.page-link:hover {
  background-color: var(--bg-secondary);
  border-color: var(--primary);
  color: var(--primary);
}

.page-item.active .page-link {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.page-item.disabled .page-link {
  background-color: var(--bg-tertiary);
  color: var(--text-muted);
}

/* ============================================
   13. Modal 對話框
   ============================================ */
.modal-content {
  border-radius: var(--radius-xl);
  border: none;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 1rem 1.25rem;
}

.modal-title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 1rem;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  padding: 0.875rem 1.25rem;
}

/* ============================================
   14. 統計卡片
   ============================================ */
.stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.25rem;
  transition: var(--transition-base);
}

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

.stat-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.stat-card-icon.primary {
  background: linear-gradient(135deg, var(--primary-100), var(--primary-200));
  color: var(--primary-dark);
}

.stat-card-icon.success {
  background: linear-gradient(135deg, var(--success-50), var(--success-light));
  color: var(--success-dark);
}

.stat-card-icon.warning {
  background: linear-gradient(135deg, var(--warning-50), var(--warning-light));
  color: var(--warning-dark);
}

.stat-card-icon.danger {
  background: linear-gradient(135deg, var(--danger-50), var(--danger-light));
  color: var(--danger-dark);
}

.stat-card-icon.info {
  background: linear-gradient(135deg, var(--info-50), var(--info-light));
  color: var(--info-dark);
}

.stat-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 0.375rem;
}

.stat-card-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ============================================
   15. 篩選區域
   ============================================ */
.filter-section {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.filter-section .row {
  --bs-gutter-x: 1rem;
  --bs-gutter-y: 0.75rem;
}

/* ============================================
   16. 操作按鈕組
   ============================================ */
.action-buttons {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.action-buttons .btn {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

/* ============================================
   17. 空狀態
   ============================================ */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  background: var(--bg-tertiary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: var(--text-muted);
}

.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.empty-state-text {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

/* ============================================
   18. 載入動畫
   ============================================ */
.spinner-border {
  width: 1.5rem;
  height: 1.5rem;
  border-width: 2px;
}

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

/* ============================================
   19. 權限選單
   ============================================ */
.permission-menu {
  flex: 1 1 0;
  min-height: 0;
  max-height: calc(100vh - 250px); /* 預留空間給品牌、網站選擇器、使用者資訊 */
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 -0.5rem;
  padding: 0 0.5rem;
  padding-bottom: 1rem;
}

/* 自訂捲軸樣式 */
.permission-menu::-webkit-scrollbar {
  width: 6px;
}

.permission-menu::-webkit-scrollbar-track {
  background: transparent;
}

.permission-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.permission-menu::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.permission-menu-loading {
  text-align: center;
  padding: 1rem;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.875rem;
}

.permission-menu-error {
  padding: 0.75rem;
}

.no-permissions {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8125rem;
  text-align: center;
  padding: 1rem;
}

/* ============================================
   20. 頁面標題
   ============================================ */
.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ============================================
   21. 工具類別
   ============================================ */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }

.bg-light { background-color: var(--bg-secondary) !important; }

.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow-md { box-shadow: var(--shadow-md) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }

.rounded-lg { border-radius: var(--radius-lg) !important; }
.rounded-xl { border-radius: var(--radius-xl) !important; }

/* ============================================
   21.5 文字顯示相容修正（避免白底白字）
   ============================================ */
.main-content .text-white,
.main-content .text-light,
.main-content .text-white-50 {
  color: var(--text-primary) !important;
}

.main-content .bg-primary .text-white,
.main-content .bg-success .text-white,
.main-content .bg-warning .text-white,
.main-content .bg-danger .text-white,
.main-content .bg-info .text-white,
.main-content .bg-secondary .text-white,
.main-content .bg-dark .text-white,
.main-content .bg-primary .text-light,
.main-content .bg-success .text-light,
.main-content .bg-warning .text-light,
.main-content .bg-danger .text-light,
.main-content .bg-info .text-light,
.main-content .bg-secondary .text-light,
.main-content .bg-dark .text-light {
  color: #ffffff !important;
}

.main-content .bg-primary .text-white-50,
.main-content .bg-success .text-white-50,
.main-content .bg-warning .text-white-50,
.main-content .bg-danger .text-white-50,
.main-content .bg-info .text-white-50,
.main-content .bg-secondary .text-white-50,
.main-content .bg-dark .text-white-50 {
  color: rgba(255, 255, 255, 0.7) !important;
}

/* ============================================
   22. 響應式設計
   ============================================ */
@media (max-width: 992px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
  }

  .sidebar.show {
    transform: translateX(0);
    width: 260px;
  }

  .main-content {
    margin-left: 0;
    padding: 1rem;
  }
}

@media (max-width: 576px) {
  .card-body {
    padding: 1rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-card-value {
    font-size: 1.5rem;
  }

  .table-wrapper {
    overflow-x: auto;
  }

  .table {
    font-size: 0.8125rem;
  }
}

/* ============================================
   23. 列印樣式
   ============================================ */
@media print {
  .sidebar,
  .no-print {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
    padding: 0;
  }

  body {
    background-color: #ffffff;
  }

  .card {
    border: 1px solid #ddd;
    box-shadow: none;
  }
}

/* ============================================
   24. Filterrific spinner
   ============================================ */
#filterrific-spinner {
  display: none;
  padding: 0.5rem;
  text-align: center;
  color: var(--text-muted);
}

#filterrific-spinner .spinner-border {
  width: 1.25rem;
  height: 1.25rem;
}

/* ============================================
   25. Sidebar 位置系統 (Issue #79)
   ============================================ */

/* 拖放手柄 */
.sidebar-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  margin: -0.5rem -0.5rem 1rem -0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  cursor: grab;
  transition: var(--transition-base);
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.75rem;
}

.sidebar-drag-handle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}

.sidebar-drag-handle:active {
  cursor: grabbing;
}

.sidebar-drag-handle i {
  font-size: 1rem;
}

.sidebar-drag-handle .drag-hint {
  font-size: 0.6875rem;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.sidebar-drag-handle:hover .drag-hint {
  opacity: 1;
}

/* 拖曳中狀態 */
.sidebar.dragging {
  opacity: 0.7;
  /* 移除 transform: scale(0.98) - 在水平模式下會導致 layout shift 取消拖曳操作 */
}

/* Drop Zones 容器 */
.sidebar-drop-zones {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  pointer-events: none;
}

.sidebar-drop-zones .drop-zone {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(249, 115, 22, 0.1);
  border: 3px dashed var(--primary);
  transition: var(--transition-base);
  pointer-events: all;
}

.sidebar-drop-zones .drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  font-weight: 600;
}

.sidebar-drop-zones .drop-zone-content i {
  font-size: 2rem;
}

.sidebar-drop-zones .drop-zone-content span {
  font-size: 0.875rem;
}

/* Drop Zone 位置 */
.drop-zone-left {
  left: 0;
  top: 0;
  bottom: 0;
  width: 120px;
}

.drop-zone-right {
  right: 0;
  top: 0;
  bottom: 0;
  width: 120px;
}

.drop-zone-top {
  top: 0;
  left: 120px;
  right: 120px;
  height: 80px;
}

.drop-zone-bottom {
  bottom: 0;
  left: 120px;
  right: 120px;
  height: 80px;
}

/* Drop Zone Hover 狀態 */
.drop-zone.drag-over {
  background: rgba(249, 115, 22, 0.25);
  border-color: var(--primary-dark);
}

.drop-zone.drag-over .drop-zone-content {
  transform: scale(1.1);
}

/* 當前位置標記 - 隱藏，因為用戶不需要拖到當前位置 */
.drop-zone.current {
  opacity: 0.3;
  pointer-events: none;
}

.drop-zone.current .drop-zone-content {
  color: var(--text-muted);
}

/* 拖曳中時降低 sidebar 的 z-index，讓 drop zones 顯示在上方 */
.sidebar.dragging {
  z-index: 500 !important;
}

/* ============================================
   Sidebar 左側（預設）
   ============================================ */
.sidebar-left .sidebar,
body:not(.sidebar-top):not(.sidebar-right):not(.sidebar-bottom) .sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  max-height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  flex-direction: column;
}

.sidebar-left .main-content,
body:not(.sidebar-top):not(.sidebar-right):not(.sidebar-bottom) .main-content {
  margin-left: var(--sidebar-width);
  margin-right: 0;
  margin-top: 0;
  margin-bottom: 0;
}

/* ============================================
   Sidebar 右側
   ============================================ */
.sidebar-right .sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  max-height: 100vh;
  position: fixed;
  top: 0;
  right: 0;
  left: auto;
  bottom: auto;
  flex-direction: column;
}

.sidebar-right .main-content {
  margin-right: var(--sidebar-width);
  margin-left: 0;
  margin-top: 0;
  margin-bottom: 0;
}

/* ============================================
   Sidebar 上方
   ============================================ */
.sidebar-top .sidebar {
  width: 100%;
  height: auto;
  max-height: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: auto;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  padding: 0.75rem 1.5rem;
  gap: 1rem;
  overflow: visible;
}

.sidebar-top .sidebar-brand {
  margin-bottom: 0;
  padding: 0;
}

.sidebar-top .website-switcher {
  margin-bottom: 0;
}

.sidebar-top .website-switcher .dropdown-toggle {
  padding: 0.5rem 0.75rem;
}

.sidebar-top .permission-menu {
  flex: 1;
  min-width: 0;
  min-height: auto;
  max-height: none;
  overflow: visible;
  margin: 0;
  padding: 0;
}

.sidebar-top .sidebar hr {
  display: none;
}

.sidebar-top .sidebar-user {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  padding-bottom: 0;
}

.sidebar-top .sidebar-drag-handle {
  margin: 0;
  padding: 0.5rem 0.75rem;
  order: -1;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-top .sidebar-drag-handle:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-top .sidebar-drag-handle i {
  font-size: 1.25rem;
}

.sidebar-top .sidebar-drag-handle .drag-hint {
  display: none;
}

.sidebar-top .main-content {
  margin-top: 70px;
  margin-left: 0;
  margin-right: 0;
  margin-bottom: 0;
}

/* 上方位置的水平選單 */
.sidebar-top .permission-menu .nav {
  flex-direction: row !important;
  flex-wrap: nowrap;
  gap: 0.25rem;
}

.sidebar-top .permission-menu .nav-item {
  position: relative;
}

.sidebar-top .permission-menu .nav-item.level-0 {
  margin-bottom: 0;
}

.sidebar-top .permission-menu .nav-link {
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
}

/* 水平模式下的子選單使用下拉 - hover 觸發 */
.sidebar-top .permission-menu .nav-item.level-0 > .collapse {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 200px;
  background: var(--sidebar-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  padding: 0.5rem;
  /* hover 觸發：預設隱藏 */
  display: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease-in-out, visibility 0.15s ease-in-out;
}

/* hover 時顯示下拉選單 */
.sidebar-top .permission-menu .nav-item.level-0:hover > .collapse {
  display: block;
  opacity: 1;
  visibility: visible;
}

/* 覆蓋 Bootstrap collapse 的 show 類別，讓 hover 控制顯示 */
.sidebar-top .permission-menu .nav-item.level-0 > .collapse.show {
  display: none;
  opacity: 0;
  visibility: hidden;
}

.sidebar-top .permission-menu .nav-item.level-0:hover > .collapse.show {
  display: block;
  opacity: 1;
  visibility: visible;
}

.sidebar-top .permission-menu .collapse .nav {
  flex-direction: column !important;
}

.sidebar-top .permission-menu .collapse .card-body {
  padding: 0;
  border: none;
  margin: 0;
}

.sidebar-top .permission-menu .collapse .nav-link {
  padding: 0.5rem 0.75rem;
}

/* hover 時旋轉箭頭圖示 */
.sidebar-top .permission-menu .nav-item.level-0:hover > .nav-link [data-toggle-icon] {
  transform: rotate(180deg);
}

/* ============================================
   Sidebar 下方
   ============================================ */
.sidebar-bottom .sidebar {
  width: 100%;
  height: auto;
  max-height: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: auto;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  padding: 0.75rem 1.5rem;
  gap: 1rem;
  overflow: visible;
}

.sidebar-bottom .sidebar-brand {
  margin-bottom: 0;
  padding: 0;
}

.sidebar-bottom .website-switcher {
  margin-bottom: 0;
}

.sidebar-bottom .website-switcher .dropdown-toggle {
  padding: 0.5rem 0.75rem;
}

.sidebar-bottom .permission-menu {
  flex: 1;
  min-width: 0;
  min-height: auto;
  max-height: none;
  overflow: visible;
  margin: 0;
  padding: 0;
}

.sidebar-bottom .sidebar hr {
  display: none;
}

.sidebar-bottom .sidebar-user {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  padding-bottom: 0;
}

.sidebar-bottom .sidebar-drag-handle {
  margin: 0;
  padding: 0.5rem 0.75rem;
  order: -1;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-bottom .sidebar-drag-handle:hover {
  background: rgba(255, 255, 255, 0.2);
}

.sidebar-bottom .sidebar-drag-handle i {
  font-size: 1.25rem;
}

.sidebar-bottom .sidebar-drag-handle .drag-hint {
  display: none;
}

.sidebar-bottom .main-content {
  margin-bottom: 70px;
  margin-left: 0;
  margin-right: 0;
  margin-top: 0;
}

/* 下方位置的水平選單 */
.sidebar-bottom .permission-menu .nav {
  flex-direction: row !important;
  flex-wrap: nowrap;
  gap: 0.25rem;
}

.sidebar-bottom .permission-menu .nav-item {
  position: relative;
}

.sidebar-bottom .permission-menu .nav-item.level-0 {
  margin-bottom: 0;
}

.sidebar-bottom .permission-menu .nav-link {
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
}

/* 水平模式下的子選單使用下拉（向上展開）- hover 觸發 */
.sidebar-bottom .permission-menu .nav-item.level-0 > .collapse {
  position: absolute;
  bottom: 100%;
  left: 0;
  min-width: 200px;
  background: var(--sidebar-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  padding: 0.5rem;
  /* hover 觸發：預設隱藏 */
  display: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease-in-out, visibility 0.15s ease-in-out;
}

/* hover 時顯示下拉選單 */
.sidebar-bottom .permission-menu .nav-item.level-0:hover > .collapse {
  display: block;
  opacity: 1;
  visibility: visible;
}

/* 覆蓋 Bootstrap collapse 的 show 類別，讓 hover 控制顯示 */
.sidebar-bottom .permission-menu .nav-item.level-0 > .collapse.show {
  display: none;
  opacity: 0;
  visibility: hidden;
}

.sidebar-bottom .permission-menu .nav-item.level-0:hover > .collapse.show {
  display: block;
  opacity: 1;
  visibility: visible;
}

.sidebar-bottom .permission-menu .collapse .nav {
  flex-direction: column !important;
}

.sidebar-bottom .permission-menu .collapse .card-body {
  padding: 0;
  border: none;
  margin: 0;
}

.sidebar-bottom .permission-menu .collapse .nav-link {
  padding: 0.5rem 0.75rem;
}

/* hover 時旋轉箭頭圖示（向上展開時箭頭向上） */
.sidebar-bottom .permission-menu .nav-item.level-0 > .nav-link [data-toggle-icon] {
  transform: rotate(180deg);
}

.sidebar-bottom .permission-menu .nav-item.level-0:hover > .nav-link [data-toggle-icon] {
  transform: rotate(0deg);
}

/* ============================================
   響應式調整
   ============================================ */
/* 上方/下方模式防止頁面水平捲動 */
body.sidebar-top,
body.sidebar-bottom {
  overflow-x: hidden;
}

@media (max-width: 768px) {
  /* 小螢幕上隱藏拖放提示 */
  .sidebar-drag-handle .drag-hint {
    display: none !important;
  }

  /* 簡化 drop zones */
  .drop-zone-content span {
    display: none;
  }

  .drop-zone-left,
  .drop-zone-right {
    width: 60px;
  }

  .drop-zone-top,
  .drop-zone-bottom {
    height: 50px;
    left: 60px;
    right: 60px;
  }
}

/* ============================================
   觸控裝置位置設定選單
   ============================================ */
.sidebar-position-menu {
  position: fixed;
  z-index: 10000;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.75rem;
  min-width: 180px;
}

.position-menu-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
}

.position-menu-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.position-menu-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.75rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-base);
  font-size: 0.8125rem;
}

.position-menu-option:hover {
  background: var(--primary-50);
  border-color: var(--primary);
  color: var(--primary);
}

.position-menu-option.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.position-menu-option i {
  font-size: 1.25rem;
}

.position-menu-option span {
  font-weight: 500;
}
