:root {
  --bg: #070709;
  --sidebar-bg: #0C0C0F;
  --card: rgba(22, 22, 27, 0.75);
  --card-border: rgba(255, 107, 0, 0.15);
  --primary: #FF6B00;
  --primary-light: #FF8833;
  --primary-glow: rgba(255, 107, 0, 0.35);
  --text: #F4F4F6;
  --muted: #8E8E96;
  --danger: #FF4D4D;
  --mono: 'JetBrains Mono', monospace;
  --display: 'Space Grotesk', sans-serif;
  --body: 'Inter', sans-serif;
  --glass-bg: rgba(12, 12, 15, 0.75);
  --glass-blur: blur(12px);
  --border-glow: rgba(255, 107, 0, 0.2);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }
::-webkit-scrollbar-track { background: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  overflow: hidden;
}

#canvas-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
  z-index: 1;
}

/* Glassmorphism Classes */
.sidebar, .card, .modal-card, .prompt-box {
  background: var(--glass-bg) !important;
  backdrop-filter: var(--glass-blur) !important;
  border: 1px solid var(--card-border) !important;
}

/* Smooth Transitions & Active States */
button, .history-item {
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

button:active { transform: scale(0.95); }

/* Message Arrival Animation */
@keyframes fadeInSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row {
  animation: fadeInSlideUp 0.4s ease-out forwards;
}

/* Loading Spinner Animation */
@keyframes spin {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.msg-row.loading .bubble.spinner {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 12px;
}

.msg-row.loading .bubble.spinner span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: spin 1.4s infinite;
}

.msg-row.loading .bubble.spinner span:nth-child(1) { animation-delay: 0s; }
.msg-row.loading .bubble.spinner span:nth-child(2) { animation-delay: 0.2s; }
.msg-row.loading .bubble.spinner span:nth-child(3) { animation-delay: 0.4s; }

/* Focus Glow for Input */
.prompt-box:focus-within {
  box-shadow: 0 0 15px var(--border-glow);
  border-color: var(--primary) !important;
}

/* SIDEBAR */
aside.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  flex-shrink: 0;
  z-index: 10;
  transition: width 0.3s ease, padding 0.3s ease;
}

/* Collapsed Sidebar State */
aside.sidebar.collapsed {
  width: 70px;
  padding: 16px 8px;
}

aside.sidebar.collapsed .brand-title,
aside.sidebar.collapsed .recents-title,
aside.sidebar.collapsed .new-chat-btn span,
aside.sidebar.collapsed .history-title,
aside.sidebar.collapsed .user-name,
aside.sidebar.collapsed .shortcut-tag {
  display: none;
}

aside.sidebar.collapsed .logo-core {
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
}

aside.sidebar.collapsed .new-chat-btn {
  padding: 10px;
  justify-content: center;
}

aside.sidebar.collapsed .history-item {
  justify-content: center;
}

aside.sidebar.collapsed .item-menu-btn {
  opacity: 0;
}

aside.sidebar.collapsed .clear-all-btn {
  display: none;
}

aside.sidebar.collapsed .user-info {
  justify-content: center;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 16px 8px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo-core {
  width: 28px;
  height: 28px;
  background: radial-gradient(circle, var(--primary) 0%, transparent 70%);
  border: 1px solid var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.75rem;
  color: #FFF;
  box-shadow: 0 0 10px var(--primary-glow);
}

.brand-title { font-family: var(--display); font-weight: 700; font-size: 1.1rem; }
.brand-title span { color: var(--primary); }

.version-badge {
  font-family: var(--mono);
  font-size: 0.65rem;
  background: rgba(255, 107, 0, 0.12);
  border: 1px solid var(--card-border);
  color: var(--primary-light);
  padding: 2px 6px;
  border-radius: 6px;
}

.new-chat-btn {
  background: rgba(255, 107, 0, 0.12);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  margin-bottom: 16px;
}

.new-chat-btn:hover {
  background: var(--primary);
  color: #070709;
  box-shadow: 0 0 18px var(--primary-glow);
}

.shortcut-tag {
  font-family: var(--mono);
  font-size: 0.65rem;
  background: rgba(255,255,255,0.1);
  padding: 2px 5px;
  border-radius: 4px;
}

.recents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 8px 8px;
}

.recents-title {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
}

.clear-all-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

.clear-all-btn:hover { color: var(--danger); background: rgba(255, 77, 77, 0.1); }

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: rgba(255,107,0,0.15); border-radius: 2px; }

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  color: #C0C0C6;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item.active {
  background: rgba(255, 107, 0, 0.15);
  border: 1px solid rgba(255, 107, 0, 0.3);
  color: #FFF;
}

.history-item:hover:not(.active) { color: var(--text); background: rgba(255, 107, 0, 0.08); }
.history-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; margin-right: 6px; }

.item-menu-btn {
  opacity: 0; background: transparent; border: none; color: var(--muted);
  cursor: pointer; padding: 2px 4px; border-radius: 4px; display: flex;
  align-items: center; justify-content: center;
}

.history-item:hover .item-menu-btn { opacity: 1; }

.dropdown-menu {
  display: none; position: absolute; right: 8px; top: 32px;
  background: #16161B; border: 1px solid var(--card-border);
  border-radius: 10px; padding: 6px; box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  z-index: 100; min-width: 120px;
}

.dropdown-menu.active { display: flex; flex-direction: column; gap: 2px; }

.dropdown-opt {
  background: transparent; border: none; color: var(--text); padding: 6px 10px;
  font-size: 0.78rem; border-radius: 6px; display: flex; align-items: center; gap: 8px;
  cursor: pointer; width: 100%;
}

.dropdown-opt:hover { background: rgba(255,255,255,0.06); }
.dropdown-opt.delete:hover { background: rgba(255, 77, 77, 0.15); color: var(--danger); }

/* USER PROFILE FOOTER */
.user-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px;
  border-top: 1px solid var(--card-border);
  margin-top: auto;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.user-profile:hover { background: rgba(255, 107, 0, 0.08); }
.user-info { display: flex; align-items: center; gap: 10px; overflow: hidden; }

.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #070709; font-weight: 700;
  font-size: 0.85rem; display: flex; align-items: center; justify-content: center;
  background-size: cover; background-position: center; flex-shrink: 0;
  border: 1px solid var(--card-border);
}

.user-name { font-size: 0.88rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* WORKSPACE */
.main-workspace {
  flex: 1; display: flex; flex-direction: column; height: 100vh; position: relative;
}

header {
  height: 60px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; border-bottom: 1px solid rgba(255,107,0,0.05);
}

.header-actions { display: flex; align-items: center; gap: 12px; }

.status-badge {
  font-family: var(--mono); font-size: 0.72rem; color: var(--primary-light);
  background: rgba(255, 107, 0, 0.08); border: 1px solid var(--card-border);
  padding: 5px 12px; border-radius: 20px; display: flex; align-items: center; gap: 8px;
}

.status-dot {
  width: 6px; height: 6px; background: var(--primary); border-radius: 50%;
  box-shadow: 0 0 10px var(--primary); animation: blink 1.8s infinite;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.chat-viewport {
  flex: 1; overflow-y: auto; padding: 20px; display: flex;
  flex-direction: column; align-items: center;
}

.chat-container { width: 100%; max-width: 800px; display: flex; flex-direction: column; gap: 24px; margin: auto 0; }

/* ULTRA SMOOTH TYPEWRITER GREETING */
.hero-greeting { text-align: center; }

.typewriter-title {
  font-size: clamp(1.6rem, 4vw, 2.8rem);
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  min-height: 1.2em;
}

.char {
  display: inline-block;
  opacity: 0;
  transform: translateY(4px) scale(0.95);
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), 
              transform 0.28s cubic-bezier(0.16, 1, 0.3, 1),
              font-family 0.4s ease,
              color 0.3s ease;
  will-change: opacity, transform;
}

.char.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.char.deleting {
  opacity: 0;
  transform: translateY(-4px) scale(0.9);
}

.char.highlight {
  color: var(--primary);
  text-shadow: 0 0 12px var(--primary-glow);
}

.cursor {
  display: inline-block;
  width: 8px;
  height: 0.82em;
  background: var(--primary);
  margin-left: 6px;
  border-radius: 2px;
  vertical-align: middle;
  box-shadow: 0 0 10px var(--primary-glow);
  animation: smoothCursorGlow 1.2s infinite ease-in-out;
}

@keyframes smoothCursorGlow {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 8px var(--primary)); }
  50% { opacity: 0.25; filter: drop-shadow(0 0 2px var(--primary)); }
}

.hero-greeting p { color: var(--muted); font-size: 1rem; font-family: var(--body); }

.message-list { display: flex; flex-direction: column; gap: 22px; width: 100%; padding-bottom: 20px; }

.msg-row { display: flex; gap: 12px; max-width: 88%; position: relative; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.ai { align-self: flex-start; }

.avatar {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.75rem; font-weight: 700;
  flex-shrink: 0; background-size: cover; background-position: center;
}

.user .avatar { background-color: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); }
.ai .avatar { background-color: var(--primary); color: #070709; }

.msg-content { display: flex; flex-direction: column; gap: 4px; }
.user .msg-content { align-items: flex-end; }

.bubble { padding: 14px 18px; border-radius: 16px; font-size: 0.95rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.user .bubble { background: rgba(255, 107, 0, 0.12); border: 1px solid rgba(255, 107, 0, 0.3); border-top-right-radius: 4px; }
.ai .bubble { background: var(--card); border: 1px solid var(--card-border); border-top-left-radius: 4px; }

.msg-toolbar { display: flex; align-items: center; gap: 8px; opacity: 0; transition: opacity 0.2s; margin-top: 2px; }
.msg-row:hover .msg-toolbar { opacity: 1; }

.tool-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.75rem; padding: 2px 6px; border-radius: 4px; display: flex; align-items: center; gap: 4px;
}
.tool-btn:hover { color: var(--text); background: rgba(255,255,255,0.08); }

.timestamp { font-family: var(--mono); font-size: 0.65rem; color: var(--muted); }

.input-wrapper { width: 100%; max-width: 800px; margin: 0 auto; padding: 0 20px 20px 20px; }

.prompt-box {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: 22px; padding: 10px 14px 10px 20px; display: flex; align-items: center; gap: 14px;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.prompt-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 15px rgba(255, 107, 0, 0.15);
}

.prompt-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: var(--body); font-size: 1rem;
}

.action-btn {
  background: var(--primary); color: #070709; border: none;
  width: 38px; height: 38px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
}

.action-btn:hover { box-shadow: 0 0 12px var(--primary-glow); }
.action-btn:active { transform: scale(0.92); }

.input-footer {
  text-align: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 15px;
  background: linear-gradient(90deg, #8E8E96 0%, #FFFFFF 50%, #8E8E96 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shine 3s infinite linear;
  letter-spacing: 0.5px;
}

@keyframes shine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* MODALS */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(8px); z-index: 1000; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal-card {
  background: #121216; border: 1px solid var(--card-border); border-radius: 20px;
  width: 100%; max-width: 460px; padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,0.8);
  display: flex; flex-direction: column; gap: 20px;
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-family: var(--display); font-size: 1.2rem; font-weight: 700; }
.close-modal-btn { background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 1.2rem; }

.modal-body { display: flex; flex-direction: column; gap: 16px; }

.avatar-upload-wrapper { position: relative; width: 80px; height: 80px; border-radius: 50%; cursor: pointer; margin: 0 auto; }

.modal-avatar-preview {
  width: 100%; height: 100%; border-radius: 50%; background: var(--primary);
  color: #070709; font-family: var(--display); font-weight: 700; font-size: 1.8rem;
  display: flex; align-items: center; justify-content: center; background-size: cover;
  background-position: center; border: 2px solid var(--primary);
}

.upload-overlay-ic {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s; color: #FFF;
}
.avatar-upload-wrapper:hover .upload-overlay-ic { opacity: 1; }

.form-group { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.form-label { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); text-transform: uppercase; }

.form-input {
  background: rgba(255,255,255,0.04); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 10px 14px; color: var(--text); font-family: var(--mono); font-size: 0.88rem; outline: none;
}
.form-input:focus { border-color: var(--primary); }

.modal-footer { display: flex; justify-content: flex-end; gap: 10px; }

.btn { padding: 9px 18px; border-radius: 10px; font-size: 0.85rem; font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; }
.btn-cancel { background: transparent; color: var(--muted); }
.btn-cancel:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-save { background: var(--primary); color: #070709; }
.btn-save:hover { box-shadow: 0 0 15px var(--primary-glow); }
/* Command Palette Style */
#cmdPalette {
  display: none; position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  width: 500px; background: #0C0C0F; border: 1px solid var(--card-border);
  border-radius: 16px; padding: 12px; box-shadow: 0 20px 50px rgba(0,0,0,0.8);
  z-index: 2000;
}
#cmdInput {
  width: 100%; background: transparent; border: none; outline: none;
  color: white; font-family: var(--mono); padding: 10px; font-size: 1rem;
}
.cmd-item {
  padding: 10px; color: var(--muted); cursor: pointer; border-radius: 8px;
  display: flex; justify-content: space-between; font-family: var(--mono);
}
.cmd-item.active { background: var(--primary); color: #000; }
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 15px; /* Adds space between the button and the badge */
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px; /* مخفية على اليسار */
    width: 280px;  /* تأكد إن العرض محدد */
    height: 100vh;
    z-index: 9999; /* رقم عالي باش تظهر فوق كل شي في الصفحة */
    transition: left 0.3s ease-in-out; /* حركة سلسة */
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5); /* ضل باش تبان طالعة فوق الصفحة */
  }

  /* كي نزيدو كلاس active تخرج الـ sidebar */
  .sidebar.active {
    left: 0 !important;
  }
}
.logo-core {
  width: 36px;
  height: 36px;
  background-color: #FF6A00;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;             
}

.logo-core img {
  width: 100%;
  height: 100%;
  object-fit: fill;        
  border-radius: 50%;
  display: block;
}


#toggleSidebar {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 10px; /* كبرنا المساحة شوية باش صبعك يجيبها بالساهل في التلفون */
  display: flex;
  align-items: center;
  justify-content: center;
  
  /* يمنع تحديد النص وظهران القائمة متاع Copy/Select */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  
  /* تحسين الاستجابة للتاتش على التلفونات */
  touch-action: manipulation;
  position: relative;
  z-index: 100; /* يضمن إن الزر جاي فوق كل شي وماهوش متغطي */
}

/* يضمن إن الـ SVG داخل الزر ما يعطلش النزلة */
#toggleSidebar svg {
  pointer-events: none;
}
