/* ============================================
   骨知 - 开源3D人体解剖学习平台
   全局样式 v1.0
   ============================================ */

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

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1e293b;
  --bg-hover: #334155;
  --bg-card: rgba(17, 24, 39, 0.92);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.3);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.2);
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #1e3a5f;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ========== 加载遮罩 ========== */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, #0a0e1a 0%, #0f172a 50%, #1e1b4b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  color: var(--text-primary);
}

.loading-icon {
  font-size: 64px;
  margin-bottom: 16px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.loading-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 4px;
  margin-bottom: 4px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loading-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
  letter-spacing: 1px;
}

.loading-bar-wrap {
  width: 280px;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto 12px;
}

.loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  border-radius: 2px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.loading-text {
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 18px;
}

/* ========== 顶部导航 ========== */
.topbar {
  height: 56px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  flex-shrink: 0;
}

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

.logo-icon {
  font-size: 22px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-badge {
  font-size: 10px;
  padding: 2px 6px;
  background: var(--success-glow);
  color: var(--success);
  border-radius: 4px;
  font-weight: 500;
}

/* ========== 解剖目录导航（响应式：竖屏底部 / 横屏左侧 / 桌面顶部条） ========== */
.anatomy-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.anatomy-nav::-webkit-scrollbar {
  display: none;
}

.anatomy-nav-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: clamp(11px, 2.5vw, 14px);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.anatomy-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.anatomy-nav-item.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.anatomy-nav-item .nav-count {
  font-size: 10px;
  opacity: 0.75;
  background: rgba(255, 255, 255, 0.12);
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  font-size: 13px;
  color: var(--text-muted);
}

.status-dot::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  margin-right: 6px;
  animation: blink 2s infinite;
}

.status-dot.ready::before {
  background: var(--success);
  animation: none;
}

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

/* ========== 主内容区 ========== */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  overflow: hidden;
}

/* ========== 左侧结构面板 ========== */
.sidebar-left {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-title {
  padding: 16px 16px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.search-box {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-count {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
  min-height: 14px;
}

.structure-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.loading-tip {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* 系统分组 */
.system-group {
  margin-bottom: 4px;
}

.system-group .structure-list {
  display: none;
  padding-top: 4px;
}

.system-group.expanded .structure-list {
  display: block;
}

.system-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background 0.15s;
}

.system-header:hover {
  background: var(--bg-tertiary);
}

.system-header .arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.system-group.expanded .system-header .arrow {
  transform: rotate(90deg);
}

/* 子分组 */
.subgroup {
  margin-bottom: 2px;
}

.subgroup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 12px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
}

.subgroup-list {
  padding-bottom: 4px;
}

/* 结构项 */
.structure-item {
  padding: 6px 10px 6px 28px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  transition: all 0.15s;
  line-height: 1.4;
}

.structure-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.structure-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 500;
}

.structure-item.search-hit {
  color: var(--text-primary);
  background: var(--success-glow);
}

.structure-item.search-hit.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.struct-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.struct-name-cn {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.struct-name-en {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.structure-item:hover .struct-name-en {
  opacity: 1;
}

.structure-item.active .struct-name-en {
  color: var(--accent);
  opacity: 0.8;
}

/* ========== 中间3D视图 ========== */
.viewer {
  position: relative;
  overflow: hidden;
}

#canvasContainer {
  width: 100%;
  height: 100%;
}

.viewer-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.ctrl-btn {
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  backdrop-filter: blur(10px);
  transition: all 0.2s;
  white-space: nowrap;
}

.ctrl-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--accent);
}

.ctrl-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* 信息卡片 */
.info-card {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
  z-index: 10;
  max-height: 40%;
  overflow-y: auto;
  transition: all 0.3s;
}

.info-card-header {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.info-card-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.info-title-en {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 8px;
}

.type-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.info-card-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.info-card-body p {
  margin-bottom: 8px;
}

.info-card-body h3 {
  font-size: 14px;
  margin: 12px 0 6px;
  color: var(--text-primary);
}

.info-card-body h4 {
  font-size: 13px;
  margin: 10px 0 4px;
  color: var(--text-primary);
}

.info-card-body ul {
  margin: 6px 0;
  padding-left: 20px;
}

.info-card-body li {
  margin-bottom: 4px;
}

.info-card-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

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

.wiki-link:hover {
  text-decoration: underline;
}

/* ========== 右侧AI面板 ========== */
.sidebar-right {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ai-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.ai-icon {
  font-size: 20px;
}

.ai-title {
  font-size: 14px;
  font-weight: 600;
}

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

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

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}

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

.user-msg .msg-avatar {
  background: var(--accent);
}

.msg-content {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

.ai-msg .msg-content {
  background: var(--bg-tertiary);
  border-bottom-left-radius: 4px;
}

.user-msg .msg-content {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-content p {
  margin-bottom: 6px;
}

.msg-content p:last-child {
  margin-bottom: 0;
}

.msg-content a {
  color: var(--accent);
}

.user-msg .msg-content a {
  color: white;
}

.typing {
  display: inline-block;
  animation: typing 1.4s infinite;
}

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

.ai-quick-actions {
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid var(--border);
}

.quick-btn {
  padding: 5px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s;
}

.quick-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.ai-input-box {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ai-input-box textarea {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.ai-input-box textarea:focus {
  border-color: var(--accent);
}

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

.ai-input-box button {
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
  height: 36px;
  flex-shrink: 0;
}

.ai-input-box button:hover {
  background: var(--accent-hover);
}

/* ========== 滚动条 ========== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--bg-hover);
}

/* ========== 响应式 ========== */
/* 平板 / 小桌面 */
@media (max-width: 1024px) {
  .main {
    grid-template-columns: 240px 1fr 280px;
  }
}

/* 手机竖屏：导航固定底部，主区域单列 */
@media (max-width: 768px) and (orientation: portrait) {
  body {
    flex-direction: column;
  }

  /* 导航移到底部，水平滚动 */
  .anatomy-nav {
    order: 99;
    border-bottom: none;
    border-top: 1px solid var(--border);
    padding: 6px 10px;
    gap: 5px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .anatomy-nav-item {
    padding: 6px 12px;
    font-size: 12px;
  }

  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .sidebar-left, .sidebar-right {
    display: none;
  }
}

/* 手机横屏：导航移到左侧，竖向排列 */
@media (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {
  body {
    flex-direction: row;
  }

  .topbar {
    display: none;
  }

  /* 导航移到左侧，纵向 */
  .anatomy-nav {
    order: 0;
    flex-direction: column;
    width: auto;
    min-width: 64px;
    max-width: 160px;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px 6px;
    gap: 4px;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }

  .anatomy-nav-item {
    padding: 6px 8px;
    font-size: 11px;
    width: 100%;
    justify-content: flex-start;
    border-radius: 8px;
  }

  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    flex: 1;
  }

  .sidebar-left, .sidebar-right {
    display: none;
  }
}

/* 极小横屏（高度很低时进一步压缩） */
@media (max-height: 400px) and (orientation: landscape) {
  .anatomy-nav-item {
    padding: 4px 6px;
    font-size: 10px;
  }

  .anatomy-nav-item .nav-count {
    font-size: 9px;
    padding: 0px 4px;
  }
}
