/* =========================================================
   APF Academy v2.1
   Final header + mobile alignment + footer refinements
   ---------------------------------------------------------
   - Opaque header and App Switcher
   - Desktop: brand + App / search / start action, nav below
   - Mobile: ONE row only => logo + App + search
   - Anchor offsets for sticky header
   - RTL mobile alignment fixes for selected homepage sections
   - Footer academy/network cards side-by-side on mobile
========================================================= */

:root {
    --apfa-header-bg: #070a0e;
    --apfa-header-surface: #0d1219;
    --apfa-header-surface-2: #111821;
    --apfa-header-line: #1b232d;
    --apfa-header-line-strong: #26313d;
    --apfa-header-text: #f3f6f8;
    --apfa-header-muted: #7f8b99;
    --apfa-brand-accent: #14b8a6;
    --apfa-brand-accent-2: #67e8d6;
    --apfa-brand-accent-3: #b4fff5;
}

/* ---------- Sticky / opaque shell ---------- */
.apfa-header {
    position: sticky;
    top: 0;
    z-index: 1500;
    width: 100%;
    background: var(--apfa-header-bg);
    border-bottom: 1px solid #151c24;
    box-shadow: 0 10px 30px rgba(0,0,0,.22);
}

.apfa-topbar {
    min-height: 76px;
    background: var(--apfa-header-bg);
}

.apfa-topbar-grid {
    min-height: 76px;
    display: grid;
    grid-template-columns: minmax(245px,1fr) minmax(340px,540px) minmax(245px,1fr);
    grid-template-areas: "left search brand";
    align-items: center;
    gap: 24px;
    direction: ltr;
}

/* ---------- Brand + App ---------- */
.apfa-brand-zone {
    grid-area: brand;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    direction: rtl;
}

.apfa-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    direction: rtl;
    text-decoration: none;
    flex: 0 0 auto;
}

.apfa-dynamic-logo {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: block;
    filter: drop-shadow(0 0 12px rgba(45,212,191,.24));
}
.apfa-dynamic-logo > use { fill: var(--apfa-brand-accent); }

.apfa-brand-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
    line-height: 1.18;
    direction: rtl;
}

.apfa-brand-copy strong,
.footer-logo-gradient {
    display: inline-block;
    direction: ltr;
    font-weight: 900;
    letter-spacing: .15px;
    background: linear-gradient(92deg, var(--apfa-brand-accent) 0%, var(--apfa-brand-accent-2) 52%, var(--apfa-brand-accent-3) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}

.apfa-brand-copy strong {
    font-size: 22px;
    white-space: nowrap;
}
.apfa-brand-copy small {
    margin-top: 4px;
    color: #8b96a4;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

/* ---------- App launcher: fully opaque ---------- */
.apfa-app-launcher {
    position: relative;
    flex: 0 0 auto;
}

.apfa-app-button {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid #29333e;
    border-radius: 16px;
    background: #11161d;
    color: #f4f4f5;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.035), 0 8px 22px rgba(0,0,0,.22);
    transition: transform .2s ease, border-color .2s ease, background .2s ease, color .2s ease;
}
.apfa-grid-icon {
    width: 23px;
    height: 23px;
    fill: currentColor;
}
.apfa-app-button:hover,
.apfa-app-launcher.is-open .apfa-app-button {
    transform: translateY(-1px);
    color: var(--apfa-brand-accent-2);
    border-color: #2a756d;
    background: #10211f;
}

.apfa-app-dropdown {
    position: absolute;
    top: calc(100% + 14px);
    right: 0;
    width: 352px;
    padding: 12px;
    border: 1px solid #26262c;
    border-radius: 24px;
    background: #0d0d10;
    box-shadow: 0 24px 70px rgba(0,0,0,.62), 0 0 34px rgba(45,212,191,.08);
    z-index: 40;
    direction: rtl;
}
.apfa-app-dropdown[hidden] { display: none !important; }
.apfa-app-dropdown::before {
    content: "";
    position: absolute;
    top: -7px;
    right: 18px;
    width: 14px;
    height: 14px;
    background: #0d0d10;
    border-right: 1px solid #26262c;
    border-top: 1px solid #26262c;
    transform: rotate(-45deg);
}

.apfa-app-card {
    --app-accent: #67e8d6;
    position: relative;
    min-height: 84px;
    display: grid;
    grid-template-columns: 46px minmax(0,1fr);
    align-items: center;
    gap: 13px;
    padding: 13px 14px;
    border: 1px solid #24242a;
    border-radius: 17px;
    background: linear-gradient(135deg,#141418,#101014);
    color: #f3f4f6;
    text-decoration: none;
    overflow: hidden;
    transition: transform .2s ease, border-color .2s ease, background .2s ease;
}
.apfa-app-card + .apfa-app-card { margin-top: 9px; }
.apfa-app-card--academy { --app-accent:#2dd4bf; }
.apfa-app-card--arab { --app-accent:#e1ba32; }
.apfa-app-card--prop { --app-accent:#16c79a; }
.apfa-app-card--brokers { --app-accent:#3c91ff; }
.apfa-app-card:hover {
    transform: translateY(-2px);
    border-color: var(--app-accent);
    background: #16161b;
}
.apfa-app-card[aria-current="page"] {
    border-color: #2a756d;
    background: #111b1b;
}
.apfa-app-card-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border: 1px solid #2b333c;
    border-radius: 14px;
    background: #0b0e12;
}
.apfa-app-card-mark svg { width: 27px; height: 27px; display: block; }
.apfa-app-card-mark use { fill: var(--app-accent); }
.apfa-app-card-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.apfa-app-card-copy strong {
    font-size: 13px;
    font-weight: 900;
    line-height: 1.4;
    direction: ltr;
    text-align: right;
    color: #f5f5f6;
}
.apfa-app-card-copy small {
    margin-top: 4px;
    color: #858b97;
    font-size: 9px;
    line-height: 1.55;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- Search ---------- */
.apfa-search {
    grid-area: search;
    position: relative;
    height: 46px;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0,1fr) 46px;
    direction: rtl;
    border: 1px solid #27313c;
    border-radius: 15px;
    background: #0d1219;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.apfa-search:focus-within {
    border-color: #2d756d;
    box-shadow: 0 0 0 3px rgba(45,212,191,.06);
}
.apfa-search input {
    min-width: 0;
    width: 100%;
    height: 44px;
    border: 0;
    outline: 0;
    background: transparent;
    color: #f1f5f9;
    padding: 0 15px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
}
.apfa-search input::placeholder { color: #687584; }
.apfa-search button {
    width: 46px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    border-right: 1px solid #202a34;
    background: transparent;
    color: #8f9baa;
    cursor: pointer;
}
.apfa-search button:hover { color: var(--apfa-brand-accent-2); }
.apfa-search button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.apfa-search-suggestions {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    left: 0;
    max-height: min(430px,65vh);
    overflow: auto;
    padding: 7px;
    border: 1px solid #26313d;
    border-radius: 16px;
    background: #0c1117;
    box-shadow: 0 22px 65px rgba(0,0,0,.58);
    z-index: 50;
    direction: rtl;
}
.apfa-search-suggestions[hidden] { display:none !important; }
.apfa-search-state { padding: 15px 13px; color:#7f8b99; font-size:11px; }
.apfa-search-result {
    min-height: 60px;
    display: grid;
    grid-template-columns: 34px minmax(0,1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 8px 9px;
    border: 1px solid transparent;
    border-radius: 11px;
    color: #eef2f6;
    text-decoration: none;
}
.apfa-search-result:hover,
.apfa-search-result.is-focused { background:#121820; border-color:#202b36; }
.apfa-search-result-icon {
    width: 34px;
    height: 34px;
    display:grid;
    place-items:center;
    border:1px solid #27313b;
    border-radius:10px;
    background:#10161d;
    color:#67e8d6;
    font-size:10px;
    font-weight:900;
}
.apfa-search-result-copy { min-width:0; display:flex; flex-direction:column; }
.apfa-search-result-copy strong { font-size:11px; font-weight:800; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.apfa-search-result-copy small { margin-top:2px; color:#6f7b89; font-size:9px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.apfa-search-result-type { color:#7f8b99; font-size:8px; white-space:nowrap; }
.apfa-search-footer {
    display:block;
    margin-top:5px;
    padding:10px 11px;
    border-top:1px solid #1b252f;
    color:#7fe7db;
    text-decoration:none;
    font-size:10px;
    font-weight:800;
}

/* ---------- Left action desktop ---------- */
.apfa-left-zone {
    grid-area: left;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-width: 0;
    direction: rtl;
}
.apfa-start-button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 15px;
    border: 1px solid #28675f;
    border-radius: 13px;
    background: #10201f;
    color: #baf7ef;
    text-decoration: none;
    font-size: 10px;
    font-weight: 900;
}
.apfa-start-button svg {
    width: 16px;
    height: 16px;
    fill:none;
    stroke:currentColor;
    stroke-width:1.8;
    stroke-linecap:round;
    stroke-linejoin:round;
}

.apfa-menu-button {
    display:none;
    width:42px;
    height:42px;
    place-items:center;
    padding:0;
    border:1px solid #29333e;
    border-radius:14px;
    background:#11161d;
    color:#eef3f6;
    cursor:pointer;
    box-shadow:inset 0 1px 0 rgba(255,255,255,.035), 0 8px 22px rgba(0,0,0,.20);
}
.apfa-menu-button svg {
    width:20px;
    height:20px;
    fill:none;
    stroke:currentColor;
    stroke-width:1.9;
    stroke-linecap:round;
}
.apfa-menu-button:hover,
.apfa-menu-button[aria-expanded="true"] {
    color:var(--apfa-brand-accent-2);
    border-color:#2a756d;
    background:#10211f;
}


/* ---------- Desktop nav ---------- */
.apfa-nav-row {
    height: 48px;
    display: block;
    background: #080c11;
    border-top: 1px solid #141b22;
}
.apfa-nav {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    direction: rtl;
}
.apfa-nav a {
    position: relative;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 15px;
    border-radius: 10px;
    color: #8e9aa8;
    text-decoration: none;
    font-size: 10px;
    font-weight: 800;
    transition: color .18s ease, background .18s ease;
}
.apfa-nav a:hover,
.apfa-nav a.is-active { color:#eef3f6; background:#0e141b; }
.apfa-nav a.is-active::after {
    content:"";
    position:absolute;
    right:15px;
    left:15px;
    bottom:0;
    height:2px;
    border-radius:99px 99px 0 0;
    background:var(--apfa-brand-accent-2);
}

/* Sticky anchor compensation: the heading itself remains fully visible. */
#start,
#paths { scroll-margin-top: 140px; }

/* ---------- Search results page ---------- */
.apfa-results { display:grid; gap:14px; }
.apfa-result-group { border:1px solid var(--line); border-radius:20px; background:rgba(255,255,255,.022); overflow:hidden; }
.apfa-result-group-head { display:flex; align-items:center; justify-content:space-between; gap:15px; padding:17px 18px; border-bottom:1px solid var(--line); }
.apfa-result-group-head h2 { font-size:16px; font-weight:900; }
.apfa-result-group-head span { color:var(--muted); font-size:10px; }
.apfa-result-list { display:grid; }
.apfa-result-item { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:14px; align-items:center; padding:16px 18px; color:inherit; text-decoration:none; border-bottom:1px solid rgba(255,255,255,.055); }
.apfa-result-item:last-child { border-bottom:0; }
.apfa-result-item:hover { background:rgba(255,255,255,.025); }
.apfa-result-item h3 { font-size:14px; font-weight:850; }
.apfa-result-item p { margin-top:4px; color:var(--muted); font-size:11px; line-height:1.75; }
.apfa-result-item span { color:#7fe7db; font-size:9px; font-weight:800; white-space:nowrap; }
.apfa-search-page-form { max-width:760px; margin:24px auto 0; display:grid; grid-template-columns:1fr auto; gap:8px; }
.apfa-search-page-form input { min-height:50px; border:1px solid var(--line-strong); border-radius:14px; padding:0 15px; background:rgba(255,255,255,.03); color:#fff; outline:none; }
.apfa-search-page-form input:focus { border-color:rgba(45,212,191,.32); }
.apfa-search-page-form button { min-width:86px; border:1px solid rgba(45,212,191,.25); border-radius:14px; background:var(--academy); color:#05110f; font-weight:900; cursor:pointer; }

/* ---------- Footer branding ---------- */
.footer-logo { direction:ltr; text-align:right; }
.footer-logo-gradient { font-size:20px; }
.footer-nav-card { min-width:0; }
.footer-bottom { justify-content:center; text-align:center; }

/* ---------- Tablet ---------- */
@media (max-width: 1080px) {
    .apfa-topbar-grid {
        grid-template-columns: minmax(205px,1fr) minmax(280px,460px) minmax(205px,1fr);
        gap: 14px;
    }
    .apfa-brand-copy strong { font-size:19px; }
    .apfa-brand-copy small { display:none; }
    .apfa-start-button span { display:none; }
    .apfa-start-button { width:42px; padding:0; }
}

/* =========================================================
   MOBILE: exactly one header row
   Right -> Logo -> App -> Search -> Left
========================================================= */
@media (max-width: 780px) {
    .apfa-header { box-shadow:0 8px 24px rgba(0,0,0,.24); }
    .apfa-topbar,
    .apfa-topbar-grid { min-height:62px; }

    .apfa-topbar-grid {
        display:grid;
        grid-template-columns: auto minmax(0,1fr) auto;
        grid-template-areas:"brand search menu";
        align-items:center;
        gap:8px;
        direction:rtl;
    }

    .apfa-brand-zone {
        grid-area:brand;
        display:flex;
        align-items:center;
        justify-content:flex-start;
        gap:8px;
        direction:rtl;
        min-width:auto;
    }

    .apfa-brand {
        gap:0;
        flex:0 0 auto;
    }
    .apfa-brand-copy { display:none !important; }
    .apfa-dynamic-logo {
        width:40px;
        height:40px;
        flex-basis:40px;
    }

    .apfa-app-button {
        width:40px;
        height:40px;
        border-radius:14px;
    }
    .apfa-grid-icon { width:21px; height:21px; }

    .apfa-search {
        grid-area:search;
        width:100%;
        min-width:0;
        height:42px;
        grid-template-columns:minmax(0,1fr) 42px;
        border-radius:13px;
    }
    .apfa-search input {
        height:40px;
        padding-inline:11px;
        font-size:10px;
    }
    .apfa-search button {
        width:42px;
        height:40px;
    }

    .apfa-left-zone {
        grid-area:menu;
        display:flex !important;
        align-items:center;
        justify-content:flex-end;
        min-width:auto;
    }
    .apfa-start-button { display:none !important; }
    .apfa-menu-button { display:grid; }

    .apfa-nav-row {
        display:none !important;
        position:absolute;
        top:calc(100% + 8px);
        right:10px;
        left:10px;
        height:auto;
        padding:7px;
        border:1px solid #26313d;
        border-radius:16px;
        background:#0c1117;
        box-shadow:0 20px 55px rgba(0,0,0,.52);
        z-index:45;
    }
    .apfa-nav-row.is-open { display:block !important; }
    .apfa-nav {
        min-height:0;
        display:grid;
        grid-template-columns:1fr;
        gap:3px;
        padding:0;
    }
    .apfa-nav a {
        min-height:43px;
        width:100%;
        justify-content:flex-start;
        padding:0 13px;
        border-radius:11px;
        font-size:10.5px;
        text-align:right;
    }
    .apfa-nav a.is-active::after {
        top:9px;
        bottom:9px;
        right:0;
        left:auto;
        width:2px;
        height:auto;
        border-radius:0 99px 99px 0;
    }

    .apfa-app-dropdown {
        width:min(352px, calc(100vw - 24px));
        right:-48px;
        left:auto;
        top:calc(100% + 12px);
    }
    .apfa-app-dropdown::before { right:64px; }

    #start,
    #paths { scroll-margin-top: 74px; }

    /* Requested RTL correction for sections that appeared left-biased. */
    .section-stage-buying .shell,
    .section-stage-articles .shell,
    .section-stage-faq .shell {
        direction:rtl;
        text-align:right;
    }
    .section-stage-buying .section-head,
    .section-stage-articles .section-head,
    .section-stage-faq .section-head {
        width:100%;
        align-items:flex-start;
        text-align:right;
        direction:rtl;
    }
    .section-stage-buying .section-head-copy,
    .section-stage-articles .section-head-copy,
    .section-stage-faq .section-head-copy {
        width:100%;
        max-width:none;
        margin-right:0;
        margin-left:auto;
        padding-right:13px;
        padding-left:0;
        text-align:right;
    }
    .section-stage-articles .text-link {
        align-self:flex-start;
        margin-right:0;
        margin-left:auto;
    }
    .section-stage-buying .buying-grid,
    .section-stage-articles .articles-grid,
    .section-stage-faq .faq-list {
        width:100%;
        direction:rtl;
        justify-items:stretch;
    }
    .section-stage-buying .check-card,
    .section-stage-articles .article-card,
    .section-stage-faq .faq-item {
        width:100%;
        margin:0;
        text-align:right;
        direction:rtl;
    }
    .section-stage-buying .check-icon { margin-right:0; margin-left:auto; }

    /* Footer: brand full width, then two cards next to each other. */
    .footer-grid {
        grid-template-columns:repeat(2,minmax(0,1fr)) !important;
        gap:12px !important;
        padding-top:32px;
    }
    .footer-brand-block {
        grid-column:1 / -1 !important;
        text-align:right;
        margin-bottom:4px;
    }
    .footer-nav-card {
        min-width:0;
        padding:16px 14px;
        border:1px solid rgba(255,255,255,.07);
        border-radius:16px;
        background:#0d1117;
    }
    .footer-nav-card h3 { margin-bottom:10px; }
    .footer-nav-card a {
        width:100%;
        font-size:10px;
        line-height:1.55;
        white-space:normal;
    }
    .footer-bottom {
        display:block !important;
        padding:14px 0 18px;
        font-size:9px;
        white-space:nowrap;
        text-align:center;
    }
}

@media (max-width: 480px) {
    .apfa-topbar-grid { gap:7px; }
    .apfa-dynamic-logo { width:38px; height:38px; flex-basis:38px; }
    .apfa-app-button { width:38px; height:38px; border-radius:13px; }
    .apfa-grid-icon { width:20px; height:20px; }
    .apfa-menu-button { width:38px; height:38px; border-radius:13px; }
    .apfa-menu-button svg { width:19px; height:19px; }
    .apfa-search { height:40px; grid-template-columns:minmax(0,1fr) 40px; }
    .apfa-search input { height:38px; font-size:9.5px; }
    .apfa-search button { width:40px; height:38px; }
    .apfa-app-dropdown { right:-46px; }
    .apfa-app-dropdown::before { right:61px; }
    .apfa-search-page-form { grid-template-columns:1fr; }
    .apfa-search-page-form button { min-height:46px; }
    .footer-nav-card { padding:14px 12px; }
    .footer-nav-card h3 { font-size:11px; }
    .footer-nav-card a { font-size:9.5px; }
    .footer-bottom { font-size:8.5px; }
}
