/* ==============================================================================
   مساعد الذكاء الاصطناعي الفيزيائي - منصة الفيزياء التعليمية
   إعداد وإشراف: أ. علي عسيري
   تصميم حديث متوافق مع كافة الشاشات والوضع الليلي والنهاري
   ============================================================================== */

:root {
  --ai-primary: #3b82f6;
  --ai-primary-hover: #2563eb;
  --ai-glow: rgba(59, 130, 246, 0.4);
  --ai-gold: #fbbf24;
  --ai-gold-glow: rgba(251, 191, 36, 0.35);
  --ai-bg-panel: rgba(13, 21, 38, 0.95);
  --ai-bg-card: rgba(19, 31, 56, 0.7);
  --ai-border: rgba(59, 130, 246, 0.25);
  --ai-text-main: #f8fafc;
  --ai-text-dim: #94a3b8;
  --ai-user-bubble: linear-gradient(135deg, #2563eb, #1d4ed8);
  --ai-bot-bubble: rgba(30, 41, 59, 0.85);
  --ai-shadow: 0 15px 35px rgba(0, 0, 0, 0.5), 0 0 20px rgba(59, 130, 246, 0.15);
}

/* Day Mode compatibility */
[data-theme="dark"] .physics-ai-container,
.day-mode .physics-ai-container {
  --ai-bg-panel: rgba(248, 250, 252, 0.98);
  --ai-bg-card: rgba(241, 245, 249, 0.9);
  --ai-border: rgba(59, 130, 246, 0.3);
  --ai-text-main: #0f172a;
  --ai-text-dim: #475569;
  --ai-bot-bubble: rgba(226, 232, 240, 0.9);
  --ai-shadow: 0 15px 35px rgba(0, 0, 0, 0.15), 0 0 20px rgba(59, 130, 246, 0.1);
}

/* ══════════════════════════════════════════════════════
   1. Floating Trigger Button (الزر العائم)
   ══════════════════════════════════════════════════════ */
.physics-ai-trigger {
  position: fixed;
  bottom: 26px;
  left: 26px;
  right: auto;
  z-index: 9998;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #312e81 100%);
  color: #ffffff;
  padding: 8px 18px 8px 12px;
  border-radius: 9999px;
  box-shadow: 0 8px 25px rgba(30, 58, 138, 0.6), 0 0 20px rgba(59, 130, 246, 0.4);
  cursor: pointer;
  border: 1.8px solid rgba(251, 191, 36, 0.45);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Readex Pro', 'Cairo', system-ui, sans-serif;
  direction: rtl;
}

.physics-ai-trigger.is-dragging {
  cursor: grabbing !important;
  opacity: 0.92;
  transform: scale(1.08) !important;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.7), 0 0 35px rgba(59, 130, 246, 0.7) !important;
  transition: none !important;
}

.physics-ai-trigger:hover {
  transform: translateY(-4px) scale(1.05);
  border-color: #fbbf24;
  box-shadow: 0 14px 35px rgba(30, 58, 138, 0.7), 0 0 30px rgba(251, 191, 36, 0.6);
}

.physics-ai-trigger:active {
  transform: translateY(0) scale(0.97);
}

.physics-ai-trigger .trigger-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fbbf24;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.6);
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.physics-ai-trigger:hover .trigger-avatar {
  transform: rotate(5deg) scale(1.1);
}

.physics-ai-trigger .trigger-icon {
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ai-pulse-rotate 8s linear infinite;
}

@keyframes ai-pulse-rotate {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(180deg) scale(1.1); }
  100% { transform: rotate(360deg); }
}

.physics-ai-trigger .trigger-text {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.physics-ai-trigger .trigger-sub {
  font-size: 0.7rem;
  opacity: 0.85;
  font-weight: 400;
}

.physics-ai-trigger .trigger-badge {
  background: #fbbf24;
  color: #0f172a;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 9999px;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
  animation: ai-badge-pulse 2s ease-in-out infinite;
}

@keyframes ai-badge-pulse {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

/* ══════════════════════════════════════════════════════
   2. Main Assistant Window (النافذة الرئيسية)
   ══════════════════════════════════════════════════════ */
.physics-ai-panel {
  position: fixed;
  bottom: 86px;
  left: 26px;
  right: auto;
  width: 480px;
  max-width: calc(100vw - 32px);
  height: 640px;
  max-height: calc(100vh - 110px);
  max-height: calc(100dvh - 100px);
  z-index: 9999;
  background: var(--ai-bg-panel);
  border: 1.5px solid var(--ai-border);
  border-radius: 24px;
  box-shadow: var(--ai-shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Readex Pro', 'Cairo', system-ui, sans-serif;
  direction: rtl;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.physics-ai-panel.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.physics-ai-panel.maximized {
  width: min(960px, 95vw) !important;
  max-width: 95vw !important;
  height: min(88vh, 88dvh) !important;
  max-height: calc(100vh - 30px) !important;
  bottom: 16px !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%) translateY(0) scale(1) !important;
  border-radius: 24px !important;
  transition: all 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
}

/* Mobile Pull Handle */
.ai-mobile-handle {
  display: none;
  width: 100%;
  padding: 8px 0 2px;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  background: transparent;
}

.ai-mobile-handle span {
  width: 42px;
  height: 5px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 9999px;
  transition: background 0.2s ease;
}

.ai-mobile-handle:hover span {
  background: #38bdf8;
}

/* Panel Header */
.ai-panel-header {
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(30, 58, 138, 0.35) 0%, rgba(15, 23, 42, 0) 100%);
  border-bottom: 1px solid var(--ai-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.ai-panel-header.is-panel-dragging,
.ai-panel-header:active {
  cursor: grabbing;
}
  gap: 12px;
}

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

.ai-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #fbbf24;
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #080d1a;
}

.ai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-title-text h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ai-text-main);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-title-text p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ai-text-dim);
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--ai-text-dim);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.85rem;
}

.ai-btn-icon:hover {
  background: rgba(59, 130, 246, 0.2);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.4);
}

.ai-btn-icon.close:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.4);
}

/* Current Lesson Pill / Context Banner */
.ai-context-banner {
  padding: 6px 16px;
  background: rgba(59, 130, 246, 0.1);
  border-bottom: 1px solid rgba(59, 130, 246, 0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #38bdf8;
  gap: 8px;
}

.ai-context-banner .lesson-title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-status-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: #34d399;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* ══════════════════════════════════════════════════════
   3. Tabs Navigation (شريط التبويبات)
   ══════════════════════════════════════════════════════ */
.ai-tabs-nav {
  display: flex;
  padding: 6px 10px;
  gap: 6px;
  background: rgba(10, 16, 30, 0.6);
  border-bottom: 1px solid var(--ai-border);
  overflow-x: auto;
}

.ai-tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ai-text-dim);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.ai-tab-btn:hover {
  color: var(--ai-text-main);
  background: rgba(255, 255, 255, 0.05);
}

.ai-tab-btn.active {
  background: rgba(59, 130, 246, 0.18);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ══════════════════════════════════════════════════════
   4. Tab Panes (محتوى التبويبات)
   ══════════════════════════════════════════════════════ */
.ai-tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.ai-pane {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.ai-pane.active {
  display: flex;
}

/* ─── Pane 1: Chat (المعلم الافتراضي) ─── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}

.ai-bubble {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.86rem;
  line-height: 1.7;
  word-break: break-word;
  animation: ai-bubble-in 0.25s ease;
}

@keyframes ai-bubble-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-bubble.user {
  align-self: flex-start;
  background: var(--ai-user-bubble);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.ai-bubble.bot {
  align-self: flex-end;
  background: var(--ai-bot-bubble);
  color: var(--ai-text-main);
  border: 1px solid var(--ai-border);
  border-bottom-left-radius: 4px;
}

.ai-bubble.bot h1, .ai-bubble.bot h2, .ai-bubble.bot h3, .ai-bubble.bot h4 {
  color: #38bdf8;
  margin: 6px 0;
  font-size: 0.95rem;
}

.ai-bubble.bot ul, .ai-bubble.bot ol {
  padding-right: 18px;
  margin: 6px 0;
}

.ai-bubble.bot strong {
  color: #fbbf24;
}

.ai-bubble.bot code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.82rem;
  color: #a78bfa;
}

.ai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--ai-bot-bubble);
  border: 1px solid var(--ai-border);
  border-radius: 14px;
  width: fit-content;
  align-self: flex-end;
}

.ai-typing-indicator span {
  width: 6px;
  height: 6px;
  background: #38bdf8;
  border-radius: 50%;
  animation: ai-typing-bounce 1.2s infinite ease-in-out;
}
.ai-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Quick Prompts Chips */
.ai-quick-chips {
  padding: 8px 12px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(10, 16, 30, 0.4);
}
.ai-quick-chips::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: #93c5fd;
  padding: 5px 11px;
  border-radius: 9999px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-chip:hover {
  background: rgba(59, 130, 246, 0.25);
  color: #ffffff;
  border-color: rgba(56, 189, 248, 0.5);
  transform: translateY(-1px);
}

/* Chat Input Bar */
.ai-input-bar {
  padding: 10px 14px;
  background: rgba(10, 16, 30, 0.7);
  border-top: 1px solid var(--ai-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-input-bar input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px 14px;
  color: var(--ai-text-main);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: all 0.2s ease;
}

.ai-input-bar input:focus {
  border-color: #38bdf8;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

.ai-send-btn {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}

.ai-send-btn:hover {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  transform: scale(1.05);
}

.ai-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ─── Pane 2: Problem Solver (حل المسائل) ─── */
.ai-solver-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-solver-card {
  background: var(--ai-bg-card);
  border: 1px solid var(--ai-border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-solver-card label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-solver-card textarea {
  width: 100%;
  height: 110px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ai-text-main);
  font-family: inherit;
  font-size: 0.85rem;
  resize: vertical;
  outline: none;
}

.ai-solver-card textarea:focus {
  border-color: #38bdf8;
}

.ai-action-btn {
  background: linear-gradient(135deg, #2563eb, #8b5cf6);
  color: #ffffff;
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.35);
}

.ai-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
}

.ai-solution-box {
  background: var(--ai-bg-card);
  border: 1.5px solid rgba(56, 189, 248, 0.3);
  border-radius: 16px;
  padding: 16px;
  font-size: 0.85rem;
  line-height: 1.8;
  color: var(--ai-text-main);
}

/* ─── Pane 3: Quiz Generator (اختبرني) ─── */
.ai-quiz-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.ai-quiz-opt {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--ai-text-main);
  font-size: 0.84rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-quiz-opt:hover:not(.disabled) {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(56, 189, 248, 0.4);
}

.ai-quiz-opt.correct {
  background: rgba(16, 185, 129, 0.2) !important;
  border-color: #10b981 !important;
  color: #34d399 !important;
}

.ai-quiz-opt.incorrect {
  background: rgba(239, 68, 68, 0.2) !important;
  border-color: #ef4444 !important;
  color: #f87171 !important;
}

.ai-quiz-feedback {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.7;
}
.ai-quiz-feedback.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
}
.ai-quiz-feedback.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* ─── Pane 4: Teacher's Corner (ركن المعلم) ─── */
.ai-teacher-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ai-teacher-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ai-tool-card {
  background: var(--ai-bg-card);
  border: 1px solid var(--ai-border);
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ai-tool-card:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: #38bdf8;
  transform: translateY(-2px);
}

.ai-tool-card i {
  font-size: 1.1rem;
  color: #fbbf24;
}

.ai-tool-card .tool-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ai-text-main);
}

.ai-tool-card .tool-desc {
  font-size: 0.7rem;
  color: var(--ai-text-dim);
}

/* Settings Modal */
.ai-settings-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(8, 13, 26, 0.95);
  z-index: 100;
  padding: 24px;
  display: none;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(10px);
}
.ai-settings-modal.active {
  display: flex;
}

/* ─── Pane 5: Instant Simulation & Game Lab (مختبر المحاكاة والألعاب) ─── */
.ai-lab-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-sim-sandbox {
  background: #050811;
  border: 1.5px solid rgba(56, 189, 248, 0.35);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  flex: 1;
  min-height: 380px;
}

.ai-sim-header-bar {
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(56, 189, 248, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ai-sim-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #38bdf8;
}

.ai-sim-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-sim-iframe {
  width: 100%;
  height: 100%;
  flex: 1;
  min-height: 350px;
  border: none;
  background: #020617;
}

/* ─── Simulation Generator Action Card in Chat ─── */
.ai-sim-action-card {
  margin-top: 10px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.22), rgba(15, 23, 42, 0.95));
  border: 1.5px solid rgba(16, 185, 129, 0.5);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45), 0 0 15px rgba(16, 185, 129, 0.2);
  animation: ai-bubble-in 0.3s ease;
}

.ai-sim-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-sim-card-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

.ai-sim-card-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: #34d399;
}

.ai-sim-card-sub {
  font-size: 0.77rem;
  color: #cbd5e1;
  margin-top: 2px;
  line-height: 1.4;
}

.ai-sim-card-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-sim-launch-btn {
  flex: 1;
  min-width: 180px;
  background: linear-gradient(135deg, #059669, #10b981);
  color: #ffffff;
  border: none;
  padding: 9px 15px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

.ai-sim-launch-btn:hover {
  background: linear-gradient(135deg, #047857, #059669);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.6);
}

.ai-sim-existing-btn {
  background: rgba(59, 130, 246, 0.18);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #38bdf8;
  padding: 9px 12px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.ai-sim-existing-btn:hover {
  background: rgba(59, 130, 246, 0.3);
  color: #ffffff;
  border-color: #38bdf8;
}

/* ─── Platform Co-Pilot Navigation Card ─── */
.ai-nav-card {
  margin-top: 10px;
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.45), rgba(15, 23, 42, 0.8));
  border: 1.5px solid rgba(56, 189, 248, 0.45);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  animation: ai-bubble-in 0.3s ease;
}

.ai-nav-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: #f8fafc;
  line-height: 1.4;
}

.ai-nav-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.ai-nav-btn {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
  flex-shrink: 0;
}

.ai-nav-btn:hover {
  background: linear-gradient(135deg, #0369a1, #1d4ed8);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.6);
}

/* ─── YouTube Video Card ─── */
.ai-yt-card {
  margin-top: 10px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.22), rgba(15, 23, 42, 0.85));
  border: 1.5px solid rgba(239, 68, 68, 0.45);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 4px 18px rgba(239, 68, 68, 0.25);
  animation: ai-bubble-in 0.3s ease;
}

.ai-yt-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: #f8fafc;
  line-height: 1.4;
}

.ai-yt-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.ai-yt-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  text-decoration: none;
  flex-shrink: 0;
}

.ai-yt-btn:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.6);
  color: #fff;
}

/* ─── Direct Contact & Messaging Card ─── */
.ai-contact-card {
  margin-top: 10px;
  background: linear-gradient(135deg, rgba(14, 116, 144, 0.28), rgba(15, 23, 42, 0.92));
  border: 1.5px solid rgba(56, 189, 248, 0.5);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.4);
  animation: ai-bubble-in 0.3s ease;
  color: #f1f5f9;
}

.ai-contact-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-contact-badge {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.35);
}

.ai-contact-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: #38bdf8;
}

.ai-contact-sub {
  font-size: 0.74rem;
  color: #94a3b8;
  margin-top: 2px;
}

.ai-field-group {
  margin-bottom: 10px;
}

.ai-field-group label {
  display: block;
  font-size: 0.76rem;
  color: #cbd5e1;
  margin-bottom: 4px;
  font-weight: 600;
}

.ai-field-group label i {
  color: #38bdf8;
  margin-left: 4px;
}

.ai-field-input {
  width: 100%;
  box-sizing: border-box;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  padding: 8px 10px;
  color: #fff;
  font-family: inherit;
  font-size: 0.8rem;
  outline: none;
  transition: all 0.2s ease;
}

.ai-field-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.ai-field-input option {
  background: #0f172a;
  color: #fff;
}

.ai-contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.ai-send-mail-btn {
  flex: 1;
  min-width: 170px;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  border: none;
  padding: 9px 14px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.35);
}

.ai-send-mail-btn:hover {
  background: linear-gradient(135deg, #0369a1, #1d4ed8);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.5);
}

.ai-copy-mail-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e2e8f0;
  padding: 9px 14px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.ai-copy-mail-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: #38bdf8;
  color: #38bdf8;
}

.ai-contact-status {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.77rem;
  line-height: 1.5;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}

.ai-webmail-links {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 0.72rem;
  color: #94a3b8;
  flex-wrap: wrap;
}

.ai-webmail-btn {
  color: #38bdf8;
  text-decoration: none;
  background: rgba(56, 189, 248, 0.12);
  padding: 3px 8px;
  border-radius: 6px;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ai-webmail-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  color: #fff;
}

/* ══════════════════════════════════════════════════════
   5. Classroom Smartboard Mode (نمط السبورة الذكية والشاشات الصفية)
   ══════════════════════════════════════════════════════ */
.physics-ai-panel.classroom-smart-mode {
  --ai-font-base: 1.15rem;
}
.physics-ai-panel.classroom-smart-mode .ai-title-text h3 {
  font-size: 1.25rem;
}
.physics-ai-panel.classroom-smart-mode .ai-title-text p {
  font-size: 0.85rem;
}
.physics-ai-panel.classroom-smart-mode .ai-bubble {
  font-size: 1.12rem;
  line-height: 1.95;
  padding: 16px 20px;
}
.physics-ai-panel.classroom-smart-mode .ai-bubble.bot h1,
.physics-ai-panel.classroom-smart-mode .ai-bubble.bot h2,
.physics-ai-panel.classroom-smart-mode .ai-bubble.bot h3 {
  font-size: 1.3rem;
  margin: 10px 0;
}
.physics-ai-panel.classroom-smart-mode .katex {
  font-size: 1.35em !important;
}
.physics-ai-panel.classroom-smart-mode .ai-tab-btn {
  font-size: 0.95rem;
  padding: 12px 16px;
  gap: 8px;
}
.physics-ai-panel.classroom-smart-mode .ai-chip {
  font-size: 0.92rem;
  padding: 9px 16px;
}
.physics-ai-panel.classroom-smart-mode .ai-input-bar input {
  font-size: 1.05rem;
  padding: 14px 18px;
}
.physics-ai-panel.classroom-smart-mode .ai-send-btn {
  width: 48px;
  height: 48px;
  font-size: 1.15rem;
}
.physics-ai-panel.classroom-smart-mode .ai-solver-card label {
  font-size: 1.05rem;
}
.physics-ai-panel.classroom-smart-mode .ai-solver-card textarea {
  font-size: 1.05rem;
  height: 140px;
  line-height: 1.8;
}
.physics-ai-panel.classroom-smart-mode .ai-action-btn {
  font-size: 1.05rem;
  padding: 14px 22px;
}
.physics-ai-panel.classroom-smart-mode .ai-quiz-opt {
  font-size: 1.08rem;
  padding: 14px 20px;
}
.physics-ai-panel.classroom-smart-mode #aiQuizQuestion {
  font-size: 1.25rem !important;
  line-height: 1.8 !important;
}

/* Toast Notification */
.ai-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  border: 1.5px solid #38bdf8;
  padding: 10px 22px;
  border-radius: 9999px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(56, 189, 248, 0.4);
  z-index: 999999;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
  direction: rtl;
}
.ai-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* KaTeX formula scrolling across all devices */
.ai-bubble .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 6px 2px;
  -webkit-overflow-scrolling: touch;
}
.ai-bubble .katex-display::-webkit-scrollbar {
  height: 4px;
}
.ai-bubble .katex-display::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

/* ══════════════════════════════════════════════════════
   6. Ultra-Wide & 4K Smart TVs / Classroom Displays (>= 1600px)
   ══════════════════════════════════════════════════════ */
@media (min-width: 1600px) {
  .physics-ai-panel.maximized {
    width: min(1380px, 92vw) !important;
    height: 90vh !important;
  }
}

/* ══════════════════════════════════════════════════════
   7. Tablets & iPads (641px to 1024px)
   ══════════════════════════════════════════════════════ */
@media (min-width: 641px) and (max-width: 1024px) {
  .physics-ai-panel {
    width: 520px;
    max-width: calc(100vw - 32px);
    height: min(720px, calc(100vh - 120px));
  }
  .physics-ai-panel.maximized {
    width: min(920px, 94vw) !important;
    height: 90vh !important;
    max-height: calc(100vh - 40px) !important;
  }
  .ai-tab-btn {
    padding: 9px 12px;
    font-size: 0.82rem;
  }
}

/* ══════════════════════════════════════════════════════
   8. Mobile Devices (<= 640px)
   ══════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .physics-ai-panel {
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100vw !important;
    height: 92dvh !important;
    height: 92vh !important;
    max-width: 100vw !important;
    max-height: 96dvh !important;
    border-radius: 24px 24px 0 0 !important;
    transform: translateY(100%);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
  }

  .physics-ai-panel.active {
    transform: translateY(0) !important;
  }

  .physics-ai-panel.maximized {
    width: 100vw !important;
    height: 98dvh !important;
    height: 98vh !important;
    max-height: 100dvh !important;
    bottom: 0 !important;
    left: 0 !important;
    transform: translateY(0) !important;
    border-radius: 20px 20px 0 0 !important;
  }

  .ai-mobile-handle {
    display: flex !important;
  }

  .physics-ai-trigger {
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    left: max(16px, env(safe-area-inset-left, 16px));
    padding: 7px 12px;
    gap: 8px;
  }

  .physics-ai-trigger .trigger-avatar {
    width: 38px;
    height: 38px;
  }

  .physics-ai-trigger .trigger-text {
    font-size: 0.84rem;
  }

  .physics-ai-trigger .trigger-sub {
    display: none;
  }

  .ai-panel-header {
    padding: 10px 14px;
    cursor: default;
  }

  .ai-avatar {
    width: 36px;
    height: 36px;
  }

  .ai-title-text h3 {
    font-size: 0.88rem;
  }

  .ai-title-text p {
    font-size: 0.68rem;
  }

  .ai-tabs-nav {
    padding: 4px 8px;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ai-tabs-nav::-webkit-scrollbar {
    display: none;
  }

  .ai-tab-btn {
    padding: 7px 10px;
    font-size: 0.75rem;
    gap: 4px;
  }

  .ai-bubble {
    max-width: 94%;
    padding: 10px 14px;
    font-size: 0.84rem;
  }

  .ai-input-bar {
    padding: 8px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  }

  .ai-input-bar input {
    padding: 8px 12px;
    font-size: 0.82rem;
  }

  .ai-send-btn {
    width: 38px;
    height: 38px;
    font-size: 0.88rem;
  }

  .ai-teacher-tools {
    grid-template-columns: 1fr;
  }

  .ai-sim-sandbox {
    min-height: 280px;
  }

  .ai-sim-iframe {
    min-height: 260px;
  }
}

/* ══════════════════════════════════════════════════════
   9. Mobile Landscape Mode (max-height: 520px)
   ══════════════════════════════════════════════════════ */
@media (max-height: 520px) {
  .physics-ai-panel {
    height: 100dvh !important;
    height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    bottom: 0 !important;
  }

  .ai-panel-header {
    padding: 6px 12px;
  }

  .ai-avatar {
    width: 28px;
    height: 28px;
  }

  .ai-title-text h3 {
    font-size: 0.82rem;
  }

  .ai-title-text p {
    display: none;
  }

  .ai-context-banner {
    padding: 3px 12px;
    font-size: 0.7rem;
  }

  .ai-tabs-nav {
    padding: 3px 6px;
  }

  .ai-tab-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
  }

  .ai-chat-messages {
    padding: 8px 12px;
    gap: 8px;
  }

  .ai-input-bar {
    padding: 6px 12px;
  }
}

/* ══════════════════════════════════════════════════════
   10. Extra Small Screens (<= 380px)
   ══════════════════════════════════════════════════════ */
@media (max-width: 380px) {
  .physics-ai-trigger {
    padding: 6px 10px;
    gap: 6px;
  }
  .physics-ai-trigger .trigger-avatar {
    width: 34px;
    height: 34px;
  }
  .physics-ai-trigger .trigger-text {
    font-size: 0.78rem;
  }
  .ai-tab-btn {
    padding: 6px 7px;
    font-size: 0.7rem;
  }
  .ai-chip {
    font-size: 0.68rem;
    padding: 4px 8px;
  }
}
