:root {
    --primary: #005f7a;
    --primary-light: #007a9e; /* Darkened for better contrast */
    --primary-dark: #00435a;
    --secondary: #f6c400; /* brighter yellow */
    --dark: #222;
    --light: #f8f9fa;
    --danger: #c0392b;
    --success: #27ae60;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --letter-spacing-tight: -0.025em;
    --letter-spacing-normal: 0;
    --letter-spacing-wide: 0.025em;
    --font-sans-latin: "Inter", system-ui, -apple-system,
        BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue",
        Arial, sans-serif;
    --font-sans-arabic: "IBM Plex Sans Arabic", "Noto Sans Arabic",
        "Noto Naskh Arabic", "Noto Sans Arabic UI",
        "Segoe UI", "Tahoma", Arial, sans-serif;
}
@font-face {
    font-family: "Inter";
    src: url("../fonts/inter/Inter-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Inter";
    src: url("../fonts/inter/Inter-Medium.woff2") format("woff2");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "Inter";
    src: url("../fonts/inter/Inter-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Sans Arabic";
    src: url("../fonts/ibm-plex-sans-arabic/IBMPlexSansArabic-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Sans Arabic";
    src: url("../fonts/ibm-plex-sans-arabic/IBMPlexSansArabic-Medium.woff2") format("woff2");
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Sans Arabic";
    src: url("../fonts/ibm-plex-sans-arabic/IBMPlexSansArabic-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
*:not(input):not(textarea) {
    -webkit-user-select: auto;
    user-select: auto;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Limit list reset to nav & explicit reset lists */
nav ul, nav ol {
    list-style: none;
    margin: 0;
    padding: 0;
}
.reset-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
html {
    overflow-y: scroll;
    overflow-x: hidden; /* Prevent horizontal overflow on mobile */
    font-family: var(--font-sans-latin);
    font-size: 100%;
}
:lang(ar),
:lang(fa),
:lang(ur),
:lang(ps),
:lang(ku),
:lang(ckb),
html[lang="ar"],
[dir="rtl"] {
    font-family: var(--font-sans-arabic);
    letter-spacing: normal;
}
body {
    font-family: var(--font-sans-latin);
    background: var(--light);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-size: 1rem; /* 16px base */
    line-height: 1.6;
    overflow-x: hidden; /* Defensive: clip any accidental overflows */
}

/* Layout container */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    overflow-x: hidden;
}
header {
    background: var(--primary);
    color: #fff;
    padding: 1rem 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    border-bottom: 1px solid #e0e0e0;
}
.ck-content, .content-area {
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    overflow-x: hidden;
}
.row {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Direction-aware defaults for public content */

/* Make media responsive to avoid horizontal scrolling */
img, svg, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

/* Allow flex children to shrink to viewport to prevent overflow */
.main-content { min-width: 0; }

/* Prevent wide tables from causing page overflow */
.ck-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

/* Guard: avoid extra spacing if a stray trailing <br> ends an H1 */
.ck-content h1 > br:last-child { display: none; }
header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
html[dir="rtl"] header .container {
    flex-direction: row-reverse;
}
.logo {
    font-size: 1.8rem;
    font-weight: var(--font-weight-bold);
    text-decoration: none;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 1rem;
    letter-spacing: var(--letter-spacing-tight);
}
.logo img {
    height: 6rem;
}
html[dir="rtl"] .logo {
    flex-direction: row-reverse;
}

/* Hide CKEditor document title/subtitle in public articles (critical path) */
article .document-title,
article .document-subtitle { display: none !important; }
article {
    width: 100%;
    font-size: 1.125rem; /* 18px LTR */
    line-height: 1.6;
}
html[lang="ar"] article,
article[dir="rtl"] {
    font-size: 1.25rem; /* 20px RTL */
    line-height: 1.8;
    text-align: right;
}
article h1.brand,
article h1:first-of-type {
    text-align: center;
    max-width: 40ch;
    margin: 0.8em 0 0.8em;
    margin-inline: auto;
    text-wrap: balance;
}
article h1,
article h2,
article h3 {
    font-weight: 700;
    margin: 0.8em 0 0.6em;
}
article h1 { text-wrap: balance; hyphens: auto; }
article h1.brand br { display: none; }
article h1.brand span {
    display: block;
    white-space: normal;
    text-wrap: balance;
    overflow-wrap: anywhere;
}
article h1.brand span:not(:last-child)::after { content: ""; }
article h1 { text-wrap: balance; hyphens: auto; }
/* Long-form container */
.article,
.article-content {
    max-width: 100%;
    margin-inline: auto;
}
@media (min-width: 1200px) {}
@media (max-width: 767.98px) {
    article { font-size: 1.0625rem; }
    html[lang="ar"] article,
    article[dir="rtl"] { font-size: 1.1875rem; }
}
/* Force RTL articles to use full available width */
html[dir="rtl"] article,
body[dir="rtl"] article,
.article[dir="rtl"] {
    max-width: none !important;
    width: 100% !important;
}
nav ul {
    display: flex;
    list-style: none;
    gap: 1.5rem;
    align-items: center;
    height: 100%;
    margin: 0;
    padding: 0;
}
nav,
.language-bar,
.top-bar,
.site-header,
.site-footer {
    font-size: 0.9375rem;
    line-height: 1.5;
}
html[lang="ar"] nav,
html[lang="ar"] .language-bar,
[dir="rtl"] nav,
[dir="rtl"] .language-bar {
    font-size: 1rem;
}
html[dir="rtl"] nav ul {
    justify-content: flex-end;
}
nav a {
    color: #fff;
    text-decoration: none;
    transition: color 0.2s;
    font-size: 0.95rem;
    font-weight: var(--font-weight-medium);
    display: inline-block;
    padding: 0.5rem 1rem;
    letter-spacing: var(--letter-spacing-normal);
    line-height: 1.5;
}
html[lang="ar"] nav a,
[dir="rtl"] nav a {
    font-size: 1rem;
}
.language-bar {
    background-color: #f5f5f5;
    padding: 8px 0;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.5;
}
.language-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px 15px;
}
.lang-link {
    color: var(--primary);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 6px;
    font-weight: var(--font-weight-medium);
    transition: all 0.2s ease;
    font-size: 1rem;
    letter-spacing: var(--letter-spacing-tight);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.lang-link.active {
    background-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 110, 144, 0.3);
    font-weight: var(--font-weight-semibold);
    transform: translateY(-1px);
}
.lang-separator {
    color: #999;
    display: inline-block;
    margin: 0 8px;
    font-size: 1rem;
}
html[dir="rtl"] #main-site-language-bar {
    flex-direction: row-reverse;
}
/* Ensure RTL stacks on small screens as well */
@media (max-width: 640px) {
    #main-site-language-bar { flex-direction: column; align-items: stretch; gap: 0.5rem; }
    html[dir="rtl"] #main-site-language-bar { flex-direction: column; }
}
.top-visitor-counter {
    display: flex;
    justify-content: center;
    padding: 0;
    margin: 10px 0;
    background-color: transparent;
    width: 100%;
    border-bottom: none;
    font-size: 0.8rem;
    direction: ltr;
    line-height: 1;
    height: 20px; /* Fixed height to prevent layout shifts */
    min-height: 20px;
}
.visitor-counter {
    padding: 0;
    margin: 0;
    justify-content: center;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    padding: 0.05rem 0;
    font-size: 0.8rem;
    color: #555;
    margin: 0;
}
/* Align visitor block logically for both LTR and RTL */
.visitor-inline { margin: 0; display: flex; align-items: center; }
.visitor-count {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    font-weight: 400;
    color: #555;
    white-space: nowrap;
}

/* Stable visitor count number - prevent layout shifts with tighter spacing */
#visitorCountNumber {
    display: inline-block;
    min-width: 2.5ch; /* up to 3 digits without excessive gap */
    text-align: right;
    font-variant-numeric: tabular-nums;
}
/* Ensure numbers render LTR inside RTL contexts */
.language-bar #visitorCountNumber { direction: ltr !important; unicode-bidi: isolate; }

.visitor-countries {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}
.country-badge {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    color: #555;
    font-weight: 400;
    white-space: nowrap;
    min-width: 3.5em; /* Stable width to prevent shifts */
    text-align: center;
}
/* Country badges should render tokens like "AU 1" left-to-right */
.language-bar .country-badge { direction: ltr !important; unicode-bidi: isolate; }

/* Subtle separator between countries with consistent spacing */
.visitor-countries .country-badge + .country-badge::before {
    content: '';
    display: inline-block !important;
    width: 0.35rem;
    height: 0.35rem;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.6;
    margin-right: 0.35rem;
}
.language-bar .visitor-count::after {
    content: '';
    display: inline-block;
    width: 0.35rem;
    height: 0.35rem;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.6;
    margin: 0 0.55rem;
    vertical-align: middle;
}

/* Simplified: keep list LTR for consistent rendering */
.language-bar .visitor-countries { direction: ltr !important; unicode-bidi: isolate; }
main {
    flex: 1;
    padding: 0 0 2rem 0;
    margin-top: 0;
}
h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-semibold);
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    letter-spacing: var(--letter-spacing-tight);
}
h1 {
    font-size: 2.25rem;
    font-weight: var(--font-weight-bold);
    line-height: 1.25;
}
h2 {
    font-size: 1.875rem;
    line-height: 1.3;
}
h3 {
    font-size: 1.5rem;
    line-height: 1.35;
}
h4 {
    font-size: 1.25rem;
    line-height: 1.4;
}
h5 {
    font-size: 1.125rem;
    line-height: 1.4;
}
h6 {
    font-size: 1rem;
    line-height: 1.4;
}
.heading-balance h1,
.heading-balance h2 { text-wrap: balance; }
:lang(ar) h1, :lang(ar) h2, :lang(ar) h3, :lang(ar) h4, :lang(ar) h5, :lang(ar) h6,
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] h4, [dir="rtl"] h5, [dir="rtl"] h6,
:lang(ar) nav a,
[dir="rtl"] nav a,
:lang(ar) .lang-link,
[dir="rtl"] .lang-link {
    letter-spacing: normal;
}
@media (max-width: 767.98px) {
    h1 { font-size: 1.875rem; }
    h2 { font-size: 1.625rem; }
    h3 { font-size: 1.375rem; }
}
.page-title {
    margin: 0.75rem 0 1.5rem;
    color: var(--primary-dark);
    font-weight: var(--font-weight-bold);
    letter-spacing: var(--letter-spacing-tight);
    font-size: 1.5rem;
}
.content-area {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    padding: 2rem;
    max-width: 900px;
    margin: 0 auto 2rem;
}
p {
    margin-bottom: 1.25rem;
    font-size: 1em;
    line-height: inherit;
}
a {
    color: var(--primary);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
    transition: color 0.2s ease, text-decoration 0.2s ease;
}
:lang(ar) a,
[dir="rtl"] a {
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.2em;
    text-decoration-skip-ink: auto;
}
html.backoffice,
body.backoffice {
    font-family: var(--font-sans-latin);
    font-size: 0.9375rem; /* 15px */
    line-height: 1.5;
}
.backoffice input,
.backoffice select,
.backoffice textarea,
.backoffice table {
    font-size: 0.9375rem;
    line-height: 1.4;
}
.sidebar {
    width: 280px;
    background: var(--primary);
    color: #fff;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 0;
}
html[dir="rtl"] .sidebar {
    width: 280px;
    min-width: 260px;
    max-width: 300px;
}
.sidebar h2 {
    margin: 0;
    font-size: 1.4rem;
}
.sidebar .page-link {
    display: block;
    padding-block: 0.55rem;
    padding-inline: 1rem;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    color: #FFFFFF;
    background-color: transparent;
    border: 1px solid transparent;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
    margin-bottom: 0.35rem;
    -webkit-tap-highlight-color: transparent;
}

html[lang="ar"] .sidebar,
html[lang="fa"] .sidebar,
html[lang="ps"] .sidebar,
html[lang="ur"] .sidebar {
    font-family: var(--font-sans-arabic);
}

html[lang="bn"] .sidebar,
html[lang="bn-BD"] .sidebar,
html[lang="bn-IN"] .sidebar {
    font-family: 'Bangla Sangam MN', 'Kohinoor Bangla', 'Mukta Mahee', 'Noto Sans Bengali', 'Arial Unicode MS', 'Segoe UI', sans-serif;
}

.sidebar .page-link.subpage {
    margin: 0.1rem 0;
    background-color: transparent;
    color: #FFFFFF;
    border-color: transparent;
    padding-inline-start: 2.25rem;
}

html[dir="rtl"] .sidebar .page-link.subpage {
    padding-inline-start: 1rem;
    padding-inline-end: 2.25rem;
}

.sidebar .page-link.subpage.active-sidebar-item {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.6);
    color: #FFFFFF;
}
.sidebar .page-link:hover,
.sidebar .page-link:focus {
    background-color: rgba(255, 255, 255, 0.1);
    color: #FFFFFF;
    border-color: rgba(255, 255, 255, 0.35);
    outline: none;
}

.sidebar .page-link:focus-visible {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.35);
    outline: none;
}

.sidebar .page-link.active-sidebar-item {
    background-color: rgba(255, 255, 255, 0.12);
    color: #FFFFFF;
    font-weight: bold;
    border-color: rgba(255, 255, 255, 0.6);
}
.row {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: stretch !important;
    margin-top: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    gap: 20px;
}
.sidebar {
    flex: 0 0 280px;
    min-width: 260px;
    max-width: 300px;
    order: 1;
    direction: ltr !important;
}
#contentArea {
    flex: 1 1 0;
    min-width: 0;
    order: 2;
    direction: ltr !important;
    margin-bottom: 0 !important;
    display: flex;
    flex-direction: column;
}
#pageList {
    text-align: left !important;
    direction: ltr !important;
}
.rtl-text {
    direction: rtl;
    text-align: right;
    max-width: 100%;
    overflow-x: hidden;
}
.ltr-text {
    direction: ltr;
    text-align: left;
    max-width: 100%;
    overflow-x: hidden;
}
.visitor-countries ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
}
header,
.sidebar,
.lang-link.active {
  background: var(--primary) !important;
}
@media (max-width: 992px) {
    .row {
        flex-direction: column !important;
    }
    .sidebar {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        margin: 0 0 1rem 0 !important;
        float: none !important;
        order: 1 !important;
        flex: 1 1 auto !important;
        padding: 1.25rem !important;
    }
    #contentArea {
        order: 2 !important;
        float: none !important;
        margin: 0 !important;
        flex: 1 1 auto !important;
        max-width: none !important;
        min-width: 0 !important;
    }
    .logo img {
        height: 4rem;
    }
}
@media (max-width: 768px) {
    header .container,
    footer .container {
        flex-direction: column;
        gap: 1rem;
    }
    nav ul {
        flex-wrap: wrap;
        justify-content: center;
    }
    .sidebar {
        width: 100%;
        min-width: 0;
        max-width: none;
        flex: 1 1 auto;
    }
    .top-visitor-counter {
        padding: 0;
        margin: 4px 0;
        font-size: 0.75rem;
        height: auto;
    }
    .visitor-counter {
        gap: 0.3rem;
        padding: 0;
    }
    .visitor-countries {
        gap: 0.25rem;
    }
}
@media (max-width: 576px) {
    header .container {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
    }
    .logo {
        font-size: 0.9rem;
        gap: 0.4rem;
    }
    .logo img {
        height: 2.5rem;
    }
    nav ul {
        flex-direction: row;
        gap: 0.5rem;
    }
    nav a {
        font-size: 0.95rem;
        padding: 0.2rem 0.4rem;
    }
    .content-area {
        padding: 1rem;
        margin: 1rem 0;
        font-size: 1rem;
    }
    .content-area h1 {
        font-size: 1.875rem;
    }
    .content-area h2 {
        font-size: 1.625rem;
    }
    .content-area h3 {
        font-size: 1.375rem;
    }
    .content-area h4 { font-size: 1.25rem; }
    .content-area h5 { font-size: 1.125rem; }
    .content-area h6 { font-size: 1rem; }
    .sidebar {
        gap: 0.75rem;
    }
}

/* Utility classes for inline style optimization */
.full-width {
    width: 100%;
    max-width: 100%;
}

.reset-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.text-center {
    text-align: center;
}

.mt-30 {
    margin-top: 30px;
}

.flex-1 {
    flex: 1;
}

.no-decoration {
    color: inherit;
    text-decoration: none;
}

/*
  WHY: The older skip-link used left:-9999px, which expands scroll width in RTL
  documents and produces a right-edge overscroll. Use the visually hidden
  pattern so the element stays within the viewport until focused.
*/
.skip-link {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-link:focus {
    clip: auto;
    clip-path: none;
    inline-size: auto;
    block-size: auto;
    inset-block-start: 1rem;
    inset-inline-start: 1rem;
    padding: .5rem 1rem;
    background: #fff;
    color: #000;
    z-index: 10000;
    border-radius: 6px;
}
