:root {
  --primary: #1677ff;
  --primary-light: #e6f4ff;
  --red: #ff4d4f;
  --red-light: #fff1f0;
  --red-dark: #cf1322;
  --text-primary: #1f1f1f;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e8e8e8;
  --bg-page: #f0f4f8;
  --bg-card: #fff;
  --sidebar-width: 200px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* ===== 顶部工具栏 ===== */
.top-toolbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  height: 32px;
}

.toolbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}

.toolbar-link {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
}

.toolbar-link:hover {
  color: var(--primary);
}

/* ===== 页头 Banner ===== */
.portal-header {
  background: linear-gradient(135deg, #e8f0fe 0%, #f5f8fc 40%, #fff 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.portal-header::before {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  width: 60%;
  height: 100%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 200'%3E%3Cpath d='M600 0 L800 0 L800 200 L500 200 Z' fill='%23f0f5ff' opacity='0.6'/%3E%3Cpath d='M650 50 L750 30 L780 120 L680 150 Z' fill='%23e6f0ff' opacity='0.4'/%3E%3C/svg%3E") no-repeat right center;
  background-size: cover;
  pointer-events: none;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: relative;
  z-index: 1;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logo-cn {
  font-size: 16px;
  font-weight: 700;
  color: #e60012;
  display: block;
}

.logo-en {
  font-size: 10px;
  color: var(--text-muted);
}

.header-title {
  flex: 1;
  text-align: center;
}

.header-title h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 2px;
}

.header-title p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.header-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 16px 4px 8px;
  width: 240px;
  flex-shrink: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.header-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12);
}

.header-search-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.2s;
}

.header-search-btn:hover {
  background: var(--primary-light);
}

.header-search-btn:hover svg {
  stroke: var(--primary);
}

.header-search input {
  border: none;
  outline: none;
  font-size: 13px;
  width: 100%;
  font-family: inherit;
  background: transparent;
}

/* ===== 主体布局 ===== */
.portal-body {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 0;
  padding: 0 16px 24px;
}

/* ===== 左侧导航 ===== */
.portal-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-top: 12px;
  padding: 16px 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
}

.user-card {
  text-align: center;
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border);
}

.user-avatar {
  margin-bottom: 8px;
}

.user-greeting {
  font-size: 13px;
  color: var(--text-secondary);
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  border-radius: 0;
}

.nav-icon {
  font-size: 14px;
  width: 20px;
  text-align: center;
}

.sidebar-qr {
  padding: 12px 16px;
  text-align: center;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.qr-placeholder {
  width: 80px;
  height: 80px;
  background: #f5f5f5;
  border: 1px dashed var(--border);
  border-radius: 4px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

/* ===== 主内容区 ===== */
.portal-main {
  flex: 1;
  min-width: 0;
  padding: 12px 0 0 12px;
}

/* ===== ★ AI 数字人输入框（红框位置） ===== */
.ai-input-section {
  margin-bottom: 12px;
  animation: fadeInDown 0.4s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-input-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 77, 79, 0.25);
  border-radius: 12px;
  padding: 10px 16px;
  box-shadow: 0 4px 16px rgba(255, 77, 79, 0.1), 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-input-bar:focus-within {
  border-color: var(--red);
  box-shadow: 0 4px 20px rgba(255, 77, 79, 0.18), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.ai-avatar-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.ai-avatar-badge:hover {
  transform: scale(1.06);
  filter: drop-shadow(0 4px 10px rgba(255, 77, 79, 0.35));
}

.ai-avatar-badge:active {
  transform: scale(0.97);
}

.ai-avatar-badge:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.ai-avatar-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
}

.ai-logo-img {
  display: block;
  object-fit: contain;
}

.ai-avatar-icon .ai-logo-img {
  height: 56px;
  width: auto;
}

.ai-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  white-space: nowrap;
}

.ai-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8f9fb;
  border-radius: 24px;
  padding: 4px 4px 4px 16px;
  border: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.ai-input-bar:focus-within .ai-input-wrapper {
  background: #fff;
  border-color: rgba(255, 77, 79, 0.3);
}

.ai-input-field {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  min-width: 0;
}

.ai-input-field::placeholder {
  color: var(--text-muted);
}

.ai-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}

.ai-send-btn:hover {
  background: var(--red-dark);
  transform: scale(1.05);
}

.ai-full-link {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-decoration: none;
  flex-shrink: 0;
  transition: all 0.2s;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.ai-full-link:hover,
.ai-history-link:hover,
.ai-history-link.active {
  background: var(--red-light);
  color: var(--red);
}

.ai-quick-queries {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  padding-left: 56px;
}

.quick-query {
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.quick-query:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-light);
}

/* ===== 内容 Tab ===== */
.content-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 2px solid var(--primary);
  overflow-x: auto;
}

.tab {
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--primary);
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* ===== 内容网格 ===== */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
  margin-top: 12px;
}

.app-grid-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 16px 12px;
}

.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 4px;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.app-item:hover {
  background: var(--primary-light);
  color: var(--primary);
  transform: translateY(-2px);
}

.app-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

/* ===== 右侧组件 ===== */
.right-widgets {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.widget-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.widget-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin: -16px -16px 12px;
  padding: 0 16px;
}

.widget-tab {
  padding: 10px 12px;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.widget-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.widget-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.notice-list {
  list-style: none;
}

.notice-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px dashed var(--border);
}

.notice-list li:last-child {
  border-bottom: none;
}

.notice-title {
  color: var(--text-primary);
}

.notice-date {
  color: var(--text-muted);
  font-size: 12px;
}

.quick-nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quick-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f8f9fb;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 12px;
  transition: all 0.2s;
}

.quick-nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.qn-icon {
  font-size: 16px;
}

/* ===== 底部区域 ===== */
.bottom-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
  margin-top: 12px;
}

.empty-hint {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px 0;
}

/* ===== AI 对话面板 ===== */
.ai-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 420px;
  height: min(780px, calc(100vh - 48px));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: row;
  z-index: 200;
  overflow: hidden;
  animation: slideUp 0.3s ease;
  border: 1px solid var(--border);
  transition: width 0.25s ease, height 0.25s ease;
}

.ai-chat-panel.with-history {
  width: min(680px, calc(100vw - 48px));
}

.ai-chat-panel.with-third {
  width: min(1000px, calc(100vw - 48px));
  height: min(840px, calc(100vh - 48px));
}

.ai-chat-panel.with-third.with-history {
  width: min(1180px, calc(100vw - 48px));
}

.chat-panel-main {
  display: flex;
  flex-direction: row;
  width: 420px;
  flex-shrink: 0;
  min-width: 0;
  height: 100%;
}

.ai-chat-panel.with-history .chat-panel-main {
  width: 680px;
}

.chat-panel-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
}

.chat-history-drawer {
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: #fafafa;
  border-right: 1px solid transparent;
  display: flex;
  flex-direction: column;
  transition: width 0.25s ease, border-color 0.25s ease;
}

.ai-chat-panel.with-history .chat-history-drawer {
  width: 260px;
  border-right-color: var(--border);
}

.chat-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-history-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-history-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
}

.chat-history-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.chat-history-new {
  margin: 10px 12px 8px;
  padding: 8px 12px;
  border: 1px dashed rgba(255, 77, 79, 0.35);
  border-radius: 8px;
  background: #fff;
  color: var(--red);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.chat-history-new:hover {
  background: var(--red-light);
  border-color: var(--red);
}

.chat-history-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 8px 12px;
}

.chat-history-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 10px 10px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
  margin-bottom: 4px;
}

.chat-history-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.chat-history-item.active {
  background: var(--red-light);
}

.chat-history-item-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.chat-history-item-time {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.ai-chat-panel.with-third .third-panel {
  width: calc(100% - 420px);
  flex: 1;
  display: flex;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--red-light) 0%, #fff 100%);
  border-bottom: 1px solid var(--border);
}

.chat-panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-panel-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chat-panel-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(255, 77, 79, 0.2);
}

.chat-panel-avatar .ai-logo-img {
  height: 40px;
  width: auto;
}

.chat-panel-title h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-panel-title p {
  font-size: 11px;
  color: #52c41a;
}

.chat-panel-actions {
  display: flex;
  gap: 4px;
}

.chat-expand-btn,
.chat-close-btn,
.chat-history-link {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.2s;
}

.chat-expand-btn:hover,
.chat-close-btn:hover,
.chat-history-link:hover,
.chat-history-link.active {
  background: rgba(0, 0, 0, 0.05);
  color: var(--primary);
}

.chat-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 90%;
}

.chat-msg > div:not(.chat-msg-avatar) {
  flex: 1;
  min-width: 0;
}

.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
}

.chat-msg.assistant .chat-msg-avatar {
  background: transparent;
  padding: 0;
  overflow: hidden;
}

.chat-msg.assistant .chat-msg-avatar .ai-logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.chat-msg.user .chat-msg-avatar {
  background: var(--primary-light);
  color: var(--primary);
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
}

.chat-msg.assistant .chat-msg-bubble {
  background: #f5f5f5;
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

.chat-msg.user .chat-msg-bubble {
  background: var(--red);
  color: #fff;
  border-top-right-radius: 4px;
}

.chat-msg-bubble.typing::after {
  content: "...";
  animation: typing 1.2s infinite;
}

@keyframes typing {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.chat-welcome-msg {
  text-align: center;
  padding: 20px 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

.chat-welcome-msg strong {
  color: var(--red);
  display: block;
  font-size: 15px;
  margin-bottom: 6px;
}

.chat-panel-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}

.chat-panel-input input {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.chat-panel-input input:focus {
  border-color: var(--red);
}

.chat-panel-input button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-panel-input button:hover {
  background: var(--red-dark);
}

/* ===== 响应式 ===== */
@media (max-width: 1200px) {
  .app-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 960px) {
  .portal-body {
    flex-direction: column;
  }

  .portal-sidebar {
    width: 100%;
    max-height: none;
  }

  .content-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }

  .ai-quick-queries {
    padding-left: 0;
  }

  .ai-label {
    display: none;
  }

  .ai-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    height: calc(100vh - 24px);
    top: 12px;
    bottom: 12px;
  }

  .ai-chat-panel.with-third {
    width: auto;
    height: calc(100vh - 24px);
    flex-direction: column;
  }

  .ai-chat-panel.with-third .chat-panel-main {
    width: 100%;
    height: 45%;
  }

  .ai-chat-panel.with-third .third-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .ai-chat-panel.with-history .chat-panel-main {
    width: 100%;
  }

  .ai-chat-panel.with-history .chat-history-drawer {
    width: 220px;
  }
}
