/* ===================================
   側邊欄多頁面架構 CSS
   =================================== */

/* 全局布局 */
#app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

#main-content {
  /* display: flex - 由 JavaScript 控制 */
  min-height: 100vh;
}

#main-content:not([style*="display: none"]) {
  display: flex;
}

/* ===================================
   側邊欄樣式
   =================================== */
.sidebar {
  width: 280px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease, width 0.3s ease;
  overflow-y: auto;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar.collapsed {
  width: 70px;
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .user-info,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-group-title span,
.sidebar.collapsed .nav-group-arrow,
.sidebar.collapsed .logout-btn span {
  display: none;
}

.sidebar.collapsed .nav-group-items {
  display: none !important;
}

/* 側邊欄頭部 */
.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.2rem;
  font-weight: 700;
}

.sidebar-logo i {
  font-size: 1.8rem;
  color: #3b82f6;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* 側邊欄使用者區域 */
.sidebar-user {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.user-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 2px;
}

/* 側邊欄導航 */
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin: 4px 0;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  cursor: pointer;
  font-size: 0.9rem;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.nav-item.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
}

.nav-item i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

/* 導航群組 */
.nav-group {
  margin: 8px 0;
}

.nav-group-title {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  font-size: 0.9rem;
  font-weight: 600;
}

.nav-group-title:hover {
  background: rgba(255, 255, 255, 0.05);
}

.nav-group-title i:first-child {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

.nav-group-title span {
  flex: 1;
}

.nav-group-arrow {
  font-size: 0.8rem;
  transition: transform 0.3s;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 4px;
}

.nav-group-arrow:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-group-title.open .nav-group-arrow {
  transform: rotate(180deg);
}

.nav-group-title.active {
  background: rgba(99, 102, 241, 0.1);
  color: #818cf8;
}

.nav-group-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding-left: 32px;
}

.nav-group-items.open {
  max-height: 500px;
}

.nav-group-items .nav-item {
  padding: 10px 16px;
  font-size: 0.85rem;
}

/* 側邊欄底部 */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #f87171;
}

.logout-btn i {
  font-size: 1.1rem;
}

/* ===================================
   主內容包裝器
   =================================== */
.main-wrapper {
  flex: 1;
  margin-left: 280px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
  background: #f8fafc;
}

.sidebar.collapsed + .main-wrapper {
  margin-left: 70px;
}

/* ===================================
   頂部導航列
   =================================== */
.topbar {
  height: 64px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #64748b;
  font-size: 0.9rem;
}

.breadcrumb i {
  color: #3b82f6;
}

.breadcrumb span {
  font-weight: 600;
  color: #1e293b;
}

.back-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  color: #64748b;
}

.back-button:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #3b82f6;
  transform: translateX(-2px);
}

.back-button i {
  font-size: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* 通知鈴鐺 */
.notification-bell {
  position: relative;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

.notification-bell:hover {
  background: #f1f5f9;
}

.notification-bell i {
  font-size: 1.3rem;
  color: #64748b;
}

.notification-bell .badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #ef4444;
  color: white;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

/* 使用者選單 */
.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.user-menu:hover {
  background: #f1f5f9;
}

.user-avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: white;
  font-size: 0.9rem;
}

/* ===================================
   通知中心
   =================================== */
.notification-center {
  position: fixed;
  top: 80px;
  right: 20px;
  width: 400px;
  max-width: 90vw;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  z-index: 1000;
  max-height: 600px;
  overflow: hidden;
}

.notification-header {
  padding: 16px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.notification-header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.notification-actions {
  display: flex;
  gap: 8px;
}

.btn-mark-read {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s;
}

.btn-mark-read:hover {
  background: rgba(255, 255, 255, 0.3);
}

.btn-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.4rem;
  padding: 0 8px;
  line-height: 1;
}

.notification-list {
  max-height: 500px;
  overflow-y: auto;
}

/* ===================================
   PWA 組件
   =================================== */
.pwa-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  max-width: 90vw;
  width: 400px;
}

.pwa-banner-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.pwa-banner-content i {
  font-size: 2rem;
}

.pwa-banner-text {
  flex: 1;
}

.pwa-banner-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.pwa-banner-subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
}

.pwa-install-btn {
  background: white;
  color: #667eea;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.pwa-install-btn:hover {
  transform: scale(1.05);
}

.pwa-close-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.5rem;
  opacity: 0.7;
  padding: 0;
  margin-left: -8px;
}

.pwa-update {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #10b981;
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  max-width: 90vw;
  width: 350px;
}

.pwa-update-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pwa-update-content i {
  font-size: 1.5rem;
}

.pwa-update-text {
  flex: 1;
}

.pwa-update-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.pwa-update-subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
}

.pwa-update-btn {
  background: white;
  color: #10b981;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #f59e0b;
  color: white;
  padding: 12px;
  text-align: center;
  z-index: 9999;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ===================================
   內容區域
   =================================== */
.content-area {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: #64748b;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===================================
   頁尾
   =================================== */
.footer {
  padding: 20px 24px;
  background: white;
  border-top: 1px solid #e2e8f0;
  text-align: center;
  color: #64748b;
  font-size: 0.85rem;
}

.footer-small {
  margin-top: 4px;
  font-size: 0.75rem;
  color: #94a3b8;
}

/* ===================================
   響應式設計
   =================================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0 !important;
  }

  .sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 101;
    background: #1e293b;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .topbar {
    padding-left: 70px;
  }

  .notification-center {
    right: 10px;
    left: 10px;
    width: auto;
  }
}

/* ===================================
   頁面特定樣式
   =================================== */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 8px;
}

.page-subtitle {
  color: #64748b;
  font-size: 0.95rem;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: #1e293b;
}

/* Table styles */
.table-row-hover {
  transition: background 0.2s;
}

.table-row-hover:hover {
  background: #f8fafc;
}

/* Toast animations */
@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

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

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