/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6C63FF;
  --primary-light: rgba(108, 99, 255, 0.08);
  --primary-faint: rgba(108, 99, 255, 0.04);
  --bg: #FFFFFF;
  --bg-secondary: #F7F7F8;
  --bg-tertiary: #FAFAFA;
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --accent-orange: #F97316;
  --error: #EF4444;
  --success: #22C55E;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* Loading */
#loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  color: var(--text-secondary);
}

.loader {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loader.small { width: 24px; height: 24px; border-width: 2px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Auth */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 12px;
  color: var(--text-secondary);
}
.auth-container h2 { color: var(--text-primary); }
.auth-container a { color: var(--primary); text-decoration: none; }

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  height: 48px;
  flex-shrink: 0;
}
.top-bar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-left: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-secondary); }

/* Main layout */
.main-content {
  display: flex;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.video-column {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-right: 16px;
}

/* Video container */
.video-container {
  width: 100%;
  max-width: 960px;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

.video-aspect-ratio {
  position: relative;
  padding-top: 56.25%; /* 16:9 */
  width: 100%;
}

.video-aspect-ratio iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* Video info */
.video-info {
  max-width: 960px;
  padding: 16px 0;
}

.video-info h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.3;
}

.video-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}
.meta-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-secondary);
  margin: 0 10px;
}

.video-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 24px;
}

.video-description {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 24px;
}

/* Exam button */
.exam-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 600px;
  height: 56px;
  background: var(--accent-orange);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
  transition: transform 0.1s, box-shadow 0.1s;
}
.exam-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.4);
}
.exam-btn:active { transform: translateY(0); }

/* Sidebar */
.sidebar {
  width: 380px;
  min-width: 380px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

.tab-headers {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 8px;
}
.tab-btn {
  flex: 1;
  padding: 14px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.tab-panel.active { display: flex; }

/* Notes */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.note-item {
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-secondary);
  margin-bottom: 8px;
  cursor: default;
}
.note-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.note-time {
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.note-time:hover { background: rgba(108, 99, 255, 0.15); }
.note-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  opacity: 0.5;
  font-size: 18px;
  padding: 2px;
}
.note-delete:hover { opacity: 1; color: var(--error); }
.note-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

.add-note-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px;
  padding: 14px;
  background: linear-gradient(135deg, #6C63FF, #8B83FF);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(108, 99, 255, 0.3);
  flex-shrink: 0;
  transition: transform 0.1s, box-shadow 0.1s;
}
.add-note-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(108, 99, 255, 0.4);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--text-secondary);
  padding: 24px;
}
.empty-state h3 { color: var(--text-primary); font-size: 18px; }
.empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(108,99,255,0.1), rgba(108,99,255,0.05));
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Transcript */
.transcript-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.transcript-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}
.transcript-item:hover { background: var(--bg-secondary); }
.transcript-item.active {
  background: var(--primary-faint);
  border-left-color: var(--primary);
}
.transcript-item.active .transcript-time {
  color: var(--primary);
  background: var(--primary-light);
}
.transcript-item.active .transcript-text {
  color: var(--text-primary);
  font-weight: 500;
}

.transcript-time {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.transcript-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  flex: 1;
}

.transcript-play-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  opacity: 0.3;
  padding: 0;
  flex-shrink: 0;
  font-size: 20px;
}
.transcript-item:hover .transcript-play-btn { opacity: 0.6; }
.transcript-item.active .transcript-play-btn { opacity: 1; color: var(--primary); }

/* Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.dialog {
  background: var(--bg);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.dialog-header h3 { font-size: 18px; font-weight: 600; }
.note-timestamp {
  font-size: 13px;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: 6px;
}
.dialog textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.dialog textarea:focus { border-color: var(--primary); }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--border); }

/* AI Chat */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--text-secondary);
  padding: 24px;
  text-align: center;
}
.ai-welcome h3 { color: var(--text-primary); font-size: 18px; }

.ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.ai-msg.assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.ai-msg.assistant.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.ai-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-chat-input-area textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 100px;
  transition: border-color 0.2s;
}
.ai-chat-input-area textarea:focus { border-color: var(--primary); }

.ai-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}
.ai-send-btn:hover { opacity: 0.85; }
.ai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Responsive */
@media (max-width: 900px) {
  .main-content { flex-direction: column; }
  .video-column { padding: 12px; }
  .sidebar {
    width: 100%;
    min-width: 100%;
    height: 50vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
