/* ========== CSS Variables & Reset ========== */
:root {
  --primary: #6366F1;
  --primary-light: #A5B4FC;
  --primary-dark: #4F46E5;
  --primary-bg: #EEF2FF;
  --accent: #F59E0B;
  --accent-light: #FEF3C7;
  --success: #10B981;
  --text: #1E293B;
  --text-secondary: #64748B;
  --text-light: #94A3B8;
  --bg: #F1F5F9;
  --card-bg: #FFFFFF;
  --border: #E2E8F0;
  --shadow-sm: 0 2px 8px rgba(99, 102, 241, 0.08);
  --shadow: 0 4px 16px rgba(99, 102, 241, 0.12), 0 2px 8px rgba(99, 102, 241, 0.06);
  --shadow-md: 0 8px 24px rgba(99, 102, 241, 0.15);
  --shadow-lg: 0 12px 40px rgba(99, 102, 241, 0.2);
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-bg: linear-gradient(135deg, #f5f7ff 0%, #e8ecf8 50%, #f0f4ff 100%);
  --gradient-card: linear-gradient(180deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.85) 100%);
  --gradient-btn: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
  --gradient-accent: linear-gradient(135deg, #f59e0b 0%, #f97316 100%);
  --glow-blue: 0 0 40px rgba(99, 102, 241, 0.15);
  --glow-purple: 0 0 60px rgba(139, 92, 246, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--gradient-bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  line-height: 1.6;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 50% 50%, rgba(245, 158, 11, 0.04) 0%, transparent 60%);
  z-index: -1;
  pointer-events: none;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ========== Header ========== */
.header {
  height: 56px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25) 0%, rgba(139, 92, 246, 0.18) 100%);
  border-bottom: 1px solid rgba(99, 102, 241, 0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(99, 102, 241, 0.08);
  backdrop-filter: blur(10px);
}

.header-left { display: flex; align-items: center; gap: 10px; }

.header-logo {
  width: 32px; height: 32px;
  display: flex;
  align-items: center; justify-content: center;
}
.header-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.header-title {
  font-size: 16px; font-weight: 700;
  color: var(--text);
}

.header-subtitle {
  font-size: 12px; color: var(--text-light);
  margin-left: 10px; padding-left: 10px;
  border-left: 1px solid var(--border);
}

.header-right {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px; color: var(--text-secondary);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--primary-bg);
  border-radius: 20px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.user-name {
  font-weight: 500;
  color: var(--text);
}

.header-badge {
  padding: 3px 10px; background: var(--primary-bg);
  color: var(--primary); border-radius: 12px;
  font-weight: 600; font-size: 11px;
}

/* ========== Main Layout ========== */
.app-container {
  display: flex;
  height: calc(100vh - 56px);
}

/* ========== Left Panel ========== */
.left-panel {
  width: 550px;
  min-width: 550px;
  background: var(--gradient-card);
  border-right: 1px solid rgba(99, 102, 241, 0.08);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
}

.panel-header {
  padding: 14px 18px 10px;
  border-bottom: 2px solid rgba(99, 102, 241, 0.08);
  flex-shrink: 0;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.03) 0%, transparent 100%);
}

.panel-header h2 {
  font-size: 14px; font-weight: 700;
  color: var(--text);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.panel-header p {
  font-size: 11px; color: var(--text-light);
  margin-top: 2px;
}

/* Chat Messages Area */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.02) 0%, rgba(139, 92, 246, 0.02) 100%);
}

.chat-message {
  display: flex;
  gap: 8px;
  max-width: 100%;
  animation: msgIn 0.3s ease-out;
}

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

.chat-message.bot { align-self: flex-start; }
.chat-message.user { align-self: flex-end; flex-direction: row-reverse; }

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

.chat-avatar.bot {
  background: var(--primary);
  color: white;
}

.chat-avatar.user {
  background: #94A3B8;
  color: white;
}

.chat-bubble {
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  min-width: 60px;
  max-width: 90%;
  word-break: normal;
  overflow-wrap: normal;
}

.chat-message.bot .chat-bubble {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
  padding: 12px 16px;
  line-height: 1.85;
}

.chat-message.bot .chat-bubble p {
  margin: 0 0 10px 0;
}
.chat-message.bot .chat-bubble p:last-child {
  margin-bottom: 0;
}
.chat-message.bot .chat-bubble b {
  color: #1E293B;
  font-weight: 700;
}
.chat-message.bot .chat-bubble hr {
  border: none;
  border-top: 1px dashed rgba(99, 102, 241, 0.25);
  margin: 10px 0;
}

.chat-message.user .chat-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
  flex-shrink: 0;
}

.chat-bubble h2 { font-size: 14px; margin: 6px 0 3px; }
.chat-bubble h3 { font-size: 13px; margin: 5px 0 2px; }
.chat-bubble p { margin: 3px 0; }
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble blockquote {
  border-left: 3px solid var(--primary-light);
  padding-left: 10px; margin: 6px 0; color: var(--text-secondary);
  font-size: 12px;
}

/* Quick reply buttons */
.quick-replies {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 2px 0;
}

.quick-reply-btn {
  padding: 6px 14px; 
  border: 1.5px solid rgba(99, 102, 241, 0.3);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
  color: var(--primary);
  border-radius: 16px; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: var(--transition);
  backdrop-filter: blur(4px);
}

.quick-reply-btn:hover {
  background: var(--gradient-btn);
  color: white; 
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

/* Typing indicator */
.typing-indicator {
  display: flex; gap: 3px; padding: 4px 0;
}
.typing-indicator span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-light);
  animation: typingBounce 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}


@keyframes fadeIn {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Bubble thinking animation */
.bubble-thinking {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px 0;
}
.bubble-thinking span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary-light);
  animation: bubbleBounce 1.2s ease-in-out infinite;
}
.bubble-thinking span:nth-child(2) { animation-delay: 0.15s; }
.bubble-thinking span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bubbleBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* Chat Input */
.chat-input-area {
  padding: 10px 14px 12px;
  border-top: 1px solid rgba(99, 102, 241, 0.08);
  background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(255,255,255,0.92) 100%);
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.chat-input-wrapper {
  display: flex; gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid rgba(99, 102, 241, 0.15);
  border-radius: 20px;
  font-size: 14px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.02) 0%, rgba(139, 92, 246, 0.02) 100%);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}

.chat-input:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.chat-send-btn {
  width: 34px; height: 34px;
  border: none; background: var(--gradient-btn);
  color: white; border-radius: 50%;
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition); flex-shrink: 0;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
}

.chat-send-btn:hover { 
  background: var(--gradient-primary);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Chat status bar */
.chat-status {
  font-size: 11px; color: var(--text-light);
  text-align: center; padding: 4px 0 2px;
}

/* ========== Right Panel ========== */
.right-panel {
  flex: 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 12px;
}

/* ========== Right Panel - Document Viewer (Full Height) ========== */
.right-top {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 10px 22px 6px;
  background: var(--gradient-card);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(99, 102, 241, 0.08);
}

.doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(99, 102, 241, 0.08);
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.03) 0%, transparent 100%);
  padding: 8px 12px;
  border-radius: var(--radius);
}

.doc-header h2 {
  font-size: 15px; font-weight: 700;
  color: var(--text);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.doc-counter {
  font-size: 12px; color: var(--text-light);
}

.doc-layout {
  display: flex;
  gap: 14px;
  flex: 1;
  overflow: hidden;
}

/* Document sidebar - school list */
.doc-sidebar {
  width: 130px;
  min-width: 130px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.02) 0%, rgba(139, 92, 246, 0.02) 100%);
  border-right: 1px solid rgba(99, 102, 241, 0.08);
  padding: 8px 6px;
}

.doc-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  background: transparent;
}

.doc-item:hover {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.08) 0%, rgba(139, 92, 246, 0.04) 100%);
}

.doc-item.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.08) 100%);
  border-left-color: var(--primary);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.12);
}

.doc-item-name {
  font-size: 13px; font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.doc-item-meta {
  font-size: 10px; color: var(--text-light);
  margin-top: 2px;
}

.doc-item-score {
  font-size: 10px; color: var(--text-secondary);
  margin-top: 2px;
}

/* Document content area */
.doc-content {
  flex: 1;
  background: var(--gradient-card);
  border: 1px solid rgba(99, 102, 241, 0.08);
  border-radius: var(--radius-lg);
  overflow-y: auto;
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
}

.doc-school-name {
  font-size: 24px; font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.doc-school-sub {
  font-size: 13px; color: var(--text-light);
  margin-bottom: 12px;
}

.doc-tags {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-bottom: 14px;
}

.doc-tag {
  font-size: 11px; 
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1) 0%, rgba(139, 92, 246, 0.1) 100%);
  color: var(--primary); 
  padding: 4px 12px;
  border-radius: 20px; font-weight: 500;
  border: 1px solid rgba(99, 102, 241, 0.15);
  transition: var(--transition);
}

.doc-tag:hover {
  background: var(--gradient-btn);
  color: white;
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.doc-ratings {
  display: flex; gap: 20px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.03) 0%, rgba(139, 92, 246, 0.03) 100%);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(99, 102, 241, 0.08);
}

.doc-rating-item {
  font-size: 13px;
}

.doc-rating-item .label {
  color: var(--text-secondary);
  font-weight: 500;
}

.doc-rating-item .stars {
  color: var(--accent);
  letter-spacing: -1px;
}

.doc-rating-item .num {
  color: var(--text-secondary);
  font-size: 12px;
}

.doc-section {
  margin-bottom: 18px;
}

.doc-section:last-child { margin-bottom: 0; }

.doc-section-title {
  font-size: 14px; font-weight: 700;
  margin-bottom: 6px;
  padding-bottom: 6px;
  padding-left: 12px;
  border-bottom: 2px solid rgba(99, 102, 241, 0.15);
  border-left: 3px solid var(--primary);
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.05) 0%, transparent 100%);
  border-radius: 0 var(--radius-sm) 0 0;
}

.doc-section p {
  font-size: 14px; color: var(--text-secondary);
  line-height: 1.8;
  text-indent: 2em;
}

.doc-score-box {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px;
  padding: 10px 18px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(5, 150, 105, 0.08) 100%);
  border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.2);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.1);
}

.doc-score-box .badge {
  background: var(--gradient-btn); 
  padding: 2px 12px;
  border-radius: 8px; 
  color: white;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.doc-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; color: var(--text-light);
  font-size: 14px; gap: 10px;
}

.doc-empty-icon { font-size: 40px; opacity: 0.4; }

/* ========== 3D Campus Button ========== */
.doc-3d-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(139, 92, 246, 0.12) 100%);
  border: 1.5px solid rgba(99, 102, 241, 0.25);
  border-radius: 22px;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(6px);
  z-index: 5;
}
.doc-3d-btn:hover {
  background: var(--gradient-btn);
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.3);
}

/* ========== Image Gallery (inline thumbnails) ========== */
.campus-tab-btn {
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid #165DFF;
  background: #fff;
  color: #165DFF;
  margin-right: 8px;
  margin-bottom: 8px;
}
.campus-tab-btn:hover {
  background: #165DFF;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22,93,255,0.25);
}
.campus-tab-btn.active {
  background: #165DFF;
  color: #fff;
}

.doc-img {
  max-width: 380px !important;
  width: 90% !important;
  height: 220px !important;
  object-fit: cover !important;
  border-radius: 8px !important;
  margin: 12px auto 0 !important;
  display: block !important;
  cursor: pointer !important;
  border: 2px solid #d1d5db !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
}

.img-gallery {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: nowrap;
  justify-content: center;
}
.img-gallery-thumb {
  width: 380px;
  height: 220px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  border: 2px solid rgba(99, 102, 241, 0.12);
  transition: var(--transition);
  position: relative;
  flex-shrink: 0;
}
.img-gallery-thumb:hover {
  border-color: var(--primary);
  transform: scale(1.06);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.25);
}
.img-gallery-thumb .thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 5px;
  font-size: 9px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  border-radius: 0 0 6px 6px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== Lightbox (Fullscreen Image Viewer) ========== */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  cursor: pointer;
}
.lightbox-overlay.active {
  opacity: 1;
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 36px;
  color: #fff;
  cursor: pointer;
  z-index: 10;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  transition: background 0.2s;
  line-height: 1;
}
.lightbox-close:hover {
  background: rgba(255,255,255,0.2);
}
.lightbox-image {
  max-width: 92vw;
  max-height: 84vh;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  cursor: default;
}
.lightbox-label {
  color: #fff;
  font-size: 15px;
  margin-top: 16px;
  opacity: 0.8;
  font-weight: 500;
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .app-container { flex-direction: column; overflow-y: auto; }
  .left-panel { width: 100%; min-width: auto; max-height: 400px; }
  .right-panel { height: auto; }
  .doc-layout { flex-direction: column; }
  .doc-sidebar { width: 100%; min-width: auto; flex-direction: row; overflow-x: auto; }
  .doc-sidebar .doc-item { min-width: 120px; }
}
