/* ==========================================================================
   Observ Media — mobile & tablet layer
   Loaded after main.css and share.css. Desktop (> 1024px) is untouched:
   every rule below is either inside a max-width query or is a safety net
   that has no visible effect on wide screens.
   Breakpoints follow main.css: 1024 · 768 · 480 · 360.
   ========================================================================== */

/* ── 1. Global safety net ─────────────────────────────────────────────── */

/* Grid and flex children default to min-width:auto, so one long word or a
   wide table inside them stretches the whole layout. */
.news-layout > *,
.single-post-layout > *,
.news-main,
.news-sidebar,
.footer-grid > *,
.stat-body,
.card-body {
  min-width: 0;
}

/* Editorial content: nothing may be wider than its column. */
.post-content,
.page-builder-content,
.team-card-body,
.card-excerpt,
.footer-about {
  overflow-wrap: anywhere;
}
.post-content :is(img, video, svg, canvas, embed, object),
.page-builder-content :is(img, video, svg, canvas, embed, object) {
  max-width: 100%;
  height: auto;
}
.post-content iframe,
.page-builder-content iframe {
  max-width: 100%;
}
/* Video embeds keep their shape instead of their fixed pixel height. */
.post-content :is(.wp-block-embed iframe, iframe[src*="youtube"], iframe[src*="youtu.be"], iframe[src*="vimeo"], iframe[src*="facebook.com/plugins/video"], iframe[width][height][title*="فيديو"], iframe[width][height][title*="video" i]),
.page-builder-content :is(.wp-block-embed iframe, iframe[src*="youtube"], iframe[src*="youtu.be"], iframe[src*="vimeo"], iframe[src*="facebook.com/plugins/video"], iframe[width][height][title*="فيديو"], iframe[width][height][title*="video" i]) {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
}
.post-content pre,
.page-builder-content pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  overflow-wrap: normal;
  direction: ltr;
  text-align: left;
  -webkit-overflow-scrolling: touch;
}
.post-content figure,
.page-builder-content figure {
  max-width: 100%;
  margin-inline: 0;
}

/* Off-canvas menu: unreachable by keyboard and screen readers while closed. */
.mobile-nav { visibility: hidden; transition: right var(--transition-slow), visibility 0s linear .6s; }
.mobile-nav.open { visibility: visible; transition: right var(--transition-slow), visibility 0s; }

/* Phones zoom into inputs whose text is under 16px (iOS). */
@media (max-width: 1024px) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]),
  select,
  textarea { font-size: max(16px, 1em); }
}

/* ── 2. Header ────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .header-inner { padding: 0 1.25rem; gap: 1rem; justify-content: space-between; }
  .hamburger {
    width: 44px; height: 44px;
    padding: 12px 9px;
    justify-content: center;
    border-radius: var(--radius-sm);
  }
}
@media (max-width: 768px) {
  /* The team-login button lives in the mobile menu footer on phones. */
  .header-actions .btn-dashboard:not(.mobile) { display: none; }
  .header-actions { gap: 0.5rem; }
  .header-inner { padding: 0 1rem; gap: 0.75rem; }
  .header-logo { flex: 1 1 auto; min-width: 0; }
  .header-logo .logo-mark,
  .header-logo .logo-mark a { display: block; max-width: 100%; }
  .header-logo img { display: block; max-width: 100%; height: auto; max-height: 34px; width: auto; }
  .btn-icon { width: 42px; height: 42px; }
  .mobile-nav-inner { padding: calc(var(--header-h) + 1.25rem) 1.25rem 1.5rem; }
}

/* ── 3. Hero & stats ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .stat-card { padding: 1.25rem; gap: 1rem; }
  .stat-icon { width: 44px; height: 44px; }
}
@media (max-width: 560px) {
  /* Two cards side by side leave ~110px for each label: stack instead. */
  .stats-grid { grid-template-columns: 1fr; gap: 0.875rem; }
  .stat-card { align-items: center; }
}

/* ── 4. Content blocks ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Wide tables scroll inside their own box instead of stretching the page. */
  .post-content table,
  .page-builder-content table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .post-content table th,
  .post-content table td,
  .page-builder-content table th,
  .page-builder-content table td { white-space: nowrap; }

  .page-builder-section { margin-top: var(--header-h); padding: 2rem 0 3rem; }
  .page-builder-section .section-title { font-size: 1.6rem; line-height: 1.4; }
  .page-builder-thumb { height: auto; aspect-ratio: 16 / 9; }
  .page-builder-content { padding: 1.25rem; }
  /* main.css pulls any first <div> to the card edge for builders; only
     builder wrappers should do that on phones. */
  .page-builder-content > div:first-child:not(.elementor):not(.elementor-section-wrap) { margin: 0; }
}

/* ── 5. Very small phones (320–360) ───────────────────────────────────── */
@media (max-width: 360px) {
  .container { padding: 0 1rem; }
  .hero-title { font-size: 1.6rem; }
}

/* ── 6. Header overlays: menu & search ────────────────────────────────── */

/* The off-canvas menu is nested inside the header, so it painted over the
   logo and hamburger and hid the only close button. Lift the bar above it. */
.header-inner { position: relative; z-index: 1001; }

.header-search {
  position: absolute;
  top: 100%;
  inset-inline: 0;
  z-index: 1002;
  padding: 0.875rem 0;
  background: var(--green-dark);
  border-top: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 18px 40px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .2s ease, transform .2s ease;
}
.header-search.open { opacity: 1; transform: none; }
.header-search__form {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}
.header-search__form svg {
  position: absolute;
  inset-inline-start: 2.1rem;
  width: 18px;
  color: rgba(255,255,255,0.55);
  pointer-events: none;
}
.header-search__form input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 2.75rem 0 1rem;
  color: var(--white);
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.14);
  border-radius: var(--radius-sm);
  outline: none;
}
.header-search__form input::placeholder { color: rgba(255,255,255,0.45); }
.header-search__form input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,168,76,0.18); }
.header-search__submit {
  height: 48px;
  padding: 0 1.25rem;
  font-weight: 700;
  color: var(--green-dark);
  background: var(--gold);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.header-search__submit:hover { background: var(--gold-light); }
@media (prefers-reduced-motion: reduce) { .header-search { transition: none; } }

/* ── 7. Search page & 404 ─────────────────────────────────────────────── */
.screen-reader-text {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.search-page-form {
  max-width: 640px;
  height: 52px;
  margin: 0 0 2rem;
  padding-inline-end: 6px;
  background: var(--white);
}
.search-page-form input { min-width: 0; height: 100%; }
.search-page-form__btn {
  height: 40px;
  padding: 0 1.25rem;
  font-weight: 700;
  color: var(--white);
  background: var(--green-primary);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.search-page-form__btn:hover { background: var(--green-mid); }
.search-grid { grid-template-columns: repeat(3, 1fr); grid-template-rows: none; }
.search-grid .card-title { font-size: 1.05rem; }
.search-grid .card-category { background: rgba(26,60,52,0.9); color: #fff; }
.search-grid .card-excerpt { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.search-page .archive-empty .btn-primary { margin-top: 0.5rem; }

.error-404-section {
  margin-top: var(--header-h);
  padding: 5rem 0 6rem;
  background: var(--off-white);
}
.error-404 { max-width: 640px; margin: 0 auto; text-align: center; }
.error-404__code {
  font-size: clamp(5rem, 22vw, 9rem);
  font-weight: 900;
  line-height: 1;
  color: transparent;
  background: linear-gradient(135deg, var(--green-primary), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
}
.error-404__title { margin: 1rem 0 0.5rem; font-size: clamp(1.5rem, 5vw, 2rem); color: var(--green-primary); }
.error-404__text { margin: 0 auto 2rem; max-width: 460px; color: var(--text-secondary); line-height: 1.8; }
.error-404 .search-page-form { margin: 0 auto 1.5rem; }
.error-404__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.75rem; }

/* ── 8. Pagination (archives & search) ────────────────────────────────── */
.archive-pagination { margin-top: 2.5rem; }
.archive-pagination ul.page-numbers {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.archive-pagination .page-numbers:not(ul) {
  min-width: 44px;
  height: 44px;
  padding: 0 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--green-primary);
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
}
.archive-pagination .page-numbers.current { color: var(--white); background: var(--green-primary); border-color: var(--green-primary); }
.archive-pagination a.page-numbers:hover { border-color: var(--green-mid); }
.archive-pagination .page-numbers.dots { border: 0; background: none; min-width: 24px; }

@media (max-width: 1024px) {
  .search-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .search-grid { grid-template-columns: 1fr; }
  .search-page-form { margin-bottom: 1.5rem; }
  .error-404-section { padding: 3rem 0 4rem; }
  .error-404__actions > * { flex: 1 1 140px; }
}

/* ── 9. Video player ──────────────────────────────────────────────────── */
/* Touch screens have no hover, so controls stay visible while playing. */
@media (hover: none) {
  .video-controls { opacity: 1; }
}
@media (max-width: 480px) {
  .video-controls { gap: 0.5rem; padding: 0 0.625rem; height: 52px; }
  .control-btn { width: 40px; height: 40px; }
  /* Phones change volume with hardware keys; the mute button stays. */
  .volume-slider { display: none; }
  .video-time { min-width: 0; font-size: 0.75rem; }
  .video-overlay-caption { bottom: 52px; padding: 0.75rem 1rem; font-size: 0.95rem; }
}

/* ── 10. Touch targets & minimum text size ────────────────────────────── */
@media (max-width: 768px) {
  /* Larger hit areas without changing the look. */
  .vsec-dot { position: relative; }
  .vsec-dot::after { content: ''; position: absolute; inset: -12px -6px; }
  .breadcrumb-link,
  .sidebar-link,
  .section-link { display: inline-flex; align-items: center; min-height: 40px; }
  .footer-legal { flex-wrap: wrap; justify-content: center; gap: 0.25rem 1rem; }
  .footer-legal a { display: inline-flex; align-items: center; min-height: 44px; }
  .newsletter-form input { height: 48px; padding: 0 1rem; }
  .newsletter-form button { min-height: 48px; }
  .agency-item strong a { display: inline-block; padding-block: 4px; }

  /* 11.2px labels are hard to read on phones. */
  .card-category,
  .card-category a,
  .pub-tag,
  .vsec-label,
  .video-time { font-size: 0.75rem; }
}

/* On touch devices the whole news card opens the article, not just its title. */
@media (hover: none) and (pointer: coarse) {
  .news-card { position: relative; }
  .news-card .card-title a::after { content: ''; position: absolute; inset: 0; z-index: 1; }
  /* Already absolutely positioned in main.css: only lift them above the link. */
  .news-card .card-actions,
  .news-card .card-category { z-index: 2; }
}

/* main.css stacks the newsletter form vertically under 480px; the field's
   flex:1 then collapses its height to ~20px. Size it by its own height. */
@media (max-width: 480px) {
  .newsletter-form input { flex: none; width: 100%; }
}

/* Category pill links: the whole pill is the target, not just its word. */
@media (max-width: 768px) {
  .card-category { padding: 6px 12px; }
  .card-category a { display: block; margin: -6px -12px; padding: 6px 12px; color: inherit; }
}
