@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-dark: #090d16;
    --card-bg: #111827;
    --card-border: #1f2937;
    --card-hover: #1f293d;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --accent-cyan: #06b6d4;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.12);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --radius: 12px;
    --font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    direction: rtl;
    text-align: right;
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: #0f172a;
    border-left: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem 1.5rem;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 1.5rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1.25rem;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.brand-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    list-style: none;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(6, 182, 212, 0.15));
    color: #fff;
    border-right: 3px solid var(--primary);
    font-weight: 600;
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid var(--card-border);
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.logout-btn:hover {
    background: var(--danger);
    color: #fff;
}

/* Main Content Area */
.main-wrapper {
    flex: 1;
    margin-right: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: calc(100% - 260px);
}

.topbar {
    height: 64px;
    background: rgba(17, 24, 39, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.topbar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
}

.content-body {
    padding: 2rem;
    flex: 1;
}

/* Cards & Grid */
.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    border-color: #374151;
}

.card-header-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.card-icon.purple {
    background: rgba(99, 102, 241, 0.15);
    color: #818cf8;
}

.card-icon.emerald {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.card-icon.amber {
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
}

.card-icon.rose {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
}

.stat-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 8px;
    background: #1f2937;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 1rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent-cyan));
    border-radius: 999px;
    transition: width 0.5s ease;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #4338ca);
    color: #fff;
    box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #1f2937;
    color: #f3f4f6;
    border: 1px solid #374151;
}

.btn-secondary:hover {
    background: #374151;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

/* Search and Actions Bar */
.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}


.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 0.35rem 0.6rem;
    flex: 1;
    max-width: 450px;
}

.search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    width: 100%;
    font-size: 0.88rem;
}

.search-box input::placeholder {
    color: var(--text-muted, #94a3b8);
}

.action-bar .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.proxy-action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.proxy-info-text {
    font-size: 0.88rem;
    color: var(--text-muted, #94a3b8);
    margin: 0;
    line-height: 1.5;
}

.proxy-action-bar .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
}

/* بهینه‌سازی اختصاصی برای گوشی‌های موبایل (کمتر از 768px) */
@media (max-width: 768px) {
    .action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
    }

    .proxy-action-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
    }

    .proxy-info-text {
        font-size: 0.82rem;
        text-align: right;
    }

    .proxy-action-bar .btn-primary {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        justify-content: center;
    }

    .search-box {
        max-width: 100%;
        width: 100%;
        padding: 0.45rem 0.75rem;
    }

    .tabs-container {
        width: 100%;
        margin-bottom: 0 !important;
    }

    .tab-btn {
        flex: 1;
        justify-content: center;
        padding: 0.65rem 0.5rem;
        font-size: 0.85rem;
    }

    .config-action-btns {
        width: 100%;
    }

    .config-action-btns .btn {
        flex: 1;
        justify-content: center;
        padding: 0.65rem 0.5rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    .search-box input {
        font-size: 0.85rem;
    }

    .search-box .btn {
        padding: 0.4rem 0.8rem;
        white-space: nowrap;
    }

    .action-bar .btn-primary {
        width: 100%;
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
        justify-content: center;
    }
}

/* Table */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--card-border);
    background: var(--card-bg);
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: right;
    font-size: 0.9rem;
}

.custom-table th {
    background: #1f2937;
    color: #9ca3af;
    padding: 1rem;
    font-weight: 600;
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
}

.custom-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--card-border);
    color: #e5e7eb;
    vertical-align: middle;
}

.custom-table tr:last-child td {
    border-bottom: none;
}

.custom-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-active {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-expired {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-country {
    background: rgba(99, 102, 241, 0.15);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
    font-family: monospace;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.5rem;
}

/* Tabs */
.tabs-container {
    display: flex;
    gap: 0.35rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.3rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.1rem;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted, #94a3b8);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn.active {
    background: var(--primary, #6366f1);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.config-action-btns {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    padding: 1.75rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    animation: modalFade 0.2s ease-out;
    /* Tall modals (e.g. API source) scroll inside the box instead of running off-screen */
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal-box::-webkit-scrollbar {
    width: 8px;
}

.modal-box::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.modal-box::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

@keyframes modalFade {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 1rem;
    /* Stays reachable while a tall modal body scrolls */
    position: sticky;
    top: -1.75rem;
    margin-top: -1.75rem;
    padding-top: 1.75rem;
    background: var(--card-bg);
    z-index: 1;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-close:hover {
    color: #fff;
}

/* Form inputs */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #d1d5db;
    margin-bottom: 0.5rem;
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    background: #0f172a;
    border: 1px solid #374151;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    color: #fff;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

/* Toast alert */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    background: #1f2937;
    color: #fff;
    border: 1px solid #374151;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: none;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.toast.show {
    display: flex;
    animation: toastIn 0.3s ease-out;
}

@keyframes toastIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Country Section in Configs */
.country-section {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.country-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
}

.country-flag {
    font-size: 1.25rem;
}

.country-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
}

/* Load More Button Container */
.load-more-container {
    text-align: center;
    margin-top: 1.5rem;
}

/* Copy code snippet */
.copy-box {
    background: #0f172a;
    border: 1px solid #1f2937;
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    font-family: monospace;
    font-size: 0.8rem;
    color: #a5b4fc;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive adjustments */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-wrapper {
        margin-right: 0;
        width: 100%;
    }

    .mobile-toggle {
        display: block;
    }
}