@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&family=Cairo:wght@400;700&display=swap');

:root {
  --primary-bg: #030712; /* Deep Obsidian */
  --sidebar-bg: #070b14;
  --accent-gold: #d4af37; /* True Gold */
  --accent-gold-hover: #e5c158;
  --accent-gold-dark: #b8860b;
  --text-main: #f3f4f6;
  --text-dim: #9ca3af;
  --white: #ffffff;
  --parchment: #fdf6e3; /* Restored for AI messages */
  --glass: rgba(17, 24, 39, 0.85);
  --glass-border: rgba(212, 175, 55, 0.2);
  --card-bg: rgba(31, 41, 55, 0.5);
  --shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.7);
  --gold-glow: 0 0 15px rgba(212, 175, 55, 0.15);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Cairo', sans-serif;
  background-color: var(--primary-bg);
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(197, 160, 89, 0.03) 0%, transparent 80%),
    url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M50 20 L50 80 M30 40 L70 40 M30 45 L70 45' stroke='%23c5a059' stroke-width='0.5' fill='none' opacity='0.05'/%3E%3C/svg%3E");
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  direction: rtl; 
}

/* Sidebar Styling */
.sidebar {
  width: 300px;
  background-color: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow);
  z-index: 10;
  position: sticky;
  top: 0;
  height: 100vh;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 3rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-bg);
  font-weight: bold;
  font-size: 1.5rem;
}

.logo-text {
  font-family: 'Amiri', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-gold);
  letter-spacing: 0.5px;
}

.new-chat-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-dark));
  color: #000;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 2rem;
  transition: var(--transition);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.new-chat-btn:hover {
  background: var(--accent-gold-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
}

.sidebar-section {
  margin-bottom: 2rem;
}

.sidebar-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1rem;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
}

.quick-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-item {
  padding: 10px;
  font-size: 0.9rem;
  color: var(--text-main);
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
}

.link-item:hover {
  background: rgba(212, 175, 55, 0.1);
  color: var(--accent-gold);
}

.sidebar-section:last-child {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  overflow-y: auto;
  padding-left: 5px; /* Space for scrollbar in RTL */
}

.history-item {
  padding: 12px 10px;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: var(--transition);
}

.history-item:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.06);
}

.empty-history {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
}

/* Main Content Styling */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 100vh;
}

.chat-header {
  padding: 1.5rem 2rem;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
  position: sticky;
  top: 0;
  z-index: 100;
}

.chat-container {
  flex: 1;
  padding: 3rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0) 0%, rgba(11, 17, 33, 0.5) 100%);
}

.message {
  max-width: 85%;
  min-height: min-content;
  height: auto;
  padding: 1.5rem 2rem;
  border-radius: 4px; 
  line-height: 1.8;
  font-size: 1.1rem;
  position: relative;
  word-break: break-word;
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.ai {
  align-self: flex-start;
  background: var(--parchment);
  color: #1a1a1a; 
  border: 1px solid rgba(0,0,0,0.1);
  border-top: 5px solid var(--accent-gold);
  font-family: 'Amiri', serif;
  font-size: 1.25rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.4);
  margin-inline-end: 2rem;
}

.message.ai::before {
  content: "الرأي القانوني المعتمد";
  display: block;
  font-size: 0.85rem;
  color: var(--accent-gold-dark);
  margin-bottom: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  border-bottom: 3px double var(--border); /* Formal double line */
  padding-bottom: 8px;
  font-family: 'Cairo', sans-serif;
}

.message.ai::after {
  content: "\f5bf"; /* FontAwesome fa-stamp/fa-scale-balanced-like icon */
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  bottom: 10px;
  left: 10px;
  font-size: 3rem;
  opacity: 0.05;
  color: var(--accent-gold-dark);
  transform: rotate(-15deg);
}

.message.ai.loading {
  background: rgba(255,255,255,0.05);
  color: var(--accent-gold);
  border-top-color: transparent;
  font-style: italic;
  animation: pulse 1.5s infinite ease-in-out;
  margin-left: 0;
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.message.user {
  align-self: flex-end;
  background: rgba(212, 175, 55, 0.1);
  color: var(--white);
  border: 1px solid var(--glass-border);
  border-right: 4px solid var(--accent-gold);
  font-weight: 500;
  border-radius: 12px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  margin-inline-start: 2rem;
}

.message.user::before {
  content: "نص الاستشارة المطلوبة";
  display: block;
  font-size: 0.7rem;
  color: var(--accent-gold);
  margin-bottom: 8px;
  font-weight: 700;
  opacity: 0.8;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.input-area {
  padding: 2rem;
  background: var(--glass);
  backdrop-filter: blur(15px);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  width: 100%;
}

.input-wrapper {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
}

#chat-input {
  width: 100%;
  padding: 1.4rem 1.8rem;
  padding-left: 5.5rem; /* For send button */
  background: rgba(25, 25, 30, 0.8);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  color: var(--white);
  font-size: 1.05rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#chat-input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

#chat-input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.1);
}

.send-btn {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, var(--accent-gold), var(--accent-gold-dark));
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  box-shadow: 0 5px 15px rgba(212, 175, 55, 0.25);
}

.send-btn:hover {
  background: var(--accent-gold-hover);
  transform: translateY(-50%) scale(1.05);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--primary-bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-gold);
}

/* Lawyer Suggestions Section */
.lawyer-suggestions {
  margin-top: 2rem;
  padding: 2rem;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.05) 0%, transparent 100%);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  animation: slideUp 0.8s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.lawyer-title {
  font-size: 1.2rem;
  color: var(--accent-gold);
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.5rem;
  font-family: 'Amiri', serif;
}

.lawyer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.lawyer-card {
  background: var(--sidebar-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 1.5rem;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.lawyer-card::before {
  content: "محامٍ موصى به";
  position: absolute;
  top: 10px;
  left: -25px;
  background: var(--accent-gold);
  color: black;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 30px;
  transform: rotate(-45deg);
}

.lawyer-card:hover {
  transform: translateY(-8px) scale(1.02);
  border-color: var(--accent-gold);
  box-shadow: 0 15px 40px rgba(212, 175, 55, 0.2);
}

.lawyer-name {
  font-weight: 800;
  color: var(--white);
  font-size: 1.15rem;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lawyer-name::after {
  content: "\f058";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  color: #4CAF50;
  font-size: 0.9rem;
}

.lawyer-spec {
  font-size: 0.85rem;
  color: var(--accent-gold);
  background: rgba(212, 175, 55, 0.15);
  padding: 4px 12px;
  border-radius: 20px;
  width: fit-content;
  margin-bottom: 15px;
  font-weight: 700;
}

.lawyer-info {
  font-size: 0.9rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.contact-btn {
  margin-top: 15px;
  padding: 12px;
  background: transparent;
  border: 1.5px solid var(--accent-gold);
  border-radius: 10px;
  color: var(--accent-gold);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  transition: var(--transition);
  display: block;
}

.contact-btn:hover {
  background: var(--accent-gold);
  color: var(--primary-bg);
  box-shadow: 0 0 15px var(--accent-gold);
}

/* Mobile Responsiveness */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100vh;
    transition: right 0.3s ease;
    z-index: 1000;
  }
  .sidebar.active {
    right: 0;
  }
  .mobile-menu-btn {
    display: block !important;
  }
  .chat-header {
    padding: 0.8rem 1rem;
  }
  .chat-container {
    padding: 1.5rem 1rem;
    gap: 1.5rem;
  }
  .message {
    max-width: 95%;
    margin-inline-start: 0 !important;
    margin-inline-end: 0 !important;
    padding: 1rem 1.2rem;
  }
  .input-area {
    padding: 1rem;
  }
  #chat-input {
    padding: 1rem 1.2rem;
    padding-left: 4.5rem;
  }
  .lawyer-grid {
    grid-template-columns: 1fr;
  }
}

/* Modern Q&A Specific Layout */
.hero-section {
  padding: 5rem 2rem;
  text-align: center;
  background: radial-gradient(circle at center, rgba(212, 175, 55, 0.08) 0%, transparent 70%);
  border-bottom: 1px solid var(--glass-border);
  margin-bottom: 3rem;
}

.hero-section h1 {
  font-family: 'Amiri', serif;
  font-size: 3.5rem;
  color: var(--white);
  margin-bottom: 1.5rem;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.hero-section h1 span {
  color: var(--accent-gold);
}

.hero-section p {
  font-size: 1.2rem;
  color: var(--text-dim);
  max-width: 700px;
  margin: 0 auto 2.5rem;
  line-height: 1.6;
}

.search-box-large {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
  box-shadow: var(--shadow);
  border-radius: 20px;
}

.search-box-large input {
  width: 100%;
  padding: 1.8rem 2rem;
  padding-right: 4rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  color: white;
  font-size: 1.2rem;
  outline: none;
  font-family: 'Cairo', sans-serif;
  transition: var(--transition);
}

.search-box-large input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 20px rgba(212, 175, 55, 0.2);
}

.search-icon-btn {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent-gold);
  font-size: 1.5rem;
}

.section-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.section-header h2 {
  font-family: 'Amiri', serif;
  font-size: 2rem;
  color: var(--accent-gold);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 4rem;
}

.cat-card {
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 16px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.cat-card i {
  font-size: 2.5rem;
  color: var(--accent-gold);
  margin-bottom: 1.2rem;
}

.cat-card h3 {
  font-size: 1.1rem;
  color: white;
}

.cat-card:hover {
  background: rgba(212, 175, 55, 0.1);
  border-color: var(--accent-gold);
  transform: translateY(-50px);
}

.qa-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.qa-card {
  background: var(--card-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.5rem;
  transition: var(--transition);
  cursor: pointer;
}

.qa-card:hover {
  transform: translateX(-5px);
  background: rgba(255,255,255,0.05);
  border-color: var(--accent-gold);
}

.qa-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 0.8rem;
  display: flex;
  justify-content: space-between;
}

.qa-tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  background: rgba(212, 175, 55, 0.15);
  color: var(--accent-gold);
  border-radius: 20px;
  font-weight: 600;
}

.qa-preview {
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.qa-meta {
  display: flex;
  gap: 20px;
  font-size: 0.8rem;
  color: #6b7280;
}

.qa-meta span i {
  margin-left: 5px;
}

/* Chat Overlays */
#qa-chat-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--primary-bg);
  z-index: 2000;
  flex-direction: column;
}

.overlay-header {
  padding: 1.5rem 2rem;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-overlay {
  background: none;
  border: none;
  color: #ff4d4d;
  font-size: 1.5rem;
  cursor: pointer;
}
