:root {
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: #e2e8f0;
    --input-bg: #ffffff;
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-light: #e0f2fe;
    --primary-light-text: #0369a1;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --danger-hover: #dc2626;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    --modal-overlay: rgba(15, 23, 42, 0.4);
    --fixed-bar-bg: #ffffff;
    --fixed-bar-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] {
    --bg-main: #0b0f19;
    --bg-card: #111827;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --border: #374151; 
    --input-bg: #1f2937;
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --primary-light: #0c4a6e;
    --primary-light-text: #38bdf8;
    --danger: #f87171;
    --danger-light: #451a03;
    --danger-hover: #ef4444;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --fixed-bar-bg: #1f2937;
    --fixed-bar-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; transition: background-color 0.25s, border-color 0.25s, color 0.25s; }
body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    margin: 0;
    padding: 20px 20px 110px 20px;
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 2.2rem;
    position: relative;
    transform: scale(0.98);
    opacity: 0;
    animation: showCard 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: max-width 0.35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease;
}
.card.expanded { max-width: 680px; }
@keyframes showCard { to { transform: scale(1); opacity: 1; } }
.hidden { display: none !important; }

h2 { margin: 0 0 1.5rem 0; font-size: 1.3rem; font-weight: 700; display: flex; justify-content: space-between; align-items: center; letter-spacing: -0.02em; }

.header-leading {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.tab-nav {
    display: none; /* Replaced by sleek off-canvas Hamburger drawer navigation */
    gap: 6px;
    margin-bottom: 1.5rem;
    background: var(--bg-main);
    padding: 4px;
    border-radius: 14px;
    border: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.tab-nav::-webkit-scrollbar {
    display: none;
}
.tab-btn {
    flex: 1;
    min-width: fit-content;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.88rem;
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    text-align: center;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.tab-btn.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.profile-info-box {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    word-break: break-all;
}
.profile-info-val {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}
.badge-days {
    background: var(--primary-light);
    color: var(--primary-light-text);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.pricing-inline {
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 12px;
    margin-top: 10px;
    padding: 6px 0;
}
.price-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}
.price-amount {
    font-weight: 700;
    color: var(--primary);
    font-size: 0.88rem;
}
.price-sep {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: var(--border);
    flex-shrink: 0;
}

/* بطاقة نظام الإحالة - Referral Card */
.referral-card {
    margin-top: 1.25rem;
    background: var(--bg-main);
    border: 1px dashed var(--border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    overflow: hidden;
}
.referral-header {
    display: flex;
    align-items: center;
    gap: 10px;
}
.referral-icon-badge {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: #fef3c7;
    color: #d97706;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
[data-theme="dark"] .referral-icon-badge {
    background: #451a03;
    color: #fcd34d;
}
.referral-title-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.referral-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
}
.referral-subtitle {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 1px;
}
.referral-desc {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--text-main);
}
.referral-desc strong {
    color: var(--primary);
}
.referral-rewards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.referral-reward-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: center;
}
.referral-reward-box.reward-you {
    border-color: rgba(2, 132, 199, 0.3);
    background: var(--primary-light);
}
.referral-reward-box.reward-you .reward-tag {
    color: var(--primary-light-text);
}
.referral-reward-box.reward-you .reward-val {
    color: var(--primary);
}
[data-theme="dark"] .referral-reward-box.reward-you {
    border-color: rgba(56, 189, 248, 0.3);
}
.referral-reward-box.reward-friend {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.08);
}
.referral-reward-box.reward-friend .reward-tag {
    color: #059669;
}
.referral-reward-box.reward-friend .reward-val {
    color: #10b981;
}
[data-theme="dark"] .referral-reward-box.reward-friend {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(52, 211, 153, 0.3);
}
[data-theme="dark"] .referral-reward-box.reward-friend .reward-tag {
    color: #34d399;
}
[data-theme="dark"] .referral-reward-box.reward-friend .reward-val {
    color: #6ee7b7;
}
.reward-tag {
    font-size: 0.74rem;
    font-weight: 700;
}
.reward-val {
    font-size: 0.98rem;
    font-weight: 800;
    letter-spacing: -0.01em;
}
.referral-note {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}
.referral-note svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--text-muted);
}

.copy-btn {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 0.85rem;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    white-space: nowrap;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.copy-btn:hover {
    background: var(--primary-light);
    color: var(--primary-light-text);
    border-color: var(--primary);
}

/* قائمة التحميل الاحتياطية */
.backup-downloads-section {
    margin-top: 1.5rem;
    padding: 16px;
    background: var(--bg-main);
    border: 1px dashed var(--border);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.backup-downloads-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}
.backup-downloads-header svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
.backup-downloads-section .profile-info-box {
    background: var(--bg-card);
}

.btn-issue-backup {
    width: 100%;
    min-height: 44px;
    padding: 10px 18px;
    background: var(--primary-light);
    color: var(--primary-light-text);
    border: 1px dashed var(--primary);
    border-radius: 12px;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.22s ease;
}
.btn-issue-backup:hover:not(:disabled) {
    background: var(--primary);
    color: #ffffff;
    border-style: solid;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.25);
    transform: translateY(-1px);
}
.btn-issue-backup:active:not(:disabled) {
    transform: scale(0.98);
}
.btn-issue-backup.loading {
    cursor: wait;
    opacity: 0.9;
    border-style: solid;
}
.btn-issue-backup .btn-issue-spinner {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(2, 132, 199, 0.25);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
[data-theme="dark"] .btn-issue-backup .btn-issue-spinner {
    border-color: rgba(56, 189, 248, 0.25);
    border-top-color: var(--primary);
}
.btn-issue-backup.loading .btn-issue-spinner {
    display: inline-block !important;
}
.btn-issue-backup.loading .btn-issue-icon {
    display: none !important;
}

.backup-links-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: backupLinksFadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes backupLinksFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-group { margin-bottom: 1rem; }
label { font-weight: 600; display: block; margin-bottom: 0.5rem; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

textarea, .text-input {
    width: 100%;
    font-size: 0.95rem;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-main);
    outline: none;
}
textarea:focus, .text-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
:disabled { background: var(--bg-main); color: var(--text-muted); cursor: not-allowed; opacity: 0.7; }

.checkbox-container { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.9rem; color: var(--text-muted); user-select: none; }
.checkbox-container input { width: 16px; height: 16px; accent-color: var(--primary); }

.url-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

.host-row { 
    display: flex;
    flex-direction: row;
    align-items: stretch;
    background: var(--bg-card); 
    border: 1.5px solid var(--border); 
    border-radius: 14px;
    padding: 10px;
    margin-bottom: 10px;
    gap: 10px;
    box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.05);
    animation: hostIn 0.25s ease forwards;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.18s ease;
}

.host-row:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 14px -2px rgba(2, 132, 199, 0.12);
}

[data-theme="dark"] .host-row {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

[data-theme="dark"] .host-row:hover {
    border-color: var(--primary);
}

.host-row.dragging {
    opacity: 0.45;
    border: 1.5px dashed var(--primary);
    background: var(--bg-main);
}

@keyframes hostIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* العمود الجانبي: رقم السيرفر وزر التحريك وزر الحذف عمودياً */
.host-side-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 5px;
    width: 36px;
    min-width: 36px;
    flex-shrink: 0;
    padding: 1px 0;
}

.host-number-badge {
    background: var(--primary-light);
    color: var(--primary-light-text);
    font-size: 0.78rem;
    font-weight: 800;
    width: 36px;
    height: 24px;
    border-radius: 7px;
    border: 1px solid var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    white-space: nowrap;
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

[data-theme="dark"] .host-number-badge {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.35);
}

.drag-handle {
    cursor: grab;
    width: 36px;
    height: 28px;
    min-height: 28px;
    padding: 0;
    color: var(--text-muted);
    background: var(--bg-main);
    border-radius: 7px;
    border: 1px solid var(--border);
    user-select: none;
    touch-action: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s ease;
    flex-shrink: 0;
}
.drag-handle:hover {
    color: var(--primary);
    background: var(--primary-light);
    border-color: var(--primary);
}
.drag-handle:active {
    cursor: grabbing;
    transform: scale(0.96);
}
.drag-handle svg {
    width: 15px;
    height: 15px;
    display: block;
    margin: auto;
    pointer-events: none;
}

.btn-delete {
    width: 36px !important;
    height: 28px !important;
    min-height: 28px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 7px !important;
    background: var(--danger-light) !important;
    color: var(--danger) !important;
    border: 1px solid rgba(239, 68, 68, 0.25) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: all 0.18s ease !important;
    flex-shrink: 0 !important;
}
[data-theme="dark"] .btn-delete {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important;
    border-color: rgba(248, 113, 113, 0.3) !important;
}
.btn-delete:hover {
    background: var(--danger) !important;
    color: #ffffff !important;
    border-color: var(--danger) !important;
    transform: scale(1.03);
}
.btn-delete:active {
    transform: scale(0.95);
}
.btn-delete svg {
    width: 14px;
    height: 14px;
    display: block;
    margin: auto;
    pointer-events: none;
}

/* عمود الحقول الرئيسي: حقول مضغوطة ومنظمة */
.host-inputs-col {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.host-field-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.host-field-prefix {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 2;
    opacity: 0.75;
}
[dir="rtl"] .host-field-prefix {
    right: 10px;
    left: auto;
}
[dir="ltr"] .host-field-prefix {
    left: 10px;
    right: auto;
}

.host-field-wrap .text-input {
    width: 100%;
    height: 38px;
    min-height: 38px;
    font-size: 0.88rem;
    border-radius: 8px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
[dir="rtl"] .host-field-wrap .text-input {
    padding-right: 32px !important;
    padding-left: 10px !important;
}
[dir="ltr"] .host-field-wrap .text-input {
    padding-left: 32px !important;
    padding-right: 10px !important;
}
.host-field-wrap .text-input:focus {
    background: var(--bg-card);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.host-divider {
    border-top: 1px solid var(--border);
    margin: 10px 0;
    width: 100%;
}

#urlContainer .host-row:only-child .btn-delete {
    display: none !important;
}

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--modal-overlay); display: flex; justify-content: center;
    align-items: center; z-index: 10000; opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content {
    background: var(--bg-card); border: 1px solid var(--border);
    padding: 2rem; border-radius: 20px; width: 90%; max-width: 520px;
    box-shadow: var(--shadow); transform: scale(0.95); transition: transform 0.2s ease;
}
.modal-overlay.active .modal-content { transform: scale(1); }
.modal-body {
    background: var(--bg-main); padding: 14px; border-radius: 12px;
    margin: 1.2rem 0; font-size: 0.9rem; max-height: 380px; overflow-y: auto;
    border: 1px solid var(--border);
}
.modal-body ul { margin: 0; padding-inline-start: 20px; color: var(--text-main); }
.modal-body li { margin-bottom: 6px; }

button {
    border: none; padding: 12px 20px; border-radius: 12px;
    font-weight: 600; font-size: 0.95rem; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; transition: all 0.2s ease;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--primary); color: white; width: 100%; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.2); }
button.primary:hover:not(:disabled) { background: var(--primary-hover); }
button.secondary { background: var(--border); color: var(--text-main); }
button.secondary:hover:not(:disabled) { filter: brightness(0.95); }
button.danger { background: var(--danger-light); color: var(--danger); padding: 12px; }
button.danger:hover:not(:disabled) { filter: brightness(0.9); }
button.add-btn { background: var(--primary-light); color: var(--primary-light-text); font-size: 0.85rem; padding: 8px 16px; margin-bottom: 0; border: 1px dashed var(--primary); }
button.add-btn:hover { filter: brightness(0.95); }

.btn-disconnect {
    color: var(--danger);
}
.btn-disconnect:hover:not(:disabled) {
    color: white !important;
    background: var(--danger) !important;
}

.card-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 12px;
}
.card-title {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-main);
}
.top-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.control-btn {
    background: transparent;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.control-btn:hover { color: var(--text-main); background: var(--bg-main); }
.btn-menu-prominent {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary-light-text);
    border: 1.5px solid var(--primary);
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.12);
    font-family: inherit;
    flex-shrink: 0;
}
.btn-menu-prominent:hover {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.28);
    transform: translateY(-1px);
}
.btn-menu-prominent:active {
    transform: scale(0.97);
}
.btn-menu-prominent svg {
    flex-shrink: 0;
    color: inherit;
}
.btn-menu-label {
    line-height: 1;
    white-space: nowrap;
}

/* =========================================================
   Off-Canvas Navigation Drawer & Backdrop
   ========================================================= */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1050;
}
.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.nav-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 82vw;
    background: var(--bg-card);
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.25);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
    visibility: hidden;
}

/* RTL / LTR drawer slide directions */
[dir="rtl"] .nav-drawer {
    right: 0;
    left: auto;
    border-left: 1px solid var(--border);
    border-right: none;
    transform: translateX(100%);
}
[dir="rtl"] .nav-drawer.open {
    transform: translateX(0);
    visibility: visible;
}

[dir="ltr"] .nav-drawer {
    left: 0;
    right: auto;
    border-right: 1px solid var(--border);
    border-left: none;
    transform: translateX(-100%);
}
[dir="ltr"] .nav-drawer.open {
    transform: translateX(0);
    visibility: visible;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    gap: 10px;
}
.drawer-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}
.drawer-brand-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.drawer-brand-icon svg {
    width: 17px;
    height: 17px;
    display: block;
    margin: auto;
}
.drawer-brand-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.drawer-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.4;
    padding-bottom: 1px;
}
.drawer-subtitle {
    font-size: 0.74rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 1px;
}

.drawer-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.drawer-pin-btn,
.drawer-close-btn {
    padding: 0 !important;
    margin: 0 !important;
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
    border-radius: 9px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
    flex-shrink: 0 !important;
    border: 1px solid var(--border) !important;
    box-sizing: border-box !important;
    outline: none !important;
}

/* زر التثبيت - Pin Button: لون أزرق ناعم وواضح */
.drawer-pin-btn {
    background: var(--bg-main) !important;
    color: var(--primary) !important;
    border-color: var(--border) !important;
}
.drawer-pin-btn:hover {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(2, 132, 199, 0.18);
}
.drawer-pin-btn:active {
    transform: scale(0.95);
}

/* عندما يكون التثبيت مفعلاً - Pinned Active State */
.drawer-pin-btn.active {
    background: var(--primary) !important;
    color: #ffffff !important;
    border-color: var(--primary) !important;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35) !important;
}
.drawer-pin-btn.active:hover {
    background: var(--primary-hover) !important;
    color: #ffffff !important;
}

/* زر الإغلاق - Close Button: لون أحمر واضح وناعم */
.drawer-close-btn {
    background: var(--danger-light) !important;
    color: var(--danger) !important;
    border-color: rgba(239, 68, 68, 0.2) !important;
}
[data-theme="dark"] .drawer-close-btn {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important;
    border-color: rgba(248, 113, 113, 0.3) !important;
}
.drawer-close-btn:hover {
    background: var(--danger) !important;
    color: #ffffff !important;
    border-color: var(--danger) !important;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(239, 68, 68, 0.25);
}
.drawer-close-btn:active {
    transform: scale(0.95);
}

/* أيقونات SVG: ضمان ظهورها بحجم وشكل واضحين تماماً */
.drawer-pin-btn svg,
.drawer-close-btn svg {
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    min-height: 18px !important;
    display: block !important;
    margin: auto !important;
    stroke: currentColor !important;
    pointer-events: none !important;
    transition: transform 0.22s ease !important;
}

.drawer-pin-btn .pin-icon {
    width: 18px !important;
    height: 18px !important;
}
.drawer-pin-btn.active .pin-icon {
    transform: rotate(-35deg) scale(1.05) !important;
}
[dir="rtl"] .drawer-pin-btn.active .pin-icon {
    transform: rotate(35deg) scale(1.05) !important;
}

/* Pinned Drawer State */
.nav-drawer.pinned {
    visibility: visible !important;
    transform: translateX(0) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    z-index: 950;
}
[data-theme="dark"] .nav-drawer.pinned {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* في حالة تسجيل الخروج أو شاشة الدخول: إخفاء القائمة تماماً حتى وإن كانت مثبتة */
body:not(.is-authenticated) .nav-drawer,
body:not(.is-authenticated) .drawer-overlay {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transform: none !important;
}

body:not(.is-authenticated).drawer-pinned {
    padding-right: 20px !important;
    padding-left: 20px !important;
}
@media (max-width: 768px) {
    body:not(.is-authenticated).drawer-pinned {
        padding-right: 12px !important;
        padding-left: 12px !important;
    }
}

body.drawer-pinned .drawer-overlay {
    display: none !important;
    pointer-events: none !important;
    opacity: 0 !important;
}

.btn-menu-prominent.drawer-is-pinned {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* Desktop layout adjustment when pinned */
@media (min-width: 769px) {
    [dir="rtl"] body.drawer-pinned {
        padding-right: 280px;
        transition: padding-right 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }
    [dir="ltr"] body.drawer-pinned {
        padding-left: 280px;
        transition: padding-left 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }

    [dir="rtl"] body.drawer-pinned .app-fixed-actions-bar {
        right: 280px;
        transition: right 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }
    [dir="ltr"] body.drawer-pinned .app-fixed-actions-bar {
        left: 280px;
        transition: left 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }
}

.drawer-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 10px;
}
.drawer-sections-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.drawer-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.drawer-section:not(:first-child) {
    padding-top: 7px;
    border-top: 1px dashed var(--border);
}
.drawer-section-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.5;
    padding: 6px 8px 3px 8px;
    letter-spacing: 0.02em;
    pointer-events: none;
    user-select: none;
    opacity: 0.95;
}
.drawer-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.drawer-item {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    text-align: inherit;
    transition: all 0.16s ease;
    font-family: inherit;
    box-sizing: border-box;
}
.drawer-item:hover {
    background: var(--bg-main);
    color: var(--text-main);
    border-color: var(--border);
}
.drawer-item.active {
    background: var(--primary-light);
    color: var(--primary-light-text);
    border-color: var(--primary-light);
    font-weight: 700;
}
.drawer-item-icon {
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
    color: inherit;
    flex-shrink: 0;
    margin: 0;
    padding: 0;
    transition: all 0.16s;
}
.drawer-item-icon svg {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    display: block;
    margin: auto;
    color: inherit;
}
.drawer-item.active .drawer-item-icon {
    background: var(--primary);
    color: #ffffff;
}
.drawer-item-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: inherit;
    line-height: 1.5;
    padding-bottom: 2px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.badge-coming-soon {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px 3px 8px;
    border-radius: 4px;
    background: #fef3c7;
    color: #b45309;
    white-space: nowrap;
    border: 1px solid rgba(180, 83, 9, 0.2);
    line-height: 1.4;
}
[data-theme="dark"] .badge-coming-soon {
    background: #78350f;
    color: #fde68a;
    border-color: rgba(253, 230, 138, 0.2);
}

/* زر استعادة النسخة في القائمة الجانبية */
.drawer-item-rollback {
    color: var(--text-muted);
}
.drawer-item-rollback .drawer-item-icon {
    color: #d97706;
    background: #fef3c7;
}
[data-theme="dark"] .drawer-item-rollback .drawer-item-icon {
    color: #fcd34d;
    background: #451a03;
}
.drawer-item-rollback:hover {
    background: #fef3c7;
    color: #92400e;
    border-color: #fcd34d;
}
[data-theme="dark"] .drawer-item-rollback:hover {
    background: #451a03;
    color: #fef3c7;
    border-color: #78350f;
}
.drawer-item-rollback .spinner {
    border-color: rgba(217, 119, 6, 0.2);
    border-top-color: #d97706;
}
[data-theme="dark"] .drawer-item-rollback .spinner {
    border-color: rgba(252, 211, 77, 0.2);
    border-top-color: #fcd34d;
}

/* VPN Card Styling */
.vpn-card {
    background: var(--bg-main);
    border: 1px dashed var(--border);
    border-radius: 18px;
    padding: 34px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}
.vpn-icon-wrap {
    width: 68px;
    height: 68px;
    border-radius: 20px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.15);
}
.vpn-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}
.vpn-badge {
    background: #fef3c7;
    color: #b45309;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 8px;
    border: 1px solid rgba(180, 83, 9, 0.2);
    display: inline-block;
}
[data-theme="dark"] .vpn-badge {
    background: #78350f;
    color: #fde68a;
    border-color: rgba(253, 230, 138, 0.2);
}
.vpn-desc {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-muted);
    max-width: 320px;
    line-height: 1.5;
}

.drawer-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    font-size: 0.74rem;
    line-height: 1.4;
    color: var(--text-muted);
    text-align: center;
}

.app-fixed-actions-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--fixed-bar-bg);
    border-top: 1px solid var(--border);
    padding: 16px 24px;
    box-shadow: var(--fixed-bar-shadow);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
}
.fixed-actions-inner {
    width: 100%;
    max-width: 680px; 
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.btn-save {
    min-height: 44px;
    font-size: 0.95rem;
}

.btn-rollback {
    min-height: 44px;
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fcd34d;
    padding: 10px 18px;
    font-weight: 600;
}
.btn-rollback:hover:not(:disabled) {
    background: #fde68a;
    color: #92400e;
    filter: none;
}
[data-theme="dark"] .btn-rollback {
    background: #451a03;
    color: #fcd34d;
    border: 1px solid #78350f;
}
[data-theme="dark"] .btn-rollback:hover:not(:disabled) {
    background: #78350f;
    color: #fef3c7;
}

.spinner {
    display: none; width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.3); border-radius: 50%;
    border-top-color: currentColor; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading .spinner { display: inline-block !important; }
.loading .btn-txt { display: none !important; }

#toastContainer { position: fixed; bottom: 94px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; max-width: 350px; width: calc(100% - 48px); }
html[dir="ltr"] #toastContainer { right: 24px; }
html[dir="rtl"] #toastContainer { left: 24px; }

.toast {
    background: var(--bg-card); color: var(--text-main); border-inline-start: 4px solid var(--primary);
    padding: 16px 20px; border-radius: 12px; font-size: 0.9rem; font-weight: 500;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    transform: translateY(120%); opacity: 0; animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes toastIn { to { transform: translateY(0); opacity: 1; } }
.toast.success { border-inline-start-color: #10b981; }
.toast.error { border-inline-start-color: var(--danger); }
.toast.warning { border-inline-start-color: #f59e0b; }
.toast-close { cursor: pointer; color: var(--text-muted); font-weight: bold; font-size: 1rem; }

/* ==========================================================================
   Extra Services (Smart Hosts)
   ========================================================================== */
.services-header-box {
    margin-bottom: 1.2rem;
}
.services-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
}
.services-header-notice {
    margin: 10px 0 0 0;
    font-size: 0.84rem;
    color: #dc2626;
    line-height: 1.5;
    background: rgba(239, 68, 68, 0.08);
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(239, 68, 68, 0.28);
    font-weight: 600;
}
[data-theme="dark"] .services-header-notice {
    color: #f87171;
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(248, 113, 113, 0.35);
}

.services-cards-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.server-card {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    transition: all 0.2s ease;
    animation: hostIn 0.3s ease forwards;
}
[data-theme="dark"] .server-card {
    background: var(--input-bg);
    border-color: var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.server-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.server-card-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}
.server-icon-badge {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.server-card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
}
.server-url-count {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 8px;
    white-space: nowrap;
}

.server-urls-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.server-url-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    transition: border-color 0.2s;
}
.server-url-item:hover {
    border-color: var(--primary);
}
.server-url-link-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}
.server-url-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}
.server-url-text {
    font-size: 0.85rem;
    color: var(--text-main);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: all;
    direction: ltr;
}
.badge-new-host {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.3;
    background: #ecfdf5;
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.28);
    white-space: nowrap;
    margin-inline-start: 6px;
    flex-shrink: 0;
    transition: opacity 0.22s ease, transform 0.22s ease;
}
[data-theme="dark"] .badge-new-host {
    background: rgba(16, 185, 129, 0.16);
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.35);
}
.badge-new-host.fade-out {
    opacity: 0;
    transform: scale(0.85);
}
.server-copy-btn {
    min-height: 36px;
    padding: 7px 12px;
    font-size: 0.82rem;
    border-radius: 8px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    color: var(--text-main);
    white-space: nowrap;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.server-copy-btn:hover {
    background: var(--primary-light);
    color: var(--primary-light-text);
    border-color: var(--primary);
}
.server-copy-btn.copied {
    background: #10b981 !important;
    color: #ffffff !important;
    border-color: #10b981 !important;
}
.server-url-empty {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 8px 0;
}

/* Skeleton Loading State */
.services-skeleton-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.services-skeleton-card {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.skeleton-line {
    background: linear-gradient(90deg, var(--border) 25%, var(--bg-card) 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
    border-radius: 6px;
}
.skeleton-title {
    width: 45%;
    height: 18px;
}
.skeleton-box {
    width: 100%;
    height: 38px;
    border-radius: 10px;
}
@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Error & Empty States */
.services-error-card {
    background: var(--danger-light);
    border: 1px solid var(--danger);
    border-radius: 16px;
    padding: 24px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.services-error-icon {
    color: var(--danger);
}
.services-error-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--danger);
}
.services-error-desc {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 300px;
    line-height: 1.4;
    word-break: break-word;
}
.services-retry-btn {
    margin-top: 8px;
    background: var(--bg-card);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.services-retry-btn:hover {
    background: var(--danger);
    color: #ffffff;
}
.services-empty-card {
    text-align: center;
    padding: 30px 16px;
    color: var(--text-muted);
    background: var(--bg-main);
    border: 1px dashed var(--border);
    border-radius: 14px;
    font-size: 0.9rem;
}

/* Responsive Polish for Small Viewports */
@media (max-width: 540px) {
    body {
        padding: 12px 12px 110px 12px;
    }
    .card {
        padding: 1.5rem 1.15rem;
        border-radius: 18px;
    }
    .app-fixed-actions-bar {
        padding: 12px 16px;
    }
    .fixed-actions-inner {
        gap: 8px;
    }
    .btn-rollback {
        padding: 10px 12px;
    }
    .btn-menu-prominent {
        padding: 5px 10px;
        height: 36px;
        font-size: 0.82rem;
        gap: 5px;
    }
    .header-leading {
        gap: 8px;
    }
    .card-header-bar {
        gap: 8px;
    }
    .host-row {
        padding: 8px;
        gap: 8px;
    }
    .host-side-col {
        width: 32px;
        min-width: 32px;
    }
    .host-number-badge {
        width: 32px;
        height: 22px;
        font-size: 0.74rem;
    }
    .drag-handle, .btn-delete {
        width: 32px !important;
        height: 26px !important;
        min-height: 26px !important;
    }
}

.hidden, [hidden] {
    display: none !important;
}

