/* ==========================================================
   LWFG — Knockout bracket
   Final at the left, opening round at the right
   ========================================================== */



.lwf-knockout-bracket {
    width: calc(100% - 48px);
    max-width: 1320px;

    margin-left: auto;
    margin-right: auto;

    min-width: 0;
    padding: 24px;

    box-sizing: border-box;

    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
}

.lwf-knockout-heading {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 0 26px;
}

.lwf-knockout-heading h3 {
    margin: 0;
    color: #111827;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.5;
}

.lwf-knockout-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 16px 10px 24px;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.lwf-knockout-tree {
    --ko-col-width: 260px;
    --ko-col-gap: 60px;
    --ko-row-height: 112px;
    --ko-line-color: #cbd5e1;
    --ko-line-width: 2px;

    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: var(--ko-col-gap);
    width: max-content;
    min-width: 100%;
    position: relative;
    direction: ltr;
    box-sizing: border-box;
}

/* Each round is one column. PHP reverses the rounds for final-left order. */
.lwf-ko-round {
    width: var(--ko-col-width);
    min-width: var(--ko-col-width);
    flex: 0 0 var(--ko-col-width);
    display: flex;
    flex-direction: column;
    position: relative;
    box-sizing: border-box;
}

.lwf-ko-round-title {
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    max-width: 100%;
    margin: 0 0 14px;
    padding: 7px 13px;
    border: 1px solid #e5e7eb;
    border-radius: 9px;
    background: #fff;
    color: #111827;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.4;
    text-align: center;
    white-space: nowrap;
    box-sizing: border-box;
}

.lwf-ko-round.is-current-round .lwf-ko-round-title {
    border-color: #008f4c;
    background: #f0fdf4;
    color: #008f4c;
}

.lwf-ko-round-matches {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(var(--ko-rows), var(--ko-row-height));
    width: 100%;
    flex: 1 0 auto;
    position: relative;
    overflow: visible;
    box-sizing: border-box;
}

.lwf-ko-slot {
    grid-row: span var(--ko-span);
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: visible;
    box-sizing: border-box;
}

/* Match cards */
.lwf-ko-match {
    width: 100%;
    min-height: 72px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 9px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #f1f3f6;
    color: #111827;
    text-decoration: none;
    position: relative;
    z-index: 2;
    box-sizing: border-box;
    transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.lwf-ko-match:hover {
    border-color: #008f4c;
    box-shadow: 0 3px 10px rgb(15 23 42 / 7%);
    transform: translateY(-1px);
}

.lwf-ko-match.is-current {
    border-color: #008f4c;
    background: #f7fcf8;
}

.lwf-ko-match--placeholder {
    cursor: default;
}

.lwf-ko-team {
    min-width: 0;
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 7px;
    direction: rtl;
}

.lwf-ko-team img,
.lwf-ko-logo-placeholder {
    display: block;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    object-fit: contain;
}

.lwf-ko-logo-placeholder {
    border-radius: 4px;
}

.lwf-ko-team-name {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    color: #374151;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}

.lwf-ko-score {
    min-width: 14px;
    flex: 0 0 auto;
    color: #111827;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-align: left;
}

/* ==========================================================
   CONNECTORS
   For each pair of matches in a round:
   - a horizontal line leaves each match toward the left
   - a vertical line joins the pair
   - the next-round match connects back to the join
   ========================================================== */

/* The two horizontal branches from each match in rounds to the right. */
.lwf-ko-round:not(:first-child) .lwf-ko-slot::after {
    content: "";
    position: absolute;
    z-index: 1;
    top: 50%;
    left: calc(-1 * var(--ko-col-gap) / 2);
    width: calc(var(--ko-col-gap) / 2);
    height: var(--ko-line-width);
    background: var(--ko-line-color);
    transform: translateY(-50%);
    pointer-events: none;
}

/* Vertical join: the top match of each pair reaches down to its partner. */
.lwf-ko-round:not(:first-child) .lwf-ko-slot:nth-child(odd)::before {
    content: "";
    position: absolute;
    z-index: 1;
    top: 50%;
    left: calc(-1 * var(--ko-col-gap) / 2);
    width: var(--ko-line-width);
    height: 100%;
    background: var(--ko-line-color);
    pointer-events: none;
}

/* Horizontal branch from the join toward the next-round match on the left.
   The card's pseudo-element is used so it doesn't conflict with the slot lines. */
.lwf-ko-round:not(:last-child) .lwf-ko-match::after {
    content: "";
    position: absolute;
    z-index: 1;
    top: 50%;
    right: calc(-1 * var(--ko-col-gap) / 2);
    width: calc(var(--ko-col-gap) / 2);
    height: var(--ko-line-width);
    background: var(--ko-line-color);
    transform: translateY(-50%);
    pointer-events: none;
}

/* Keep the connectors behind the cards. */
.lwf-ko-round,
.lwf-ko-round-matches,
.lwf-ko-slot {
    overflow: visible;
}

/* Hide legacy bracket elements if any are still present. */
.lwf-knockout-half,
.lwf-knockout-half-right,
.lwf-knockout-half-left,
.lwf-knockout-center,
.lwf-knockout-final-label,
.lwf-knockout-bottom-final-label {
    display: none !important;
}

/* Tablet */
@media (max-width: 1100px) {
    .lwf-knockout-bracket {
        padding: 20px 16px;
    }

    .lwf-knockout-tree {
        --ko-col-width: 235px;
        --ko-col-gap: 44px;
        --ko-row-height: 106px;
        justify-content: flex-start;
    }

    .lwf-ko-match {
        padding: 10px 11px;
        gap: 8px;
    }
}

/* Mobile: keep the bracket intact and scroll horizontally. */
@media (max-width: 768px) {
    .lwf-knockout-bracket {
        padding: 17px 10px;
        border-radius: 13px;
    }

    .lwf-knockout-heading {
        margin-bottom: 18px;
    }

    .lwf-knockout-heading h3 {
        font-size: 18px;
    }

    .lwf-knockout-scroll {
        padding: 12px 6px 20px;
    }

    .lwf-knockout-tree {
        --ko-col-width: 220px;
        --ko-col-gap: 34px;
        --ko-row-height: 96px;
        justify-content: flex-start;
    }

    .lwf-ko-round-title {
        min-height: 30px;
        margin-bottom: 12px;
        padding: 6px 10px;
        font-size: 11px;
    }

    .lwf-ko-match {
        min-height: 78px;
        padding: 9px 10px;
        gap: 7px;
    }

    .lwf-ko-team {
        gap: 5px;
    }

    .lwf-ko-team img,
    .lwf-ko-logo-placeholder {
        width: 21px;
        height: 21px;
        flex-basis: 21px;
    }

    .lwf-ko-team-name {
        font-size: 11px;
    }

    .lwf-ko-score {
        font-size: 12px;
    }
}

/* ==========================================================
   توحيد حجم نتيجة المباراة وركلات الترجيح
   ========================================================== */

.lwf-ko-penalty-score {
    flex: 0 0 auto;
    color: #111827;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-align: left;
}

/* نفس حجم النتيجة الأساسية في الهاتف */
@media (max-width: 768px) {
    .lwf-ko-penalty-score {
        font-size: 12px;
    }
}

.lwf-ko-penalty-score {
    flex: 0 0 auto;
    color: #111827;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-align: left;

    /* تقريب نتيجة الركلات من النتيجة الأساسية */
    margin-left: -9px;
}

/* =========================================
   الأدوار الإقصائية - توحيد العرض في الهاتف
========================================= */

@media (max-width: 768px) {

    .match-page .match-content .lwf-knockout-bracket {
        width: calc(100vw - 30px) !important;
        max-width: none !important;

        margin-left: calc((100% - (100vw - 30px)) / 2) !important;
        margin-right: calc((100% - (100vw - 30px)) / 2) !important;

        box-sizing: border-box !important;
    }

}

/* =========================================
   Knockout Bracket - French / LTR
========================================= */

.lwf-knockout-bracket--fr {
    direction: ltr !important;
    text-align: left !important;
}

/* عنوان البطاقة */
.lwf-knockout-bracket--fr .lwf-knockout-heading {
    direction: ltr !important;
}

/* الـ bracket */
.lwf-knockout-bracket--fr .lwf-knockout-scroll,
.lwf-knockout-bracket--fr .lwf-knockout-tree {
    direction: ltr !important;
}

/* عناوين الأدوار */
.lwf-knockout-bracket--fr .lwf-ko-round-title {
    direction: ltr !important;
    text-align: center !important;
}

/* بطاقات المباريات */
.lwf-knockout-bracket--fr .lwf-ko-match {
    direction: ltr !important;
    text-align: left !important;
}

/* الفريق */
.lwf-knockout-bracket--fr .lwf-ko-team {
    direction: ltr !important;
    flex-direction: row !important;
    text-align: left !important;
}

/* اسم الفريق */
.lwf-knockout-bracket--fr .lwf-ko-team-name {
    direction: ltr !important;
    text-align: left !important;
}

/* النتيجة */
.lwf-knockout-bracket--fr .lwf-ko-score,
.lwf-knockout-bracket--fr .lwf-ko-penalty-score {
    direction: ltr !important;
    text-align: left !important;
}

/* =========================================
   French bracket - align inside match page
========================================= */

@media (min-width: 993px) {

    .match-content .lwf-knockout-bracket--fr {
        margin-left: auto !important;
        margin-right: 0 !important;
    }

}

/* =========================================
   French bracket - true LTR stage order
========================================= */

.lwf-knockout-bracket--fr .lwf-knockout-tree {
    direction: ltr !important;
}

/* =========================================
   French bracket - connectors
========================================= */

/* الدخول إلى الدور التالي من اليسار */
.lwf-knockout-bracket--fr
.lwf-ko-round:not(:first-child)
.lwf-ko-slot::after {
    left: calc(-1 * var(--ko-col-gap) / 2) !important;
    right: auto !important;
}

 /* =========================================
    French bracket - vertical joins
========================================= */

/* إلغاء الخط العمودي من بطاقة النهائي */
.lwf-knockout-bracket--fr
.lwf-ko-round:last-child
.lwf-ko-slot::before {
    content: none !important;
}

/* الخط العمودي يكون على يمين الدور
   ويربط المباراتين مع بعض */
.lwf-knockout-bracket--fr
.lwf-ko-round:not(:first-child):not(:last-child)
.lwf-ko-slot:nth-child(odd)::before {
    content: "";
    position: absolute;
    z-index: 1;

    top: 50%;
    right: calc(-1 * var(--ko-col-gap) / 2);
    left: auto;

    width: var(--ko-line-width);
    height: 100%;

    background: var(--ko-line-color);

    transform: translateY(0);
    pointer-events: none;
}

/* الخروج من الدور نحو الدور الذي بعده */
.lwf-knockout-bracket--fr
.lwf-ko-round:not(:last-child)
.lwf-ko-match::after {
    right: calc(-1 * var(--ko-col-gap) / 2) !important;
    left: auto !important;
}