:root {
  /* Primary Blue Palette - Dark Mode */
  --primary-blue: #1e40af;
  --dark-blue: #1e3a8a;
  --light-blue: #3b82f6;

  /* Background Colors - Dark Mode */
  --bg-white: #0f172a;
  --bg-light: #1e293b;
  --bg-color: #020617;

  /* Text Colors - Dark Mode */
  --text-black: #f8fafc;
  --text-color: #f1f5f9;
  --text-gray: #94a3b8;
  --say-color: #60a5fa;

  /* Border & Utility Colors - Dark Mode */
  --border-color: #334155;
  --error-red: #f87171;
  --success-green: #34d399;

  /* Message Colors - Dark Mode */
  --user2-msg-bg: #1e293b;
  --user-msg-bg: #1e40af;
  --user-msg-color: #ffffff;
  --input-bg: #1e293b;

  /* Sidebar and Accents - Dark Mode */
  --sidebar-bg: #0f172a;
  --accent-color: #60a5fa;
  --danger-color: #f87171;

  /* Shadow - Dark Mode */
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);

  /* Layout Heights */
  --header-height: 60px;
  --input-height: 70px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  transition: 0.3s;
  height: 100vh;
  overflow: hidden;
}

/* ============================================
   CONTAINER & LAYOUT UTILITIES
   ============================================ */
.container {
  max-width: 100%;
  margin: 0 auto;
  padding: 15px;
}

.page-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background-color: var(--bg-color);
}

.card {
  background-color: var(--bg-white);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 30px;
  width: 90%;
  max-width: 400px;
  margin: 20px;
  border: 1px solid var(--border-color);
}

.card-header {
  margin-bottom: 25px;
}

.card-header h1 {
  color: var(--accent-color);
  font-size: 28px;
  margin-bottom: 10px;
}

.card-header p {
  color: var(--text-gray);
}

.card-body {
  margin-top: 20px;
}

/* ============================================
   FORM STYLES
   ============================================ */
.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
}

.form-label {
  font-weight: 600;
  color: var(--accent-color);
  margin-bottom: 8px;
  font-size: 14px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background-color: var(--bg-light);
  color: var(--text-color);
  transition: all 0.3s ease;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.2);
}

.form-input:focus-visible {
  outline: 3px solid var(--primary-blue);
  outline-offset: 2px;
}

.form-input.error {
  border-color: var(--error-red);
  background-color: rgba(248, 113, 113, 0.1);
}

.form-input::placeholder {
  color: var(--text-gray);
}

/* ============================================
   BUTTON STYLES
   ============================================ */
.btn {
  padding: 14px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-block;
  text-align: center;
  border: none;
  width: 100%;
  font-family: inherit;
}

.btn-primary {
  background-color: var(--primary-blue);
  color: var(--bg-white);
}

.btn-primary:hover {
  background-color: var(--dark-blue);
  transform: scale(1.02);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:focus-visible {
  outline: 3px solid var(--dark-blue);
  outline-offset: 2px;
}

.btn-secondary {
  background-color: transparent;
  border: 2px solid var(--primary-blue);
  color: var(--primary-blue);
  width: auto;
  padding: 8px 16px;
}

.btn-secondary:hover {
  background-color: var(--primary-blue);
  color: var(--bg-white);
}

.btn-send {
  width: auto;
  min-width: 50px;
  height: 50px;
  padding: 0;
  border-radius: 50%;
  background-color: var(--primary-blue);
  color: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
}

.btn-send:hover {
  background-color: var(--dark-blue);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-link {
  color: var(--accent-color);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.text-link:hover {
  text-decoration: underline;
  color: var(--light-blue);
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-gray {
  color: var(--text-gray);
  font-size: 12px;
  margin-top: 5px;
}

.error-message {
  color: var(--error-red);
  font-size: 14px;
  margin-top: 5px;
  display: none;
}

.error-message.show {
  display: block;
}

.success-message {
  color: var(--success-green);
  font-size: 14px;
  margin-top: 5px;
  display: none;
}

.success-message.show {
  display: block;
}

.mt-1 {
  margin-top: 10px;
}

.mt-2 {
  margin-top: 20px;
}

.mt-3 {
  margin-top: 30px;
}

.mb-1 {
  margin-bottom: 10px;
}

.mb-2 {
  margin-bottom: 20px;
}

.mb-3 {
  margin-bottom: 30px;
}

.hidden {
  display: none;
}

.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile First Layout */
.app-container {
  display: flex;
  height: 100vh;
  position: relative;
  background-color: var(--bg-color);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  background-color: var(--bg-color);
}

/* Header - Mobile Optimized */
.header {
  height: var(--header-height);
  padding: 0 15px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-white);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 {
  font-size: 20px;
  color: var(--accent-color);
  font-weight: 700;
}

/* Chat Container - Mobile Optimized */
#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--input-height));
  overflow: hidden;
  background-color: var(--bg-color);
}

.say_hi {
  font-weight: bold;
  font-size: 28px;
  text-align: center;
  margin-top: 300px;
  color: var(--say-color);
  text-shadow: 1px 1px 6px rgba(0, 0, 0, 0.5);
}

/* vv: صندوق الرسائل بعرض 65% وفي المنتصف */
#chat-box {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-color: var(--bg-color);
  width: 65%;
  margin: 0 auto;
  max-width: 800px;
}

/* ============================================
   ELEGANT MESSAGE STYLING
   ============================================ */
.message {
  display: flex;
  padding: 12px 16px;
  margin: 0;
  transition: all 0.2s ease;
  border-radius: 8px;
  max-width: 100%;
  position: relative;
  background-color: var(--user2-msg-bg);
  border: 1px solid var(--border-color);
}

.message:hover {
  background-color: rgba(30, 41, 59, 0.6);
  border-color: var(--primary-blue);
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-right: 12px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: white;
  font-size: 14px;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 15px;
}

.message-username {
  font-weight: 600;
  font-size: 15px;
  color: var(--accent-color);
}

.message-time {
  font-size: 11px;
  color: var(--text-gray);
  font-weight: 400;
}

.message-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-color);
  word-wrap: break-word;
  white-space: pre-wrap;
  margin: 0;
}

/* User message styling */
.user-msg {
  background-color: var(--user-msg-bg);
  margin-left: auto;
  border-color: var(--primary-blue);
}

.user-msg .message-avatar {
  background: linear-gradient(135deg, #1e3a8a, #1e40af);
  order: 2;
  margin-right: 0;
  margin-left: 12px;
}

.user-msg .message-content {
  order: 1;
}

.user-msg .message-username {
  color: var(--user-msg-color);
}

.user-msg .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.user-msg .message-text {
  color: var(--user-msg-color);
}

/* AI message styling */
.user2-msg {
  background-color: var(--user2-msg-bg);
  margin-right: auto;
}

.user2-msg .message-avatar {
  background: linear-gradient(135deg, #475569, #64748b);
}

/* Input Area - Mobile Optimized */
.input-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-white);
  border-top: 1px solid var(--border-color);
  padding: 10px 15px;
  height: var(--input-height);
}

/* vv: منطقة الإدخال بعرض 65% وفي المنتصف */
#input-area {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px;
  box-shadow: var(--shadow);
  width: 65%;
  margin: 0 auto;
  max-width: 800px;
}

textarea {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: inherit;
  background: transparent;
  color: var(--text-color);
  resize: none;
  min-height: 40px;
  max-height: 100px;
  padding: 8px 12px;
  line-height: 1.4;
}

textarea::placeholder {
  color: var(--text-gray);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-light);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-blue);
}

/* Responsive Design */
@media (min-width: 768px) {
  .header {
    padding: 0 25px;
  }

  h1 {
    font-size: 24px;
  }

  .input-container {
    position: relative;
    padding: 15px 25px;
  }

  #chat-container {
    height: auto;
  }
  
  #chat-box {
    padding: 20px;
  }
  
  .message {
    padding: 14px 18px;
  }
  
  .message-avatar {
    width: 40px;
    height: 40px;
    margin-right: 14px;
  }
  
  .user-msg .message-avatar {
    margin-left: 14px;
  }
}

@media (max-width: 480px) {
  .header-right {
    gap: 5px;
  }

  .btn-secondary {
    padding: 6px 10px;
    font-size: 11px;
  }

  h1 {
    font-size: 18px;
  }

  .message {
    padding: 10px 12px;
  }
  
  .message-avatar {
    width: 32px;
    height: 32px;
    margin-right: 10px;
    font-size: 13px;
  }
  
  .user-msg .message-avatar {
    margin-left: 10px;
  }
  
  /* vv: مسافة 12px بين اسم المرسل ومحتوى الرسالة على الشاشات الصغيرة */
  .message-header {
    margin-bottom: 12px;
  }
  
  .message-username {
    font-size: 14px;
  }
  
  .message-text {
    font-size: 14px;
  }

  /* vv: على الشاشات الصغيرة، صندوق الرسائل يأخذ العرض الكامل */
  #chat-box {
    width: 95%;
    margin: 0 auto;
  }

  /* vv: على الشاشات الصغيرة، منطقة الإدخال تأخذ العرض الكامل */
  #input-area {
    width: 95%;
    margin: 0 auto;
  }
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
  .input-container {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}

/* تحسينات إضافية للوضع الداكن */
body {
  background: var(--bg-color);
  color: var(--text-color);
}

.card p {
  color: var(--text-gray);
}

/* تحسين التباين للوضع الداكن */
.form-input {
  background: var(--bg-light);
  color: var(--text-color);
}

/* تحسين الظلال للوضع الداكن */
.card, .message, #input-area {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* تحسين ألوان الروابط في الرسائل */
.message-text a {
  color: var(--accent-color);
  text-decoration: none;
}

.message-text a:hover {
  color: var(--light-blue);
  text-decoration: underline;
}

/* تأثيرات خاصة للرسائل */
.message {
  animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}