/* =============================================================================
   Classroom Chatbot Styles
   ============================================================================= */

/* CSS Variables */
:root {
  --primary-color: #4f46e5;
  --primary-hover: #4338ca;
  --secondary-color: #6b7280;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  --background: rgba(0, 0, 0, 0.3);
  --surface: rgba(15, 15, 25, 0.85);
  --text-primary: #e0e0ff;
  --text-secondary: #a0a0c0;
  --border-color: rgba(79, 70, 229, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
  --radius: 8px;
  --radius-lg: 12px;
}

/* 3D Background Canvas */
#bg-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

/* Initial hidden state for chatbot UI */
.app-container {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 1s ease, transform 1s ease;
}

.app-container.visible {
  opacity: 1;
  transform: scale(1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: transparent;
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* =============================================================================
   Layout
   ============================================================================= */

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

html[data-embed='true'] .app-container {
  max-width: none;
  margin: 0;
  min-height: 100dvh;
  height: 100dvh;
}

.header {
  background: var(--surface);
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  box-shadow: 0 0 20px rgba(79, 70, 229, 0.3);
}

.header-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.header-copy {
  min-width: 0;
  text-align: center;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #00ff88;
  text-shadow: 0 0 10px #00ff88, 0 0 20px #00ff88;
}

.header .subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.api-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 32px;
  padding: 0.35rem 0.65rem;
  border: 1px solid rgba(160, 160, 192, 0.25);
  border-radius: 999px;
  background: rgba(5, 5, 10, 0.75);
  color: var(--text-secondary);
  font-family: 'Courier New', monospace;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  white-space: nowrap;
}

.api-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.65);
}

.api-status--online {
  border-color: rgba(0, 255, 136, 0.35);
  color: #00ff88;
}

.api-status--online .api-status-dot {
  background: #00ff88;
  box-shadow: 0 0 8px #00ff88, 0 0 14px rgba(0, 255, 136, 0.6);
}

.api-status--offline {
  border-color: rgba(255, 68, 68, 0.35);
  color: #ff6b6b;
}

.api-status--offline .api-status-dot {
  background: #ff4444;
  box-shadow: 0 0 8px #ff4444, 0 0 14px rgba(255, 68, 68, 0.5);
}

.main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* =============================================================================
   Filters Panel
   ============================================================================= */

.filters-panel {
  width: 250px;
  background: var(--surface);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem;
  overflow-y: auto;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.filters-panel h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #00ff88;
  text-shadow: 0 0 5px #00ff88;
}

.filter-group {
  margin-bottom: 1.25rem;
}

.filter-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.filter-group select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: rgba(15, 15, 25, 0.9);
  color: var(--text-primary);
  min-height: 100px;
}

.filter-group select:focus {
  outline: none;
  border-color: #00ff88;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.3);
}

/* =============================================================================
   Cockpit Toggle Button
   ============================================================================= */

.cockpit-toggle {
  position: absolute;
  left: 250px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.cockpit-toggle.collapsed {
  left: 0;
}

.cockpit-toggle-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, #1a1a2e 0%, #0d0d1a 100%);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-left: none;
  border-radius: 0 8px 8px 0;
  padding: 14px 8px;
  box-shadow:
    0 0 10px rgba(0, 255, 136, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: box-shadow 0.3s ease;
}

.cockpit-toggle:hover .cockpit-toggle-body {
  box-shadow:
    0 0 20px rgba(0, 255, 136, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Label */
.cockpit-label {
  font-family: 'Courier New', monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #00ff88;
  text-shadow: 0 0 5px #00ff88;
  writing-mode: vertical-lr;
  text-orientation: mixed;
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

.cockpit-toggle.collapsed .cockpit-label {
  color: rgba(0, 255, 136, 0.55);
  text-shadow: 0 0 4px rgba(0, 255, 136, 0.35);
}

.cockpit-grip {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cockpit-grip span {
  display: block;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: rgba(0, 255, 136, 0.7);
  box-shadow: 0 0 5px rgba(0, 255, 136, 0.4);
}

.cockpit-toggle.collapsed .cockpit-grip span {
  background: rgba(0, 255, 136, 0.45);
  box-shadow: none;
}

/* Filters panel slide animation */
.filters-panel {
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.3s ease,
              border-color 0.3s ease;
  overflow: hidden;
}

.filters-panel.collapsed {
  width: 0 !important;
  padding: 0 !important;
  opacity: 0;
  border-color: transparent !important;
}

/* Make main-content relative for toggle positioning */
.main-content {
  position: relative;
}

/* =============================================================================
   Chat Container
   ============================================================================= */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--background);
  min-width: 0;
  min-height: 0;
  backdrop-filter: blur(5px);
}

.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* =============================================================================
   Messages
   ============================================================================= */

.message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
  background: var(--primary-color);
  color: white;
  box-shadow: 0 0 15px rgba(79, 70, 229, 0.4);
}

.message.bot {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid rgba(0, 255, 136, 0.3);
  box-shadow: 0 0 15px rgba(0, 255, 136, 0.1);
  backdrop-filter: blur(10px);
}

.message-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  opacity: 0.8;
}

.message.user .message-label {
  color: rgba(255, 255, 255, 0.8);
}

.message.bot .message-label {
  color: #00ff88;
  text-shadow: 0 0 5px #00ff88;
}

.message-content {
  font-size: 0.9375rem;
  line-height: 1.6;
}

/* Blurred message styling */
.message.blurred {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-color: var(--warning-color);
}

.message.blurred .disclaimer {
  font-size: 0.8125rem;
  color: var(--warning-color);
  font-style: italic;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed var(--warning-color);
}

/* Error message styling */
.message.error {
  background: #fef2f2;
  border-color: var(--error-color);
}

.message.error .message-label {
  color: var(--error-color);
}

/* Typing indicator */
.message.typing .message-content {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Show sources button in message */
.show-sources-btn {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  background: var(--background);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.show-sources-btn:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* =============================================================================
   Chat Form
   ============================================================================= */

.chat-form {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(180deg, #0a0a14 0%, #050508 100%);
  border-top: 1px solid rgba(0, 255, 136, 0.15);
  backdrop-filter: blur(10px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 -4px 20px rgba(0, 0, 0, 0.5);
}

.chat-input {
  flex: 1;
  padding: 0.85rem 1.1rem;
  font-size: 1rem;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
  border: 1px solid rgba(0, 255, 136, 0.15);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
  background: rgba(5, 5, 10, 0.95);
  color: #c0ffd8;
}

.chat-input::placeholder {
  color: rgba(0, 255, 136, 0.25);
  font-family: 'Courier New', monospace;
}

.chat-input:focus {
  border-color: #00ff88;
  box-shadow: 0 0 12px rgba(0, 255, 136, 0.25), inset 0 0 8px rgba(0, 255, 136, 0.05);
  background: rgba(5, 5, 12, 1);
}

.chat-input:disabled {
  background: rgba(5, 5, 8, 0.7);
  cursor: not-allowed;
  opacity: 0.5;
}

/* =============================================================================
   Buttons
   ============================================================================= */

.btn {
  padding: 0.75rem 1.5rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #0d1a12 0%, #050a08 100%);
  color: #00ff88;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 0.8rem;
  border: 1px solid rgba(0, 255, 136, 0.3);
  box-shadow:
    0 0 10px rgba(0, 255, 136, 0.15),
    inset 0 1px 0 rgba(0, 255, 136, 0.1);
  text-shadow: 0 0 6px #00ff88;
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 136, 0.1), transparent);
  transition: left 0.5s ease;
}

.btn-primary:hover:not(:disabled)::before {
  left: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #0f2018 0%, #081210 100%);
  border-color: #00ff88;
  box-shadow:
    0 0 20px rgba(0, 255, 136, 0.3),
    inset 0 1px 0 rgba(0, 255, 136, 0.15);
  text-shadow: 0 0 10px #00ff88, 0 0 20px #00ff88;
}

.btn-primary:active:not(:disabled) {
  background: linear-gradient(180deg, #081210 0%, #050a08 100%);
  box-shadow:
    0 0 8px rgba(0, 255, 136, 0.2),
    inset 0 2px 4px rgba(0, 0, 0, 0.5);
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--background);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border-color);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--text-secondary);
}

.btn-icon:hover {
  background: var(--background);
}

.btn-floating {
  position: fixed;
  bottom: 100px;
  right: 24px;
  padding: 0.75rem 1rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 24px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 100;
}

.btn-floating:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.15);
}

/* =============================================================================
   Citations Drawer
   ============================================================================= */

.citations-drawer {
  width: 0;
  min-width: 0;
  max-width: min(360px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--border-color);
  border-left-color: transparent;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  z-index: 20;
  box-shadow: var(--shadow-lg);
  transition: width 0.3s ease, border-color 0.3s ease;
}

.citations-drawer.open {
  width: clamp(280px, 36vw, 360px);
  border-left-color: var(--border-color);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  min-width: 280px;
}

.drawer-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  min-width: 280px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 2rem 1rem;
}

/* Citation item */
.citation-item {
  padding: 0.875rem;
  background: var(--background);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  border: 1px solid var(--border-color);
}

.citation-item:hover {
  border-color: var(--primary-color);
}

.citation-pseudonym {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 0.25rem;
}

.citation-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.citation-snippet {
  font-size: 0.8125rem;
  color: var(--text-primary);
  line-height: 1.5;
}

/* =============================================================================
   Toast Notifications
   ============================================================================= */

.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.875rem 1.25rem;
  background: var(--text-primary);
  color: white;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.toast.error {
  background: var(--error-color);
}

.toast.warning {
  background: var(--warning-color);
  color: var(--text-primary);
}

.toast.success {
  background: var(--success-color);
}

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

/* =============================================================================
   Responsive Design
   ============================================================================= */

@media (max-width: 768px) {
  .header {
    padding: 1rem;
  }

  .header-body {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .api-status {
    justify-self: center;
  }

  .filters-panel {
    display: none;
  }

  .message {
    max-width: 90%;
  }

  .citations-drawer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 0;
    max-width: 100%;
  }

  .citations-drawer.open {
    width: min(100%, 360px);
  }
}

@media (min-width: 769px) {
  html[data-embed='true'] .header {
    padding: 1rem 1.25rem;
  }

  html[data-embed='true'] .header-body {
    grid-template-columns: clamp(220px, 18vw, 250px) minmax(0, 1fr) auto;
  }

  html[data-embed='true'] .header-copy {
    grid-column: 2;
  }

  html[data-embed='true'] .api-status {
    grid-column: 3;
    justify-self: end;
  }

  html[data-embed='true'] .filters-panel {
    width: clamp(220px, 18vw, 250px);
  }

  html[data-embed='true'] .cockpit-toggle {
    left: clamp(220px, 18vw, 250px);
  }

  html[data-embed='true'] .chat-window {
    padding: 1.25rem;
    align-items: stretch;
  }

  html[data-embed='true'] .chat-form {
    padding: 0.875rem 1.25rem;
  }

  html[data-embed='true'] .message.bot {
    max-width: none;
    width: 100%;
  }

  html[data-embed='true'] .citations-drawer.open {
    width: clamp(280px, 24vw, 340px);
  }
}

@media (max-width: 480px) {
  .header h1 {
    font-size: 1.25rem;
  }

  .chat-form {
    padding: 0.75rem;
  }

  .btn {
    padding: 0.625rem 1rem;
  }
}
