
:root {
  --bg-primary: #fdfdfd;
  --bg-secondary: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #1159af;
  --accent-hover: #0f4e99;
  --accent-light: rgba(17, 89, 175, 0.08);
  --border-color: #e2e8f0;
  --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --header-gradient: linear-gradient(135deg, #1159af 0%, #1f6fde 100%);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(17, 89, 175, 0.08);
}

[data-theme="dark"] {
  --bg-primary: #0c0f19;
  --bg-secondary: #151a26;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent: #7C5CFF;
  --accent-hover: #6c4de6;
  --accent-light: rgba(124, 92, 255, 0.15);
  --border-color: rgba(255, 255, 255, 0.1);
  --card-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
  --header-gradient: linear-gradient(135deg, #151a26 0%, #0c0f19 100%);
  --glass-bg: rgba(21, 26, 38, 0.85);
  --glass-border: rgba(124, 92, 255, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.2s, border-color 0.2s;
}

body {
  font-family: 'Cairo', 'Tajawal', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  direction: rtl;
  text-align: right;
  line-height: 1.6;
}

header.hero {
  background: var(--header-gradient);
  color: white;
  padding: 4rem 2rem 6rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

header.hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4rem;
  background: linear-gradient(to top, var(--bg-primary), transparent);
}

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

h1.hero-title {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 1rem;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, #ffffff 0%, #a7f3d0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: #a7f3d0;
  margin-bottom: 2rem;
  font-weight: 300;
}

/* Nav */
nav.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.nav-brand {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.theme-toggle, .back-btn {
  background: none;
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  cursor: pointer;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
}

.theme-toggle:hover, .back-btn:hover {
  background-color: var(--accent-light);
  border-color: var(--accent);
}

/* Search Box */
.search-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.search-input {
  width: 100%;
  padding: 1rem 3rem 1rem 1.5rem;
  font-size: 1.05rem;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
  outline: none;
  font-family: inherit;
  backdrop-filter: blur(10px);
}

.search-input:focus {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}

.search-input::placeholder {
  color: #a7f3d0;
}

.search-input:focus::placeholder {
  color: var(--text-secondary);
}

.search-icon {
  position: absolute;
  top: 50%;
  right: 1.25rem;
  transform: translateY(-50%);
  fill: #a7f3d0;
  pointer-events: none;
}

.search-input:focus ~ .search-icon {
  fill: var(--accent);
}

/* Search results container */
#search-results-container {
  display: none;
  max-width: 800px;
  margin: -2.5rem auto 3rem;
  background-color: var(--bg-secondary);
  border-radius: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  position: relative;
  z-index: 50;
}

.search-result-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.search-result-title:hover {
  text-decoration: underline;
}

.search-result-path {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.search-result-snippet {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Layout container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Collection Cards Grid */
.collections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-top: -3rem;
  margin-bottom: 4rem;
  position: relative;
  z-index: 20;
}

.collection-card {
  background-color: var(--bg-secondary);
  border-radius: 1rem;
  padding: 2rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.collection-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

.collection-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.collection-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 0.75rem;
  object-fit: cover;
}

.collection-name {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
}

.collection-card:hover .collection-name {
  color: var(--accent);
}

.collection-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  flex-grow: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.collection-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

/* Detail page template layout */
.layout-columns {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  margin-top: 2rem;
  margin-bottom: 4rem;
}

@media (max-width: 900px) {
  .layout-columns {
    grid-template-columns: 1fr;
  }
}

/* Sidebar styling */
.sidebar {
  background-color: var(--bg-secondary);
  border-radius: 0.75rem;
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  align-self: start;
  position: sticky;
  top: 5rem;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  color: var(--text-primary);
}

.sidebar-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border-radius: 0.25rem;
  display: block;
}

.sidebar-link:hover {
  background-color: var(--accent-light);
  color: var(--accent);
}

.sidebar-link.active {
  background-color: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
}

/* Main content */
.main-pane {
  background-color: var(--bg-secondary);
  border-radius: 1rem;
  padding: 2.5rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--card-shadow);
}

@media (max-width: 600px) {
  .main-pane {
    padding: 1.5rem;
  }
}

/* Articles listing inside collections */
.article-row-link {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 1.25rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.article-row-link:hover {
  border-color: var(--accent);
  background-color: var(--accent-light);
}

.article-row-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.article-row-link:hover .article-row-title {
  color: var(--accent);
}

.article-row-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.subcollection-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 2rem 0 1rem 0;
  border-right: 4px solid var(--accent);
  padding-right: 0.75rem;
}

/* Article content body styles */
h1.article-title {
  font-size: 1.85rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.article-desc {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.article-meta-info {
  display: flex;
  gap: 1.5rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.5rem;
}

.article-body-text {
  font-size: 1.05rem;
}

.article-body-text p {
  margin-bottom: 1.25rem;
}

.article-body-text ul, .article-body-text ol {
  margin-bottom: 1.25rem;
  margin-right: 1.5rem;
}

.article-body-text li {
  margin-bottom: 0.5rem;
}

.article-body-text img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 1.5rem 0;
  border: 1px solid var(--border-color);
}

.article-body-text iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 0.5rem;
  margin: 1.5rem 0;
  border: none;
}

.article-body-text table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.article-body-text th, .article-body-text td {
  border: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  text-align: right;
}

.article-body-text th {
  background-color: var(--bg-primary);
  font-weight: 700;
}

.intercom-h2b-button {
  display: inline-block;
  background-color: var(--accent);
  color: white !important;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 700;
  margin: 1rem 0;
}

.intercom-h2b-button:hover {
  background-color: var(--accent-hover);
}

/* Related articles section */
.related-section {
  margin-top: 3rem;
  border-top: 1px solid var(--border-color);
  padding-top: 2rem;
}

.related-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 1.25rem;
}

.related-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .related-links {
    grid-template-columns: 1fr;
  }
}

.related-card {
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  display: block;
}

.related-card:hover {
  border-color: var(--accent);
  background-color: var(--accent-light);
  color: var(--accent);
}

/* Footer styling */
footer.site-footer {
  text-align: center;
  padding: 3rem 0;
  margin-top: 4rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Highlight matching search text */
.highlight {
  background-color: rgba(124, 92, 255, 0.3);
  font-weight: bold;
  border-radius: 2px;
  padding: 0 2px;
}

/* Iframe Integration Styles */
body.in-iframe nav.navbar {
  display: none !important;
}

body.in-iframe footer.site-footer {
  display: none !important;
}

body.in-iframe {
  background-color: transparent !important;
}

body.in-iframe .container {
  padding-top: 1rem !important;
  max-width: 100% !important;
}

body.in-iframe header.hero {
  padding: 3rem 1.5rem 4rem !important;
  border-radius: 12px;
  margin-bottom: 2rem;
}
