/* ========================================================== */
/*                   ROOT & THEME VARIABLES                   */
/* ========================================================== */
:root {
    --primary-color-light: #00A78B;
    --primary-color-light-t1: rgba(0, 167, 139, 0.2);
    --primary-color-light-t2: rgba(0, 167, 139, 0.1);
    --background-color-light: #f8f9fa;
    --text-color-light: #212529;
    --header-bg-light: #ffffff;

    --primary-color-dark: #009dff;
    --primary-color-dark-t1: rgba(0, 157, 255, 0.25);
    --primary-color-dark-t2: rgba(0, 157, 255, 0.15);
    --background-color-dark: #12181f;
    --text-color-dark: #e8e6e3;
    --header-bg-dark: #1c242c;
}

/* ========================================================== */
/*                GLOBAL STYLES & BOX SIZING                  */
/* ========================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.4s, color 0.4s;
}
.light-theme {
    --primary-color: var(--primary-color-light);
    --primary-color-t1: var(--primary-color-light-t1);
    --primary-color-t2: var(--primary-color-light-t2);
    background-color: var(--background-color-light);
    color: var(--text-color-light);
    --download-color: #00A78B;
    --upload-color: #8E44AD;
}
.dark-theme {
    --primary-color: var(--primary-color-dark);
    --primary-color-t1: var(--primary-color-dark-t1);
    --primary-color-t2: var(--primary-color-dark-t2);
    background-color: var(--background-color-dark);
    color: var(--text-color-dark);
    --download-color: #009dff;
    --upload-color: #9B59B6;
}
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
main {
    min-height: calc(100vh - 140px);
}

/* ========================================================== */
/*                   HEADER & NAVIGATION (v3)                 */
/* ========================================================== */
header {
    background-color: var(--header-bg-light);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: background-color 0.4s;
}
.dark-theme header {
    background-color: var(--header-bg-dark);
}
header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 70px;
}

.logo img {
    height: 35px;
    display: block;
}
.logo .logo-dark { display: none; }
.logo .logo-light { display: block; }
.dark-theme .logo .logo-dark { display: block; }
.dark-theme .logo .logo-light { display: none; }

.desktop-nav {
    flex-grow: 1;
}
.nav-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 30px;
    margin-left: 40px; /* Space between logo and nav */
}
.nav-links a {
    text-decoration: none;
    color: inherit;
    font-weight: 500;
    transition: color 0.2s;
    padding: 5px 0;
}
.nav-links a:hover {
    color: var(--primary-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}
.header-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

.language-switcher select {
    background-color: transparent;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 5px 8px;
    color: inherit;
    font-family: inherit;
}
.dark-theme .language-switcher select {
    border-color: #555;
    background: var(--header-bg-dark);
}
.dark-theme .language-switcher select option {
    background: var(--header-bg-dark);
    color: var(--text-color-dark);
}

.theme-switcher button {
    background: none; border: none; cursor: pointer; padding: 0; display: flex;
}
.theme-switcher img {
    width: 22px; height: 22px;
}
.moon-icon { display: none; }
.dark-theme .sun-icon { display: none; }
.dark-theme .moon-icon { display: block; }

.user-icon-btn {
    background: none; border: none; cursor: pointer; padding: 5px; display: flex;
}
.user-icon-btn svg {
    width: 26px; height: 26px; stroke: currentColor; stroke-width: 2; fill: none; opacity: 0.7; transition: opacity 0.2s;
}
.user-icon-btn:hover svg { opacity: 1; }
.dark-theme .user-icon-btn svg { stroke: var(--text-color-dark); }

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    top: 120%;
    right: 0;
    background: var(--header-bg-light);
    border-radius: 8px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.1);
    list-style: none;
    margin: 0;
    padding: 10px 0;
    min-width: 180px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    z-index: 100;
}
.dark-theme .dropdown-menu { background: var(--header-bg-dark); }
.dropdown:hover .dropdown-menu,
.dropdown.active .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu li a { display: block; padding: 10px 20px; font-size: 0.95em; white-space: nowrap; text-decoration: none; color: inherit; }
.dropdown-menu li a:hover { background-color: var(--primary-color-t2); }

/* --- MOBILE NAVIGATION --- */
.burger {
    display: none;
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 0;
    z-index: 1001;
}
.burger div {
    width: 25px; height: 3px; background-color: var(--text-color-light); margin: 5px 0; transition: all 0.3s ease;
}
.dark-theme .burger div { background-color: var(--text-color-dark); }
.toggle .line1 { transform: rotate(-45deg) translate(-5px, 6px); }
.toggle .line2 { opacity: 0; }
.toggle .line3 { transform: rotate(45deg) translate(-5px, -6px); }

.mobile-nav-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: var(--header-bg-light);
    box-shadow: -5px 0 25px rgba(0,0,0,0.1);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    z-index: 999;
    padding-top: 80px;
}
.dark-theme .mobile-nav-drawer { background: var(--header-bg-dark); }
.mobile-nav-drawer.open { transform: translateX(0); }
.mobile-nav-drawer .nav-links { flex-direction: column; align-items: flex-start; gap: 0; margin-left: 0; }
.mobile-nav-drawer .nav-links a { display: block; padding: 15px 30px; width: 100%; font-size: 1.1em; }
.mobile-nav-drawer .dropdown-menu { all: unset; }
.mobile-nav-drawer .dropdown > a { display: none; }
.mobile-nav-drawer .dropdown li a { padding-left: 45px; font-size: 1em; opacity: 0.8; }

/* ========================================================== */
/*                   HOMEPAGE "GO" BUTTON                     */
/* ========================================================== */
.test-container {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
}
.start-button-outer-ring {
    width: 280px; height: 280px; border-radius: 50%; padding: 20px;
    box-shadow: 0 0 0 10px var(--primary-color-t1), 0 0 0 20px var(--primary-color-t2);
    animation: cycle-glow 3s infinite ease-in-out;
}
.start-button-inner-ring {
    width: 100%; height: 100%; border-radius: 50%; background-color: var(--primary-color-t2);
    display: flex; justify-content: center; align-items: center;
}
.start-button {
    width: 180px; height: 180px; border-radius: 50%; background: var(--primary-color);
    display: flex; justify-content: center; align-items: center;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.3s ease;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}
.start-button:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
}
.start-button span {
    font-size: 50px; font-weight: bold; color: white; text-transform: uppercase;
}
@keyframes cycle-glow {
    0% { box-shadow: 0 0 0 10px var(--primary-color-t1), 0 0 0 20px var(--primary-color-t2); }
    50% { box-shadow: 0 0 0 20px var(--primary-color-t1), 0 0 0 40px var(--primary-color-t2); }
    100% { box-shadow: 0 0 0 10px var(--primary-color-t1), 0 0 0 20px var(--primary-color-t2); }
}
.branding-box {
    text-align: center; margin-bottom: 20px; color: var(--text-color-light); opacity: 0.8;
}
.dark-theme .branding-box { color: var(--text-color-dark); }
.branding-box h2 { margin: 0; font-size: 1.2em; font-weight: 400; }
.branding-box .company-name { font-weight: 600; font-size: 1.5em; }

/* ========================================================== */
/*                 IN-PROGRESS TEST VIEW UI                   */
/* ========================================================== */
.test-in-progress {
    width: 100%; max-width: 900px; margin: auto; padding: 20px;
    opacity: 0; transition: opacity 0.5s ease;
}
.test-area-split { display: flex; gap: 30px; width: 100%; }
.test-gauges-area {
    width: 70%; display: flex; flex-direction: column; gap: 20px; justify-content: center;
}
.overall-progress-container {
    width: 100%; height: 30px; background-color: var(--primary-color-t2);
    border-radius: 20px; position: relative; overflow: hidden;
}
.overall-progress-container .progress-bar {
    width: 0%; height: 100%; background: var(--primary-color); transition: width 0.2s linear;
}
.progress-text {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    display: flex; justify-content: center; align-items: center;
    color: white; font-weight: bold; text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.gauge-item .item-label { margin-bottom: 8px; font-weight: 500; opacity: 0.8; }
.gauge-container { display: flex; align-items: center; gap: 15px; }
.gauge-label { font-family: monospace; font-size: 0.9em; }
.gauge-label span { transition: opacity 0.3s ease-in-out; }
.fade-out { opacity: 0; }
.gauge-bar-wrapper {
    flex-grow: 1; height: 50px; background-color: var(--primary-color-t2); border-radius: 8px; padding: 5px;
}
.gauge-bar { width: 0%; height: 100%; border-radius: 5px; transition: width 0.1s linear; }
.gauge-bar.download { background-color: var(--download-color); }
.gauge-bar.upload { background-color: var(--upload-color); }

.test-results-live { width: 30%; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.result-box {
    background-color: var(--header-bg-light); border-radius: 10px; padding: 15px; text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); transition: background-color 0.4s;
}
.dark-theme .result-box { background-color: var(--header-bg-dark); }
.result-label { font-size: 0.9em; font-weight: 500; opacity: 0.7; }
.result-value { font-size: 1.8em; font-weight: 700; margin-top: 5px; color: var(--primary-color); }
.result-value span { font-size: 1.2em; }
.quality-ratings {
    grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 15px;
}
.quality-item {
    display: flex; align-items: center; gap: 10px; background-color: var(--header-bg-light);
    border-radius: 10px; padding: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); transition: background-color 0.4s;
}
.dark-theme .quality-item { background-color: var(--header-bg-dark); }
.quality-icon { color: var(--primary-color); display: flex; align-items: center; }
.quality-icon svg { width: 28px; height: 28px; }
.quality-label { font-size: 0.9em; font-weight: 500; }
.quality-value { font-size: 0.9em; opacity: 0.7; }
.test-info-area {
    display: flex; justify-content: space-between; margin-top: 25px; padding: 10px;
    background-color: var(--primary-color-t2); border-radius: 8px; font-size: 0.9em; opacity: 0.8;
}

/* ========================================================== */
/*                       RESULTS VIEW UI                      */
/* ========================================================== */
.test-results-container {
    width: 100%; max-width: 900px; margin: auto; padding: 20px;
    opacity: 0; transform: translateY(20px); transition: opacity 0.5s ease, transform 0.5s ease;
}
.results-summary { display: grid; grid-template-columns: 1fr 1fr 1.5fr 1.5fr; gap: 20px; margin-bottom: 40px; }
.summary-box {
    background-color: var(--header-bg-light); border-radius: 12px; padding: 20px; text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.07); transition: background-color 0.4s;
}
.dark-theme .summary-box { background-color: var(--header-bg-dark); }
.summary-label { font-size: 1em; opacity: 0.7; margin-bottom: 5px; }
.summary-value { font-size: 2.5em; font-weight: 700; line-height: 1; }
.summary-unit { font-size: 1em; opacity: 0.8; }
.summary-box.main-result .summary-value { color: var(--primary-color); font-size: 3.5em; }
.results-quality-ratings h3 { text-align: center; margin-bottom: 20px; }
.quality-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.results-quality-ratings .quality-item {
    display: flex; flex-direction: column; align-items: center; padding: 20px;
    background-color: var(--header-bg-light); border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.07); transition: background-color 0.4s;
}
.dark-theme .results-quality-ratings .quality-item { background-color: var(--header-bg-dark); }
.results-quality-ratings .quality-icon { width: 40px; height: 40px; color: var(--primary-color); margin-bottom: 10px; }
.quality-dots { display: flex; gap: 4px; margin: 10px 0; }
.quality-dots .dot { width: 12px; height: 12px; border-radius: 50%; background-color: #e0e0e0; }
.dark-theme .quality-dots .dot { background-color: #444; }
.quality-dots .dot.filled { background-color: var(--primary-color); }
.quality-assessment { font-weight: bold; }
.results-graphs { margin-top: 40px; }
.graph-container {
    background-color: var(--header-bg-light); border-radius: 12px; padding: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.07); transition: background-color 0.4s;
}
.dark-theme .graph-container { background-color: var(--header-bg-dark); }
.graph-container h3 { text-align: center; margin-top: 0; margin-bottom: 20px; }
.results-footer {
    display: flex; justify-content: space-between; align-items: center; margin-top: 40px;
    padding-top: 20px; border-top: 1px solid #e0e0e0; flex-wrap: wrap;
}
.dark-theme .results-footer { border-top-color: #444; }
.user-server-info { font-size: 0.9em; opacity: 0.8; }
.share-section { display: flex; align-items: center; gap: 10px; }
.share-buttons { display: flex; gap: 10px; color: var(--primary-color); }
.share-buttons button {
    background-color: transparent; border: 1px solid var(--primary-color-t1); border-radius: 8px; cursor: pointer;
    width: 40px; height: 40px; display: flex; justify-content: center; align-items: center; transition: background-color 0.2s; padding: 0;
}
.share-buttons button:hover { background-color: var(--primary-color-t2); }
.share-buttons button svg { width: 20px; height: 20px; fill: var(--primary-color); stroke: var(--primary-color); }
#copy-link-btn svg { fill: none; }
.copy-notification {
    position: absolute; bottom: 100%; right: 0; background-color: #333; color: white;
    padding: 5px 10px; border-radius: 5px; font-size: 0.9em; opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.test-again-section { width: 100%; text-align: center; margin-top: 30px; }
#testAgainBtn {
    background-color: var(--primary-color); color: white; border: none; border-radius: 25px;
    padding: 12px 30px; font-size: 1.1em; font-weight: bold; cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
#testAgainBtn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.15); }

/* ========================================================== */
/*                 CONTENT, STATS, & FOOTER                   */
/* ========================================================== */
.content-section { padding: 60px 0; background-color: var(--header-bg-light); }
.dark-theme .content-section { background-color: var(--header-bg-dark); }
.content-section .container { max-width: 800px; }
.content-section h2 { text-align: center; margin-top: 0; font-size: 2.2rem; }
.content-section p { line-height: 1.7; text-align: justify; }

.stats-section { padding: 50px 0; }
.stats-section .container { display: flex; justify-content: space-around; align-items: center; gap: 20px; flex-wrap: wrap; }
.stat-box { text-align: center; padding: 20px; }
.stat-value { font-size: 3em; font-weight: 700; color: var(--primary-color); line-height: 1.1; }
.stat-label { font-size: 1.1em; opacity: 0.8; margin-top: 5px; }

footer { padding: 35px 0; text-align: center; opacity: 0.7; }
.footer-links a { margin: 0 10px; text-decoration: none; color: inherit; }
.copyright { margin-top: 10px; font-size: 0.9em; }

/* ========================================================== */
/*            CONSOLIDATED RESPONSIVE MEDIA QUERIES           */
/* ========================================================== */
@media (max-width: 900px) {
    /* Header */
    .desktop-nav { display: none; }
    .burger { display: block; }
    .header-controls .language-switcher { display: none; }
}

@media (max-width: 768px) {
    /* In-Progress Test UI */
    .test-area-split { flex-direction: column; }
    .test-gauges-area, .test-results-live { width: 100%; }
    .test-info-area { flex-direction: column; text-align: center; gap: 5px; }
    
    /* Results UI */
    .results-summary, .quality-grid { grid-template-columns: 1fr 1fr; }
    .results-footer { flex-direction: column; gap: 20px; }
}

@media (max-width: 480px) {
    /* In-Progress Test UI */
    .quality-ratings { grid-template-columns: 1fr; }

    /* Results UI */
    .test-results-container { padding: 15px 10px; }
    .results-summary, .quality-grid { grid-template-columns: 1fr; gap: 15px; }
    .summary-box { padding: 15px; }
    .summary-value { font-size: 2em; }
    .summary-box.main-result .summary-value { font-size: 2.8em; }
}

/* --- FINAL MOBILE NAVIGATION STYLES --- */
body.no-scroll {
    overflow: hidden; /* Prevent background from scrolling */
}

.mobile-nav-drawer .mobile-nav-content {
    padding: 20px 0;
}

/* Style the language switcher inside the mobile menu */
.mobile-nav-drawer .language-switcher {
    padding: 15px 30px;
}
.mobile-nav-drawer .language-switcher select {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
}

.mobile-nav-drawer hr {
    border: none;
    border-top: 1px solid var(--primary-color-t2);
    margin: 15px 30px;
}

/* Reset styles for cloned elements to fit the mobile drawer */
.mobile-nav-drawer .nav-links {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    margin: 0;
}
.mobile-nav-drawer .nav-links a {
    display: block;
    padding: 15px 30px;
    width: 100%;
    font-size: 1.1em;
}
.mobile-nav-drawer .dropdown-menu,
.mobile-nav-drawer .dropdown > a {
    /* Hide desktop dropdown elements, as we show all links directly */
    display: none;
}

/* ========================================================== */
/*                   RTL (Right-to-Left) STYLES               */
/* ========================================================== */

/* --- GLOBAL FLIPS & TYPOGRAPHY --- */
[dir="rtl"] {
    text-align: right;
}
[dir="rtl"] body {
    /* You can load an RTL-specific font here if needed, e.g., for Arabic */
    /* font-family: 'Tajawal', sans-serif; */
}

/* --- HEADER & NAVIGATION --- */
[dir="rtl"] .logo {
    margin-right: 0;
    margin-left: 20px;
}
[dir="rtl"] .desktop-nav {
    /* No change needed for flex-grow, but we flip the inner alignment */
}
[dir="rtl"] .nav-links {
    justify-content: flex-end; /* Align links to the right */
    margin-left: 0;
    margin-right: 40px; /* Space between logo and nav */
}
[dir="rtl"] .dropdown-menu {
    right: auto; /* Unset the right positioning */
    left: 0;     /* Position from the left */
    text-align: right;
}
[dir="rtl"] .user-menu .dropdown-menu {
    left: 0;
    right: auto;
}
[dir="rtl"] .dropdown-toggle {
    /* Flip the dropdown arrow */
    padding-left: 10px;
    padding-right: 0;
}

/* --- MOBILE NAVIGATION --- */
[dir="rtl"] .mobile-nav-drawer {
    right: auto;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 5px 0 25px rgba(0,0,0,0.1);
}
[dir="rtl"] .mobile-nav-drawer.open {
    transform: translateX(0);
}
[dir="rtl"] .mobile-nav-drawer .nav-links {
    align-items: flex-end;
}
[dir="rtl"] .mobile-nav-drawer .dropdown li a {
    padding-left: 15px;
    padding-right: 45px;
}

/* --- FORMS & UI ELEMENTS --- */
[dir="rtl"] .form-group label,
[dir="rtl"] .radio-group {
    text-align: right;
}
[dir="rtl"] .custom-select-wrapper::after {
    right: auto;
    left: 15px;
}
[dir="rtl"] .filter-container select {
    padding: 10px 15px 10px 35px; /* Adjust padding for arrow */
}

/* --- SERVER DETAILS & DASHBOARDS --- */
[dir="rtl"] .h1-with-edit {
    flex-direction: row-reverse;
}
[dir="rtl"] .header-meta,
[dir="rtl"] .server-url-container {
    flex-direction: row-reverse;
}
[dir="rtl"] #copyUrlBtn {
    margin-left: 0;
    margin-right: 8px;
}
[dir="rtl"] table th,
[dir="rtl"] table td {
    text-align: right;
}
[dir="rtl"] .pagination-controls button:first-child {
    /* Flip Previous/Next buttons */
    content: 'Next &rarr;';
}
[dir="rtl"] .pagination-controls button:last-child {
    content: '&larr; Previous';
}

/* --- BLOG & FAQ --- */
[dir="rtl"] .back-link,
[dir="rtl"] .read-more {
    /* Flip arrows */
    content: '&larr; Read Answer'; 
}
[dir="rtl"] .post-content ul,
[dir="rtl"] .post-content ol {
    padding-left: 0;
    padding-right: 25px; /* Indent on the right */
}