/* ========================================
   STUDENT BOT - MODERN CHATBOT STYLES
   ======================================== */

/* CSS Custom Properties - Design Tokens */
:root {
  /* Colors - Dark Theme (Default) */
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.4);

  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-glass: rgba(30, 41, 59, 0.8);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border-color: rgba(148, 163, 184, 0.1);
  --border-glow: rgba(99, 102, 241, 0.3);

  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px var(--primary-glow);

  /* Typography */
  --font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;

  /* Z-Index */
  --z-base: 1;
  --z-header: 100;
  --z-modal: 1000;
  --z-toast: 1100;
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #e2e8f0;
  --bg-tertiary: #cbd5e1;
  --bg-glass: rgba(255, 255, 255, 0.9);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border-color: rgba(15, 23, 42, 0.1);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* ========================================
   BASE RESET & DEFAULTS
   ======================================== */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
  transition:
    background-color var(--transition-base),
    color var(--transition-base);
}

/* ========================================
   BACKGROUND ANIMATION
   ======================================== */

.background-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.floating-shapes {
  position: absolute;
  width: 100%;
  height: 100%;
}

.shape {
  position: absolute;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), transparent);
  opacity: 0.08;
  animation: float 28s infinite ease-in-out;
  will-change: transform;
}

.shape:nth-child(n + 4) {
  display: none;
}

.shape:nth-child(1) {
  width: 300px;
  height: 300px;
  top: 10%;
  left: 10%;
  animation-delay: 0s;
}

.shape:nth-child(2) {
  width: 200px;
  height: 200px;
  top: 60%;
  right: 10%;
  animation-delay: -5s;
}

.shape:nth-child(3) {
  width: 150px;
  height: 150px;
  bottom: 20%;
  left: 30%;
  animation-delay: -10s;
}

.shape:nth-child(4) {
  width: 250px;
  height: 250px;
  top: 30%;
  right: 30%;
  animation-delay: -15s;
}

.shape:nth-child(5) {
  width: 180px;
  height: 180px;
  bottom: 10%;
  right: 20%;
  animation-delay: -7s;
}

@keyframes float {
  0%,
  100% {
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  25% {
    transform: translate(30px, -30px) rotate(90deg) scale(1.1);
  }
  50% {
    transform: translate(-20px, 20px) rotate(180deg) scale(0.9);
  }
  75% {
    transform: translate(20px, 10px) rotate(270deg) scale(1.05);
  }
}

/* ========================================
   APP CONTAINER
   ======================================== */

.app-container {
  display: flex;
  flex-direction: column;
  max-width: 900px;
  height: 100vh;
  margin: 0 auto;
  background: var(--bg-glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

/* ========================================
   HEADER
   ======================================== */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: var(--z-header);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.bot-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  border-radius: var(--radius-full);
  font-size: 1.5rem;
  animation: pulse-glow 3.2s infinite;
}

.avatar-icon {
  animation: bounce 3s infinite;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 var(--primary-glow);
  }
  50% {
    box-shadow: 0 0 20px 5px var(--primary-glow);
  }
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: var(--success);
  border: 2px solid var(--bg-secondary);
  border-radius: var(--radius-full);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.header-info h1 {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.status-text {
  font-size: var(--font-size-sm);
  color: var(--success);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.theme-toggle,
.help-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  font-size: 1.2rem;
}

.theme-toggle:hover,
.help-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.05);
  box-shadow: var(--shadow-glow);
}

.theme-toggle {
  position: relative;
  overflow: hidden;
}

.theme-icon {
  position: absolute;
  transition: all var(--transition-base);
}

.theme-icon.sun {
  opacity: 0;
  transform: translateY(20px) rotate(-90deg);
}

.theme-icon.moon {
  opacity: 1;
  transform: translateY(0) rotate(0deg);
}

[data-theme="light"] .theme-icon.sun {
  opacity: 1;
  transform: translateY(0) rotate(0deg);
}

[data-theme="light"] .theme-icon.moon {
  opacity: 0;
  transform: translateY(-20px) rotate(90deg);
}

/* ========================================
   CHAT MESSAGES
   ======================================== */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: var(--space-sm);
  max-width: 85%;
  animation: fadeInUp 0.4s ease-out;
}

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

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

.message.bot {
  align-self: flex-start;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.message.bot .message-avatar {
  background: linear-gradient(135deg, var(--primary), #a855f7);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--success), #059669);
}

.message-content {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-lg);
  position: relative;
}

.message.bot .message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: var(--radius-sm);
}

.message.user .message-content {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.message-text {
  font-size: var(--font-size-base);
  line-height: 1.5;
  word-wrap: break-word;
}

.message-time {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--space-xs);
  opacity: 0.7;
}

.message.user .message-time {
  color: rgba(255, 255, 255, 0.7);
}

/* ========================================
   DATA TABLE IN MESSAGES
   ======================================== */

.data-table-wrapper {
  margin-top: var(--space-md);
  overflow: hidden;
  border-radius: var(--radius-md);
  animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  background: var(--bg-tertiary);
}

.data-table th,
.data-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background: var(--primary);
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  font-size: var(--font-size-xs);
  letter-spacing: 0.5px;
}

.data-table tr {
  transition: background var(--transition-fast);
}

.data-table tr:hover {
  background: rgba(99, 102, 241, 0.1);
}

.data-table tr:last-child td {
  border-bottom: none;
}

/* Grade Colors */
.grade-a {
  color: var(--success);
  font-weight: 600;
}
.grade-b {
  color: var(--info);
  font-weight: 600;
}
.grade-c {
  color: var(--warning);
  font-weight: 600;
}
.grade-d {
  color: var(--error);
  font-weight: 600;
}

/* ========================================
   TYPING INDICATOR
   ======================================== */

.typing-indicator {
  display: none;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-lg);
  margin-left: calc(36px + var(--space-sm));
}

.typing-indicator.active {
  display: flex;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: var(--radius-full);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) {
  animation-delay: 0s;
}
.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* ========================================
   INPUT AREA
   ======================================== */

.chat-input-area {
  padding: var(--space-md) var(--space-lg) var(--space-lg);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

.input-container {
  display: flex;
  gap: var(--space-sm);
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-xs);
  transition: all var(--transition-base);
}

.input-container:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--font-size-base);
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
}

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

.send-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  color: white;
}

.send-btn svg {
  width: 20px;
  height: 20px;
  transition: transform var(--transition-base);
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-glow);
}

.send-btn:hover svg {
  transform: translateX(2px);
}

.send-btn:active {
  transform: scale(0.95);
}

.input-hints {
  margin-top: var(--space-sm);
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* ========================================
   MODALS
   ======================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9) translateY(20px);
  transition: all var(--transition-base);
  box-shadow: var(--shadow-lg);
}

/* Add Student form modal: keep the form in one compact section without an internal scrollbar */
#studentFormModal .modal-content {
  width: min(96vw, 860px);
  max-width: 860px;
  max-height: none;
  overflow: hidden;
}

#studentFormModal {
  align-items: flex-start;
  overflow-y: auto;
  padding: 18px 0;
}

.modal-overlay.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-large {
  max-width: 800px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
  font-size: var(--font-size-xl);
  font-weight: 600;
}

.modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--error);
  color: white;
}

/* ========================================
   STUDENT FORM
   ======================================== */

.student-form {
  padding: var(--space-lg);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.form-row {
  display: contents;
}

.marks-row {
  display: contents;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-divider,
.form-actions {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-family: inherit;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-divider {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin: var(--space-sm) 0;
}

.form-divider::before,
.form-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-color);
}

.form-divider span {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  margin-top: 2px;
}

.btn-primary,
.btn-secondary {
  padding: var(--space-sm) var(--space-xl);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

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

.btn-secondary:hover {
  background: var(--bg-primary);
}

.btn-loader {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

.btn-primary.loading .btn-text {
  visibility: hidden;
}

.btn-primary.loading .btn-loader {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ========================================
   TABLE CONTAINER
   ======================================== */

.table-container {
  padding: var(--space-lg);
  overflow-x: auto;
}

.table-container .data-table {
  min-width: 600px;
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  z-index: var(--z-toast);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.4s ease-out;
  max-width: 350px;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.success {
  border-left: 4px solid var(--success);
}
.toast.error {
  border-left: 4px solid var(--error);
}
.toast.warning {
  border-left: 4px solid var(--warning);
}
.toast.info {
  border-left: 4px solid var(--info);
}

.toast-icon {
  font-size: 1.2rem;
}

.toast-message {
  flex: 1;
  font-size: var(--font-size-sm);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  transition: color var(--transition-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast.removing {
  animation: slideOutRight 0.3s ease-out forwards;
}

@keyframes slideOutRight {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* ========================================
   SKELETON LOADING
   ======================================== */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-secondary) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1em;
  margin: var(--space-xs) 0;
}

.skeleton-text:last-child {
  width: 70%;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
  .app-container {
    border: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .chat-header {
    padding: var(--space-sm) var(--space-md);
  }

  .header-info h1 {
    font-size: var(--font-size-base);
  }

  .status-text {
    display: none;
  }

  .chat-messages {
    padding: var(--space-md);
  }

  .message {
    max-width: 90%;
  }

  .chat-input-area {
    padding: var(--space-sm) var(--space-md) var(--space-md);
  }

  .input-hints {
    display: none;
  }

  .form-row,
  .marks-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .student-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: var(--space-md);
  }

  .modal-content {
    width: 95%;
    margin: var(--space-md);
  }

  #studentFormModal .modal-content {
    width: min(96vw, 760px);
    max-width: 760px;
  }

  .toast-container {
    left: var(--space-md);
    right: var(--space-md);
  }

  .toast {
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .background-animation {
    display: none;
  }

  .app-container {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

@media (max-width: 480px) {
  .bot-avatar {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }

  .theme-toggle,
  .help-btn {
    width: 38px;
    height: 38px;
  }

  .message-content {
    padding: var(--space-sm) var(--space-md);
  }

  .send-btn {
    width: 44px;
    height: 44px;
  }

  .student-form {
    grid-template-columns: 1fr;
    gap: 9px;
  }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
  .background-animation,
  .chat-input-area,
  .header-right,
  .typing-indicator {
    display: none !important;
  }

  .app-container {
    max-width: 100%;
    height: auto;
  }

  .chat-messages {
    overflow: visible;
  }
}
