/* ==========================================================
   خواطر الإمام الشعراوي — Al-Shaarawy Grounded AI Styling
   Clean, respectful, modern Arabic RTL design system
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400&family=Tajawal:wght@300;400;500;700;800&display=swap');

:root {
  --primary: #155e46; /* Deep Islamic Emerald */
  --primary-hover: #0f4936;
  --primary-light: #e8f5e9;
  --gold: #c59b27;
  --gold-light: #fff8e1;
  --bg-dark: #0f172a;
  --card-bg: #ffffff;
  --text-dark: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Tajawal', sans-serif;
  direction: rtl;
  text-align: right;
  background: #f8fafc;
  color: var(--text-dark);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Navigation */
header {
  background: linear-gradient(135deg, #0d3b2e 0%, #155e46 100%);
  color: #ffffff;
  padding: 2.5rem 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 50% 120%, rgba(197, 155, 39, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.header-container {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.brand-badge {
  display: inline-block;
  background: rgba(197, 155, 39, 0.25);
  color: #ffd700;
  border: 1px solid rgba(197, 155, 39, 0.4);
  padding: 0.35rem 1rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 1rem;
  letter-spacing: 0.5px;
}

h1.main-title {
  font-family: 'Amiri', serif;
  font-size: 2.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #ffffff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

p.subtitle {
  font-size: 1.15rem;
  color: #e2e8f0;
  max-width: 650px;
  margin: 0 auto 1.5rem;
  font-weight: 300;
}

.nav-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.nav-link {
  color: #ffffff;
  text-decoration: none;
  font-size: 0.95rem;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

/* Main Container */
main.app-container {
  max-width: 900px;
  width: 100%;
  margin: -1.5rem auto 3rem;
  padding: 0 1rem;
  flex: 1;
  position: relative;
  z-index: 2;
}

/* Search & Chat Card */
.interaction-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.8rem;
  border: 1px solid var(--border-color);
  margin-bottom: 2rem;
}

.mode-selector {
  display: flex;
  background: #f1f5f9;
  padding: 0.3rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.2rem;
  gap: 0.3rem;
}

.mode-btn {
  flex: 1;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.mode-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.input-box-wrapper {
  position: relative;
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

textarea.chat-input {
  flex: 1;
  font-family: inherit;
  font-size: 1.05rem;
  padding: 0.9rem 1.2rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  resize: none;
  min-height: 60px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

textarea.chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 94, 70, 0.12);
}

button.submit-btn {
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0 1.8rem;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

button.submit-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

button.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.quick-examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.example-tag {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s;
}

.example-tag:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Result Card */
.result-container {
  display: none;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  padding: 2rem;
  margin-bottom: 2rem;
  animation: fadeIn 0.3s ease;
}

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

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.grounding-status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: 9999px;
}

.status-grounded {
  background: var(--primary-light);
  color: var(--primary);
}

.status-refused {
  background: #fee2e2;
  color: #dc2626;
}

.latency-tag {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.answer-body {
  font-family: 'Amiri', serif;
  font-size: 1.35rem;
  line-height: 2.0;
  color: #1e293b;
  margin-bottom: 2rem;
  white-space: pre-line;
}

.sources-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 1.2rem;
}

.sources-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.source-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 1.2rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.source-card:last-child {
  margin-bottom: 0;
}

.source-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
}

.source-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
  color: #1e293b;
}

.source-meta-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.sot-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: linear-gradient(135deg, #064e3b, #047857);
  color: #f0fdf4;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  box-shadow: 0 1px 3px rgba(6, 78, 59, 0.25);
  letter-spacing: 0.02em;
}

.source-timestamp {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  direction: ltr;
}

.source-excerpt {
  font-family: 'Amiri', serif;
  font-size: 1.12rem;
  color: #334155;
  line-height: 1.8;
  background: #f8fafc;
  padding: 0.85rem 1rem;
  border-right: 4px solid var(--primary);
  border-radius: 4px;
  margin: 0.75rem 0;
}

/* Source Media Toolbar */
.source-media-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--border-color);
}

.clip-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clip-toggle-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.clip-action-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s ease;
}

.clip-action-link:hover {
  background: #e2e8f0;
  color: var(--primary);
  border-color: var(--primary);
}

/* Video Player Container */
.source-video-container {
  display: none;
  background: #0f172a;
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 0.9rem;
  border: 1px solid #334155;
  color: #e2e8f0;
  animation: fadeIn 0.25s ease;
}

.video-player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: #94a3b8;
}

.video-player-header strong {
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.video-player-frame {
  width: 100%;
  max-height: 380px;
  background: #000000;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  outline: none;
}

.video-player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid #1e293b;
  font-size: 0.8rem;
}

.speed-selector {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.speed-pill {
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-pill:hover, .speed-pill.active {
  background: #38bdf8;
  color: #0f172a;
  border-color: #38bdf8;
  font-weight: 700;
}

.video-truth-disclaimer {
  font-size: 0.78rem;
  color: #94a3b8;
  margin-top: 0.6rem;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Loading Spinner */
.spinner {
  display: none;
  text-align: center;
  padding: 2rem;
}

.spinner-circle {
  width: 42px;
  height: 42px;
  border: 3px solid rgba(21, 94, 70, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border-color);
  background: #ffffff;
}

/* Responsive */
@media (max-width: 640px) {
  h1.main-title { font-size: 2.1rem; }
  .input-box-wrapper { flex-direction: column; }
  button.submit-btn { width: 100%; padding: 0.8rem; }
  .interaction-card { padding: 1.2rem; }
  .answer-body { font-size: 1.2rem; }
}
