/**
 * 益泰 AI 产业助手 · Layout — 顶部栏 + 布局框架 + 侧边栏 + 主画布 + 面板 + 移动端
 */

/* ===================== 顶部栏 ===================== */
.ai-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 60px; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  background: var(--ai-surface); border-bottom: 1px solid var(--ai-border);
  backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
}

.ai-topbar-left, .ai-topbar-right { display: flex; align-items: center; gap: 14px; }

.ai-logo {
  display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700;
  color: var(--ai-text); letter-spacing: -0.01em;
}
.ai-logo svg { color: var(--ai-primary); filter: drop-shadow(0 0 8px var(--ai-primary-glow)); }

.ai-product-name { font-size: 14px; font-weight: 500; color: var(--ai-text-secondary); }

.ai-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border-radius: var(--radius-sm); color: var(--ai-text-muted); border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.ai-icon-btn:hover {
  color: var(--ai-text); background: rgba(148, 163, 184, 0.08); border-color: var(--ai-border-highlight);
}
.ai-icon-btn i { font-size: 17px; }

/* ===================== 布局框架 ===================== */
.ai-layout {
  /* 120px 预留底部输入栏空间（与 .ai-inputbar 的 bottom: 24px + 自身高度对应） */
  display: flex; height: 100vh; padding-top: 60px; padding-bottom: 120px; background: var(--ai-bg-1);
}

/* ===================== 左侧边栏 ===================== */
.ai-sidebar {
  position: fixed; top: 60px; left: 12px; bottom: 120px; width: 56px; z-index: 900;
  display: flex; flex-direction: column;
  background: var(--ai-surface); border: 1px solid var(--ai-border); border-radius: var(--radius-lg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 10px 6px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1); overflow: hidden; box-shadow: var(--ai-shadow);
}
.ai-sidebar:hover { width: 176px; background: var(--ai-surface-elevated); }

.ai-nav, .ai-sidebar-footer {
  display: flex; flex-direction: column; gap: 4px; margin-top: auto; padding-top: 8px;
  border-top: 1px solid var(--ai-border);
}

.ai-sidebar-divider { width: 28px; height: 1px; background: var(--ai-divider); margin: 10px auto; border-radius: 1px; }
.ai-sidebar-section { padding: 4px 8px; }

/* 对话历史区 — 可滚动，不挤压底部导航 */
.ai-sidebar-chat-section {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 4px 8px;
  scrollbar-width: none; /* 收起时隐藏滚动条 */
}
.ai-sidebar-chat-section::-webkit-scrollbar { width: 0; }
.ai-sidebar:hover .ai-sidebar-chat-section {
  scrollbar-width: thin;
  scrollbar-color: var(--ai-border-highlight) transparent;
}
.ai-sidebar:hover .ai-sidebar-chat-section::-webkit-scrollbar { width: 4px; }
.ai-sidebar:hover .ai-sidebar-chat-section::-webkit-scrollbar-thumb {
  background: var(--ai-border-highlight); border-radius: 2px;
}
.ai-sidebar:hover .ai-sidebar-chat-section::-webkit-scrollbar-track { background: transparent; }

.ai-sidebar-section-title {
  display: flex; align-items: center; justify-content: space-between; font-size: 11px;
  color: var(--ai-muted); padding: 4px 0; margin-bottom: 4px; font-weight: 500; letter-spacing: 0.02em;
}
.ai-sidebar-action {
  background: none; border: none; color: var(--ai-muted); cursor: pointer; padding: 2px;
  border-radius: 4px; transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.ai-sidebar-action:hover { color: var(--ai-text); background: var(--ai-surface); }

.ai-chat-history { list-style: none; padding: 0; margin: 0; }
.ai-chat-history li { margin-bottom: 2px; }
.ai-chat-history .ai-chat-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; transition: all 0.2s; position: relative;
}
.ai-chat-history .ai-chat-item:hover { background: var(--ai-surface); }
.ai-chat-history .ai-chat-item.active { background: var(--ai-card); border: 1px solid var(--ai-border-highlight); }
.ai-chat-history .ai-chat-item i { font-size: 14px; color: var(--ai-muted); flex-shrink: 0; }
.ai-chat-history .ai-chat-item span {
  flex: 1; font-size: 13px; color: var(--ai-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-chat-history .ai-chat-item .ai-chat-actions {
  display: none; gap: 4px; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: var(--ai-surface); border-radius: 6px; padding: 2px; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.ai-chat-history .ai-chat-item:hover .ai-chat-actions { display: flex; }
.ai-chat-history .ai-chat-actions button {
  background: none; border: none; color: var(--ai-muted); cursor: pointer; padding: 4px;
  border-radius: 4px; transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.ai-chat-history .ai-chat-actions button:hover { color: var(--ai-text); background: var(--ai-card); }

.ai-nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 40px; padding: 0 10px;
  border-radius: var(--radius-sm); color: var(--ai-text-muted); white-space: nowrap;
  transition: all 0.2s ease; position: relative;
}
.ai-nav-item i { flex-shrink: 0; font-size: 18px; width: 22px; text-align: center; }
.ai-nav-item span { font-size: 13px; font-weight: 500; opacity: 0; transform: translateX(-6px); transition: all 0.25s ease; }
.ai-sidebar:hover .ai-nav-item span { opacity: 1; transform: translateX(0); }
.ai-nav-item:hover { color: var(--ai-text); background: rgba(148, 163, 184, 0.08); }
.ai-nav-item.active { color: var(--ai-primary); background: var(--ai-primary-soft); }
.ai-nav-item.active::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--ai-primary);
  box-shadow: 0 0 10px var(--ai-primary-glow);
}

.ai-nav-data { padding-top: 2px; }

/* ===================== 用户系统 ===================== */
.ai-user {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 8px;
  cursor: pointer; transition: all 0.2s; font-size: 13px;
}
.ai-user:hover { background: var(--ai-surface); }

.ai-avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-primary-dark));
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: white;
}
.ai-avatar-lg {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-primary-dark));
  display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 600; color: white; margin: 0 auto;
}
.ai-user-profile { text-align: center; padding: 16px; }

.ai-divider { height: 1px; background: var(--ai-border); margin: 0; }

/* 抽屉面板 */
.ai-drawer-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px); z-index: 1999; display: flex; align-items: flex-end; justify-content: flex-end;
}
.ai-drawer {
  position: fixed; top: 60px; right: 0; bottom: 0; width: 320px; background: var(--ai-surface);
  border-left: 1px solid var(--ai-border); box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  display: flex; flex-direction: column; z-index: 2000; transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.ai-drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--ai-border); }
.ai-drawer-body { flex: 1; overflow-y: auto; padding: 8px 0; }
.ai-drawer-menu { display: flex; flex-direction: column; }
.ai-drawer-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; color: var(--ai-text);
  text-decoration: none; font-size: 14px; transition: background 0.2s; cursor: pointer;
}
.ai-drawer-item:hover { background: var(--ai-card); }
.ai-drawer-item i:first-child { font-size: 16px; color: var(--ai-muted); width: 20px; text-align: center; }
.ai-drawer-item i:last-child { margin-left: auto; font-size: 12px; }

#userMenuToggle i:last-child { font-size: 10px; transition: transform 0.2s; }
#userMenuToggle.active i:last-child { transform: rotate(180deg); }

/* ===================== 主画布 ===================== */
.ai-main {
  flex: 1; min-height: 0; margin-left: 80px; margin-right: 380px; overflow-y: auto; overflow-x: hidden;
  position: relative; background: var(--ai-bg-1); padding-bottom: 20px;
}
.ai-main::before {
  content: ""; position: fixed; top: 60px; left: 80px; right: 380px; bottom: 120px;
  background: radial-gradient(ellipse 60% 40% at 50% 20%, rgba(43, 127, 255, 0.04), transparent);
  pointer-events: none; z-index: 0;
}
.ai-module-root { position: relative; z-index: 1; min-height: 100%; padding: 28px 36px 36px; }

/* ===================== 右侧面板 ===================== */
.ai-panel {
  position: fixed; top: 72px; right: 12px; bottom: 120px; width: 356px; z-index: 800;
  display: flex; flex-direction: column; background: var(--ai-surface); border: 1px solid var(--ai-border);
  border-radius: var(--radius-lg); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--ai-shadow); overflow: hidden;
}
.ai-panel-header {
  display: flex; align-items: center; height: 52px; padding: 0 18px; border-bottom: 1px solid var(--ai-border);
  font-size: 14px; font-weight: 600; color: var(--ai-text);
}
.ai-panel-body { flex: 1; overflow-y: auto; padding: 16px 18px; }

/* ===================== 历史记录面板 ===================== */
.ai-history-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 1500; display: none;
}
.ai-history-overlay.open { display: block; }

.ai-history-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 300px; z-index: 1501;
  background: var(--ai-surface); border-right: 1px solid var(--ai-border);
  transform: translateX(-100%); transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex; flex-direction: column; box-shadow: 4px 0 24px rgba(0,0,0,0.3);
}
.ai-history-drawer.open { transform: translateX(0); }

.ai-history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--ai-border);
  flex-shrink: 0;
}
.ai-history-header h3 {
  font-size: 16px; font-weight: 700; color: var(--ai-text); margin: 0;
}
.ai-history-close {
  background: none; border: none; color: var(--ai-text-muted);
  font-size: 18px; cursor: pointer; padding: 4px; border-radius: 6px;
  transition: all 0.2s;
}
.ai-history-close:hover { color: var(--ai-text); background: var(--ai-bg-1); }

.ai-history-search {
  padding: 12px 16px; border-bottom: 1px solid var(--ai-border); flex-shrink: 0;
}
.ai-history-search-input {
  width: 100%; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--ai-border);
  background: var(--ai-bg-1); color: var(--ai-text); font-size: 13px; outline: none;
  transition: border-color 0.2s;
}
.ai-history-search-input:focus { border-color: var(--ai-primary); }
.ai-history-search-input::placeholder { color: var(--ai-text-muted); }

.ai-history-list {
  flex: 1; overflow-y: auto; padding: 8px 12px;
}
.ai-history-list::-webkit-scrollbar { width: 4px; }
.ai-history-list::-webkit-scrollbar-thumb { background: var(--ai-border-highlight); border-radius: 2px; }

.ai-history-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; cursor: pointer; transition: all 0.15s; margin-bottom: 2px;
}
.ai-history-item:hover { background: var(--ai-bg-1); }
.ai-history-item.active { background: var(--ai-primary-soft); border: 1px solid rgba(43,127,255,0.2); }
.ai-history-item i { font-size: 15px; color: var(--ai-text-muted); flex-shrink: 0; }
.ai-history-item-title {
  flex: 1; font-size: 13px; color: var(--ai-text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ai-history-item-time {
  font-size: 11px; color: var(--ai-text-muted); flex-shrink: 0;
}
.ai-history-delete {
  opacity: 0; background: none; border: none; color: var(--ai-text-muted);
  cursor: pointer; padding: 2px 4px; border-radius: 4px; font-size: 12px;
  transition: all 0.15s; flex-shrink: 0;
}
.ai-history-item:hover .ai-history-delete { opacity: 1; }
.ai-history-delete:hover { color: #F87171; background: rgba(248,113,113,0.1); }

.ai-history-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px; text-align: center;
}
.ai-history-empty i { font-size: 40px; color: var(--ai-text-muted); margin-bottom: 12px; opacity: 0.4; }
.ai-history-empty p { font-size: 13px; color: var(--ai-text-muted); margin: 0 0 16px 0; }
.ai-history-empty .ai-new-chat-btn {
  padding: 8px 20px; border-radius: 8px; border: 1px solid var(--ai-border);
  background: transparent; color: var(--ai-text-secondary); font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.ai-history-empty .ai-new-chat-btn:hover {
  border-color: var(--ai-primary); color: var(--ai-primary);
  background: var(--ai-primary-soft);
}

.ai-history-footer {
  padding: 12px 16px; border-top: 1px solid var(--ai-border); flex-shrink: 0;
}
.ai-history-new-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px; border-radius: 10px; border: 1px dashed var(--ai-border);
  background: transparent; color: var(--ai-text-secondary); font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.ai-history-new-btn:hover {
  border-color: var(--ai-primary); color: var(--ai-primary);
  background: var(--ai-primary-soft);
}

/* 顶部栏历史入口按钮 */
.ai-history-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--ai-border);
  background: transparent; color: var(--ai-text-secondary);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.ai-history-toggle:hover {
  border-color: var(--ai-border-highlight); color: var(--ai-text);
  background: var(--ai-bg-1);
}
.ai-history-toggle i { font-size: 16px; }

/* API 状态指示器 */
.ai-api-status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 16px; border: 1px solid var(--ai-border);
  background: transparent; cursor: pointer; transition: all 0.2s;
  font-size: 12px; color: var(--ai-text-secondary);
}
.ai-api-status:hover {
  border-color: var(--ai-border-highlight); background: var(--ai-bg-1);
}
.ai-api-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--ai-text-muted); transition: background 0.3s;
}
.ai-api-dot.connected { background: #10B981; box-shadow: 0 0 6px rgba(16,185,129,0.5); }
.ai-api-dot.connecting { background: #FBBF24; animation: ai-pulse 1s ease-in-out infinite; }
.ai-api-dot.error { background: #F87171; }
@keyframes ai-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

@media (max-width: 768px) {
  .ai-history-drawer { width: 280px; }
}

/* ===================== 移动端导航 ===================== */
/* AI 助手移动端导航 — 与标准页 nav-mobile-* class 隔离（同名异义，仅 CSS 注释，不修改选择器以避免破坏 JS 逻辑） */
/* 1. 抽屉结构样式（仅位置/尺寸/过渡，不设 display） */
.nav-mobile-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 2000;
}
.nav-mobile-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 280px; z-index: 2100;
  background: var(--ai-surface); transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16,1,0.3,1);
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.nav-mobile-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--ai-border);
}
.nav-mobile-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 700; color: var(--ai-text);
}
.nav-mobile-close {
  background: none; border: none; color: var(--ai-text-muted); cursor: pointer;
  font-size: 20px; padding: 4px;
}
.nav-mobile-content {
  flex: 1; overflow-y: auto; padding: 12px 0;
}
.nav-mobile-content .nav-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  color: var(--ai-text); text-decoration: none; font-size: 14px;
  transition: background 0.2s;
}
.nav-mobile-content .nav-link:hover { background: var(--ai-card); }
.nav-mobile-content .nav-link i { font-size: 16px; color: var(--ai-text-muted); width: 20px; text-align: center; }

/* 2. 桌面端默认隐藏 */
.nav-hamburger,
.nav-mobile-drawer,
.nav-mobile-overlay,
.mobile-tab-bar { display: none; }

/* 3. 抽屉打开状态（更高优先级覆盖 display:none） */
.nav-mobile-overlay.open { display: block; }
.nav-mobile-drawer.open { display: flex; flex-direction: column; transform: translateX(0); }

/* ===================== 响应式 ===================== */
@media (max-width: 1279px) {
  .ai-panel { display: none; }
  .ai-main { margin-right: 20px; }
  .ai-inputbar { width: min(900px, calc(100% - 120px)); }
}

@media (max-width: 768px) {
  /* 移动端：显示汉堡菜单按钮（点击打开右侧抽屉） */
  .nav-hamburger { display: flex !important; }
  /* 移动端底部 Tab 栏 AI 页面不需要 */
  .mobile-tab-bar { display: none !important; }
  body.ai-app { overflow: auto !important; }
  html { overflow-x: clip !important; }
  .ai-topbar { padding: 0 14px; }
  .ai-product-name, .ai-divider, .ai-user span { display: none; }
  .ai-sidebar { display: none; }
  .ai-layout { padding-bottom: 16px; }
  .ai-main { margin-left: 0; margin-right: 0; padding-bottom: 80px; }
  .ai-inputbar { left: 8px; right: 8px; transform: none; width: auto; bottom: 16px; }
  .ai-inputbar-inner { padding: 8px 10px; }
  .ai-welcome-title { font-size: 28px; }
  .ai-message-inner { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
