/* ============================================================
   CaptainProLive – Matches (STABLE FINAL)
   ✅ Desktop: Left(Group+Match) | Right(Date+Status)
   ✅ Mobile: Group/Match داخل الكارد + يمين مضبوط
   ✅ Tabs order ثابت (Groups ثم Knockout)
   ✅ Filters start LEFT (scrollable on mobile)
   ✅ Info + Time + Countdown align LEFT
   ✅ Animations + LIVE glow
============================================================ */

/* ============================
   GENERAL WRAPPER
============================ */
.cpl-wrapper{
  background:#000;
  padding:15px;
  border-radius:10px;
  color:#fff;
  font-family:Arial, sans-serif;

  /* نخلي محتوى منطقة المباريات LTR عشان الترتيب ما يتقلبش بسبب RTL العام */
  direction:ltr;
}

/* ============================
   HEADER: TABS + SEARCH
   Tabs LEFT / Search RIGHT
============================ */
.cpl-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin-bottom:15px;
}

.cpl-tabs{
  display:flex;
  gap:10px;
  direction:ltr; /* مهم جدًا لترتيب Groups ثم Knockout */
}

.cpl-tab-btn{
  background:#111;
  color:#fff;
  padding:8px 14px;
  border-radius:6px;
  border:1px solid #333;
  cursor:pointer;
  font-weight:bold;
  transition:0.2s;
}

.cpl-tab-btn:hover{ background:#222; }

.cpl-tab-btn.active{
  background:#d4af37;
  color:#000;
  border-color:#d4af37;
}

.cpl-search-box{
  flex:0 0 auto;
}

.cpl-search-box input{
  padding:8px 12px;
  border-radius:6px;
  border:1px solid #333;
  background:#111;
  color:#fff;
  min-width:220px;
}

/* ============================
   SUBTABS (GROUPS / KNOCKOUT)
   Start LEFT
============================ */
.cpl-subtabs{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-bottom:15px;
  justify-content:flex-start;
  direction:ltr;
}

.cpl-filter-btn{
  background:#111;
  color:#fff;
  padding:6px 12px;
  border-radius:6px;
  border:1px solid #333;
  cursor:pointer;
  font-size:13px;
  transition:0.2s;
}

.cpl-filter-btn:hover{ background:#222; }

.cpl-filter-btn.active{
  background:#d4af37;
  color:#000;
  border-color:#d4af37;
}

/* ============================
   MATCH CARD
============================ */
.cpl-match{
  background:#0a0a0a;
  border:1px solid #333;
  padding:12px;
  border-radius:10px;
  margin-bottom:15px;

  /* Safety: يمنع أي خروج بره الكارد */
  overflow:hidden;
}

/* ============================
   TOP BAR + HEADER ROW (DESKTOP)
   Left: Group + Match
   Right: Date + Status
   NOTE: نستخدم GRID ثابت بدون absolute
============================ */
.cpl-topbar,
.cpl-header-row{
  display:grid;
  grid-template-columns: 1fr 1fr;
  align-items:center;
  column-gap:10px;
  row-gap:6px;
}

/* Left side (Group / Match) */
.cpl-stage-badge{
  justify-self:start;
  background:#d4af37;
  color:#000;
  padding:4px 10px;
  border-radius:6px;
  font-weight:bold;
  white-space:nowrap;
  max-width:100%;
  overflow:hidden;
  text-overflow:ellipsis;
}

.cpl-match-number{
  justify-self:start;
  color:#FFD800;
  opacity:1;
  background:rgba(0,0,0,0.75);
  padding:6px 12px;
  border-radius:10px;
  border:1px solid rgba(255,216,0,0.5);
  font-size:14px;
  font-weight:900;
  text-shadow:0 0 6px rgba(0,0,0,0.8);
  display:inline-block;
  white-space:nowrap;
}

/* Right side (Date / Status) */
.cpl-date-label{
  justify-self:end;
  color:#ccc;
  white-space:nowrap;
}

.cpl-status-badge{
  justify-self:end;
  padding:4px 10px;
  border-radius:6px;
  font-weight:bold;
  color:#000;
  white-space:nowrap;
}

.cpl-status-upcoming{ background:#3498db; }
.cpl-status-live{ background:#e74c3c; }
.cpl-status-finished{ background:#2ecc71; }

/* ============================
   LIVE GLOW EFFECT
============================ */
.cpl-status-live{
  box-shadow:0 0 8px rgba(255,0,0,0.75);
  animation:liveGlow 1.2s infinite alternate;
}

@keyframes liveGlow{
  from{
    box-shadow:0 0 6px rgba(255,0,0,0.55), 0 0 12px rgba(255,0,0,0.35);
    transform:scale(1);
  }
  to{
    box-shadow:0 0 12px rgba(255,0,0,0.95), 0 0 20px rgba(255,0,0,0.75);
    transform:scale(1.05);
  }
}

/* ============================
   TEAMS ROW
============================ */
.cpl-teams-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  margin:12px 0;
}

.cpl-team{
  display:flex;
  align-items:center;
  gap:8px;
  min-width:0;
}

.cpl-team-name{
  font-size:15px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:180px;
}

.cpl-flag{
  width:32px;
  height:22px;
  border-radius:3px;
  object-fit:cover;
  flex:0 0 auto;
}

.cpl-flag-empty{
  width:34px;
  height:24px;
  border-radius:6px;
  border:1px dashed rgba(255,255,255,0.25);
  background:rgba(255,255,255,0.04);
  flex:0 0 auto;
}

.cpl-score{
  font-size:24px;
  font-weight:bold;
  color:#d4af37;
  white-space:nowrap;
}

/* ============================
   INFO + COUNTDOWN (ALIGN LEFT)
============================ */
.cpl-info{
  background:#000;
  padding:10px;
  border-radius:8px;
  border:1px solid #222;
  font-size:13px;

  direction:ltr;
  text-align:left;
}

.cpl-info div{ text-align:left; }

.cpl-info span{
  font-weight:bold;
  color:#d4af37;
}

.cpl-countdown{
  margin-top:10px;
  text-align:left;
}

.cpl-countdown-values{
  display:flex;
  gap:6px;
  margin-top:4px;
  justify-content:flex-start;
}

/* Bounce for countdown digits (JS adds .updated) */
.cpl-countdown-values span{
  display:inline-block;
  transition:transform 0.2s ease, color 0.2s ease;
}
.cpl-countdown-values span.updated{
  transform:scale(1.15);
  color:#FFD800;
}

/* ============================
   ANIMATION (tab changes)
============================ */
.cpl-match{
  animation:fadeInMatch 0.25s ease;
}
@keyframes fadeInMatch{
  from{ opacity:0; transform:translateY(6px); }
  to{ opacity:1; transform:translateY(0); }
}

/* ============================
   MOBILE – FINAL FIX
   ✅ هنا حل المشكلة اللي بتظهر عندك في iOS:
   Group A / Match # لازم يبقوا "يمين" داخل الكارد
   بدون أي absolute وبدون خروج.
============================ */
@media (max-width: 768px){

  /* Header stack */
  .cpl-header{
    flex-direction:column;
    align-items:stretch;
    gap:10px;
  }

  .cpl-search-box input{
    width:100%;
    min-width:unset;
  }

  .cpl-tabs{
    justify-content:space-between;
  }

  /* Filters horizontal scroll */
  .cpl-subtabs{
    flex-wrap:nowrap;
    overflow-x:auto;
    gap:6px;
    padding-bottom:6px;
  }

  .cpl-filter-btn{
    flex:0 0 auto;
    font-size:12px;
    padding:5px 10px;
  }

  .cpl-subtabs::-webkit-scrollbar{ height:4px; }
  .cpl-subtabs::-webkit-scrollbar-thumb{
    background:#444;
    border-radius:10px;
  }

  /* ============================
     ✅ النقطة الأساسية:
     نحول topbar + header-row إلى FLEX عمودي يمين
     عشان Group/Match يثبتوا يمين الكارد (زي اللي انت عايزه)
  ============================ */
  .cpl-topbar,
  .cpl-header-row{
    display:flex !important;
    flex-direction:column !important;
    align-items:flex-end !important;
    gap:6px !important;

    /* تمنع أي تحرك غريب */
    width:100%;
  }

  /* أحجام داخل الموبايل */
  .cpl-stage-badge,
  .cpl-date-label,
  .cpl-match-number,
  .cpl-status-badge{
    font-size:12px;
  }

  .cpl-match-number{
    padding:4px 8px;
  }
  .cpl-status-badge{
    padding:3px 8px;
  }

  /* Teams */
  .cpl-team-name{
    font-size:13px;
    max-width:120px;
  }
  .cpl-flag{
    width:24px;
    height:16px;
  }
  .cpl-score{
    font-size:18px;
  }

  /* Info */
  .cpl-info{
    font-size:12px;
    padding:8px;
  }
  .cpl-countdown-values{
    gap:4px;
    font-size:12px;
  }
}
/* ============================================================
   MOBILE HEADER LAYOUT (FINAL)
   Left: Group + Match (stacked)
   Right: Status
   Hide header date (date stays in info box)
============================================================ */
@media (max-width: 768px){

  /* خلي الكارد نفسه Grid */
  .cpl-match{
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    grid-template-areas:
      "left status"
      "left status"
      "teams teams"
      "info info" !important;
    row-gap: 10px !important;
  }

  /* خلي الـ wrappers ما تبقاش عناصر في الـ grid (الأبناء يدخلوا مباشرة) */
  .cpl-topbar,
  .cpl-header-row{
    display: contents !important;
  }

  /* اخفاء تاريخ الهيدر عشان ما يبقاش بين Group و Match */
  .cpl-date-label{
    display: none !important;
  }

  /* وضع Group في يسار الهيدر */
  .cpl-stage-badge{
    grid-area: left !important;
    justify-self: start !important;
    align-self: start !important;
    margin: 0 !important;
  }

  /* وضع Match تحت Group في نفس العمود اليسار */
  .cpl-match-number{
    grid-area: left !important;
    justify-self: start !important;
    align-self: end !important;
    margin: 6px 0 0 0 !important;
  }

  /* وضع Status في يمين نفس الصف */
  .cpl-status-badge{
    grid-area: status !important;
    justify-self: end !important;
    align-self: center !important;
    margin: 0 !important;
  }

  /* اجبار بقية أجزاء الكارد لمكانها */
  .cpl-teams-row{
    grid-area: teams !important;
  }

  .cpl-info{
    grid-area: info !important;
  }
}
/* ============================================================
   FINAL MOBILE FIX (LEFT GROUP / RIGHT STATUS)
============================================================ */
@media (max-width: 768px){

  /* نخلي الصف flex عادي */
  .cpl-topbar,
  .cpl-header-row{
    display:flex !important;
    justify-content:space-between !important;
    align-items:flex-start !important;
  }

  /* نخلي Group + Match على الشمال في عمود */
  .cpl-stage-badge,
  .cpl-match-number{
    align-self:flex-start !important;
    margin-left:0 !important;
  }

  /* نجمعهم عمود */
  .cpl-header-row{
    flex-direction:row !important;
  }

  /* نخلي الجزء الشمال stack */
  .cpl-header-row > *:first-child{
    display:flex;
    flex-direction:column;
    align-items:flex-start;
  }

  /* Status يمين */
  .cpl-status-badge{
    margin-left:auto !important;
  }

  /* ❌ نخفي التاريخ اللي مكرر */
  .cpl-date-label{
    display:none !important;
  }

}
/* ============================
   VISUAL ALERT - LIVE MATCH
============================ */

/* لما المباراة تبقى LIVE */
.cpl-match.live-active {
    animation: liveFlash 1s infinite alternate;
    border: 1px solid #ff0000;
}

/* حركة اللمعة */
@keyframes liveFlash {
    from {
        box-shadow: 0 0 8px rgba(255,0,0,0.5);
    }
    to {
        box-shadow: 0 0 18px rgba(255,0,0,1);
    }
}