/**
 * Responsive Layout - 响应式布局
 * 断点：900px
 * - >= 900px: 完整模式（左侧导航 + 对话栏 + 展示栏）
 * - < 900px: 紧凑模式（底部导航 + 全屏面板切换）
 * 最小宽度：480px
 */

/* ===== 紧凑模式 (< 900px) ===== */
@media (max-width: 899px) {
  /* 主容器改为垂直布局 */
  #main-container {
    flex-direction: column;
    position: relative;
  }
  
  /* 侧边栏变为底部固定导航 - 深色玻璃态风格 */
  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-width: 100%;
    height: var(--bottom-nav-height, 64px);
    min-height: var(--bottom-nav-height, 64px);
    flex-direction: row;
    align-items: center;
    justify-content: space-evenly;
    padding: 0.375rem 1rem;
    padding-bottom: calc(0.375rem + env(safe-area-inset-bottom, 0px));
    border-right: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none;
    z-index: 100;
    /* 深色玻璃态效果 */
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  
  /* 让 nav-section 不影响布局，使按钮直接在 sidebar 中均匀分布 */
  #sidebar .nav-section {
    display: contents;
  }
  
  /* 隐藏导航分隔符 */
  #sidebar .nav-spacer {
    display: none;
  }
  
  /* 导航按钮 - 等宽分布，深色主题风格 */
  #sidebar .nav-btn {
    flex: 1;
    max-width: 6rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.5rem;
    gap: 0.25rem;
    min-height: 48px;
    border-radius: var(--radius);
    /* 深色主题下的默认颜色 */
    color: rgba(255, 255, 255, 0.6);
    /* 微交互动画 */
    transition: 
      background var(--duration-fast, 150ms) var(--ease-smooth),
      color var(--duration-fast, 150ms) var(--ease-smooth),
      transform 0.1s ease;
  }
  
  #sidebar .nav-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
  }
  
  #sidebar .nav-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
  }
  
  /* 点击缩放效果 */
  #sidebar .nav-btn:active {
    transform: scale(0.92);
  }
  
  /* 显示导航标签 */
  #sidebar .nav-label {
    display: block;
    font-size: 0.625rem;
    font-weight: 500;
  }
  
  /* 图标尺寸 */
  #sidebar .nav-icon {
    width: 1.5rem;
    height: 1.5rem;
  }
  
  #sidebar .nav-icon svg {
    width: 1.5rem;
    height: 1.5rem;
  }
  
  /* 激活状态图标高亮 */
  #sidebar .nav-btn.active .nav-icon {
    color: var(--primary);
  }
  
  /* 激活状态指示器 - 底部短横条 */
  #sidebar .nav-btn.active::before {
    left: 50%;
    top: auto;
    bottom: 4px;
    transform: translateX(-50%);
    width: 1.5rem;
    height: 2px;
    border-radius: 1px;
    background: var(--primary);
  }
  
  @keyframes slideIndicatorIn {
    from {
      transform: translateX(-50%) scaleX(0);
      opacity: 0;
    }
    to {
      transform: translateX(-50%) scaleX(1);
      opacity: 1;
    }
  }
  
  /* ===== 移动版面板状态控制 ===== */
  /* 对话面板和展示面板互斥显示 */
  
  #chat-panel {
    width: 100%;
    min-width: 0;
    flex: 1;
    border-right: none;
    padding-bottom: var(--bottom-nav-height, 64px);
    /* 默认显示 */
    display: flex;
  }
  
  #display-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: var(--bottom-nav-height, 64px);
    width: 100%;
    /* 默认隐藏 */
    display: none;
    z-index: 50;
  }
  
  /* 移动版面板可见状态 */
  #chat-panel.mobile-panel-hidden {
    display: none !important;
  }
  
  #display-panel.mobile-panel-visible {
    display: flex !important;
  }
  
  /* 移动版面板顶部导航栏（桌面版隐藏） */
  .display-panel-header {
    display: flex !important;
  }
  
  /* 徽标样式（预留功能） */
  #sidebar .nav-btn .badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 16px);
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    background: var(--destructive);
    color: white;
    font-size: 9px;
    font-weight: 600;
    line-height: 14px;
    text-align: center;
    border-radius: 7px;
    display: none; /* 默认隐藏，JS 控制显示 */
  }
  
  #sidebar .nav-btn .badge.show {
    display: block;
  }
  
  
  /* ===== 移动版面板内容区调整 ===== */
  
  /* 文件面板 - 移动版下隐藏文件列表侧边栏 */
  #files-split-container {
    flex-direction: column;
  }
  
  #files-list-pane {
    display: none;
  }
  
  #file-preview-pane {
    width: 100%;
  }
  
  #files-resizer {
    display: none;
  }
  
  /* 浏览器面板 - 移动版下隐藏菜单侧边栏 */
  #browser-split-container {
    flex-direction: column;
  }
  
  #browser-menu-pane {
    display: none;
  }
  
  #browser-display-pane {
    width: 100%;
  }
  
  #browser-resizer {
    display: none;
  }
  
  /* 浏览器面板 - 移动版标签卡片样式 */
  /* 保持双列时的卡片宽度，单列居中显示 */
  .tabs-grid {
    grid-template-columns: 1fr !important;
    justify-items: center;
    padding: 1rem;
  }
  
  .tabs-grid .glass-card {
    width: 100%;
    max-width: 340px;
  }
  
  /* 设置面板 - 移动版下隐藏导航侧边栏 */
  .settings-split-layout {
    flex-direction: column;
  }
  
  .settings-nav {
    display: none;
  }
  
  .settings-content {
    width: 100%;
  }
}

/* ===== 浅色主题适配 ===== */
@media (max-width: 899px) {
  body:not(.dark) #sidebar {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top-color: var(--border);
  }
  
  body:not(.dark) #sidebar .nav-btn {
    color: var(--muted-foreground);
  }
  
  body:not(.dark) #sidebar .nav-btn:hover {
    background: var(--glass-bg-hover);
    color: var(--foreground);
  }
  
  body:not(.dark) #sidebar .nav-btn.active {
    background: var(--glass-bg-hover);
    color: var(--foreground);
  }
  
  body:not(.dark) #sidebar .nav-btn.active .nav-icon {
    color: var(--primary);
  }
  
  body:not(.dark) #sidebar .nav-btn.active::before {
    background: var(--primary);
  }
  
  /* 浅色主题 - 展示面板顶部导航栏 */
  body:not(.dark) .display-panel-header {
    background: rgba(255, 255, 255, 0.8);
    border-bottom-color: var(--border);
  }
  
  body:not(.dark) .display-header-btn {
    color: var(--muted-foreground);
  }
  
  body:not(.dark) .display-header-btn:hover {
    background: var(--glass-bg-hover);
    color: var(--foreground);
  }
  
  /* 浅色主题 - 抽屉 */
  body:not(.dark) .mobile-drawer {
    background: rgba(255, 255, 255, 0.98);
  }
  
  body:not(.dark) .mobile-drawer-header {
    border-bottom-color: var(--border);
  }
  
  body:not(.dark) .mobile-drawer-header h3 {
    color: var(--foreground);
  }
  
  body:not(.dark) .mobile-drawer-close {
    color: var(--muted-foreground);
  }
  
  body:not(.dark) .mobile-drawer-close:hover {
    background: var(--glass-bg-hover);
    color: var(--foreground);
  }
}

/* ===== 移动版抽屉样式（全局） ===== */
/* 抽屉元素由 JS 动态创建，默认隐藏 */

/* 抽屉遮罩层 - 默认隐藏 */
.mobile-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.mobile-drawer-overlay.visible {
  opacity: 1;
  visibility: visible;
}

/* 抽屉容器 - 默认移出屏幕 */
.mobile-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 85%;
  max-width: 320px;
  background: var(--glass-bg, rgba(23, 23, 23, 0.98));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 210;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* 右侧抽屉（默认） */
.mobile-drawer.drawer-right {
  right: 0;
  border-left: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  transform: translateX(100%);
}

.mobile-drawer.drawer-right.open {
  transform: translateX(0);
}

/* 左侧抽屉（设置面板） */
.mobile-drawer.drawer-left {
  left: 0;
  border-right: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  transform: translateX(-100%);
}

.mobile-drawer.drawer-left.open {
  transform: translateX(0);
}

/* 抽屉头部 */
.mobile-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.mobile-drawer-header h3,
.mobile-drawer-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--foreground);
  margin: 0;
}

.mobile-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius, 6px);
  background: transparent;
  color: var(--muted-foreground);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mobile-drawer-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--foreground);
}

/* 抽屉内容区 */
.mobile-drawer-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

/* 移动端抽屉适配底部导航栏 */
@media (max-width: 899px) {
  .mobile-drawer-overlay {
    bottom: var(--bottom-nav-height, 64px);
  }
  
  .mobile-drawer {
    bottom: var(--bottom-nav-height, 64px);
  }
}

/* 抽屉内克隆内容的强制显示样式 */
.mobile-drawer-cloned-content {
  display: flex !important;
  flex-direction: column !important;
}

/* 抽屉内设置面板导航项样式 */
.mobile-drawer-content .settings-nav-item {
  display: flex !important;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted-foreground);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-fast, 150ms) ease;
  margin-bottom: 0.25rem;
  /* 保持自然高度，不撑满 */
  flex: 0 0 auto !important;
  width: 100% !important;
}

/* 强制显示抽屉内设置导航项的文字（覆盖 panel.css 中 768px 媒体查询的隐藏规则） */
.mobile-drawer-content .settings-nav-item span:not(.nav-icon) {
  display: inline !important;
}

.mobile-drawer-content .settings-nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--foreground);
}

.mobile-drawer-content .settings-nav-item.active {
  background: var(--primary);
  color: var(--primary-foreground);
}

.mobile-drawer-content .settings-nav-item .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
}

.mobile-drawer-content .settings-nav-item .nav-icon svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* 抽屉内文件列表面板样式 */
.mobile-drawer-content .files-list-pane,
.mobile-drawer-content .breadcrumb {
  display: block !important;
}

.mobile-drawer-content #files-container {
  flex: 1;
  overflow-y: auto;
}

/* 抽屉内浏览器菜单样式 */
.mobile-drawer-content .browser-menu-pane {
  display: flex !important;
  flex-direction: column;
}

.mobile-drawer-content .browser-menu-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mobile-drawer-content .browser-menu-list {
  flex: 1;
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  overflow-y: auto;
  overflow-x: hidden !important;
  padding: 0.5rem;
}

/* 抽屉内浏览器菜单项样式（覆盖 768px 媒体查询） */
.mobile-drawer-content .browser-menu-item {
  display: flex !important;
  width: 100% !important;
  flex: 0 0 auto !important;
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
}

/* 强制显示抽屉内浏览器菜单项的文字 */
.mobile-drawer-content .browser-menu-item .menu-label {
  display: block !important;
}

/* ===== 浅色主题 - 全局抽屉样式 ===== */
body:not(.dark) .mobile-drawer-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

body:not(.dark) .mobile-drawer-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

body:not(.dark) .mobile-drawer-content .settings-nav-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

body:not(.dark) .mobile-drawer-content .browser-menu-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
