:root {
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --line-color: #94a3b8;
    --alive: #10b981;
    --dead: #94a3b8;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    
    /* THEME COLORS */
    --female-bg: #fce7f3;
    --female-border: #f472b6;
    --male-bg: #dbeafe;
    --male-border: #60a5fa;
    --dead-bg: #e2e8f0;
    --dead-border: #94a3b8;

    /* LINK COLORS */
    --link-male: #1d4ed8;   
    --link-female: #db2777; 
    --link-dead: #64748b;   
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    /* font-family: 'Cairo', sans-serif; */
    font-family: "Noto Sans Arabic", sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 24px 24px;
    color: var(--text-main);
    overflow: hidden;
    height: 100vh; width: 100vw;
    direction: rtl; /* RTL SUPPORT */
    text-align: right;
}

/* --- Top Bar --- */
.top-bar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 56px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; z-index: 100;
}
.logo { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }

/* Search */
.search-container { position: relative; width: 320px; }
.search-container input {
    width: 100%; padding: 8px 36px 8px 12px;
    border: 1px solid var(--border); border-radius: 6px;
    font-family: 'Cairo', sans-serif;
    font-size: 0.9rem; outline: none; transition: 0.2s;
    text-align: right;
}
.search-container input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search-results {
    position: absolute; top: 45px; left: 0; right: 0;
    background: white; border: 1px solid var(--border);
    border-radius: 6px; box-shadow: var(--shadow);
    max-height: 300px; overflow-y: auto; z-index: 200;
}

.search-item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--bg-color); }

.search-name { font-weight: 600; font-size: 0.9rem; display: block; }
.search-name.is-male { color: var(--link-male); }
.search-name.is-female { color: var(--link-female); }
.search-name.is-dead { color: var(--link-dead); }
.search-desc { font-size: 0.75rem; color: green; display: block; margin-top: 2px; }

.controls button, #btnCenter { 
    padding: 6px 12px; border: 1px solid var(--border); background: white; 
    border-radius: 6px; cursor: pointer; font-family: 'Cairo', sans-serif; 
}

/** HOVER
.controls button:hover { background: var(--bg-color); }
*/

/* --- Workspace --- */
.workspace { width: 100%; height: 100%; overflow: hidden; position: relative; cursor: grab; direction: ltr; touch-action: none; /* Prevents native zoom */ }
.workspace:active { cursor: grabbing; }

.tree-canvas { width: 100%; height: 100%; transform-origin: 0 0; }
.tree-container { position: absolute; padding: 100px; display: flex; justify-content: center; min-width: 100%; }

/* --- Tree Connectors --- */
.tree { display: flex; justify-content: center; direction: ltr; }
.tree ul {
    padding-top: 40px;
    position: relative;
    display: flex; justify-content: center;
}
.tree li {
    text-align: center; list-style-type: none;
    position: relative;
    padding: 20px 20px 0 20px;
    flex-shrink: 0;
}

/* 1. Horizontal Connectors */
.tree li::before, .tree li::after {
    content: ''; position: absolute; top: 0; right: 50%;
    border-top: 2px solid var(--line-color);
    width: 50%; height: 2px; z-index: -1;
}
.tree li::after { right: auto; left: 50%; }
.tree li:only-child::after, .tree li:only-child::before { display: none; }
.tree li:first-child::before { border: 0 none; }
.tree li:last-child::after { border: 0 none; }
.tree li:only-child { padding-top: 20px; } 

/* 2. Upward Vertical Stub (Fixes the gap for only children) */
.node-wrapper { 
    display: inline-flex; 
    flex-direction: column; 
    align-items: center; 
    position: relative; 
    margin: 0 30px !important; /* هذا هو الحل السحري الذي سيفرض مسافة 60px بين أي أخوين دائماً */
}

.node-wrapper::before {
    content: '';
    position: absolute;
    top: -20px; 
    left: 50%;
    border-left: 2px solid var(--line-color);
    width: 0;
    height: 20px;
    margin-left: -1px;
    z-index: -1;
    display: block;
}


/* Hide upward stub for the absolute Root Node */
.tree > ul > li > .node-wrapper::before {
    display: none !important;
}

/* 3. Downward Vertical Stub (Drops perfectly to the children row) */
.node-wrapper.is-parent::after {
    content: '';
    position: absolute;
    top: calc(100% - 78px);
    bottom: -40px; 
    left: 50%;
    border-left: 2px solid var(--line-color);
    margin-left: -1px;
    z-index: -2;
}

/* Downward line adjustment for zoomed out state */
.zoom-small .node-wrapper.is-parent::after {
    top: calc(100% - 57px);
}

/* --- Cards (RTL) --- */
.card-group { display: flex; align-items: center; gap: 40px; position: relative; padding: 0; direction: rtl; }

.card-group.has-spouse::before {
    content: ''; position: absolute; top: 50%; left: 100px; right: 100px; transform: translateY(-50%);
    height: 1px; border-bottom: 2px dashed var(--line-color); z-index: -1; opacity: 0.6;
    width: auto;
}
.card {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 12px; 
    width: 200px; 
    height: 85px; /* Fixed height */
    text-align: right;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); cursor: pointer; position: relative;
    display: flex; align-items: center; gap: 12px; transition: 0.2s;
}

/* --- Added Gender Card Borders and Highlights --- */
.card.card-male { border-top: 3px solid var(--primary); }
.card.card-female { border-top: 3px solid var(--link-female); }

/** HOVER
.card.card-male:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.card.card-female:hover { border-color: var(--link-female); transform: translateY(-2px); box-shadow: var(--shadow); }
*/

.card.card-male.highlighted { 
    box-shadow: 0 0 0 2px var(--primary-soft), 0 0 0 4px var(--primary); 
    border-color: var(--primary); 
}
.card.card-female.highlighted { 
    box-shadow: 0 0 0 2px var(--female-bg), 0 0 0 4px var(--link-female); 
    border-color: var(--link-female); 
}
/* ------------------------------------------------ */

.avatar {
    width: 48px; height: 48px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; background: #eee; flex-shrink: 0; position: relative;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dead); position: absolute; top: 18px; right: 8px; border: 1px solid white; }
.status-dot.alive { background: var(--alive); }
.card-info { overflow: hidden; }

.name { 
    font-weight: 600; 
    font-family: 'Cairo', sans-serif; 
    white-space: nowrap;     /* Forces the text to stay on exactly one line */
    overflow: visible;       /* Ensures no text gets cut off or hidden */
    line-height: 1.2; 
}

.toggle-btn {
    width: 24px; height: 24px; background: white; border: 1px solid var(--border); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; cursor: pointer; margin-top: 12px;
    font-weight: bold; color: var(--text-muted); z-index: 20; box-shadow: var(--shadow); transition: 0.2s;
}
/** HOVER
.toggle-btn:hover { border-color: var(--primary); color: var(--primary); transform: scale(1.1); }
*/
.toggle-parent-btn { position: absolute; top: -30px; left: 50%; transform: translateX(-50%); margin-top: 0; }

/* --- Minimap & Controls --- */
.minimap {
    display: none;
    position: fixed; bottom: 80px; left: 20px; width: 200px; height: 140px;
    background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(8px);
    border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; z-index: 900;
}
.minimap-content { position: absolute; top: 0; left: 0; transform-origin: 0 0; pointer-events: none; }
.mini-node { position: absolute; background: var(--primary); opacity: 0.6; border-radius: 2px; }
.minimap-viewport {
    position: absolute; border: 2px solid var(--primary); background: rgba(37, 99, 235, 0.1); cursor: grab; z-index: 2;
}
.zoom-controls {
    position: fixed; bottom: 20px; right: 20px; display: flex; background: white; border: 1px solid var(--border);
    border-radius: 8px; box-shadow: var(--shadow); z-index: 90;
}
.zoom-controls button { width: 40px; height: 40px; border: none; background: none; font-size: 1.2rem; cursor: pointer; }
.zoom-controls span { display: flex; align-items: center; padding: 0 10px; font-size: 0.8rem; border-left: 1px solid var(--border); border-right: 1px solid var(--border); min-width: 50px; justify-content: center; }

/* --- Sidebar --- */
.sidebar {
    position: fixed; top: 56px; right: 0; left: auto; bottom: 0; 
    width: 340px;
    background: white; border-left: 1px solid var(--border); border-right: none;
    padding: 24px; 
    transform: translateX(100%); 
    transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto; z-index: 950;
    text-align: right;
    direction: rtl;
}
.sidebar.show { transform: translateX(0); box-shadow: -4px 0 15px rgba(0,0,0,0.05); }

.close-btn { position: absolute; top: 15px; left: 15px; right: auto; border: none; background: none; font-size: 14px; font-family: "Noto Sans Arabic", sans-serif; cursor: pointer; color: var(--text-muted); z-index:9999 }

.profile-header { text-align: center; margin-bottom: 24px; position: relative; }
.avatar-large { 
    width: 80px; height: 80px; border-radius: 50%; background: #eee; 
    font-size: 3rem; display: flex; align-items: center; justify-content: center; 
    margin: 0 auto 12px; position: relative; 
}
.status-dot-large {
    width: 16px; height: 16px; background: var(--dead);
    border: 3px solid white; border-radius: 50%;
    position: absolute; bottom: 2px; right: 2px;
}
.status-dot-large.alive { background: var(--alive); }

.sidebar.theme-male .avatar-large { background-color: var(--male-bg); color: var(--text-main); }
.sidebar.theme-male .detail-meta { color: var(--male-border); }
.sidebar.theme-female .avatar-large { background-color: var(--female-bg); color: var(--text-main); }
.sidebar.theme-female .detail-meta { color: var(--female-border); }

.sidebar.theme-dead.theme-male .avatar-large { background-color: var(--male-bg); color: var(--text-main); opacity: 0.8; }
.sidebar.theme-dead.theme-female .avatar-large { background-color: var(--female-bg); color: var(--text-main); opacity: 0.8; }
.sidebar.theme-dead .detail-meta { color: var(--text-muted); }

.detail-meta { color: var(--primary); font-weight: 500; font-size: 0.95rem; margin-top: 4px; }

.detail-contact { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-muted); }
.contact-item { display: flex; align-items: center; justify-content: center; gap: 6px; direction: ltr; }

.sidebar-divider { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.detail-section { margin-bottom: 16px; }
.detail-section h3 { font-size: 0.8rem; text-transform: uppercase; font-weight: 700; color: #ffa700; margin-bottom: 8px; }

.inline-list { display: flex; flex-wrap: wrap; gap: 4px; line-height: 1.5; font-size: 0.95rem; }

.link-span { cursor: pointer; border-bottom: 1px solid transparent; transition: 0.2s; font-weight: 500; }
/** HOVER
.link-span:hover { text-decoration: underline; }
*/
.link-span.is-male { color: var(--link-male); }
.link-span.is-female { color: var(--link-female); }
.link-span.is-dead { color: var(--link-dead); }

.hidden { display: none !important; }

/* --- Generations Toggle Styles --- */
.gen-toggle {
    font-size: 0.9rem; font-weight: 700; color: var(--primary); 
    cursor: pointer; padding: 10px 0; display: flex; justify-content: space-between;
    align-items: center; border-bottom: 1px dashed var(--border); margin-bottom: 12px;
    transition: color 0.2s;
}
/** HOVER
.gen-toggle:hover { color: var(--text-main); }
*/
.gen-content { margin-bottom: 16px; padding-right: 12px; border-right: 2px solid var(--primary-soft); }
.gen-content .detail-section { margin-bottom: 12px; }
.gen-content .detail-section h3 { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }

/* --- Stacked Layout for Multiple Wives --- */
.card-group-vertical {
    display: flex; flex-direction: column; align-items: center; gap: 24px; position: relative; padding: 0; direction: rtl;
}
.main-card-row { position: relative; z-index: 2; }
.spouses-card-row { display: flex; gap: 40px; position: relative; z-index: 2; }

/* Horizontal dashed line connecting the wives */
.spouses-card-row::before {
    content: ''; position: absolute; top: 50%; left: 100px; right: 100px; transform: translateY(-50%);
    border-bottom: 2px dashed var(--line-color); opacity: 0.6; z-index: -1;
}

/* Vertical dashed line dropping from Husband down to the wives' horizontal line */
.main-card-row::after {
    content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
    width: 0; height: 55px; /* Spans the 24px gap + exactly half the height of the wives' cards */
    border-left: 2px dashed var(--line-color); opacity: 0.6; z-index: -1;
}

/* Upward solid stub connecting the top Husband to the parent tree line */
.main-card-row .card::before {
    content: ''; position: absolute; top: -22px; left: 50%;
    border-left: 2px solid var(--line-color); width: 0; height: 22px; margin-left: -1px; z-index: -1;
}

/* --- Stacked Columns Layout for Multiple Wives --- */
.spouses-columns-container { display: flex; gap: 40px; position: relative; z-index: 2; }
.spouses-column { display: flex; flex-direction: column; gap: 16px; position: relative; }

/* 1. Central vertical dashed line dropping from Husband through the center */
.spouses-columns-container::before {
    content: ''; position: absolute; 
    top: -24px;    /* Reaches up across the 24px gap to touch the husband */
    bottom: 31px;  /* Stops exactly at the middle of the bottom-most wife card */
    left: 50%; transform: translateX(-50%);
    border-left: 2px dashed var(--line-color); opacity: 0.6; z-index: -1;
}

/* If there are children, extend the central line all the way down to the toggle button */
.card-group-vertical.has-children .spouses-columns-container::before {
    bottom: -12px; 
}

/* 2. Short horizontal dashed lines connecting each individual wife to the central axis */
.spouses-column .card::after {
    content: ''; position: absolute;
    top: 50%; 
    width: 20px; /* Spans exactly half of the 40px gap between the two columns */
    border-bottom: 2px dashed var(--line-color); opacity: 0.6; z-index: -1;
}

/* Right column (first child in RTL) connects inward to the left */
.spouses-columns-container .spouses-column:first-child .card::after {
    left: -20px;
}

/* Left column (last child in RTL) connects inward to the right */
.spouses-columns-container .spouses-column:last-child .card::after {
    right: -20px;
}

/* Overriding the old shift rule so parent lines hit the Husband dead center */
.tree li:has(.has-spouses)::before {
    right: 50% !important; 
    width: 50% !important;
}
.tree li:has(.has-spouses)::after {
    left: 50% !important; 
    width: 50% !important;
    border-left: 2px solid var(--line-color) !important;
}

/* --- New Additions --- */
.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.card-extra {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* --- Dynamic Zoom Visibility --- */
/* Default state (Zoomed In) */
.short-name { display: none; }
.full-name { display: block; }

/* Small state (Zoomed Out) */
.zoom-small .short-name { 
    display: block; 
    text-align: center; 
}
.zoom-small .full-name { display: none; }
.zoom-small .avatar { display: none; } /* Hide picture */
.zoom-small .card-extra { display: none; } /* Hide surname and origin */
.zoom-small .deceased-badge { display: none; } /* Hide the badge on small zoom */

.zoom-small .card { 
    justify-content: center; /* Center the short text */
    padding: 8px 12px;
    height: 40px; /* Uniform height for the zoomed-out state */
}

/* --- Deceased Badge (Absolute positioned inside .card) --- */
.deceased-badge {
    position: absolute;
    left: 8px;
    top: 58px;
    font-size: 0.65rem;
    color: var(--text-muted);
    z-index: 5;
}

/* --- Header Tools (New Menu) --- */
.left-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-tools {
    display: flex;
    gap: 4px;
    align-items: center;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.tool-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

/** HOVER
.tool-btn:hover {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow);
}
*/

.tool-btn svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* تعطيل الأزرار بصرياً ومنع النقر عليها */
.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    background: transparent !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
}

/* --- Help Modal --- */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); backdrop-filter: blur(2px); }
.modal:not(.hidden) { display: flex; align-items: center; justify-content: center; }
.modal-content { background-color: #fff; padding: 20px; border-radius: 8px; width: 90%; max-width: 450px; text-align: center; color: #333; }
.help-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; text-align: right; }
.help-table td { border: 1px solid var(--border); padding: 12px; font-size: 0.95rem; font-weight: 600; color: #555; width: 50%; float: right;}
.help-td-content { display: flex; justify-content: space-between; align-items: center; }
.help-td-content svg { 
    width: 20px; 
    height: 20px; 
    stroke: currentColor; 
    stroke-width: 2; 
    fill: none; 
    stroke-linecap: round; 
    stroke-linejoin: round; 
    color: #888; 
}
.help-text p { font-size: 1.1rem; font-weight: 500; margin: 15px 0; color: #444; }
.help-text hr { border: none; border-top: 1px solid var(--border); }

/* --- Select Logo Styling --- */
.logo-select {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    border: none;
    background: transparent;
    outline: none;
    cursor: pointer;
    color: var(--text-main);
}

.tree > ul > li:only-child:has(.has-spouse)::before { display: none !important; }
.tree > ul > li::before, .tree > ul > li::after { display: none !important; }
.tree > ul > li { padding-top: 0 !important; }


/* إخفاء زر بحث الموبايل في شاشات الكمبيوتر */
.mobile-search-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 5px;
}

/* --- تصحيح استقامة الخطوط بين الآباء والأبناء --- */

/* 1. إلغاء أي إزاحة سابقة أثرت على الآباء */
.card-group.has-spouse {
    margin-right: 0 !important;
}

/* 2. جعل الخط الصاعد من الابن يخرج من منتصف بطاقته هو (وليس من منتصف الزواج) */
.node-wrapper:has(> .has-spouse)::before {
    left: calc(50% + 120px) !important;
}

/* 3. تعديل الخطوط الأفقية للإخوة (إن وجدوا) لكي تصل بشكل صحيح إلى بطاقة الابن */
.tree li:has(> .node-wrapper > .has-spouse)::before {
    right: calc(50% - 120px) !important; 
    width: calc(50% + 120px) !important;
}
.tree li:has(> .node-wrapper > .has-spouse)::after {
    left: calc(50% + 120px) !important; 
    width: calc(50% - 120px) !important;
}

/* إزاحة الابن الوحيد المتزوج وزوجته لليسار ليتطابق مع خط الآباء المستقيم */
.tree li:only-child:has(> .node-wrapper > .has-spouse) {
    transform: translateX(-120px);
}

/* إخفاء الجسر الأفقي للابن الوحيد لأنه لم يعد ضرورياً */
.tree li:only-child:has(> .node-wrapper > .has-spouse)::before,
.tree li:only-child:has(> .node-wrapper > .has-spouse)::after {
    display: none !important;
}

#closeSidebar, #backSidebarBtn, #closeSidebarBottom, #backSidebarBtnBottom {
    color: green;
    z-index: 9999;
}


/* =========================================
   الإصلاح النهائي والذكي لتعدد الزوجات
   ========================================= */

/* 1. إخفاء الخطوط القديمة لمنع التداخل */
.main-card-row::after,
.spouses-columns-container::before {
    display: none !important;
}

/* 2. رسم خط ديناميكي يغطي كل الزوجات مهما كان عددهن (2, 4, أو أكثر) */
.card-group-vertical::after {
    display: block !important;
    content: '';
    position: absolute;
    top: 85px !important;       /* يبدأ بالضبط من أسفل بطاقة الزوج */
    bottom: 42.5px !important;  /* يتوقف تماماً في منتصف الزوجات في الأسفل */
    left: 50% !important;
    transform: translateX(-50%) !important;
    border-left: 2px dashed var(--line-color) !important;
    opacity: 0.6 !important;
    z-index: -1 !important;
}

/* 3. في حال وجود أبناء: تمديد الخط ليلتمس بزر (+) */
.card-group-vertical.has-children::after {
    bottom: -12px !important;
}

/* 4. الخط المتصل للأبناء: يبدأ من حيث ينتهي الخط المتقطع */
.node-wrapper.is-parent:has(> .card-group-vertical)::after {
    top: calc(100% - 36px) !important;
    bottom: -40px !important;
    height: auto !important;
    z-index: -2 !important;
}

/* 5. القياسات في وضع تصغير الشاشة (Zoom Out) */
.zoom-small .card-group-vertical::after {
    top: 40px !important;
    bottom: 20px !important;
}
.zoom-small .card-group-vertical.has-children::after {
    bottom: -12px !important;
}
.zoom-small .node-wrapper.is-parent:has(> .card-group-vertical)::after {
    top: calc(100% - 36px) !important;
}


/* =========================================
   إلغاء التحريك برمجياً لتسريع التكبير والتصغير
   ========================================= */
.no-transitions, .no-transitions * {
    transition: none !important;
}


/* --- Avatar Popup Modal --- */
#avatarPopup {
    display: none; 
    position: fixed; 
    z-index: 3000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%;
    background-color: rgba(0,0,0,0.8); 
    backdrop-filter: blur(5px);
    align-items: center; 
    justify-content: center; 
    opacity: 0; 
    transition: opacity 0.3s ease;
    touch-action: none;
}
#avatarPopup.show { 
    display: flex; 
    opacity: 1; 
}
#avatarPopup img {
    width: 250px; 
    height: 250px; 
    border-radius: 50%; 
    object-fit: cover;
    border: 5px solid white; 
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    transform: scale(0.8); 
    transition: transform 0.3s ease;
}
#avatarPopup.show img { 
    transform: scale(1); 
}

.gen-content .detail-section h3 {
    color: #ffa700;
}

/*
@media (hover: hover) {
    .search-item:hover { 
        background: var(--bg-color); 
    }
}
*/

/* --- Burger Menu (Hidden by default on desktop) --- */

.burger-btn {
    display: none; 
}

@media (max-width: 950px) and (orientation: landscape) {
    .burger-btn {
        display: inline-flex !important;
        order: 6; 
        margin-right: auto; 
        z-index: 1001;
    }

    nav.top-bar div.left-actions div.controls:first-child {
        display: none !important; 
        position: absolute;
        top: 60px;
        left: 15px; 
        background: white;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: 0 10px 25px rgba(0,0,0,0.2);
        flex-direction: column;
        padding: 10px;
        gap: 8px;
        z-index: 1000;
        min-width: 160px;
    }
    
    /* إضافة الترتيب الجديد للقائمة هنا */
    #btnHome { order: 1; }
    #btnHelp { order: 2; }
    #btnContact { order: 3; }

    #btnCenter {
        order: 4;
        width: 70px;
        padding: 6px 6px;
    }

    .top-bar {
        padding: 0 10px;
    }

    .search-container {
        width: 315px;
        padding: 0 4px;
        margin-left: 10px;
    }

    /* The class JavaScript will add to show the menu */
    nav.top-bar div.left-actions div.controls.show-burger-menu {
        display: flex !important;
    }

    /* Style the control buttons to look like a dropdown list */
    nav.top-bar div.left-actions div.controls button {
        width: 100%;
        text-align: right;
        padding: 10px;
        background: var(--bg-color);
        border: 1px solid var(--border);
    }

    .logo-select {
        width: 100%;
        font-size: 14px;
    }

    .modal-content {
        width: 90%;
        height: 94%;
        overflow: auto;
    }
}


/* =========================================
   تعديلات الهاتف المحمول فقط (Mobile Only)
   ========================================= */
@media (max-width: 768px) {
    .minimap { display: none !important; }
    
    .mobile-search-btn { 
        display: inline-flex; 
        align-items: center; 
        justify-content: center; 
    }

    .top-bar {
        display: flex !important;
        flex-wrap: wrap;
        padding: 8px 12px; 
        gap: 5px; 
        height: auto;
        align-items: center;
        justify-content: flex-start; /* يمنع الأزرار من التباعد المفرط */
    }

    /* Unwrap containers to allow flex ordering in .top-bar */
    .logo, .left-actions, .controls {
        display: contents !important;
    }

    /* --- Line 1 --- */
    select.logo-select { 
        order: 1;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
    
    /* Hide text, format as icons, and position between select & search */
    #btnContact { order: 2; margin-right: auto !important; margin-left: 0 !important; font-size: 0; padding: 6px; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
    #btnHome { order: 3; margin: 0 !important; font-size: 0; padding: 6px; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
    #btnHelp { order: 4; margin-right: 0 !important; margin-left: auto !important; font-size: 0; padding: 6px; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
    
    #btnContact svg, #btnHome svg, #btnHelp svg { margin: 0 !important; }

    #mobileSearchBtn { 
        order: 5; 
        flex-shrink: 0; 
        padding: 5px 4px;
    }
    #mobileSearchBtn span { margin-right: 4px !important; font-size: 0.9rem; }

    /* Force line break for 2-line header */
    .top-bar::after {
        content: "";
        width: 100%;
        order: 6;
    }

    /* --- Line 2 --- */
    #toolbar { order: 7; display: flex; }
    #btnCenter { order: 8; margin-right: 10px; } /* Next to the toolbar */

    #mobileSearchBtn {
        z-index: 99999;
    }

    .search-container {
        display: none;
        position: absolute;
        top: 90px;
        left: 15px;
        right: 15px;
        width: auto;
        background: white;
        padding: 15px;
        border-radius: 8px;
        box-shadow: 0 10px 25px rgba(0,0,0,0.15);
        border: 1px solid var(--border);
        z-index: 1000;
    }

    .search-container.show-mobile { display: block; }

    /* --- Touch Hover Labels (Long Press) --- */
    #btnContact, #btnHome, #btnHelp, #zoomIn, #zoomOut, .tool-btn {
        position: relative;
    }

    /* إخفاء التلميحات افتراضياً مع إعطاء تأثير ظهور متأخر */
    #btnContact::before, #btnHome::before, #btnHelp::before, #zoomIn::before, #zoomOut::before, .tool-btn::before {
        content: attr(title);
        position: absolute;
        background: rgba(0,0,0,0.85); color: white;
        padding: 5px 10px; border-radius: 4px; font-size: 13px;
        white-space: nowrap; z-index: 9999;
        pointer-events: none;
        font-family: 'Cairo', sans-serif;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease, visibility 0.2s ease;
        transition-delay: 0s; /* يختفي فور إزالة الإصبع */
    }

    /* Header buttons & Toolbar buttons: Tooltip on the right side */
    #btnContact::before, #btnHome::before, #btnHelp::before {
        bottom: auto; 
        top: 50%; 
        left: calc(100% + 12px); 
        right: auto; 
        transform: translateY(-50%);
    }

    /* Zoom buttons: Tooltip on top */
    #zoomIn::before, #zoomOut::before, .tool-btn::before {
        top: -35px; left: 50%; transform: translateX(-50%);
    }

    /* إظهار التلميح فقط عند الضغط المطول (نصف ثانية) */
    #btnContact:active::before, #btnHome:active::before, #btnHelp:active::before, #zoomIn:active::before, #zoomOut:active::before, .tool-btn:active::before {
        opacity: 1;
        visibility: visible;
        transition-delay: 0.5s; /* الانتظار 500ms قبل الظهور */
    }

    #input-search-icon { display: none; }

    .sidebar {
        top: 0px;
        width: 100%;
    }

    .logo-select {
        font-size: 14px;
    }
}

