/* ==============================
   CSS Variables & Reset
================================ */
[hidden] { display: none !important; }
:root {
  --primary:        #c0392b;
  --primary-dark:   #96281b;
  --bg:             #f0f2f5;
  --bg-card:        #ffffff;
  --bg-header:      #1a1a2e;
  --bg-nav:         #16213e;
  --text:           #2c3e50;
  --text-muted:     #7f8c8d;
  --border:         #e0e0e0;
  --shadow:         0 2px 12px rgba(0,0,0,.08);
  --shadow-hover:   0 8px 24px rgba(0,0,0,.14);
  --radius:         12px;
  --ticker-bg:      #e74c3c;
  --cat-active-bg:  #c0392b;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Cairo', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ==============================
   Header
================================ */
.site-header {
  background: var(--bg-header);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(0,0,0,.3);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  text-decoration: none;
}

.logo-icon { font-size: 1.6rem; }

.logo-text {
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: -0.5px;
}

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

.btn-search {
  background: none;
  border: none;
  cursor: pointer;
  color: #fff;
  padding: .4rem;
  border-radius: 50%;
  transition: background .2s;
  display: flex;
  align-items: center;
}

.btn-search:hover { background: rgba(255,255,255,.12); }
.btn-search svg { width: 22px; height: 22px; }

.clock {
  font-size: .8rem;
  color: rgba(255,255,255,.65);
  white-space: nowrap;
}

/* ==============================
   Breaking News Ticker
================================ */
.ticker-wrap {
  background: var(--ticker-bg);
  color: #fff;
  display: flex;
  align-items: center;
  overflow: hidden;
  height: 36px;
}

.ticker-label {
  background: #96281b;
  padding: 0 1rem;
  font-weight: 700;
  font-size: .85rem;
  white-space: nowrap;
  height: 100%;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ticker-content {
  flex: 1;
  overflow: hidden;
  height: 100%;
  display: flex;
  align-items: center;
}

.ticker-items {
  display: flex;
  animation: ticker-scroll 40s linear infinite;
  white-space: nowrap;
  font-size: .88rem;
}

.ticker-items span {
  padding: 0 2rem;
}

.ticker-items span::after {
  content: ' • ';
  color: rgba(255,255,255,.5);
}

@keyframes ticker-scroll {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100vw); }
}

/* ==============================
   Search Overlay
================================ */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 80px;
  backdrop-filter: blur(4px);
}

.search-box {
  width: 100%;
  max-width: 680px;
  display: flex;
  gap: .5rem;
  padding: 0 1rem;
}

#searchInput {
  flex: 1;
  padding: .85rem 1.2rem;
  font-size: 1.1rem;
  font-family: 'Cairo', sans-serif;
  border: none;
  border-radius: var(--radius);
  outline: none;
  direction: rtl;
  background: #fff;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
}

.btn-close-search {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  align-self: center;
  transition: background .2s;
}

.btn-close-search:hover { background: rgba(255,255,255,.25); }

.search-results {
  width: 100%;
  max-width: 680px;
  margin-top: 1rem;
  padding: 0 1rem;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.search-result-item {
  background: #fff;
  border-radius: 10px;
  padding: .8rem 1rem;
  cursor: pointer;
  transition: background .15s;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.search-result-item:hover { background: #f8f8f8; }

.search-result-item img {
  width: 70px;
  height: 50px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.search-result-item .sr-title {
  font-weight: 600;
  font-size: .92rem;
  line-height: 1.4;
  color: var(--text);
}

.search-result-item .sr-cat {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .2rem;
}

/* ==============================
   Category Navigation
================================ */
.category-nav {
  background: var(--bg-nav);
  border-bottom: 3px solid var(--primary);
  position: sticky;
  top: 60px;
  z-index: 90;
}

.cat-list {
  list-style: none;
  display: flex;
  gap: .25rem;
  padding: .5rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.cat-list::-webkit-scrollbar { display: none; }

.cat-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.7);
  padding: .45rem 1rem;
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: .92rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all .2s;
}

.cat-btn:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.cat-btn.active {
  background: var(--cat-active-bg);
  color: #fff;
  box-shadow: 0 2px 8px rgba(192,57,43,.4);
}

/* ==============================
   Main & Status Bar
================================ */
.main { padding: 1.5rem 0 3rem; }

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.stats-count { font-weight: 600; }

/* ==============================
   News Grid & Cards
================================ */
.news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.news-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.news-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.card-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: #ecf0f1;
}

.card-image-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  background: linear-gradient(135deg, #ecf0f1 0%, #bdc3c7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.card-body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .6rem;
}

.card-category {
  font-size: .72rem;
  font-weight: 700;
  padding: .2rem .65rem;
  border-radius: 20px;
  background: var(--primary);
  color: #fff;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.card-category.cat-saudi  { background: #27ae60; }
.card-category.cat-world  { background: #2980b9; }
.card-category.cat-markets{ background: #8e44ad; }
.card-category.cat-crypto { background: #f39c12; color: #333; }
.card-category.cat-wars   { background: #c0392b; }
.card-category.cat-usmarkets { background: #1e40af; }

.card-date {
  font-size: .75rem;
  color: var(--text-muted);
  direction: ltr;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: .5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-summary {
  font-size: .87rem;
  color: var(--text-muted);
  line-height: 1.6;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  padding: .6rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text-muted);
}

.fetched-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(34, 197, 94, 0.12);
  color: #22c55e;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: auto;
}

.card-source { font-weight: 600; }

.card-link {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.card-link:hover { text-decoration: underline; }

/* ==============================
   Skeleton Loader
================================ */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.skeleton-card {
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  height: 320px;
  position: relative;
  overflow: hidden;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,0.6) 50%,
    rgba(255,255,255,0) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    /* image placeholder */
    linear-gradient(#ecf0f1, #ecf0f1) 0 0 / 100% 160px no-repeat,
    /* title line 1 */
    linear-gradient(#ecf0f1, #ecf0f1) 1rem 176px / 85% 16px no-repeat,
    /* title line 2 */
    linear-gradient(#ecf0f1, #ecf0f1) 1rem 200px / 65% 16px no-repeat,
    /* summary line 1 */
    linear-gradient(#ecf0f1, #ecf0f1) 1rem 232px / 90% 12px no-repeat,
    /* summary line 2 */
    linear-gradient(#ecf0f1, #ecf0f1) 1rem 252px / 75% 12px no-repeat;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* ==============================
   Empty State
================================ */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
}

.empty-icon { font-size: 4rem; margin-bottom: 1rem; }

.empty-state h3 {
  font-size: 1.3rem;
  margin-bottom: .5rem;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.btn-refresh, .btn-load-more {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: .7rem 2rem;
  border-radius: 24px;
  font-family: 'Cairo', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .15s;
}

.btn-refresh:hover, .btn-load-more:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.load-more-wrap {
  text-align: center;
  margin-top: 2rem;
}

/* ==============================
   Article Modal
================================ */
.article-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

.article-modal-inner {
  background: #fff;
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.article-modal-header {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1;
}

.article-modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  padding-left: 1rem;
}

.btn-close-modal {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: .3rem;
  border-radius: 50%;
  transition: background .2s;
  flex-shrink: 0;
}

.btn-close-modal:hover { background: #f0f0f0; }

.article-modal-body { padding: 1.5rem; }

.article-modal-body img {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 1rem;
  object-fit: cover;
  max-height: 300px;
}

.article-modal-body .article-summary {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--text);
  margin-bottom: 1.5rem;
  background: #f8f9fa;
  padding: 1rem 1.2rem;
  border-radius: 8px;
  border-right: 4px solid var(--primary);
}

/* New unified section blocks (summary + analysis) */
.modal-section {
  margin-bottom: 1.2rem;
  background: #f8f9fa;
  padding: 1rem 1.2rem;
  border-radius: 8px;
  border-right: 4px solid var(--primary);
}

.modal-analysis {
  background: #fff8e1;
  border-right-color: #f59e0b;
}

.modal-section-label {
  font-weight: 700;
  font-size: .88rem;
  color: var(--primary);
  margin-bottom: .5rem;
  letter-spacing: .02em;
}

.modal-analysis .modal-section-label {
  color: #b45309;
}

.modal-section-text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.85;
  color: var(--text);
}

.article-modal-body .summary-label {
  font-weight: 700;
  font-size: .9rem;
  color: var(--primary);
  margin-bottom: .6rem;
  letter-spacing: .02em;
}

.article-modal-body .article-summary p {
  margin: 0;
}

.modal-cat-badge {
  display: inline-block;
  font-size: .8rem;
  font-weight: 700;
  padding: .2rem .7rem;
  border-radius: 12px;
  background: #eee;
  margin-bottom: .5rem;
}

.meta-source, .meta-date {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}

.modal-hero-img {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 1rem;
  object-fit: cover;
  max-height: 280px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.6;
  margin: 0 0 .8rem;
  color: var(--text);
}

.article-modal-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--text-muted);
  margin-bottom: 1.2rem;
}

.article-modal-link {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: .65rem 1.5rem;
  border-radius: 24px;
  text-decoration: none;
  font-weight: 700;
  font-size: .95rem;
  transition: background .2s;
}

.article-modal-link:hover { background: var(--primary-dark); }

/* ==============================
   Footer
================================ */
.site-footer {
  background: var(--bg-header);
  color: rgba(255,255,255,.55);
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: .82rem;
  line-height: 2;
}

.footer-sub { font-size: .75rem; }

/* ==============================
   Responsive
================================ */
@media (max-width: 640px) {
  .logo-text { font-size: 1.2rem; }
  .news-grid { grid-template-columns: 1fr; }
  .skeleton-grid { grid-template-columns: 1fr; }
  .cat-btn { font-size: .82rem; padding: .4rem .8rem; }
  .card-title { font-size: .95rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #bdc3c7; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #95a5a6; }
