/**
 * Browser Panel Component - Glass Design Style
 * 浏览器面板样式
 * 
 * @created 2026-01-18
 * @description 左右分栏布局：左侧展示区，右侧菜单栏
 */

/* ===== Browser 面板无头部布局 ===== */
.panel-content.browser-panel-no-header {
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* ===== 分栏容器 ===== */
.browser-split-container {
  display: flex;
  flex-direction: row-reverse; /* 交换左右位置：展示区在左，菜单栏在右 */
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ===== 右侧菜单栏（作为侧边栏） ===== */
.browser-menu-pane {
  flex: 0 0 180px;
  min-width: 140px;
  max-width: 280px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  transition: flex var(--transition-normal, 200ms) ease-out;
}

/* 菜单头部 */
.browser-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--border);
}

.browser-menu-header h3 {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--foreground);
  margin: 0;
}

.browser-menu-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all var(--transition-fast, 150ms);
}

.browser-menu-action:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--foreground);
}

.browser-menu-action:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.95);
}

.browser-menu-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.browser-menu-action:disabled:hover {
  background: transparent;
  color: var(--muted-foreground);
}

/* 刷新按钮旋转动画 */
.browser-menu-action.refreshing svg {
  animation: spin 1s linear infinite;
}

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

.browser-menu-action svg {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* 菜单列表 */
.browser-menu-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

/* 菜单项 */
.browser-menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all var(--transition-fast, 150ms) ease;
  margin-bottom: 0.25rem;
  user-select: none;
}

.browser-menu-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--foreground);
}

.browser-menu-item.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.browser-menu-item .menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.browser-menu-item .menu-icon svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.browser-menu-item .menu-icon svg rect,
.browser-menu-item .menu-icon svg circle {
  fill: none;
  stroke: currentColor;
}

.browser-menu-item .menu-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browser-menu-item .menu-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.375rem;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--muted-foreground);
}

.browser-menu-item.active .menu-badge {
  background: rgba(0, 0, 0, 0.2);
  color: var(--primary-foreground);
}

/* ===== 分栏拖拽条 ===== */
.browser-resizer {
  width: 4px;
  background: var(--border);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background var(--transition-fast, 150ms);
  position: relative;
  display: block;
}

.browser-resizer:hover,
.browser-resizer.dragging {
  background: var(--primary);
}

.browser-resizer::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  right: -4px;
}

/* ===== 左侧展示区（主视觉区域） ===== */
.browser-display-pane {
  flex: 1;
  min-width: 300px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #000;
}

/* ===== Three.js 动态背景容器 ===== */
.browser-threejs-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  background: #000;
  overflow: hidden;
}

.browser-threejs-bg canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ===== 标签页内容容器 ===== */
.browser-content-container {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0; /* 重要：允许在 flex 容器中正确滚动 */
  overflow-y: auto;
  padding: 1.5rem;
  background: transparent; /* 透明背景，让 Three.js 动画作为背景显示 */
}

/* ===== 标签页 Grid 布局 ===== */
.tabs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

/* ===== 毛玻璃卡片样式 ===== */
.glass-card {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  transition: all var(--transition-normal, 200ms) ease;
}

.glass-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
}

/* ===== Tab 卡片样式 ===== */
.tab-card {
  padding: 1.25rem;
}

/* 活动标签页高亮 */
.tab-card.active {
  border-left: 3px solid #22c55e;
}

.tab-card.active .tab-card-title {
  color: #22c55e;
}

.tab-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.tab-card-icon {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.tab-card-icon img {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.25rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 0.125rem;
  flex-shrink: 0;
  object-fit: contain;
}

.tab-card-icon .tab-icon-fallback {
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.tab-card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-card-status {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.tab-card-status.complete {
  background: #22c55e;
}

.tab-card-status.loading {
  background: #eab308;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

/* Tab URL */
.tab-card-url {
  font-size: 0.75rem;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  color: var(--muted-foreground);
  margin-bottom: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tab 信息网格 */
.tab-card-info {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  margin-bottom: 0.75rem;
}

.tab-card-info-item {
  background: rgba(255, 255, 255, 0.05);
  padding: 0.375rem 0.5rem;
  border-radius: 0.375rem;
}

/* Tab 操作按钮容器 */
.tab-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* Tab 卡片操作按钮 - 使用更具体的选择器覆盖 tabs.css 中的样式 */
.tab-card-actions .tab-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 1.75rem;
  min-width: fit-content;
  font-size: 0.75rem;
  padding: 0 0.75rem;
  border-radius: 0.25rem;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition-fast, 150ms);
  font-weight: 500;
  outline: none;
  white-space: nowrap;
  line-height: 1;
  text-align: center;
  vertical-align: middle;
  box-sizing: border-box;
}

.tab-card-actions .tab-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.tab-card-actions .tab-action-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.tab-card-actions .tab-action-btn:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.98);
}

.tab-card-actions .tab-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* 危险按钮（关闭） */
.tab-card-actions .tab-action-btn.danger {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  margin-left: auto;
}

.tab-card-actions .tab-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

.tab-card-actions .tab-action-btn.danger:focus-visible {
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.4);
}

.tab-card-actions .tab-action-btn.danger:active {
  background: rgba(239, 68, 68, 0.4);
}

/* ===== 空状态 ===== */
.browser-empty-state {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted-foreground);
  z-index: 1;
  padding: 2rem;
}

.browser-empty-state[style*="display: none"] {
  display: none !important;
}

.browser-empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.browser-empty-state .empty-icon svg {
  width: 3rem;
  height: 3rem;
  stroke: currentColor;
  stroke-width: 1.5;
  fill: none;
  opacity: 0.6;
}

.browser-empty-state p {
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
}

.browser-empty-state .empty-hint {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  max-width: 280px;
}

/* ===== 加载状态 ===== */
.browser-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6); /* 半透明背景，让 Three.js 动画透出 */
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2;
}

/* ===== 响应式设计 ===== */
@media (max-width: 768px) {
  .browser-split-container {
    flex-direction: column-reverse;
  }
  
  .browser-menu-pane {
    flex: 0 0 auto;
    max-width: none;
    min-width: 0;
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }
  
  .browser-menu-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
    overflow-x: auto;
    overflow-y: hidden;
  }
  
  .browser-menu-item {
    flex: 0 0 auto;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0;
  }
  
  .browser-menu-item .menu-label {
    display: none;
  }
  
  .browser-resizer {
    display: none;
  }
  
  .browser-display-pane {
    min-width: 0;
  }
  
  .tabs-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1200px) {
  .tabs-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  }
}

/* ===== 浅色主题样式 - 颜色反转 ===== */

/* 右侧菜单栏 - 浅色主题 */
body:not(.dark) .browser-menu-pane {
  background: rgba(0, 0, 0, 0.03);
}

/* 菜单操作按钮 - 浅色主题 */
body:not(.dark) .browser-menu-action:hover {
  background: rgba(0, 0, 0, 0.1);
}

body:not(.dark) .browser-menu-action:active {
  background: rgba(0, 0, 0, 0.15);
}

/* 菜单项 - 浅色主题 */
body:not(.dark) .browser-menu-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

body:not(.dark) .browser-menu-item .menu-badge {
  background: rgba(0, 0, 0, 0.1);
}

/* 左侧展示区 - 浅色主题 */
body:not(.dark) .browser-display-pane {
  background: #f8f8f8;
}

/* Three.js 动态背景容器 - 浅色主题 */
body:not(.dark) .browser-threejs-bg {
  background: #f0f0f0;
}

/* 毛玻璃卡片 - 浅色主题 */
body:not(.dark) .glass-card {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

body:not(.dark) .glass-card:hover {
  background: rgba(0, 0, 0, 0.06);
  border-color: rgba(0, 0, 0, 0.15);
}

/* Tab 卡片图标 - 浅色主题 */
body:not(.dark) .tab-card-icon img {
  background: rgba(0, 0, 0, 0.1);
}

/* Tab 信息网格 - 浅色主题 */
body:not(.dark) .tab-card-info-item {
  background: rgba(0, 0, 0, 0.05);
}

/* Tab 操作按钮容器边框 - 浅色主题 */
body:not(.dark) .tab-card-actions {
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Tab 卡片操作按钮 - 浅色主题 */
body:not(.dark) .tab-card-actions .tab-action-btn {
  background: rgba(0, 0, 0, 0.1);
  color: var(--foreground);
}

body:not(.dark) .tab-card-actions .tab-action-btn:hover {
  background: rgba(0, 0, 0, 0.2);
}

body:not(.dark) .tab-card-actions .tab-action-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3);
}

body:not(.dark) .tab-card-actions .tab-action-btn:active {
  background: rgba(0, 0, 0, 0.25);
}

/* 加载状态 - 浅色主题 */
body:not(.dark) .browser-loading-overlay {
  background: rgba(255, 255, 255, 0.6);
}
