/* ai.css - D.BTEC AI Chat Interface - Premium Edition */

/* ===== AI Page Body Overrides ===== */
body.ai-page {
  margin: 0;
  padding: 0;
  font-family: 'IBM Plex Sans Arabic', sans-serif;
  direction: rtl;
  background-color: #F8FAFC;
  color: #0f172a;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  cursor: auto !important;
}

body.ai-page * {
  cursor: auto !important;
}

body.ai-page a,
body.ai-page button {
  cursor: pointer !important;
}

/* ===== Layout ===== */
.ai-layout {
  display: flex;
  flex-direction: row !important;
  height: 100vh;
  overflow: hidden;
}

/* ===== Header ===== */
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  z-index: 10;
  min-height: 56px;
}

.ai-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-header-title {
  font-weight: 700;
  color: #111835;
  font-size: 1.25rem;
  margin: 0;
}

.ai-menu-btn {
  display: none;
  background: none;
  border: none;
  color: #111835;
  font-size: 1.25rem;
  padding: 0.5rem;
  cursor: pointer !important;
}

/* ===== Sidebar ===== */
.ai-sidebar {
  width: 300px;
  background: linear-gradient(180deg, #111835 0%, #0d1229 100%);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
  border-left: 1px solid rgba(255,255,255,0.06);
}

.ai-sidebar-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.ai-sidebar-header .ai-logo-link {
  margin-right: auto; /* Pushes the logo to the left in RTL */
}

.ai-sidebar-header .ai-logo-link img {
  height: 28px;
  opacity: 0.9;
  transition: opacity 0.2s;
}

.ai-sidebar-header .ai-logo-link img:hover {
  opacity: 1;
}

.ai-sidebar-close {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 1.25rem;
  padding: 0.25rem;
  cursor: pointer !important;
}

.ai-sidebar-close:hover {
  color: white;
}

/* New Chat Button */
.ai-new-chat-btn {
  width: calc(100% - 2rem);
  margin: 1rem;
  padding: 0.875rem;
  background: linear-gradient(135deg, #F8D613 0%, #f0c800 100%);
  color: #111835;
  border: none;
  font-weight: 700;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer !important;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 0 !important;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(248, 214, 19, 0.2);
}

.ai-new-chat-btn:hover {
  background: linear-gradient(135deg, #f0c800 0%, #e6bc00 100%);
  box-shadow: 0 4px 12px rgba(248, 214, 19, 0.35);
  transform: translateY(-1px);
}

.ai-new-chat-btn:active {
  transform: translateY(0);
}

/* Retention Note */
.ai-retention-note {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.35);
  text-align: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* Conversations List */
.ai-conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.ai-conversations-list::-webkit-scrollbar {
  width: 4px;
}
.ai-conversations-list::-webkit-scrollbar-track {
  background: transparent;
}
.ai-conversations-list::-webkit-scrollbar-thumb {
  background-color: rgba(248, 214, 19, 0.3);
  border-radius: 0;
}
.ai-conversations-list::-webkit-scrollbar-thumb:hover {
  background-color: rgba(248, 214, 19, 0.5);
}

.ai-conversation-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 2px;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer !important;
  border-radius: 0 !important;
  transition: all 0.15s ease;
  font-size: 0.875rem;
  position: relative;
}

.ai-conversation-item:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
}

.ai-conversation-item.active {
  background-color: rgba(248, 214, 19, 0.1);
  color: white;
  border-right: 3px solid #F8D613;
}

.ai-conversation-item i.far {
  font-size: 0.85rem;
  opacity: 0.6;
  flex-shrink: 0;
}

.ai-conversation-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.ai-conversation-delete {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.3);
  cursor: pointer !important;
  padding: 0.25rem;
  font-size: 0.75rem;
  opacity: 0;
  transition: all 0.15s ease;
}

.ai-conversation-item:hover .ai-conversation-delete {
  opacity: 1;
}

.ai-conversation-delete:hover {
  color: #ef4444;
}

/* Sidebar Footer */
.ai-sidebar-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ai-user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.ai-user-avatar {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #0248C1 0%, #0356e0 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 0 !important;
  flex-shrink: 0;
}

.ai-user-details {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  overflow: hidden;
}

.ai-user-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: white;
}

.ai-user-email {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-sidebar-actions {
  display: flex;
  gap: 0.5rem;
}

.ai-sidebar-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  font-size: 0.8rem;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer !important;
  border-radius: 0 !important;
  transition: all 0.15s ease;
}

.ai-sidebar-action-btn:hover {
  background: rgba(255,255,255,0.12);
  color: white;
}

/* ===== Chat Main Area ===== */
.ai-chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: #F8FAFC;
  min-width: 0;
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  z-index: 10;
}

.ai-header-right, .ai-header-left {
  display: flex;
  align-items: center;
}

.ai-header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #111835;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-beta-badge {
  font-size: 0.65rem;
  background: linear-gradient(135deg, #F8D613 0%, #f0c800 100%);
  color: #111835;
  padding: 0.2rem 0.5rem;
  font-weight: 800;
  letter-spacing: 1px;
}

.ai-messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2rem 1rem;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

.ai-messages-area::-webkit-scrollbar {
  width: 6px;
}
.ai-messages-area::-webkit-scrollbar-track {
  background: transparent;
}
.ai-messages-area::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 0;
}
.ai-messages-area::-webkit-scrollbar-thumb:hover {
  background-color: #94a3b8;
}

.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

/* ===== Message Bubbles ===== */
.ai-message {
  max-width: 82%;
  padding: 1rem 1.25rem;
  border-radius: 0 !important;
  line-height: 1.75;
  font-size: 0.95rem;
  animation: messageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

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

.ai-message-user {
  align-self: flex-start; /* In RTL cross-axis starts at Right */
  margin-right: 0;
  margin-left: auto; /* Push left to allow sizing */
  background: linear-gradient(135deg, #FFFDE6 0%, #fef9c3 100%);
  color: #111835;
  border: 1px solid rgba(248, 214, 19, 0.3);
  border-right: 3px solid #F8D613;
}

.ai-message-assistant {
  align-self: flex-end; /* In RTL cross-axis ends at Left */
  margin-left: 0;
  margin-right: auto; /* Push right */
  background: linear-gradient(135deg, #EEF4FF 0%, #e0ebfb 100%);
  color: #111835;
  border: 1px solid rgba(2, 72, 193, 0.12);
  border-right: 3px solid #0248C1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.ai-message-error {
  align-self: center;
  margin: 0.75rem auto;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-right: 3px solid #ef4444;
  text-align: center;
  max-width: 90%;
  font-size: 0.875rem;
}

/* ===== Markdown in Messages ===== */
.ai-message-content {
  text-align: right;
}

.ai-message h1, .ai-message h2, .ai-message h3, .ai-message h4 {
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
  color: #111835;
  font-weight: 700;
}

.ai-message h1 { font-size: 1.25rem; }
.ai-message h2 { font-size: 1.15rem; }
.ai-message h3 { font-size: 1.05rem; }

.ai-message p {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.ai-message p:last-child {
  margin-bottom: 0;
}

.ai-message ul, .ai-message ol {
  padding-right: 1.5rem;
  margin-bottom: 0.75rem;
}

.ai-message li {
  margin-bottom: 0.25rem;
}

.ai-message blockquote {
  border-right: 3px solid #0248C1;
  margin: 0.5rem 0;
  padding: 0.5rem 1rem 0.5rem 0;
  background: rgba(2, 72, 193, 0.04);
  color: #334155;
}

.ai-message code {
  font-family: 'Fira Code', 'Cascadia Code', monospace;
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.15rem 0.4rem;
  font-size: 0.85em;
  border-radius: 0 !important;
}

.ai-message pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  border-radius: 0 !important;
  margin: 0.5rem 0;
  border-left: 3px solid #F8D613;
}

.ai-message pre code {
  background: transparent;
  padding: 0;
  font-size: 0.85rem;
}

.ai-message strong {
  color: #111835;
  font-weight: 700;
}

.ai-message a {
  color: #0248C1;
  text-decoration: underline;
}

/* ===== Typing Indicator (4 dots) ===== */
.ai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  align-self: flex-end; /* Left in RTL */
  margin-right: auto;
  margin-left: 0;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #EEF4FF 0%, #e0ebfb 100%);
  border: 1px solid rgba(2, 72, 193, 0.12);
  border-right: 3px solid #0248C1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  animation: messageSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ai-typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 0 !important;
  display: inline-block;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

/* Alternating: blue, yellow, blue, yellow */
.ai-typing-dots span:nth-child(1) { background-color: #0248C1; animation-delay: 0s; }
.ai-typing-dots span:nth-child(2) { background-color: #F8D613; animation-delay: 0.15s; }
.ai-typing-dots span:nth-child(3) { background-color: #0248C1; animation-delay: 0.3s; }
.ai-typing-dots span:nth-child(4) { background-color: #F8D613; animation-delay: 0.45s; }

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0) scale(1);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px) scale(1.2);
    opacity: 1;
  }
}

.ai-typing-label {
  font-size: 0.8rem;
  color: #94a3b8;
  font-weight: 500;
}

/* ===== Welcome State ===== */
.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 2rem;
  animation: fadeIn 0.5s ease;
}

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

.ai-welcome-icon {
  font-size: 3rem;
  color: #0248C1;
  margin-bottom: 1rem;
  opacity: 0.8;
}

.ai-welcome-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: #111835;
  margin-bottom: 0.5rem;
}

.ai-welcome-desc {
  color: #64748b;
  margin-bottom: 2.5rem;
  max-width: 500px;
  font-size: 0.95rem;
  line-height: 1.7;
}

.ai-suggestions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  max-width: 720px;
  width: 100%;
}

.ai-suggestion-chip {
  background: white;
  border: 1px solid #e2e8f0;
  padding: 1rem;
  text-align: right;
  cursor: pointer !important;
  border-radius: 0 !important;
  transition: all 0.2s ease;
  font-family: inherit;
  font-size: 0.85rem;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  line-height: 1.5;
}

.ai-suggestion-chip i {
  color: #0248C1;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.ai-suggestion-chip:hover {
  border-color: #F8D613;
  background: #FFFDE6;
  box-shadow: 0 4px 12px rgba(248, 214, 19, 0.15);
  transform: translateY(-2px);
}

.ai-suggestion-chip:active {
  transform: translateY(0);
}

.ai-input-area {
  padding: 0.75rem 2rem 1.5rem;
  background: #F8FAFC;
}

.ai-input-wrapper {
  max-width: 900px;
  margin: 0 auto 2.5rem;
}

.ai-input-box {
  display: flex;
  align-items: flex-end;
  background: white;
  border: 2px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border-radius: 0 !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-input-box:focus-within {
  border-color: #0248C1;
  box-shadow: 0 0 0 3px rgba(2, 72, 193, 0.1);
}

.ai-attach-btn {
  background: none !important;
  border: none !important;
  color: #94a3b8 !important;
  cursor: pointer !important;
  font-size: 1.1rem !important;
  padding: 0.875rem !important;
  transition: color 0.2s !important;
}

.ai-attach-btn:hover {
  color: #0248C1 !important;
}

.ai-input {
  flex: 1;
  border: none;
  padding: 0.875rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  max-height: 160px;
  background: transparent;
  color: #0f172a;
  line-height: 1.5;
}

.ai-input:focus {
  outline: none;
}

.ai-input::placeholder {
  color: #94a3b8;
}

.ai-input-actions {
  display: flex;
  align-items: flex-end;
  padding: 0.5rem;
  gap: 0.25rem;
}

.ai-char-count {
  font-size: 0.7rem;
  color: #94a3b8;
  padding: 0.5rem 0.25rem;
  white-space: nowrap;
}

.ai-send-btn, .ai-stop-btn {
  background: none;
  border: none;
  cursor: pointer !important;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 0 !important;
  transition: all 0.2s ease;
}

.ai-send-btn {
  color: #0248C1;
  background: rgba(2, 72, 193, 0.08);
}

.ai-send-btn:hover {
  background: rgba(2, 72, 193, 0.15);
}

.ai-send-btn:disabled {
  color: #cbd5e1;
  background: transparent;
  cursor: not-allowed !important;
}

.ai-stop-btn {
  color: white;
  background: #ef4444;
}

.ai-stop-btn:hover {
  background: #dc2626;
}

/* Disclaimer */
.ai-disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: #94a3b8;
  margin: 0.5rem 0 0;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

/* Attachments Preview */
#ai-attachments-preview {
  max-width: 900px;
  margin: 0 auto 0.5rem;
}

/* ===== Limit Modal ===== */
.ai-limit-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.ai-limit-modal-content {
  background: white;
  padding: 3rem;
  text-align: center;
  max-width: 400px;
  width: 90%;
  border-radius: 0 !important;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.ai-limit-icon {
  font-size: 3rem;
  color: #f59e0b;
  margin-bottom: 1rem;
}

.ai-limit-modal-content h3 {
  color: #111835;
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
}

.ai-limit-modal-content p {
  color: #64748b;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.ai-limit-home-btn {
  display: inline-block;
  padding: 0.75rem 2rem;
  background: #0248C1;
  color: white;
  text-decoration: none;
  font-weight: 600;
  font-family: inherit;
  border-radius: 0 !important;
  transition: background 0.2s;
}

.ai-limit-home-btn:hover {
  background: #003799;
}

/* ===== Mobile Sidebar Backdrop ===== */
.ai-sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
  backdrop-filter: blur(2px);
}

.ai-sidebar-backdrop.open {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .ai-message { max-width: 90%; }
  .ai-suggestions { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .ai-menu-btn { display: flex; }
  .ai-sidebar-close { display: block; }

  .ai-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: -300px;
    width: 300px;
    height: 100%;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .ai-sidebar.open {
    right: 0;
  }

  .ai-suggestions { grid-template-columns: 1fr 1fr; }
  .ai-messages-area { padding: 1rem; }
  .ai-message { max-width: 95%; padding: 0.875rem 1rem; }
  .ai-input-area { padding: 0.5rem 1rem 0.75rem; }
  .ai-welcome-title { font-size: 1.5rem; }
  .ai-welcome-desc { font-size: 0.875rem; }
}

@media (max-width: 480px) {
  .ai-suggestions { grid-template-columns: 1fr; }
  .ai-welcome-title { font-size: 1.25rem; }
}
